/* 台灣雨量監測面板 — v2 專業監控台（預設亮色 + 暗色）
   設計語言：operations console（DarkCell / Windy / NWS 風）
   克制的 accent、hairline 分隔、tabular 數字、14/13/12/11 字級階層 */
:root {
  --bg-0: #f4f6f9;
  --bg-1: #ffffff;
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --line: #e3e8ef;
  --line-2: #edf1f6;
  --text-1: #1b2430;
  --text-2: #566274;
  --text-3: #8a94a6;
  --accent: #0b6ea8;
  --accent-2: #0e7a91;
  --ok: #1a7f5f;
  --run: #b3671b;
  --err: #c03030;
  --shadow: 0 1px 2px rgba(16,24,40,.05);
  --radius: 8px;
  --radius-s: 6px;
  --map-filter: none;
  --map-bg: #e9eef4;
  /* 天氣類別色（縣市卡片 icon + 文字） */
  --wx-sun: #fbbf24;      /* 晴：金黃 */
  --wx-cloud: #6b7f96;    /* 多雲：灰藍 */
  --wx-overcast: #38455a; /* 陰：深灰 */
  --wx-fog: #5e6d82;      /* 霧：霧灰 */
  --wx-rain: #0b6ea8;     /* 雨：藍 */
}
html[data-theme="dark"] {
  --bg-0: #0e131b;
  --bg-1: #131a24;
  --panel: #151c27;
  --panel-2: #111823;
  --line: #242e3d;
  --line-2: #1c2534;
  --text-1: #e9edf4;
  --text-2: #9fabbf;
  --text-3: #64718a;
  --accent: #58a6d6;
  --accent-2: #7cc3e8;
  --ok: #3fae86;
  --run: #d9a441;
  --err: #e07a7a;
  --shadow: 0 1px 2px rgba(0,0,0,.35);
  --map-filter: invert(1) grayscale(1) contrast(0.92) brightness(0.9);
  --map-bg: #0a0f16;
  --wx-sun: #fbbf24;
  --wx-cloud: #8fa3bc;
  --wx-overcast: #c3cddd;
  --wx-fog: #7f8ba0;
  --wx-rain: #58a6d6;
}

* { box-sizing: border-box; }
html { height: auto; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg-0);
  color: var(--text-1);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
/* 數字一律 tabular，避免跳動 */
.stat-num, .rank-val, .srow-val, .clock-time, .clock-sub, .legend-scale span,
.hist-date, .img-ts, .rank-idx, .search-meta b { font-variant-numeric: tabular-nums; }

