/* ============================================================
   StillOS Design System — ds.css
   Institutional charcoal + brass. Bloomberg/Renaissance, not Robinhood.
   ============================================================ */

/* ---------- TOKENS ---------- */
:root {
  /* surfaces */
  --bg-0: #0d0d11;
  --bg-1: #121218;
  --surface-1: #18181f;
  --surface-2: #1e1e28;
  --surface-3: #242432;

  /* borders */
  --border-subtle: #1e1e28;
  --border-default: #28283a;
  --border-strong: #363650;
  --border-accent: #7a6428;

  /* text */
  --text-primary: #eeebe4;
  --text-secondary: #8c8a96;
  --text-tertiary: #54525e;

  /* accent */
  --accent: #b8960c;
  --accent-dim: #7a6428;
  --accent-bright: #d4a818;

  /* semantic */
  --success: #2a7a54;
  --success-text: #47c180;
  --success-bg: rgba(42,122,84,0.08);
  --success-border: rgba(42,122,84,0.25);

  --warning: #8a6010;
  --warning-text: #d4a017;
  --warning-bg: rgba(212,160,23,0.08);
  --warning-border: rgba(212,160,23,0.25);

  --danger: #7a1c1c;
  --danger-text: #d45050;
  --danger-bg: rgba(212,80,80,0.08);
  --danger-border: rgba(212,80,80,0.25);

  --info: #1a4464;
  --info-text: #4a90c4;
  --info-bg: rgba(74,144,196,0.08);
  --info-border: rgba(74,144,196,0.25);

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

  /* typography */
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --fz-xs: 11px; --fz-sm: 12px; --fz-md: 14px;
  --fz-lg: 16px; --fz-xl: 20px;
  --fz-metric: 26px; --fz-heading: 18px;

  /* radii */
  --r1: 3px; --r2: 5px; --r3: 8px; --r4: 12px;

  /* shadows */
  --sh-1: 0 1px 2px rgba(0,0,0,0.4);
  --sh-2: 0 4px 16px rgba(0,0,0,0.45);
  --sh-3: 0 8px 40px rgba(0,0,0,0.6);

  /* motion */
  --t-fast: 120ms ease;
  --t-base: 200ms ease;
  --t-slow: 320ms cubic-bezier(.4,0,.2,1);
}

/* ---------- RESET ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: var(--fz-md);
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-0);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-bright); }
ul, ol { list-style: none; }
table { border-collapse: collapse; width: 100%; }

/* ---------- TYPOGRAPHY UTILS ---------- */
.t-xs   { font-size: var(--fz-xs); letter-spacing: 0.06em; }
.t-sm   { font-size: var(--fz-sm); }
.t-md   { font-size: var(--fz-md); }
.t-lg   { font-size: var(--fz-lg); }
.t-xl   { font-size: var(--fz-xl); }
.metric { font-size: var(--fz-metric); font-weight: 700; line-height: 1.1; letter-spacing: -0.01em; }
.heading{ font-size: var(--fz-heading); font-weight: 600; }
.muted  { color: var(--text-secondary); }
.dim    { color: var(--text-tertiary); }
.upper  { text-transform: uppercase; letter-spacing: 0.08em; }
.mono   { font-variant-numeric: tabular-nums; }
.bold   { font-weight: 700; }
.label  { font-size: var(--fz-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-tertiary); font-weight: 700; }
.accent { color: var(--accent-bright); }
.center { text-align: center; }
.right  { text-align: right; }

