/* Area Redesign Digital Twin: layout + shared components
 * (docs/BRAND_ALIGNMENT_SPEC.md section 2).
 *
 * Geometry and primitives come from the Neighbourhood DT reference
 * (aadorp-energy-dt-backend/web/index.html): a full bleed scene with floating
 * glass over it, so the two tools read as one product.
 *
 * Owned by stage 1. Stage-2 agents must NOT edit this file: scene styles go in
 * css/scene.css, panel styles in css/panels.css (both load after this file, so
 * they can extend or override).
 *
 * Quality badge classes are driven by the quality STRING coming from the API
 * (js/util.js: PocUtil.qualityBadge). Nothing here is per device.
 */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  overflow: hidden; /* no page scroll: panels scroll internally */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p { margin: 0; }
button { font-family: inherit; }

h2, h3, h4, .ptitle, #bp-title, #brand, .kpi-num, .badge, .btn {
  font-family: var(--font-head);
  letter-spacing: .005em;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@keyframes poc-spin { to { transform: rotate(360deg); } }

.loading {
  color: var(--ink3);
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.loading::before {
  content: "";
  width: 12px; height: 12px; min-width: 12px;
  border-radius: 50%;
  border: 2px solid var(--brd);
  border-top-color: var(--accent);
  animation: poc-spin .8s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

.muted { color: var(--ink3); }
.small { font-size: 11.5px; }
.hidden { display: none !important; }
a { color: var(--accent); }
.footnote { font-size: 10.5px; color: var(--ink3); margin-top: 11px; line-height: 1.55; }

/* ---------------- glass primitive ---------------- */

.glass {
  background: var(--glass);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--brd);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}

/* ---------------- scene ---------------- */

#canvasWrap { position: absolute; inset: 0; z-index: 0; }
#cesiumContainer { position: absolute; inset: 0; }
#cesiumContainer .cesium-viewer-bottom { left: 8px; bottom: 6px; }
#cesiumContainer .cesium-credit-lightbox,
#cesiumContainer .cesium-widget-credits { font-size: 10px; }

/* ---------------- top bar: docked flush to the top edge, full width -------- */

#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-radius: 0; border-left: 0; border-right: 0; border-top: 0;
  background: var(--glass2);
}
/* thin brand accent along the whole bottom edge (logo blue to leaf green) */
#topbar::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, var(--accent2), var(--leaf));
  opacity: .5;
  pointer-events: none;
}

#brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  min-width: 0;
}
#brand .t { overflow: hidden; text-overflow: ellipsis; }
#brand .dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--accent), var(--leaf));
  box-shadow: 0 0 10px var(--accent);
}
#brandLink {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: var(--ink3);
  border-radius: 6px;
  transition: var(--t);
}
#brandLink:hover { opacity: .85; }

#licenseNote { font-size: 10.5px; white-space: nowrap; }
.header-spacer { flex: 1 1 auto; }

/* ---------------- segmented control ----------------
 * .seg is the reference primitive. .segmented / .seg-btn is the same control
 * under the class names js/scene.js already emits for the sun date presets, so
 * both vocabularies render as one thing. */

.seg, .segmented {
  display: flex;
  background: rgba(0,0,0,.24);
  border: 1px solid var(--brd2);
  border-radius: 10px;
  overflow: hidden;
  flex: none;
}
.seg button, .segmented .seg-btn {
  all: unset;
  cursor: pointer;
  padding: 7px 13px;
  font-size: 12.5px;
  color: var(--ink2);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--t);
}
.seg button.on, .segmented .seg-btn.active { background: var(--accent2); color: #fff; }
.segmented .seg-btn:disabled { cursor: default; opacity: .45; }

/* ---------------- icon button ---------------- */

.iconbtn {
  all: unset;
  cursor: pointer;
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink2);
  border: 1px solid var(--brd2);
  transition: var(--t);
  flex: none;
}
.iconbtn:hover { color: var(--ink); border-color: var(--brd); background: rgba(255,255,255,.06); }
.iconbtn[aria-pressed="true"] { background: var(--accent2); color: #fff; border-color: var(--accent2); }

/* ---------------- left rail ---------------- */

#rail {
  position: absolute;
  left: 12px;
  top: var(--below);
  z-index: 35;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 7px;
}
.railbtn {
  all: unset;
  cursor: pointer;
  width: 42px; height: 42px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--ink2);
  transition: var(--t);
  position: relative;
}
.railbtn span { font-size: 8.5px; letter-spacing: .02em; }
.railbtn:hover { color: var(--ink); background: rgba(255,255,255,.07); }
.railbtn.on { color: #fff; background: var(--accent2); }

/* ---------------- left side panels ---------------- */

.sidepanel {
  position: absolute;
  left: 66px;
  top: var(--below);
  width: 326px;
  max-height: calc(100% - var(--topbar-h) - 36px);
  z-index: 34;
  padding: 14px;
  overflow: auto;
  display: none;
  animation: slideL var(--t);
}
.sidepanel.open { display: block; }
@keyframes slideL {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: none; }
}

