/* Shared design tokens and primitives for the dashboard and the zone editor.
   One stylesheet so the two pages cannot drift apart. */

:root {
  color-scheme: light dark;

  /* Surfaces */
  --bg: #eef1f6;
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --line: #e2e8f0;
  --line-soft: #eef2f7;

  /* Ink */
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;

  /* Series colours — unchanged, the charts depend on them */
  --red: #e0453f;
  --green: #16a34a;
  --blue: #2b7fd4;
  --accent: #7c5cd6;

  /* Brand */
  --brand: #0e7490;
  --brand-ink: #ffffff;
  --brand-soft: #ecfeff;

  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 8px 24px -12px rgba(15, 23, 42, .18);
  --shadow-lg: 0 2px 4px rgba(15, 23, 42, .05), 0 18px 44px -20px rgba(15, 23, 42, .28);

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;

  --gap: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1017;
    --panel: #131a24;
    --panel-2: #182131;
    --line: #253044;
    --line-soft: #1d2635;

    --ink: #e8eef6;
    --ink-2: #c2cdda;
    --muted: #8b9ab0;

    --red: #ff7b72;
    --green: #56d18a;
    --blue: #6ea8ff;
    --accent: #b39bff;

    --brand: #22d3ee;
    --brand-ink: #06222a;
    --brand-soft: #0d2b33;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px -16px rgba(0, 0, 0, .8);
    --shadow-lg: 0 2px 6px rgba(0, 0, 0, .45), 0 22px 50px -24px rgba(0, 0, 0, .9);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.topbar-inner {
  max-width: 1560px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.brandmark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(140deg, var(--brand), var(--blue));
  display: grid;
  place-items: center;
  color: var(--brand-ink);
  font-weight: 700;
  font-size: 15px;
  flex: none;
}

.titles { min-width: 0; margin-right: auto; }

.titles h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.titles .meta {
  color: var(--muted);
  font-size: 12.5px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.meta .dot-sep::before { content: "·"; margin-right: 10px; }

.coords {
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
}

/* ------------------------------------------------------------------ layout */

.wrap {
  max-width: 1560px;
  margin: 0 auto;
  padding: var(--gap) 24px 64px;
}

@media (max-width: 560px) {
  :root { --gap: 12px; }
  .wrap { padding: 12px 12px 48px; }
  .topbar-inner { padding: 10px 14px; }
  .card { padding: 15px 14px 16px; border-radius: var(--r); }
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--gap);
  /* Stretch, not start: cards sharing a row match heights, so their tops and
     bottoms line up instead of ending wherever their content happens to. */
  align-items: stretch;
}

/* Column spans. Mobile is one column; the spans only apply once there is room. */
.col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-12 { grid-column: span 12; }

@media (min-width: 760px) {
  .col-3 { grid-column: span 6; }
  .col-4 { grid-column: span 6; }
  .col-5 { grid-column: span 6; }
  .col-6 { grid-column: span 6; }
  .col-7 { grid-column: span 12; }
  .col-8 { grid-column: span 12; }
  .col-9 { grid-column: span 12; }
}

@media (min-width: 1180px) {
  .col-3 { grid-column: span 3; }
  .col-4 { grid-column: span 4; }
  .col-5 { grid-column: span 5; }
  .col-6 { grid-column: span 6; }
  .col-7 { grid-column: span 7; }
  .col-8 { grid-column: span 8; }
  .col-9 { grid-column: span 9; }
}

/* ------------------------------------------------------------------- cards */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 18px 20px 20px;
  min-width: 0;
  /* A column, so the chart can take the slack when a card is stretched to match
     a taller neighbour rather than leaving a gap under the heading. */
  display: flex;
  flex-direction: column;
}

/* The note block is what varies most between paired panels, so let it reserve a
   consistent amount of room and push the charts onto a common baseline. */
.card > .note { flex: none; }
.card > .scroll { margin-top: auto; }
.card > .legend { flex: none; }

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}

.card h2 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 650;
  letter-spacing: -0.005em;
}

.note {
  color: var(--muted);
  font-size: 12.5px;
  margin: 6px 0 14px;
  max-width: 78ch;
}

/* --------------------------------------------------------------- kpi tiles */

.kpis {
  grid-column: span 12;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--gap);
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 15px 17px 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: relative;
  overflow: hidden;
}

.kpi::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--kpi-accent, var(--brand));
}

.kpi .k {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
}

.kpi .v {
  font-size: 27px;
  font-weight: 640;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.kpi .sub {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--line-soft);
  color: var(--muted);
}

.pill.up { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.pill.down { background: color-mix(in srgb, var(--blue) 14%, transparent); color: var(--blue); }
.pill.flat { background: var(--line-soft); color: var(--muted); }

/* ------------------------------------------------------------------ charts */

.scroll { overflow-x: auto; }

/* Charts are drawn at their container's width, down to a floor of 480 (see
   MIN_W in charts.js). Below that the SVG keeps its natural size and the panel
   pans, rather than shrinking the axis text to nothing. */
.chart svg { display: block; width: 100%; min-width: 480px; height: auto; }

.grid-line { stroke: var(--line); stroke-width: 1; }
.axis { fill: var(--muted); font-size: 11px; }
.dot { opacity: .85; }
.dot.suspect { opacity: .9; }
.dot-hit { cursor: pointer; }

.legend {
  display: flex;
  gap: 8px 18px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 10px;
}

.legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.empty {
  color: var(--muted);
  padding: 40px 0;
  text-align: center;
  font-size: 13.5px;
}

/* ------------------------------------------------------------------ inputs */

select, button, input {
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 6px 10px;
}

select { cursor: pointer; }
button { cursor: pointer; }
button:disabled { opacity: .5; cursor: not-allowed; }

button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
  font-weight: 620;
}

input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.tabs { display: flex; gap: 4px; }

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
}

.tab[aria-selected="true"] { background: var(--brand-soft); color: var(--brand); }
