/* TerritoryAid: mobile-first, high-contrast field navigation.
   Teal is interactive, amber is the current selection, and status colours are reserved for meaning. */

@font-face {
  font-family: "Barlow Semi Condensed";
  src: url("vendor/fonts/barlow-semi-condensed/5.0.8/barlow-semi-condensed-latin-600-normal.woff2") format("woff2");
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Barlow Semi Condensed";
  src: url("vendor/fonts/barlow-semi-condensed/5.0.8/barlow-semi-condensed-latin-700-normal.woff2") format("woff2");
  font-weight: 700 900; font-style: normal; font-display: swap;
}

:root {
  --canvas: #f5f6f7;
  --paper: #ffffff;
  --surface: #eef1f2;
  --surface-hover: #e2e7e8;
  --line: #d2dadd;
  --line-strong: #74878c;
  --ink: #17272b;
  --ink-soft: #566a6f;
  --ink-faint: #75878b;
  --band: #ffffff;
  --band-ink: #17272b;

  --accent: #f59e0b;
  --accent-strong: #b45309;
  --accent-ink: #2b1700;
  --action: #376f78;
  --action-ink: #ffffff;
  --link: #2f6872;
  --action-soft: #e5eff1;

  /* Status: separate from the accent */
  --inside: #15803d;
  --inside-bg: #dcfce7;
  --inside-fg: #166534;
  --outside: #c2410c;
  --outside-bg: #ffedd5;
  --outside-fg: #9a3412;
  --neutral-bg: #e6eeed;
  --neutral-fg: #37504d;
  --note-bg: #fff7e6;
  --error-bg: #fef2f2;
  --error-ink: #991b1b;
  --error-line: #fecaca;

  /* On the map */
  --pin: #facc15;
  --gps: #377d86;
  --label-bg: rgba(255, 255, 255, 0.9);
  --label-ink: #131722;
  --map-bg: #dfe7e5;
  --scrim: rgba(255, 255, 255, 0.9);
  --shadow: 0 4px 14px rgba(7, 21, 19, 0.16);
  --shadow-lg: 0 16px 40px rgba(7, 21, 19, 0.22);

  /* Type */
  --font-display: "Barlow Semi Condensed", "Arial Narrow", system-ui, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs-xs: 12px;
  --fs-sm: 14px;
  --fs-md: 16px;
  --fs-lg: 18px;
  --fs-xl: 26px;

  --radius: 12px;
  --radius-sm: 8px;
  --tap: 48px;
  color-scheme: light;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-md);
  -webkit-text-size-adjust: 100%;
}
body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

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

/* ---------- Top bar and search ---------- */
.topbar {
  position: relative; flex: none; z-index: 1001;
  display: flex; align-items: center; gap: 12px;
  background: var(--band);
  border-bottom: 1px solid var(--line);
  padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  padding-top: calc(8px + env(safe-area-inset-top));
}
.brand { display: none; align-items: center; gap: 9px; color: var(--band-ink); text-decoration: none; font-weight: 800; letter-spacing: -0.02em; }
.brand-mark { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-family: var(--font-display); font-size: 21px; }
.search-sheet-head { display: none; }
.search-close {
  display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0;
  border: 0; border-radius: 50%; background: var(--surface); color: var(--ink);
}
.search-kicker { display: block; margin-bottom: 2px; color: var(--ink-soft); font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }
.search-backdrop { position: fixed; inset: 0; z-index: 1400; border: 0; background: rgba(17, 28, 32, .28); backdrop-filter: blur(2px); }
.search-backdrop[hidden] { display: none; }
.search { position: relative; display: flex; flex: 1; gap: 8px; max-width: 640px; margin: 0 auto; }
.search-field { position: relative; flex: 1; min-width: 0; display: flex; }
.search input {
  flex: 1; min-width: 0; height: var(--tap); padding: 0 14px;
  border: none; border-radius: var(--radius-sm);
  background: var(--paper); color: var(--ink);
  font-family: var(--font-display); font-size: 20px; font-weight: 700; letter-spacing: 0.02em;  /* >= 16px: no iOS zoom */
}
.search input::placeholder { color: var(--ink-faint); font-family: var(--font-body); font-size: var(--fs-lg); font-weight: 400; letter-spacing: 0; }
.search input:focus { outline: 3px solid var(--action); outline-offset: 1px; }

