/* Painel Carrinho Lateral
   Layout: barra superior fixa · coluna de edição com abas à esquerda · prévia ao vivo fixa à direita. */
:root {
  --bg: #f1f1f1;
  --surface: #ffffff;
  --surface-2: #f7f7f7;
  --fg: #303030;
  --muted: #616161;
  --line: #e3e3e3;
  --primary: #303030;
  --primary-fg: #ffffff;
  --focus: #2c6ecb;
  --selected: #ebf3ff;
  --success: #29845a;
  --success-bg: #e3f8ec;
  --warn-bg: #fff5d6;
  --warn-fg: #6b4c00;
  --critical: #c70a24;
  --stage: #e9e8e4;
  --font: -apple-system, BlinkMacSystemFont, "San Francisco", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --r: 12px;
  --shadow: 0 1px 0 rgba(26, 26, 26, .07), 0 1px 2px rgba(26, 26, 26, .08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1a1a; --surface: #262626; --surface-2: #2f2f2f; --fg: #e8e8e8; --muted: #a8a8a8; --line: #3a3a3a;
    --primary: #f0f0f0; --primary-fg: #1a1a1a; --focus: #6ea2ff; --selected: #22324a; --success: #5fd09a; --success-bg: #173826;
    --warn-bg: #3b3115; --warn-fg: #f2d68a; --critical: #ff7b8a; --stage: #121212;
    --shadow: 0 1px 0 rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1a1a1a; --surface: #262626; --surface-2: #2f2f2f; --fg: #e8e8e8; --muted: #a8a8a8; --line: #3a3a3a;
  --primary: #f0f0f0; --primary-fg: #1a1a1a; --focus: #6ea2ff; --selected: #22324a; --success: #5fd09a; --success-bg: #173826;
  --warn-bg: #3b3115; --warn-fg: #f2d68a; --critical: #ff7b8a; --stage: #121212;
  --shadow: 0 1px 0 rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 13.5px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
.cl-loading { padding: 40px 16px; text-align: center; color: var(--muted); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* Barra superior */
.cl-top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.cl-brand { display: flex; align-items: center; gap: 10px; min-width: 0; margin-right: auto; }
.cl-brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--primary); color: var(--primary-fg); display: grid; place-items: center; flex: none; }
.cl-brand h1 { margin: 0; font-size: 15px; font-weight: 650; white-space: nowrap; }
.cl-status { font-size: 12px; color: var(--muted); }
.cl-status.is-dirty { color: var(--warn-fg); background: var(--warn-bg); padding: 2px 8px; border-radius: 999px; }
.cl-status.is-saved { color: var(--success); }

.cl-btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--fg); border-radius: 8px;
  padding: 6px 12px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; box-shadow: var(--shadow);
  white-space: nowrap;
}
.cl-btn:hover { background: var(--surface-2); }
.cl-btn:disabled { opacity: .45; cursor: default; }
.cl-btn--primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.cl-btn--primary:hover { background: var(--primary); opacity: .88; }
.cl-btn--plain { border-color: transparent; box-shadow: none; background: none; color: var(--focus); padding: 4px 6px; }
.cl-btn--plain:hover { background: var(--selected); }
.cl-btn--danger { color: var(--critical); }
.cl-btn--sm { padding: 4px 9px; font-size: 12.5px; }

.cl-demo {
  margin: 12px 20px 0; padding: 10px 14px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-fg); font-size: 13px;
}

/* Grade principal */
.cl-main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 460px); gap: 20px; padding: 16px 20px 40px; align-items: start; }
.cl-editor { min-width: 0; display: flex; flex-direction: column; gap: 14px; }

/* Abas */
.cl-tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; background: var(--surface); padding: 4px; border-radius: 10px; box-shadow: var(--shadow); }
.cl-tabs::-webkit-scrollbar { display: none; }
.cl-tab {
  appearance: none; border: 0; background: none; padding: 7px 12px; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--muted);
  white-space: nowrap; display: inline-flex; gap: 6px; align-items: center;
}
.cl-tab:hover { background: var(--surface-2); color: var(--fg); }
.cl-tab[aria-selected="true"] { background: var(--selected); color: var(--fg); }
.cl-tab .cl-count { font-size: 11px; background: var(--line); border-radius: 999px; padding: 0 6px; color: var(--fg); }