/* ---------- topbar (command bar) ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 16px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: wrap;
}
.topbar-left,
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand-text { min-width: 0; }
.brand-text h1 { font-size: 15px; font-weight: 800; margin: 0; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { margin: 1px 0 0; font-size: 11px; color: var(--text-3); letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-right { display: flex; align-items: center; gap: 14px; }
.auto-refresh {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-3);
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--panel-2);
  white-space: nowrap;
  flex-shrink: 0;
}
.auto-refresh-lab {
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
  flex-shrink: 0;
}
.auto-refresh select {
  font-size: 12px; font-family: inherit; font-variant-numeric: tabular-nums;
  color: var(--text-1);
  background: transparent; border: none; outline: none;
  cursor: pointer;
}
.live {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 600; color: var(--text-2);
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  white-space: nowrap;
  flex-shrink: 0;
}
.live:empty { display: none; }
.clock-row { display: flex; align-items: center; gap: 12px; }
.clock {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  line-height: 1.2;
}
.clock-time { font-size: 19px; font-weight: 700; letter-spacing: .03em; }
.clock-sub { font-size: 11px; color: var(--text-3); margin-top: 1px; white-space: nowrap; }
.clock-sub span { color: var(--text-2); }

.theme-toggle {
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: var(--radius-s);
  color: var(--text-2);
  cursor: pointer;
  flex-shrink: 0;
  transition: color .15s, border-color .15s;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-moon { display: none; }
html[data-theme="dark"] .icon-sun { display: none; }
html[data-theme="dark"] .icon-moon { display: block; }

/* ---------- status dots ---------- */
.status-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-3); flex: none; margin-right: 5px; vertical-align: middle;
}
.status-dot.done { background: var(--ok); }
.status-dot.running { background: var(--run); animation: pulse 1.1s ease-in-out infinite; }
.status-dot.error { background: var(--err); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

/* ---------- top alert banner ---------- */
.alert-banner {
  background: #fffbeb;
  border-bottom: 1px solid #fef08a;
  color: #854d0e;
  padding: 8px 16px;
  font-size: 13px;
  position: sticky;
  top: 52px;
  z-index: 40;
}
html[data-theme="dark"] .alert-banner {
  background: #231c0a;
  border-bottom-color: #4d3810;
  color: #fde047;
}
.alert-banner.alert-danger-theme {
  background: #fef2f2;
  border-bottom-color: #fecaca;
  color: #991b1b;
}
html[data-theme="dark"] .alert-banner.alert-danger-theme {
  background: #271113;
  border-bottom-color: #531c21;
  color: #f87171;
}
.alert-banner-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.alert-badge {
  font-size: 11px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: .02em;
  white-space: nowrap;
}
.alert-badge.warning {
  background: #fef08a;
  color: #854d0e;
}
html[data-theme="dark"] .alert-badge.warning {
  background: #4d3810;
  color: #fde047;
}
.alert-badge.danger {
  background: #fecaca;
  color: #991b1b;
}
html[data-theme="dark"] .alert-badge.danger {
  background: #531c21;
  color: #f87171;
}
.alert-summary {
  flex: 1;
  min-width: 200px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.alert-time {
  font-size: 11.5px;
  opacity: .85;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.alert-jump {
  font-size: 12px;
  font-weight: 700;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
  margin-left: auto;
}
.alert-jump:hover {
  opacity: .85;
}

/* ---------- dashboard grid ---------- */
.dash {
  flex: 1;
  display: grid;
  grid-template-columns: 300px minmax(0,1fr) 280px;
  grid-template-areas:
    "side map right"
    "county county county"
    "dgpa dgpa dgpa"
    "warn warn warn"
    "imgs imgs imgs";
  grid-template-rows: auto auto auto auto auto;
  gap: 10px;
  padding: 10px 16px 0;
}
.dash-side { grid-area: side; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.dash-side > .panel { flex-shrink: 0; }
.dash-map {
  grid-area: map;
  min-width: 0;
  min-height: 540px;
  display: flex;
  flex-direction: column;
  isolation: isolate;
}
.dash-right { grid-area: right; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.dash-right > .panel { flex: none; display: flex; flex-direction: column; }
.dash-imgs { grid-area: imgs; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; min-width: 0; }
.dash-dgpa { grid-area: dgpa; min-width: 0; display: flex; }
.dash-dgpa > .panel { flex: 1; display: flex; flex-direction: column; }
.dash-county { grid-area: county; min-width: 0; display: flex; }
.dash-county > .panel { flex: 1; display: flex; flex-direction: column; }
.dash-warn { grid-area: warn; min-width: 0; display: flex; }
.dash-warn > .panel { flex: 1; display: flex; flex-direction: column; }
.rank-list { max-height: 460px; overflow: auto; }

/* ---------- 縣市即時天氣（CWA 21 縣市卡片）— HUD console 風格 ---------- */
:root {
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Consolas, "Noto Sans Mono", monospace;
  --county-bracket: rgba(2, 132, 199, .38);
}
html[data-theme="dark"] {
  --county-bracket: rgba(88, 166, 214, .42);
}
.county-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 6px;
  padding: 10px 12px;
}
.county-card {
  position: relative;
  padding: 8px 10px 7px;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  min-width: 0;
  transition: border-color .12s;
}
.county-card:hover { border-color: var(--line); }
/* HUD 角標（左上 / 右下 L 形括弧） */
.county-card::before,
.county-card::after {
  content: "";
  position: absolute;
  width: 9px;
  height: 9px;
  pointer-events: none;
  border: 0 solid var(--county-bracket);
}
.county-card::before { top: -1px; left: -1px; border-top-width: 1.5px; border-left-width: 1.5px; }
.county-card::after { bottom: -1px; right: -1px; border-bottom-width: 1.5px; border-right-width: 1.5px; }
.county-row1 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}
.county-id { display: flex; align-items: center; gap: 5px; min-width: 0; font-size: 12px; }
.county-id svg { width: 13px; height: 13px; flex: none; color: var(--text-3); }
.county-id b { font-weight: 700; font-size: 12.5px; color: var(--text-1); letter-spacing: .03em; white-space: nowrap; }
.county-id i { font-style: normal; font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.county-temp {
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 700;
  color: var(--text-1);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.county-temp .deg { font-size: 11px; font-weight: 500; color: var(--text-3); margin-left: 1px; }
.county-row2 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-top: 3px;
  font-size: 11px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.county-rain b { font-family: var(--font-mono); font-weight: 600; color: var(--text-2); }
/* 天氣類別色：icon + 天氣文字（判定順序 雨 > 霧 > 陰 > 雲 > 晴，雨量強調另見 .rain/.heavy） */
.county-id.wx-sun svg, .county-id.wx-sun i { color: var(--wx-sun); }
.county-id.wx-cloud svg, .county-id.wx-cloud i { color: var(--wx-cloud); }
.county-id.wx-overcast svg, .county-id.wx-overcast i { color: var(--wx-overcast); }
.county-id.wx-fog svg, .county-id.wx-fog i { color: var(--wx-fog); }
.county-id.wx-rain svg, .county-id.wx-rain i { color: var(--wx-rain); }
/* 1h 雨量強度計（0–30 mm/h 滿格） */
.county-meter {
  margin-top: 6px;
  height: 3px;
  border-radius: 2px;
  background: var(--line-2);
  overflow: hidden;
}
.county-meter i {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  transition: width .3s ease;
}
/* 有雨量（>0 mm）：icon 與雨量數值 accent */
.county-card.rain .county-id svg,
.county-card.rain .county-rain b { color: var(--accent); }
/* 時雨量達量雨標準（>= 16 mm/h）：warn 強調 */
.county-card.heavy .county-meter i { background: var(--run); }
.county-card.heavy .county-id svg,
.county-card.heavy .county-rain b { color: var(--run); }
.county-card.heavy .county-rain b { font-weight: 700; }
.county-empty { grid-column: 1 / -1; padding: 14px 4px; font-size: 12.5px; color: var(--text-3); }
/* 收合：隱藏內容，只留 panel-head */
.dash-county > .panel.collapsed { grid-template-rows: auto; }
.dash-county > .panel.collapsed .county-grid { display: none; }

/* ---------- 風力與颱風警報 (dash-warn) ---------- */
.warn-head-left { display: flex; align-items: center; gap: 10px; }
.warn-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
  letter-spacing: .02em;
}
.warn-pill.calm {
  background: rgba(26, 127, 95, .12);
  color: var(--ok);
  border: 1px solid rgba(26, 127, 95, .25);
}
.warn-pill.warning {
  background: #fffbeb;
  border: 1px solid #fef08a;
  color: #854d0e;
}
html[data-theme="dark"] .warn-pill.warning {
  background: #231c0a;
  border: 1px solid #4d3810;
  color: #fde047;
}
.warn-pill.danger {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}
html[data-theme="dark"] .warn-pill.danger {
  background: #271113;
  border: 1px solid #531c21;
  color: #f87171;
}

.warn-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 14px;
  padding: 12px 14px;
  flex: 1;
}
@media (max-width: 820px) {
  .warn-grid { grid-template-columns: 1fr; }
}

.warn-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.warn-block-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-1);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.warn-tag {
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  line-height: 1.3;
  display: inline-block;
}
.warn-tag.tag-yellow {
  background: #fffbeb;
  border: 1px solid #fef08a;
  color: #854d0e;
}
html[data-theme="dark"] .warn-tag.tag-yellow {
  background: #231c0a;
  border-color: #4d3810;
  color: #fde047;
}
.warn-tag.tag-orange,
.warn-tag.tag-red {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}
html[data-theme="dark"] .warn-tag.tag-orange,
html[data-theme="dark"] .warn-tag.tag-red {
  background: #271113;
  border-color: #531c21;
  color: #f87171;
}
.warn-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}
.warn-desc {
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.6;
  background: var(--panel-2);
  padding: 10px 12px;
  border-radius: var(--radius-s);
  border: 1px solid var(--line-2);
}
.warn-desc-hl {
  font-weight: 700;
  color: var(--text-1);
  margin-bottom: 6px;
  line-height: 1.5;
}
.warn-desc-body {
  white-space: pre-line;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.6;
}
.warn-calm-box, .typhoon-calm-box {
  padding: 18px 14px;
  text-align: center;
  background: var(--panel-2);
  border-radius: var(--radius-s);
  border: 1px solid var(--line-2);
}
.warn-calm-text {
  font-size: 14px;
  font-weight: 700;
  color: var(--ok);
  margin-bottom: 4px;
}
.typhoon-calm-text {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-1);
  margin-bottom: 4px;
}
.warn-calm-sub, .typhoon-calm-sub {
  font-size: 11.5px;
  color: var(--text-3);
  margin-bottom: 8px;
}
.typhoon-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}
.typhoon-link:hover { text-decoration: underline; }

