/* Dashboards: a long, scannable report page. Summary first (overview cards, goal), then detail. */
html, body.dash-body { height: auto; }
.dash-top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30; }
body.dash-body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 31; background: var(--surface); }
.brand-name { margin: 0; font-size: 16px; font-weight: 700; }
.dash {
  max-width: 1240px; margin: 0 auto; display: flex; flex-direction: column; gap: 28px;
  padding-block: 28px 56px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.hero { display: flex; flex-direction: column; gap: 10px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.hero .eyebrow { margin: 0; color: var(--accent); }
.hero h1 { margin: 0; font-size: clamp(28px, 4vw, 40px); line-height: 1.08; font-weight: 800; letter-spacing: -0.02em; text-wrap: balance; }
.lede { margin: 0; font-size: 16px; color: var(--muted); max-width: 64ch; }
.hero-controls { display: flex; flex-wrap: wrap; gap: 16px 32px; align-items: end; margin-top: 6px; }
.hero-controls .field { flex: 0 0 260px; }
.data-note { margin: 0; font-size: 12.5px; color: var(--muted); max-width: 62ch; flex: 1 1 320px; }

.sec { display: flex; flex-direction: column; gap: 14px; }
.sec-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 8px 16px; }
.sec-head h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.sec-head p { margin: 2px 0 0; font-size: 13px; color: var(--muted); max-width: 70ch; }
.sec-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.sec-tools select { padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-2); }
.panel-box { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px; min-width: 0; }

/* KPI cards */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.kpi .v { font: 600 26px/1.1 var(--font-data); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.kpi .v small { font-size: 15px; color: var(--muted); }
.kpi .l { font-size: 13px; font-weight: 600; }
.kpi .s { font-size: 12px; color: var(--muted); }
.kpi .focus { font: 12px var(--font-data); color: var(--select); }

/* goal tracker */
.goal { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 20px; }
.goal-big { font: 600 34px/1 var(--font-data); letter-spacing: -0.02em; }
.goal-big small { font-size: 16px; color: var(--muted); font-weight: 400; }
.track { position: relative; height: 30px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; margin-top: 14px; }
.track .fill { position: absolute; inset: 0 auto 0 0; background: var(--accent); }
.track .pace { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); }
.track-scale { display: flex; justify-content: space-between; font: 11px var(--font-data); color: var(--muted); margin-top: 4px; }
.goal-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.goal-facts div { font-size: 12px; color: var(--muted); }
.goal-facts b { display: block; font: 600 16px var(--font-data); color: var(--ink); }
.callout { font-size: 12.5px; color: var(--muted); border-left: 3px solid var(--line); padding-left: 10px; margin: 0; }
.mini-bars { display: flex; flex-direction: column; gap: 5px; }
.mb-row { display: grid; grid-template-columns: 82px minmax(0, 1fr) 64px; gap: 8px; align-items: center; font-size: 12px; }
.mb-row .bar { height: 12px; background: var(--accent); border-radius: 2px; opacity: 0.85; }
.mb-row.on .bar { background: var(--select); opacity: 1; }
.mb-row .n { font: 11.5px var(--font-data); text-align: right; font-variant-numeric: tabular-nums; }

/* compare */
.compare { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 16px; }
.chart-box svg { display: block; width: 100%; height: auto; }
.chart-box .axis text, .chart-box text.lbl { fill: var(--muted); font: 11px var(--font-data); }
.chart-box text.name { fill: var(--ink); font: 12px var(--font-ui); }
.chart-box text.val { fill: var(--ink); font: 11px var(--font-data); }
.chart-box .grid line { stroke: var(--line); stroke-dasharray: 2 3; }
.chart-box .ref { stroke: var(--ink); stroke-width: 1.2; stroke-dasharray: 4 3; }
.dtable-wrap { overflow-x: auto; }
.dtable { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.dtable th, .dtable td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.dtable th:first-child, .dtable td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
.dtable th { font-weight: 600; font-size: 11.5px; color: var(--muted); cursor: pointer; vertical-align: bottom; white-space: normal; min-width: 84px; }
.dtable th[aria-sort] { color: var(--accent); }
.dtable td { font-family: var(--font-data); font-variant-numeric: tabular-nums; }
.dtable td:first-child { font-family: var(--font-ui); font-weight: 500; }
.dtable tr.region td { background: var(--surface-2); font-weight: 600; }
.dtable tr.region td:first-child { background: var(--surface-2); }
.dtable tbody tr { cursor: pointer; }
.dtable tbody tr:hover td { background: var(--surface-2); }
.dtable tr.on td { background: var(--accent-soft); }

/* profile drawer */
.profile-card { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 8px 20px; }
.pc-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.pc-row .num { font: 13px var(--font-data); }
.chipx { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; white-space: nowrap; }
.chipx.good { background: color-mix(in srgb, #2f9e44 18%, transparent); color: #2b8a3e; }
.chipx.bad { background: color-mix(in srgb, #e03131 16%, transparent); color: #c92a2a; }
.chipx.mid { background: color-mix(in srgb, #f08c00 18%, transparent); color: #c66b00; }
.chipx.neutral { background: var(--surface-2); color: var(--muted); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chipx.good { color: #69db7c; }
  :root:not([data-theme="light"]) .chipx.bad { color: #ff8787; }
  :root:not([data-theme="light"]) .chipx.mid { color: #ffc078; }
}
:root[data-theme="dark"] .chipx.good { color: #69db7c; }
:root[data-theme="dark"] .chipx.bad { color: #ff8787; }
:root[data-theme="dark"] .chipx.mid { color: #ffc078; }

/* map */
.dmap { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; }
.dmap-canvas { position: relative; height: 500px; border-radius: 8px; overflow: hidden; background: var(--map-bg); border: 1px solid var(--line); }
.dmap-canvas canvas { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.dmap-side { display: flex; flex-direction: column; gap: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.seg button { border: 0; background: var(--surface-2); padding: 6px 10px; cursor: pointer; font-size: 12.5px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.info { font-size: 13px; }
.info h3 { margin: 0 0 4px; font-size: 15px; }
.info .big { font: 600 22px var(--font-data); }
.layer-toggles { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; }

/* stacked bars */
.stack-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); }
.stack-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: 5px; vertical-align: -2px; }

/* scorecard */
.score td .chipx { margin-left: 6px; }
.score td.tgt { color: var(--muted); }
.legend-line { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); align-items: center; }

.dash-foot { font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 16px; display: flex; flex-direction: column; gap: 4px; }
.dash-foot a { color: var(--accent); }

@media (max-width: 900px) {
  .goal, .compare, .dmap { grid-template-columns: minmax(0, 1fr); }
  .dmap-canvas { height: 420px; }
}
@media print {
  .dash-top, .sec-tools, .hero-controls .field, #btn-print { display: none !important; }
  body.dash-body { background: #fff; }
  .sec { break-inside: avoid; }
  .dmap-canvas { height: 380px; }
}

.dmap-side .field { flex: none; }
.chart-box svg { max-width: 100%; }
.unit-ctl { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.unit-ctl .seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.unit-ctl select[hidden] { display: none; }
@media print { .unit-ctl { display: none; } }
.shaky { color: var(--select); font-weight: 700; margin-left: 2px; cursor: help; }
