/* Bank map. System fonts only; every colour is a token so dark mode is one block. */
:root {
  --ink: #1d1b18; --mute: #6a6358; --line: #e4dfd3; --surface: #fffdf8; --canvas: #f6f3ec;
  --accent: #a3550a; --accent-soft: color-mix(in srgb, #a3550a 13%, var(--surface));
  --hover: color-mix(in srgb, var(--ink) 5%, var(--surface));
  --raised: #ffffff; --shadow: 0 6px 22px rgb(40 30 15 / .16), 0 1px 3px rgb(40 30 15 / .12);
  --panel-w: 360px; --ease: cubic-bezier(.22, .9, .28, 1);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Thai", "Leelawadee UI", sans-serif;
  color-scheme: light dark;
  font: 15px/1.45 var(--sans);
  color: var(--ink);
  accent-color: var(--accent);
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f4efe6; --mute: #a39b8c; --line: #302c26; --surface: #1a1816; --canvas: #100f0d;
    --accent: #f2b34d; --accent-soft: color-mix(in srgb, #f2b34d 15%, var(--surface));
    --hover: color-mix(in srgb, var(--ink) 6%, var(--surface));
    --raised: #24211e; --shadow: 0 8px 26px rgb(0 0 0 / .45), 0 1px 3px rgb(0 0 0 / .4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--canvas); }
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.ico { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ico circle { fill: currentColor; stroke: none; }

/* ---------- layout: side panel + map (desktop) ---------- */
body {
  display: grid; grid-template-columns: var(--panel-w) minmax(0, 1fr);
  height: 100dvh; overflow: hidden;
  transition: grid-template-columns 280ms var(--ease);
}
[data-panel="closed"] body { grid-template-columns: 0px minmax(0, 1fr); }
[data-anim="off"] body, [data-anim="off"] aside { transition: none !important; }

aside {
  position: relative; z-index: 2; min-width: 0; overflow: hidden;
  background: var(--surface); border-right: 1px solid var(--line);
  transition: visibility 0s;
}
[data-panel="closed"] aside { visibility: hidden; transition: visibility 0s linear 280ms; }
.panel-inner { width: var(--panel-w); height: 100%; display: flex; flex-direction: column; }

.panel-head {
  flex: none; display: flex; align-items: flex-start; gap: 12px;
  padding: 18px 12px 14px 20px; border-bottom: 1px solid var(--line);
}
.titles { flex: 1; min-width: 0; }
h1 { font-size: 19px; line-height: 1.25; letter-spacing: -0.01em; margin: 2px 0 3px; text-wrap: balance; }
.summary { margin: 0; color: var(--mute); font-size: 13px; }
.titles .summary + .summary { margin-top: 1px; }

.icon-btn {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px 0 9px; margin-top: 0;
  border: 1px solid var(--line); border-radius: 10px; background: transparent; color: var(--mute); cursor: pointer;
  font-size: 13px; font-weight: 600;
}
.icon-btn:hover { background: var(--hover); color: var(--ink); border-color: color-mix(in srgb, var(--ink) 18%, var(--surface)); }
.icon-btn:active { background: color-mix(in srgb, var(--ink) 10%, var(--surface)); }
.ico-down { display: none; }

.panel-body {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--ink) 22%, transparent) transparent;
  padding: 6px 0 20px;
}

