:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --border: #e8e8e8;
  --ink: #111111;
  --muted: #888888;
  --faint: #f5f5f5;
  --current: #1a6b5a;
  --new: #b05a1a;
  --good: #1a6b3a;
  --bad: #b01a1a;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app-shell[hidden] {
  display: none;
}

.password-gate {
  align-items: center;
  background: #fff;
  display: flex;
  inset: 0;
  justify-content: center;
  min-height: 100vh;
  padding: 40px;
  position: fixed;
  z-index: 9999;
}

.password-gate[hidden] {
  display: none;
}

.password-panel {
  border-top: 1px solid var(--border);
  max-width: 420px;
  padding-top: 40px;
  width: 100%;
}

.password-panel h2 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 300;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: 12px;
}

.password-panel p:not(.eyebrow):not(.password-error) {
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.7;
  margin-bottom: 24px;
}

.password-panel input {
  background: var(--faint);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--ink);
  display: block;
  font: inherit;
  margin-bottom: 10px;
  padding: 12px;
  width: 100%;
}

.password-panel button {
  width: 100%;
}

.password-error {
  color: var(--bad);
  font-size: 0.8125rem;
  margin-top: 12px;
  min-height: 1.25em;
}

/* ── Layout ─────────────────────────────────────── */

.page {
  margin: 0 auto;
  max-width: 1120px;
  padding: 0 40px;
}

/* ── Header ─────────────────────────────────────── */

header {
  border-bottom: 1px solid var(--border);
  padding: 72px 0 64px;
}

.header-inner {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 20px;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.25rem);
  font-weight: 300;
  letter-spacing: -0.03em;
  line-height: 1.1;
  max-width: 680px;
}

h1 em {
  font-style: normal;
  font-weight: 600;
}

.intro {
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.7;
  margin-top: 16px;
  max-width: 520px;
}

/* ── Recalculate button ──────────────────────────── */

button {
  background: var(--ink);
  border: none;
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 10px 20px;
  transition: opacity 0.15s;
  white-space: nowrap;
}

button:hover {
  opacity: 0.75;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── Summary strip ───────────────────────────────── */

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
}

.summary-card {
  padding: 48px 0;
  border-right: 1px solid var(--border);
}

.summary-card:last-child {
  border-right: none;
  padding-left: 48px;
}

.summary-card:not(:first-child):not(:last-child) {
  padding-left: 48px;
}

.summary-card > span {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: block;
  margin-bottom: 12px;
}

.summary-card > strong {
  display: block;
  font-size: clamp(1.75rem, 3vw, 2.75rem);
  font-weight: 300;
  letter-spacing: -0.03em;
  line-height: 1;
  margin-bottom: 8px;
}

.summary-card.current > strong { color: var(--current); }
.summary-card.new > strong     { color: var(--new); }

.summary-card > small {
  color: var(--muted);
  font-size: 0.8125rem;
}

/* ── Controls bar ────────────────────────────────── */

.controls {
  align-items: center;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 32px;
  justify-content: space-between;
  padding: 20px 0;
}

.api-section {
  border-bottom: 1px solid var(--border);
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 440px);
  padding: 32px 0;
}

.api-section[hidden] {
  display: none;
}

.api-section h2 {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.api-section p {
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.7;
  max-width: 560px;
}

.api-form {
  align-items: flex-start;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.api-form input {
  background: var(--faint);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--ink);
  font: inherit;
  font-size: 0.8125rem;
  min-width: 0;
  padding: 10px 12px;
  width: 100%;
}

.api-status {
  grid-column: 1 / -1;
}

label {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 0.8125rem;
  gap: 8px;
}

select {
  appearance: none;
  background: var(--faint);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--ink);
  font: inherit;
  font-size: 0.8125rem;
  padding: 6px 10px;
}

.control-note {
  color: var(--muted);
  font-size: 0.8125rem;
}

/* ── Map ─────────────────────────────────────────── */

.map-section {
  border-bottom: 1px solid var(--border);
  padding: 48px 0 0;
}

.map-meta {
  align-items: flex-end;
  display: flex;
  gap: 24px;
  justify-content: space-between;
  margin-bottom: 24px;
}

.map-meta h2 {
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.map-meta p {
  font-size: 0.8125rem;
  color: var(--muted);
}

.legend {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: flex-end;
  flex-shrink: 0;
}

.legend span {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  font-size: 0.75rem;
  gap: 6px;
  letter-spacing: 0.02em;
}

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

.current-dot  { background: var(--current); }
.new-dot      { background: var(--new); }

.line {
  border-radius: 2px;
  display: inline-block;
  height: 2px;
  width: 20px;
}

.current-line { background: var(--current); }
.new-line     { background: var(--new); }

#map {
  border: 1px solid var(--border);
  border-radius: 4px;
  display: block;
  height: min(56vh, 520px);
  min-height: 360px;
  max-width: 100%;
  overflow: hidden;
  position: relative;
  width: 100%;
  margin-bottom: 48px;
}

