/* kavach.dashweb — mobile-first token system.
   Mirrors the project's report-artifact design language: near-neutral paper,
   one teal accent, tabular-nums, 1px-bordered cards. Light/dark via
   prefers-color-scheme, with an explicit [data-theme] override that wins. */

:root {
  --paper:      #f7f7f5;
  --card:       #ffffff;
  --ink:        #1c1d1f;
  --muted:      #6b6f76;
  --faint:      #9aa0a6;
  --line:       #e3e4e6;
  --line-soft:  #eeeef0;
  --accent:     #0e7467;
  --accent-bg:  rgba(14,116,103,0.08);
  --pos:        #1a7f4b;
  --neg:        #c0392b;
  --warn:       #b8791b;
  --warn-bg:    rgba(184,121,27,0.10);
  --live:       #1a7f4b;
  --paper-badge:#6b6f76;
  --radius:     12px;
  --shadow:     0 1px 2px rgba(0,0,0,0.04);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper:#131416; --card:#1c1e21; --ink:#e8e9ea; --muted:#9aa0a6; --faint:#6b6f76;
    --line:#2c2f33; --line-soft:#26282b; --accent:#3fbfae; --accent-bg:rgba(63,191,174,0.12);
    --pos:#4ecb83; --neg:#e5705f; --warn:#e0ad5b; --warn-bg:rgba(224,173,91,0.12);
    --live:#4ecb83; --shadow:0 1px 2px rgba(0,0,0,0.3);
  }
}
:root[data-theme="light"] {
  --paper:#f7f7f5; --card:#ffffff; --ink:#1c1d1f; --muted:#6b6f76; --faint:#9aa0a6;
  --line:#e3e4e6; --line-soft:#eeeef0; --accent:#0e7467; --accent-bg:rgba(14,116,103,0.08);
  --pos:#1a7f4b; --neg:#c0392b; --warn:#b8791b; --warn-bg:rgba(184,121,27,0.10);
  --live:#1a7f4b; --shadow:0 1px 2px rgba(0,0,0,0.04);
}
:root[data-theme="dark"] {
  --paper:#131416; --card:#1c1e21; --ink:#e8e9ea; --muted:#9aa0a6; --faint:#6b6f76;
  --line:#2c2f33; --line-soft:#26282b; --accent:#3fbfae; --accent-bg:rgba(63,191,174,0.12);
  --pos:#4ecb83; --neg:#e5705f; --warn:#e0ad5b; --warn-bg:rgba(224,173,91,0.12);
  --live:#4ecb83; --shadow:0 1px 2px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper); color: var(--ink); font-family: var(--sans);
  font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased;
  padding-bottom: 76px; /* room for the sticky bottom nav */
}
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
a { color: var(--accent); text-decoration: none; }

