/* BCM Law Firm Health dashboard.
 * Theme tokens follow the validated reference palette; charts read these
 * custom properties at render time, so theme switches re-render charts. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  --s1: #2a78d6;  /* blue */
  --s2: #1baf7a;  /* aqua */
  --s3: #eda100;  /* yellow */
  --s4: #008300;  /* green */
  --s5: #4a3aa7;  /* violet */
  --s6: #e34948;  /* red */
  --s7: #e87ba4;  /* magenta */
  --s8: #eb6834;  /* orange */
  --other: #898781;

  --accent: var(--s1);
  --track: #cde2fb;        /* meter track: light step of the accent ramp */
  --neutral-fill: #f0efec;

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-text: #006300;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);

    --s1: #3987e5;
    --s2: #199e70;
    --s3: #c98500;
    --s4: #008300;
    --s5: #9085e9;
    --s6: #e66767;
    --s7: #d55181;
    --s8: #d95926;

    --track: #0d366b;
    --neutral-fill: #383835;
    --good-text: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);

  --s1: #3987e5;
  --s2: #199e70;
  --s3: #c98500;
  --s4: #008300;
  --s5: #9085e9;
  --s6: #e66767;
  --s7: #d55181;
  --s8: #d95926;

  --track: #0d366b;
  --neutral-fill: #383835;
  --good-text: #0ca30c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

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

header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--page);
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 1rem 0;
}
.header-row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
  max-width: 1200px;
  margin: 0 auto;
}
.header-row h1 {
  font-size: 1.05rem;
  font-weight: 650;
  margin: 0;
  white-space: nowrap;
}
#as-of-line { color: var(--muted); font-size: 0.82rem; }
.header-spacer { flex: 1; }
.header-controls { display: flex; align-items: center; gap: 0.4rem; }

.tabs {
  display: flex;
  gap: 0.25rem;
  max-width: 1200px;
  margin: 0.45rem auto 0;
}
.tabs a {
  color: var(--ink-2);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 550;
  padding: 0.4rem 0.8rem;
  border-bottom: 2px solid transparent;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); }
.tabs a:hover { color: var(--ink); }

button, select {
  font: inherit;
  font-size: 0.84rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.35rem 0.6rem;
  min-height: 34px;
  cursor: pointer;
}
button:hover, select:hover { border-color: var(--baseline); }

/* ---------- layout ---------- */

main { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.view { display: none; }
.view.active { display: block; }

.strip {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  flex-wrap: wrap;
  margin: 0.25rem 0 1rem;
}
.strip .month-title { font-size: 1.35rem; font-weight: 650; }
.strip .elapsed { color: var(--ink-2); font-size: 0.9rem; }
.strip .note { color: var(--muted); font-size: 0.82rem; }

section.metric-section { margin-bottom: 1.6rem; }
section.metric-section > h2 {
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.6rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.8rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1rem;
}
.card .label { font-size: 0.84rem; color: var(--ink-2); }
.card .value {
  font-size: 1.9rem;
  font-weight: 650;
  line-height: 1.15;
  margin: 0.1rem 0 0.15rem;
}
.card .sub { font-size: 0.8rem; color: var(--muted); }
.card .missing { color: var(--muted); font-size: 0.9rem; padding: 0.6rem 0; }

/* ---------- meter (pace bar) ---------- */

.meter {
  position: relative;
  height: 10px;
  border-radius: 5px;
  background: var(--track);
  margin: 0.55rem 0 0.35rem;
  overflow: visible;
}
.meter .fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 5px;
  background: var(--accent);
  min-width: 2px;
}
.meter .fill.behind { background: var(--serious); }
.meter .tick {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: var(--ink);
  border-radius: 1px;
}
.meter.no-tick { background: var(--neutral-fill); }

/* ---------- status pill ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.74rem;
  font-weight: 650;
  border-radius: 999px;
  padding: 0.12rem 0.55rem;
  border: 1px solid transparent;
  vertical-align: middle;
}
.pill.ahead    { color: var(--good-text); border-color: var(--good); }
.pill.on_track { color: var(--ink-2); border-color: var(--baseline); }
.pill.behind   { color: var(--critical); border-color: var(--serious); }
.pill.unknown  { color: var(--muted); border-color: var(--border); }
.pill.final-hit  { color: var(--good-text); border-color: var(--good); }
.pill.final-miss { color: var(--critical); border-color: var(--serious); }

/* ---------- ops weekly mini-bars ---------- */

