/* Area Redesign Digital Twin: panel styles
 * (docs/BRAND_ALIGNMENT_SPEC.md sections 2 and 4).
 *
 * Owned by the stage-2 "panels" agent. Loads after css/app.css, so rules here
 * may extend or override the shared components.
 *
 * This file adds only what is genuinely panel specific: the KPI card grid, the
 * uPlot hosts, the PM2.5 bars, the 48 h scrubber and the Data sources panel.
 * Everything else (.card, .badge, .chip, .kv, h4.sub, .loading, .footnote,
 * .muted, .small) comes from app.css, which carries the Neighbourhood DT
 * primitives verbatim. Type weights follow that reference: 10px uppercase
 * badges, 11px uppercase h4.sub, 12.5px body, var(--r2) radii on cards.
 *
 * Dark is the only theme. Colours come from the brand tokens in css/tokens.css;
 * there are no raw palette values here except the tinted chip backgrounds the
 * reference itself spells out.
 *
 * Provenance chips are NOT styled here: .badge and .q-measured / .q-derived /
 * .q-synthetic live in app.css and are chosen from the quality STRING by
 * js/panels.js, never per device.
 */

/* ================= Data sources panel (spec section 4) ==================== */

/* Four sections: what is live in this build, the vendor message formats, the
 * switch to real sensors, and what is modelled rather than sensed. */

#sources-body h4.sub:first-child { margin-top: 2px; }
#sources-body .card { margin-bottom: 4px; }
#sources-body .card p + p { margin-top: 8px; }

/* the badge vocabulary, explained once, next to the streams it applies to */
.prov-legend {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--brd2);
}
.prov-legend .prov-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 6px 0;
}
.prov-legend .prov-row .badge { margin-left: 0; flex: none; }
.prov-legend .prov-meaning { color: var(--ink3); font-size: 11.5px; line-height: 1.5; }

/* ================= KPI cards (top of the Environment tab) ================= */

#kpiGrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 9px;
}

.kpi-card {
  border: 1px solid var(--brd2);
  border-radius: var(--r2);
  padding: 9px 10px;
  min-width: 0; /* grid children may shrink: the charts measure the real width */
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: var(--t);
}
.kpi-card:hover { border-color: var(--brd); }

.kpi-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 5px;
  min-width: 0;
}
.kpi-title {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--ink3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kpi-badges { flex: none; }
.kpi-badges .badge { margin-left: 0; }

.kpi-value {
  min-height: 24px;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px;
}
.kpi-num.big { font-size: 18px; font-weight: 700; line-height: 1.1; color: var(--ink); }
.kpi-unit { font-size: 10.5px; color: var(--ink3); margin-left: 3px; }
.kpi-nodata { font-size: 11.5px; cursor: help; }

/* trend arrow: calm and neutral, direction is information, not judgement */
.kpi-trend {
  font-size: 11px;
  color: var(--ink3);
  margin-left: 4px;
  cursor: help;
}

/* PM2.5 card: two sub-values, indoor and outdoor */
.kpi-dual { gap: 8px; }
.kpi-sub { white-space: nowrap; }
.kpi-sub-label { font-size: 10px; color: var(--ink3); }
.kpi-sub .kpi-num { font-size: 13px; font-weight: 700; color: var(--ink); }

.kpi-spark { height: 36px; min-width: 0; overflow: hidden; }
.kpi-spark canvas { display: block; }
.kpi-spark .u-over, .kpi-spark .u-under { background: transparent; }

.kpi-time { font-size: 10px; }
.kpi-note { font-size: 10px; line-height: 1.5; }

/* the one big number outside the grid (block net power) */
.big-num { font-size: 20px; font-weight: 700; font-family: var(--font-head); color: var(--ink); }

/* ================= PM2.5 bars against the WHO guideline =================== */

/* Same geometry as the reference .bar primitive: label, track, value. */

.pm-wrap { margin: 8px 0 2px; }
.pm-row {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 8px;
  margin: 5px 0;
  font-size: 11.5px;
  color: var(--ink2);
}
.pm-label { color: var(--ink3); }
.pm-track {
  position: relative;
  height: 13px;
  border-radius: 6px;
  background: rgba(255,255,255,.1);
}
.pm-bar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  border-radius: 6px;
  transition: width .5s var(--ease);
}
.pm-bar.indoor { background: var(--dom-indoor); }
.pm-bar.outdoor { background: var(--dom-air); }
/* the guideline marker overhangs the track so it reads as a threshold, not a value */
.pm-guideline {
  position: absolute;
  top: -3px; bottom: -3px;
  width: 0;
  border-left: 2px dashed var(--warn);
}
.pm-val { white-space: nowrap; text-align: right; color: var(--ink); font-weight: 600; }

/* ================= charts: uPlot hosts, canvas fallback =================== */

/* js/panels.js reads the token colours at render time and passes them to uPlot,
 * so the canvas strokes and these rules cannot drift apart. Both the uPlot host
 * and the fallback canvas get the same frame. */

#spark-chart, #spark {
  margin-top: 8px;
  background: rgba(0,0,0,.24);
  border: 1px solid var(--brd2);
  border-radius: var(--r2);
  overflow: hidden;
}
#spark-chart { padding: 2px 0; }
#spark { display: block; width: 100%; height: auto; }