/* 颱風有警報動態佈局 */
.typhoon-active-layout {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.typhoon-head-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.typhoon-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--text-1);
}
.typhoon-report {
  font-size: 11.5px;
  color: var(--accent);
  font-weight: 700;
}
.typhoon-issued {
  font-size: 11px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.typhoon-img-container {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 6px;
  text-align: center;
}
.typhoon-img-container img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  opacity: 0.94;
  display: block;
  margin: 0 auto;
}
.typhoon-img-hint {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 4px;
  display: block;
  text-align: right;
}
.typhoon-img-hint a {
  color: var(--accent);
  text-decoration: none;
}
.typhoon-img-hint a:hover { text-decoration: underline; }

.typhoon-table {
  width: 100%;
  font-size: 12px;
  border-collapse: collapse;
  background: var(--panel-2);
  border-radius: var(--radius-s);
  border: 1px solid var(--line-2);
  overflow: hidden;
}
.typhoon-table tr:not(:last-child) td {
  border-bottom: 1px solid var(--line-2);
}
.typhoon-table td {
  padding: 6px 10px;
  vertical-align: top;
}
.typhoon-label {
  font-weight: 700;
  color: var(--text-2);
  white-space: nowrap;
  width: 105px;
}
.typhoon-val {
  color: var(--text-1);
  font-variant-numeric: tabular-nums;
}
.typhoon-area-box {
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-s);
  padding: 8px 10px;
  line-height: 1.55;
}
.typhoon-area-box b {
  color: var(--err);
}

