:root {
  --ink: #1d1a2b;
  --ink-2: #4b4760;
  --ink-3: #6a6580;
  --line: #e6e3ee;
  --surface: #ffffff;
  --surface-2: #f6f4fa;
  --canvas: #eceaf2;
  --brand: #5b3fa6;
  --brand-ink: #ffffff;
  --brand-soft: #efeafb;
  --nurse: #c7365f;
  --nurse-soft: #fbe9ef;
  --change: #0f7c70;
  --change-soft: #e3f4f1;
  --mrt: #2459c7;
  --mrt-soft: #e7eefc;
  --road: #9a5300;
  --road-soft: #fbf0e1;
  --ok: #1d7a3e;
  --warn: #8a5a00;
  --warn-soft: #fff4dc;
  --bad: #b3261e;
  --shadow: 0 1px 2px rgb(29 26 43 / 0.08), 0 8px 28px rgb(29 26 43 / 0.14);
  --radius: 18px;
  --panel: 420px;
  --font: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #f1eef9; --ink-2: #cdc8de; --ink-3: #aaa4bf; --line: #2f2c3d; --surface: #1c1a26; --surface-2: #242131;
    --canvas: #13121a; --brand: #b9a6f5; --brand-ink: #1b1530; --brand-soft: #2c2547; --nurse: #ff8fae; --nurse-soft: #3a2230;
    --change: #5fd3c2; --change-soft: #183330; --mrt: #8db2ff; --mrt-soft: #1d2740; --road: #f2b566; --road-soft: #35281a;
    --ok: #7ad69a; --warn: #f2c66d; --warn-soft: #3a2f17; --bad: #ff8a80;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 10px 30px rgb(0 0 0 / 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--canvas); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.6; -webkit-text-size-adjust: 100%; }
body { overflow: hidden; overscroll-behavior: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
[hidden] { display: none !important; }

#map { position: fixed; inset: 0; }
.maplibregl-ctrl-attrib { font-size: 12px; }
.maplibregl-ctrl-bottom-right { bottom: var(--sheet-visible, 0px); }

/* ---------- Top bar: floating search + filters ---------- */
.topbar { position: fixed; z-index: 5; top: 0; left: 0; right: 0; padding: calc(env(safe-area-inset-top) + 10px) 12px 8px; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.searchrow { display: flex; gap: 8px; align-items: center; }
.brand { flex: none; width: 48px; height: 48px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); display: grid; place-items: center; }
.brand svg { width: 32px; height: 32px; }
.search { flex: 1; min-width: 0; height: 48px; display: flex; align-items: center; gap: 8px; padding: 0 6px 0 14px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); color: var(--ink-3); }
.search svg { width: 20px; height: 20px; flex: none; }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 16px; color: var(--ink); height: 100%; }
.search input::placeholder { color: var(--ink-3); }
.search input::-webkit-search-cancel-button { display: none; }
.clear { width: 36px; height: 36px; border: 0; border-radius: 12px; background: var(--surface-2); font-size: 22px; line-height: 1; color: var(--ink-2); }
.iconbtn { flex: none; min-width: 48px; height: 48px; padding: 0 10px; border: 0; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); font-weight: 600; font-size: 15px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 2px 6px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 15px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); box-shadow: 0 1px 3px rgb(29 26 43 / 0.08); font-size: 15px; white-space: nowrap; color: var(--ink); }
.chip i { width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
.chip.c-n i { background: var(--nurse); } .chip.c-c i { background: var(--change); } .chip.c-m i { background: var(--mrt); } .chip.c-f i { background: var(--road); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chip.toggle[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip.toggle[aria-pressed="true"]::before { content: "✓"; font-weight: 700; }
.chipsep { flex: none; width: 1px; margin: 8px 2px; background: var(--line); }

.fab { position: fixed; z-index: 4; right: 12px; bottom: calc(var(--sheet-visible, 0px) + 14px); width: 52px; height: 52px; border-radius: 18px; border: 0; background: var(--surface); color: var(--brand); box-shadow: var(--shadow); display: grid; place-items: center; transition: bottom .25s ease; }
.fab svg { width: 24px; height: 24px; }
.sheet-full .fab { opacity: 0; pointer-events: none; }
.fab.active { color: var(--brand-ink); background: var(--brand); }

.crosshair { position: fixed; z-index: 3; left: 50%; top: var(--cross-y, 40%); width: 44px; height: 56px; margin: -56px 0 0 -22px; pointer-events: none;
  background: no-repeat center/contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 44 56'%3E%3Cpath d='M22 54s18-19 18-32A18 18 0 0 0 4 22c0 13 18 32 18 32z' fill='%235b3fa6' stroke='white' stroke-width='3'/%3E%3Ccircle cx='22' cy='22' r='7' fill='white'/%3E%3C/svg%3E"); }

/* ---------- Bottom sheet (phone) / side panel (desktop) ---------- */
.sheet { position: fixed; z-index: 6; left: 0; right: 0; bottom: 0; height: calc(100% - var(--top-h, 120px)); background: var(--surface); border-radius: 24px 24px 0 0; box-shadow: 0 -6px 30px rgb(29 26 43 / 0.16);
  display: flex; flex-direction: column; transform: translateY(var(--sheet-y, 50%)); transition: transform .32s cubic-bezier(.2,.8,.2,1); will-change: transform; }
.sheet.dragging { transition: none; }
.grab { flex: none; height: 26px; display: grid; place-items: center; touch-action: none; cursor: grab; }
.grab span { width: 44px; height: 5px; border-radius: 3px; background: var(--line); }
.sheet-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 0 16px calc(env(safe-area-inset-bottom) + 24px); -webkit-overflow-scrolling: touch; }

@media (min-width: 900px) {
  .topbar { right: auto; width: var(--panel); padding: 14px 14px 8px; background: var(--surface); box-shadow: none; border-right: 1px solid var(--line); }
  .brand, .search, .iconbtn { box-shadow: none; background: var(--surface-2); }
  .chip { box-shadow: none; }
  .chips { flex-wrap: wrap; overflow: visible; }
  .sheet { top: var(--top-h, 140px); right: auto; width: var(--panel); height: auto; border-radius: 0; box-shadow: 8px 0 30px rgb(29 26 43 / 0.08); transform: none !important; border-right: 1px solid var(--line); }
  .grab { display: none; }
  .sheet-body { padding-top: 6px; }
  .fab { bottom: 28px; right: 18px; }
  .maplibregl-ctrl-bottom-right { bottom: 0; }
}

/* ---------- Sheet content ---------- */
.sheet-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 2px 0 10px; }
.sheet-head h2 { margin: 0; font-size: 20px; line-height: 1.4; font-weight: 700; }
.sheet-head .meta { color: var(--ink-2); font-size: 15px; white-space: nowrap; }
.textbtn { border: 0; background: none; color: var(--brand); font-weight: 600; padding: 8px 4px; font-size: 15px; }

.list { list-style: none; margin: 0; padding: 0; }
.item { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: start; width: 100%; padding: 12px 6px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; border-radius: 0; }
.item:hover { background: var(--surface-2); }
.item:last-child { border-bottom: 0; }
.badge { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; }
.badge svg { width: 26px; height: 26px; }
.t-n .badge { background: var(--nurse-soft); color: var(--nurse); }
.t-c .badge { background: var(--change-soft); color: var(--change); }
.t-m .badge { background: var(--mrt-soft); color: var(--mrt); }
.t-f .badge { background: var(--road-soft); color: var(--road); }

.item-name, .item-sub { display: block; }
.item-name { font-weight: 600; font-size: 16px; line-height: 1.45; overflow-wrap: anywhere; }
.item-sub { color: var(--ink-2); font-size: 15px; line-height: 1.5; margin-top: 2px; }
.dist { color: var(--ink); font-weight: 600; font-size: 15px; white-space: nowrap; padding-top: 1px; }
.dist small { display: block; color: var(--ink-2); font-weight: 400; font-size: 14px; text-align: right; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 14px; line-height: 1.6; background: var(--surface-2); color: var(--ink-2); }
.tag.dad { background: var(--brand-soft); color: var(--brand); }
.tag.open { background: #e4f4e9; color: var(--ok); }
.tag.closed { background: var(--surface-2); color: var(--ink-2); }
.tag.approx { background: var(--warn-soft); color: var(--warn); }
.tag.cert { background: var(--nurse-soft); color: var(--nurse); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tag.open { background: #183424; } }
.empty { padding: 28px 8px; color: var(--ink-2); text-align: center; }
.more { display: block; width: 100%; margin: 10px 0 0; padding: 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; color: var(--brand); }

/* detail */
.detail-top { display: flex; gap: 12px; align-items: flex-start; margin: 4px 0 6px; }
.detail-top h2 { margin: 0; font-size: 22px; line-height: 1.4; overflow-wrap: anywhere; }
.kind { color: var(--ink-2); font-size: 15px; margin: 2px 0 0; }
.back { flex: none; width: 44px; height: 44px; border-radius: 14px; border: 0; background: var(--surface-2); display: grid; place-items: center; }
.back svg { width: 22px; height: 22px; }
.actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin: 14px 0 6px; }
.action { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 64px; padding: 8px 4px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); font-size: 15px; font-weight: 600; color: var(--ink); text-decoration: none; }
.action svg { width: 22px; height: 22px; color: var(--brand); }
.action.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.action.primary svg { color: var(--brand-ink); }
.facts { margin: 8px 0 0; padding: 0; list-style: none; }
.fact { display: grid; grid-template-columns: 28px 1fr; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.fact:last-child { border-bottom: 0; }
.fact svg { width: 22px; height: 22px; color: var(--ink-3); margin-top: 2px; }
.fact b { display: block; font-weight: 600; }
.fact .v { color: var(--ink); overflow-wrap: anywhere; white-space: pre-line; }
.fact .s { color: var(--ink-2); font-size: 15px; }
.fact a { font-weight: 600; text-decoration: none; }
.callout { margin: 12px 0; padding: 12px 14px; border-radius: 14px; background: var(--warn-soft); color: var(--ink); font-size: 15px; }
.callout b { color: var(--warn); }
.panel { margin: 16px 0 0; padding: 14px; border-radius: 16px; background: var(--surface-2); }
.panel h3 { margin: 0 0 6px; font-size: 16px; }
.panel p { margin: 0; color: var(--ink-2); font-size: 15px; }
.rooms { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.room { padding: 6px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-size: 15px; }
.room.yes { border-color: var(--change); color: var(--change); font-weight: 600; }
.source { margin-top: 16px; font-size: 14px; line-height: 1.6; color: var(--ink-2); }
.source a { color: var(--ink-2); }
.nearby .item { padding: 10px 4px; }

/* forms */
.form h2 { margin: 4px 0 4px; font-size: 20px; }
.form p.lead { margin: 0 0 12px; color: var(--ink-2); font-size: 15px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0 14px; }
.seg label, .checks label { position: relative; }
.seg input, .checks input { position: absolute; opacity: 0; inset: 0; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 52px; padding: 6px; border-radius: 14px; border: 1.5px solid var(--line); text-align: center; font-weight: 600; font-size: 15px; line-height: 1.35; }
.seg input:checked + span { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.seg input:focus-visible + span, .checks input:focus-visible + span { outline: 3px solid var(--brand); outline-offset: 2px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 14px; }
.checks span { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--line); font-size: 15px; }
.checks input:checked + span { border-color: var(--change); background: var(--change-soft); color: var(--change); font-weight: 600; }
.checks input:checked + span::before { content: "✓ "; white-space: pre; }
.field { display: block; margin: 0 0 12px; }
.field > span { display: block; font-weight: 600; margin-bottom: 6px; font-size: 15px; }
.field input, .field textarea { width: 100%; border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; background: var(--surface); font-size: 16px; }
.field textarea { min-height: 88px; resize: vertical; }
.submit { width: 100%; min-height: 52px; border: 0; border-radius: 16px; background: var(--brand); color: var(--brand-ink); font-weight: 700; font-size: 16px; }
.submit[disabled] { opacity: .6; }
.err { margin: 10px 0 0; padding: 10px 12px; border-radius: 12px; background: #fdecea; color: var(--bad); font-size: 15px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .err { background: #3a1d1b; } }
.community { margin-top: 14px; }
.community .bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--ink-2); font-size: 15px; }
.community .count { font-weight: 700; color: var(--ink); }

/* sources */
.sources h2 { margin: 4px 0 6px; font-size: 20px; }
.sources p { color: var(--ink-2); margin: 0 0 12px; font-size: 15px; }
.sources ul { padding-left: 20px; margin: 0 0 14px; }
.sources li { margin: 0 0 8px; font-size: 15px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0 16px; }
.stat { padding: 12px; border-radius: 14px; background: var(--surface-2); }
.stat b { display: block; font-size: 22px; line-height: 1.3; }
.stat span { color: var(--ink-2); font-size: 14px; }

.footer-links { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); }

.toast { position: fixed; z-index: 20; left: 50%; top: calc(env(safe-area-inset-top) + 72px); transform: translateX(-50%); max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px; background: var(--ink); color: var(--surface); box-shadow: var(--shadow); font-size: 15px; }

.skeleton { height: 64px; margin: 10px 0; border-radius: 14px; background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite linear; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .sheet, .fab { transition: none; } .skeleton { animation: none; } }
