/* quant-lab dashboard
 *
 * Rating colors are an ORDINAL DIVERGING scale (Buy -> Sell) with a deliberately
 * neutral midpoint at Hold, plus REVIEW as an off-scale state. Adjacent steps sit
 * close together on purpose -- that is what a ramp is -- so identity never rests on
 * color: every badge carries its rating word, and the scale color appears as a dot
 * beside high-contrast text rather than as the text itself.
 * Steps validated for contrast against both surfaces.
 */

:root {
  color-scheme: light;

  --bg: #fcfcfb;
  --surface: #ffffff;
  --surface-sunk: #f5f5f2;
  --ink: #1a1c1e;
  --ink-2: #4a5157;
  --muted: #656d75;   /* 4.9:1 on --bg; #767e86 measured 4.01:1 and failed AA */
  --line: #e4e3de;
  --line-soft: #efeeea;

  --accent: #2d5a6b;
  --accent-soft: #e6eef1;

  --buy: #0b7a57;
  --overweight: #52ad86;
  --hold: #79716b;
  --underweight: #dd7a4f;
  --sell: #b32d23;
  --review: #6a63c4;

  --warn-bg: #fdf3e2;
  --warn-line: #e8c98c;
  --warn-ink: #7a5710;

  --radius: 7px;
  --gutter: 20px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg: #16171a;
    --surface: #1d1f22;
    --surface-sunk: #232629;
    --ink: #e9eaec;
    --ink-2: #b6bcc2;
    --muted: #8b939b;
    --line: #2c3035;
    --line-soft: #24282c;

    --accent: #74b3c9;
    --accent-soft: #1b2e36;

    --buy: #2a9c74;
    --overweight: #4fa886;
    --hold: #8a827a;
    --underweight: #d08257;
    --sell: #d4574c;
    --review: #8079d8;

    --warn-bg: #2f2716;
    --warn-line: #5d4a1e;
    --warn-ink: #e0bd73;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16171a;
  --surface: #1d1f22;
  --surface-sunk: #232629;
  --ink: #e9eaec;
  --ink-2: #b6bcc2;
  --muted: #8b939b;
  --line: #2c3035;
  --line-soft: #24282c;
  --accent: #74b3c9;
  --accent-soft: #1b2e36;
  --buy: #2a9c74;
  --overweight: #4fa886;
  --hold: #8a827a;
  --underweight: #d08257;
  --sell: #d4574c;
  --review: #8079d8;
  --warn-bg: #2f2716;
  --warn-line: #5d4a1e;
  --warn-ink: #e0bd73;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Public Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }

/* ---- header ------------------------------------------------------------ */

.masthead { border-bottom: 1px solid var(--line); background: var(--surface); }
.masthead .wrap {
  padding-block: 20px 18px;
  display: flex; flex-wrap: wrap; gap: 12px 24px;
  align-items: baseline; justify-content: space-between;
}
.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
h1 {
  font-family: "Newsreader", ui-serif, Georgia, serif;
  font-size: 25px; font-weight: 500; margin: 0; letter-spacing: -0.01em;
}
.paper-tag {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-soft);
  padding: 3px 8px; border-radius: 3px; white-space: nowrap;
}
.stamps {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11.5px; color: var(--muted);
  display: flex; flex-wrap: wrap; gap: 4px 16px;
}

/* ---- landing ----------------------------------------------------------- */

.landing { padding-block: 26px 8px; }

.kpis {
  display: grid; gap: 1px; background: var(--line-soft);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.kpi { background: var(--surface); padding: 15px 18px 16px; }
.kpi-label {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 7px;
}
.kpi-value {
  font-family: "Newsreader", ui-serif, Georgia, serif;
  font-size: 27px; line-height: 1.1; font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.kpi-note { font-size: 12px; color: var(--muted); margin-top: 5px; }

.ratings-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }

.notice {
  margin-top: 18px; border: 1px solid var(--warn-line); background: var(--warn-bg);
  color: var(--warn-ink); border-radius: var(--radius); padding: 12px 15px;
  font-size: 13px;
}
.notice strong { font-weight: 600; }

/* ---- rating badges ----------------------------------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); border-radius: 100px;
  padding: 4px 12px 4px 9px; background: var(--surface);
  font-size: 12.5px; white-space: nowrap;
}
.badge .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.badge .tk { font-family: "JetBrains Mono", ui-monospace, monospace; font-weight: 500; }
.badge .rt { color: var(--ink-2); }

.r-buy         .dot { background: var(--buy); }
.r-overweight  .dot { background: var(--overweight); }
.r-hold        .dot { background: var(--hold); }
.r-underweight .dot { background: var(--underweight); }
.r-sell        .dot { background: var(--sell); }
.r-review      .dot { background: var(--review); }

.pill {
  display: inline-block; font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 10.5px; letter-spacing: .07em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 3px; border: 1px solid var(--line);
  color: var(--ink-2);
}

/* ---- tabs -------------------------------------------------------------- */

nav.tabs {
  display: flex; gap: 2px; margin-top: 30px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: thin;
  /* a fade on the right edge so a clipped fourth tab reads as scrollable, not truncated */
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 22px), transparent 100%);
          mask-image: linear-gradient(to right, #000 calc(100% - 22px), transparent 100%);
}
@media (min-width: 620px) {
  nav.tabs { -webkit-mask-image: none; mask-image: none; }
}
@media (max-width: 400px) {
  /* At and below this the fade either dims a tab that is barely cut (implying content that
     is not there) or lands on empty space with the fourth tab entirely unrendered. Wrap
     instead, keeping the left-aligned rhythm -- a stretched lone tab on row two reads as a
     rule rather than a tab. */
  nav.tabs { flex-wrap: wrap; overflow-x: visible;
             -webkit-mask-image: none; mask-image: none; }
  nav.tabs button { flex: 0 0 auto; padding: 9px 12px; }
}
nav.tabs button {
  font: inherit; font-size: 13.5px; color: var(--muted);
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 9px 14px; cursor: pointer; white-space: nowrap; margin-bottom: -1px;
}
nav.tabs button:hover { color: var(--ink); }
nav.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
nav.tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.panel { padding-block: 24px 60px; }
.panel h2 {
  font-family: "Newsreader", ui-serif, Georgia, serif;
  font-size: 19px; font-weight: 500; margin: 0 0 4px;
}
.panel .sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; max-width: 64ch; }

/* ---- tables ------------------------------------------------------------ */

.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line-soft); }
th {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); font-weight: 400; background: var(--surface-sunk);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
/* Keep data columns to their content so rows read as rows, not scattered cells, and let a
   trailing spacer absorb the leftover width. Handing the slack to the last real column put a
   ~780px void mid-row wherever that column was right-aligned. */
table th, table td { width: 1%; white-space: nowrap; }
table th.spacer, table td.spacer { width: auto; padding: 0; border-bottom-color: transparent; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums;
                 font-family: "JetBrains Mono", ui-monospace, monospace; }
td.tk { font-family: "JetBrains Mono", ui-monospace, monospace; font-weight: 500; }

/* ---- stat grid (backtest) ---------------------------------------------- */

.stats {
  display: grid; gap: 1px; background: var(--line-soft);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); margin-bottom: 22px;
}
.stat { background: var(--surface); padding: 13px 15px; }
.stat-label {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 5px;
}
.stat-value {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 17px; font-variant-numeric: tabular-nums;
}

/* ---- chart ------------------------------------------------------------- */

.chart-card {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); padding: 18px 18px 10px; position: relative;
}
.chart-head { display: flex; justify-content: space-between; align-items: baseline;
              gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.chart-title { font-size: 13px; font-weight: 500; }
.chart-meta { font-family: "JetBrains Mono", ui-monospace, monospace;
              font-size: 11px; color: var(--muted); }
svg.equity { display: block; width: 100%; height: auto; touch-action: pan-y; }
svg.equity .grid { stroke: var(--line-soft); stroke-width: 1; }
svg.equity .axis-text { fill: var(--muted); font-size: 10px;
                        font-family: "JetBrains Mono", ui-monospace, monospace; }
svg.equity .series { fill: none; stroke: var(--accent); stroke-width: 2;
                     stroke-linejoin: round; stroke-linecap: round; }
svg.equity .area { fill: var(--accent); opacity: .08; }
svg.equity .crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
svg.equity .cursor-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--line); border-radius: 5px;
  padding: 7px 10px; font-size: 12px; box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.tooltip .t-date { color: var(--muted); font-size: 11px;
                   font-family: "JetBrains Mono", ui-monospace, monospace; }
.tooltip .t-val { font-family: "JetBrains Mono", ui-monospace, monospace; }

/* ---- verdicts ---------------------------------------------------------- */

.verdict-list { display: grid; gap: 10px; }
.verdict {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  overflow: hidden;
}
.verdict-head {
  width: 100%; font: inherit; text-align: left; background: none; border: none;
  padding: 14px 16px; cursor: pointer; display: flex; align-items: center;
  gap: 12px; flex-wrap: wrap; color: inherit;
}
.verdict-head:hover { background: var(--surface-sunk); }
.verdict-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.verdict-head .tk { font-family: "JetBrains Mono", ui-monospace, monospace;
                    font-size: 15px; font-weight: 500; }
.verdict-head .spacer { flex: 1; }
.verdict-head .chev { color: var(--muted); font-size: 11px; }
.verdict-body { border-top: 1px solid var(--line-soft); padding: 4px 16px 18px; }

.md { font-size: 13.5px; color: var(--ink-2); max-width: 74ch; }
.md-scroll {
  max-height: 65vh; overflow-y: auto; overscroll-behavior: contain;
  max-width: 74ch;                       /* match .md so no dead strip eats wheel events */
  padding: 10px 14px; margin-top: 10px;
  border: 1px solid var(--line); border-radius: 5px;
  background: var(--surface-sunk);
  scrollbar-width: thin;
}
.md-scroll .md { max-width: none; }
.md h1, .md h2, .md h3, .md h4 {
  font-family: "Newsreader", ui-serif, Georgia, serif; color: var(--ink);
  font-weight: 500; line-height: 1.25;
}
.md h1 {
  font-size: 20px; margin: 30px 0 10px; padding-top: 14px;
  border-top: 1px solid var(--line);
}
.md h1:first-child { margin-top: 4px; padding-top: 0; border-top: none; }
.md h2 { font-size: 15.5px; margin: 26px 0 6px; }
.md h3 {
  font-family: "Public Sans", ui-sans-serif, system-ui, sans-serif;
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); font-weight: 600; margin: 18px 0 5px;
}
.md h4 { font-size: 13.5px; font-weight: 600; margin: 14px 0 4px; }
.md p { margin: 0 0 10px; }
.md ul { margin: 0 0 12px; padding-left: 20px; }
.md li { margin-bottom: 4px; }
.md strong { color: var(--ink); font-weight: 600; }
.md code {
  font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 12px;
  background: var(--surface-sunk); padding: 1px 5px; border-radius: 3px;
}
.md blockquote {
  margin: 0 0 12px; padding-left: 12px; border-left: 2px solid var(--line);
  color: var(--muted);
}

.report-tabs { display: flex; flex-wrap: wrap; gap: 2px; margin: 18px 0 0;
               border-bottom: 1px solid var(--line); }
.report-tabs button {
  font: inherit; font-size: 12.5px; background: none; border: none; cursor: pointer;
  color: var(--muted); padding: 7px 12px; border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.report-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.report-tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---- states ------------------------------------------------------------ */

.empty, .error {
  border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 30px 22px; text-align: center; color: var(--muted); font-size: 13.5px;
}
.error { border-style: solid; border-color: var(--sell); color: var(--ink-2); text-align: left; }
.error strong { display: block; color: var(--ink); margin-bottom: 6px; font-size: 14px; }
.error code {
  font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 12px;
  display: block; margin-top: 8px; color: var(--muted); word-break: break-word;
}
.loading { color: var(--muted); padding: 30px 0; text-align: center; font-size: 13.5px; }

.footnote { color: var(--muted); font-size: 12px; margin-top: 14px; max-width: 70ch; }

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

@media (max-width: 560px) {
  .verdict-head {
    display: grid; grid-template-columns: auto 1fr auto; gap: 6px 10px; align-items: center;
  }
  .verdict-head .spacer { display: none; }
  .verdict-head .badge { grid-column: 1 / -1; justify-self: start; }
  .verdict-head .pill { grid-column: 1; }
  .verdict-head .chev { grid-column: 3; grid-row: 1; justify-self: end; }
  .verdict-head .tk { grid-column: 1; grid-row: 1; }
  .md-scroll { max-height: 70vh; }
  h1 { font-size: 21px; }
  .kpi-value { font-size: 23px; }
  .masthead .wrap { padding-block: 16px 14px; }
}
