:root {
  /* 品牌 */
  --brand: #0a6ea8;
  --brand-deep: #08537f;
  --brand-soft: #eaf4fb;
  --brand-tint: #f4f9fd;
  /* 中性 */
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e6ebf2;
  --border-strong: #d7dee8;
  --text: #0f1e2b;
  --text-2: #3d5266;
  --muted: #64748b;
  --faint: #94a3b8;
  /* 语义 */
  --up: #e0393e;
  --up-soft: #fdf0f0;
  --down: #16a34a;
  --down-soft: #eefaf2;
  --flat: #94a3b8;
  --warn: #dc2626;
  --warn-soft: #fef2f2;
  --radius: 14px;
  --radius-sm: 9px;
  /* 卡片行高，app.js 的 ROW_H 必须与之保持一致 */
  --row-h: 110px;
  --shadow: 0 1px 2px rgba(15, 30, 43, .04), 0 4px 16px rgba(15, 30, 43, .06);
  --shadow-sm: 0 1px 2px rgba(15, 30, 43, .06);
  --shadow-pop: 0 6px 24px rgba(15, 30, 43, .14);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue",
    "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

/* ---------- 头部 ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 720px;
  margin: 0 auto;
  padding: 10px 14px;
}
.header-row--status {
  padding-top: 0;
  padding-bottom: 9px;
  border-top: 1px solid var(--border);
  margin-top: 2px;
}
.brand { min-width: 0; }
.app-header .title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .3px;
}
.app-header .subtitle {
  margin: 1px 0 0;
  font-size: 11px;
  color: var(--muted);
}

/* 视图切换（分段控件） */
.view-toggle {
  display: inline-flex;
  flex: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}
.view-toggle button {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 7px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.view-toggle button.active {
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* 状态行 */
.header-status { display: flex; align-items: center; gap: 8px; min-width: 0; }
.live-dot {
  flex: none;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--down);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, .14);
}
.live-dot.is-stale { background: var(--warn); box-shadow: 0 0 0 3px rgba(220, 38, 38, .14); }
.status-time {
  flex: 1;
  min-width: 0;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-time.scrape-warning { color: var(--warn); }
.icon-btn {
  flex: none;
  width: 30px; height: 30px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--brand);
  border-radius: 8px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: var(--brand-soft); border-color: #cfe4f2; }
.icon-btn:active { background: #ddeef9; }
.icon-btn[disabled] { opacity: .55; cursor: default; }
.icon-btn.spinning { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.container { max-width: 720px; margin: 0 auto; padding: 12px 14px 40px; }

/* ---------- 概览条 ---------- */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}
.stat {
  position: relative;
  text-align: center;
  padding: 11px 2px 10px;
}
.stat + .stat::before {
  content: "";
  position: absolute;
  left: 0; top: 18%;
  height: 64%;
  width: 1px;
  background: var(--border);
}
.stat-num {
  display: block;
  font-size: 19px;
  font-weight: 700;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.2px;
}
.stat-label { display: block; font-size: 11px; color: var(--muted); margin-top: 1px; }
.stat--up .stat-num { color: var(--up); }
.stat--down .stat-num { color: var(--down); }
.stat--flat .stat-num { color: var(--faint); }
.stat--warn .stat-num { color: var(--faint); }
.stat--warn.is-active { background: var(--warn-soft); }
.stat--warn.is-active .stat-num { color: var(--warn); }

/* ---------- 工具栏 ---------- */
.toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px;
  margin-bottom: 8px;
}
.search-box { position: relative; }
.search-icon {
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  color: var(--faint);
  pointer-events: none;
  line-height: 1;
}
.search-box input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  padding: 9px 34px 9px 31px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s, background .15s;
}
.search-box input:focus { border-color: var(--brand); background: var(--surface); }
.search-box input::-webkit-search-cancel-button { display: none; }
.clear-btn {
  position: absolute;
  right: 7px; top: 50%;
  transform: translateY(-50%);
  border: none;
  background: var(--border-strong);
  color: #fff;
  width: 20px; height: 20px;
  border-radius: 50%;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.filter-row { display: flex; gap: 8px; margin-top: 8px; }
.filter-row select {
  flex: 1 1 0;
  min-width: 0;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2)
    url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%2364748b' d='M0 0h10L5 6z'/%3E%3C/svg%3E")
    no-repeat right 10px center;
  padding: 8px 26px 8px 10px;
  font-size: 13px;
  min-height: 36px;
  cursor: pointer;
}
.filter-row select:focus { border-color: var(--brand); }

.status-line {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--muted);
  padding: 0 4px 8px;
}

/* ---------- 站点卡片 ---------- */
/* 虚拟滚动：卡片绝对定位，容器高度由 JS 设置 */
.station-list { position: relative; }
.card {
  position: absolute;
  left: 0; top: 0;
  height: var(--row-h);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 13px 12px 15px;
  box-shadow: var(--shadow);
  cursor: pointer;
  overflow: hidden;
  transition: box-shadow .15s, transform .08s;
}
.card:active { transform: scale(.995); }
.card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--flat);
}
.card.over-warning::before { background: var(--warn); }
.card.up::before { background: var(--up); }
.card.down::before { background: var(--down); }
.card.flat::before { background: var(--border-strong); }
.card.over-warning { background: linear-gradient(90deg, var(--warn-soft) 0, var(--surface) 34%); }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
.card-title { display: flex; align-items: baseline; min-width: 0; flex-wrap: nowrap; overflow: hidden; }
.card-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 auto;
}
.card-river {
  font-size: 12px;
  color: var(--muted);
  margin-left: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 auto;
}
.trend-badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.5;
  padding: 0 6px;
  border-radius: 20px;
  margin-left: 6px;
  vertical-align: 1px;
  flex: none;
}
.trend-up { color: var(--up); background: var(--up-soft); }
.trend-down { color: var(--down); background: var(--down-soft); }
.trend-flat { color: var(--muted); background: var(--surface-2); }
.card-time {
  font-size: 11px;
  color: var(--faint);
  white-space: nowrap;
  flex: none;
  font-variant-numeric: tabular-nums;
}

