/* MP Insights — base stylesheet.
   Tokens live on :root. Dark values are redefined, never defined only there. */

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --border: #e2e2dd;
  --text: #1a1a18;
  --muted: #6b6b65;
  --accent: #1d4ed8;
  --accent-text: #ffffff;
  --ok-bg: #e7f5ec;  --ok-text: #14532d;
  --warn-bg: #fdf3e0; --warn-text: #7c4a03;
  --off-bg: #eeeeea;  --off-text: #5a5a55;
  --error-bg: #fdecec; --error-text: #8a1c1c;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17181a;
    --surface: #1f2023;
    --border: #33353a;
    --text: #ececea;
    --muted: #9a9a95;
    --accent: #7ea2ff;
    --accent-text: #10131c;
    --ok-bg: #16301f;  --ok-text: #a8e6bf;
    --warn-bg: #33270f; --warn-text: #f0c67a;
    --off-bg: #26272b;  --off-text: #9a9a95;
    --error-bg: #3a1a1a; --error-text: #f3b0b0;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Layout ------------------------------------------------------------------ */

.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 650; }
.topbar nav { display: flex; gap: 16px; margin-right: auto; }
.topbar a { color: var(--text); text-decoration: none; }
.topbar a:hover { text-decoration: underline; }
.topbar .who { color: var(--muted); font-size: 13px; margin-right: 10px; }

.wrap { max-width: 980px; margin: 0 auto; padding: 28px 20px 60px; }
.centre {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}

h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 17px; margin: 32px 0 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card.narrow { width: 100%; max-width: 420px; }

/* Forms ------------------------------------------------------------------- */

label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 4px; }
input, select, textarea {
  width: 100%; padding: 9px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text);
  font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea:disabled, input:disabled, button:disabled { opacity: .55; cursor: not-allowed; }

button {
  font: inherit; cursor: pointer;
  padding: 9px 16px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
button.primary {
  margin-top: 18px;
  background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600;
}
button.link {
  background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline;
}
form.inline { display: inline; }
.filters { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 14px; }
.filters label { margin: 0; }
.filters select { width: auto; min-width: 180px; }

/* Messages ---------------------------------------------------------------- */

.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.error, .success, .notice {
  padding: 10px 12px; border-radius: 6px; margin: 14px 0; font-size: 14px;
}
.error   { background: var(--error-bg); color: var(--error-text); }
.success { background: var(--ok-bg);    color: var(--ok-text); }
.notice  { background: var(--warn-bg);  color: var(--warn-text); }

code.temp { font-size: 15px; font-weight: 700; letter-spacing: .5px; }

.pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; margin-right: 4px;
}
.pill.ok   { background: var(--ok-bg);   color: var(--ok-text); }
.pill.warn { background: var(--warn-bg); color: var(--warn-text); }
.pill.off  { background: var(--off-bg);  color: var(--off-text); }

.checks { padding-left: 20px; color: var(--muted); }
.checks li { margin: 4px 0; }

/* Tables ------------------------------------------------------------------ */

table {
  width: 100%; border-collapse: collapse; margin-top: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
tr:last-child td { border-bottom: none; }

/* Wide content scrolls inside itself. The page body never scrolls sideways. */
main { overflow-x: auto; }

/* Conversations ------------------------------------------------------------ */

.turn { margin: 14px 0; }
.turn-label {
  font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); margin-bottom: 8px;
}
.user-turn { background: var(--bg); }
.question-text { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Rendered Markdown from the model. */
.answer { overflow-wrap: break-word; }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer p { margin: 0 0 12px; }
.answer h2 { font-size: 16px; margin: 20px 0 8px; }
.answer h3 { font-size: 14px; margin: 16px 0 6px; }
.answer ul, .answer ol { margin: 0 0 12px; padding-left: 22px; }
.answer li { margin: 3px 0; }
.answer code {
  background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 4px; font-size: 13px;
}
.answer pre { margin: 0 0 12px; }
.answer pre code { background: none; border: none; padding: 0; }
.answer blockquote {
  margin: 0 0 12px; padding-left: 12px;
  border-left: 3px solid var(--border); color: var(--muted);
}
.answer hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

/* A wide table scrolls inside its own box. The page never scrolls sideways. */
.answer table {
  display: block; width: max-content; max-width: 100%;
  overflow-x: auto; margin: 0 0 14px;
}
.answer th, .answer td { white-space: nowrap; }
/* Numbers read better right-aligned, and these tables are mostly numbers. */
.answer td + td, .answer th + th { text-align: right; }
.turn-meta { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }

details.calls { margin: 0 0 18px; }
details.calls > summary {
  cursor: pointer; font-size: 13px; color: var(--muted);
  padding: 6px 0;
}
.call { border-left: 2px solid var(--border); padding: 8px 0 8px 12px; margin: 8px 0; }
.call-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.call-body strong { display: block; margin: 8px 0 2px; color: var(--muted); }
pre {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 10px; overflow-x: auto; font-size: 12px; margin: 0;
  max-height: 340px;
}

/* Progress ----------------------------------------------------------------- */

.progress { border-left: 3px solid var(--accent); }
.progress-row { display: flex; align-items: center; gap: 10px; }

.spinner {
  width: 14px; height: 14px; flex: none;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.progress:not(.running) .spinner { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }

/* Respect a reader who asked for less motion. */
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-top-color: var(--border); }
}

