/* ═══════════════════════════════════════════════════════════════════════════
   AI Gen Studio — Design System  "Clay"
   Claude-warm palette + Apple structural language.
   Two visuals: [data-theme="light"] (bone) and [data-theme="dark"] (graphite).
   Legacy token aliases (--glass, --line, --red-grad …) are mapped per-theme so
   existing markup keeps working while the look changes completely.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Shared, theme-independent ───────────────────────────────────────────── */
:root {
  /* radii */
  --r-xs: 6px;  --r-sm: 8px;  --r-md: 10px;  --r-lg: 14px;  --r-xl: 20px;
  --r: 14px;    --rs: 10px;             /* legacy */

  /* spacing scale */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px;
  --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-7: 32px;

  /* type scale */
  --fs-xs: 11px; --fs-sm: 12px; --fs-md: 13px; --fs-base: 13.5px; --fs-lg: 15px; --fs-xl: 18px;
  --ff: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', 'Inter', 'Helvetica Neue', sans-serif;
  --ff-mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, monospace;

  /* motion */
  --ease: cubic-bezier(.2, .8, .3, 1);
  --dur: .18s;

  /* layout */
  --bottom-h: 268px;
  --topbar-h: 52px;
  --tabstrip-h: 40px;
}

/* ── Theme: Light "Bone" (Claude) ────────────────────────────────────────── */
:root, [data-theme="light"] {
  color-scheme: light;

  --bg:         #FAF9F5;
  --bg-tint:    #F3F1E9;
  --surface:    #FFFFFF;
  --surface-2:  #F5F3EC;
  --surface-3:  #EBE8DE;
  --surface-4:  #E0DCD0;

  --border:     rgba(34, 31, 26, .10);
  --border-2:   rgba(34, 31, 26, .16);
  --border-3:   rgba(34, 31, 26, .24);

  --text:       #1F1D1A;
  --text-2:     #57534A;
  --text-3:     #86827A;
  --text-4:     #A8A49B;

  --accent:     #C05F3C;
  --accent-2:   #A94D2D;
  --accent-3:   #D97757;
  --accent-fg:  #FFFFFF;
  --accent-soft:   rgba(192, 95, 60, .10);
  --accent-soft-2: rgba(192, 95, 60, .18);
  --accent-border: rgba(192, 95, 60, .34);
  --accent-ring:   rgba(192, 95, 60, .26);

  --green:  #2C8A52;  --green-soft:  rgba(44,138,82,.12);  --green-border: rgba(44,138,82,.30);
  --amber:  #B27411;  --amber-soft:  rgba(178,116,17,.12); --amber-border: rgba(178,116,17,.30);
  --red:    #C0392B;  --red-soft:    rgba(192,57,43,.10);  --red-border:   rgba(192,57,43,.30);
  --blue:   #2F6FBF;  --blue-soft:   rgba(47,111,191,.10);

  --sh-1: 0 1px 2px rgba(31,28,24,.06), 0 1px 1px rgba(31,28,24,.04);
  --sh-2: 0 2px 6px rgba(31,28,24,.07), 0 1px 2px rgba(31,28,24,.05);
  --sh-3: 0 8px 24px rgba(31,28,24,.10), 0 2px 6px rgba(31,28,24,.06);
  --sh-4: 0 24px 60px rgba(31,28,24,.18), 0 6px 16px rgba(31,28,24,.10);
  --sh-inset: inset 0 1px 0 rgba(255,255,255,.7);

  --scrim: rgba(250,249,245,.72);

  /* ── legacy aliases ── */
  --glass:        rgba(34,31,26,.028);
  --glass-2:      rgba(34,31,26,.045);
  --glass-3:      rgba(34,31,26,.06);
  --glass-strong: rgba(34,31,26,.09);
  --glass-white:  #FFFFFF;
  --line:   var(--border);
  --line-2: var(--border-2);
  --muted:   var(--text-3);
  --muted-2: var(--text-3);
  --label:   var(--text-3);
  --dark:    var(--text);
  --bg-3:    var(--surface-2);
  --amber-l: var(--amber);
  --accent-l: var(--accent-2);
  --pink: var(--accent); --pink-l: var(--accent-2);
  --red-2: var(--red); --danger: var(--red);
  --glow: none; --glow-s: none;
  --blur: blur(20px) saturate(1.5);
  --accent-grad: linear-gradient(180deg, var(--accent-3), var(--accent));
  --accent-shadow: 0 1px 2px rgba(120,50,25,.25), inset 0 1px 0 rgba(255,255,255,.22);
  --red-grad: var(--accent-grad);
  --red-shadow: var(--accent-shadow);
}

