:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1f2328;
  --ink-2: #4b5563;
  --ink-3: #6b7280;
  --line: #e5e7eb;
  --accent: #1a73e8;
  --ok: #2f9e44;
  --warn: #b35c00;
  --warn-bg: #fff4e5;
  --bad: #c92a2a;
  --bad-bg: #fff0f0;
  --info-bg: #eef4ff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.08), 0 2px 8px rgba(0,0,0,.06);
  --c-med: #e03131;
  --c-welfare: #f06595;
  --c-edu: #7048e8;
  --c-park: #2f9e44;
  --c-pxmart: #1864ab;
  --c-cvs: #f76707;
  --c-bus: #f59f00;
  --c-rain: #339af0;
  --c-water: #0b7285;
  --c-res: #364fc7;
  --panel-w: 420px;
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { font-size: 14px; line-height: 1.5; }
a { color: var(--accent); }
button { font: inherit; }

#app { display: flex; height: 100vh; width: 100vw; overflow: hidden; }
#panel {
  width: var(--panel-w); min-width: var(--panel-w); height: 100%;
  overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
#map { flex: 1; height: 100%; position: relative; }

.panel-head { padding: 14px 16px 8px; border-bottom: 1px solid var(--line); }
.panel-head h1 { font-size: 19px; margin: 0; letter-spacing: .5px; }
.panel-head .sub { margin: 2px 0 6px; color: var(--ink-3); font-size: 13px; }
#sys-status { display: flex; flex-wrap: wrap; gap: 6px; }