/* ── layout ─────────────────────────────────────────────────────────────── */
.wrap { max-width: 720px; margin: 0 auto; padding: 12px 14px 24px; }
header.app {
  position: sticky; top: 0; z-index: 20; background: var(--card);
  border-bottom: 1px solid var(--line); padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
header.app .brand { font-weight: 650; letter-spacing: -0.01em; display: flex; gap: 8px; align-items: baseline; }
header.app .brand small { color: var(--muted); font-weight: 500; font-size: 11px; }
header.app .who { color: var(--muted); font-size: 12px; display: flex; gap: 8px; align-items: center; }
.theme-toggle { background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 4px 8px; font-size: 13px; cursor: pointer; }

h1,h2,h3 { letter-spacing: -0.01em; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin: 18px 2px 8px; font-weight: 600; }

/* ── cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 10px; }
.grid.cards-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cards-3 { grid-template-columns: repeat(3, 1fr); }
@media (min-width: 560px) { .grid.cards-auto { grid-template-columns: repeat(3, 1fr); } }
.grid.cards-auto { grid-template-columns: repeat(2, 1fr); }

/* book strip card */
.book {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px 12px; display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.book.stale { border-color: var(--warn); }
.book.broken { border-color: var(--neg); }
.book .top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.book .name { font-size: 12px; color: var(--muted); font-weight: 600; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.book .pnl { font-size: 20px; font-weight: 650; letter-spacing: -0.02em; }
.book .sub { font-size: 11px; color: var(--faint); }
.book .warn { font-size: 11px; color: var(--warn); font-weight: 600; }

.badge { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 999px;
  border: 1px solid var(--line); white-space: nowrap; }
.badge.live { color: var(--live); border-color: color-mix(in srgb, var(--live) 40%, transparent); }
.badge.paper { color: var(--paper-badge); }
.badge.off { color: var(--faint); }

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }

/* ── open-trade cards ───────────────────────────────────────────────────── */
.trade { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
  background: var(--card); display: flex; flex-direction: column; gap: 8px; }
.trade .row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.trade .dir { font-weight: 650; }
.trade .dir.bull { color: var(--pos); }
.trade .dir.bear { color: var(--neg); }
.trade .legs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; font-size: 13px; }
.trade .legs .k { color: var(--muted); font-size: 11px; display: block; }
.chip { display: inline-flex; gap: 5px; align-items: center; font-size: 12px; font-weight: 600;
  padding: 3px 8px; border-radius: 999px; background: var(--accent-bg); color: var(--accent); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }

/* ── day plan ───────────────────────────────────────────────────────────── */
.regime { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.regime .chip-lg { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.regime .meta { color: var(--muted); font-size: 13px; }
.ruleset { margin: 6px 0 0; padding: 0; list-style: none; }
.ruleset li { padding: 6px 0 6px 20px; position: relative; border-top: 1px solid var(--line-soft);
  font-size: 14px; }
.ruleset li:first-child { border-top: none; }
.ruleset li::before { content: "›"; position: absolute; left: 4px; color: var(--accent); font-weight: 700; }
.plan-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.plan-head .engine { font-family: var(--mono); font-size: 12px; color: var(--accent);
  background: var(--accent-bg); padding: 2px 7px; border-radius: 6px; }

/* timeline */
.timeline { position: relative; height: 64px; margin: 14px 4px 6px; }
.timeline .track { position: absolute; top: 28px; left: 0; right: 0; height: 3px;
  background: var(--line); border-radius: 3px; }
.timeline .track .done { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent);
  border-radius: 3px; opacity: 0.5; }
.timeline .ev { position: absolute; top: 20px; transform: translateX(-50%); }
.timeline .ev .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted);
  border: 2px solid var(--card); margin: 0 auto; }
.timeline .ev.square_off .dot { background: var(--neg); }
.timeline .ev.cap_deadline .dot { background: var(--warn); }
.timeline .ev.market_open .dot { background: var(--accent); }
.timeline .ev.now .dot { background: var(--ink); width: 3px; height: 30px; border-radius: 2px; margin-top: -10px; }
.timeline .ev .lbl { font-size: 9px; color: var(--faint); white-space: nowrap; text-align: center;
  margin-top: 2px; }
.timeline .ev .tm { font-size: 10px; color: var(--muted); text-align: center; }
.timeline-legend { font-size: 11px; color: var(--faint); display: flex; gap: 12px; flex-wrap: wrap; margin-top: 2px; }

.warn-banner { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn);
  border-radius: 10px; padding: 8px 12px; font-size: 13px; margin: 10px 0; }

/* ── charts ─────────────────────────────────────────────────────────────── */
.chart-box { height: 300px; width: 100%; }
.chart-empty { color: var(--muted); font-size: 13px; padding: 40px 0; text-align: center; }

/* ── Today's trades (Charts tab) — grouped per-book cards ─────────────────── */
.tt-books { display: flex; flex-direction: column; gap: 16px; }
.tt-book { display: flex; flex-direction: column; gap: 8px; }
.tt-book-head { display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px; border-bottom: 1px solid var(--line); padding-bottom: 5px; }
.tt-book-label { font-size: 13px; font-weight: 650; color: var(--ink); letter-spacing: -0.01em; }
.tt-nd { font-size: 12px; font-style: italic; }
.tt-empty { font-size: 12px; padding: 2px 2px 4px; }
.tt-cards { display: grid; gap: 10px; }
@media (min-width: 560px) { .tt-cards { grid-template-columns: repeat(2, 1fr); } }
.tt-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
  background: var(--card); display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow); }