/* Code suggestions under the search box */
.suggest {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 1100;
  margin: 0; padding: 4px 0; list-style: none;
  background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  max-height: 60vh; overflow-y: auto;
}
.suggest[hidden] { display: none; }
.suggest-item { display: flex; align-items: center; gap: 10px; min-height: var(--tap); padding: 0 14px; cursor: pointer; }
.suggest-item + .suggest-item { border-top: 1px solid var(--line); }
.suggest-item:hover, .suggest-item[aria-selected="true"] { background: var(--action-soft); }
.suggest-code { font-family: var(--font-display); font-weight: 700; font-size: 19px; color: var(--ink); white-space: nowrap; }
.suggest-label { color: var(--ink-soft); font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 899px) {
  .topbar { display: none; }
  .search-open .topbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1500;
    display: block;
    padding: 18px max(18px, env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    border-radius: 26px 26px 0 0;
    background: var(--paper);
    box-shadow: 0 -18px 50px rgba(23, 33, 38, .18);
  }
  .search-open .brand { display: none; }
  .search-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
  .search-sheet-head strong { display: block; font-size: 18px; font-weight: 600; }
  .search { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; max-width: none; }
  .search input { height: 52px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); font-family: var(--font-body); font-size: 17px; font-weight: 500; letter-spacing: 0; }
  .search-submit { align-self: start; min-height: 52px; border-radius: 13px; box-shadow: none; }
  .suggest { position: static; grid-column: 1 / -1; margin-top: 4px; padding: 4px 0; border-radius: 12px; background: var(--surface); box-shadow: none; max-height: 34vh; }
  .suggest-code { font-family: var(--font-body); font-size: 16px; font-weight: 600; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); min-width: var(--tap); padding: 0 16px;
  border: 1.5px solid var(--line-strong); border-radius: 10px;
  background: var(--paper); color: var(--ink);
  font: inherit; font-size: 17px; font-weight: 700; text-decoration: none;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--action); outline-offset: 2px; }
.btn-primary { background: var(--action); border-color: var(--action); color: var(--action-ink); box-shadow: 0 5px 14px rgba(55, 111, 120, 0.2); }
.btn-primary:hover { background: #2d5e66; border-color: #2d5e66; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.4; pointer-events: none; }
.btn-wide { flex: 1; }
.btn .ic { flex: none; }
.btn-main { display: inline-flex; align-items: center; gap: 6px; }
.btn-sub { font-size: 13px; font-weight: 600; opacity: 0.9; font-variant-numeric: tabular-nums; }

/* ---------- Banner (errors / suggestions) ---------- */
.banner {
  flex: none; z-index: 1000;
  padding: 10px 14px;
  background: var(--error-bg); color: var(--error-ink);
  border-bottom: 2px solid var(--error-line);
  font-weight: 600;
}
.banner .suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.banner .btn { min-height: 44px; font-size: var(--fs-md); border-color: var(--error-ink); color: var(--error-ink); background: transparent; }

/* ---------- Map ---------- */
#map { flex: 1; min-height: 0; background: var(--map-bg); }

/* Keep the street map light and quiet regardless of the device appearance. */
.basemap-street .leaflet-tile-pane { filter: saturate(0.3) brightness(1.04) contrast(0.92); }

/* Leaflet's own controls and popups follow the theme */
.leaflet-container { font-family: var(--font-body); }
.leaflet-bar { border: none !important; box-shadow: var(--shadow) !important; }
.leaflet-touch .leaflet-bar a, .leaflet-bar a {
  width: 44px; height: 44px; line-height: 44px; font-size: 24px;
  background: var(--paper); color: var(--ink); border-bottom-color: var(--line);
}
.leaflet-bar a:hover { background: var(--surface); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--paper); color: var(--ink); box-shadow: var(--shadow-lg); }
.leaflet-popup-content-wrapper { border-radius: var(--radius); }
.leaflet-container a.leaflet-popup-close-button { width: 32px; height: 32px; font-size: 24px; line-height: 32px; color: var(--ink-soft); }
.leaflet-control-attribution { background: var(--label-bg) !important; color: var(--ink-soft); }
.leaflet-control-attribution a { color: var(--link); }
.leaflet-control-scale-line {
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
  border-width: 3px; border-color: var(--ink); background: var(--label-bg); color: var(--ink);
}
/* Phones: pinch to zoom; the + / - buttons and scale only take map space. */
@media (pointer: coarse), (max-width: 899px) {
  .leaflet-control-zoom,
  .leaflet-control-scale { display: none; }
}
/* Keep the open Map menu above the shared toolbar. */
.leaflet-top.leaflet-right { z-index: 1001; }