.card { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.card h2 { font-size: 15px; margin: 0 0 8px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.hint { background: var(--info-bg); border-radius: 8px; padding: 8px 10px; color: #1c3d7a; font-size: 13px; }

/* 半徑 */
#radius { width: 100%; accent-color: var(--accent); }
#radius-out { font-weight: 600; }

/* 圖層切換 */
.layers { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; margin: 8px 0 0; padding: 0; border: 0; }
.layers legend { font-weight: 600; padding: 0; margin-bottom: 4px; }
.layer-toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; padding: 3px 2px; border-radius: 6px; user-select: none; }
.layer-toggle:hover { background: #f3f4f6; }
.layer-toggle input { accent-color: var(--accent); margin: 0; }
.swatch { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.25); flex: none; }
.swatch.square { border-radius: 3px; }
.group-label { grid-column: 1 / -1; font-size: 12px; color: var(--ink-3); margin-top: 4px; }

/* 分頁 */
.tabs { display: flex; gap: 2px; padding: 8px 10px 0; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 5; }
.tabs button { border: 0; background: none; padding: 8px 10px; border-radius: 8px 8px 0 0; cursor: pointer; color: var(--ink-2); font-weight: 600; }
.tabs button[aria-selected="true"] { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
.tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tab-body { padding: 10px 16px 24px; }
.tab-body[hidden] { display: none; }

/* 區塊 */
.block { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; background: #fff; }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.block-head h3 { font-size: 14px; margin: 0; display: flex; align-items: center; gap: 6px; }
.block .meta { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.block .meta a { color: var(--ink-3); }
.block .msg { font-size: 12.5px; margin-top: 6px; padding: 6px 8px; border-radius: 6px; }
.msg.warn { background: var(--warn-bg); color: #7a3e00; }
.msg.bad { background: var(--bad-bg); color: #8a1c1c; }
.msg.info { background: var(--info-bg); color: #1c3d7a; }
.note { font-size: 12px; color: var(--ink-2); margin-top: 6px; }

.badge { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.badge.ok { background: #e6f4ea; color: #1e6b31; }
.badge.static { background: #eef1f5; color: #3b4452; }
.badge.stale, .badge.cache, .badge.partial, .badge.limited { background: var(--warn-bg); color: #8a4600; border-color: #f5c27a; }
.badge.error, .badge.missing_key, .badge.auth { background: var(--bad-bg); color: #9b1c1c; border-color: #f3a8a8; }
.badge.empty { background: #f1f3f5; color: #495057; }
.badge.loading { background: #f1f3f5; color: #6b7280; }

.list { list-style: none; padding: 0; margin: 6px 0 0; }
.list li { padding: 6px 0; border-top: 1px dashed var(--line); }
.list li:first-child { border-top: 0; }
.item-btn { all: unset; cursor: pointer; display: block; width: 100%; }
.item-btn:hover .item-name, .item-btn:focus-visible .item-name { text-decoration: underline; }
.item-btn:focus-visible { outline: 2px solid var(--accent); border-radius: 4px; }
.item-name { font-weight: 600; }
.item-sub { font-size: 12px; color: var(--ink-3); }
.dist { float: right; font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 12.5px; margin-left: 8px; }
.counts { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12.5px; color: var(--ink-2); margin-top: 4px; }

details.more { margin-top: 6px; }
details.more summary { cursor: pointer; color: var(--accent); font-size: 12.5px; }

/* 環境數值 */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }
.big { font-size: 20px; font-weight: 700; }
.aqi-chip { display: inline-block; min-width: 38px; text-align: center; border-radius: 6px; padding: 1px 6px; font-weight: 700; border: 1px solid rgba(0,0,0,.2); }
.slots { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 6px; }
.slots th, .slots td { text-align: left; padding: 3px 4px; border-bottom: 1px solid var(--line); }
.slots th { color: var(--ink-3); font-weight: 600; }

/* 公車 */
.search { display: flex; gap: 6px; }
.search input { flex: 1; padding: 7px 10px; border: 1px solid #cfd4dc; border-radius: 8px; font: inherit; }
.search input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.btn { border: 1px solid #cfd4dc; background: #fff; border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.btn:hover { background: #f3f4f6; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.small { padding: 2px 8px; font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { border: 1px solid #d0d7de; background: #fff; border-radius: 999px; padding: 1px 8px; font-size: 12px; cursor: pointer; }
.chip:hover { background: #fff8e1; border-color: var(--c-bus); }
.chip.dir-1 { border-style: dashed; }
.seg { display: inline-flex; border: 1px solid #cfd4dc; border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 4px 12px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.stops { list-style: none; margin: 6px 0 0; padding: 0; max-height: 360px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.stops li { display: flex; gap: 8px; align-items: baseline; padding: 4px 8px; border-top: 1px solid #f1f3f5; cursor: pointer; font-size: 13px; }
.stops li:first-child { border-top: 0; }
.stops li:hover { background: #f8f9fa; }
.stops li.sel { background: #fff4d6; }
.stops .ord { color: var(--ink-3); min-width: 26px; font-variant-numeric: tabular-nums; }
.stops .warn-tag { color: var(--warn); font-size: 11.5px; }
.times { display: flex; flex-wrap: wrap; gap: 3px 6px; font-variant-numeric: tabular-nums; font-size: 12.5px; margin-top: 4px; }
.times span { background: #f1f3f5; border-radius: 4px; padding: 0 5px; }
.hour-row { display: flex; gap: 8px; font-size: 12.5px; padding: 2px 0; border-bottom: 1px dotted var(--line); font-variant-numeric: tabular-nums; }
.hour-row b { min-width: 28px; color: var(--ink-3); }

/* 地圖上的元件 */
.map-hint {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 800;
  background: rgba(255,255,255,.95); padding: 7px 14px; border-radius: 999px; box-shadow: var(--shadow); font-size: 13px;
  pointer-events: none;
}
.toast-wrap { position: absolute; right: 12px; bottom: 28px; z-index: 900; display: flex; flex-direction: column; gap: 6px; max-width: 360px; }
.toast { background: #2b2f36; color: #fff; padding: 8px 12px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); }
.toast.bad { background: #8a1c1c; }
.loading-bar { position: absolute; top: 0; left: 0; height: 3px; background: var(--accent); z-index: 900; width: 0; transition: width .2s; }

.dicon { background: none; border: 0; }
.aqi-mk { display: flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 50%; font-weight: 700; font-size: 12px; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.wx-mk { background: #fff; border: 1px solid #adb5bd; border-radius: 8px; padding: 1px 5px; font-size: 11.5px; white-space: nowrap; box-shadow: 0 1px 3px rgba(0,0,0,.2); transform: translate(-50%, -50%); display: inline-block; }
.wx-mk b { font-weight: 700; }
.wx-mk.old { background: #fff4e5; border: 1.5px dashed #b35c00; color: #5c3100; }
.wx-mk.expired { background: #f1f3f5; border: 1px dashed #868e96; color: #6b7280; }
.wx-tag { background: #b35c00; color: #fff; border-radius: 4px; padding: 0 4px; font-size: 10.5px; font-weight: 700; }
.wx-state.on { margin-left: 4px; font-size: 11px; background: #fff4e5; color: #8a4600; border: 1px solid #f5c27a; border-radius: 999px; padding: 0 6px; }
.slots tr.cur td { background: #eef4ff; }
.res-mk { width: 22px; height: 22px; background: var(--c-res); color: #fff; border: 2px solid #fff; border-radius: 4px; box-shadow: 0 0 0 1px rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; }
.res-mk.uncertain { background: #748ffc; }
.plant-mk { width: 16px; height: 16px; background: var(--c-water); border: 2px solid #fff; border-radius: 3px; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.well-mk { width: 10px; height: 10px; background: #fff; border: 2px solid var(--c-water); border-radius: 50%; }

.leaflet-popup-content { font-size: 13px; line-height: 1.5; margin: 10px 12px; min-width: 220px; }
.pop-title { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.pop-type { color: var(--ink-3); font-size: 12px; margin-bottom: 4px; }
.pop-row { margin: 1px 0; }
.pop-src { margin-top: 6px; padding-top: 4px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--ink-3); }
.pop-warn { color: #8a4600; font-size: 12px; }

@media (max-width: 760px) {
  #app { flex-direction: column-reverse; }
  #panel { width: 100%; min-width: 0; height: 52vh; border-right: 0; border-top: 1px solid var(--line); }
  #map { height: 48vh; flex: none; }
  .layers { grid-template-columns: 1fr 1fr; }
  .map-hint { font-size: 12px; top: 8px; }
}