/* ---------- panels（降調：hairline + 極淡陰影 + 8px 圓角） ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.panel.grow { flex: 1; }
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-2);
  background: var(--panel-2);
  flex: none;
}
.panel-head h2 {
  font-size: 12px; font-weight: 700; margin: 0;
  letter-spacing: .05em; color: var(--text-2);
}
.panel-hint { font-size: 11px; color: var(--text-3); display: flex; align-items: center; white-space: nowrap; margin-left: auto; }
/* panel 收合鈕（chevron，hover 顯示 accent；收合時 chevron 轉 180°） */
.panel-collapse-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition: color .12s, background .12s, transform .18s;
}
.panel-collapse-btn:hover { color: var(--text-1); background: var(--panel); }
.panel-collapse-btn:active { transform: scale(.92); }
.panel.collapsed .panel-collapse-btn svg { transform: rotate(180deg); }

/* ---------- search ---------- */
.search-row { display: flex; gap: 8px; padding: 10px 12px 6px; }
.search-row input {
  flex: 1; min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--bg-1);
  color: var(--text-1);
  font-size: 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search-row input::placeholder { color: var(--text-3); }
.search-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent); }
.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text-1);
  border-radius: var(--radius-s);
  padding: 7px 12px;
  font-size: 12.5px; font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.small { padding: 3px 8px; font-size: 11.5px; }