/* Round icon buttons on the map (labels show until the first tip is dismissed) */
.map-buttons { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.map-btn.btn { min-height: 44px; font-size: 15px; box-shadow: var(--shadow); }
.map-btn.icon-btn {
  min-width: 46px; min-height: 46px; padding: 0 12px; gap: 6px;
  border-radius: 23px; border: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 94%, transparent); color: var(--ink);
  backdrop-filter: blur(10px);
}
.map-btn.icon-btn .btn-label { display: none; }
.map-labels .map-btn.icon-btn .btn-label { display: inline; }
.map-btn.icon-btn[disabled], .map-btn.btn[disabled] { opacity: 0.5; }
.focus-btn.btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.search-btn.btn { display: inline-flex; padding: 0 12px; }
.search-btn.btn.icon-btn { padding: 0; }

/* Map menu (top right): map style, what to show, colour key */
.map-menu { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.map-menu-row { display: flex; gap: 8px; }
.map-panel {
  width: 320px; max-height: 76vh; overflow-y: auto; padding: 16px;
  background: var(--paper); color: var(--ink); border-radius: 20px; box-shadow: var(--shadow-lg);
}
.map-panel[hidden] { display: none; }
.map-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.map-panel-head strong { display: block; margin-top: 2px; font-weight: 600; }
.map-panel-kicker { display: block; color: var(--ink-soft); font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }
.map-panel-close { display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: var(--surface); color: var(--ink); font-size: 24px; }
.map-style-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.map-style-btn { display: grid; grid-template-columns: 54px 1fr; align-items: center; gap: 9px; min-height: 58px; padding: 7px; border: 1px solid var(--line); border-radius: 13px; background: var(--paper); color: var(--ink); font: inherit; text-align: left; }
.map-style-btn[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.map-style-btn strong { font-size: 14px; font-weight: 600; }
.map-style-thumb { display: block; width: 54px; height: 42px; border-radius: 9px; }
.map-style-thumb.is-street { background: linear-gradient(28deg, #d9dedb 42%, #fff 43% 53%, #d9dedb 54%); }
.map-style-thumb.is-satellite { background: linear-gradient(145deg, #6f805f 0 45%, #9b8b62 46% 62%, #566d58 63%); }
.view-switches { display: grid; margin-top: 12px; }
.view-switch { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 64px; border-top: 1px solid var(--line); }
.view-switch-copy { min-width: 0; }
.view-switch-copy strong,.view-switch-copy small { display: block; }
.view-switch-copy strong { font-size: 15px; font-weight: 600; }
.view-switch-copy small { margin-top: 2px; color: var(--ink-soft); font-size: 12px; line-height: 1.25; }
.view-switch input { appearance: none; flex: 0 0 auto; width: 42px; height: 24px; margin: 0; padding: 3px; border: 0; border-radius: 999px; background: var(--line-strong); }
.view-switch input::before { content: ""; display: block; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.22); transition: transform .16s ease; }
.view-switch input:checked { background: var(--action); }
.view-switch input:checked::before { transform: translateX(18px); }
.view-switch input:focus-visible { outline: 3px solid var(--action); outline-offset: 2px; }

@media (max-width: 899px) {
  .leaflet-top.leaflet-right {
    top: 10px;
    right: 10px;
    display: flex;
    flex-direction: row-reverse;
    align-items: flex-start;
    gap: 6px;
  }
  .leaflet-top.leaflet-right > .leaflet-control {
    float: none;
    clear: none;
    margin: 0;
  }
  .map-buttons { flex-direction: row; align-items: center; gap: 6px; }
  .map-menu-row { gap: 6px; }
  .map-btn.icon-btn {
    min-width: 42px;
    width: 42px;
    min-height: 42px;
    height: 42px;
    padding: 0;
  }
  .map-labels .map-btn.icon-btn .btn-label { display: none; }
  .map-menu { position: relative; }
  .map-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: auto;
    border-radius: 26px 26px 0 0;
    padding: 18px max(18px, env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  }
}

.map-panel-title, .card-section h3 {
  margin: 6px 4px 4px; font-size: var(--fs-xs); font-weight: 800; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-soft);
}
.seg { display: flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--surface); }
.seg-btn {
  flex: 1; min-height: 40px; border: none; border-radius: 8px; background: transparent;
  font: inherit; font-size: 15px; font-weight: 700; color: var(--ink-soft); cursor: pointer;
}
.seg-btn[aria-pressed="true"] { background: var(--paper); color: var(--ink); box-shadow: var(--shadow); }
.seg-btn:focus-visible { outline: 3px solid var(--action); outline-offset: 1px; }
.layers-row {
  display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 10px 0 6px;
  font-size: var(--fs-md); font-weight: 600; cursor: pointer; white-space: nowrap;
}
.layers-row input { width: 22px; height: 22px; accent-color: var(--action); }
.key-toggle {
  display: block; width: 100%; margin-top: 8px; min-height: 40px; padding: 0 4px;
  border: none; background: none; text-align: left;
  font: inherit; font-size: 15px; font-weight: 700; color: var(--link); text-decoration: underline; cursor: pointer;
}
.map-key[hidden] { display: none; }
.key-row { display: flex; align-items: center; gap: 10px; min-height: 30px; padding: 0 4px; font-size: var(--fs-sm); }
.key-icon { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 20px; font-family: var(--font-display); font-size: 13px; font-weight: 700; }
.key-icon.swatch { border-radius: 4px; border: 2px solid var(--ink-soft); background: var(--surface); }
.key-icon.swatch.sel { border: 3px solid var(--accent); background: rgba(230, 0, 126, 0.18); }
.key-icon.swatch.sec { border: 2px dashed var(--accent); background: none; }
.key-icon.pin { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #131722; background: var(--pin); color: #131722; }
.key-icon.pin.start { background: #047857; color: #fff; border-color: #fff; outline: 2px solid #047857; }
.key-icon.pin.end { background: #131722; color: #fff; border-color: #fff; outline: 2px solid #131722; }
.key-icon.dot::before { content: ""; width: 14px; height: 14px; border-radius: 50%; background: var(--gps); border: 3px solid #fff; box-shadow: 0 0 0 1px var(--gps); }
.key-icon.line::before { content: ""; width: 26px; border-top: 3px dashed var(--gps); }

/* ---------- Labels on the map ---------- */
.territory-label, .group-label { background: none; border: none; }
.territory-label span {
  display: inline-block; position: relative;   /* app.js nudges labels clear of others with left/top */
  transform: translate(-50%, -50%);
  padding: 1px 6px; border-radius: 6px;
  background: var(--label-bg); color: var(--label-ink);
  font-family: var(--font-display); font-size: 14px; font-weight: 700; letter-spacing: 0.01em;
  white-space: nowrap; pointer-events: none;
}
.territory-label.selected span {
  padding: 2px 8px; background: var(--accent); color: var(--accent-ink);
  font-size: 17px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
/* Street labels sit just above the line so they don't hide it */
.territory-label.street span { transform: translate(-50%, calc(-100% - 8px)); }
/* Section labels: smaller; numbers when they're the selected territory's sections */
.territory-label.section span { font-size: 13px; padding: 0 5px; border: 1px solid var(--line-strong); }
.territory-label.sibling span {
  min-width: 22px; text-align: center; font-size: 15px;
  border: 2px solid var(--accent); color: var(--accent-strong); background: #fff;
}
.territory-label.parent span { background: #fff; color: var(--accent-strong); border: 2px solid var(--accent); font-size: 15px; }
.territory-label.section.selected span { border: none; font-size: 17px; color: var(--accent-ink); }
.territory-label.at-top span { transform: translate(-50%, 4px); }
/* A selected section's name sits just above its top edge, so it doesn't cover the section */
.territory-label.above span { transform: translate(-50%, calc(-100% - 6px)); }
/* With a section selected, the other sections' numbers step back to grey */
.territory-label.sibling.quiet span { border-color: #6b7385; color: #3c4352; font-size: 14px; }
/* Labels that don't fit or would overlap another (app.js layoutLabels). Hidden, not removed, so they can still be measured. */
.territory-label.label-off { visibility: hidden; }

/* Group names: shown when zoomed out, in the group's colour; tap to select the group */
.group-label span {
  display: inline-block; position: relative; transform: translate(-50%, -50%);
  padding: 3px 11px; border-radius: 999px;
  color: #fff; font-family: var(--font-display); font-size: 16px; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); pointer-events: auto; cursor: pointer;
}
.group-label.label-off { display: none; }

/* GPS dot, guide arrow, compass cone */
.leaflet-interactive.gps-dot { filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.5)); }
.guide-arrow { background: none; border: none; pointer-events: none; }
.guide-arrow span { position: absolute; inset: 0; display: block; }
.guide-arrow span::before {
  content: ""; position: absolute; left: 50%; top: 2px; transform: translateX(-50%);
  border-left: 9px solid transparent; border-right: 9px solid transparent; border-bottom: 14px solid var(--gps);
  filter: drop-shadow(0 0 2px #fff) drop-shadow(0 0 1px #fff);
}
.heading-cone { background: none; border: none; pointer-events: none; }
.heading-cone span {
  position: absolute; inset: 0; display: block; border-radius: 50%;
  background: conic-gradient(from -25deg, rgba(37, 99, 235, 0.35) 0deg 50deg, transparent 50deg 360deg);
  -webkit-mask: radial-gradient(circle, #000 0 44px, transparent 45px);
          mask: radial-gradient(circle, #000 0 44px, transparent 45px);
}

/* ---------- Lettered points (A, B, C…) ---------- */
/* Pin colours stay the same in both themes: they sit on the map, and match the key. */
.point-pin { background: none; border: none; }
.point-badge {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--pin); color: #131722; border: 3px solid #131722;
  font-family: var(--font-display); font-size: 17px; font-weight: 700; line-height: 1;
}
.point-pin .point-badge { width: 36px; height: 36px; font-size: 20px; box-shadow: 0 1px 5px rgba(0, 0, 0, 0.55); }
.point-badge.is-start { background: #047857; color: #fff; border-color: #fff; outline: 2px solid #047857; }
.point-badge.is-end { background: #131722; color: #fff; border-color: #fff; outline: 2px solid #131722; }
/* Section points seen from their territory: "2A" */
.point-badge.has-prefix { width: auto; min-width: 30px; padding: 0 5px; border-radius: 15px; font-size: 15px; }
.point-pin.from-section .point-badge { width: auto; min-width: 36px; height: 30px; padding: 0 6px; border-radius: 15px; font-size: 16px; }

/* Point popup */
.point-popup-wrap .leaflet-popup-content { margin: 12px 14px; min-width: 200px; }
.point-popup { font-size: 15px; max-width: 240px; }
.point-head { display: flex; align-items: center; gap: 10px; }
.point-title { display: flex; flex-direction: column; min-width: 0; padding-right: 18px; }
.point-role { font-size: 11px; font-weight: 800; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-soft); }
.point-desc { margin-top: 8px; white-space: pre-line; }
.point-actions { display: flex; gap: 8px; margin-top: 10px; }
.point-actions .popup-btn { flex: 1; padding: 0 10px; }
.sv-popup .leaflet-popup-content { margin: 10px 30px 10px 10px; }
.popup-btn.btn { min-height: 44px; font-size: var(--fs-md); white-space: nowrap; }
.leaflet-container a.popup-btn.btn { color: var(--action-ink); }
.leaflet-container a.popup-btn-plain.btn { color: var(--ink); }

/* Aerial snapshot of a point */
.aerial { position: relative; overflow: hidden; flex: none; border-radius: var(--radius-sm); background: var(--line); }
.aerial img { position: absolute; width: 256px; height: 256px; max-width: none; }
.aerial-dot { position: absolute; left: 50%; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; background: var(--pin); border: 2px solid #131722; box-shadow: 0 0 0 2px #fff; }
.point-popup .aerial { margin-top: 8px; width: 100% !important; }

/* First-run tip */
.first-tip {
  position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 1002;
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--band); color: var(--band-ink); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  font-size: 15px; line-height: 1.35;
}
.first-tip span { flex: 1; }
.first-tip .btn { min-height: 40px; background: var(--band-ink); color: var(--band); border-color: var(--band-ink); font-size: 15px; }

/* ---------- Bottom panel / sheet ---------- */
.panel {
  flex: none; z-index: 1000;
  background: var(--paper);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -10px 30px rgba(7, 21, 19, 0.14);
  padding: 0 max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.panel > * { max-width: 640px; margin-left: auto; margin-right: auto; }

/* Header: code and status chip share the first line; the breadcrumb gets the whole second line */
.panel-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 10px; align-items: center; }
.panel-title { display: contents; }
.territory-code {
  grid-column: 1; grid-row: 1;
  font-family: var(--font-display); font-size: var(--fs-xl); font-weight: 700; line-height: 1.1; letter-spacing: 0.01em;
  text-wrap: balance;
}
.territory-zone {
  grid-column: 1 / -1; grid-row: 2; margin-top: 2px;
  font-size: var(--fs-sm); color: var(--ink-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.crumb-sep { color: var(--ink-faint); }
.zone-link {
  background: none; border: none; padding: 4px 2px; margin: -4px 0;
  font: inherit; font-weight: 600; color: var(--link); text-decoration: none; cursor: pointer;
}
.zone-link:hover, .zone-link:focus-visible { text-decoration: underline; }

/* Status chip: short, tinted, with an arrow pointing the way */
.status {
  grid-column: 2; grid-row: 1; justify-self: end;
  display: inline-flex; align-items: center; gap: 5px; padding: 6px 11px;
  border-radius: 999px; white-space: nowrap;
  font-size: var(--fs-sm); font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums;
}
.status-inside  { background: var(--inside-bg); color: var(--inside-fg); }
.status-outside { background: var(--outside-bg); color: var(--outside-fg); }
.status-neutral { background: var(--neutral-bg); color: var(--neutral-fg); }
.status-arrow { flex: none; transition: transform 0.3s ease; }

/* One-line hint under the header, with "more" */
.status-hint { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; margin-top: 6px; font-size: var(--fs-sm); color: var(--ink-soft); white-space: pre-line; }
.hint-text { flex: 1; min-width: 0; white-space: pre-line; }
.hint-more {
  flex: none; border: none; background: none; padding: 0 2px; min-height: 24px;
  font: inherit; font-size: var(--fs-sm); font-weight: 700; color: var(--link); text-decoration: underline; cursor: pointer;
}
.retry-btn.btn {
  align-self: center;
  min-width: 0;
  min-height: 30px;
  padding: 0 9px;
  border-color: var(--action);
  border-radius: 999px;
  color: var(--link);
  font-size: 13px;
  line-height: 1;
}

.panel-actions { display: flex; gap: 8px; margin-top: 10px; }
.panel-actions .btn { min-height: 52px; }
#navigate-btn { flex-direction: column; line-height: 1.1; }

/* Card summary strip: a section's walk (A start → end · time), or a one-line description */
.card-toggle {
  display: flex; align-items: center; gap: 8px; width: 100%;
  min-height: 44px; margin-top: 8px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 15px; font-weight: 600; text-align: left; cursor: pointer;
}
.card-toggle:hover { background: var(--surface-hover); }
.card-toggle[hidden] { display: none; }
.card-toggle:focus-visible { outline: 3px solid var(--action); outline-offset: 2px; }
.card-summary { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-chevron::after { content: "▾"; font-size: 18px; color: var(--ink-soft); }
.card-toggle[aria-expanded="true"] .card-chevron::after { content: "▴"; }
.card-toggle.walk .card-summary { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.walk-dot {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%; background: #047857; color: #fff;
  font-family: var(--font-display); font-size: 14px; font-weight: 700;
}
.walk-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.walk-time { flex: none; color: var(--ink-soft); font-size: var(--fs-sm); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Card ---------- */
.card { overflow-y: auto; padding: 4px 2px 8px; -webkit-overflow-scrolling: touch; transition: max-height 0.18s ease; }
.card-section { margin-top: 12px; }
.card-section h3 { margin: 0 0 6px; }
.card-note { margin: 0; padding: 9px 12px; background: var(--note-bg); border-radius: var(--radius-sm); white-space: pre-line; font-size: var(--fs-md); line-height: 1.4; }
.card-line { margin: 0; font-size: var(--fs-md); line-height: 1.45; font-variant-numeric: tabular-nums; }
.card-sides { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: var(--fs-md); }
.card-sides dt { font-weight: 700; color: var(--ink-soft); }
.card-sides dd { margin: 0; }
.card-list { margin: 0; padding-left: 20px; font-size: var(--fs-md); line-height: 1.45; }
.card-source { margin: 14px 0 2px; font-size: 13px; color: var(--ink-faint); }

/* Points on a card: tap the row to see it on the map; the round button opens Street View */
.card-points { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.card-point { display: flex; gap: 6px; align-items: center; }
.card-point-main {
  display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0;
  min-height: 52px; padding: 6px 10px;
  border: none; border-radius: var(--radius); background: var(--surface);
  font: inherit; font-size: 15px; text-align: left; color: var(--ink); cursor: pointer;
}
.card-point-main:hover { background: var(--surface-hover); }
.card-point-main:focus-visible { outline: 3px solid var(--action); outline-offset: 2px; }
.card-point-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.card-point-sv.btn { flex: none; width: 48px; height: 48px; min-height: 48px; padding: 0; border-radius: 50%; border-color: var(--line); color: var(--link); }

/* A group's territories */
.card-sections { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.card-section-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 48px; padding: 6px 12px;
  border: none; border-radius: var(--radius); background: var(--surface);
  font: inherit; font-size: var(--fs-md); text-align: left; color: var(--ink); cursor: pointer;
}
.card-section-btn:hover { background: var(--surface-hover); }
.card-section-btn:focus-visible { outline: 3px solid var(--action); outline-offset: 2px; }
.card-section-btn strong { font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 700; }
.section-extra { font-size: var(--fs-sm); color: var(--ink-soft); }
.section-num {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  min-width: 30px; height: 30px; padding: 0 4px; border-radius: var(--radius-sm);
  border: 2px solid var(--accent); color: var(--accent); font-family: var(--font-display); font-weight: 700;
}

/* A territory's sections: a compact grid of the numbers agents see on the map */
.section-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.section-chip {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  width: 100%; min-height: 54px; padding: 4px 2px;
  border: none; border-radius: var(--radius); background: var(--surface);
  font: inherit; color: var(--ink); cursor: pointer;
}
.section-chip:hover { background: var(--surface-hover); }
.section-chip:focus-visible { outline: 3px solid var(--action); outline-offset: 2px; }
.section-chip-num { font-family: var(--font-display); font-size: 22px; font-weight: 700; color: var(--accent); line-height: 1.05; }
.section-chip-time { font-size: var(--fs-xs); color: var(--ink-soft); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- Loading overlay ---------- */
.loading {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: var(--scrim); color: var(--ink);
  font-size: var(--fs-lg); font-weight: 700;
}
.loading[hidden] { display: none; }

/* ---------- Larger phones and tablets ---------- */
@media (min-width: 768px) {
  .territory-code { font-size: 30px; }
}

/* ---------- Desktop: the details become a left sidebar ---------- */
@media (min-width: 900px) {
  body { display: grid; grid-template-columns: clamp(360px, 31vw, 440px) minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); }
  .topbar { grid-column: 1; grid-row: 1; flex-direction: column; align-items: stretch; padding: 16px; border-right: 1px solid var(--line); }
  .brand { display: inline-flex; }
  body:not(.search-open) .topbar .search { display: none; }
  .search-open .topbar {
    position: fixed;
    left: 50%;
    top: 50%;
    z-index: 1500;
    display: block;
    width: min(520px, calc(100vw - 40px));
    padding: 20px;
    border: 0;
    border-radius: 22px;
    background: var(--paper);
    box-shadow: var(--shadow-lg);
    transform: translate(-50%, -50%);
  }
  .search-open .brand { display: none; }
  .search-open .search-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
  .search-open .search-sheet-head strong { display: block; font-size: 18px; font-weight: 600; }
  .search-open .search { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; width: 100%; max-width: none; margin: 0; }
  .search-open .search input { height: 52px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); font-family: var(--font-body); font-size: 17px; font-weight: 500; letter-spacing: 0; }
  .search-open .search-submit { align-self: start; min-height: 52px; border-radius: 13px; box-shadow: none; }
  .search-open .suggest { position: static; grid-column: 1 / -1; margin-top: 4px; border-radius: 12px; background: var(--surface); box-shadow: none; }
  .banner { grid-column: 1; grid-row: 2; }
  #map { grid-column: 2; grid-row: 1 / -1; }
  .panel {
    grid-column: 1; grid-row: 3; display: flex; flex-direction: column;
    border-top: none; border-right: 1px solid var(--line); box-shadow: none;
    border-radius: 0; padding: 18px 16px 0; overflow-y: auto;
  }
  .panel > * { max-width: none; margin-left: 0; margin-right: 0; }
  /* Plenty of room: the card is always open, under its summary */
  .panel .card { display: block !important; max-height: none !important; overflow: visible; flex: 1; }
  .card-toggle { pointer-events: none; }
  .card-toggle .card-chevron { display: none; }
  .card-toggle:not(.walk) .card-summary { white-space: normal; }
  .panel-actions { order: 3; position: sticky; bottom: 0; background: var(--paper); margin-top: auto; padding: 12px 0 14px; }
  .panel-row { order: 0; } .status-hint { order: 1; } .card-toggle { order: 2; } .card { order: 2; }
  .first-tip { left: auto; right: 72px; bottom: 18px; max-width: 420px; }
}
