/* ============================================================================
   Alphabot — design system

   Dark-first, because this is a screen someone stares at early in the morning.
   Both themes are defined at token level: the bare :root block carries the
   complete dark palette, and a light palette is swapped in for viewers whose OS
   asks for it or who toggle explicitly. No component ever hard-codes a colour.

   Colour has two jobs here and they are kept strictly apart:
     accent (amber)  — brand, navigation, focus. Never means "good".
     semantic        — profit green / loss red / warning. Never decorative.
   Mixing them is how a dashboard ends up with a green "Save" button sitting
   next to a green "+2.4%" and the reader has to work out which is which.
   ========================================================================= */

:root {
  --ground:      #0b0f17;
  --surface:     #131a25;
  --raised:      #1a2331;
  --sunk:        #0e141d;
  --line:        #222c3c;
  --line-soft:   #1a2331;

  --ink:         #e7ecf3;
  --muted:       #93a1b5;
  --faint:       #5f6d80;

  --accent:      #f0b429;
  --accent-ink:  #1a1204;
  --accent-soft: #2a2010;
  --accent-line: #4a3a17;

  --up:          #34d399;   /* profit */
  --down:        #f87171;   /* loss   */
  --warn:        #fbbf24;   /* attention needed */
  --up-soft:     #0f2a22;
  --down-soft:   #2b1414;
  --warn-soft:   #2a2110;

  --display: 'Instrument Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono:    'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --r-sm: 8px;  --r-md: 12px;  --r-lg: 16px;
  --pad:  20px;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.28);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --ground:    #f6f7f9;
    --surface:   #ffffff;
    --raised:    #ffffff;
    --sunk:      #eef1f5;
    --line:      #dfe4ec;
    --line-soft: #eaeef4;

    --ink:       #131922;
    --muted:     #56637a;
    --faint:     #8b97a8;

    --accent:      #a16207;
    --accent-ink:  #ffffff;
    --accent-soft: #fdf6e7;
    --accent-line: #ecd9a8;

    --up:   #15803d;  --down: #b91c1c;  --warn: #b45309;
    --up-soft: #eafaf0;  --down-soft: #fdecec;  --warn-soft: #fdf4e3;
    --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
  }
}
:root[data-theme="light"] {
  --ground:#f6f7f9; --surface:#fff; --raised:#fff; --sunk:#eef1f5;
  --line:#dfe4ec; --line-soft:#eaeef4;
  --ink:#131922; --muted:#56637a; --faint:#8b97a8;
  --accent:#a16207; --accent-ink:#fff; --accent-soft:#fdf6e7; --accent-line:#ecd9a8;
  --up:#15803d; --down:#b91c1c; --warn:#b45309;
  --up-soft:#eafaf0; --down-soft:#fdecec; --warn-soft:#fdf4e3;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--display);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; text-wrap: balance; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 14px; font-weight: 700; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

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

.side {
  width: 232px; flex: 0 0 232px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 22px 14px;
  display: flex; flex-direction: column; gap: 26px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
  font-weight: 800; font-size: 15px; letter-spacing: -0.04em;
}
.brand-name { font-weight: 800; font-size: 16px; letter-spacing: -0.02em; }
.brand-sub { font-size: 10px; color: var(--faint); font-family: var(--mono);
             letter-spacing: .1em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 10px; font-family: var(--mono); letter-spacing: .12em;
             text-transform: uppercase; color: var(--faint); padding: 0 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--r-sm);
  color: var(--muted); font-size: 14px; font-weight: 500;
  transition: background .14s ease, color .14s ease;
}
.nav a:hover { background: var(--sunk); color: var(--ink); }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.nav a.on .ic { opacity: 1; }
.ic { width: 17px; text-align: center; opacity: .75; }

.side-foot { margin-top: auto; font-size: 11px; color: var(--faint); padding: 0 10px; }
.side-foot .row { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; }

.main { flex: 1; min-width: 0; padding: 26px 30px 70px; max-width: 1320px; }
.head { display: flex; align-items: flex-start; justify-content: space-between;
        gap: 20px; flex-wrap: wrap; margin-bottom: 22px; }
.head p { margin: 5px 0 0; color: var(--muted); font-size: 14px; max-width: 62ch; }

/* ── Cards & sections ────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--pad);
}
.card + .card { margin-top: 16px; }
.sec { margin-top: 30px; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between;
            gap: 16px; margin-bottom: 12px; flex-wrap: wrap; }
.sec-head p { margin: 3px 0 0; color: var(--faint); font-size: 13px; max-width: 70ch; }

/* ── Regime hero ─────────────────────────────────────────────────────────── */
.hero {
  background: var(--surface); border: 1px solid var(--line);
  border-left: 5px solid var(--tone, var(--accent));
  border-radius: var(--r-md); padding: 20px 22px;
}
.hero .eyebrow { font-family: var(--mono); font-size: 10px; letter-spacing: .14em;
                 text-transform: uppercase; color: var(--faint); }