.tt-card .dir { font-weight: 650; }
.tt-card .dir.bull { color: var(--pos); }
.tt-card .dir.bear { color: var(--neg); }
.tt-card .row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tt-card .legs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; font-size: 13px; }
.tt-card .legs .k { color: var(--muted); font-size: 11px; display: block; }
.tt-meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 11px; align-items: center; }
.tt-chart-wrap { border-top: 1px solid var(--line-soft); padding-top: 8px; }
.tt-chart { display: none; }                 /* mobile: no ECharts bundle */
.tt-chart-note { font-size: 11px; }
@media (min-width: 900px) {
  .tt-cards { grid-template-columns: 1fr; }  /* full-width so the chart has room */
  .tt-chart { display: block; height: 360px; width: 100%; }
  .tt-chart-note { display: none; }
}
select, .btn { font-family: var(--sans); font-size: 14px; }
select { background: var(--card); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; }

/* ── tables ─────────────────────────────────────────────────────────────── */
.tbl-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
table.data th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }

/* ── bottom nav ─────────────────────────────────────────────────────────── */
nav.bottom {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--card); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
nav.bottom a { color: var(--muted); display: flex; flex-direction: column; align-items: center;
  gap: 2px; font-size: 10px; padding: 4px 12px; border-radius: 10px; min-width: 56px; }
nav.bottom a .ic { font-size: 19px; line-height: 1; }
nav.bottom a.active { color: var(--accent); background: var(--accent-bg); }

/* ── desktop shell (Stage 2) ──────────────────────────────────────────────
   Everything below is ADDITIVE: the left rail, the desktop-only analysis
   bodies and the wider canvas are hidden by default (mobile-first, layout
   byte-for-byte the same) and only turned on inside @media (min-width: 900px).
   No existing mobile rule above is modified. */

/* hidden on mobile by default */
nav.rail { display: none; }
.desktop-only { display: none; }
.mobile-note { display: block; }

/* analysis-tab chrome (only ever visible at desktop width) */
.analysis-head { display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; margin-bottom: 10px; }
.param-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.param-bar .param { font-size: 12px; color: var(--muted); background: var(--card);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.param-bar .param b { color: var(--ink); font-weight: 600; }
.chart-box-lg { height: 420px; width: 100%; }
.chart-box-xl { height: 480px; width: 100%; }

/* interactive param form (Trade Inspector) */
.param-form { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end;
  margin-bottom: 14px; padding: 12px 14px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); }
.param-form .pf { display: flex; flex-direction: column; gap: 4px; }
.param-form .pf > span { font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 600; }
.param-form .pf input[type=number] { width: 78px; }
.param-form .pf input, .param-form .pf select { font-family: var(--sans); font-size: 13px;
  background: var(--card); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 8px; }
.param-form .pf.check { flex-direction: row; align-items: center; gap: 6px; }
.param-form .pf.check > span { text-transform: none; letter-spacing: 0; font-size: 12px; }

/* headline metric tiles */
.insp-metrics { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px;
  margin-bottom: 16px; }
.metric { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; box-shadow: var(--shadow); }
.metric .k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); font-weight: 600; }
.metric .v { font-size: 19px; font-weight: 650; letter-spacing: -0.01em; margin-top: 2px; }

/* per-trade chart sections */
.trade-section { margin-bottom: 16px; }
.trade-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  margin-bottom: 8px; font-size: 13px; }
.trade-head .dir { font-weight: 650; }
.trade-head .pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line); }

