/* =================================================================
   AI Aggregator — design tokens + components
   Warm cinematographic dark, violet #a78bfa as glow accent.
   Tokens are namespaced under .ai-root so the design-canvas chrome
   (warm beige) is unaffected.
   ================================================================= */

.ai-root {
  /* ── Warm dark surfaces ───────────────────────── */
  --bg:           oklch(0.145 0.005 60);
  --bg-soft:      oklch(0.175 0.006 60);
  --bg-card:      oklch(0.195 0.007 60);
  --bg-elev:      oklch(0.225 0.008 60);
  --bg-hover:     oklch(0.235 0.008 60);

  /* ── Borders ──────────────────────────────────── */
  --border:        oklch(0.30 0.007 60 / 0.6);
  --border-strong: oklch(0.40 0.009 60 / 0.7);
  --border-focus:  oklch(0.71 0.16 295 / 0.55);

  /* ── Text ─────────────────────────────────────── */
  --text:        oklch(0.96 0.005 80);
  --text-soft:   oklch(0.82 0.006 80);
  --text-muted:  oklch(0.62 0.008 75);
  --text-dim:    oklch(0.46 0.008 70);

  /* ── Violet (the only saturated hue) ──────────── */
  --violet:        #a78bfa;
  --violet-soft:   oklch(0.62 0.14 295);
  --violet-deep:   oklch(0.45 0.13 295);
  --violet-bg:     oklch(0.71 0.16 295 / 0.12);
  --violet-bg-2:   oklch(0.71 0.16 295 / 0.20);
  --violet-glow:   oklch(0.71 0.16 295 / 0.30);
  --violet-glow-2: oklch(0.71 0.16 295 / 0.55);

  /* ── Status (distinguishable on warm dark) ────── */
  --status-queued:    oklch(0.74 0.06 235);  /* muted steel-blue */
  --status-running:   var(--violet);
  --status-succeeded: oklch(0.78 0.11 145);  /* warm green */
  --status-failed:    oklch(0.70 0.18 25);   /* warm red */
  --status-warn:      oklch(0.80 0.13 80);   /* amber for count */

  /* ── Radii (tweakable) ────────────────────────── */
  --r-xs: 6px;
  --r-sm: 8px;
  --r:    12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-pill: 999px;

  /* ── Spacing scale (tweakable density) ────────── */
  --gap: 14px;
  --pad-card: 18px;
  --pad-field: 12px 14px;

  /* ── Typography ───────────────────────────────── */
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;

  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-feature-settings: "cv11", "ss01", "ss03";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  letter-spacing: -0.005em;
  height: 100%;
  overflow: hidden;
}

/* Density variants applied to .ai-root */
.ai-root[data-density="compact"]  { --gap: 10px; --pad-card: 14px; --pad-field: 9px 11px; }
.ai-root[data-density="comfy"]    { --gap: 18px; --pad-card: 22px; --pad-field: 14px 16px; }

/* Radius variants */
.ai-root[data-radii="sharp"] { --r-xs: 2px; --r-sm: 4px; --r: 6px; --r-lg: 8px; --r-xl: 10px; }
.ai-root[data-radii="pill"]  { --r-xs: 10px; --r-sm: 14px; --r: 18px; --r-lg: 22px; --r-xl: 28px; }

/* Violet intensity */
.ai-root[data-violet="muted"] {
  --violet-glow:   oklch(0.71 0.16 295 / 0.14);
  --violet-glow-2: oklch(0.71 0.16 295 / 0.28);
  --violet-bg:    oklch(0.71 0.16 295 / 0.07);
  --violet-bg-2:  oklch(0.71 0.16 295 / 0.13);
}
.ai-root[data-violet="glow"] {
  --violet-glow:   oklch(0.71 0.16 295 / 0.45);
  --violet-glow-2: oklch(0.71 0.16 295 / 0.75);
  --violet-bg:    oklch(0.71 0.16 295 / 0.18);
  --violet-bg-2:  oklch(0.71 0.16 295 / 0.28);
}

/* ── Reset inside root ──────────────────────────── */
.ai-root, .ai-root * { box-sizing: border-box; }
.ai-root button { font: inherit; color: inherit; background: none; border: 0; cursor: default; padding: 0; }
.ai-root input, .ai-root textarea, .ai-root select { font: inherit; color: inherit; background: none; border: 0; outline: none; }

/* Premium = invisible scrollbars everywhere inside the app */
.ai-root, .ai-root * { scrollbar-width: none; -ms-overflow-style: none; }
.ai-root *::-webkit-scrollbar { display: none; width: 0; height: 0; }

/* =================================================================
   Layout — desktop shell
   ================================================================= */