.hero .verdict { font-size: 30px; font-weight: 800; letter-spacing: -.03em;
                 color: var(--tone, var(--ink)); margin-top: 2px; line-height: 1.1; }
.hero .detail { color: var(--muted); font-size: 13px; margin-top: 8px; }
.hero .note { color: var(--faint); font-size: 12px; font-style: italic; margin-top: 2px; }

/* ── Stat tiles ──────────────────────────────────────────────────────────── */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--line);
        border-top: 3px solid var(--tone, var(--accent));
        border-radius: var(--r-md); padding: 14px 16px; }
.tile .k { font-size: 11px; color: var(--faint); font-weight: 600; letter-spacing: .02em; }
.tile .v { font-size: 27px; font-weight: 800; letter-spacing: -.03em; line-height: 1.15;
           margin-top: 4px; color: var(--tone, var(--ink)); font-family: var(--mono); }
.tile .s { font-size: 11px; color: var(--faint); margin-top: 3px; }

/* ── Pills & badges ──────────────────────────────────────────────────────── */
.pill { display: inline-block; padding: 3px 10px; border-radius: 20px;
        font-size: 11px; font-weight: 700; white-space: nowrap; letter-spacing: .01em; }
.pill-buy  { background: var(--up-soft);   color: var(--up); }
.pill-acc  { background: var(--accent-soft); color: var(--accent); }
.pill-hold { background: var(--sunk);      color: var(--muted); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-exit { background: var(--down-soft); color: var(--down); }
.up { color: var(--up); } .down { color: var(--down); } .flat { color: var(--muted); }

/* ── Recommendation card ─────────────────────────────────────────────────── */
.rec { background: var(--surface); border: 1px solid var(--line);
       border-left: 4px solid var(--tone, var(--up));
       border-radius: var(--r-md); overflow: hidden; }
.rec + .rec { margin-top: 12px; }
.rec-top { display: flex; align-items: flex-start; justify-content: space-between;
           gap: 14px; padding: 14px 16px 10px; }
.rec-sym { font-size: 19px; font-weight: 800; letter-spacing: -.02em; }
.rec-sub { font-size: 11px; color: var(--faint); margin-top: 1px; }
.rec-inst { margin: 0 16px 12px; padding: 11px 13px; border-radius: var(--r-sm);
            background: var(--sunk); font-size: 13.5px; font-weight: 600; line-height: 1.5; }
.rec-note { font-size: 11px; color: var(--faint); font-style: italic; margin-top: 5px;
            font-weight: 400; }
.rec-plan { display: grid; grid-template-columns: repeat(4, 1fr);
            border-top: 1px solid var(--line-soft); }
.rec-plan > div { padding: 10px 14px; border-right: 1px solid var(--line-soft); }
.rec-plan > div:last-child { border-right: 0; }
.rec-plan .k { font-size: 9px; font-family: var(--mono); letter-spacing: .09em;
               text-transform: uppercase; color: var(--faint); }
.rec-plan .v { font-size: 15px; font-weight: 700; margin-top: 3px; font-family: var(--mono); }
.rec-plan .s { font-size: 10px; color: var(--faint); }
.rec-why { padding: 11px 16px; font-size: 12px; color: var(--muted);
           border-top: 1px solid var(--line-soft); line-height: 1.5; }
@media (max-width: 720px) { .rec-plan { grid-template-columns: repeat(2, 1fr); } }

/* Gate panel — status is glyph AND colour AND value, never colour alone. */
.gates { padding: 0 16px 12px; }
.gate-row { margin-top: 10px; }
.gate-lbl { display: flex; justify-content: space-between; font-size: 9px;
            font-family: var(--mono); letter-spacing: .08em; text-transform: uppercase;
            color: var(--faint); margin-bottom: 5px; }
.gate-grid { display: grid; gap: 5px; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }
.gate { border-radius: var(--r-sm); padding: 6px 7px; text-align: center;
        border: 1px solid var(--line); background: var(--sunk); }
.gate.ok   { border-color: color-mix(in srgb, var(--up) 35%, transparent);   background: var(--up-soft); }
.gate.no   { border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: var(--warn-soft); }
.gate .n { font-size: 11px; font-weight: 800; }
.gate.ok .n { color: var(--up); } .gate.no .n { color: var(--warn); }
.gate .d { font-size: 9px; color: var(--muted); margin-top: 2px; line-height: 1.3; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md);
            background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; font-family: var(--mono); font-size: 10px; font-weight: 600;
  letter-spacing: .09em; text-transform: uppercase; color: var(--faint);
  padding: 11px 12px; border-bottom: 1px solid var(--line);
  background: var(--sunk); white-space: nowrap; position: sticky; top: 0;
}
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--sunk); }
td.r, th.r { text-align: right; }
td.c, th.c { text-align: center; }
.sym { font-weight: 700; }
.sub { font-size: 10px; color: var(--faint); font-weight: 400; }

