/* ── Reset & base ───────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #0f0f1a;
  color: #e0e0e0;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: linear-gradient(135deg, #1a1a36 0%, #232352 100%);
  border-bottom: 2px solid #3a3a6a;
  flex-shrink: 0;
}

.header-titles h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.2;
}

.header-titles h2 {
  font-size: 0.72rem;
  font-weight: 400;
  color: #a8b3d8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* ── Metric tabs ────────────────────────────────────────────────────── */
.metric-tabs {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid #3a3a6a;
  border-radius: 6px;
  overflow: hidden;
}

.metric-tab {
  background: transparent;
  border: 0;
  color: #c8d0ee;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  border-right: 1px solid #2a2a4a;
}

.metric-tab:last-child { border-right: 0; }

.metric-tab:hover { background: rgba(255, 255, 255, 0.06); }

.metric-tab.is-active {
  background: #4f6dff;
  color: #ffffff;
}

#back-button {
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
  cursor: pointer;
  font-weight: 600;
}
#back-button:hover { background: rgba(255, 255, 255, 0.14); }

.toggle-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: #c8d0ee;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 10px;
  border: 1px solid #3a3a6a;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
}
.toggle-field input { accent-color: #4f6dff; cursor: pointer; }

/* ── Timeline bar ───────────────────────────────────────────────────── */
#timeline-bar {
  padding: 8px 16px 10px;
  background: #131326;
  border-bottom: 1px solid #2a2a4a;
  flex-shrink: 0;
}

.timeline-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.timeline-slider-row { margin-top: 8px; }

.timeline-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #a8b3d8;
}

.timeline-field select,
.timeline-field input[type="date"] {
  padding: 6px 8px;
  border: 1px solid #3a3a6a;
  background: #1c1c36;
  color: #ffffff;
  border-radius: 4px;
  min-width: 140px;
  font-size: 0.85rem;
  font-family: inherit;
  color-scheme: dark;
}

.timeline-speed select { min-width: 80px; }
.timeline-speed input[type="number"] {
  padding: 6px 8px;
  border: 1px solid #3a3a6a;
  background: #1c1c36;
  color: #ffffff;
  border-radius: 4px;
  width: 80px;
  font-size: 0.85rem;
}

#play-button {
  padding: 6px 14px;
  font-size: 0.95rem;
  background: #4f6dff;
  color: #ffffff;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 700;
  margin-top: 14px;
}

#play-button:hover { background: #6181ff; }
#play-button.is-playing { background: #c0392b; }
#play-button.is-playing:hover { background: #d04a3a; }

.timeline-current {
  display: flex;
  flex-direction: column;
  margin-top: 14px;
  margin-left: auto;
  text-align: right;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #a8b3d8;
}

.timeline-current-value {
  font-size: 1rem;
  font-weight: 700;
  color: #ffffff;
  text-transform: none;
  letter-spacing: 0;
  margin-top: 2px;
}

#scrubber {
  width: 100%;
  accent-color: #4f6dff;
}

/* ── Legend section ──────────────────────────────────────────────────── */
#legend-section {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px 16px;
  background: #151528;
  border-bottom: 1px solid #2a2a4a;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.legend-label {
  font-size: 0.72rem;
  color: #a0a0c0;
  white-space: nowrap;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#legend {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: nowrap;
}

.legend-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.legend-swatch {
  width: 28px;
  height: 16px;
  border-radius: 2px;
}

.legend-item span {
  font-size: 0.6rem;
  color: #808090;
  white-space: nowrap;
}

.legend-note {
  margin-left: auto;
  font-size: 0.68rem;
  color: #606070;
  white-space: nowrap;
}

#view-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 16px;
  border-bottom: 1px solid #2a2a4a;
  background: #101024;
  flex-wrap: wrap;
}

#breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  min-width: 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: #f0f4ff;
}

.crumb {
  appearance: none;
  background: transparent;
  border: 0;
  margin: 0;
  padding: 0;
  color: #9eb0e8;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.crumb:hover:not(:disabled) {
  color: #ffffff;
  text-decoration: underline;
}

.crumb:disabled {
  color: #f0f4ff;
  -webkit-text-fill-color: #f0f4ff;
  opacity: 1;
  cursor: default;
}

.crumb-sep {
  margin: 0 0.4rem;
  color: #6d7898;
  font-weight: 600;
  user-select: none;
}

#detail-summary {
  font-size: 0.75rem;
  color: #92a1c5;
}

/* ── Heatmap container ───────────────────────────────────────────────── */
#heatmap {
  flex: 1 1 auto;
  overflow: hidden;
  min-height: 0;
}

#heatmap svg { display: block; }

@media (max-height: 600px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  #heatmap {
    flex: none;
    min-height: 320px;
  }
}

/* ── Tooltip ─────────────────────────────────────────────────────────── */
#tooltip {
  position: fixed;
  display: none;
  background: rgba(10, 10, 30, 0.96);
  border: 1px solid #3a3a6a;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 0.78rem;
  line-height: 1.55;
  pointer-events: none;
  z-index: 9999;
  max-width: 300px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
}

.tooltip-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #ffffff;
  border-bottom: 1px solid #3a3a6a;
  margin-bottom: 6px;
  padding-bottom: 4px;
}

.tooltip-section {
  margin-top: 6px;
  padding-top: 4px;
  border-top: 1px dashed #2a2a4a;
}
.tooltip-section:first-of-type {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}

.tooltip-section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8898c8;
  margin-bottom: 2px;
}

.tooltip-row {
  color: #a0a0c0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.tooltip-row .value { color: #e0e0e0; font-variant-numeric: tabular-nums; }
.tooltip-row .value.positive { color: #66dd66; }
.tooltip-row .value.negative { color: #ff6666; }

/* ── Region label text inside SVG ───────────────────────────────────── */
.region-label {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: 13px;
  font-weight: 700;
  fill: #d0d0e0;
  pointer-events: none;
  text-shadow: 0 1px 2px #000;
}

/* ── Tile text inside SVG ───────────────────────────────────────────── */
.tile-name,
.tile-pct {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  fill: rgba(255, 255, 255, 0.95);
  pointer-events: none;
}

.tile-name { font-weight: 700; }

.tile rect { cursor: pointer; }

@media (max-width: 900px) {
  .header-controls {
    width: 100%;
    justify-content: flex-start;
  }
  .timeline-current {
    margin-left: 0;
    text-align: left;
  }
  #view-bar { align-items: flex-start; }
}

/* Auth + admin link buttons in the header */
.header-link {
  background: transparent;
  color: #e8ecf3;
  border: 1px solid #3a4666;
  padding: 0.35rem 0.75rem;
  border-radius: 4px;
  text-decoration: none;
  font-size: 0.85rem;
  cursor: pointer;
  margin-left: 0.4rem;
}
.header-link:hover { background: #2a3556; }
.header-link:disabled { opacity: 0.55; cursor: progress; }
