/* ===========================================================================
   Digger — SaaS Design System (vanilla CSS, no framework)
   Standard: Geist (neutral, high-contrast, border-led) × warm accent (Terracotta).
   Defined in DESIGN_SYSTEM.md — keep every surface consistent with it.
   =========================================================================== */

:root {
  /* Color — neutral grayscale base (Geist), separation carried by 1px borders */
  --bg:        #fafafa;
  --surface:   #ffffff;
  --surface-2: #f5f5f5;
  --border:    #e5e5e5;
  --border-2:  #d4d4d4;
  --text:      #0a0a0a;
  --muted:     #525252;
  --muted-2:   #a3a3a3;

  /* Accent — Terracotta (the single warm brand color: CTA, active, focus) */
  --primary:      #c2563b;
  --primary-600:  #a8462e;
  --primary-700:  #8f3a25;
  --primary-50:   #fbf0ec;
  --success:      #0e9f6e;
  --success-50:   #e7f7f0;
  --warning:      #d9930a;
  --warning-50:   #fbf3e2;
  --danger:       #df1b41;
  --danger-50:    #fce8ec;

  /* Decorative brand gradient — logo/avatar only; buttons stay flat */
  --grad-primary: linear-gradient(180deg, #cb6149 0%, #c2563b 100%);
  --focus-ring:   0 0 0 3px rgba(194,86,59,.18);
  --glow:         rgba(194,86,59,.14);   /* soft accent halo (empty states, accents) */

  /* Semantic surfaces / fixed roles — so a theme change cascades everywhere */
  --on-accent:  #ffffff;             /* text & icons on a filled accent/dark surface */
  --overlay:    rgba(0,0,0,.45);     /* modal / drawer / command-palette backdrop */
  --glass-bg:   rgba(255,255,255,.72); /* frosted topbar; reused by future glass UI */
  --glass-blur: blur(10px) saturate(1.4);
  --backdrop-blur: blur(2px);        /* dim layer behind modal / drawer / ⌘K */
  --skel-hi:    #ededed;             /* skeleton shimmer highlight */

  /* Typography — Geist Sans (body) + Geist Mono (numbers, prices, code) */
  --font:      'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Spacing scale (4px) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;

  /* Radius — tight & precise (Geist) */
  --r-sm: 6px; --r-md: 8px; --r-lg: 10px; --r-xl: 16px; --r-pill: 999px;

  /* Shadow — minimal; depth only for floating layers, never for flat surfaces */
  --sh-xs: 0 1px 2px rgba(0,0,0,.10);   /* raised: buttons, logo, avatar */
  --sh-sm: 0 1px 2px rgba(0,0,0,.05);
  --sh-md: 0 2px 4px rgba(0,0,0,.06), 0 4px 10px rgba(0,0,0,.04);
  --sh-lg: 0 8px 30px rgba(0,0,0,.10), 0 2px 6px rgba(0,0,0,.05);

  --sidebar-w: 248px;
  --rail-w: 64px;
  --subnav-w: 208px;
  --topbar-h: 60px;
}

* { box-sizing: border-box; }
.icon { display: inline-block; vertical-align: middle; flex: none; }
.grip-handle { color: var(--muted-2); cursor: grab; }
.check-ok { color: var(--success); }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
/* Tabular figures for any numeric value (prices, stats, counts) */
.mono, .num { font-family: var(--font-mono); font-feature-settings: "tnum" 1; }

/* ---- Motion: View Transitions ------------------------------------------- */
/* Cross-document nav fades the content while the chrome (sidebar/topbar) stays
   put; the same crossfade also wraps JS-driven fragment swaps via Digger.vt(). */
@view-transition { navigation: auto; }
.rail   { view-transition-name: vt-rail; }
.subnav { view-transition-name: vt-subnav; }
.topbar { view-transition-name: vt-topbar; }
::view-transition-old(root) { animation: vt-out .16s ease both; }
::view-transition-new(root) { animation: vt-in  .22s ease both; }
@keyframes vt-out { to   { opacity: 0; } }
@keyframes vt-in  { from { opacity: 0; } to { opacity: 1; } }

/* Frosted-glass surface — use sparingly on floating/sticky layers only */
.glass { background: var(--glass-bg); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur); }
a { color: var(--primary-600); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { margin: 0 0 var(--s3); font-weight: 600; line-height: 1.22; letter-spacing: -.018em; color: var(--text); }
h1 { font-size: 25px; font-weight: 700; } h2 { font-size: 20px; } h3 { font-size: 16px; }
p { margin: 0 0 var(--s3); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Keyboard focus ring on every interactive control (mouse focus unaffected).
   Form fields keep their own box-shadow ring, so opt them out here. */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible, .cs-button:focus-visible { outline: none; }

/* ---- Layout: shell ------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }

/* ---- Level 1: icon rail -------------------------------------------------- */
.rail {
  width: var(--rail-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  position: fixed; inset: 0 auto 0 0; z-index: 50;
  padding: var(--s3) 0;
}
.rail__brand {
  display: grid; place-items: center;
  width: 40px; height: 40px; margin-bottom: var(--s3);
}
.rail__brand .logo {
  width: 28px; height: 28px; border-radius: var(--r-sm);
  background: var(--grad-primary); box-shadow: var(--sh-xs);
}
.rail__nav { display: flex; flex-direction: column; gap: var(--s2); flex: 1; }
.rail__item {
  position: relative;
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: var(--r-md);
  color: var(--muted); transition: background .12s, color .12s;
}
.rail__item:hover { background: var(--surface-2); color: var(--text); }
.rail__item.active { background: var(--primary-50); color: var(--primary-700); }
.rail__item.active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--primary);
}
.rail__item svg { width: 20px; height: 20px; }
.rail__foot { margin-top: auto; }

/* ---- Level 2: section sub-panel ----------------------------------------- */
.subnav {
  width: var(--subnav-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; inset: 0 auto 0 var(--rail-w); z-index: 40;
}
.subnav__head {
  font-weight: 700; font-size: 15px; letter-spacing: -.01em;
  padding: var(--s4) var(--s4) var(--s3);
}
.subnav__nav { padding: 0 var(--s3) var(--s3); display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-2); padding: var(--s4) var(--s3) var(--s2); }
.nav-link {
  position: relative;
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s2) var(--s3); border-radius: var(--r-sm);
  color: var(--muted); font-weight: 500;
}
.nav-link { transition: background .12s ease, color .12s ease; }
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--primary-50); color: var(--primary-700); font-weight: 600; }
.nav-link.active::before { content: ""; position: absolute; left: 0; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0; background: var(--primary); }
.nav-link.active svg { color: var(--primary); }
.nav-link svg { width: 18px; height: 18px; flex: none; }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.main--two { margin-left: calc(var(--rail-w) + var(--subnav-w)); }