#spark-chart .u-legend { display: none; } /* the caption below carries the meta */
#spark-chart .u-select { background: rgba(63,146,224,.12); }
#spark-chart .u-cursor-x, #spark-chart .u-cursor-y { border-color: var(--brd); }

#spark-caption { font-size: 10.5px; line-height: 1.55; margin-top: 7px; }

/* ================= footer: 48 h scrubber and the live toggle ============== */

.scrub-box {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}
.scrub-label { flex: none; white-space: nowrap; }

#btn-live {
  all: unset;
  cursor: pointer;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 999px;
  border: 1px solid var(--brd2);
  background: rgba(0,0,0,.24);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--ink2);
  white-space: nowrap;
  transition: var(--t);
}
#btn-live:hover { color: var(--ink); border-color: var(--brd); }
#btn-live[aria-pressed="true"] { color: var(--ink); border-color: var(--good); }
#btn-live:active { transform: scale(.965); }

.live-dot {
  width: 8px; height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--ink3);
}
#btn-live[aria-pressed="true"] .live-dot {
  background: var(--good);
  animation: poc-live-pulse 2s ease-in-out infinite;
}
@keyframes poc-live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

/* subtle countdown to the next 60 s refresh */
#live-count {
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  color: var(--ink3);
  min-width: 30px;
  text-align: right;
}

#scrub-range {
  flex: 1 1 auto;
  min-width: 80px;
  margin: 0;
  accent-color: var(--accent);
}

/* The historical chip is informational, so it takes the accent tint of the
 * reference .chip. Amber stays reserved for the provenance badges. */
.scrub-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(63,146,224,.18);
  color: #bcdcf3;
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
}
.scrub-chip.in-panel { margin: 2px 0 4px; }

/* The live pulse runs for the whole session, so honour a reduced-motion
 * request. The dot's colour still carries the state: only the motion drops. */
@media (prefers-reduced-motion: reduce) {
  #btn-live[aria-pressed="true"] .live-dot { animation: none; }
}

/* ================= presentation mode ===================================== */

/* Type scale x1.25 for a projector at the back of a room. The behaviour lives
 * in js/main.js (body.presentation); the numbers a room actually reads are the
 * KPI values, so those are what step up. */

body.presentation .kpi-title { font-size: 12px; }
body.presentation .kpi-num.big { font-size: 22.5px; }
body.presentation .kpi-sub .kpi-num { font-size: 16px; }
body.presentation .kpi-unit { font-size: 13px; }
body.presentation .kpi-nodata { font-size: 14px; }
body.presentation .kpi-trend { font-size: 13.5px; }
body.presentation .kpi-sub-label { font-size: 12.5px; }
body.presentation .kpi-time,
body.presentation .kpi-note { font-size: 12.5px; }
body.presentation .big-num { font-size: 25px; }
body.presentation .pm-row { font-size: 14px; }
body.presentation .scrub-chip { font-size: 13px; }

/* ---------------- Gebied: the area panel (G1) ----------------
 * No new token. Every colour below is one of the rgba recipes already in
 * css/app.css (.q-measured, .q-derived, .q-synthetic, .chip.ok), reused so a
 * status chip cannot introduce a colour the rest of the interface does not use.
 *
 * The STATUS chip is the point of the norms list: municipal policy and a sector
 * guideline must not read with the same authority as law, so each status gets a
 * visibly different chip and the class is derived from the status STRING in
 * js/area.js, never decided per norm. */
.area-tools { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 10px; }

.badge.st-law              { background: rgba(63,146,224,.16); color: #bcdcf3; }
.badge.st-municipal_policy { background: rgba(141,184,41,.17); color: #cfe39a; }
.badge.st-national_guideline { background: rgba(129,150,172,.18); color: #c8d4e0; }
.badge.st-sector_guideline { background: rgba(255,180,84,.16); color: #ffce8f; }
.badge.st-none, .badge.st-unknown { background: rgba(158,190,232,.10); color: var(--ink3); }

.norm-card { margin: 8px 0; }
.norm-head {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  font-family: var(--font-head); font-size: 12px; color: var(--ink);
}
.norm-value {
  font-family: var(--font-head); font-size: 17px; color: var(--ink);
  margin: 4px 0 2px;
}
.norm-verdict { margin-bottom: 4px; }
.norm-missing { margin: 4px 0 2px; }
.norm-missing ul { margin: 3px 0 0; padding-left: 16px; }
.norm-missing li { font-size: 11px; color: var(--ink2); margin-bottom: 2px; }
#area-body .footnote { word-break: break-word; }
#area-body table.metrics { margin-bottom: 6px; }

/* ---------------- Plekken: points of interest (G2) ----------------
 * No new token: the accent, ink and card recipes are the ones already in use. */
.poi-card { margin: 8px 0; }
.poi-card.on { border-color: var(--brd); }
.poi-head {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  padding: 0; cursor: pointer;
  font-family: var(--font-head); font-size: 13px; color: var(--ink);
}
.poi-card.on .poi-head { color: var(--accent); }
.poi-fact { margin: 7px 0; padding-left: 8px; border-left: 2px solid var(--brd2); }
.poi-fact-head {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  font-size: 11px; color: var(--ink2);
}
.poi-fact-value {
  font-family: var(--font-head); font-size: 16px; color: var(--ink); margin: 2px 0;
}
.poi-start { margin: 8px 0; }
.poi-start-btn { margin-top: 6px; }
#poi-body .footnote { word-break: break-word; }