/* ── Theme: Dark "Graphite" ──────────────────────────────────────────────── */
[data-theme="dark"] {
  color-scheme: dark;

  --bg:         #171614;
  --bg-tint:    #1C1B18;
  --surface:    #201F1C;
  --surface-2:  #282622;
  --surface-3:  #322F2B;
  --surface-4:  #3D3A35;

  --border:     rgba(255, 252, 245, .09);
  --border-2:   rgba(255, 252, 245, .15);
  --border-3:   rgba(255, 252, 245, .22);

  --text:       #F3F1EB;
  --text-2:     #ADA99F;
  --text-3:     #837F76;
  --text-4:     #66625B;

  --accent:     #D97757;
  --accent-2:   #E08D71;
  --accent-3:   #C6613F;
  --accent-fg:  #201008;
  --accent-soft:   rgba(217, 119, 87, .13);
  --accent-soft-2: rgba(217, 119, 87, .22);
  --accent-border: rgba(217, 119, 87, .38);
  --accent-ring:   rgba(217, 119, 87, .30);

  --green:  #3FBF6B;  --green-soft:  rgba(63,191,107,.14);  --green-border: rgba(63,191,107,.34);
  --amber:  #E0A33F;  --amber-soft:  rgba(224,163,63,.14);  --amber-border: rgba(224,163,63,.34);
  --red:    #E5695B;  --red-soft:    rgba(229,105,91,.13);  --red-border:   rgba(229,105,91,.34);
  --blue:   #6BA3E8;  --blue-soft:   rgba(107,163,232,.13);

  --sh-1: 0 1px 2px rgba(0,0,0,.4);
  --sh-2: 0 2px 8px rgba(0,0,0,.45);
  --sh-3: 0 10px 28px rgba(0,0,0,.5), 0 2px 6px rgba(0,0,0,.35);
  --sh-4: 0 28px 70px rgba(0,0,0,.66), 0 8px 20px rgba(0,0,0,.45);
  --sh-inset: inset 0 1px 0 rgba(255,255,255,.05);

  --scrim: rgba(18,17,15,.74);

  /* ── legacy aliases ── */
  --glass:        rgba(255,252,245,.035);
  --glass-2:      rgba(255,252,245,.055);
  --glass-3:      rgba(255,252,245,.08);
  --glass-strong: rgba(255,252,245,.12);
  --glass-white:  #F3F1EB;
  --line:   var(--border);
  --line-2: var(--border-2);
  --muted:   var(--text-3);
  --muted-2: var(--text-3);
  --label:   var(--text-3);
  --dark:    #171614;
  --bg-3:    var(--surface-2);
  --amber-l: var(--amber);
  --accent-l: var(--accent-2);
  --pink: var(--accent); --pink-l: var(--accent-2);
  --red-2: var(--red); --danger: var(--red);
  --glow: none; --glow-s: none;
  --blur: blur(20px) saturate(1.4);
  --accent-grad: linear-gradient(180deg, var(--accent-2), var(--accent-3));
  --accent-shadow: 0 1px 2px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.14);
  --red-grad: var(--accent-grad);
  --red-shadow: var(--accent-shadow);
}