.ai-shell { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.ai-topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, oklch(0.17 0.005 60) 0%, oklch(0.16 0.005 60) 100%);
  flex: 0 0 auto;
}
.ai-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; font-size: 14px; letter-spacing: -0.01em;
}
.ai-brand-dot {
  width: 22px; height: 22px; border-radius: var(--r-sm);
  background: linear-gradient(140deg, var(--violet) 0%, oklch(0.55 0.14 285) 100%);
  box-shadow: 0 0 16px var(--violet-glow);
  position: relative; flex: 0 0 auto;
}
.ai-brand-dot::after {
  content: ""; position: absolute; inset: 5px; border-radius: 4px;
  background: oklch(0.12 0.005 60); opacity: 0.85;
  clip-path: polygon(35% 25%, 35% 75%, 75% 50%);
}
.ai-brand-name { color: var(--text); }
.ai-brand-tag {
  font-size: 11px; color: var(--text-muted); font-weight: 500;
  padding: 2px 7px; border-radius: var(--r-pill);
  background: var(--bg-elev); border: 1px solid var(--border);
}

.ai-topbar-spacer { flex: 1; }

.ai-topbar-actions { display: flex; align-items: center; gap: 10px; }

.ai-balance-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px 7px 10px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font-size: 12.5px; font-weight: 500;
}
.ai-balance-chip .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: oklch(0.78 0.11 145);
  box-shadow: 0 0 8px oklch(0.78 0.11 145 / 0.5);
}
.ai-balance-chip .val { font-family: var(--font-mono); color: var(--text); }
.ai-balance-chip .unit { color: var(--text-muted); font-size: 11px; }

.ai-icon-btn {
  width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r); background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-soft); transition: all .15s ease;
}
.ai-icon-btn:hover { background: var(--bg-hover); border-color: var(--border-strong); color: var(--text); }
.ai-icon-btn[data-on="true"] {
  background: var(--violet-bg);
  border-color: oklch(0.71 0.16 295 / 0.4);
  color: var(--violet);
}

.ai-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, oklch(0.55 0.07 50), oklch(0.32 0.04 40));
  border: 1px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: var(--text);
}

/* ── Main body ──────────────────────────────────── */
.ai-body { flex: 1; display: grid; grid-template-columns: minmax(0,1fr) 380px; min-height: 0; }
.ai-body[data-cols="single"] { grid-template-columns: minmax(0,1fr); }

.ai-editor { padding: 24px 28px; overflow-y: auto; }
.ai-history { border-left: 1px solid var(--border); background: oklch(0.155 0.005 60); padding: 18px 18px 22px; overflow-y: auto; }

/* =================================================================
   Editor — model row, mode tabs, fields
   ================================================================= */
.ai-section { display: flex; flex-direction: column; gap: var(--gap); }

.ai-section + .ai-section { margin-top: 18px; }

.ai-row-h { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ai-row-h-tight { display: flex; align-items: center; gap: 8px; }

.ai-eyebrow {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.10em; color: var(--text-dim);
}

/* Model select pill */
.ai-model-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px;
}
.ai-model-select {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 9px 12px 9px 14px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r);
  transition: all .15s ease;
}
.ai-model-select:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.ai-model-select .name { font-weight: 600; font-size: 13.5px; }
.ai-model-select .sub  { font-size: 11.5px; color: var(--text-muted); }
.ai-model-select .chev { color: var(--text-muted); margin-left: 4px; }