.card-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-top: 9px;
}
.metric { padding: 0 4px; position: relative; }
.metric + .metric::before {
  content: "";
  position: absolute;
  left: 0; top: 12%;
  height: 76%;
  width: 1px;
  background: var(--border);
}
.m-label { font-size: 11px; color: var(--muted); }
.m-value {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.2px;
  margin-top: 1px;
}
.m-unit { font-size: 11px; font-weight: 400; color: var(--muted); margin-left: 1px; }
.val-up { color: var(--up); }
.val-down { color: var(--down); }
.val-safe { color: var(--brand); }
.val-flat { color: var(--muted); font-size: 15px; }

.empty-tip {
  text-align: center;
  color: var(--muted);
  padding: 46px 20px;
  font-size: 14px;
}
.empty-tip button {
  display: block;
  margin: 12px auto 0;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 16px;
  font-size: 13px;
  color: var(--brand);
  cursor: pointer;
}

/* ---------- 地图 ---------- */
.map-view {
  position: relative;
  z-index: 0;
  width: 100%;
  height: 68vh;
  min-height: 420px;
  background: var(--brand-tint);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
#mapContainer { position: absolute; inset: 0; }
.map-bar {
  position: absolute;
  top: 10px; left: 10px;
  z-index: 1001;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(6px);
  border-radius: 9px;
  padding: 6px 11px;
  font-size: 11.5px;
  color: var(--text-2);
  box-shadow: var(--shadow-pop);
}
.map-tip {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, .95);
  padding: 8px 16px;
  border-radius: 9px;
  font-size: 13px;
  color: var(--muted);
  z-index: 1001;
  max-width: 80%;
  text-align: center;
}
.locate-btn {
  position: absolute;
  right: 12px; bottom: 14px;
  z-index: 1001;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .96);
  color: var(--brand);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-pop);
  display: flex;
  align-items: center;
  justify-content: center;
}
.locate-btn:active { background: var(--brand-soft); }
.locate-btn.locating { opacity: .6; pointer-events: none; }

.map-legend {
  position: absolute;
  left: 10px; bottom: 10px;
  z-index: 1001;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(6px);
  border-radius: 9px;
  padding: 6px 10px;
  display: flex;
  gap: 10px;
  font-size: 11.5px;
  color: var(--text-2);
  box-shadow: var(--shadow-pop);
}
.map-legend .dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}
.dot-warn { background: var(--warn); }
.dot-up { background: var(--up); }
.dot-down { background: var(--down); }
.dot-flat { background: var(--faint); }

/* ---------- 弹层 ---------- */
.mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 30, 43, .42);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  animation: fade-in .18s ease;
}
.mask[hidden] { display: none; }
@keyframes fade-in { from { opacity: 0; } }
.sheet {
  background: var(--surface);
  width: 100%;
  max-width: 720px;
  border-radius: 18px 18px 0 0;
  padding: 6px 14px calc(14px + env(safe-area-inset-bottom));
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  box-shadow: 0 -6px 32px rgba(15, 30, 43, .18);
  animation: slide-up .24s cubic-bezier(.22, .8, .3, 1);
}
@keyframes slide-up { from { transform: translateY(100%); } }
.sheet-handle {
  width: 36px; height: 4px;
  border-radius: 3px;
  background: var(--border-strong);
  margin: 2px auto 8px;
  flex: none;
}
.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  flex: none;
}
.sheet-title { font-size: 17px; font-weight: 700; }
.sheet-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.sheet-current {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 7px;
  font-size: 12.5px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.sheet-current b { font-weight: 700; }
.close-btn {
  flex: none;
  border: none;
  background: var(--surface-2);
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}
.close-btn:hover { background: var(--border); }

.range-tabs {
  display: inline-flex;
  flex: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  margin-top: 12px;
  align-self: flex-start;
}
.range-tabs button {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 6px 13px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 7px;
  cursor: pointer;
}
.range-tabs button.active { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }

.chart { width: 100%; height: 420px; margin-top: 8px; flex: 1 1 auto; min-height: 300px; }
.sheet-foot {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 6px;
  min-height: 16px;
  flex: none;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(15, 30, 43, .9);
  color: #fff;
  padding: 9px 16px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 200;
  box-shadow: var(--shadow-pop);
  animation: fade-in .18s ease;
}

/* ---------- 响应式 ---------- */
@media (min-width: 600px) {
  .container { padding: 14px 18px 48px; }
  /* 双列时卡片变窄，指标字号相应收紧 */
  .station-list.cols-2 .m-value { font-size: 15px; }
  .station-list.cols-2 .card-name { font-size: 15px; }
  .station-list.cols-2 .card-river { font-size: 11px; }
}
@media (max-width: 400px) {
  .m-value { font-size: 15px; }
  .card-name { font-size: 15px; }
  .stat-num { font-size: 17px; }
  .filter-row { flex-wrap: wrap; }
  .filter-row select { flex: 1 1 44%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