.topbar {
  height: var(--topbar-h);
  background: var(--glass-bg); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--s5); position: sticky; top: 0; z-index: 30;
}
.topbar__title { font-weight: 600; font-size: 16px; letter-spacing: -.01em; }
.topbar__right { display: flex; align-items: center; gap: var(--s3); }
.avatar {
  width: 34px; height: 34px; border-radius: var(--r-pill);
  background: var(--grad-primary); color: var(--on-accent);
  display: grid; place-items: center; font-weight: 600; font-size: 13px;
  box-shadow: var(--sh-xs);
}
.content { padding: var(--s5); flex: 1; }
.container { max-width: 1100px; margin: 0 auto; }

/* ---- Cards --------------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.card:hover { box-shadow: var(--sh-sm); }
.card__body { padding: var(--s5); }
.card__head { padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }

.grid { display: grid; gap: var(--s4); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* Stat card */
.stat { padding: var(--s5); position: relative; }
.stat__icon { width: 36px; height: 36px; border-radius: var(--r-md); background: var(--surface-2); color: var(--muted); display: grid; place-items: center; margin-bottom: var(--s4); }
.stat__label { color: var(--muted); font-size: 13px; margin-bottom: var(--s2); }
.stat__value { font-size: 28px; font-weight: 700; font-family: var(--font-mono); font-feature-settings: "tnum" 1; letter-spacing: -.02em; }
.stat__delta { font-size: 12px; margin-top: var(--s1); }
.stat__delta.up { color: var(--success); } .stat__delta.down { color: var(--danger); }

/* ---- Bento grid (content-rich dashboards) ------------------------------- */
.bento { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s4); align-items: stretch; }
.bento > * { margin: 0; }                 /* cards manage their own height */
.bento .col-2 { grid-column: span 2; }
.bento .col-3 { grid-column: span 3; }
.bento .col-4 { grid-column: span 4; }
.bento .row-2 { grid-row: span 2; }
/* A bento cell that needs to stack head/body/foot and fill its track */
.bento .card { display: flex; flex-direction: column; }
.bento .card > .card__body { flex: 1; }
/* Hero welcome cell */
.bento__hero { background: linear-gradient(150deg, var(--primary-50), var(--surface) 70%); }
.bento__hero h1 { font-size: 22px; margin-bottom: var(--s1); }
@media (max-width: 860px) {
  .bento { grid-template-columns: repeat(2, 1fr); }
  .bento .col-2, .bento .col-3, .bento .col-4 { grid-column: span 2; }
}
@media (max-width: 520px) {
  .bento { grid-template-columns: 1fr; }
  .bento .col-2, .bento .col-3, .bento .col-4 { grid-column: auto; }
  .bento .row-2 { grid-row: auto; }
}

/* ---- Buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  font-family: inherit; font-size: 14px; font-weight: 600; line-height: 1;
  padding: 10px 16px; border-radius: var(--r-md); border: 1px solid transparent;
  cursor: pointer; transition: transform .12s ease, box-shadow .12s ease, background .12s ease, border-color .12s ease;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--on-accent); box-shadow: var(--sh-xs); }
.btn-primary:hover { background: var(--primary-600); box-shadow: var(--sh-sm); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-2); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--muted-2); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: var(--on-accent); box-shadow: var(--sh-xs); }
.btn-danger:hover { filter: brightness(1.05); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 13px 22px; font-size: 15px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---- Forms --------------------------------------------------------------- */
.field { margin-bottom: var(--s4); }
.label { display: block; font-weight: 500; font-size: 13px; margin-bottom: 6px; }
.input, .select, .textarea {
  width: 100%; font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--r-md); padding: 10px 12px; transition: .12s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: var(--focus-ring);
}
.input.error, .textarea.error { border-color: var(--danger); }
.textarea { min-height: 96px; resize: vertical; }
/* Custom dropdown chevron (replaces the native, far-right browser arrow) */
.select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding-right: 38px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%23a3a3a3" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>');
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.select::-ms-expand { display: none; }
.select--auto { width: auto; }

/* Custom select component (enhances native select.select) */
.cs { position: relative; }
.cs-native { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; } /* hidden but still submits */
.cs-button {
  width: 100%; text-align: left; font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--r-md);
  padding: 10px 38px 10px 12px; cursor: pointer; display: block; transition: .12s;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%23a3a3a3" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>');
  background-repeat: no-repeat; background-position: right 12px center;
}
.cs.open .cs-button, .cs-button:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus-ring); }
.cs-value { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-menu {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 60;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: var(--sh-lg); padding: 4px; max-height: 260px; overflow-y: auto; display: none;
}
.cs.open .cs-menu { display: block; animation: pop .12s ease; }
.cs-option { padding: 8px 10px; border-radius: var(--r-md); cursor: pointer; font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 2px; }
.cs-option:last-child { margin-bottom: 0; }
.cs-option:hover, .cs-option.active { background: var(--surface-2); }
.cs-option.selected { background: var(--primary-50); color: var(--primary-700); font-weight: 500; }
.cs-option--child { padding-left: 24px; }
.cs-button:disabled { opacity: .55; cursor: not-allowed; background-color: var(--surface-2); }
.field__error { color: var(--danger); font-size: 12px; margin-top: 4px; }
.field__hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.input-group { display: flex; gap: var(--s2); }
.input-addon { display: inline-flex; align-items: center; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border-2); border-radius: var(--r-md); color: var(--muted); font-size: 14px; white-space: nowrap; flex: none; }

/* Switch */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--border-2); border-radius: var(--r-pill); transition: .15s; }
.switch .track::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: var(--surface); border-radius: 50%; transition: .15s; }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::before { transform: translateX(18px); }

/* ---- Badges -------------------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: var(--r-pill); font-size: 12px; font-weight: 500; }
.badge-success { background: var(--success-50); color: var(--success); }
.badge-warning { background: var(--warning-50); color: var(--warning); }
.badge-danger  { background: var(--danger-50);  color: var(--danger); }
.badge-muted   { background: var(--surface-2);  color: var(--muted); }

/* ---- Table --------------------------------------------------------------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); }
.table td { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); }
.table tr:hover td { background: var(--surface-2); }
.table tr:last-child td { border-bottom: none; }

/* ---- Empty state --------------------------------------------------------- */
.empty { text-align: center; padding: var(--s8) var(--s5); }
.empty__icon { width: 60px; height: 60px; margin: 0 auto var(--s6); border-radius: var(--r-xl); background: linear-gradient(160deg, var(--primary-50), var(--surface)); color: var(--primary); display: grid; place-items: center; }
.empty h3 { margin-bottom: var(--s2); }
.empty p { color: var(--muted); max-width: 360px; margin: 0 auto var(--s4); }

/* Richer empty-state icon: soft accent halo (outset shadow) + concentric dashed
   ring (::after, sits outside the badge). Static — no float (kept premium).
   Robust against ancestor stacking contexts since nothing relies on negative z. */
.empty__icon, .ml-empty__icon {
  position: relative;
  box-shadow: inset 0 0 0 1px var(--border), 0 0 36px 4px var(--glow);
}
.empty__icon::after, .ml-empty__icon::after {
  content: ""; position: absolute; inset: -11px; border-radius: var(--r-xl);
  border: 1px dashed var(--border-2); pointer-events: none;
}