/* ---------- LAYOUT UTILS ---------- */
.row { display: flex; align-items: center; }
.row.gap1 { gap: var(--s1); } .row.gap2 { gap: var(--s2); }
.row.gap3 { gap: var(--s3); } .row.gap4 { gap: var(--s4); }
.col { display: flex; flex-direction: column; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ---------- BRAND ---------- */
.brand { display: inline-flex; align-items: center; gap: var(--s2); font-weight: 700; letter-spacing: 0.04em; color: var(--text-primary); }
.brand .diamond { color: var(--accent); }
.brand small { color: var(--text-tertiary); font-weight: 500; letter-spacing: 0.1em; font-size: var(--fz-xs); }

/* ---------- BADGE ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 7px; border-radius: var(--r1);
  border: 1px solid var(--border-default);
  color: var(--text-secondary); background: transparent;
  white-space: nowrap;
}
.badge-active   { color: var(--success-text); border-color: var(--success-border); background: var(--success-bg); }
.badge-pending  { color: var(--warning-text); border-color: var(--warning-border); background: var(--warning-bg); }
.badge-payment  { color: var(--accent-bright); border-color: var(--border-accent); background: rgba(184,150,12,0.08); }
.badge-complete { color: var(--success-text); border-color: var(--success-border); background: var(--success-bg); opacity: 0.7; }
.badge-blocked  { color: var(--danger-text); border-color: var(--danger-border); background: var(--danger-bg); }
.badge-info     { color: var(--info-text); border-color: var(--info-border); background: var(--info-bg); }

/* ---------- BUTTON ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  font-family: inherit; font-size: 12px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer; border-radius: var(--r2);
  border: 1px solid transparent; background: transparent; color: var(--text-primary);
  padding: 9px 16px; transition: all var(--t-fast); user-select: none;
}
.btn-sm { padding: 6px 11px; font-size: 11px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-bright); border-color: var(--accent-bright); }
.btn-ghost { border-color: var(--border-default); color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { border-color: var(--border-accent); color: var(--accent-bright); }
.btn-danger { border-color: var(--danger-border); color: var(--danger-text); background: var(--danger-bg); }
.btn-danger:hover:not(:disabled) { border-color: var(--danger-text); }
.btn-success { background: var(--success); color: #000; border-color: var(--success); }
.btn-success:hover:not(:disabled) { filter: brightness(1.12); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- INPUT ---------- */
.input, input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="search"], textarea, select {
  width: 100%; background: var(--bg-0); border: 1px solid var(--border-default);
  color: var(--text-primary); padding: 10px 14px; border-radius: var(--r2);
  outline: none; transition: border-color var(--t-fast); font-size: var(--fz-md);
}
.input:focus, input:focus, textarea:focus, select:focus { border-color: var(--accent); }
::placeholder { color: var(--text-tertiary); }
textarea { resize: vertical; min-height: 72px; line-height: 1.5; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: var(--fz-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-tertiary); font-weight: 700; }

/* search field with icon spacing */
.search { background: var(--bg-0); }

/* ---------- CARD ---------- */
.card {
  background: var(--surface-1); border: 1px solid var(--border-default);
  border-radius: var(--r3); padding: var(--s5);
}
.card-2 { background: var(--surface-2); }
.card-flush { padding: 0; overflow: hidden; }
.card-gold { border-color: var(--border-accent); box-shadow: inset 0 0 0 1px rgba(184,150,12,0.06); }

/* ---------- KPI ---------- */
.kpi-strip { display: grid; gap: 1px; background: var(--border-subtle); border: 1px solid var(--border-default); border-radius: var(--r3); overflow: hidden; }
.kpi { background: var(--surface-1); padding: var(--s4) var(--s5); display: flex; flex-direction: column; gap: 4px; }
.kpi .k-label { font-size: var(--fz-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-tertiary); font-weight: 700; }
.kpi .k-val { font-size: var(--fz-metric); font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }

/* ---------- PROGRESS ---------- */
.progress { height: 3px; background: var(--border-subtle); border-radius: 2px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width var(--t-base); }
.progress.tall { height: 6px; }

/* ---------- TABLE ---------- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  font-size: var(--fz-xs); text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-tertiary); font-weight: 700; text-align: left;
  border-bottom: 1px solid var(--border-subtle); padding: var(--s3) var(--s4);
  white-space: nowrap;
}
.tbl td { font-size: var(--fz-sm); color: var(--text-primary); border-bottom: 1px solid var(--border-subtle); padding: var(--s3) var(--s4); vertical-align: middle; }
.tbl tbody tr { transition: background var(--t-fast); }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr.selected { background: var(--surface-3); }
.tbl td.num { font-variant-numeric: tabular-nums; }

/* ---------- DRAWER ---------- */
.drawer-scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  opacity: 0; pointer-events: none; transition: opacity var(--t-base); z-index: 90;
}
.drawer-scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; right: 0; top: 0; height: 100vh; width: 420px;
  background: var(--bg-1); border-left: 1px solid var(--border-default);
  transform: translateX(100%); transition: transform var(--t-slow);
  z-index: 100; display: flex; flex-direction: column; box-shadow: var(--sh-3);
}
.drawer.open { transform: none; }
.drawer-head { padding: var(--s5); border-bottom: 1px solid var(--border-subtle); }
.drawer-body { padding: var(--s5); overflow-y: auto; flex: 1; }
.drawer-foot { padding: var(--s4) var(--s5); border-top: 1px solid var(--border-subtle); display: flex; gap: var(--s2); }
@media (max-width: 640px) { .drawer { width: 100%; } }