.ptitle {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink3);
  margin: 0 0 10px;
}
h4.sub {
  margin: 14px 0 7px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink3);
}

/* generic option button */
button.opt {
  all: unset;
  cursor: pointer;
  border: 1px solid var(--brd2);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13px;
  color: var(--ink2);
  transition: var(--t);
}
button.opt:hover { border-color: var(--brd); color: var(--ink); }
button.opt.on { background: var(--accent2); color: #fff; border-color: var(--accent2); }
button.opt:disabled { opacity: .4; cursor: not-allowed; }

/* pathway-style card (reference primitive; available to the panels stage) */
.pcard {
  border: 1px solid var(--brd2);
  border-radius: 12px;
  padding: 11px 12px;
  margin: 8px 0;
  transition: var(--t);
}
.pcard:hover { border-color: var(--brd); }
.pcard.on { border-color: var(--accent); background: rgba(63,146,224,.08); }

/* ---- layer rows ---- */

.layer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--ink2);
  margin: 6px 0;
  cursor: pointer;
}
.layer-row input { accent-color: var(--accent); margin: 0; flex: none; }
.layer-row .count { color: var(--ink3); font-size: 11px; margin-left: auto; }
.swatch {
  display: inline-block;
  width: 14px; height: 14px;
  flex: none;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,.35);
}
.swatch.round { border-radius: 50%; }

#domainLegend { margin: 6px 0 0 22px; font-size: 11px; color: var(--ink3); }
#domainLegend .dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin: 0 4px -1px 0;
}
#domainLegend .item { display: inline-block; margin-right: 8px; }

.imagery { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--brd2); }
.imagery .mini-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink3);
  margin-bottom: 5px;
}
.imagery label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-right: 12px;
  font-size: 12.5px;
  color: var(--ink2);
  cursor: pointer;
}
.imagery input { accent-color: var(--accent); margin: 0; }

#layer-notes { margin-top: 8px; }
#layer-notes .layer-note { font-size: 10.5px; color: var(--warn); line-height: 1.5; margin: 4px 0; }

#viewpointBar { min-height: 4px; } /* the stage-2 scene fills this */

/* ---- redesign panel controls (same ids and behaviour as before) ---- */

#redesignCard button {
  all: unset;
  cursor: pointer;
  border: 1px solid var(--brd2);
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 12.5px;
  color: var(--ink2);
  transition: var(--t);
}
#redesignCard button:hover:not(:disabled) { border-color: var(--brd); color: var(--ink); }
#redesignCard button:disabled { opacity: .4; cursor: default; }
#btn-redesign { display: inline-flex; align-items: center; gap: 6px; }
#btn-redesign.on { background: var(--accent2); color: #fff; border-color: var(--accent2); }
#redesign-hint { margin-top: 8px; line-height: 1.5; }
.redesign-actions { margin-top: 8px; display: flex; gap: 7px; }
#redesign-error { color: var(--bad); font-size: 11.5px; margin-top: 6px; line-height: 1.5; }

.spinner {
  width: 13px; height: 13px;
  flex: none;
  border: 2px solid var(--brd);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  vertical-align: middle;
  margin-left: 8px;
  animation: poc-spin .8s linear infinite;
}

/* ---------------- right contextual panel (reference #bpanel language) ------ */

#sidePanel {
  position: absolute;
  right: 12px;
  top: var(--below);
  bottom: 14px;
  width: 384px;
  max-width: calc(100% - 24px);
  z-index: 36;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* selected block info: docks above the tabs, in the #bp-head pattern */
#blockInfo {
  flex: none;
  padding: 14px 16px;
  border-bottom: 1px solid var(--brd2);
  background: rgba(63,146,224,.08);
}
#blockInfo h2 { font-size: 15px; font-weight: 700; margin: 0 0 6px; }
#blockInfo .unconfirmed { color: var(--warn); font-weight: 600; margin-top: 6px; font-size: 11.5px; }