/* ---- Modal --------------------------------------------------------------- */
.modal-backdrop { position: fixed; inset: 0; background: var(--overlay); backdrop-filter: var(--backdrop-blur); z-index: 80; display: none; }
.modal-backdrop.open { display: grid; place-items: center; }
.modal { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--sh-lg); width: 100%; max-width: 480px; margin: var(--s4); overflow: hidden; animation: pop .14s ease; }
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal__head { padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal__body { padding: var(--s5); }
.modal__foot { padding: var(--s4) var(--s5); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--s2); }

/* ---- Toast --------------------------------------------------------------- */
/* Inline alert — static form messages (auth pages) */
.alert { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--muted); border-radius: var(--r-md); padding: var(--s3) var(--s4); font-size: 14px; }
.alert--success { border-left-color: var(--success); }
.alert--error   { border-left-color: var(--danger); }
.alert--info    { border-left-color: var(--primary); }
.alert--warning { border-left-color: var(--warning); }

/* Toast notifications — transient, JS-driven (2026 style) */
.toast-wrap { position: fixed; bottom: var(--s4); right: var(--s4); z-index: 100; display: flex; flex-direction: column-reverse; gap: 10px; max-width: 380px; }
.toast {
  position: relative; display: flex; align-items: flex-start; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--sh-lg); padding: 12px 36px 12px 14px; min-width: 280px; overflow: hidden;
  animation: toast-in .32s cubic-bezier(.21,1.02,.73,1); touch-action: pan-y;
}
.toast--out { animation: toast-out .28s ease forwards; }
.toast__icon { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; }
.toast__body { flex: 1; font-size: 14px; color: var(--text); line-height: 1.45; padding-top: 1px; }
.toast__close { position: absolute; top: 8px; right: 8px; border: none; background: none; cursor: pointer; color: var(--muted-2); padding: 4px; border-radius: var(--r-sm); display: flex; }
.toast__close:hover { color: var(--text); background: var(--surface-2); }
.toast__bar { position: absolute; left: 0; bottom: 0; height: 2px; width: 100%; transform-origin: left; opacity: .55; animation: toast-bar linear forwards; }
.toast--success .toast__icon { color: var(--success); background: var(--success-50); }
.toast--success .toast__bar { background: var(--success); }
.toast--error .toast__icon { color: var(--danger); background: var(--danger-50); }
.toast--error .toast__bar { background: var(--danger); }
.toast--info .toast__icon { color: var(--primary); background: var(--primary-50); }
.toast--info .toast__bar { background: var(--primary); }
.toast--warning .toast__icon { color: var(--warning); background: var(--warning-50); }
.toast--warning .toast__bar { background: var(--warning); }
@keyframes toast-in { from { transform: translateX(115%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toast-out { to { transform: translateX(115%); opacity: 0; } }
@keyframes toast-bar { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* ---- Auth pages ---------------------------------------------------------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--s5); background: radial-gradient(1200px 600px at 50% -20%, var(--primary-50), var(--bg)); }
.auth__card { width: 100%; max-width: 420px; }
.auth__logo { text-align: center; margin-bottom: var(--s5); font-weight: 700; font-size: 22px; }
.auth__alt { text-align: center; margin-top: var(--s4); color: var(--muted); }

/* ---- Utilities ----------------------------------------------------------- */
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.gap-2 { gap: var(--s2); } .gap-3 { gap: var(--s3); } .gap-4 { gap: var(--s4); }
.mt-2{margin-top:var(--s2)} .mt-4{margin-top:var(--s4)} .mt-5{margin-top:var(--s5)}
.mb-4{margin-bottom:var(--s4)} .mb-5{margin-bottom:var(--s5)}
.text-right { text-align: right; } .text-center { text-align: center; } .w-full { width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s5); }
.container-narrow { max-width: 680px; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.d-inline { display: inline; }
/* Headings inside section/modal/drawer heads carry no default margin */
.card__head h3, .modal__head h3, .drawer__head h3 { margin: 0; }

/* ---- Design editor ------------------------------------------------------- */
.editor { display: grid; grid-template-columns: 380px 1fr; gap: 24px; align-items: start; }
.editor__panel { display: flex; flex-direction: column; }

.editor-tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--r-md); margin-bottom: var(--s4); }
.editor-tab { flex: 1; border: none; background: transparent; font: inherit; font-size: 13px; font-weight: 500; color: var(--muted); padding: 8px; border-radius: var(--r-sm); cursor: pointer; transition: .12s; }
.editor-tab:hover { color: var(--text); }
.editor-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--sh-sm); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.color-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.color-row:last-child { border-bottom: none; }
.color-swatch { display: flex; align-items: center; gap: 10px; }
.color-swatch input[type=color] { width: 40px; height: 32px; padding: 0; border: 1px solid var(--border-2); border-radius: var(--r-md); cursor: pointer; background: none; }
.color-hex { font-family: var(--font-mono); font-size: 12px; color: var(--muted); width: 64px; }