.search-meta { padding: 4px 12px 6px; font-size: 12px; color: var(--text-2); }
.search-meta b { color: var(--text-1); }
.search-results { padding: 0 12px 10px; overflow: auto; }
.srow {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 6px 8px;
  border-radius: var(--radius-s);
  cursor: pointer;
  font-size: 12.5px;
  transition: background .12s;
}
.srow:hover { background: var(--panel-2); }
.srow-name { color: var(--text-1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srow-val { color: var(--accent-2); font-weight: 700; white-space: nowrap; }

/* ---------- KPI band（統計：單一條帶 + hairline 分隔） ---------- */
.stat-grid {
  display: flex;
  margin: 10px 12px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--panel-2);
  overflow: hidden;
}
.stat {
  flex: 1;
  padding: 9px 8px 8px;
  text-align: center;
  border-left: 1px solid var(--line-2);
  min-width: 0;
}
.stat:first-child { border-left: none; }
.stat-num {
  font-size: 25px; font-weight: 800;
  line-height: 1.05; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.stat-num.has-wet { color: var(--accent); }
.stat-num.has-max { color: var(--accent); }
.stat-lab {
  font-size: 10.5px; color: var(--text-3);
  margin-top: 4px; font-weight: 600; letter-spacing: .06em;
  white-space: nowrap;
}

/* ---------- legend ---------- */
.legend { padding: 0 12px 11px; margin-top: 10px; }
.legend-head { margin-bottom: 6px; }
.legend-title { font-size: 11px; color: var(--text-2); font-weight: 600; }
.legend-bars { display: flex; gap: 2px; }
.legend-bars i { flex: 1; height: 9px; border-radius: 2px; display: block; }
.legend-scale { display: flex; gap: 2px; margin-top: 4px; }
.legend-scale span { flex: 1; text-align: center; font-size: 9px; color: var(--text-3); }

/* ---------- map card（標題移卡頭） ---------- */
.map-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-2);
  background: var(--panel-2);
  flex: none;
}
.map-title { font-size: 12px; font-weight: 700; letter-spacing: .05em; color: var(--text-2); }
.map-note { font-size: 11px; color: var(--text-3); }
.map-wrap { position: relative; flex: 1; min-height: 540px; }
/* 桌面：地圖加高至 720px → fitBounds 可達 zoom 8（島嶼 3.5° 高在 web-mercator
   需 ~640px 起才 z=8），島嶼填滿畫面高度，避免寬容器被壓到 zoom 7 造成大片海面 */
@media (min-width: 1101px) {
  .map-wrap { min-height: 720px; }
}
.mapbox {
  position: absolute; inset: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
  background: var(--map-bg);
}
.leaflet-tile { filter: var(--map-filter); }
.leaflet-container { background: var(--map-bg); font-family: inherit; }
.leaflet-control-zoom {
  border: 1px solid var(--line) !important;
  border-radius: var(--radius-s) !important;
  overflow: hidden;
  box-shadow: var(--shadow) !important;
}
.leaflet-control-zoom a {
  background: var(--panel) !important;
  color: var(--text-1) !important;
  border-bottom: 1px solid var(--line) !important;
}
.leaflet-control-zoom a:last-child { border-bottom: none !important; }
.leaflet-control-zoom a:hover { background: var(--panel-2) !important; }
.leaflet-control-attribution {
  background: color-mix(in srgb, var(--bg-1) 88%, transparent) !important;
  color: var(--text-3) !important;
  font-size: 10px !important;
}
.leaflet-popup-content-wrapper {
  background: var(--panel); color: var(--text-1);
  border: 1px solid var(--line); border-radius: var(--radius-s);
  box-shadow: 0 4px 14px rgba(15,23,42,.18);
}
.leaflet-popup-tip { background: var(--panel); }
.leaflet-popup-content { margin: 10px 13px; font-size: 12.5px; line-height: 1.55; }
.leaflet-popup-content .sid { color: var(--text-3); font-size: 11px; }

