/* ==========================================================================
   Asymmetric — investor console
   "The private-office ledger": calm, moneyed, precise. Cool porcelain / graphite
   grounds (not warm cream), a brass accent kept separate from semantic gain/loss,
   a system serif for titles, tabular figures. Light + dark, no external assets.
   ========================================================================== */

/* ---- reset --------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
a { color: inherit; }

/* ---- design tokens ------------------------------------------------------- */
:root {
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;

  --ground: #e9ece7;
  --surface: #f5f6f2;
  --surface-2: #fcfcf9;
  --ink: #1a1d22;
  --ink-muted: #59606a;
  --ink-faint: #6d747e;   /* AA-legible on light grounds (~4.5:1 on --surface) */
  --hairline: #d6d9d1;
  --hairline-strong: #c2c6bc;

  --accent: #8f6d2c;
  --accent-line: #a07d38;
  --accent-soft: rgba(143, 109, 44, 0.12);
  --on-accent: #fbfaf5;

  --gain: #1c7d51;
  --gain-soft: rgba(28, 125, 81, 0.12);
  --loss: #b23b34;
  --loss-soft: rgba(178, 59, 52, 0.12);
  --warn: #9c6b16;
  --warn-soft: rgba(156, 107, 22, 0.13);

  --grid-line: rgba(26, 29, 34, 0.06);
  --shadow: 0 1px 2px rgba(20, 22, 28, 0.05), 0 10px 28px rgba(20, 22, 28, 0.05);
  --radius: 12px;
  --radius-sm: 8px;
  --maxw: 1220px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #111418;
    --surface: #181c22;
    --surface-2: #1d222a;
    --ink: #e6e8e3;
    --ink-muted: #99a0a9;
    --ink-faint: #8a919b;
    --hairline: #272d35;
    --hairline-strong: #333a44;

    --accent: #c6a35d;
    --accent-line: #cfae6a;
    --accent-soft: rgba(198, 163, 93, 0.15);
    --on-accent: #16130c;

    --gain: #46b784;
    --gain-soft: rgba(70, 183, 132, 0.15);
    --loss: #e0736a;
    --loss-soft: rgba(224, 115, 106, 0.15);
    --warn: #d1a24b;
    --warn-soft: rgba(209, 162, 75, 0.15);

    --grid-line: rgba(230, 232, 227, 0.06);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 14px 34px rgba(0, 0, 0, 0.38);
  }
}

:root[data-theme="dark"] {
  --ground: #111418;
  --surface: #181c22;
  --surface-2: #1d222a;
  --ink: #e6e8e3;
  --ink-muted: #99a0a9;
  --ink-faint: #666d76;
  --hairline: #272d35;
  --hairline-strong: #333a44;

  --accent: #c6a35d;
  --accent-line: #cfae6a;
  --accent-soft: rgba(198, 163, 93, 0.15);
  --on-accent: #16130c;

  --gain: #46b784;
  --gain-soft: rgba(70, 183, 132, 0.15);
  --loss: #e0736a;
  --loss-soft: rgba(224, 115, 106, 0.15);
  --warn: #d1a24b;
  --warn-soft: rgba(209, 162, 75, 0.15);

  --grid-line: rgba(230, 232, 227, 0.06);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 14px 34px rgba(0, 0, 0, 0.38);
}

/* ---- base ---------------------------------------------------------------- */
body {
  font-family: var(--sans);
  background: var(--ground);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  user-select: none;             /* serious-app chrome; data marked selectable */
}
.selectable, input, textarea, [data-selectable] { user-select: text; }

.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

.eyebrow {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
h1, h2, h3 { font-weight: 600; text-wrap: balance; }

.up { color: var(--gain); }
.down { color: var(--loss); }
.flat { color: var(--ink-muted); }

/* ---- top bar ------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: var(--ground);   /* fallback if color-mix() unsupported */
  background: color-mix(in srgb, var(--ground) 86%, transparent);
  backdrop-filter: saturate(1.1) blur(10px);
  -webkit-backdrop-filter: saturate(1.1) blur(10px);
  border-bottom: 1px solid var(--hairline);
}
.brand { display: flex; flex-direction: column; line-height: 1.05; margin-right: auto; }
.brand__mark {
  font-family: var(--serif);
  font-size: 22px; font-weight: 600; letter-spacing: 0.01em;
}
.brand__mark::first-letter { color: var(--accent); }
.brand__tag { font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint); margin-top: 2px; }