.seg { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--r-md); }
.seg button { flex: 1; border: none; background: transparent; font: inherit; font-size: 13px; padding: 8px; border-radius: var(--r-sm); cursor: pointer; color: var(--muted); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--sh-sm); font-weight: 500; }

input[type=range] { -webkit-appearance: none; appearance: none; height: 6px; border-radius: var(--r-pill); background: var(--surface-2); outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--primary); cursor: pointer; box-shadow: var(--sh-sm); }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border: none; border-radius: 50%; background: var(--primary); cursor: pointer; }

/* Realistic phone mockup for live preview (iPhone-style) */
.preview-stage { position: sticky; top: 80px; }
.phone {
  /* Component-local tokens: fixed realistic-device chrome, intentionally NOT
     part of the brand theme. Centralized here so nothing is a stray literal. */
  --frame:  linear-gradient(150deg, #3a3a3d 0%, #1c1c1e 45%, #2a2a2d 100%);
  --bezel:  #000;
  --screen: #fff;
  --status: #0f172a;
  --btn:    linear-gradient(180deg, #404043, #1a1a1c);
  --cam:    radial-gradient(circle at 35% 35%, #2b3a55, #050608 70%);
  --shadow: 0 24px 60px rgba(15,23,42,.35), inset 0 0 0 2px rgba(255,255,255,.06), inset 0 0 6px rgba(0,0,0,.6);
  position: relative;
  /* Size driven by height, width derived from a real phone aspect ratio,
     so it always looks like a tall slim device and fits the viewport. */
  height: clamp(420px, calc(100vh - 232px), 860px);
  aspect-ratio: 80 / 147;
  margin: 0 auto;
  padding: 14px;
  border-radius: 58px;
  background: var(--frame);
  box-shadow: var(--shadow);
}
/* Inner metal ring around the screen */
.phone::before {
  content: "";
  position: absolute; inset: 8px;
  border-radius: 50px; /* = bezel radius (58) - inset (8), concentric */
  background: var(--bezel);
  z-index: 1;
}
/* Clips the iframe with overflow:hidden for pixel-perfect rounded corners
   (iframe's own border-radius can leave 1px artifacts). */
.phone__screenwrap {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%; /* fills the bezel; aspect ratio is set on .phone */
  border-radius: 44px; /* = bezel radius (58) - padding (14), concentric */
  overflow: hidden;
  background: var(--screen);
}
.phone__screen {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: var(--screen);
}
/* Dynamic Island */
.phone__island {
  position: absolute;
  top: 24px; left: 50%; transform: translateX(-50%);
  width: 108px; height: 31px;
  background: var(--bezel);
  border-radius: var(--r-pill);
  z-index: 3;
}
/* White background strip behind the status bar (sits above the iframe) */
.phone__statusbg {
  position: absolute; z-index: 2;
  top: 14px; left: 14px; right: 14px; height: 51px;
  background: var(--screen);
  border-radius: 44px 44px 0 0; /* matches the screen's top corners */
  pointer-events: none;
}

/* Status bar (time + system icons) flanking the island */
.phone__status {
  position: absolute; top: 24px; left: 18px; right: 18px; height: 31px;
  display: flex; align-items: center;
  z-index: 3; color: var(--status); pointer-events: none;
}
.phone__notch-gap { width: 120px; flex: none; }   /* reserves the island so both sides center */
.phone__time { flex: 1; text-align: center; font-size: 14px; font-weight: 600; letter-spacing: .2px; }
.phone__sysicons { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; }
.phone__sysicons svg { display: block; }

.phone__island::after { /* camera dot */
  content: "";
  position: absolute; top: 50%; right: 14px; transform: translateY(-50%);
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--cam);
}
/* Side buttons */
.phone__btn { position: absolute; background: var(--btn); border-radius: 2px; z-index: 0; }
.phone__btn--silent { left: -3px; top: 130px; width: 3px; height: 30px; }
.phone__btn--volup  { left: -3px; top: 180px; width: 3px; height: 58px; }
.phone__btn--voldn  { left: -3px; top: 250px; width: 3px; height: 58px; }
.phone__btn--power  { right: -3px; top: 200px; width: 3px; height: 84px; }

/* ---- Menu manager (unified) --------------------------------------------- */
.ml-grid { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: stretch; min-height: calc(100vh - 210px); }
.ml-pane { display: flex; flex-direction: column; }
.ml-pane .ml-list { flex: 1; }
.ml-list { padding: 6px; min-height: 300px; overflow-y: auto; } /* fills pane height, scrolls internally */
.ml-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--r-md); position: relative; margin-bottom: 2px; }
/* Drag drop cues */
.ml-row.drop-before::after, .ml-row.drop-after::after { content: ""; position: absolute; left: 6px; right: 6px; height: 2px; background: var(--primary); border-radius: 2px; }
.ml-row.drop-before::after { top: -1px; }
.ml-row.drop-after::after { bottom: -1px; }
.ml-row.drop-into { box-shadow: inset 0 0 0 2px var(--primary); background: var(--primary-50); }
.ml-row.drop-invalid { box-shadow: inset 0 0 0 2px var(--danger); }
.ml-row:hover { background: var(--surface-2); }
.ml-cat.active { background: var(--primary-50); }
/* Sub-category rows: guide line lives in the .ml-sub gutter; rows are indented
   via margin so their hover/active highlight starts to the RIGHT of the line. */
