/* TEAM: a full-size map with compact control surfaces.
   Interface colours follow the Better Places Lab; data colours live in js/palette.js. */

:root {
  color-scheme: light;
  --navy: #0c0c48;
  --ink: #15252e;
  --ink-soft: #3b4d56;
  --muted: #55646c;
  --paper: #f7f3ea;
  --surface: #ffffff;
  --wash: #f3f4f1;
  --line: rgba(18, 52, 67, 0.14);
  --line-strong: rgba(18, 52, 67, 0.28);
  --accent: #1f6178;
  --track: #ecebe6;
  --bar: #2a78d6;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(12, 12, 72, 0.12);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #e6e6e3;
  color: var(--ink);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link { position: absolute; top: -60px; left: 12px; z-index: 50; padding: 8px 12px; background: var(--navy); color: #fff; border-radius: 0 0 8px 8px; text-decoration: none; }
.skip-link:focus { top: 0; }

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

/* ------------------------------------------------------------------ panel */

.panel {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 10;
  display: flex;
  flex-direction: column;
  width: 364px;
  max-height: calc(100% - 24px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.brand { display: flex; align-items: center; gap: 8px; padding: 14px 12px 12px 14px; border-bottom: 1px solid var(--line); }
.brand-mark { flex: 0 0 auto; width: 36px; height: 36px; }
.brand-text { flex: 1 1 auto; min-width: 0; }
.brand h1 { margin: 0; color: var(--navy); font-size: 22px; font-weight: 800; letter-spacing: 0.08em; line-height: 1; }
.brand p { margin: 3px 0 0; font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tagline { color: var(--muted); }
.mini { display: none; color: var(--navy); font-weight: 600; }
body[data-panel="collapsed"] .tagline { display: none; }
body[data-panel="collapsed"] .mini { display: block; }
.text-button { padding: 6px 4px; border: 0; background: none; color: var(--accent); font-size: 13px; font-weight: 600; }
.text-button:hover { color: var(--navy); text-decoration: underline; }
.icon-button { display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--muted); }
.icon-button:hover { background: var(--wash); color: var(--navy); }
.panel-toggle svg { transition: transform 160ms ease; }
body[data-panel="collapsed"] .panel-toggle svg { transform: rotate(180deg); }
body[data-panel="collapsed"] .panel-body, body[data-panel="collapsed"] .panel-foot { display: none; }

.panel-body { display: flex; flex-direction: column; gap: 14px; min-height: 0; padding: 12px 14px 8px; overflow-y: auto; overscroll-behavior: contain; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-head { display: flex; align-items: baseline; gap: 8px; }
.field-label { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.01em; }
.field-value { color: var(--navy); font-size: 13px; font-weight: 700; }
.field-head .text-button { margin-left: auto; font-size: 12px; }
input[type="range"] { width: 100%; accent-color: var(--navy); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 32px; padding: 5px 11px; border: 1px solid var(--line-strong); border-radius: 999px; background: #fff; color: var(--ink); font-size: 13px; font-weight: 500; }
.chip:hover { border-color: var(--navy); }
.chip[aria-checked="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
.chips-compact .chip { min-height: 30px; padding: 4px 10px; font-size: 12.5px; }

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); margin: 2px -14px 0; padding: 0 8px; border-bottom: 1px solid var(--line); }
.tabs button { min-height: 42px; padding: 8px 4px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); font-size: 13px; font-weight: 600; }
.tabs button[aria-selected="true"] { border-bottom-color: var(--navy); color: var(--navy); }
.tabs button:hover { color: var(--navy); }

.view { display: flex; flex-direction: column; gap: 14px; }
.hero-figure { color: var(--navy); font-size: 48px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.hero-text { margin: 6px 0 0; font-size: 15px; line-height: 1.4; }
.hero-sub { margin: 6px 0 0; color: var(--ink-soft); font-size: 13px; }
.note { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }

.legend { display: flex; flex-direction: column; gap: 6px; }
.legend-scale { display: grid; gap: 2px; }
.legend-step { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.legend-swatch { display: block; height: 12px; }
.legend-step:first-child .legend-swatch { border-radius: 3px 0 0 3px; }
.legend-step:last-child .legend-swatch { border-radius: 0 3px 3px 0; }
.legend-step.is-divider { border-left: 2px solid var(--navy); padding-left: 2px; margin-left: -2px; }
.legend-label { color: var(--muted); font-size: 11px; line-height: 1.2; }

.check { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; }
.check input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--navy); }

.chart { display: flex; flex-direction: column; gap: 6px; }
.chart-caption { margin: 0; color: var(--muted); font-size: 12px; font-weight: 600; }
.bars { display: flex; flex-direction: column; gap: 5px; }
.bar-row { display: grid; grid-template-columns: 138px 1fr 42px; align-items: center; gap: 8px; font-size: 12.5px; }
.bar-label { overflow: hidden; color: var(--ink-soft); text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; background: var(--track); border-radius: 2px; }
.bar-fill { display: block; height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; opacity: 0.55; }
.bar-row.is-emphasis .bar-fill { opacity: 1; }
.bar-row.is-emphasis .bar-label { color: var(--ink); font-weight: 600; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }

.reason-list { display: flex; flex-direction: column; gap: 4px; }
.reason-row { display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; text-align: left; }
.reason-row:hover { border-color: var(--navy); }
.reason-row.is-focus { border-color: var(--navy); box-shadow: inset 0 0 0 1px var(--navy); }
.reason-swatch { width: 12px; height: 12px; border-radius: 3px; }
.reason-text { display: flex; flex-direction: column; min-width: 0; }
.reason-text strong { font-size: 13px; font-weight: 600; }
.reason-fix { color: var(--muted); font-size: 12px; }
.reason-count { font-variant-numeric: tabular-nums; font-weight: 600; }

.rank-list { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; counter-reset: rank; }
.rank-list li { counter-increment: rank; }
.rank-row { display: grid; grid-template-columns: 20px 1fr auto; grid-template-areas: "n name meta" "n reason reason"; gap: 2px 8px; width: 100%; padding: 7px 6px; border: 0; border-radius: 8px; background: none; text-align: left; }
.rank-row::before { content: counter(rank); grid-area: n; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.rank-row:hover { background: var(--wash); }
.rank-name { grid-area: name; font-weight: 600; }
.rank-meta { grid-area: meta; color: var(--ink-soft); font-size: 12px; font-variant-numeric: tabular-nums; }
.rank-reason { grid-area: reason; display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.reason-dot { width: 8px; height: 8px; border-radius: 50%; }

.panel-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11.5px; }
.panel-foot { flex-wrap: wrap; gap: 2px 10px; }
.lab-link { display: inline-flex; align-items: center; gap: 6px; color: var(--navy); font-weight: 600; text-decoration: none; white-space: nowrap; }
.share-button { flex: 0 0 auto; margin-left: auto; font-size: 12px; }
.foot-note { flex: 1 0 100%; font-size: 11px; }
.lab-link:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ place panel */

.place {
  position: absolute;
  top: calc(max(12px, env(safe-area-inset-top)) + 52px);
  right: max(12px, env(safe-area-inset-right));
  z-index: 11;
  display: flex;
  flex-direction: column;
  width: 340px;
  max-height: calc(100% - 118px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.place-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 14px 14px 10px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 2px; color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.place-head h2 { margin: 0; color: var(--navy); font-size: 18px; line-height: 1.2; }
.place-sub { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.place-body { padding: 4px 14px 14px; overflow-y: auto; overscroll-behavior: contain; }
.place-section { padding: 12px 0; border-bottom: 1px solid var(--line); }
.place-section:last-child { border-bottom: 0; }
.place-section h3 { margin: 0 0 8px; font-size: 13px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; font-size: 12.5px; }
.kv-key { color: var(--ink-soft); }
.kv-value { text-align: right; font-variant-numeric: tabular-nums; }

.service-row { border-radius: 8px; }
.service-row + .service-row { margin-top: 2px; }
.service-row summary { display: grid; grid-template-columns: 58px 1fr auto; align-items: center; gap: 8px; padding: 6px 4px; list-style: none; cursor: pointer; font-size: 12.5px; }
.service-row summary::-webkit-details-marker { display: none; }
.service-row summary:hover { background: var(--wash); border-radius: 8px; }
.badge { padding: 2px 6px; border-radius: 999px; font-size: 11px; font-weight: 700; text-align: center; }
.is-met .badge { background: #dbe8f8; color: #184f95; }
.is-missed .badge { background: #fbe3d6; color: #833607; }
.service-name { font-weight: 600; }
.service-time { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.service-reason, .service-nearest, .service-standard { margin: 4px 4px 0 70px; color: var(--ink-soft); font-size: 12px; }
.mode-grid { display: grid; grid-template-columns: 1fr auto; gap: 1px 12px; margin: 6px 4px 6px 70px; font-size: 12px; }
.mode-name { color: var(--muted); }
.mode-time { text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ map tools */

.map-tools { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); z-index: 12; display: flex; align-items: flex-start; gap: 8px; }
.search { position: relative; }
.search input { width: 220px; height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; box-shadow: 0 2px 12px rgba(12, 12, 72, 0.08); }
.search-results { position: absolute; top: 42px; left: 0; right: 0; margin: 0; padding: 4px; list-style: none; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.search-results li { display: flex; flex-direction: column; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.search-results li.is-active, .search-results li:hover { background: var(--wash); }
.search-board { color: var(--muted); font-size: 11.5px; }
.segmented { display: inline-flex; padding: 3px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 2px 12px rgba(12, 12, 72, 0.08); }
.segmented button { min-height: 30px; padding: 4px 10px; border: 0; border-radius: 7px; background: none; color: var(--ink-soft); font-size: 12.5px; font-weight: 600; }
.segmented button[aria-pressed="true"] { background: var(--navy); color: #fff; }
.layers { position: relative; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 2px 12px rgba(12, 12, 72, 0.08); }
.layers summary { min-height: 36px; padding: 8px 12px; color: var(--ink-soft); font-size: 12.5px; font-weight: 600; list-style: none; cursor: pointer; }
.layers summary::-webkit-details-marker { display: none; }
.layer-list { display: flex; flex-direction: column; gap: 6px; padding: 0 12px 10px; white-space: nowrap; }

.tooltip { position: absolute; top: 0; left: 0; z-index: 30; display: flex; flex-direction: column; gap: 1px; max-width: 260px; padding: 8px 10px; background: rgba(12, 12, 72, 0.94); color: #fff; border-radius: 8px; font-size: 12px; pointer-events: none; }
.tooltip strong { font-size: 12.5px; }
.loading { position: absolute; left: 50%; bottom: 40px; z-index: 40; padding: 10px 14px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); transform: translateX(-50%); font-size: 13px; }

.maplibregl-ctrl-bottom-right { bottom: env(safe-area-inset-bottom); }
.maplibregl-ctrl-group button { width: 36px; height: 36px; }

/* ------------------------------------------------------------------ about */

.about { width: min(640px, 94vw); max-height: 88dvh; padding: 26px 28px; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); color: var(--ink); overflow-y: auto; }
.about::backdrop { background: rgba(12, 12, 72, 0.45); }
.about h2 { margin: 0 0 10px; color: var(--navy); font-size: 22px; }
.about h3 { margin: 20px 0 6px; font-size: 14px; }
.about p, .about li { font-size: 14px; line-height: 1.55; }
.about ul { padding-left: 18px; }
.about-close-form { position: sticky; top: 0; float: right; margin: -8px -10px 0 0; }
.about-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.about-table th, .about-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.about-table th { color: var(--muted); font-weight: 600; }
.about-links a { color: var(--accent); font-weight: 600; }

/* ------------------------------------------------------------------ small screens */

@media (max-width: 1100px) {
  .search input { width: 170px; }
}

@media (max-width: 760px) {
  .panel {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    width: auto;
    max-height: 62dvh;
    border-radius: 16px;
  }
  body[data-place="open"] .panel { display: none; }
  /* A bottom sheet opens upwards, so the arrow points up while it is folded. */
  .panel-toggle svg { transform: rotate(180deg); }
  body[data-panel="collapsed"] .panel-toggle svg { transform: none; }
  .brand { padding: 10px 10px 8px 12px; }
  .brand h1 { font-size: 19px; }
  .hero-figure { font-size: 40px; }
  .place { top: auto; left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); width: auto; max-height: 62dvh; }
  .map-tools { left: 8px; right: 8px; flex-wrap: wrap; }
  .search { flex: 1 1 140px; }
  .search input { width: 100%; }
  .basemaps { order: 3; }
  input[type="search"] { font-size: 16px; }
  .maplibregl-ctrl-bottom-right { bottom: calc(62dvh + 20px); }
  body[data-panel="collapsed"] .maplibregl-ctrl-bottom-right { bottom: 90px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
