:root {
  --cambium-primary:   #3AE8D1;
  --cambium-accent:    #FD5001;
  --cambium-secondary: #8D51F5;
  --cambium-tertiary:  #90BBFF;
  --cambium-fg:        #000000;
  --cambium-bg:        #FFFFFF;
  --cambium-muted:     #6B7280;
  --cambium-surface:   #F9FAFB;
}

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--cambium-fg);
  background: var(--cambium-bg);
}

#map { position: absolute; inset: 0; }

/* ── Side panel ─────────────────────────────────────────────────────────── */
#panel {
  position: absolute; top: 12px; left: 12px; z-index: 10;
  background: rgba(255,255,255,0.96);
  border: 1px solid color-mix(in srgb, var(--cambium-primary) 35%, transparent);
  border-radius: 10px;
  padding: 14px 18px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  width: 280px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  backdrop-filter: blur(6px);
}

#panel h1 {
  font-size: 15px; margin: 0 0 2px;
  color: var(--cambium-fg);
  letter-spacing: -0.01em;
  display: flex; align-items: center; gap: 8px;
}
#panel h1::before {
  content: ""; display: inline-block;
  width: 10px; height: 10px; flex-shrink: 0;
  border-radius: 2px;
  background: linear-gradient(135deg, var(--cambium-primary), var(--cambium-secondary));
}
#panel .subtitle { margin: 0 0 12px; font-size: 11px; color: var(--cambium-muted); }

/* ── Year / office toggles ──────────────────────────────────────────────── */
.ctrl-group { margin-bottom: 12px; }
.ctrl-label {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--cambium-muted); margin-bottom: 4px;
}

.btn-row { display: flex; gap: 4px; flex-wrap: wrap; }
.btn-row button {
  flex: 1 1 auto;
  padding: 5px 0; border: 1px solid #d1d5db;
  border-radius: 5px; background: white; cursor: pointer;
  font-size: 12px; color: var(--cambium-fg);
  transition: background 0.15s, border-color 0.15s;
}
.btn-row button.active {
  background: var(--cambium-primary);
  border-color: var(--cambium-primary);
  color: #000; font-weight: 600;
}
.btn-row button:hover:not(.active) { background: var(--cambium-surface); }

/* ── Layer toggles ──────────────────────────────────────────────────────── */
.section-title {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--cambium-muted);
  margin: 10px 0 4px;
}
label.layer-toggle {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; cursor: pointer;
  padding: 3px 4px; border-radius: 4px;
}
label.layer-toggle:hover { background: var(--cambium-surface); }
label.layer-toggle input { accent-color: var(--cambium-secondary); }

/* ── Legend ─────────────────────────────────────────────────────────────── */
#legend {
  margin: 10px 0 2px;
  font-size: 11px; color: var(--cambium-muted);
}
#legend .legend-title { margin-bottom: 4px; font-weight: 500; }
.legend-row { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.swatch { display: inline-block; width: 16px; height: 12px; border-radius: 2px; flex-shrink: 0; }

/* ── Precinct detail (right panel) ──────────────────────────────────────── */
/* The .popup-* metric-grid classes below are shared by the detail panel;
   the floating maplibre popup was retired in favour of this panel. */
#detail {
  position: absolute; top: 12px; right: 12px; bottom: 12px; z-index: 11;
  width: 340px;
  background: rgba(255,255,255,0.97);
  border: 1px solid color-mix(in srgb, var(--cambium-primary) 35%, transparent);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.14);
  padding: 16px 18px 20px;
  overflow-y: auto;
  backdrop-filter: blur(6px);
  transition: transform 0.22s ease, opacity 0.22s ease;
}
#detail.hidden {
  transform: translateX(calc(100% + 24px));
  opacity: 0;
  pointer-events: none;
}
#detail-close {
  position: absolute; top: 8px; right: 10px;
  width: 26px; height: 26px; line-height: 22px;
  border: 1px solid #e5e7eb; border-radius: 6px;
  background: white; cursor: pointer;
  font-size: 18px; color: var(--cambium-muted);
}
#detail-close:hover { background: var(--cambium-surface); color: var(--cambium-fg); }

/* When the panel is open, keep the map controls clear of it */
body.detail-open .maplibregl-ctrl-top-right,
body.detail-open .maplibregl-ctrl-bottom-right { margin-right: 352px; }

/* Detail header */
.d-header { margin: 0 24px 12px 0; }
.d-eyebrow {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--cambium-muted);
}
.d-title { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; margin-top: 2px; }
.d-sub { font-size: 12px; color: var(--cambium-muted); margin-top: 1px; }
.d-note { font-size: 10px; font-style: italic; color: var(--cambium-muted); margin-top: 8px; }

/* Shared metric grid (also used by the detail panel) */
.popup-title { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.popup-grid { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; }
.popup-key { color: var(--cambium-muted); }
.popup-val { font-weight: 500; text-align: right; }
.popup-section { margin-top: 6px; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--cambium-muted);
  grid-column: 1 / -1; border-top: 1px solid #e5e7eb; padding-top: 6px; margin-top: 10px; }

/* Demographic composition bars */
.d-bars { margin-top: 8px; }
.bar { margin: 7px 0; }
.bar-head { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 3px; }
.bar-head small { color: var(--cambium-muted); font-weight: 400; margin-left: 4px; }
.bar-pct { font-weight: 600; font-variant-numeric: tabular-nums; }
.bar-track { height: 7px; border-radius: 4px; background: #eceef1; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; }

/* Example messaging (action view) */
.msg-theme { font-size: 12px; font-weight: 600; margin: 6px 0 3px; }
.msg-body { font-size: 12px; line-height: 1.45; }

/* Primary drivers — signed attribution bars (blue → D, red → R) */
.drv-headline { font-size: 12px; margin: 6px 0 2px; }
.drv-headline small { color: var(--cambium-muted); }
.drv-row { margin: 7px 0; }
.drv-head { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 3px; }
.drv-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.drv-track {
  position: relative; height: 7px; border-radius: 4px; background: #eceef1;
}
.drv-track::before {
  content: ""; position: absolute; left: 50%; top: -1px; bottom: -1px;
  width: 1px; background: #c7cbd1;
}
.drv-fill { position: absolute; top: 0; height: 100%; }
.drv-fill.d { left: 50%; background: #2166ac; border-radius: 0 4px 4px 0; }
.drv-fill.r { right: 50%; background: #b2182b; border-radius: 4px 0 0 4px; }

.drv-retry {
  font-size: 10px; padding: 1px 8px; margin-left: 4px;
  border: 1px solid #d1d5db; border-radius: 4px; background: white; cursor: pointer;
}
.drv-retry:hover { background: var(--cambium-surface); }

@media (max-width: 640px) {
  #detail { width: auto; left: 12px; max-height: 55vh; top: auto; }
  body.detail-open .maplibregl-ctrl-top-right,
  body.detail-open .maplibregl-ctrl-bottom-right { margin-right: 0; }
}

/* ── Loading indicator ──────────────────────────────────────────────────── */
#loading {
  position: absolute; bottom: 20px; right: 20px; z-index: 10;
  background: rgba(255,255,255,0.9); border-radius: 6px;
  padding: 6px 12px; font-size: 12px; color: var(--cambium-muted);
  display: none;
}

/* ── Attribution nudge (move above the panel area) ─────────────────────── */
.maplibregl-ctrl-bottom-left { left: 310px; }