/* ---------- typhoon track on map (TASK7) ---------- */
.map-typhoon-legend {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1000;
  background: var(--panel);
  color: var(--text-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  box-shadow: 0 4px 14px rgba(15,23,42,.16);
  padding: 8px 10px;
  font-size: 11px;
  line-height: 1.4;
  pointer-events: auto;
  display: none;
}
.ty-leg-title {
  font-weight: 700;
  color: var(--text-1);
  margin-bottom: 5px;
  letter-spacing: .02em;
}
.ty-leg-orgs {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 5px;
}
.ty-leg-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-2);
  font-size: 10.5px;
}
.ty-leg-item i {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.ty-leg-meta {
  color: var(--text-2);
  font-size: 10.5px;
  font-weight: 600;
  margin-bottom: 5px;
  font-variant-numeric: tabular-nums;
}
.ty-leg-types {
  display: flex;
  gap: 9px;
  color: var(--text-3);
  font-size: 10px;
  border-top: 1px solid var(--line-2);
  padding-top: 4px;
}
.ty-leg-type {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.ty-leg-type i.solid {
  display: inline-block;
  width: 14px;
  height: 2.5px;
  background: var(--text-2);
}
.ty-leg-type i.dashed {
  display: inline-block;
  width: 14px;
  height: 0;
  border-top: 3px dashed #8b5cf6;
}
.ty-leg-type i.circle {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px dashed #f59e0b;
  background: rgba(245, 158, 11, 0.08);
  box-sizing: border-box;
}

.leaflet-tooltip.typhoon-tip {
  background: var(--panel) !important;
  color: var(--text-1) !important;
  border: 1px solid var(--line) !important;
  border-radius: var(--radius-s) !important;
  box-shadow: 0 2px 8px rgba(15,23,42,.18) !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  padding: 3px 6px !important;
  white-space: nowrap !important;
}
.leaflet-tooltip.typhoon-tip::before {
  border-top-color: var(--line) !important;
}
.leaflet-tooltip.typhoon-tip.fc {
  font-weight: 600 !important;
  font-size: 10px !important;
  color: var(--text-2) !important;
  padding: 2px 5px !important;
}
.leaflet-tooltip.typhoon-tip.fc::before {
  border-right-color: var(--line) !important;
}

.typhoon-calm-meta {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  line-height: 1.6;
}

.typhoon-focus-btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text-1);
  border-radius: var(--radius-s);
  padding: 3px 8px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.typhoon-focus-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.typhoon-focus-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- rank list（兩行 + hairline 分隔 + 底部細條） ---------- */
.rank-list { overflow: auto; padding: 4px 0; flex: 1; }
.rank-item {
  position: relative;
  display: grid;
  grid-template-columns: 22px minmax(0,1fr) auto;
  grid-template-rows: auto auto;
  grid-template-areas: "idx main val" "bar bar bar";
  align-items: center;
  gap: 2px 8px;
  padding: 7px 12px 8px;
  border-bottom: 1px solid var(--line-2);
  cursor: pointer;
  transition: background .12s;
}
.rank-item:last-child { border-bottom: none; }
.rank-item:hover { background: var(--panel-2); }
.rank-idx {
  grid-area: idx;
  font-size: 11px; color: var(--text-3);
  text-align: center; width: 20px; height: 20px;
  display: grid; place-items: center;
  border-radius: 5px; font-weight: 600;
  align-self: start;
}
.rank-top .rank-idx { color: #fff; background: var(--accent); font-weight: 800; }
.rank-main { grid-area: main; min-width: 0; }
.rank-name {
  font-size: 12.5px; font-weight: 700; color: var(--text-1);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block;
}
.rank-sub {
  font-size: 10.5px; color: var(--text-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block;
  margin-top: 1px;
}
.rank-val {
  grid-area: val;
  font-size: 13px; font-weight: 800; color: var(--text-1);
  text-align: right; white-space: nowrap;
}
.rank-unit { font-size: 9.5px; font-weight: 500; color: var(--text-3); margin-left: 2px; }
.rank-bar {
  grid-area: bar;
  height: 3px; background: var(--line-2); border-radius: 2px; overflow: hidden;
  margin-top: 3px;
}
.rank-bar i { display: block; height: 100%; border-radius: 2px; }
.rank-empty { padding: 16px; text-align: center; color: var(--text-3); font-size: 12.5px; }

/* ---------- image cards（收緊高度） ---------- */
.img-card {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.img-stage { flex: 1; display: flex; align-items: center; justify-content: center; padding: 6px 8px; background: #0d131a; }
.dash-imgs img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  border-radius: 6px;
}
.img-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 7px 11px;
  border-bottom: 1px solid var(--line-2);
  background: var(--panel-2);
  flex-wrap: wrap;
}
.img-title { font-size: 12.5px; font-weight: 700; }
.img-src { font-size: 10.5px; color: var(--text-3); font-weight: 400; margin-left: 6px; }
.img-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.img-ts { font-size: 11px; color: var(--text-2); white-space: nowrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.seg button {
  border: none; background: var(--panel-2); color: var(--text-2);
  font-size: 11.5px; font-weight: 600; padding: 4px 9px; cursor: pointer;
  transition: background .15s, color .15s;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--accent); color: #fff; }
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- DGPA（行距收緊、停止事項 bad 色） ---------- */
.dgpa-cols { display: grid; grid-template-columns: minmax(0,1.4fr) minmax(0,1fr); flex: 1; min-height: 0; }
.dgpa-latest-body { padding: 11px 14px; border-right: 1px solid var(--line-2); overflow: auto; min-height: 0; }
.dgpa-history { padding: 4px 14px; overflow: auto; min-height: 0; }
.dgpa-title { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.dgpa-date {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  font-size: 11.5px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border-radius: 5px;
  vertical-align: 2px;
  font-variant-numeric: tabular-nums;
}
.dgpa-meta { font-size: 11px; color: var(--text-3); margin-bottom: 8px; }
.dgpa-meta a { color: var(--accent); text-decoration: none; }
.dgpa-meta a:hover { text-decoration: underline; }
.dgpa-rows { display: flex; flex-direction: column; gap: 7px; }
.dgpa-city b { font-size: 12.5px; color: var(--text-1); }
.dgpa-city ul { margin: 3px 0 0; padding-left: 16px; }
.dgpa-city li { font-size: 12px; color: var(--text-2); margin: 2px 0; }
.dgpa-city li.dgpa-bad { color: var(--err); font-weight: 600; }
.dgpa-none { display: flex; flex-direction: column; gap: 5px; padding: 6px 0 2px; }
.dgpa-none-line { font-size: 14px; font-weight: 700; color: var(--ok); }
.dgpa-none-sub { font-size: 11.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.dgpa-note { font-size: 11px; color: var(--text-3); line-height: 1.5; }
.dgpa-warn { font-size: 12.5px; color: var(--run); line-height: 1.6; margin-bottom: 6px; }
.dgpa-err { font-size: 12.5px; color: var(--err); }
.hist-row {
  display: flex; gap: 10px; align-items: baseline;
  padding: 6px 4px;
  border-bottom: 1px solid var(--line-2);
  text-decoration: none;
  transition: background .12s;
}
.hist-row:last-child { border-bottom: none; }
.hist-row:hover { background: var(--panel-2); }
.hist-date { font-size: 11.5px; color: var(--accent-2); font-weight: 700; white-space: nowrap; }
.hist-title { font-size: 12px; color: var(--text-1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dgpa-disclaimer {
  padding: 8px 14px;
  font-size: 11px;
  color: var(--text-3);
  border-top: 1px solid var(--line-2);
  background: var(--panel-2);
  line-height: 1.5;
}
.dgpa-disclaimer a {
  color: var(--accent);
  text-decoration: none;
}
.dgpa-disclaimer a:hover {
  text-decoration: underline;
}

/* ---------- 來源小字（取代 full-width 頁尾帶） ---------- */
.src-note {
  flex: none;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 5px 16px 7px;
  font-size: 10.5px;
  color: var(--text-3);
  text-align: left;
  letter-spacing: .02em;
}
.src-note .src-text {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.src-feedback {
  flex: none;
  margin-left: auto;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}
.src-feedback:hover { text-decoration: underline; }
.src-link {
  flex: none;
  color: var(--text-2);
  text-decoration: none;
  white-space: nowrap;
}
.src-note a::before {
  content: "·";
  margin-right: 10px;
  color: var(--line-2);
}
.src-link:hover { color: var(--accent); text-decoration: underline; }

/* ---------- 首頁 SSR 靜態語意內容（SEO skeleton） ---------- */
.seo-section {
  width: calc(100% - 32px);
  max-width: 1100px;
  margin: 14px auto 6px;
}
.seo-inner {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 26px 24px;
}
.seo-inner > h2 {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .02em;
}
.seo-inner > p {
  margin: 0 0 16px;
  font-size: 13.5px;
  color: var(--text-2);
  line-height: 1.7;
}
.seo-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
  margin-bottom: 14px;
}
.seo-col h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-1);
  margin: 0 0 8px;
  letter-spacing: .04em;
}
.seo-col ul { margin: 0; padding-left: 18px; }
.seo-col li {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.65;
  margin-bottom: 5px;
}
.seo-section h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-1);
  margin: 16px 0 8px;
  letter-spacing: .04em;
}
.seo-faq { margin: 0; }
.seo-faq dt {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-1);
  margin-top: 10px;
}
.seo-faq dd {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.65;
}
@media (max-width: 820px) {
  .seo-cols { grid-template-columns: 1fr; gap: 12px; }
  .seo-inner { padding: 16px; }
}

/* ---------- 法律頁（隱私權政策） ---------- */
.legal-page {
  flex: 1;
  width: 100%;
  max-width: 760px;
  margin: 28px auto;
  padding: 0 16px;
}
.legal-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 32px 32px;
}
.legal-title {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: .01em;
}
.legal-updated {
  margin: 0 0 22px;
  font-size: 12px;
  color: var(--text-3);
}
.legal-panel section { margin-bottom: 20px; }
.legal-panel h2 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-1);
  margin: 0 0 8px;
  letter-spacing: .03em;
}
.legal-panel p, .legal-panel li {
  font-size: 13.5px;
  color: var(--text-2);
  line-height: 1.7;
}
.legal-panel ul { margin: 8px 0 0; padding-left: 20px; }
.legal-panel li { margin-bottom: 4px; }
.legal-panel code {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", monospace;
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}
.legal-panel a { color: var(--accent); }
.legal-back {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  text-decoration: none;
  margin-bottom: 12px;
}
.legal-back:hover {
  color: var(--text-1);
}
.brand-home { color: inherit; text-decoration: none; }
.brand-home:hover { color: var(--accent); text-decoration: underline; }
@media (max-width: 640px) {
  .legal-panel { padding: 20px; }
  .legal-page { margin-top: 16px; }
  /* 手機 topbar 折成 2 行（~85px），sticky banner 的 top:52px 會滑進 topbar 下方被遮；
     改為 static（隨文流置於 topbar 之下），避免重疊 */
  .alert-banner {
    position: static;
  }
}

