:root {
  --text-xs: clamp(0.75rem, 0.72rem + 0.15vw, 0.8125rem);
  --text-sm: clamp(0.875rem, 0.85rem + 0.15vw, 0.9375rem);
  --text-base: 1rem;
  --text-lg: clamp(1.125rem, 1.05rem + 0.4vw, 1.375rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-16: 4rem;

  --font-body: 'Golos Text', 'Segoe UI', system-ui, sans-serif;

  --color-bg: oklch(0.975 0.006 85);
  --color-surface: oklch(0.995 0.003 85);
  --color-surface-2: oklch(0.945 0.008 85);
  --color-text: oklch(0.24 0.012 60);
  --color-text-muted: oklch(0.47 0.012 60);
  --color-border: oklch(0.24 0.012 60 / 0.12);
  --color-primary: oklch(0.5 0.17 25);
  --color-primary-strong: oklch(0.42 0.16 25);
  --color-primary-soft: oklch(0.5 0.17 25 / 0.1);

  /* Status colours; app.js uses the same hex values for the map layers. */
  --color-free: #2f8f5b;
  --color-free-strong: #1f6e44; /* green for text and hovered marks: AA contrast on the surface */
  --color-free-soft: #2f8f5b1f;
  --color-none: #9a948c;
  --color-error: #c8732a;

  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --transition-interactive: 160ms cubic-bezier(0.16, 1, 0.3, 1);
}

html,
body {
  height: 100%;
}

body {
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: minmax(19rem, 23rem) 1fr;
  height: 100dvh;
}

/* ---------- Panel ---------- */
.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
}

.panel__head {
  padding: var(--space-5) var(--space-5) var(--space-3);
}

.panel__head h1 {
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.panel__meta,
.panel__updated {
  margin-top: var(--space-1);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.panel__updated {
  margin-top: 0;
  font-size: var(--text-xs);
}

.panel__updated.is-stale {
  color: var(--color-primary-strong);
  font-weight: 600;
}

.town {
  display: block;
  width: 100%;
  min-height: 2.25rem;
  margin-top: var(--space-3);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
}

.town:hover {
  background: var(--color-surface-2);
}

/* ---------- Chart ---------- */
.chart {
  margin-top: var(--space-4);
}

.chart[hidden] {
  display: none;
}

.chart__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-2);
  font-size: var(--text-xs);
}

/* Title and readout never wrap, so hovering the chart cannot shift the layout. */
.chart__title {
  flex: none;
  font-weight: 600;
  white-space: nowrap;
}

.chart__scope {
  font-weight: 400;
  color: var(--color-text-muted);
}

.chart__scope[hidden] {
  display: none;
}