/* ---------- map key ---------- */
.key { margin: 8px 12px 4px; border: 1px solid var(--line); border-radius: 12px; }
.key summary {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 40px; padding: 9px 10px 9px 12px; cursor: pointer; list-style: none;
  font-size: 13px; font-weight: 600; color: var(--mute); border-radius: 11px;
}
.key summary::-webkit-details-marker { display: none; }
.key summary:hover { color: var(--ink); background: var(--hover); }
.key .chev { width: 16px; height: 16px; transition: transform 200ms var(--ease); }
.key[open] .chev { transform: rotate(90deg); }
.key-body { padding: 2px 12px 12px; }
fieldset { border: 0; margin: 0 0 10px; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; }
legend { padding: 0; margin-bottom: 4px; font-size: 12px; color: var(--mute); }
fieldset label { display: inline-flex; align-items: center; gap: 8px; min-height: 32px; cursor: pointer; font-size: 14px; }
fieldset input { width: 16px; height: 16px; margin: 0; }
.swatch-home { width: 14px; height: 14px; flex: none; border-radius: 50%; border: 3px solid #d62828; background: radial-gradient(circle closest-side, #d62828 0 45%, #ffffff 55%); }
.pop-head .swatch-home { width: 24px; height: 24px; border-width: 5px; margin-top: 1px; }
.swatch-banks { width: 22px; height: 12px; border-radius: 6px; background: linear-gradient(90deg, #1e4598 0 25%, #138f2d 0 50%, #d8a300 0 75%, #eb198d 0); }
.legend { list-style: none; margin: 0; padding: 10px 0 0; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 6px 16px; }
.legend li { display: flex; align-items: center; gap: 7px; min-width: 0; font-size: 13px; line-height: 1.3; }
.legend .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .15); }
.legend .name { min-width: 0; }
.legend .count { color: var(--mute); font-variant-numeric: tabular-nums; }

/* ---------- branch list ---------- */
.group { margin-top: 6px; }
.group h2 {
  position: sticky; top: -6px; z-index: 1; margin: 0; padding: 12px 20px 6px;
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  font-size: 13px; font-weight: 650; background: var(--surface);
}
.group h2 .range { font-weight: 400; color: var(--mute); font-size: 12px; font-variant-numeric: tabular-nums; }
.list ol { list-style: none; margin: 0; padding: 0 8px; }
.row {
  width: 100%; display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 2px 12px; align-items: start;
  padding: 9px 12px; border: 0; border-radius: 10px; background: transparent; text-align: left; cursor: pointer;
}
.row:hover, .row.hover { background: var(--hover); }
.row[aria-current="true"] { background: var(--accent-soft); }
.row:focus-visible { outline-offset: -2px; }
.badge {
  display: grid; place-items: center; width: 26px; height: 26px; margin-top: -1px; border-radius: 50%;
  font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
  box-shadow: 0 0 0 2px var(--surface), 0 1px 2px 2px rgb(0 0 0 / .08);
}
.row[aria-current="true"] .badge { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); }
.row .main { min-width: 0; }
.bank { display: block; font-weight: 600; line-height: 1.3; }
.bank .paren, .pop-bank .paren { font-weight: 400; color: var(--mute); }
.branch { display: block; margin-top: 2px; color: var(--mute); font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; }
.km { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1.3; }
.km small { font-size: 12px; font-weight: 400; color: var(--mute); }
.tag {
  display: inline-block; margin-top: 5px; padding: 1px 7px; border-radius: 999px;
  font-size: 12px; line-height: 1.5; color: var(--mute); background: color-mix(in srgb, var(--ink) 6%, transparent);
}
.empty { margin: 24px 20px; color: var(--mute); font-size: 14px; }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; }