/* ---------- skeleton ---------- */
.skeleton {
  border-radius: var(--radius-s);
  background: linear-gradient(90deg, var(--panel-2) 25%, var(--line-2) 37%, var(--panel-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
.skeleton-card { height: 40px; margin-bottom: 8px; }
.skeleton-line { height: 12px; margin-bottom: 8px; }
@keyframes shimmer { 0%{background-position:100% 0} 100%{background-position:-100% 0} }
.hidden { display: none !important; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .dash {
    grid-template-columns: 280px minmax(0,1fr);
    grid-template-areas:
      "side map"
      "right right"
      "county county"
      "warn warn"
      "dgpa dgpa"
      "imgs imgs";
    grid-template-rows: minmax(430px, auto) auto auto auto auto auto;
  }
  .dash-right { flex-direction: row; }
  .dash-right .panel { flex: 1; }
  .rank-list { max-height: 320px; }
}
@media (max-width: 900px) {
  .topbar {
    padding: 6px 12px;
    gap: 6px 12px;
  }
  .topbar-left,
  .brand {
    flex-basis: 100%;
    width: 100%;
    min-width: 0;
  }
  .brand-text h1 {
    font-size: 14px;
  }
  .topbar-right {
    flex-direction: row;
    flex-basis: 100%;
    width: 100%;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex-wrap: wrap;
  }
  .auto-refresh {
    padding: 3px 8px;
    gap: 5px;
    font-size: 11.5px;
  }
  .auto-refresh select {
    font-size: 11.5px;
  }
  .clock-row {
    margin-left: auto;
    gap: 6px;
    flex-shrink: 0;
    align-items: center;
  }
  .live {
    font-size: 11.5px;
    padding: 3px 8px;
  }
  .clock-time {
    font-size: 15px;
  }
  .clock-sub {
    font-size: 10.5px;
    display: none; /* mobile：狀態 pill 已表達「已更新」，避免右側兩行臃腫錯位 */
  }
  .clock { gap: 0; }
  .theme-toggle {
    width: 28px;
    height: 28px;
  }
}
@media (max-width: 820px) {
  .dash {
    grid-template-columns: 1fr;
    grid-template-areas: "side" "map" "right" "county" "dgpa" "warn" "imgs";
    grid-template-rows: auto auto auto auto auto auto auto;
  }
  .map-wrap { min-height: 360px; }
  .dash-imgs { grid-template-columns: 1fr; }
  .dash-right { flex-direction: column; }
  .dgpa-cols { grid-template-columns: 1fr; }
  .dgpa-latest-body { border-right: none; border-bottom: 1px solid var(--line-2); }
  .dash { padding: 8px 12px 0; }
}