.topbar__status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar__tools { display: flex; align-items: center; gap: 14px; }
.clock { font-size: 12.5px; color: var(--ink-muted); }

.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  border: 1px solid var(--hairline); border-radius: 9px; color: var(--ink-muted);
  transition: border-color .15s, color .15s, background .15s;
}
.icon-btn:hover { color: var(--ink); border-color: var(--hairline-strong); background: var(--surface); }

/* ---- badges & chips ------------------------------------------------------ */
.badge, .chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.01em;
  padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--hairline-strong);
  white-space: nowrap;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-faint); flex: none; }
.dot--on { background: var(--gain); box-shadow: 0 0 0 3px var(--gain-soft); }
.dot--off { background: var(--ink-faint); }
.dot--warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }

.regime-badge[data-regime="on"]      { color: var(--gain); background: var(--gain-soft); border-color: transparent; }
.regime-badge[data-regime="off"]     { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.regime-badge[data-regime="unknown"] { color: var(--ink-muted); background: transparent; }

/* ---- layout grid --------------------------------------------------------- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: clamp(16px, 3vw, 30px) clamp(16px, 4vw, 40px) 60px; }
.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: clamp(14px, 1.6vw, 20px); }

.panel {
  grid-column: span 12;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: clamp(18px, 2vw, 26px);
  box-shadow: var(--shadow);
  min-width: 0;
}
.panel__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel__title { font-family: var(--serif); font-size: 19px; }
.panel__meta { font-size: 12px; color: var(--ink-faint); }

.col-4 { grid-column: span 4; }
.col-5 { grid-column: span 5; }
.col-6 { grid-column: span 6; }
.col-7 { grid-column: span 7; }
.col-8 { grid-column: span 8; }
@media (max-width: 940px) { .col-4, .col-5, .col-6, .col-7, .col-8 { grid-column: span 12; } }

/* ---- notice banner ------------------------------------------------------- */
.notice {
  grid-column: span 12;
  display: flex; align-items: flex-start; gap: 12px;
  padding: 13px 18px; border-radius: var(--radius-sm);
  background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  color: var(--ink); font-size: 13.5px;
}
.notice[hidden] { display: none; }   /* class display:flex would otherwise defeat [hidden] */
.notice strong { color: var(--warn); }
.notice__x { margin-left: auto; color: var(--ink-faint); font-size: 18px; line-height: 1; cursor: pointer; }

/* ---- hero (north-star) --------------------------------------------------- */
.hero { display: flex; flex-direction: column; gap: 4px; }
.hero__value {
  font-family: var(--serif);
  font-size: clamp(38px, 6.2vw, 58px); font-weight: 600; letter-spacing: -0.01em; line-height: 1;
  margin: 6px 0 2px;
}
.hero__row { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-top: 6px; }
.hero__delta { font-size: 16px; font-weight: 600; }
.hero__vs { font-size: 13px; color: var(--ink-muted); }
.hero__state {
  margin-top: 16px; display: inline-flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--ink-muted);
  padding: 7px 12px; border: 1px dashed var(--hairline-strong); border-radius: var(--radius-sm); align-self: flex-start;
}

/* ---- verdict card -------------------------------------------------------- */
.verdict { display: flex; flex-direction: column; height: 100%; }
.verdict__status {
  display: inline-flex; align-items: center; gap: 8px; align-self: flex-start;
  font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 5px 11px; border-radius: 999px; margin-bottom: 14px;
}
.verdict__status[data-s="validated"] { color: var(--gain); background: var(--gain-soft); }
.verdict__status[data-s="pending"]   { color: var(--warn); background: var(--warn-soft); }
.verdict__status[data-s="error"]     { color: var(--loss); background: var(--loss-soft); }
.verdict__text { font-size: 14.5px; color: var(--ink); line-height: 1.55; }
.verdict__text .lede { font-family: var(--serif); font-size: 17px; display: block; margin-bottom: 6px; }
.verdict__actions { margin-top: auto; padding-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ---- buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--hairline-strong); color: var(--ink);
  transition: border-color .15s, background .15s, transform .1s;
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-faint); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); border-color: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .icon-btn:focus-visible, .btn-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-link { color: var(--accent); font-size: 13px; font-weight: 600; text-decoration: none; border-bottom: 1px solid transparent; }
.btn-link:hover { border-bottom-color: currentColor; }

/* ---- stat tiles ---------------------------------------------------------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.tile { padding: 14px 16px; border: 1px solid var(--hairline); border-radius: var(--radius-sm); background: var(--surface-2); }
.tile__label { font-size: 10.5px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint); }
.tile__value { font-size: 24px; font-weight: 600; margin-top: 6px; font-family: var(--serif); }
.tile__sub { font-size: 11.5px; color: var(--ink-muted); margin-top: 2px; }

/* ---- performance / chart ------------------------------------------------- */
.perf-layout { display: grid; grid-template-columns: 1.7fr 1fr; gap: clamp(16px, 2vw, 26px); align-items: stretch; }
@media (max-width: 820px) { .perf-layout { grid-template-columns: 1fr; } }
.chart-wrap { position: relative; min-width: 0; }
.chart-legend { display: flex; gap: 16px; margin-bottom: 10px; font-size: 12px; color: var(--ink-muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend-swatch { width: 14px; height: 3px; border-radius: 2px; }
.legend-swatch--port { background: var(--accent-line); }
.legend-swatch--bench { background: var(--ink-faint); }
.chart-svg { width: 100%; height: auto; overflow: visible; }
.chart-tooltip {
  position: absolute; pointer-events: none; opacity: 0; transition: opacity .1s;
  background: var(--surface-2); border: 1px solid var(--hairline-strong); border-radius: 8px;
  padding: 8px 11px; font-size: 12px; box-shadow: var(--shadow); z-index: 5; white-space: nowrap;
}
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 8px; }
.chart-tooltip .tt-date { color: var(--ink-faint); font-size: 11px; margin-bottom: 4px; }

/* ---- holdings table ------------------------------------------------------ */
.table-scroll { overflow-x: auto; margin: 0 -6px; }
table.holdings { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.holdings th {
  text-align: right; font-size: 10.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-faint); padding: 0 10px 10px; border-bottom: 1px solid var(--hairline); white-space: nowrap;
}
.holdings th:first-child, .holdings td:first-child { text-align: left; padding-left: 6px; }
.holdings td { padding: 11px 10px; border-bottom: 1px solid var(--hairline); text-align: right; white-space: nowrap; }
.holdings tr:last-child td { border-bottom: none; }
.holdings .sym { font-weight: 600; letter-spacing: 0.01em; }
.holdings .weight-cell { width: 30%; min-width: 130px; }
.weight-bar { position: relative; height: 6px; border-radius: 3px; background: var(--accent-soft); overflow: hidden; }
.weight-bar > i { position: absolute; inset: 0 auto 0 0; background: var(--accent-line); opacity: .75; border-radius: 3px; }
.weight-num { font-size: 11.5px; color: var(--ink-muted); margin-top: 4px; display: block; text-align: left; }

/* ---- strategy panel ------------------------------------------------------ */
.strat-grid { display: flex; flex-direction: column; gap: 16px; }
.strat-line { display: flex; justify-content: space-between; gap: 14px; font-size: 13.5px; padding-bottom: 12px; border-bottom: 1px solid var(--hairline); }
.strat-line:last-child { border-bottom: none; padding-bottom: 0; }
.strat-line dt { color: var(--ink-muted); }
.strat-line dd { text-align: right; font-weight: 500; }
.factor { padding: 12px 14px; border: 1px solid var(--hairline); border-radius: var(--radius-sm); background: var(--surface-2); }
.factor h4 { font-size: 13.5px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.factor p { font-size: 12.5px; color: var(--ink-muted); margin-top: 4px; }
.factor .tag { font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); background: var(--accent-soft); padding: 2px 7px; border-radius: 5px; }
.filter-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.filter-list li { font-size: 13px; color: var(--ink-muted); display: flex; gap: 9px; }
.filter-list li::before { content: ""; width: 5px; height: 5px; margin-top: 8px; border-radius: 50%; background: var(--accent); flex: none; }

/* ---- health rows (broker / feed / alerts) -------------------------------- */
.health-list { display: flex; flex-direction: column; }
.health-row { display: flex; align-items: center; gap: 12px; padding: 13px 2px; border-bottom: 1px solid var(--hairline); }
.health-row:last-child { border-bottom: none; }
.health-row__label { font-size: 13.5px; font-weight: 500; }
.health-row__sub { font-size: 12px; color: var(--ink-faint); }
.health-row__state { margin-left: auto; display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600; }
.state-ok { color: var(--gain); }
.state-bad { color: var(--loss); }
.state-warn { color: var(--warn); }
.state-idle { color: var(--ink-faint); }

/* ---- activity ------------------------------------------------------------ */
.activity { display: flex; flex-direction: column; gap: 0; }
.activity__row { display: flex; gap: 14px; padding: 11px 2px; border-bottom: 1px solid var(--hairline); font-size: 13px; }
.activity__row:last-child { border-bottom: none; }
.activity__time { color: var(--ink-faint); font-size: 12px; white-space: nowrap; min-width: 58px; }
.activity__msg { color: var(--ink-muted); }

/* ---- empty states -------------------------------------------------------- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 34px 20px; color: var(--ink-muted); }
.empty__icon { width: 40px; height: 40px; color: var(--ink-faint); opacity: .8; }
.empty__title { font-family: var(--serif); font-size: 16px; color: var(--ink); }
.empty__body { font-size: 13px; max-width: 340px; }

/* ---- sample-mode ribbon -------------------------------------------------- */
.sample-ribbon {
  grid-column: span 12; display: none; align-items: center; gap: 10px;
  font-size: 12.5px; color: var(--ink); background: var(--accent-soft);
  border: 1px dashed color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: var(--radius-sm); padding: 9px 16px;
}
body[data-demo="1"] .sample-ribbon { display: flex; }
.sample-ribbon strong { color: var(--accent); letter-spacing: 0.04em; }
.sample-ribbon code { font-family: var(--mono); font-size: 11.5px; }

/* per-card 'SAMPLE' stamp so no single card is mistakable for real */
.sample-tag {
  display: inline-block; font-size: 9.5px; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--accent); background: var(--accent-soft);
  padding: 2px 7px; border-radius: 5px; vertical-align: middle; margin-left: 8px;
}

/* manual holdings entry — the bridge while Sharekhan denies API account data */
.hold-form { display: flex; flex-direction: column; gap: 12px; }
.hold-form__lede { font-size: 13px; color: var(--ink-muted); }
.hold-form__lede code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.hold-textarea {
  width: 100%; resize: vertical; font-size: 13.5px; line-height: 1.7; padding: 12px 14px;
  border: 1px solid var(--hairline-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink);
}
.hold-textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.hold-form__actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hold-form__err { font-size: 12.5px; color: var(--loss); }
.hold-note { font-size: 12px; color: var(--ink-faint); margin-top: 10px; }

/* ---- footer -------------------------------------------------------------- */
.foot { max-width: var(--maxw); margin: 0 auto; padding: 20px clamp(16px, 4vw, 40px) 40px; display: flex; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--ink-faint); border-top: 1px solid var(--hairline); }
.foot a { color: var(--ink-muted); text-decoration: none; }
.foot a:hover { color: var(--ink); }

/* ---- motion -------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