.ai-headline { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.ai-subhead { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ── Mode tabs (Text / Image / Multi-ref) ───── */
.ai-tabs {
  display: inline-flex; padding: 4px 6px; gap: 18px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: var(--r);
}
.ai-tab {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 12px;
  font-size: 13px; font-weight: 500; color: var(--text-muted);
  border-radius: calc(var(--r) - 4px);
  transition: all .15s ease;
  white-space: nowrap;
}
.ai-tab .glyph { order: -1; opacity: 0.85; flex: 0 0 auto; }
.ai-tab:hover { color: var(--text-soft); }
.ai-tab[data-on="true"] {
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: 0 1px 0 oklch(1 0 0 / 0.04) inset, 0 0 0 1px var(--border);
}
.ai-tab[data-on="true"] .glyph { color: var(--violet); opacity: 1; }

/* ── Field shells ───────────────────────────── */
.ai-field {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.ai-field:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 4px var(--violet-bg), 0 0 24px -8px var(--violet-glow);
}

.ai-prompt {
  display: flex; flex-direction: column;
  padding: 14px 16px 12px;
  gap: 10px;
}
.ai-prompt textarea {
  resize: none; min-height: 84px; font-size: 15px; line-height: 1.5;
  color: var(--text);
  font-family: var(--font);
}
.ai-prompt textarea::placeholder { color: var(--text-dim); }

.ai-prompt-footer {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
}
.ai-prompt-footer .count {
  margin-left: auto;
  font-size: 11.5px; color: var(--text-muted);
  font-family: var(--font-mono);
}
.ai-prompt-footer .count[data-warn="yes"] { color: var(--status-warn); }

/* ── Param chips (resolution / aspect / duration) ─ */
.ai-paramgrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.ai-paramcard {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 12px 14px 14px;
}
.ai-paramcard-head {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: 11px; color: var(--text-muted); font-weight: 500;
  letter-spacing: 0.04em; text-transform: uppercase;
  margin-bottom: 8px;
}
.ai-paramcard-head .hint { text-transform: none; letter-spacing: 0; color: var(--text-dim); font-family: var(--font-mono); }

.ai-seg {
  display: inline-flex; flex-wrap: wrap; gap: 4px;
  padding: 3px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: var(--r);
  width: 100%;
}
.ai-seg button {
  flex: 1 1 auto; min-width: 0;
  padding: 7px 10px;
  font-size: 12.5px; font-weight: 500; color: var(--text-muted);
  border-radius: calc(var(--r) - 4px);
  transition: all .12s ease;
  font-family: var(--font-mono);
  letter-spacing: 0.01em;
}
.ai-seg button:hover { color: var(--text); background: oklch(0.25 0.007 60 / 0.5); }
.ai-seg button[data-on="true"] {
  background: var(--bg-elev); color: var(--text);
  box-shadow: 0 1px 0 oklch(1 0 0 / 0.05) inset, 0 0 0 1px var(--border-strong);
}

/* Aspect ratio mini-icons */
.ai-aspect {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
}
.ai-aspect button {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 8px 4px;
  border-radius: var(--r-sm);
  background: var(--bg-soft); border: 1px solid var(--border);
  transition: all .12s ease;
}
.ai-aspect button:hover { background: var(--bg-elev); border-color: var(--border-strong); }
.ai-aspect button[data-on="true"] {
  background: var(--bg-elev);
  border-color: oklch(0.71 0.16 295 / 0.45);
  box-shadow: 0 0 0 1px oklch(0.71 0.16 295 / 0.3) inset;
}
.ai-aspect .ratio-glyph {
  background: oklch(0.30 0.007 60);
  border-radius: 3px;
}
.ai-aspect button[data-on="true"] .ratio-glyph { background: var(--violet); box-shadow: 0 0 10px var(--violet-glow); }
.ai-aspect .ratio-label {
  font-size: 11px; font-family: var(--font-mono); color: var(--text-muted);
}
.ai-aspect button[data-on="true"] .ratio-label { color: var(--text); }

/* ── Sound toggle ───────────────────────────── */
.ai-toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 12px 16px;
}
.ai-toggle-row .label { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.ai-toggle-row .label .glyph { color: var(--text-muted); width: 16px; }
.ai-toggle-row .sublabel { font-size: 11.5px; color: var(--text-muted); }

.ai-switch {
  width: 34px; height: 20px; border-radius: 999px;
  background: var(--bg-elev); border: 1px solid var(--border-strong);
  position: relative; transition: all .18s ease;
}
.ai-switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--text-soft); transition: all .2s cubic-bezier(.2,.7,.3,1);
}
.ai-switch[data-on="true"] {
  background: var(--violet-bg-2);
  border-color: oklch(0.71 0.16 295 / 0.5);
  box-shadow: 0 0 12px var(--violet-glow);
}
.ai-switch[data-on="true"]::after { left: 16px; background: var(--violet); }

/* ── Advanced disclosure ────────────────────── */
.ai-advanced {
  margin-top: 4px;
  border-top: 1px dashed var(--border);
  padding-top: 14px;
}
.ai-advanced-trig {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--text-muted); font-weight: 500;
  padding: 4px 8px; margin-left: -8px; border-radius: var(--r-sm);
  transition: all .12s ease;
}
.ai-advanced-trig:hover { color: var(--text); background: var(--bg-soft); }
.ai-advanced-trig .chev { transition: transform .2s ease; }
.ai-advanced[data-open="true"] .ai-advanced-trig .chev { transform: rotate(90deg); }

/* ── Seed row ───────────────────────────────── */
.ai-seed {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 6px 6px 6px 14px;
}
.ai-seed .lbl { font-size: 11.5px; color: var(--text-muted); }
.ai-seed input {
  flex: 1; font-family: var(--font-mono); font-size: 13px;
  padding: 5px 0;
}
.ai-seed .dice {
  width: 28px; height: 28px; border-radius: var(--r-sm);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-elev); border: 1px solid var(--border);
  color: var(--text-soft);
  transition: all .12s ease;
}
.ai-seed .dice:hover { color: var(--violet); border-color: oklch(0.71 0.16 295 / 0.4); }

/* =================================================================
   Buttons
   ================================================================= */