.ml-sub { position: relative; }
.ml-sub::before {
  content: ""; position: absolute; left: 17px; top: 0; bottom: 6px;
  width: 2px; background: var(--border);
}
.ml-cat.is-child { margin-left: 24px; }
.ml-cat.is-child .ml-cat__sel { color: var(--muted); }
.ml-grip { display: flex; cursor: grab; color: var(--muted-2); flex: none; touch-action: none; }
.ml-grip:active { cursor: grabbing; }
.ml-row.is-dragging {
  background: var(--surface);
  box-shadow: var(--sh-lg);
  transform: scale(1.02);
  position: relative; z-index: 5;
  border-radius: var(--r-md);
}
.ml-cat__sel { flex: 1; text-align: left; border: none; background: none; font: inherit; cursor: pointer; color: var(--text); display: flex; align-items: center; gap: 8px; padding: 2px 0; min-width: 0; }
.ml-cat__sel { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ml-row__actions { display: flex; align-items: center; gap: 4px; opacity: 0; transition: opacity .12s; flex: none; }
.ml-row:hover .ml-row__actions { opacity: 1; }
.icon-btn { border: none; background: none; cursor: pointer; color: var(--muted); padding: 5px; border-radius: var(--r-sm); display: flex; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }
.ml-thumb { width: 40px; height: 40px; border-radius: var(--r-md); object-fit: cover; flex: none; }
.ml-thumb--empty { background: var(--surface-2); }
.ml-prod__info { flex: 1; min-width: 0; }
.ml-prod__info strong { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ml-prod__meta { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.ml-empty { text-align: center; padding: 32px 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; min-height: 240px; }
.ml-empty__icon { width: 56px; height: 56px; border-radius: var(--r-xl); background: linear-gradient(160deg, var(--primary-50), var(--surface)); color: var(--primary); display: grid; place-items: center; margin-bottom: var(--s6); box-shadow: inset 0 0 0 1px var(--border), 0 0 36px 4px var(--glow); }
.ml-empty__title { font-weight: 600; font-size: 15px; color: var(--text); margin-bottom: 4px; }
.ml-empty__text { color: var(--muted); font-size: 13px; margin: 0 0 16px; max-width: 280px; line-height: 1.5; }
.ml-curimg { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.ml-curimg img { width: 56px; height: 56px; border-radius: var(--r-lg); object-fit: cover; }

/* Slide-over drawer */
.drawer-backdrop { position: fixed; inset: 0; background: var(--overlay); backdrop-filter: var(--backdrop-blur); z-index: 85; opacity: 0; visibility: hidden; transition: .2s; }
.drawer-backdrop.open { opacity: 1; visibility: visible; }
.drawer { position: absolute; top: 0; right: 0; height: 100%; width: 440px; max-width: 92vw; background: var(--surface); box-shadow: var(--sh-lg); transform: translateX(100%); transition: transform .22s ease; display: flex; flex-direction: column; }
.drawer-backdrop.open .drawer { transform: none; }
.drawer__head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.drawer__body { padding: 20px; overflow-y: auto; flex: 1; }
.drawer__foot { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---- Topbar search trigger ---------------------------------------------- */
.topbar-search { display: inline-flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); border-radius: var(--r-pill); padding: 6px 10px 6px 12px; font: inherit; font-size: 13px; cursor: pointer; transition: .12s; }
.topbar-search:hover { border-color: var(--border-2); color: var(--text); }
.topbar-search kbd { font: inherit; font-size: 11px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 1px 5px; color: var(--muted-2); }

/* ---- User menu (topbar avatar dropdown) -------------------------------- */
.usermenu { position: relative; }
.usermenu__btn { display: flex; align-items: center; gap: 6px; background: none; border: none; cursor: pointer; padding: 4px 8px 4px 4px; border-radius: var(--r-pill); transition: background .12s; }
.usermenu__btn:hover { background: var(--surface-2); }
.usermenu__btn > svg { color: var(--muted-2); transform: rotate(90deg); transition: transform .15s; }
.usermenu.open .usermenu__btn > svg { transform: rotate(-90deg); }
.usermenu__pop { position: absolute; top: calc(100% + 8px); right: 0; width: 240px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-lg); padding: 8px; display: none; z-index: 60; animation: pop .14s ease; }
.usermenu.open .usermenu__pop { display: block; }
.usermenu__head { display: flex; align-items: center; gap: 10px; padding: 6px 8px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.usermenu__id { min-width: 0; }
.usermenu__id strong { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.usermenu__id span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.usermenu__items a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--r-md); color: var(--text); font-size: 14px; }
.usermenu__items a + a { margin-top: 2px; }
.usermenu__items a:hover { background: var(--surface-2); text-decoration: none; }
.usermenu__items a svg { color: var(--muted-2); }
.usermenu__items a.text-danger svg { color: var(--danger); }
/* Rail user menu: button centered, popover opens upward to the right. */
.usermenu--rail .usermenu__btn { padding: 4px; }
.usermenu__pop--up { top: auto; bottom: calc(100% + 8px); left: 0; right: auto; }

/* ---- Command palette (⌘K) ---------------------------------------------- */
.cmdk { position: fixed; inset: 0; z-index: 120; background: var(--overlay); backdrop-filter: var(--backdrop-blur); display: flex; align-items: flex-start; justify-content: center; padding-top: 12vh; }
.cmdk[hidden] { display: none; }
.cmdk__panel { width: 100%; max-width: 560px; margin: 0 16px; background: var(--glass-bg); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-lg); overflow: hidden; animation: pop .14s ease; }
.cmdk__search { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); color: var(--muted); }
.cmdk__search input { flex: 1; border: none; outline: none; font: inherit; font-size: 15px; color: var(--text); background: none; }
.cmdk__search kbd { font: inherit; font-size: 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 2px 6px; color: var(--muted-2); }
.cmdk__list { max-height: 340px; overflow-y: auto; padding: 8px; }
.cmdk__item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: none; background: none; cursor: pointer; border-radius: var(--r-lg); font: inherit; font-size: 14px; color: var(--text); text-align: left; }
.cmdk__item + .cmdk__item { margin-top: 2px; }
.cmdk__item svg { color: var(--muted-2); flex: none; }
/* Hover is neutral everywhere; accent is reserved for the active (keyboard) item. */
.cmdk__item:hover { background: var(--surface-2); color: var(--text); }
.cmdk__item.active { background: var(--primary-50); color: var(--primary-700); }
.cmdk__item.active svg { color: var(--primary); }
.cmdk__none { padding: 24px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---- Skeleton loaders --------------------------------------------------- */
.skel { background: linear-gradient(90deg, var(--surface-2) 25%, var(--skel-hi) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: skel 1.2s ease infinite; border-radius: var(--r-md); }
.skel-row { height: 40px; margin: 6px; }
@keyframes skel { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ---- Media library + picker --------------------------------------------- */
.media-layout { display: grid; grid-template-columns: 1fr 300px; gap: var(--s4); align-items: start; }
.media-main { min-width: 0; }
.media-toolbar { display: flex; gap: var(--s2); align-items: center; margin-bottom: var(--s4); }
.media-toolbar .input { max-width: 280px; }
.media-count { color: var(--muted); font-size: 13px; }

/* Drag-and-drop upload zone (also replaces the raw file input) */
.dropzone {
  border: 1.5px dashed var(--border-2); border-radius: var(--r-lg);
  background: var(--surface); padding: var(--s5); text-align: center;
  color: var(--muted); cursor: pointer; margin-bottom: var(--s4);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 180px; /* matches the details card so the two top boxes align */
  transition: border-color .12s, background .12s, color .12s;
}
.dropzone:hover { border-color: var(--muted-2); }
.dropzone.dragover { border-color: var(--primary); background: var(--primary-50); color: var(--primary-700); }
.dropzone__icon { width: 44px; height: 44px; border-radius: var(--r-xl); background: var(--surface-2); color: var(--muted); display: grid; place-items: center; transition: background .12s, color .12s; }
.dropzone.dragover .dropzone__icon { background: var(--surface); color: var(--primary); }
.dropzone input[type=file] { display: none; }

/* Thumbnail grid */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: var(--s3); }
.media-tile {
  position: relative; aspect-ratio: 1; border: 1px solid var(--border); border-radius: var(--r-md);
  overflow: hidden; cursor: pointer; background: var(--surface-2);
  transition: box-shadow .12s, border-color .12s;
}
.media-tile:hover { border-color: var(--border-2); box-shadow: var(--sh-sm); }
.media-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-tile.selected { border-color: var(--primary); box-shadow: inset 0 0 0 2px var(--primary); }
.media-tile.is-uploading { opacity: .55; }
.media-tile__check {
  position: absolute; top: 6px; left: 6px; width: 20px; height: 20px; border-radius: var(--r-pill);
  background: var(--surface); border: 1px solid var(--border-2); display: none; place-items: center; color: var(--on-accent);
}
.media-tile.selected .media-tile__check { display: grid; background: var(--primary); border-color: var(--primary); }

/* Details panel (library page) */
.media-details { position: sticky; top: 80px; }
.media-details > .card { min-height: 180px; display: flex; } /* equal height with the dropzone */
.media-details > .card > .card__body { flex: 1; display: flex; flex-direction: column; }
.media-details__preview { width: 100%; aspect-ratio: 1; object-fit: contain; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); display: block; }
.media-details dl { display: grid; grid-template-columns: auto 1fr; gap: 4px var(--s3); font-size: 13px; margin: var(--s4) 0; }
.media-details dt { color: var(--muted); }
.media-details dd { margin: 0; text-align: right; word-break: break-all; }
.media-details__empty { color: var(--muted); text-align: center; padding: var(--s4); font-size: 13px; margin: auto; }
.media-uses { font-size: 12px; color: var(--warning); margin-top: var(--s2); }

/* Picker modal — wider than the default modal */
.modal--wide { max-width: 760px; }
.modal--wide .modal__body { max-height: 62vh; overflow-y: auto; }
.media-tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--r-md); margin-bottom: var(--s4); }
.media-tabs button { flex: 1; border: none; background: transparent; font: inherit; font-size: 13px; font-weight: 500; color: var(--muted); padding: 8px; border-radius: var(--r-sm); cursor: pointer; }
.media-tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--sh-sm); }