#tabs {
  flex: none;
  display: flex;
  padding: 0 16px;
  border-bottom: 1px solid var(--brd2);
}
#tabs .tab {
  all: unset;
  flex: 1;
  cursor: pointer;
  text-align: center;
  padding: 12px 4px;
  font-size: 12.5px;
  color: var(--ink3);
  border-bottom: 2px solid transparent;
  transition: var(--t);
}
#tabs .tab:hover { color: var(--ink2); }
#tabs .tab.active { color: var(--ink); border-bottom-color: var(--accent); }

.tab-body {
  display: none;
  flex: 1 1 auto;
  overflow: auto;
  min-height: 0;
  padding: 14px 16px;
  font-size: 13px;
}
.tab-body.active { display: block; }

/* ---------------- cards + shared content primitives ---------------- */

.card {
  border: 1px solid var(--brd2);
  border-radius: var(--r2);
  padding: 11px 12px;
  margin-bottom: 11px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink2);
}
.card h2 {
  margin: 0 0 7px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink3);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.card h3 { margin: 8px 0 4px; font-size: 11px; color: var(--ink3); }

.refresh-link {
  float: right;
  font-size: 10.5px;
  color: var(--ink3);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  text-decoration: underline;
  transition: var(--t);
}
.refresh-link:hover { color: var(--accent); }

.devid { color: var(--ink3); }
.src { font-size: 10.5px; color: var(--ink3); }
.num { text-align: right; white-space: nowrap; }
.age { color: var(--ink3); white-space: nowrap; }

/* ---------------- provenance chips (spec section 4) ----------------
 * Text and colour are chosen from the quality STRING by js/util.js, never per
 * device: measured = accent, derived = ink3, synthetic = warn. Each chip
 * carries a title naming the source, built from the API's own source field. */