.ai-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 14px;
  font-size: 13px; font-weight: 500;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-soft);
  transition: all .15s ease;
  white-space: nowrap;
  position: relative;
}
.ai-btn:hover { background: var(--bg-hover); border-color: var(--border-strong); color: var(--text); }
.ai-btn[data-size="sm"] { padding: 6px 10px; font-size: 12px; border-radius: var(--r-sm); }

.ai-btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.ai-btn-ghost:hover { background: var(--bg-soft); color: var(--text); border-color: var(--border); }

.ai-btn-violet {
  background: var(--violet-bg);
  border-color: oklch(0.71 0.16 295 / 0.35);
  color: oklch(0.85 0.10 295);
}
.ai-btn-violet:hover {
  background: var(--violet-bg-2);
  border-color: oklch(0.71 0.16 295 / 0.55);
  color: oklch(0.92 0.08 295);
}

/* Primary CTA — the only thing with a real glow */
.ai-cta {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px 22px;
  font-size: 15px; font-weight: 600; letter-spacing: -0.005em;
  border-radius: var(--r);
  background: linear-gradient(180deg,
    oklch(0.74 0.16 295) 0%,
    oklch(0.62 0.16 295) 100%);
  color: white;
  box-shadow:
    0 0 0 1px oklch(0.81 0.13 295 / 0.5) inset,
    0 1px 0 oklch(1 0 0 / 0.22) inset,
    0 0 28px var(--violet-glow),
    0 8px 22px -10px var(--violet-glow-2);
  transition: all .18s ease;
  position: relative;
  width: 100%;
}
.ai-cta:hover {
  box-shadow:
    0 0 0 1px oklch(0.84 0.13 295 / 0.6) inset,
    0 1px 0 oklch(1 0 0 / 0.28) inset,
    0 0 40px var(--violet-glow),
    0 10px 26px -10px var(--violet-glow-2);
  transform: translateY(-0.5px);
}
.ai-cta:active { transform: translateY(0.5px); }
.ai-cta[disabled], .ai-cta[data-state="disabled"] {
  background: var(--bg-elev);
  color: var(--text-dim);
  box-shadow: 0 0 0 1px var(--border) inset;
  cursor: not-allowed;
}
.ai-cta[data-state="loading"] {
  background: linear-gradient(180deg,
    oklch(0.50 0.13 295) 0%,
    oklch(0.42 0.12 295) 100%);
  color: oklch(0.92 0.05 295);
}
.ai-cta[data-state="loading"] .ai-spinner { animation: ai-spin 0.8s linear infinite; }
.ai-cta-chip {
  font-family: var(--font-mono); font-size: 12px; font-weight: 500;
  padding: 3px 8px; border-radius: var(--r-pill);
  background: oklch(0 0 0 / 0.22);
  color: oklch(1 0 0 / 0.85);
}

.ai-spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid oklch(1 0 0 / 0.25);
  border-top-color: white;
  animation: ai-spin 0.8s linear infinite;
}
@keyframes ai-spin { to { transform: rotate(360deg); } }

/* ── Helper hover-only utility class ─────────── */
.ai-error {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: oklch(0.70 0.18 25 / 0.10);
  border: 1px solid oklch(0.70 0.18 25 / 0.35);
  color: oklch(0.85 0.12 25);
  border-radius: var(--r);
  font-size: 12.5px;
}

/* =================================================================
   Refs carousel
   ================================================================= */
.ai-refs {
  display: flex; flex-direction: column; gap: 10px;
}
.ai-refs-row {
  display: flex; gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}
.ai-refs-row::-webkit-scrollbar { height: 6px; }
.ai-refs-row::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* Mobile: 3-col grid wrap so all 9 fit without horizontal scroll */
.ai-refs-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.ai-refs-grid .ai-ref,
.ai-refs-grid .ai-ref-slot {
  flex: initial;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
}

.ai-ref {
  position: relative;
  flex: 0 0 96px; height: 96px;
  border-radius: var(--r);
  background: var(--bg-card);
  border: 1px solid var(--border);
  overflow: hidden;
}
.ai-ref-thumb {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
}
.ai-ref-badge {
  position: absolute; top: 6px; left: 6px;
  padding: 2px 6px;
  background: oklch(0 0 0 / 0.65);
  backdrop-filter: blur(6px);
  border-radius: var(--r-xs);
  font-size: 10px; font-weight: 600; color: white;
  display: inline-flex; align-items: center; gap: 4px;
  letter-spacing: 0.02em;
  font-family: var(--font-mono);
}
.ai-ref-badge.role-1 { background: oklch(0.71 0.16 295 / 0.85); }
.ai-ref-badge.role-2 { background: oklch(0.78 0.11 145 / 0.85); }
.ai-ref-badge.role-img { background: oklch(0 0 0 / 0.65); }
.ai-ref-badge.role-vid { background: oklch(0.74 0.06 235 / 0.85); }
.ai-ref-badge.role-aud { background: oklch(0.80 0.13 80 / 0.85); }
.ai-ref-x {
  position: absolute; top: 6px; right: 6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: oklch(0 0 0 / 0.6);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 11px;
  opacity: 0; transition: opacity .12s ease;
}
.ai-ref:hover .ai-ref-x { opacity: 1; }