.chart__readout {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chart__detail {
  max-width: none;
  height: 1.125rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-xs);
  line-height: 1.125rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.chart__cols {
  display: flex;
  gap: 2px;
  height: 5rem;
  padding-top: 1.125rem; /* room for the peak's value label */
  border-bottom: 1px solid var(--color-border);
}

.col {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  border-radius: 0;
}

.col--empty {
  pointer-events: none;
}

.col__bar {
  width: 100%;
  max-width: 24px;
  height: var(--h);
  background: var(--color-free);
  border-radius: 4px 4px 0 0;
  transition: background var(--transition-interactive);
}

.col:hover .col__bar,
.col:focus-visible .col__bar {
  background: var(--color-free-strong);
}

.col__value {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

.chart__axis {
  display: flex;
  gap: 2px;
  height: 1.125rem;
}

.chart__tick {
  position: relative;
  flex: 1;
  min-width: 0;
}

.chart__date {
  position: absolute;
  top: 0.125rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chart__date--first {
  left: 0;
  transform: none;
}

.tabs {
  display: flex;
  gap: var(--space-1);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.tab {
  flex: 1;
  min-height: 2.5rem;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

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

.tab[aria-selected='true'] {
  color: var(--color-text);
  border-bottom-color: var(--color-free);
}

.branches[hidden] {
  display: none;
}

.branches {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-2) var(--space-2) var(--space-4);
  overscroll-behavior: contain;
}

.group + .group {
  margin-top: var(--space-2);
}

.group__title {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  position: sticky;
  top: calc(-1 * var(--space-2));
  z-index: 1;
  padding: var(--space-2) var(--space-3) var(--space-1);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  background: var(--color-surface);
}

.group__count {
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  font-variant-numeric: tabular-nums;
}

.group__list {
  list-style: none;
}

.branch {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  column-gap: var(--space-3);
  width: 100%;
  min-height: 2.75rem;
  padding: var(--space-2) var(--space-3);
  text-align: left;
  border-radius: var(--radius-md);
}

.branch:hover {
  background: var(--color-surface-2);
}

.branch[aria-pressed='true'] {
  background: var(--color-free-soft);
}

.branch__name {
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1.3;
}

.branch__count {
  min-width: 2.25rem;
  padding: 0 var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.6;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: var(--color-free);
  border-radius: 999px;
}

.branch[data-status='none'] .branch__count {
  background: var(--color-none);
}

.branch[data-status='error'] .branch__count {
  background: var(--color-error);
}

.branch__next {
  grid-column: 1 / -1;
  font-size: var(--text-xs);
  line-height: 1.4;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.branch[data-status='error'] .branch__next {
  color: var(--color-error);
}

.slot {
  display: grid;
  grid-template-columns: 3.25rem 1fr auto;
  align-items: baseline;
  column-gap: var(--space-2);
  width: 100%;
  min-height: 2.75rem;
  padding: var(--space-2) var(--space-3);
  text-align: left;
  border-radius: var(--radius-md);
}

.slot:hover {
  background: var(--color-surface-2);
}

.slot[aria-pressed='true'] {
  background: var(--color-free-soft);
}

.slot__time {
  font-size: var(--text-base);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--color-free-strong);
}

.slot__name {
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1.3;
}

.slot__more {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.slot__city {
  grid-column: 2 / -1;
  font-size: var(--text-xs);
  line-height: 1.4;
  color: var(--color-text-muted);
}

.more {
  display: flex;
  width: calc(100% - 2 * var(--space-3));
  margin: var(--space-3) var(--space-3) 0;
}

.empty {
  padding: var(--space-4) var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.panel__foot {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border);
}

.btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  text-decoration: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.btn:hover {
  background: var(--color-surface-2);
}

/* ---------- Map ---------- */
.map-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--color-surface-2);
}

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

.maplibregl-map {
  font-family: var(--font-body);
}

.legend {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
  /* leave room for the zoom buttons on the right */
  max-width: calc(100% - var(--space-3) - 3.5rem);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text);
  background: oklch(0.995 0.003 85 / 0.92);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 1px 4px oklch(0.24 0.012 60 / 0.12);
}

.has-popup .legend {
  display: none;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.legend span[hidden] {
  display: none;
}

.dot {
  display: inline-block;
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
}

.dot--free {
  background: var(--color-free);
}

.dot--none {
  background: var(--color-none);
}

.dot--error {
  background: var(--color-error);
}

.map-error {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--space-6);
  max-width: none;
  text-align: center;
  color: var(--color-text-muted);
}

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

/* ---------- Popup ---------- */
.branch-popup .maplibregl-popup-content {
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 18px oklch(0.24 0.012 60 / 0.2);
}

.branch-popup .maplibregl-popup-close-button {
  width: 2rem;
  height: 2rem;
  font-size: 1.25rem;
  color: var(--color-text-muted);
}

.pop {
  font-family: var(--font-body);
  color: var(--color-text);
}

.pop__kicker {
  padding-right: var(--space-6);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.pop__title {
  margin-top: var(--space-1);
  padding-right: var(--space-4);
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1.3;
}

.pop__city {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.pop__note,
.pop__error {
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-error);
}

.pop__sum,
.pop__empty {
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 500;
}

.pop__days {
  position: relative; /* offset parent for scrolling the expanded day into view */
  margin-top: var(--space-2);
  max-height: min(18rem, 45dvh);
  overflow-y: auto;
  overscroll-behavior: contain;
  border-top: 1px solid var(--color-border);
}

.day {
  border-bottom: 1px solid var(--color-border);
}

.day summary,
.day--closed {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-1);
  font-size: var(--text-sm);
}

.day summary {
  cursor: pointer;
  list-style: none;
}

.day summary::-webkit-details-marker {
  display: none;
}

.day summary::before {
  content: '▸';
  margin-right: var(--space-1);
  color: var(--color-text-muted);
}

.day[open] summary::before {
  content: '▾';
}

.day summary:hover {
  background: var(--color-surface-2);
}

.day__date {
  flex: 1;
  font-weight: 500;
}

.day__count {
  font-size: var(--text-xs);
  color: var(--color-free-strong);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.day--closed .day__date,
.day--closed .day__count {
  color: var(--color-text-muted);
  font-weight: 400;
}

.times {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding: 0 var(--space-1) var(--space-3);
  list-style: none;
}

.times li {
  padding: 0.0625rem var(--space-2);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  background: var(--color-free-soft);
  border-radius: var(--radius-sm);
}

.pop__link {
  display: inline-block;
  margin-top: var(--space-3);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-free-strong);
}

/* ---------- Trend chart ---------- */
.trend {
  display: grid;
  grid-template-columns: 1fr 2.75rem;
  grid-template-rows: minmax(0, 1fr);
  height: 5rem;
  margin-top: var(--space-1);
}

.trend__area {
  position: relative;
  min-width: 0;
  border-radius: 0;
  cursor: crosshair;
}

/* Absolutely sized: the square viewBox must stretch to the plot instead of dictating its height. */
.trend__svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  overflow: visible;
}

.trend__line {
  fill: none;
  stroke: var(--color-free);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.trend__zero {
  stroke: var(--color-border);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.trend__dot {
  position: absolute;
  width: 0.5rem;
  height: 0.5rem;
  margin: -0.25rem 0 0 -0.25rem;
  border-radius: 50%;
  background: var(--color-free);
  box-shadow: 0 0 0 2px var(--color-surface);
  pointer-events: none;
}

.trend__cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--color-text-muted);
  opacity: 0.5;
  pointer-events: none;
}

.trend__cursor[hidden] {
  display: none;
}

.trend__gutter {
  position: relative;
}

.trend__y {
  position: absolute;
  right: 0;
  transform: translateY(-50%);
  font-size: 0.6875rem;
  line-height: 1;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.trend__axis {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-2);
  margin-top: 0.125rem;
  padding-right: 2.75rem;
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.trend__axis > :last-child {
  text-align: right;
}

.trend__legend {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.key {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 2px;
}

.key--added {
  background: #2a78d6;
}

.key--taken {
  margin-left: var(--space-2);
  background: #e34948;
}

/* Until there are two updates there is no line and nothing to compare. */
.chart--waiting .trend__legend {
  visibility: hidden;
}

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }

  .map-wrap {
    grid-row: 1;
  }

  .panel {
    grid-row: 2;
    border-right: 0;
    border-top: 1px solid var(--color-border);
  }

  .panel__head {
    padding: var(--space-3) var(--space-4) var(--space-2);
  }

  .chart {
    margin-top: var(--space-2);
  }

  .chart__cols {
    height: 3.5rem;
  }

  /* The short panel has no room for a second chart. */
  .chart--trend {
    display: none;
  }

  .pop__days {
    max-height: 20dvh;
  }

  /* zoom buttons would crowd the popup's close button; pinch-zoom still works */
  .has-popup .maplibregl-ctrl-top-right {
    display: none;
  }

  .panel__foot {
    padding: var(--space-2) var(--space-3);
  }
}
