:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;
  --status-highlight: #f0c400;

  /* Kp-skala: rød (svag) -> gul (omkring alarmtærsklen) -> grøn (stærk) */
  --seq-100: #d1403f;
  --seq-200: #dd6b35;
  --seq-300: #e2953a;
  --seq-400: #e2b93a;
  --seq-500: #c7c93f;
  --seq-600: #8bbf45;
  --seq-700: #4a9d4f;

  --map-shadow: rgba(20, 20, 10, 0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);

    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-critical: #e66767;
    --status-highlight: #ffd93d;

    --seq-100: #e5605f;
    --seq-200: #e8813f;
    --seq-300: #eba83f;
    --seq-400: #edc93f;
    --seq-500: #c9d558;
    --seq-600: #97d15c;
    --seq-700: #5cc262;

    --map-shadow: rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  padding: 16px;
}

main {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

main[hidden] {
  display: none;
}

header.page-header {
  max-width: 860px;
  margin: 0 auto 16px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px;
}

header.page-header h1 {
  font-size: 1.25rem;
  margin: 0;
}

header.page-header .location {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

section {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

/* Tabs (switch between the Nordlys and Strava views) */
.tabs {
  max-width: 860px;
  margin: 0 auto 16px;
  display: flex;
  gap: 20px;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 2px;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  color: var(--text-primary);
  border-bottom-color: var(--text-primary);
}

/* Hero / stat tile */
.hero {
  text-align: center;
}

.hero .eyebrow {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.hero .headline {
  font-size: clamp(1.6rem, 5vw, 2.6rem);
  font-weight: 700;
  line-height: 1.15;
  margin: 0 0 8px;
  font-variant-numeric: proportional-nums;
}

.hero .headline.active {
  color: var(--status-good);
}

.hero .detail {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* Strava hero: four peer stats, not one headline - a stat-tile row */
.strava-hero {
  text-align: center;
}

.strava-hero .eyebrow {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 20px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 20px;
}

.stat-row[hidden] {
  display: none;
}

.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-value {
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.strava-hero .sub {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 20px 0 0;
}

/* Strava-kort: .strava-map-section selv får baggrund/kant/radius/padding
   gratis fra den bare `section`-regel ovenfor - kun selve kort-boksen og
   Leaflets eget UI skal overstyres her. */
.strava-map-section .sub {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: 0 0 12px;
}

.strava-map {
  height: 360px;
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden; /* klipper fliselag til de afrundede hjørner */
}

.strava-map[hidden] {
  display: none;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--surface-1);
  color: var(--text-primary);
  box-shadow: 0 6px 18px var(--map-shadow);
}

.leaflet-popup-content {
  font-family: inherit;
  font-size: 0.85rem;
  margin: 10px 12px;
}

.leaflet-control-zoom a {
  background: var(--surface-1);
  color: var(--text-primary);
}

.leaflet-control-zoom a:hover {
  background: var(--gridline);
}

.leaflet-bar {
  border-color: var(--border) !important;
}

/* Dæmper OSM-flisernes lyse farver i mørkt tema, så kortet ikke bliver et
   lyst hul i en ellers mørk side. Ikke pixel-perfekt (farver labels med),
   men godt nok til et hobbyprojekt. */
@media (prefers-color-scheme: dark) {
  .strava-map .leaflet-tile-pane {
    filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9);
  }
}

/* Timeline: dag x time-gitter (dage som rækker, timer 00-23 som kolonner) */
.timeline h2, .windows h2, .datastatus h2, .strava-by-type h2, .strava-map-section h2 {
  font-size: 1rem;
  margin: 0 0 4px;
}

.timeline .sub {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: 0 0 12px;
}

.grid-scroll {
  overflow-x: auto;
  padding-bottom: 4px;
}

.week-grid {
  display: grid;
  grid-template-columns: 72px repeat(24, minmax(20px, 1fr));
  gap: 2px;
  min-width: 680px;
}

.week-grid .gcell {
  font-variant-numeric: tabular-nums;
}

.week-grid .hour-head {
  text-align: center;
  font-size: 0.62rem;
  color: var(--text-muted);
  padding-bottom: 4px;
}

.week-grid .hour-head.anchor {
  color: var(--text-secondary);
  font-weight: 600;
}

.week-grid .row-day-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: right;
  padding-right: 8px;
  line-height: 1.25;
}

.week-grid .row-day-label .dow {
  font-weight: 700;
  color: var(--text-primary);
}

.week-grid .swatch {
  height: 28px;
  border-radius: 4px;
  border: 1px solid var(--border);
  position: relative;
  transition: transform 0.1s;
}

.week-grid .swatch:not(.empty):hover {
  transform: scale(1.12);
  z-index: 2;
}

.week-grid .swatch.daylight {
  opacity: 0.35;
}

.week-grid .swatch.empty {
  background: transparent;
  border-style: dashed;
  opacity: 0.3;
}

.week-grid .swatch.low-confidence {
  opacity: 0.55;
  background-image: repeating-linear-gradient(
    45deg,
    rgba(0, 0, 0, 0.16) 0,
    rgba(0, 0, 0, 0.16) 1.5px,
    transparent 1.5px,
    transparent 5px
  );
}

.week-grid .swatch.match::after {
  content: "";
  position: absolute;
  inset: -2px;
  border: 2px solid var(--status-highlight);
  border-radius: 6px;
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.legend-row .item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid var(--border);
  display: inline-block;
}

.legend-ramp {
  width: 80px;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--seq-100), var(--seq-700));
  display: inline-block;
}

.legend-ring {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 2px solid var(--status-highlight);
  display: inline-block;
}

.legend-hatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--seq-400);
  opacity: 0.55;
  background-image: repeating-linear-gradient(
    45deg,
    rgba(0, 0, 0, 0.16) 0,
    rgba(0, 0, 0, 0.16) 1.5px,
    transparent 1.5px,
    transparent 5px
  );
  display: inline-block;
}

.confidence-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.confidence-badge.high {
  background: color-mix(in srgb, var(--status-good) 18%, transparent);
  color: var(--status-good);
}

.confidence-badge.low {
  background: color-mix(in srgb, var(--status-warning) 25%, transparent);
  color: var(--text-secondary);
}

/* Windows table */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--gridline);
}

th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

td.num, th.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.empty-state {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Data status */
.datastatus .row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 6px;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.ok { background: var(--status-good); }
.dot.fail { background: var(--status-critical); }

#stravaByTypeTable .dot {
  margin-right: 8px;
  vertical-align: middle;
}

footer {
  max-width: 860px;
  margin: 16px auto 0;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: center;
}