/* Room-to-stop meter: five segments against the ORIGINAL risk budget. */
.room { display: inline-flex; gap: 2px; }
.room i { width: 9px; height: 7px; border-radius: 2px; background: var(--line); display: block; }
.room i.on { background: var(--tone, var(--up)); }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.fields { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.field { background: var(--surface); border: 1px solid var(--line);
         border-radius: var(--r-md); padding: 14px 16px; }
.field.dirty { border-color: var(--accent-line); }
.field-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.field label { font-size: 13.5px; font-weight: 700; }
.field .unit { font-size: 10px; color: var(--faint); font-family: var(--mono); }
.field .help { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.5; }
.field .caution { font-size: 11.5px; color: var(--warn); margin-top: 7px; line-height: 1.45;
                  background: var(--warn-soft); border-radius: 6px; padding: 7px 9px; }
.field .ctl { display: flex; align-items: center; gap: 10px; margin-top: 9px; }
input[type="number"], input[type="text"], select {
  background: var(--sunk); border: 1px solid var(--line); color: var(--ink);
  border-radius: var(--r-sm); padding: 8px 10px; font-size: 14px;
  font-family: var(--mono); width: 120px;
}
input:focus, select:focus, button:focus-visible, .nav a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.chip-default { font-size: 10px; color: var(--faint); font-family: var(--mono); }
.chip-changed { font-size: 10px; color: var(--accent); font-family: var(--mono); font-weight: 700; }

/* Switch */
.sw { position: relative; display: inline-block; width: 42px; height: 24px; flex: 0 0 42px; }
.sw input { opacity: 0; width: 0; height: 0; }
.sw span { position: absolute; inset: 0; background: var(--line); border-radius: 24px;
           cursor: pointer; transition: background .18s ease; }
.sw span::before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px;
                   top: 3px; background: var(--surface); border-radius: 50%;
                   transition: transform .18s ease; }
.sw input:checked + span { background: var(--accent); }
.sw input:checked + span::before { transform: translateX(18px); }
.sw input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--sunk); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 9px 15px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  font-family: var(--display); transition: background .14s ease, border-color .14s ease;
}
.btn:hover { border-color: var(--accent-line); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ── Notices ─────────────────────────────────────────────────────────────── */
.note-box { border-radius: var(--r-md); padding: 13px 16px; font-size: 13.5px;
            border: 1px solid var(--line); background: var(--surface); line-height: 1.5; }
.note-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent);
             color: var(--warn); }
.note-down { background: var(--down-soft); border-color: color-mix(in srgb, var(--down) 30%, transparent);
             color: var(--down); }
.note-ok   { background: var(--up-soft); border-color: color-mix(in srgb, var(--up) 30%, transparent);
             color: var(--up); }
.empty { color: var(--faint); font-size: 13.5px; font-style: italic; padding: 26px;
         text-align: center; }

/* ── Two-panel held card ─────────────────────────────────────────────────── */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 12px 12px; }
@media (max-width: 700px) { .split { grid-template-columns: 1fr; } }
.panel { border: 1px solid var(--line); border-top: 3px solid var(--tone, var(--muted));
         border-radius: var(--r-sm); padding: 11px 13px; background: var(--sunk); }
.panel h4 { margin: 0 0 7px; font-size: 9px; font-family: var(--mono); letter-spacing: .09em;
            text-transform: uppercase; color: var(--tone, var(--muted)); display: flex;
            justify-content: space-between; align-items: center; gap: 8px; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; padding: 2px 0; }
.kv .k { color: var(--faint); } .kv .v { font-weight: 700; font-family: var(--mono); }
.panel .foot { font-size: 11px; color: var(--muted); margin-top: 8px; line-height: 1.45; }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .side { width: auto; flex: none; height: auto; position: static;
          flex-direction: row; align-items: center; gap: 14px; overflow-x: auto;
          padding: 12px 14px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side-foot, .nav-label { display: none; }
  .nav { flex-direction: row; gap: 4px; }
  .nav a { white-space: nowrap; padding: 7px 11px; }
  .main { padding: 18px 16px 60px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