/* ── Base ────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: var(--fs-base)/1.45 var(--ff);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -.006em;
  user-select: none;
  transition: background .25s var(--ease), color .25s var(--ease);
}
textarea, input { user-select: text; letter-spacing: 0; }
::selection { background: var(--accent-soft-2); }

/* Scrollbars — thin, unobtrusive, theme-aware */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-2); border-radius: 6px;
  border: 3px solid transparent; background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--border-3); background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }

/* ── Typography helpers ──────────────────────────────────────────────────── */
.t-label {
  font-size: var(--fs-xs); font-weight: 590; letter-spacing: .045em;
  text-transform: uppercase; color: var(--text-3);
}
.t-mono { font-family: var(--ff-mono); font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }

/* ── Controls ────────────────────────────────────────────────────────────── */
button, select, .btn {
  font: inherit;
  font-size: var(--fs-md);
  font-weight: 540;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  min-height: 34px;
  padding: 0 13px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  box-shadow: var(--sh-1);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              color var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
              transform .1s var(--ease), opacity var(--dur);
  white-space: nowrap;
}
button:hover:not(:disabled), .btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border-3); }
button:active:not(:disabled), .btn:active:not(:disabled) { transform: scale(.978); box-shadow: none; }
button:disabled, .btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }

button.primary, .btn-primary {
  background: var(--accent); border-color: transparent; color: #fff;
  font-weight: 590; box-shadow: var(--sh-1);
}
button.primary:hover:not(:disabled), .btn-primary:hover:not(:disabled) { background: var(--accent-3); border-color: transparent; }
[data-theme="dark"] button.primary, [data-theme="dark"] .btn-primary { color: #23120A; }
[data-theme="dark"] button.primary:hover:not(:disabled) { background: var(--accent-2); }

button.ghost, .btn-ghost {
  background: transparent; border-color: var(--border-2); color: var(--text-2); box-shadow: none;
}
button.ghost:hover:not(:disabled), .btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-quiet { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-quiet:hover:not(:disabled) { background: var(--surface-2); color: var(--text); border-color: transparent; }

.btn-accent-soft {
  background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent); box-shadow: none;
}
.btn-accent-soft:hover:not(:disabled) { background: var(--accent-soft-2); border-color: var(--accent); }

.btn-danger { color: var(--red); border-color: var(--red-border); background: var(--red-soft); box-shadow: none; }
.btn-danger:hover:not(:disabled) { background: var(--red); color: #fff; border-color: transparent; }

.btn-sm { min-height: 28px; padding: 0 10px; font-size: var(--fs-sm); border-radius: var(--r-sm); gap: 5px; }
.btn-xs { min-height: 24px; padding: 0 8px; font-size: var(--fs-xs); border-radius: var(--r-xs); gap: 4px; font-weight: 560; }
.btn-lg { min-height: 42px; padding: 0 20px; font-size: var(--fs-lg); border-radius: var(--r-lg); font-weight: 580; }
.btn-icon { min-height: 30px; width: 30px; padding: 0; }
.btn-block { width: 100%; }

/* Inputs */
textarea, input[type=text], input[type=number], input[type=search], select {
  font: inherit; font-size: var(--fs-md);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  padding: 8px 11px;
  width: 100%;
  box-shadow: var(--sh-1);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur);
}
[data-theme="dark"] textarea, [data-theme="dark"] input[type=text],
[data-theme="dark"] input[type=number], [data-theme="dark"] input[type=search],
[data-theme="dark"] select { background: var(--surface-2); }
textarea { line-height: 1.5; resize: vertical; }
textarea::placeholder, input::placeholder { color: var(--text-4); }
select {
  cursor: pointer; padding-right: 30px; min-height: 34px;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
select option { background: var(--surface); color: var(--text); }

textarea:focus, input:focus, select:focus {
  outline: none; border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
button:focus-visible, .btn:focus-visible, [tabindex]:focus-visible {
  outline: none; box-shadow: 0 0 0 3px var(--accent-ring);
}

input[type=checkbox] {
  appearance: none; -webkit-appearance: none;
  width: 16px; height: 16px; min-width: 16px; border-radius: 5px;
  border: 1.5px solid var(--border-3); background: var(--surface);
  cursor: pointer; position: relative; transition: all var(--dur) var(--ease);
}
input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
input[type=checkbox]:checked::after {
  content: ''; position: absolute; left: 4.5px; top: 1px; width: 4px; height: 8px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(43deg);
}

/* Range slider */
input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 22px;
  background: transparent; cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px; background: var(--surface-3);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%; margin-top: -6px;
  background: var(--surface); border: 1px solid var(--border-3);
  box-shadow: var(--sh-2); transition: transform .12s var(--ease);
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.12); }
input[type=range]:focus { outline: none; }
input[type=range]:focus::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--accent-ring); }