/* Cartões e campos */
.cl-card { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 14px; transition: box-shadow .15s; }
.cl-card.is-focus { box-shadow: var(--shadow), 0 0 0 2px var(--focus); }
.cl-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.cl-card h2 { margin: 0; font-size: 14px; font-weight: 650; text-wrap: balance; }
.cl-card .cl-sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; max-width: 60ch; }
.cl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.cl-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.cl-field > label, .cl-label { font-weight: 550; font-size: 13px; }
.cl-help { color: var(--muted); font-size: 12px; }
.cl-input, .cl-select, .cl-textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-height: 34px;
}
.cl-input:hover, .cl-select:hover { border-color: var(--muted); }
.cl-input:focus, .cl-select:focus, .cl-textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus); }
.cl-input--mono { font-family: var(--mono); font-size: 12.5px; }
.cl-textarea { min-height: 64px; resize: vertical; }

.cl-check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.cl-check input { margin: 2px 0 0; width: 16px; height: 16px; accent-color: var(--primary); flex: none; }
.cl-check span { display: flex; flex-direction: column; }

.cl-switch { position: relative; width: 36px; height: 20px; flex: none; }
.cl-switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.cl-switch i { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: background .15s; }
.cl-switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 999px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
.cl-switch input:checked + i { background: var(--success); }
.cl-switch input:checked + i::after { transform: translateX(16px); }
.cl-switch input:focus-visible + i { outline: 2px solid var(--focus); outline-offset: 2px; }

.cl-color { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 3px 8px 3px 3px; background: var(--surface); }
.cl-color input[type="color"] { width: 28px; height: 26px; border: 0; padding: 0; background: none; cursor: pointer; border-radius: 6px; }
.cl-color input[type="text"] { border: 0; background: none; width: 100%; min-width: 0; font-family: var(--mono); font-size: 12.5px; outline: none; }
.cl-range { display: flex; align-items: center; gap: 10px; }
.cl-range input { flex: 1; accent-color: var(--primary); }
.cl-range output { font-variant-numeric: tabular-nums; min-width: 48px; text-align: right; color: var(--muted); }

/* Segmentado */
.cl-seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; }
.cl-seg button { appearance: none; border: 0; background: none; padding: 6px 11px; border-radius: 6px; cursor: pointer; font-weight: 600; color: var(--muted); }
.cl-seg button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }

/* Regras de upsell */
.cl-rules { display: flex; flex-direction: column; gap: 10px; }
.cl-rule { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.cl-rule.is-open { border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus); }
.cl-rule.is-off .cl-rule-flow { opacity: .55; }
.cl-rule-row { display: flex; align-items: center; gap: 12px; padding: 12px; }
.cl-rule-order { display: flex; flex-direction: column; gap: 2px; }
.cl-rule-order button { appearance: none; border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 4px; line-height: 1; font-size: 11px; }
.cl-rule-order button:disabled { opacity: .25; cursor: default; }
.cl-rule-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.cl-rule-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cl-rule-flow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; }
.cl-rule-flow b { color: var(--fg); font-weight: 600; }
.cl-arrow { color: var(--muted); }
.cl-rule-actions { display: flex; align-items: center; gap: 6px; }
.cl-rule-body { border-top: 1px solid var(--line); padding: 14px; display: flex; flex-direction: column; gap: 16px; }
.cl-step { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 10px; }
.cl-step-n { width: 22px; height: 22px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; font-size: 11.5px; font-weight: 700; color: var(--muted); }
.cl-step-body { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.cl-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cl-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 3px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); max-width: 100%; }
.cl-chip img, .cl-chip .cl-ph { width: 26px; height: 26px; border-radius: 5px; object-fit: cover; flex: none; background: var(--line); }
.cl-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.cl-chip button { appearance: none; border: 0; background: none; cursor: pointer; color: var(--muted); padding: 2px 5px; border-radius: 5px; font-size: 14px; line-height: 1; }
.cl-chip button:hover { background: var(--line); color: var(--fg); }
.cl-empty-rules { text-align: center; padding: 26px 16px; border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.cl-confirm { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px; background: var(--warn-bg); color: var(--warn-fg); border-radius: 8px; }
.cl-pill { font-size: 11.5px; font-weight: 650; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.cl-pill--on { background: var(--success-bg); border-color: transparent; color: var(--success); }
.cl-pill--match { background: var(--selected); border-color: transparent; color: var(--focus); }

/* Níveis de recompensa */
.cl-tier { display: grid; grid-template-columns: 90px minmax(0, 1fr) 150px 32px; gap: 8px; align-items: end; }
.cl-note { padding: 10px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-fg); font-size: 12.5px; }

/* Prévia */
.cl-preview { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 70px); display: flex; flex-direction: column; gap: 10px; }
.cl-preview-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.cl-preview-head h2 { margin: 0; font-size: 13px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.cl-live { width: 8px; height: 8px; border-radius: 999px; background: var(--success); box-shadow: 0 0 0 3px var(--success-bg); }
.cl-stage { background: var(--stage); border-radius: var(--r); padding: 14px; display: flex; justify-content: center; }
.cl-device { width: 100%; max-width: 390px; height: min(720px, calc(100vh - 240px)); min-height: 480px; border-radius: 26px; overflow: hidden; background: #fff; box-shadow: 0 0 0 8px #1b1b1b, 0 12px 30px rgba(0,0,0,.25); }
.cl-device--desktop { max-width: 440px; border-radius: 6px; box-shadow: 0 0 0 1px rgba(0,0,0,.15), 0 12px 30px rgba(0,0,0,.18); }
.cl-device iframe { width: 100%; height: 100%; border: 0; display: block; }
.cl-testcart { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.cl-testcart-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.cl-testcart-head strong { font-size: 12.5px; }
.cl-zone-hint { font-size: 12px; color: var(--muted); min-height: 1.4em; }
.cl-zone-hint b { color: var(--focus); }

/* Seletor (modo demonstração) */
.cl-modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.cl-modal { width: min(520px, 100%); max-height: min(640px, 90vh); background: var(--surface); border-radius: 14px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.cl-modal header, .cl-modal footer { padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cl-modal header { border-bottom: 1px solid var(--line); }
.cl-modal header h3 { margin: 0; font-size: 15px; }
.cl-modal footer { border-top: 1px solid var(--line); justify-content: flex-end; }
.cl-modal-search { padding: 12px 16px 4px; }
.cl-modal-list { overflow-y: auto; padding: 6px 8px 10px; }
.cl-pick { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; cursor: pointer; }
.cl-pick:hover { background: var(--surface-2); }
.cl-pick img { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; }
.cl-pick span { flex: 1; min-width: 0; }
.cl-pick small { display: block; color: var(--muted); }

.cl-toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: #1a1a1a; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.cl-toast.is-error { background: var(--critical); }

@media (max-width: 1080px) {
  .cl-main { grid-template-columns: minmax(0, 1fr); }
  .cl-preview { position: static; order: -1; }
  .cl-device { height: 560px; }
}
@media (max-width: 560px) {
  .cl-top, .cl-main { padding-left: 16px; padding-right: 16px; }
  .cl-demo { margin-left: 16px; margin-right: 16px; }
  .cl-tier { grid-template-columns: 70px minmax(0, 1fr) 32px; }
  .cl-tier .cl-tier-gift { grid-column: 1 / -1; }
  .cl-rule-row { flex-wrap: wrap; align-items: flex-start; }
  .cl-rule-main { flex-basis: calc(100% - 40px); }
  .cl-rule-actions { margin-left: 32px; width: 100%; }
  .cl-device { height: 520px; min-height: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