/* Media field — picker trigger + preview (replaces raw <input type=file> in forms) */
.media-field { display: flex; align-items: center; gap: var(--s3); }
.media-field__preview { width: 64px; height: 64px; border-radius: var(--r-md); object-fit: cover; border: 1px solid var(--border); background: var(--surface-2); flex: none; display: grid; place-items: center; color: var(--muted-2); overflow: hidden; }
.media-field__preview img { width: 100%; height: 100%; object-fit: cover; }

/* ---- Mobile -------------------------------------------------------------- */
.menu-toggle { display: none; }
@media (max-width: 860px) {
  /* Rail + sub-panel slide in together as one drawer. */
  .rail, .subnav { transform: translateX(-100%); transition: transform .2s; box-shadow: var(--sh-lg); }
  .shell.nav-open .rail, .shell.nav-open .subnav { transform: none; }
  .main, .main--two { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .editor { grid-template-columns: 1fr; }
  .preview-stage { position: static; }
  .ml-grid { grid-template-columns: 1fr; }
  .media-layout { grid-template-columns: 1fr; }
  .media-details { position: static; }
  .ml-row__actions { opacity: 1; }
  .topbar-search span, .topbar-search kbd { display: none; }
  .topbar-search { padding: 7px; }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: 1fr; }
  .content { padding: var(--s4); }
  .toast-wrap { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}

/* ── Onboarding wizard ──────────────────────────────────────────────── */
.onb-steps { display: flex; align-items: center; gap: var(--s2); }
.onb-step { display: flex; align-items: center; gap: var(--s2); color: var(--muted-2); font-size: 14px; }
.onb-step:not(:last-child)::after { content: ""; width: 28px; height: 2px; background: var(--border); margin-left: var(--s2); }
.onb-step.active { color: var(--text); font-weight: 600; }
.onb-step.done { color: var(--primary-700); }
.onb-step__dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: var(--r-pill);
  border: 1px solid var(--border-2); background: var(--surface);
  font-size: 12px; font-weight: 600;
}
.onb-step.active .onb-step__dot { border-color: var(--primary); color: var(--primary-700); background: var(--primary-50); }
.onb-step.done .onb-step__dot { border-color: var(--primary); color: var(--on-accent); background: var(--primary); }

.onb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--s3); }
.onb-card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: var(--s2);
  padding: var(--s5) var(--s3); border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); cursor: pointer; text-align: center; transition: border-color .12s, background .12s;
}
.onb-card:hover { background: var(--surface-2); }
.onb-card input { position: absolute; opacity: 0; pointer-events: none; }
.onb-card:has(input:checked) { border-color: var(--primary); background: var(--primary-50); }
.onb-card__icon { color: var(--muted); }
.onb-card:has(input:checked) .onb-card__icon { color: var(--primary-700); }
.onb-card__name { font-size: 14px; font-weight: 500; color: var(--text); }
.onb-swatch { display: flex; gap: 3px; }
.onb-swatch__dot { width: 16px; height: 16px; border-radius: var(--r-pill); border: 1px solid var(--border); }