/* Drop slot variants */
.ai-ref-slot {
  flex: 0 0 96px; height: 96px;
  border-radius: var(--r);
  border: 1.5px dashed var(--border-strong);
  background: var(--bg-soft);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 11.5px;
  transition: all .15s ease;
  position: relative;
}
.ai-ref-slot:hover {
  border-color: oklch(0.71 0.16 295 / 0.5);
  color: var(--violet);
  background: var(--violet-bg);
}
.ai-ref-slot[data-active="true"] {
  border-style: solid; border-color: var(--violet);
  background: var(--violet-bg-2);
  color: var(--violet);
  box-shadow: 0 0 0 4px var(--violet-bg), 0 0 24px var(--violet-glow);
}
.ai-ref-slot[data-disabled="true"] {
  opacity: 0.45; cursor: not-allowed;
}
.ai-ref-slot .pos {
  position: absolute; top: 6px; left: 6px;
  font-family: var(--font-mono); font-size: 10px; font-weight: 600;
  color: var(--text-muted);
}
.ai-ref-slot .icon { font-size: 22px; line-height: 1; }
.ai-ref-slot .hint { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.04em; text-transform: uppercase; }

/* Big multi-ref dropzone */
.ai-dropzone {
  border: 1.5px dashed var(--border-strong);
  background: var(--bg-soft);
  border-radius: var(--r-lg);
  padding: 20px;
  display: flex; align-items: center; gap: 16px;
  transition: all .15s ease;
}
.ai-dropzone:hover {
  border-color: oklch(0.71 0.16 295 / 0.4);
  background: var(--violet-bg);
}
.ai-dropzone[data-active="true"] {
  border-color: var(--violet);
  background: var(--violet-bg-2);
  box-shadow: 0 0 0 4px var(--violet-bg), 0 0 32px var(--violet-glow);
}
.ai-dropzone .dz-icon {
  width: 42px; height: 42px; border-radius: var(--r);
  background: var(--bg-elev); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 20px;
  flex: 0 0 auto;
}
.ai-dropzone[data-active="true"] .dz-icon {
  background: var(--violet-bg-2); color: var(--violet); border-color: oklch(0.71 0.16 295 / 0.5);
}
.ai-dropzone .dz-title { font-size: 14px; font-weight: 500; color: var(--text); margin-bottom: 2px; }
.ai-dropzone .dz-sub { font-size: 12px; color: var(--text-muted); }
.ai-dropzone .dz-counts { margin-left: auto; display: flex; gap: 14px; }
.ai-dropzone .dz-count {
  display: flex; flex-direction: column; align-items: flex-end;
  font-size: 11px; color: var(--text-muted);
}
.ai-dropzone .dz-count .num {
  font-family: var(--font-mono); font-size: 14px; color: var(--text);
}
.ai-dropzone .dz-count .num .max { color: var(--text-dim); }

/* Mobile variant: centred, taller, big upload glyph */
.ai-dropzone[data-mobile="true"] {
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 22px 18px;
  gap: 10px;
}
.ai-dropzone[data-mobile="true"] .dz-icon {
  width: 52px; height: 52px;
  border-radius: var(--r-lg);
}
.ai-dropzone[data-mobile="true"] .dz-title { font-size: 14.5px; font-weight: 500; }
.ai-dropzone[data-mobile="true"] .dz-sub {
  font-family: var(--font-mono); font-size: 11px;
  letter-spacing: 0.04em;
}

/* =================================================================
   Cost bar (balance left · price right)
   ================================================================= */
.ai-costbar {
  display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-lg);
  position: relative;
  overflow: hidden;
}
.ai-costbar::before {
  /* faint violet wash on the right */
  content: ""; position: absolute; right: -20%; top: -50%; width: 60%; height: 200%;
  background: radial-gradient(circle, var(--violet-glow) 0%, transparent 60%);
  pointer-events: none; opacity: 0.5;
}
.ai-costbar > * { position: relative; }

.ai-costbar .col { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ai-costbar .col.right { align-items: flex-end; }
.ai-costbar .lbl {
  font-size: 10.5px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.08em; font-weight: 500;
}
.ai-costbar .val { display: inline-flex; align-items: baseline; gap: 5px; }
.ai-costbar .val .num { font-family: var(--font-mono); font-size: 18px; font-weight: 500; color: var(--text); letter-spacing: -0.01em; }
.ai-costbar .val .num.minus { color: var(--violet); }
.ai-costbar .val .unit { font-size: 11px; color: var(--text-muted); }

.ai-costbar .arrow {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--bg-elev); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 11px;
}