.week-rows { margin-top: 0.5rem; display: grid; gap: 0.45rem; }
.week-row { display: grid; grid-template-columns: 5.2rem 1fr 3.4rem; align-items: center; gap: 0.5rem; }
.week-row .wk-label { font-size: 0.78rem; color: var(--ink-2); white-space: nowrap; }
.week-row .wk-val { font-size: 0.78rem; color: var(--ink-2); text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- history sub-toggle ---------- */

.subtabs {
  display: inline-flex;
  gap: 2px;
  background: var(--neutral-fill);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 2px;
  margin-bottom: 1rem;
}
.subtabs button {
  border: none;
  background: transparent;
  border-radius: 7px;
  padding: 0.35rem 0.9rem;
  min-height: 32px;
  color: var(--ink-2);
  font-weight: 550;
}
.subtabs button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

/* ---------- scorecard ---------- */

.scorecard-legend { color: var(--muted); font-size: 0.8rem; margin-bottom: 0.6rem; }
table.scorecard {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.86rem;
}
table.scorecard th, table.scorecard td {
  text-align: right;
  padding: 0.4rem 0.65rem;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
table.scorecard thead th {
  color: var(--ink-2);
  font-weight: 600;
  border-bottom: 1px solid var(--baseline);
}
table.scorecard th.metric, table.scorecard td.metric {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 1;
}
table.scorecard th.target, table.scorecard td.target {
  color: var(--ink-2);
  border-right: 1px solid var(--baseline);
}
table.scorecard td.na { color: var(--muted); }
table.scorecard tr.section-row td.section {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--page);
  padding-top: 0.6rem;
  border-bottom: 1px solid var(--baseline);
  position: sticky;
  left: 0;
}
table.scorecard td.hit { background: rgba(12, 163, 12, 0.13); }
table.scorecard td.miss { background: rgba(208, 59, 59, 0.12); }
.scorecard .v { font-weight: 600; }
.scorecard .mark { font-size: 0.72rem; margin-left: 0.3rem; font-weight: 700; }
.scorecard .mark.hit, .trend.good { color: var(--good-text); }
.scorecard .mark.miss, .trend.bad { color: var(--critical); }
.scorecard .trend { font-size: 0.68rem; margin-left: 0.25rem; }
.scorecard-legend .mark, .scorecard-legend .trend { margin-left: 0; margin-right: 0.15rem; }

/* ---------- charts ---------- */

.chart-card { min-height: 260px; }
.chart-card h3 { font-size: 0.9rem; font-weight: 600; margin: 0 0 0.5rem; color: var(--ink); }
.chart-box { position: relative; height: 230px; }
.chart-box.tall { height: 260px; }
.chart-box.short { height: 170px; }
.grid.charts { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

/* ---------- table view ---------- */

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
table.data {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.84rem;
}
table.data th, table.data td {
  text-align: right;
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
table.data th:first-child, table.data td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
table.data thead th { color: var(--ink-2); font-weight: 600; border-bottom: 1px solid var(--baseline); }
table.data td.na { color: var(--muted); }

/* ---------- banner ---------- */

#banner {
  display: none;
  background: var(--neutral-fill);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--ink-2);
}
#banner.show { display: block; }

/* ---------- footer ---------- */

footer { max-width: 1200px; margin: 0 auto; padding: 0 1rem 1.5rem; color: var(--muted); font-size: 0.78rem; }

/* ---------- print / PDF export ---------- */

#print-header { display: none; }

/* While preparing a print/PDF snapshot: give every view layout so the
 * chart canvases render before the print dialog snapshots the page. */
body.print-prep .view { display: block !important; }
body.print-prep #print-header { display: block; font-size: 1.1rem; font-weight: 650; }
body.print-prep #print-header .print-sub { font-size: 0.8rem; font-weight: 400; color: var(--ink-2); }

@media print {
  :root, :root[data-theme="dark"] { color-scheme: light; }
  body { background: #fff; font-size: 12px; }
  header, footer, .header-controls, .tabs, .subtabs, #banner { display: none !important; }
  #print-header {
    display: block;
    font-size: 1.1rem;
    font-weight: 650;
    margin: 0 0 0.2rem;
  }
  #print-header .print-sub { font-size: 0.8rem; font-weight: 400; color: #52514e; }
  main { max-width: none; padding: 0; }
  .view { display: block !important; }
  .view + .view { break-before: page; }
  section.metric-section { break-inside: avoid; }
  .card { break-inside: avoid; border-color: #ddd; }
  .grid { grid-template-columns: repeat(2, 1fr); }
  .grid.charts { grid-template-columns: 1fr 1fr; }
  .table-wrap { overflow: visible; }
  table.data th, table.data td { white-space: normal; }
}