.leaflet-container {
  font-family: inherit;
  overflow: hidden;
  position: relative;
  touch-action: pan-x pan-y;
}

/* Local safeguards in case the CDN Leaflet CSS is delayed or blocked. */
.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  left: 0;
  position: absolute;
  top: 0;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  user-select: none;
  -webkit-user-drag: none;
}

.leaflet-tile {
  border: 0;
  filter: none;
  max-width: none !important;
  max-height: none !important;
}

.leaflet-pane > svg {
  pointer-events: none;
}

.leaflet-marker-icon,
.leaflet-interactive {
  pointer-events: auto;
}

.leaflet-control-container .leaflet-top,
.leaflet-control-container .leaflet-bottom {
  position: absolute;
  z-index: 1000;
}

.leaflet-control-container .leaflet-top {
  top: 10px;
}

.leaflet-control-container .leaflet-left {
  left: 10px;
}

.leaflet-control-container .leaflet-right {
  right: 10px;
}

.leaflet-control-container .leaflet-bottom {
  bottom: 10px;
}

.leaflet-control {
  float: left;
  clear: both;
}

.leaflet-right .leaflet-control {
  float: right;
}

.leaflet-control-zoom a {
  background: #fff;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  display: block;
  height: 26px;
  line-height: 26px;
  text-align: center;
  text-decoration: none;
  width: 26px;
}

/* map markers */
.map-marker {
  align-items: center;
  border-radius: 50%;
  color: #fff;
  display: flex;
  font-size: 0.6rem;
  font-weight: 700;
  height: 26px;
  justify-content: center;
  letter-spacing: 0;
  outline: 2px solid #fff;
  width: 26px;
}

.current-marker { background: var(--current); }
.new-marker     { background: var(--new); }
.place-marker   { background: #555; height: 10px; width: 10px; }

.leaflet-popup-content {
  color: var(--ink);
  font-family: inherit;
  font-size: 0.8125rem;
  line-height: 1.5;
  margin: 10px 14px;
}

.popup-title {
  display: block;
  font-weight: 600;
  margin-bottom: 2px;
}

/* ── Table ───────────────────────────────────────── */

.table-section {
  padding: 48px 0;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  min-width: 900px;
  width: 100%;
}

thead tr {
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  padding: 0 0 14px;
  text-align: left;
  text-transform: uppercase;
}

td {
  border-bottom: 1px solid var(--border);
  padding: 20px 0;
  vertical-align: top;
}

tbody tr:last-child td {
  border-bottom: none;
}

/* column spacing */
td:not(:last-child),
th:not(:last-child) {
  padding-right: 40px;
}

.place-name {
  display: block;
  font-size: 0.9375rem;
  font-weight: 500;
  margin-bottom: 3px;
}

.place-address,
.status {
  color: var(--muted);
  display: block;
  font-size: 0.8125rem;
}

.metric strong,
.change strong {
  display: block;
  font-size: 0.9375rem;
  font-weight: 500;
  margin-bottom: 3px;
}

.metric span,
.change span {
  color: var(--muted);
  font-size: 0.8125rem;
}

.change.better strong { color: var(--good); }
.change.worse  strong { color: var(--bad); }

.status.warning { color: var(--bad); }

.frequency-cell {
  min-width: 126px;
}

.frequency-control {
  align-items: center;
  display: inline-flex;
  gap: 6px;
}

.frequency-btn {
  align-items: center;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--ink);
  display: inline-flex;
  font-size: 0.875rem;
  height: 28px;
  justify-content: center;
  letter-spacing: 0;
  padding: 0;
  width: 28px;
}

.frequency-btn:hover {
  opacity: 1;
  border-color: var(--ink);
}

.days-input {
  background: var(--faint);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--ink);
  font: inherit;
  font-size: 0.8125rem;
  height: 28px;
  text-align: center;
  width: 46px;
}

/* links */
.links {
  white-space: nowrap;
  padding-top: 2px;
}

.links a {
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 500;
  margin-right: 6px;
  padding: 5px 10px;
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}

.links a:hover {
  border-color: var(--ink);
  color: var(--ink);
}

/* ── Footer note ─────────────────────────────────── */

.notes {
  padding: 40px 0 80px;
}

.notes p {
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.7;
  max-width: 640px;
}

/* ── Responsive ──────────────────────────────────── */

@media (max-width: 720px) {
  .page {
    padding: 0 20px;
  }

  header {
    padding: 48px 0 40px;
  }

  .header-inner {
    align-items: flex-start;
    flex-direction: column;
  }

  button {
    align-self: flex-start;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .summary-card {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 32px 0;
  }

  .summary-card:last-child {
    padding-left: 0;
  }

  .summary-card:not(:first-child):not(:last-child) {
    padding-left: 0;
  }

  .controls {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .api-section {
    grid-template-columns: 1fr;
  }

  .api-form {
    flex-direction: column;
  }

  .map-meta {
    flex-direction: column;
    align-items: flex-start;
  }

  .legend {
    justify-content: flex-start;
  }

  #map {
    min-height: 300px;
  }
}