/* Demo-mode masks */
.ai-mask { position: relative; }
.ai-mask[data-demo="true"] .ai-money { color: transparent; }
.ai-mask[data-demo="true"] .ai-money::after {
  content: ""; position: absolute; inset: 4px 0;
  background: var(--bg-elev);
  border-radius: 4px;
  background-image: linear-gradient(135deg,
    var(--bg-elev) 0%, var(--bg-elev) 49%,
    var(--border) 49%, var(--border) 51%,
    var(--bg-elev) 51%, var(--bg-elev) 100%);
  background-size: 6px 6px;
}

/* =================================================================
   History column
   ================================================================= */
.ai-history-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 6px 6px 14px;
}
.ai-history-head .title { font-size: 13.5px; font-weight: 600; letter-spacing: -0.005em; }
.ai-history-head .count { font-size: 11.5px; color: var(--text-muted); font-family: var(--font-mono); }
.ai-history-head .filter {
  font-size: 11.5px; color: var(--text-muted);
  padding: 4px 8px; border-radius: var(--r-sm);
}
.ai-history-head .filter:hover { background: var(--bg-soft); color: var(--text); }

.ai-history-list { display: flex; flex-direction: column; gap: 14px; }

/* =================================================================
   Video card (history item)
   ================================================================= */
.ai-vidcard {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: all .2s ease;
  position: relative;
}
.ai-vidcard:hover {
  border-color: oklch(0.71 0.16 295 / 0.35);
  box-shadow: 0 0 0 1px oklch(0.71 0.16 295 / 0.2),
              0 0 32px -8px var(--violet-glow),
              0 16px 40px -22px oklch(0 0 0 / 0.6);
  transform: translateY(-1px);
}

.ai-vidcard .video {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: oklch(0.10 0.005 60);
  overflow: hidden;
}
.ai-vidcard[data-aspect="9:16"] .video { aspect-ratio: 9 / 16; }
.ai-vidcard[data-aspect="1:1"] .video { aspect-ratio: 1 / 1; }
.ai-vidcard[data-aspect="21:9"] .video { aspect-ratio: 21 / 9; }

.ai-vidcard .video-img {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
}
.ai-vidcard .video-img::after {
  /* Subtle vignette to lift overlay controls */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 60%, oklch(0 0 0 / 0.55) 100%);
}

.ai-vidcard .video-top {
  position: absolute; top: 10px; left: 10px; right: 10px;
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 8px; z-index: 2;
}

/* Status pip */
.ai-status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px 4px 7px;
  background: oklch(0 0 0 / 0.55);
  backdrop-filter: blur(8px);
  border-radius: var(--r-pill);
  font-size: 11px; font-weight: 500;
  color: white;
  letter-spacing: 0.02em;
}
.ai-status .pip {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}
.ai-status[data-status="queued"]    { color: var(--status-queued); }
.ai-status[data-status="running"]   { color: var(--status-running); }
.ai-status[data-status="succeeded"] { color: var(--status-succeeded); }
.ai-status[data-status="failed"]    { color: var(--status-failed); }
.ai-status[data-status="running"] .pip { animation: ai-pip 1.4s ease-in-out infinite; box-shadow: 0 0 8px currentColor; }
@keyframes ai-pip { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:0.35;transform:scale(0.85)} }
.ai-status[data-status="queued"] .pip { animation: ai-pip 2s ease-in-out infinite; }
.ai-status[data-status="succeeded"] .pip { box-shadow: 0 0 6px currentColor; }

.ai-vidcard .video-aspect-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 8px;
  background: oklch(0 0 0 / 0.55);
  backdrop-filter: blur(8px);
  border-radius: var(--r-pill);
  font-size: 10.5px; font-weight: 500;
  color: oklch(1 0 0 / 0.85);
  font-family: var(--font-mono);
}

/* Centre play button */
.ai-vidcard .video-play {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 52px; height: 52px;
  border-radius: 50%;
  background: oklch(0 0 0 / 0.55);
  backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  color: white;
  border: 1px solid oklch(1 0 0 / 0.18);
  opacity: 0; transition: all .22s ease;
  z-index: 2;
}
.ai-vidcard:hover .video-play { opacity: 1; }
.ai-vidcard .video-play .tri {
  width: 0; height: 0;
  border-left: 12px solid white;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  margin-left: 3px;
}

/* Bottom-overlay controls */
.ai-vidcard .video-controls {
  position: absolute; left: 12px; right: 12px; bottom: 10px;
  display: flex; align-items: center; gap: 10px;
  z-index: 2;
  opacity: 0; transition: opacity .2s ease;
}
.ai-vidcard:hover .video-controls,
.ai-vidcard.always-controls .video-controls { opacity: 1; }
.ai-vidcard .video-time {
  font-size: 11px; font-family: var(--font-mono);
  color: oklch(1 0 0 / 0.85);
  background: oklch(0 0 0 / 0.45);
  backdrop-filter: blur(6px);
  padding: 2px 7px; border-radius: var(--r-xs);
}
.ai-vidcard .video-progress {
  flex: 1; height: 3px; border-radius: 999px;
  background: oklch(1 0 0 / 0.18);
  overflow: hidden;
}
.ai-vidcard .video-progress .fill {
  height: 100%; background: var(--violet);
  box-shadow: 0 0 8px var(--violet-glow);
}
.ai-vidcard .video-iconbtn {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: oklch(0 0 0 / 0.45);
  backdrop-filter: blur(6px);
  color: white;
  font-size: 12px;
}

/* Meta row beneath video */
.ai-vidcard .meta {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 8px;
}
.ai-vidcard .meta .prompt {
  flex: 1; min-width: 0;
  font-size: 12.5px; color: var(--text-soft);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.45;
  letter-spacing: -0.005em;
}
.ai-mobile .ai-vidcard .meta .prompt { -webkit-line-clamp: 3; }
.ai-vidcard .meta .rating {
  display: flex; gap: 2px; flex: 0 0 auto;
}
.ai-vidcard .meta .rating button {
  width: 26px; height: 26px; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 13px;
  transition: all .12s ease;
}
.ai-vidcard .meta .rating button:hover { background: var(--bg-elev); color: var(--text); }
.ai-vidcard .meta .rating button[data-on="up"] { color: oklch(0.78 0.11 145); background: oklch(0.78 0.11 145 / 0.12); }
.ai-vidcard .meta .rating button[data-on="down"] { color: oklch(0.70 0.18 25); background: oklch(0.70 0.18 25 / 0.12); }

.ai-vidcard .stats {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 4px 12px 10px;
  font-size: 11px; color: var(--text-muted);
  font-family: var(--font-mono);
}
.ai-vidcard .stats .sep { color: var(--text-dim); }
.ai-vidcard .stats .credit { color: var(--violet); }

.ai-vidcard .actions {
  display: flex; gap: 6px;
  padding: 4px 10px 10px;
}
.ai-vidcard .actions .ai-btn { flex: 1; padding: 7px 10px; font-size: 12px; }

/* =================================================================
   Skeletons
   ================================================================= */
@keyframes ai-shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.ai-sk {
  display: block;
  background: linear-gradient(90deg,
    oklch(0.21 0.007 60) 0%,
    oklch(0.27 0.008 60) 50%,
    oklch(0.21 0.007 60) 100%);
  background-size: 200% 100%;
  animation: ai-shimmer 1.6s ease-in-out infinite;
  border-radius: var(--r-sm);
}
.ai-sk[data-shape="line"] { height: 12px; border-radius: 999px; }
.ai-sk[data-shape="title"] { height: 18px; border-radius: 999px; }
.ai-sk[data-shape="thumb"] { aspect-ratio: 16/9; border-radius: var(--r); }
.ai-sk[data-shape="circle"] { border-radius: 50%; }

/* Generating progress strip (used inside a video tile) */
.ai-gen-tile {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 14px;
  background: linear-gradient(135deg,
    oklch(0.16 0.007 295) 0%,
    oklch(0.13 0.005 60) 100%);
  overflow: hidden;
}
.ai-gen-tile::before {
  /* slow drifting violet wash */
  content: ""; position: absolute; inset: -50%;
  background: radial-gradient(circle, var(--violet-glow) 0%, transparent 50%);
  animation: ai-drift 5s ease-in-out infinite;
}
@keyframes ai-drift {
  0%, 100% { transform: translate(-10%, -10%) scale(1); opacity: 0.5; }
  50%      { transform: translate(15%, 10%)  scale(1.15); opacity: 0.85; }
}
.ai-gen-tile .gen-spinner {
  position: relative;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 2px solid oklch(1 0 0 / 0.08);
  border-top-color: var(--violet);
  animation: ai-spin 1s linear infinite;
  box-shadow: 0 0 24px var(--violet-glow);
}
.ai-gen-tile .gen-text {
  position: relative;
  font-size: 12.5px; font-weight: 500;
  color: oklch(0.92 0.05 295);
  letter-spacing: 0.02em;
  font-family: var(--font-mono);
}
.ai-gen-tile .gen-prog {
  position: relative;
  width: 60%; height: 2px; border-radius: 999px;
  background: oklch(1 0 0 / 0.08);
  overflow: hidden;
}
.ai-gen-tile .gen-prog .bar {
  height: 100%; width: 38%;
  background: linear-gradient(90deg, transparent, var(--violet), transparent);
  animation: ai-bar 1.6s ease-in-out infinite;
}
@keyframes ai-bar {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(280%); }
}

/* =================================================================
   Mobile shell
   ================================================================= */
