/* dotdotQ client dashboard. Colours only from tokens.css. Small accent text uses --brand-soft
   and small captions --text-secondary, for AA contrast on the dark theme. */

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
}

a { color: var(--brand-soft); text-underline-offset: 3px; }
a:hover { color: var(--text-strong); }
:focus-visible { outline: 2px solid var(--brand-soft); outline-offset: 3px; border-radius: var(--radius-sm); }
h1, h2, h3 { color: var(--text-strong); margin: 0; line-height: 1.25; }
p { margin: 0; }
img { display: block; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .wrap { padding: 0 32px; } }

.skip-link { position: absolute; left: 16px; top: -48px; padding: 8px 12px; background: var(--brand); color: #fff; border-radius: var(--radius-sm); z-index: 10; }
.skip-link:focus { top: 12px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.muted { color: var(--text-secondary); }
.small { font-size: 12px; }
.label { font-size: 13px; color: var(--brand-soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 8px 14px;
  font: inherit; font-size: 13px; font-weight: 500; text-decoration: none; white-space: nowrap; cursor: pointer;
  border-radius: var(--radius); border: 1px solid var(--border-strong); background: transparent; color: var(--text-strong);
}
.btn:hover { background: var(--surface-2); color: var(--text-strong); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-deep); color: #fff; }

.pill { display: inline-block; padding: 1px 10px; font-family: var(--font-mono); font-size: 12px; font-weight: 400; border-radius: 999px; border: 1px solid var(--border-strong); color: var(--text-secondary); vertical-align: middle; }
.pill.healthy { color: var(--brand-soft); border-color: var(--brand-deep); }
.pill.needs_work { color: var(--alert); border-color: var(--alert); }

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

.top { border-bottom: 1px solid var(--border); }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; }
.brand img { width: 164px; height: 20px; image-rendering: pixelated; }
@media (max-width: 420px) {
  .brand img { width: 82px; height: 10px; }
}

main { padding: 32px 0 64px; }
.head { display: grid; gap: 6px; margin-bottom: 24px; }
.head h1 { font-family: var(--font-sans); font-size: clamp(26px, 5vw, 36px); font-weight: 600; }
.note { font-size: 13px; color: var(--text-secondary); border-left: 2px solid var(--border-strong); padding-left: 10px; }

/* ---------- level 1: cards ---------- */

.cards { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 860px) { .cards { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; } }

.score-card {
  position: relative; display: grid; gap: 6px; padding: 16px; text-align: left; cursor: pointer;
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.score-card:hover { background: var(--surface-2); }
.score-card[aria-pressed="true"] { background: var(--selected); border-color: var(--brand-deep); }
.sc-name { font-size: 13px; color: var(--text-secondary); }
.sc-value { font-size: 40px; font-weight: 700; line-height: 1; color: var(--text-strong); }
.sc-of { font-size: 13px; font-weight: 400; color: var(--text-secondary); margin-left: 4px; }
.sc-status { font-size: 12px; }
.score-card[data-status="healthy"] .sc-status { color: var(--brand-soft); }
.score-card[data-status="watch"] .sc-status { color: var(--text-secondary); }
.score-card[data-status="needs_work"] .sc-status { color: var(--alert); }
.score-card[data-status="needs_work"]::after { content: ""; position: absolute; top: 16px; right: 16px; width: 8px; height: 8px; background: var(--alert); }
.sc-delta { font-size: 12px; color: var(--text-secondary); }
.sc-delta.up { color: var(--brand-soft); }

.meter { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 999px; }
.score-card[data-status="healthy"] .meter span { background: var(--brand-soft); }
.score-card[data-status="watch"] .meter span { background: var(--text-secondary); }
.score-card[data-status="needs_work"] .meter span { background: var(--alert); }

.legend-line { margin-top: 10px; }
.k.healthy { color: var(--brand-soft); }
.k.needs_work { color: var(--alert); }

/* ---------- level 2: detail ---------- */

.detail { margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--border); scroll-margin-top: 16px; }
.detail h2 { font-size: 22px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.d-score { color: var(--text-strong); }
#detail-summary { margin: 4px 0 16px; }

.tiles { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.tile { display: grid; gap: 4px; align-content: start; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.tile.context { border-style: dashed; }
.t-name { font-size: 12px; color: var(--text-secondary); }
.t-value { font-size: 26px; font-weight: 700; color: var(--text-strong); line-height: 1.15; }
.t-text { font-size: 14px; color: var(--text-strong); }
.t-delta { font-size: 12px; color: var(--text-secondary); }
.t-delta.up { color: var(--brand-soft); }
.t-meta { font-size: 12px; color: var(--text-secondary); }
.rough { color: var(--text-strong); border-bottom: 1px dotted var(--text-secondary); }
.t-bar { height: 4px; margin-top: 4px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.t-bar span { display: block; height: 100%; background: var(--brand-soft); border-radius: 999px; }
.t-small { font-size: 12px; color: var(--alert); }

.detail-grid { display: grid; gap: 14px; margin-top: 14px; }
.detail-grid > * { min-width: 0; } /* let the chart scroll inside its panel on phones */
@media (min-width: 960px) { .detail-grid { grid-template-columns: 1.4fr 1fr; } }
.panel { margin: 0; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.panel-title { display: block; margin-bottom: 10px; font-size: 13px; font-weight: 500; color: var(--text-strong); }

/* Chart text scales with the chart, so on phones the chart keeps a readable minimum width
   and scrolls sideways inside its panel instead of shrinking the labels. */
.chart { overflow-x: auto; }
.chart-svg { display: block; width: 100%; min-width: 480px; height: auto; overflow: visible; }
.chart-svg .grid { stroke: var(--border); stroke-width: 1; }
.chart-svg .axis { fill: var(--text-secondary); font-family: var(--font-mono); font-size: 13px; }
.chart-svg .small-flag { fill: var(--alert); }
.chart-svg .line { fill: none; stroke: var(--brand-text); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-svg .point { fill: var(--brand-text); }
.chart-svg .point.latest { fill: var(--text-strong); stroke: var(--brand-text); stroke-width: 2; }
.chart-svg .value-label { fill: var(--text-strong); font-family: var(--font-mono); font-size: 14px; font-weight: 700; }
.chart-svg .bar { fill: var(--brand); }
.chart-svg .bar.comparison { fill: var(--neutral-series); }
.chart-svg .marker { stroke: var(--alert); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-svg .marker-label { fill: var(--alert); font-family: var(--font-mono); font-size: 13px; }
.legend { display: flex; gap: 16px; margin-top: 8px; font-size: 12px; color: var(--text-secondary); }
.legend .key { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 2px; background: var(--brand); vertical-align: -1px; }
.legend .key.comparison { background: var(--neutral-series); }

.causes { display: grid; gap: 12px; margin: 0 0 12px; padding: 0; list-style: none; }
.causes li { display: grid; grid-template-columns: 72px 1fr; gap: 10px; }
.causes .pts { font-weight: 700; color: var(--alert); }
.causes .c-name { display: block; font-size: 12px; color: var(--text-secondary); }
.causes .c-body { color: var(--text-strong); }
.causes .none { display: block; color: var(--text-secondary); }

/* ---------- level 3: raw data ---------- */

.raw-section { margin-top: 32px; }
details summary { cursor: pointer; font-weight: 500; color: var(--text-strong); padding: 10px 0; }
.raw-actions { margin: 6px 0 12px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-secondary); font-weight: 500; background: var(--surface); }
td.num, th.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }

/* ---------- call to action and footer ---------- */

.cta { display: grid; gap: 10px; justify-items: start; margin-top: 48px; padding: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.cta h2 { font-family: var(--font-sans); font-size: 24px; font-weight: 600; }
.foot { padding: 24px 0 40px; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-secondary); }
.foot a { color: var(--text-secondary); }

@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

@media print {
  .top, .cta, .skip-link, .raw-actions { display: none; }
}