/* ---------- map stage ---------- */
.stage { position: relative; min-width: 0; height: 100dvh; background: #dbd8d2; }
#map { position: absolute; inset: 0; }
.map-btn {
  position: absolute; top: 10px; left: 10px; z-index: 3;
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px 0 12px;
  border: 0; border-radius: 12px; background: var(--raised); color: var(--ink); box-shadow: var(--shadow);
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.map-btn[hidden] { display: none; }
.map-btn:hover { background: color-mix(in srgb, var(--accent) 8%, var(--raised)); }
.map-btn-count {
  min-width: 22px; padding: 0 6px; border-radius: 999px; font-size: 12px; line-height: 20px; text-align: center;
  background: color-mix(in srgb, var(--ink) 9%, transparent); font-variant-numeric: tabular-nums;
}
.map-btn-count:empty { display: none; }
.map-msg {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 2; margin: 0;
  max-width: min(360px, calc(100% - 32px)); padding: 12px 16px; border-radius: 12px;
  background: var(--raised); color: var(--ink); box-shadow: var(--shadow); font-size: 14px; text-align: center;
}
[data-map="ready"] .map-msg { display: none; }

/* MapLibre's own surfaces, themed from the palette */
.maplibregl-map { font-family: var(--sans); }
.maplibregl-ctrl-group { border-radius: 10px; box-shadow: var(--shadow) !important; }
.maplibregl-ctrl-group button { width: 36px; height: 36px; }
.maplibregl-ctrl button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.maplibregl-ctrl-scale { border-color: #5b5449; color: #3c3730; background: rgb(255 255 255 / .8); }

.maplibregl-popup { max-width: min(300px, calc(100vw - 32px)) !important; }
.maplibregl-popup-content {
  padding: 14px 16px 14px; border-radius: 14px; background: var(--raised); color: var(--ink);
  box-shadow: var(--shadow); font: 14px/1.4 var(--sans);
}
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip,
.maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip,
.maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip { border-top-color: var(--raised); }
.maplibregl-popup-anchor-top .maplibregl-popup-tip,
.maplibregl-popup-anchor-top-left .maplibregl-popup-tip,
.maplibregl-popup-anchor-top-right .maplibregl-popup-tip { border-bottom-color: var(--raised); }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--raised); }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--raised); }
.maplibregl-popup-close-button {
  top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 8px;
  font-size: 22px; line-height: 1; color: var(--mute);
}
.maplibregl-popup-close-button:hover { background: var(--hover); color: var(--ink); }
.pop:focus { outline: none; }
.pop-head { display: flex; gap: 10px; align-items: flex-start; padding-right: 26px; }
.pop-head .badge { flex: none; margin-top: 0; box-shadow: none; }
.pop-bank { font-weight: 650; font-size: 15px; line-height: 1.3; }
.pop-branch { margin: 2px 0 0; color: var(--mute); font-size: 13px; overflow-wrap: anywhere; }
.pop-facts { margin: 10px 0 0; padding: 10px 0 0; border-top: 1px solid var(--line); display: grid; gap: 4px; font-size: 13px; }
.pop-facts .km { font-size: 14px; }
.pop-facts a { color: inherit; }
.pop .tag { margin-top: 8px; }
.pop details { margin-top: 8px; font-size: 13px; }
.pop summary { cursor: pointer; color: var(--mute); width: fit-content; border-radius: 4px; }
.pop summary:hover { color: var(--ink); }
.hours { margin: 6px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 1px 12px; font-variant-numeric: tabular-nums; }
.hours dt { color: var(--mute); }
.hours dd { margin: 0; }
.pop-link {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 12px; min-height: 32px;
  color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px;
}
.pop-link .ico { width: 15px; height: 15px; }

/* ---------- phone: the panel becomes a bottom sheet over the map ---------- */
@media (max-width: 720px) {
  body { display: block; }
  .stage { position: fixed; inset: 0; height: auto; }
  aside {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
    height: min(62dvh, 560px); border-right: 0; border-radius: 18px 18px 0 0;
    box-shadow: 0 -10px 30px rgb(0 0 0 / .2); transform: translateY(0);
    transition: transform 300ms var(--ease), visibility 0s;
  }
  [data-panel="closed"] aside {
    transform: translateY(calc(100% + 24px));
    transition: transform 240ms cubic-bezier(.4, 0, .9, .5), visibility 0s linear 240ms;
  }
  .panel-inner { width: auto; }
  .panel-head { padding: 14px 8px 12px 18px; }
  .icon-btn { width: 44px; height: 44px; padding: 0; justify-content: center; margin-top: -6px; border: 0; border-radius: 50%; background: var(--hover); color: var(--ink); }
  .btn-label, .hint { display: none; }
  .ico-side { display: none; }
  .ico-down { display: block; width: 24px; height: 24px; }
  .panel-body { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .row { padding: 11px 12px; }
  fieldset label { min-height: 44px; }
  .key summary { min-height: 44px; }
  .map-btn { top: calc(10px + env(safe-area-inset-top)); }
}

@media (prefers-reduced-motion: reduce) {
  body, aside, .key .chev { transition: none !important; }
}