.ai-mobile {
  height: 100%;
  display: flex; flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}
.ai-mobile-top {
  padding: 14px 16px 10px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border);
  background: oklch(0.16 0.005 60);
  flex: 0 0 auto;
}
.ai-mobile-top .title { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.ai-mobile-top .spacer { flex: 1; }

.ai-mobile-scroll {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column;
  gap: 14px;
}

.ai-mobile-stickybar {
  flex: 0 0 auto;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, oklch(0.16 0.005 60 / 0) 0%, oklch(0.15 0.005 60) 30%);
  display: flex; flex-direction: column; gap: 8px;
  border-top: 1px solid var(--border);
}

.ai-tabbar {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  border-top: 1px solid var(--border);
  background: oklch(0.155 0.005 60);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
  flex: 0 0 auto;
}
.ai-tabbar .tab {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 6px 4px 4px;
  color: var(--text-dim); font-size: 10.5px;
  border-radius: var(--r-sm);
  font-weight: 500;
}
.ai-tabbar .tab[data-on="true"] { color: var(--violet); }
.ai-tabbar .tab .glyph { font-size: 18px; }

/* Mobile param grid is 1-column friendly */
.ai-mobile .ai-paramgrid { grid-template-columns: 1fr 1fr; }

/* Mobile mode tabs become full-width segmented */
.ai-mobile .ai-tabs { display: grid; grid-template-columns: 1fr 1fr 1fr; width: 100%; }

/* Touch targets — bigger on mobile */
.ai-mobile .ai-btn { min-height: 38px; padding: 10px 14px; font-size: 13.5px; }
.ai-mobile .ai-seg button { padding: 10px 8px; min-height: 38px; font-size: 13px; }
.ai-mobile textarea { font-size: 16px; }  /* prevent iOS zoom */
.ai-mobile .ai-prompt textarea { min-height: 100px; }
.ai-mobile .ai-cta { padding: 14px 16px; font-size: 15px; }

/* Mobile cards stack tighter */
.ai-mobile .ai-history-list { gap: 18px; }
.ai-mobile .ai-vidcard .actions .ai-btn { font-size: 12.5px; }

/* =================================================================
   Frames (artboard wrappers)
   ================================================================= */
.frame { display: block; }
.frame-mobile { width: 100%; height: 100%; }

/* Icon stroke style.
   Sizing comes from the SVG's own width/height attributes (set in Icon),
   so it survives the host instrumenter overwriting className.
   We only style stroke/fill here — and rely on a baseline width fallback
   for SVGs without an explicit width attribute. */
.ai-root svg {
  flex: 0 0 auto;
  stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
  display: inline-block; vertical-align: -2px;
}
.ai-root svg:not([width]) { width: 14px; height: 14px; }
.ai-root svg path, .ai-root svg rect, .ai-root svg circle,
.ai-root svg polygon, .ai-root svg polyline, .ai-root svg line {
  fill: none;
  stroke: currentColor;
}
.ai-root svg [fill]:not([fill="none"]) {
  fill: currentColor;
  stroke: none;
}

/* Drag ghost — neutral dark file pill, violet outline, soft shadow.
   Reads as "you're holding a file", never as a warning. */
.ai-drag-ghost {
  position: absolute;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px 8px 8px;
  min-width: 168px;
  background: oklch(0.21 0.006 60);
  border: 1px solid oklch(0.71 0.16 295 / 0.55);
  border-radius: var(--r);
  box-shadow:
    0 0 0 4px var(--violet-bg),
    0 14px 36px -8px oklch(0 0 0 / 0.55),
    0 0 24px -6px var(--violet-glow);
  color: var(--text);
  opacity: 0.92;
  z-index: 3;
  pointer-events: none;
}
.ai-drag-ghost .ghost-thumb {
  width: 36px; height: 36px;
  border-radius: var(--r-sm);
  background: oklch(0.27 0.007 60);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--violet);
  flex: 0 0 auto;
}
.ai-drag-ghost .ghost-meta {
  display: flex; flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}
.ai-drag-ghost .ghost-name {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 140px;
}
.ai-drag-ghost .ghost-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
}
/* Pointer "tail" — left or right side */
.ai-drag-ghost .ghost-cursor {
  position: absolute;
  width: 16px; height: 22px;
  background: white;
  filter: drop-shadow(0 2px 3px oklch(0 0 0 / 0.5));
}
.ai-drag-ghost .ghost-cursor.right {
  bottom: -14px; right: -8px;
  clip-path: polygon(0 0, 0 76%, 28% 58%, 50% 100%, 65% 92%, 48% 56%, 100% 56%);
}
.ai-drag-ghost .ghost-cursor.left {
  bottom: -14px; left: -8px;
  clip-path: polygon(100% 0, 100% 76%, 72% 58%, 50% 100%, 35% 92%, 52% 56%, 0 56%);
}