.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .03em;
  vertical-align: middle;
  margin-left: 4px;
  white-space: nowrap;
  background: rgba(63,146,224,.16);
  color: #bcdcf3;
}
.q-measured { background: rgba(63,146,224,.16); color: #bcdcf3; }
.q-derived  { background: rgba(129,150,172,.18); color: #c8d4e0; }
.q-synthetic{ background: rgba(255,180,84,.16); color: #ffce8f; }
.q-unknown  { background: rgba(158,190,232,.10); color: var(--ink3); }

.chip {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(63,146,224,.18);
  color: #bcdcf3;
  margin: 1px 2px 1px 0;
}
.chip.warn { background: rgba(255,122,112,.16); color: #ffb0aa; }
.chip.ok { background: rgba(141,184,41,.17); color: #cfe39a; }
.chip.sim { background: rgba(255,180,84,.16); color: #ffce8f; }

/* massing estimates always travel with their wording */
.massing-label {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255,180,84,.16);
  color: #ffce8f;
  vertical-align: middle;
  white-space: nowrap;
}

.api-notice {
  background: rgba(255,122,112,.10);
  border: 1px solid rgba(255,122,112,.30);
  color: #ffb0aa;
  padding: 9px 11px;
  border-radius: 10px;
  font-size: 11.5px;
  line-height: 1.5;
  margin: 9px 0;
}
.internal-note {
  background: rgba(255,255,255,.05);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 11px;
  color: var(--ink2);
  line-height: 1.55;
  margin: 9px 0;
}

/* ---------------- tables ---------------- */

table.metrics, table.buurt { width: 100%; border-collapse: collapse; font-size: 11.5px; }
table.metrics td, table.metrics th,
table.buurt td, table.buurt th {
  padding: 4px 4px;
  border-bottom: 1px solid var(--brd2);
  vertical-align: middle;
}
table.metrics td, table.metrics th { text-align: left; }
table.buurt td, table.buurt th { text-align: right; }
table.buurt td:first-child, table.buurt th:first-child { text-align: left; }
table.metrics th, table.buurt th { color: var(--ink3); font-weight: 600; }
table.metrics td.num, table.buurt td.num { text-align: right; white-space: nowrap; }

ul.facts { list-style: none; margin: 0; padding: 0; }
ul.facts li { padding: 6px 0; border-bottom: 1px solid var(--brd2); }

/* WBGT band chips (colours come inline from the one WBGT_BANDS const) */
.wbgt-chip {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 6px;
  font-weight: 700;
  color: #08131e;
  font-size: 11px;
}

/* ---------------- redesign deltas: floating card over the scene ---------- */

#deltasPanel {
  position: absolute;
  right: 408px;
  /* clear the footer, whose height changes with the window: js/main.js measures
   * it into --footer-h. 14px is the footer's own bottom offset, 10px the gap. */
  bottom: calc(14px + var(--footer-h, 100px) + 10px);
  z-index: 32;
  width: 340px;
  max-width: calc(100% - 90px);
  max-height: 52vh;
  overflow: auto;
  padding: 14px;
  font-size: 12.5px;
}
#deltasPanel h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink3);
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
#deltasPanel h2 + table { margin-bottom: 4px; }
#deltasPanel table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
#deltasPanel td { padding: 4px 4px; border-bottom: 1px solid var(--brd2); }
#deltasPanel td.num { text-align: right; white-space: nowrap; }

.delta-good { color: var(--good); font-weight: 700; }
.delta-bad { color: var(--bad); font-weight: 700; }
.delta-zero { color: var(--ink3); font-weight: 700; }
.ok-line { color: var(--good); font-weight: 600; margin-top: 8px; line-height: 1.5; }
.bad-line { color: var(--bad); font-weight: 600; margin-top: 8px; line-height: 1.5; }
.warn-line { color: var(--warn); font-weight: 600; margin-top: 6px; line-height: 1.5; }

/* ---------------- floating footer ---------------- */

#appFooter {
  position: absolute;
  left: 66px;
  right: 408px;
  bottom: 14px;
  z-index: 33;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 9px 14px;
  min-width: 0;
}
#sunControls { flex: 1 1 50%; min-width: 0; }   /* stage-2 scene */
#sensorScrubber { flex: 1 1 50%; min-width: 0; } /* stage-2 panels */
#perfReadout { flex: none; font-size: 10.5px; }

/* ---------------- intro tour ---------------- */

#introOverlay { position: fixed; inset: 0; z-index: 300; }
#introBackdrop {
  position: absolute;
  inset: 0;
  background: rgba(6,14,24,.62);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
#introCard {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(430px, calc(100vw - 32px));
  padding: 24px 26px 20px;
  background: var(--glass2);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--brd);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}
#introStep { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; }
#introCard h2 { margin: 6px 0 8px; font-size: 19px; }
#introBody { color: var(--ink2); font-size: 13.5px; line-height: 1.6; min-height: 76px; }
#introSkipRow {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 16px;
  font-size: 11.5px;
  color: var(--ink3);
  cursor: pointer;
}
#introSkipRow input { accent-color: var(--accent); margin: 0; }
#introNav { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
#introNav button {
  all: unset;
  cursor: pointer;
  padding: 9px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink2);
  border: 1px solid var(--brd);
  transition: var(--t);
}
#introNav button:hover:not(:disabled) { color: var(--ink); border-color: var(--accent); }
#introNav button:disabled { opacity: .4; cursor: default; }
#introNav #introNext {
  background: var(--accent2);
  border-color: var(--accent2);
  color: #fff;
}
#introNav #introNext:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }

/* the tour highlights the thing it is talking about */
.intro-spotlight {
  position: relative;
  z-index: 301;
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* gentle press feedback on every interactive control */
.opt:active, .btn:active, .railbtn:active, .iconbtn:active,
.seg button:active, .segmented .seg-btn:active, #tabs .tab:active { transform: scale(.965); }

/* ---------------- presentation mode ----------------
 * Here the operator chrome steps out of the way, since a room is reading the
 * scene, not the diagnostics. The type scale sits next to the text it enlarges:
 * css/panels.css for the KPI values a room actually reads, css/scene.css for
 * the sun and viewpoint controls. */

body.presentation .refresh-link,
body.presentation .devid,
body.presentation #perfReadout,
body.presentation #licenseNote { display: none !important; }

/* ---------------- narrow windows ----------------
 * Above 820px the footer and the deltas card stay clear of the 384px right
 * panel (12 + 384 + 12 = 408). Below it the panels span nearly the whole width
 * and there is no clear strip left, so the right panel simply wins on z-index,
 * the same compromise the reference makes. */

@media (max-width: 820px) {
  #brand .t { display: none; }
  .sidepanel { width: calc(100% - 90px); }
  #sidePanel { width: calc(100% - 24px); }
  #appFooter { right: 12px; }
  #deltasPanel { right: 12px; }
}