@media (min-width: 900px) {
  body { padding-bottom: 24px; }               /* no bottom-nav gutter on desktop */

  nav.bottom { display: none; }                /* mobile bottom nav → hidden */

  nav.rail {
    display: flex; flex-direction: column; gap: 2px;
    position: fixed; top: 45px; left: 0; bottom: 0; width: 208px; z-index: 15;
    background: var(--card); border-right: 1px solid var(--line);
    padding: 14px 10px; overflow-y: auto;
  }
  nav.rail a { color: var(--muted); display: flex; align-items: center; gap: 10px;
    font-size: 14px; padding: 9px 12px; border-radius: 10px; }
  nav.rail a .ic { font-size: 18px; line-height: 1; width: 20px; text-align: center; }
  nav.rail a.active { color: var(--accent); background: var(--accent-bg); font-weight: 600; }
  nav.rail a:hover { background: var(--line-soft); }
  nav.rail .rail-sec { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--faint); font-weight: 700; margin: 16px 12px 4px; }

  .wrap { margin: 0 auto 0 208px; max-width: 1240px; padding: 22px 40px 32px; }

  .desktop-only { display: block; }            /* analysis body → shown */
  .mobile-note { display: none; }              /* "best viewed on desktop" → hidden */

  .grid.cards-auto { grid-template-columns: repeat(3, 1fr); }
}

/* ── COT tab (slice 4) ─────────────────────────────────────────────────────
   Additive only: the Buy/Sell COT ladder + interval-totals tables. Reuses the
   .tbl-scroll wrapper; adds COT-specific cell classes for the extraordinary-
   value highlight (green buy / red sell), the sign-coloured NET DELTA (DAY)
   row, the warm ATM tint, per-strike zebra and the group divider. */
.cot-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.cot-controls label { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.cot-controls output { font-variant-numeric: tabular-nums; color: var(--ink); min-width: 2.2em; }
.cot-caption { font-size: 12px; color: var(--muted); margin: 6px 2px 0; }
.cot-scroll { overflow: auto; max-height: 900px; border: 1px solid var(--line); border-radius: 8px; }
.cot-scroll.totals { max-height: 420px; }

table.cot { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px;
  font-variant-numeric: tabular-nums; }
table.cot th, table.cot td { padding: 4px 9px; border-bottom: 1px solid var(--line-soft);
  white-space: nowrap; text-align: right; }
/* sticky header row (position + opaque bg only) */
table.cot thead th { position: sticky; top: 0; z-index: 3; background: var(--card);
  color: var(--muted); font-weight: 600; text-align: center; border-bottom: 1px solid var(--line); }
/* the two frozen left columns: position only — their fill comes from the row
   class below (so zebra/ATM tint show through), never a bg set here. */
table.cot th.cot-rowlabel { position: sticky; left: 0; z-index: 2; text-align: left;
  font-weight: 600; color: var(--ink); min-width: 84px; }
table.cot th.cot-metric { position: sticky; left: 84px; z-index: 2; text-align: left;
  font-weight: 600; color: var(--muted); font-style: italic; font-size: 12px; }
table.cot thead th.cot-corner { left: 0; z-index: 4; background: var(--card); }

/* row backgrounds — also fill the sticky columns (higher specificity than the
   bg-less sticky rules above) */
table.cot tbody tr.cot-za > * { background: var(--card); }
table.cot tbody tr.cot-zb > * { background: var(--line-soft); }
table.cot tbody tr.cot-atm > * { background: var(--warn-bg); }
table.cot tbody tr.cot-group > * { border-top: 2px solid var(--faint); }

/* extraordinary-value highlight — fixed light green/red with dark text so it
   reads on both themes (legacy #8fe38f / #ff9a9a). */
table.cot td.cot-green { background: #8fe38f !important; color: #10240f; font-weight: 600; }
table.cot td.cot-red   { background: #ff9a9a !important; color: #2a0d0d; font-weight: 600; }
table.cot td.cot-netpos { color: var(--pos); font-weight: 700; }
table.cot td.cot-netneg { color: var(--neg); font-weight: 700; }

/* ── login ──────────────────────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input[type=text], .field input[type=password] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--paper); color: var(--ink); font-size: 15px; }
.field.check { display: flex; align-items: center; gap: 8px; }
.btn { display: inline-block; width: 100%; text-align: center; background: var(--accent);
  color: #fff; border: none; border-radius: 10px; padding: 11px 14px; font-weight: 600;
  cursor: pointer; font-size: 15px; }
.err { background: var(--warn-bg); color: var(--neg); border: 1px solid var(--neg);
  border-radius: 10px; padding: 9px 12px; font-size: 13px; margin-bottom: 12px; }
.logout-btn { background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