/* ── Segmented control (Apple style) ─────────────────────────────────────── */
.seg {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.seg > button, .seg > .seg-item {
  min-height: 26px; padding: 0 12px; border: none; background: transparent;
  color: var(--text-2); font-size: var(--fs-sm); font-weight: 550;
  border-radius: 7px; box-shadow: none; flex: 1;
}
.seg > button:hover:not(:disabled) { background: transparent; color: var(--text); }
.seg > button.active, .seg > .seg-item.active {
  background: var(--surface); color: var(--text); box-shadow: var(--sh-1);
}
[data-theme="dark"] .seg > button.active { background: var(--surface-4); }

/* ── Surfaces ────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--sh-1);
}
.panel {
  background: var(--bg-tint);
  border-color: var(--border);
}
.hairline-r { border-right: 1px solid var(--border); }
.hairline-l { border-left: 1px solid var(--border); }
.hairline-t { border-top: 1px solid var(--border); }
.hairline-b { border-bottom: 1px solid var(--border); }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 100px; font-size: var(--fs-xs); font-weight: 550;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
}
.chip-accent { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent); }
.chip-green  { background: var(--green-soft);  border-color: var(--green-border);  color: var(--green); }
.chip-red    { background: var(--red-soft);    border-color: var(--red-border);    color: var(--red); }
.chip-amber  { background: var(--amber-soft);  border-color: var(--amber-border);  color: var(--amber); }

/* ── Icons ───────────────────────────────────────────────────────────────── */
.ico { width: 1em; height: 1em; display: inline-flex; vertical-align: -.14em; flex: 0 0 auto; }
.ico-sm { width: 13px; height: 13px; }
.ico-md { width: 15px; height: 15px; }
.ico-lg { width: 18px; height: 18px; }
.ico-xl { width: 22px; height: 22px; }

/* ── Toasts ──────────────────────────────────────────────────────────────── */
.toast-region {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 2147483000;
  pointer-events: none; align-items: center;
}
.toast {
  padding: 9px 16px; border-radius: 100px; font-size: var(--fs-md); font-weight: 520;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-2); box-shadow: var(--sh-3);
  animation: toastIn .26s var(--ease);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
}
[data-theme="dark"] .toast { background: var(--surface-3); }
.toast.error { border-color: var(--red-border); color: var(--red); }
.toast.success { border-color: var(--green-border); color: var(--green); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spin {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--border-2); border-top-color: var(--accent);
  animation: spin .7s linear infinite; flex: 0 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Progress ────────────────────────────────────────────────────────────── */
.prog { height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.prog > i { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width .3s var(--ease); }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; color: var(--text-3); font-size: var(--fs-md); text-align: center; padding: 28px 20px;
}
.empty strong { color: var(--text-2); font-weight: 570; font-size: var(--fs-base); }

/* ── Utilities ───────────────────────────────────────────────────────────── */
.row { display: flex; align-items: center; gap: var(--sp-2); }
.col { display: flex; flex-direction: column; }
.grow { flex: 1; min-width: 0; min-height: 0; }
.spacer { flex: 1; }
.hidden, [hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scroll-y { overflow-y: auto; overscroll-behavior: contain; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
