:root {
  color-scheme: light dark;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5b6776;
  --edge: #d5dbe3;
  --accent: #1a6bc7;
  --chip: #e8eef6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1317;
    --surface: #1b2026;
    --text: #e6ebf1;
    --muted: #9aa7b5;
    --edge: #2f3842;
    --accent: #6cb0f2;
    --chip: #232b34;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--edge);
}
.top-main { flex: 1 1 340px; min-width: 0; }
.top h1 { margin: 0; font-size: 20px; line-height: 1.25; }
.note { margin: 2px 0 0; color: var(--muted); }
.note:empty { display: none; }
.links { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.links a { color: inherit; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.chip {
  padding: 4px 10px;
  border: 1px solid var(--edge);
  border-radius: 999px;
  background: var(--chip);
  white-space: nowrap;
}
.chip-k { color: var(--muted); }
.chip-v { font-weight: 600; font-variant-numeric: tabular-nums; }
.back { font-weight: 600; white-space: nowrap; }

.stage {
  flex: 1 1 auto;
  min-height: 0;
  padding: 16px 20px;
  display: grid;
  gap: 16px;
}
.stage.dash { grid-template-columns: repeat(6, minmax(0, 1fr)); grid-template-rows: minmax(0, 1.35fr) minmax(0, 1fr); grid-auto-rows: minmax(300px, 1fr); }
.stage.dash > .panel { grid-column: span 3; }
/* The dashboard reflows to the panels still in it: a popped-out panel leaves no hole.
   Five: the tall row holds two panels, the second row three. Four: two by two. */
.stage.dash[data-count="5"] > .panel:nth-child(n+3) { grid-column: span 2; }
.stage.dash[data-count="3"] > .panel:last-child { grid-column: 1 / -1; }
.stage.dash[data-count="2"] { grid-template-rows: minmax(0, 1fr); }
.stage.dash[data-count="1"] { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.stage.dash[data-count="1"] > .panel { grid-column: 1 / -1; }
.popped .chip { gap: 8px; }
.btn-small { padding: 2px 8px; font-size: 12px; line-height: 1.4; }
.stage.single { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
@media (max-width: 800px) {
  .stage.dash, .stage.dash[data-count] { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-auto-rows: 420px; }
  .stage.dash[data-count] > .panel, .stage.dash[data-count] > .panel:nth-child(n) { grid-column: auto; }
  .top { padding: 12px 14px; }
  .stage { padding: 12px 14px; }
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 10px;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--edge);
}
.panel-head h2 { margin: 0; font-size: 15px; }
.btn {
  font: inherit;
  padding: 4px 12px;
  color: var(--text);
  background: var(--chip);
  border: 1px solid var(--edge);
  border-radius: 6px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.panel-body { position: relative; flex: 1 1 auto; min-height: 0; overflow: auto; }
.panel-body.fill > * { height: 100%; }
.panel-body.chart { padding: 8px; }
.panel-body.map { overflow: hidden; }
.panel-body.map .lat-mapview__legend { top: 8px; bottom: auto; left: auto; right: 8px; }
.panel-body.kpi {
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  grid-auto-rows: 96px;
  align-content: start;
  gap: 12px;
}
.panel-body.kpi .lat-kpi__tile { min-width: 0; justify-content: center; }
.panel-body.kpi .lat-kpi__value { font-size: 34px; font-weight: 650; line-height: 1.1; }
.away {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
}
.away p { margin: 0; font-size: 15px; }
.lg-hidden { position: absolute; left: -9999px; top: 0; width: 640px; height: 240px; overflow: hidden; }

.foot { padding: 10px 20px; border-top: 1px solid var(--edge); background: var(--surface); color: var(--muted); }