/* ---------- MODAL ---------- */
.modal-scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; padding: var(--s4);
  opacity: 0; pointer-events: none; transition: opacity var(--t-base); z-index: 110;
}
.modal-scrim.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: var(--r4); padding: var(--s6); width: 100%; max-width: 420px;
  box-shadow: var(--sh-3); transform: translateY(8px); transition: transform var(--t-slow);
}
.modal-scrim.open .modal { transform: none; }

/* ---------- TOAST ---------- */
.toast-host { position: fixed; bottom: var(--s5); right: var(--s5); display: flex; flex-direction: column; gap: var(--s2); z-index: 200; }
.toast {
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent); color: var(--text-primary);
  padding: var(--s3) var(--s4); border-radius: var(--r2); font-size: var(--fz-sm);
  box-shadow: var(--sh-2); min-width: 220px; max-width: 360px;
  animation: toast-in var(--t-slow);
}
.toast.ok { border-left-color: var(--success-text); }
.toast.err { border-left-color: var(--danger-text); }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ---------- ALERT BANNER ---------- */
.alert {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4); border-radius: var(--r2);
  border: 1px solid var(--border-default); font-size: var(--fz-sm);
}
.alert-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
.alert-info { background: var(--info-bg); border-color: var(--info-border); color: var(--info-text); }
.alert-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.alert-danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger-text); }

/* ---------- CHIPS ---------- */
.chips { display: flex; gap: var(--s2); flex-wrap: wrap; }
.chip {
  font-size: var(--fz-xs); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700;
  padding: 6px 11px; border-radius: 999px; border: 1px solid var(--border-default);
  color: var(--text-secondary); background: transparent; cursor: pointer; transition: all var(--t-fast);
  white-space: nowrap;
}
.chip:hover { border-color: var(--border-strong); color: var(--text-primary); }
.chip.active { background: var(--accent); color: #000; border-color: var(--accent); }

/* ---------- SKELETON ---------- */
.skel { background: var(--surface-2); border-radius: var(--r2); position: relative; overflow: hidden; }
.skel::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.04), transparent); animation: shimmer 1.2s infinite; }
.skel-line { height: 12px; margin: 8px 0; }
@keyframes shimmer { to { transform: translateX(100%); } }

/* ---------- EMPTY STATE ---------- */
.empty { text-align: center; padding: var(--s7) var(--s4); color: var(--text-tertiary); }
.empty .e-icon { font-size: 28px; color: var(--border-strong); margin-bottom: var(--s3); }
.empty .e-title { color: var(--text-secondary); font-weight: 600; margin-bottom: 4px; }

/* ---------- TABS ---------- */
.tabs { display: flex; gap: 2px; }
.tab {
  font-size: var(--fz-sm); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-secondary); background: transparent; border: none; cursor: pointer;
  padding: var(--s3) var(--s4); border-bottom: 2px solid transparent; transition: all var(--t-fast);
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent-bright); border-bottom-color: var(--accent); }

/* ---------- TOPBAR ---------- */
.topbar {
  display: flex; align-items: center; gap: var(--s5);
  padding: 0 var(--s5); height: 56px;
  border-bottom: 1px solid var(--border-default); background: var(--bg-1);
  position: sticky; top: 0; z-index: 50;
}

/* ---------- PILL ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fz-sm); font-weight: 600; color: var(--text-secondary); border: 1px solid var(--border-default); border-radius: 999px; padding: 5px 12px; }

/* ---------- DIVIDER ---------- */
.hr { height: 1px; background: var(--border-subtle); border: none; margin: var(--s4) 0; }

/* ---------- PROSE (blueprint doc) ---------- */
.prose { max-width: 760px; margin: 0 auto; color: var(--text-primary); line-height: 1.7; }
.prose h2 { font-size: var(--fz-xl); margin: var(--s7) 0 var(--s3); color: var(--text-primary); letter-spacing: -0.01em; }
.prose h3 { font-size: var(--fz-lg); margin: var(--s5) 0 var(--s2); color: var(--accent-bright); }
.prose p { margin: var(--s3) 0; color: var(--text-secondary); }
.prose .eyebrow { font-size: var(--fz-xs); text-transform: uppercase; letter-spacing: 0.14em; color: var(--accent-dim); font-weight: 700; }
.prose .formula { background: var(--bg-0); border: 1px solid var(--border-default); border-radius: var(--r2); padding: var(--s4); font-variant-numeric: tabular-nums; margin: var(--s4) 0; }
.prose .formula div { padding: 3px 0; color: var(--text-primary); font-size: var(--fz-sm); }
.prose table { margin: var(--s4) 0; }
.prose table th, .prose table td { padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border-subtle); text-align: left; font-size: var(--fz-sm); }
.prose table th { color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.06em; font-size: var(--fz-xs); }
.prose .phase-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: var(--s3); margin: var(--s4) 0; }
.prose .phase-card { background: var(--surface-1); border: 1px solid var(--border-default); border-radius: var(--r3); padding: var(--s4); }
.prose .phase-card .pc-month { font-size: var(--fz-xs); letter-spacing: 0.1em; color: var(--text-tertiary); text-transform: uppercase; font-weight: 700; }
.prose .phase-card .pc-amt { font-size: var(--fz-xl); font-weight: 700; color: var(--accent-bright); }
.prose .note { background: var(--surface-1); border-left: 3px solid var(--accent-dim); padding: var(--s3) var(--s4); margin: var(--s4) 0; border-radius: 0 var(--r2) var(--r2) 0; }