/* Dashboards --------------------------------------------------------------- */
/* Series colours come from the dataviz reference palette. Both columns were
   checked with its validator: lightness band, chroma floor, colour-vision
   separation and contrast all pass. Assign slots in order; never cycle a 9th. */

:root {
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #4a3aa7; --series-8: #e34948;
  --viz-grid: #e1e0d9;
  --viz-axis-ink: #898781;
  --viz-surface: #fcfcfb;
  --delta-good: #006300;
  --delta-bad: #8a1c1c;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --viz-grid: #2c2c2a;
    --viz-axis-ink: #898781;
    --viz-surface: #1a1a19;
    --delta-good: #0ca30c;
    --delta-bad: #f3b0b0;
  }
}

.dash-actions { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.dash-head { border-bottom: 2px solid var(--border); padding-bottom: 14px; margin-bottom: 18px; }
.dash-head h1 { font-size: 26px; margin: 0 0 4px; }
.dash-sub { margin: 0 0 6px; color: var(--muted); }
.dash-meta { margin: 0; font-size: 13px; color: var(--muted); }
.dash-headline { font-size: 17px; line-height: 1.5; margin: 0 0 22px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 26px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.kpi-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kpi-value { font-size: 26px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-unit { font-size: 14px; font-weight: 400; color: var(--muted); margin-left: 3px; }
.kpi-delta { font-size: 13px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi-delta.good { color: var(--delta-good); }
.kpi-delta.bad  { color: var(--delta-bad); }
.kpi-delta.flat { color: var(--muted); }
.kpi-cmp { color: var(--muted); margin-left: 4px; }

/* Charts. Text wears ink tokens; only the marks carry series colour. */
.viz { margin: 0 0 26px; padding: 0; }
.viz figcaption { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.viz svg { width: 100%; height: auto; display: block; background: var(--viz-surface);
           border: 1px solid var(--border); border-radius: var(--radius); }
.viz-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.viz-key { display: inline-flex; align-items: center; gap: 6px; }
.viz-swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.viz-axis-title { font-size: 12px; color: var(--muted); margin: 0 0 4px; }
.viz-note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }

.viz-grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz-axis { font-size: 11px; fill: var(--viz-axis-ink); font-family: inherit; }
.viz-line { stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-dot  { stroke: var(--viz-surface); stroke-width: 2; }
.viz-slice { stroke: var(--viz-surface); stroke-width: 2; }

.dash-table { margin-bottom: 26px; }
.dash-table h2, .dash-prose h2, .dash-foot h2 { font-size: 15px; margin: 0 0 8px; }
.table-scroll { overflow-x: auto; }
.dash-table td + td, .dash-table th + th { text-align: right; font-variant-numeric: tabular-nums; }
.dash-prose { margin-bottom: 22px; }
.recs { padding-left: 20px; }
.recs li { margin-bottom: 12px; }
.dash-foot { border-top: 1px solid var(--border); margin-top: 30px; padding-top: 16px; color: var(--muted); }
.dash-foot ul { padding-left: 20px; }

.print-only { display: none; }

/* Print -------------------------------------------------------------------- */

@page { size: A4; margin: 15mm; }

@media print {
  /* Always print the light palette, whatever the reader's screen theme. */
  :root {
    --bg: #ffffff; --surface: #ffffff; --border: #cccccc;
    --text: #000000; --muted: #444444;
    --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
    --series-5: #e87ba4; --series-6: #008300; --series-7: #4a3aa7; --series-8: #e34948;
    --viz-grid: #dddddd; --viz-axis-ink: #555555; --viz-surface: #ffffff;
    --delta-good: #006300; --delta-bad: #8a1c1c;
  }

  html, body {
    background: #fff; color: #000;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }

  .no-print, .topbar, details.calls { display: none !important; }
  .print-only { display: block; }

  main.wrap { max-width: none; padding: 0; }

  /* Nothing that reads as one unit may be split across a page. */
  .kpi, .viz, .dash-table, .dash-prose section, .recs li, table, tr { break-inside: avoid; }
  h1, h2 { break-after: avoid; }
  .dash-head { break-after: avoid; }

  /* A wide table must print in full, not scroll off the page. */
  .table-scroll { overflow: visible; }
  .answer table { display: table; width: 100%; }
  .answer th, .answer td { white-space: normal; }

  a { text-decoration: none; color: inherit; }
}

label.check {
  display: flex; align-items: center; gap: 8px;
  margin: 14px 0 0; font-size: 14px; color: var(--text);
}
label.check input { width: auto; margin: 0; }