/* ---------- PAGE WRAP ---------- */
.page { padding: var(--s5); max-width: 1240px; margin: 0 auto; }
.page-narrow { max-width: 720px; margin: 0 auto; padding: var(--s5); }
.stack > * + * { margin-top: var(--s4); }
.stack-sm > * + * { margin-top: var(--s2); }
.stack-lg > * + * { margin-top: var(--s5); }

/* ---------- AUTH SHELL ---------- */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--s5); }
.auth-card { width: 100%; max-width: 400px; }

/* ---------- PAY METHOD CARD ---------- */
.pay-method {
  display: flex; align-items: flex-start; gap: var(--s3); cursor: pointer;
  border: 1px solid var(--border-default); border-radius: var(--r2);
  padding: var(--s3) var(--s4); transition: all var(--t-fast); background: var(--bg-0);
}
.pay-method:hover { border-color: var(--border-strong); }
.pay-method.selected { border-color: var(--accent); background: rgba(184,150,12,0.06); }
.pay-method .pm-radio { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); flex-shrink: 0; margin-top: 2px; transition: all var(--t-fast); }
.pay-method.selected .pm-radio { border-color: var(--accent); box-shadow: inset 0 0 0 3px var(--accent); }
.pay-method .pm-label { font-weight: 700; font-size: var(--fz-md); }
.pay-method .pm-handle { font-size: var(--fz-sm); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.pay-method .pm-instr { font-size: var(--fz-xs); color: var(--text-tertiary); margin-top: 2px; }

/* ---------- STEP ROW ---------- */
.step-row { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border: 1px solid var(--border-subtle); border-radius: var(--r2); background: var(--surface-1); }
.step-row .s-num { width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--border-default); display: flex; align-items: center; justify-content: center; font-size: var(--fz-xs); font-weight: 700; color: var(--text-secondary); flex-shrink: 0; }
.step-row.done .s-num { border-color: var(--success-border); color: var(--success-text); }

/* ---------- BOOKS GRID ---------- */
.books-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: var(--s2); }
.book-item { display: flex; align-items: center; gap: var(--s2); font-size: var(--fz-sm); color: var(--text-secondary); cursor: pointer; padding: var(--s2); border-radius: var(--r2); border: 1px solid transparent; }
.book-item:hover { background: var(--surface-2); }
.book-item input { width: auto; accent-color: var(--accent); }

/* ---------- PROOF STRIP ---------- */
.proof-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--border-subtle); border: 1px solid var(--border-default); border-radius: var(--r3); overflow: hidden; }
.proof-cell { background: var(--surface-1); padding: var(--s4); text-align: center; }
.proof-cell .pf-val { font-size: var(--fz-xl); font-weight: 700; color: var(--accent-bright); }
.proof-cell .pf-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-tertiary); margin-top: 2px; }
@media (max-width: 560px) { .proof-strip { grid-template-columns: repeat(2,1fr); } }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 900px) {
  .kpi-strip { grid-template-columns: repeat(2, 1fr) !important; }
  .topbar { gap: var(--s3); padding: 0 var(--s4); }
}
@media (max-width: 640px) {
  .page { padding: var(--s4); }
  .hide-sm { display: none !important; }
  .kpi-strip { grid-template-columns: 1fr 1fr !important; }
}

/* ---------- MOTION PREFERENCE ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ---------- FOCUS ---------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- FOOTER ---------- */
.foot-note { font-size: var(--fz-xs); color: var(--text-tertiary); text-align: center; padding: var(--s5); }

.spinner { width:24px; height:24px; border:2px solid var(--border-subtle); border-top-color:var(--accent); border-radius:50%; animation:spin .7s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }
