:root {
  --normal: #16a34a;
  --cut: #dc2626;
  --turbid: #f59e0b;
  --other: #eab308;
  --primary: #0b66c3;
  --primary-dark: #09539e;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #16202c;
  --text-2: #5b6b7c;
  --text-3: #8b9aa9;
  --line: #e4e9ef;
  --shadow: 0 2px 12px rgba(16, 32, 48, .08);
  --shadow-lg: 0 -8px 32px rgba(16, 32, 48, .16);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.5;
  overscroll-behavior-y: none;
}

#app { display: flex; flex-direction: column; height: 100dvh; max-width: 720px; margin: 0 auto; background: var(--bg); position: relative; }

/* ---------- 顶栏 ---------- */
.topbar { background: var(--card); box-shadow: var(--shadow); z-index: 30; flex: none; }
.topbar-main { display: flex; align-items: center; gap: 8px; padding: 10px 14px 6px; }
.brand { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.brand .drop { width: 26px; height: 26px; flex: none; fill: var(--primary); }
.brand-text { min-width: 0; }
.brand h1 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand p { margin: 1px 0 0; font-size: 11.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn { width: 34px; height: 34px; flex: none; border: 1px solid var(--line); background: #fff; border-radius: 10px; display: grid; place-items: center; cursor: pointer; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: var(--text-2); stroke-width: 1.9; stroke-linecap: round; }
.icon-btn.ghost { border: none; background: transparent; }

.statbar { display: flex; gap: 6px; padding: 0 12px 10px; overflow-x: auto; scrollbar-width: none; }
.statbar::-webkit-scrollbar { display: none; }

/* 免责声明：信息由市民自愿上报 */
.notice {
  background: #fff8e1; color: #6b4f00; font-size: 11.5px;
  padding: 6px 14px; text-align: center; line-height: 1.45;
  border-top: 1px solid #f0e2a8; border-bottom: 1px solid #f0e2a8;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.notice b { color: #4a3700; font-weight: 600; }
.stat {
  flex: 1 1 0; min-width: 62px; border: 1px solid var(--line); border-radius: 10px;
  background: #fbfcfd; padding: 6px 4px 5px; cursor: pointer; text-align: center;
  display: flex; flex-direction: column; gap: 1px; font-family: inherit;
}
.stat b { font-size: 17px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--text-2); }
.stat.s-normal b { color: var(--normal); }
.stat.s-cut b { color: var(--cut); }
.stat.s-turbid b { color: var(--turbid); }
.stat.s-other b { color: #ca8a04; }
.stat.s-truck b { color: var(--primary); }
.stat.active { border-color: currentColor; box-shadow: inset 0 0 0 1px currentColor; }
.stat.s-normal.active { color: var(--normal); border-color: var(--normal); }
.stat.s-cut.active { color: var(--cut); border-color: var(--cut); }
.stat.s-turbid.active { color: var(--turbid); border-color: var(--turbid); }
.stat.s-other.active { color: #ca8a04; border-color: #ca8a04; }
.stat.s-truck.active { color: var(--primary); border-color: var(--primary); }

/* ---------- 地图 ---------- */
.map-wrap { position: relative; flex: 1 1 auto; min-height: 0; }
.map { position: absolute; inset: 0; background: #eaeef3; }
/* overlay 仅负责绘制点位/热力，必须允许点击穿透到地图层；
   否则它会把所有 pointer/touch 事件吃掉，导致地图拖不动、上报选不了点 */
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; z-index: 5; pointer-events: none; }

.map-tools { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 1100; }
.round-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.96);
  font-size: 18px; line-height: 1; color: var(--text-2); cursor: pointer; display: grid; place-items: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.1); font-family: inherit;
}
.round-btn svg { width: 18px; height: 18px; fill: none; stroke: var(--text-2); stroke-width: 1.8; stroke-linecap: round; }

.legend {
  position: absolute; left: 10px; bottom: 10px; z-index: 1100; background: rgba(255,255,255,.96);
  border-radius: 10px; padding: 7px 10px; display: flex; gap: 10px; font-size: 11.5px; color: var(--text-2);
  box-shadow: 0 1px 5px rgba(0,0,0,.12); pointer-events: none;
}
.legend span { display: flex; align-items: center; gap: 4px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.d-normal { background: var(--normal); } .d-cut { background: var(--cut); }
.d-turbid { background: var(--turbid); } .d-other { background: var(--other); }
.d-none { background: #9aa7b4; }

.viewswitch { position: absolute; right: 10px; top: 10px; z-index: 1100; display: flex; background: rgba(255,255,255,.96); border-radius: 10px; overflow: hidden; box-shadow: 0 1px 5px rgba(0,0,0,.12); }
.viewswitch button { border: none; background: transparent; padding: 7px 12px; font-size: 12.5px; color: var(--text-2); cursor: pointer; font-family: inherit; }
.viewswitch button.active { background: var(--primary); color: #fff; font-weight: 600; }

.live-badge {
  position: absolute; left: 10px; top: 10px; z-index: 1100; background: rgba(255,255,255,.96);
  border-radius: 20px; padding: 5px 10px; font-size: 11.5px; color: var(--text-2);
  display: flex; align-items: center; gap: 5px; box-shadow: 0 1px 5px rgba(0,0,0,.12);
}
.live-badge i { width: 7px; height: 7px; border-radius: 50%; background: var(--normal); animation: pulse 2s infinite; }
.live-badge.stale i { background: var(--turbid); animation: none; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- FAB ---------- */
.fab {
  position: absolute; right: 14px; bottom: calc(16px + var(--safe-b)); z-index: 1100;
  width: 62px; height: 62px; border-radius: 50%; border: none; background: var(--primary); color: #fff;
  box-shadow: 0 6px 20px rgba(11, 102, 195, .42); cursor: pointer; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px; font-family: inherit;
}
.fab:active { transform: scale(.94); background: var(--primary-dark); }
.fab svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; }
.fab em { font-style: normal; font-size: 11px; font-weight: 600; }

/* ---------- 抽屉 ---------- */
.sheet-mask { position: absolute; left: 0; right: 0; top: 0; bottom: 0; background: rgba(12, 22, 34, .26); z-index: 40; animation: fade .18s ease; pointer-events: auto; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 50; background: var(--card);
  border-radius: 18px 18px 0 0; box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  max-height: 92%; animation: up .24s cubic-bezier(.22,.7,.3,1);
}
/* [hidden] 在 .sheet/详情卡上的 display 必须胜出，否则抽屉会默认全开 */
.sheet[hidden], #detailCard[hidden], #reportSheet[hidden], #feedSheet[hidden], #shareSheet[hidden],
.sheet-mask[hidden], #offlineBar[hidden], #toast[hidden], #searchBox[hidden], #noteInput[hidden],
#btnAdd[hidden], .search-results[hidden] { display: none !important; }
@keyframes up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px; flex: none; }
.sheet-head h2 { margin: 0; font-size: 16.5px; font-weight: 700; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 14px 8px; flex: 1 1 auto; }
.sheet-foot { padding: 10px 14px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); flex: none; background: var(--card); border-radius: 0 0 18px 18px; }

.field { margin-bottom: 16px; }
.field-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; }

.seg { display: flex; background: #eef2f6; border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: none; background: transparent; padding: 8px; border-radius: 8px; font-size: 13.5px; color: var(--text-2); cursor: pointer; font-family: inherit; }
.seg button.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.1); }

.search-box { margin-top: 8px; }
.text-input, #searchInput {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px;
  font-family: inherit; background: #fff; color: var(--text); outline: none;
}
.text-input:focus, #searchInput:focus { border-color: var(--primary); }
.search-results { list-style: none; margin: 6px 0 0; padding: 0; max-height: 210px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.search-results li { padding: 9px 12px; border-bottom: 1px solid #f0f3f6; cursor: pointer; font-size: 13.5px; }
.search-results li:last-child { border-bottom: none; }
.search-results li small { display: block; color: var(--text-3); font-size: 11.5px; margin-top: 2px; }
.search-results li:hover { background: #f6f9fc; }

.loc-info { display: flex; gap: 8px; align-items: flex-start; margin-top: 10px; padding: 10px; background: #f6f9fc; border-radius: 10px; border: 1px solid #e8eef5; }
.loc-info.clickable { cursor: pointer; }
.loc-info.clickable:hover { background: #eef4fa; border-color: #cdddee; }
.loc-info.clickable:active { background: #e6eef8; }
.loc-info svg { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--primary); stroke-width: 1.7; margin-top: 1px; }
.loc-info strong { display: block; font-size: 13.5px; font-weight: 600; }
.loc-info small { display: block; font-size: 11.5px; color: var(--text-3); margin-top: 2px; font-variant-numeric: tabular-nums; }
.loc-info.picked { background: #eef7f0; border-color: #d5ecdc; }
.loc-info .loc-hint { display: block; font-size: 11px; color: var(--primary); margin-top: 4px; font-weight: 600; }
#addressInput { margin-top: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  border: 1px solid var(--line); background: #fbfcfd; border-radius: 999px; padding: 7px 13px;
  font-size: 13px; color: var(--text-2); cursor: pointer; font-family: inherit;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

.status-list { display: flex; flex-direction: column; gap: 8px; }
.status-item {
  display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); background: #fbfcfd;
  border-radius: 12px; padding: 12px 14px; font-size: 14.5px; cursor: pointer; text-align: left; font-family: inherit; color: var(--text);
}
.status-item i { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.status-item.s-normal i { background: var(--normal); } .status-item.s-cut i { background: var(--cut); }
.status-item.s-turbid i { background: var(--turbid); } .status-item.s-other i { background: var(--other); }
.status-item.active { font-weight: 600; box-shadow: inset 0 0 0 2px currentColor; border-color: currentColor; }
.status-item.s-normal.active { color: var(--normal); } .status-item.s-cut.active { color: var(--cut); }
.status-item.s-turbid.active { color: var(--turbid); } .status-item.s-other.active { color: #ca8a04; }
#noteInput { margin-top: 8px; resize: none; }

.consent { font-size: 12px; color: var(--text-3); padding: 2px 0 6px; }
.consent label { display: flex; align-items: flex-start; gap: 7px; cursor: pointer; }
.consent input { margin-top: 2px; accent-color: var(--primary); }

.btn-primary {
  width: 100%; border: none; background: var(--primary); color: #fff; border-radius: 12px;
  padding: 14px; font-size: 15.5px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn-primary:disabled { background: #b9c7d6; cursor: not-allowed; }
.btn-ghost { flex: 1; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px; font-size: 13.5px; color: var(--text-2); cursor: pointer; font-family: inherit; }
.btn-ghost.active { border-color: var(--primary); color: var(--primary); font-weight: 600; background: #f2f8ff; }

/* ---------- 详情卡 ---------- */
.detail-card {
  position: absolute; left: 12px; right: 12px; bottom: calc(14px + var(--safe-b)); z-index: 35;
  background: #fff; border-radius: 14px; padding: 14px; box-shadow: var(--shadow-lg); animation: up .2s ease;
}
.detail-close { position: absolute; right: 8px; top: 6px; border: none; background: transparent; font-size: 22px; color: var(--text-3); cursor: pointer; line-height: 1; }
.detail-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; }
.detail-status.normal { background: #e8f7ed; color: var(--normal); }
.detail-status.cut { background: #fdeaea; color: var(--cut); }
.detail-status.turbid { background: #fdf3e2; color: #b45309; }
.detail-status.other { background: #fdf8e3; color: #a16207; }
.detail-title { font-size: 16px; font-weight: 700; margin: 8px 20px 4px 0; }
.detail-meta { font-size: 12px; color: var(--text-3); }
.detail-note { margin: 8px 0 0; font-size: 13.5px; color: var(--text-2); background: #f6f9fc; padding: 8px 10px; border-radius: 8px; }
.detail-note:empty { display: none; }
.detail-actions { display: flex; gap: 8px; margin-top: 12px; }

/* ---------- 动态列表 ---------- */
.sheet-feed { height: 76%; }
.filter-row { display: flex; gap: 7px; padding: 0 14px 10px; overflow-x: auto; border-bottom: 1px solid var(--line); flex: none; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.filter-row button { flex: none; border: 1px solid var(--line); background: #fbfcfd; border-radius: 999px; padding: 6px 14px; font-size: 12.5px; color: var(--text-2); cursor: pointer; font-family: inherit; }
.filter-row button.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.feed-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1 1 auto; }
.feed-list li { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid #f0f3f6; cursor: pointer; }
.feed-list li:active { background: #f6f9fc; }
.feed-badge { flex: none; width: 8px; border-radius: 4px; }
.feed-badge.normal { background: var(--normal); } .feed-badge.cut { background: var(--cut); }
.feed-badge.turbid { background: var(--turbid); } .feed-badge.other { background: var(--other); }
.feed-main { flex: 1; min-width: 0; }
.feed-main strong { font-size: 14px; font-weight: 600; }
.feed-main p { margin: 3px 0 0; font-size: 12.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-main small { display: block; font-size: 11.5px; color: var(--text-3); margin-top: 3px; }
.feed-time { flex: none; font-size: 11.5px; color: var(--text-3); }
.empty { text-align: center; color: var(--text-3); font-size: 13px; padding: 40px 20px; }

/* ---------- 提示 ---------- */
.toast {
  position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(10px); z-index: 90;
  background: rgba(20, 30, 42, .92); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13.5px;
  opacity: 0; pointer-events: none; transition: all .22s ease; max-width: 86%; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.offline-bar { position: absolute; top: 0; left: 0; right: 0; background: #b45309; color: #fff; font-size: 12px; text-align: center; padding: 5px; z-index: 60; }

/* ---------- 分享面板 ---------- */
.share-lead { margin: 2px 0 14px; font-size: 13.5px; color: var(--text-2); }
.share-buttons { display: flex; flex-direction: column; gap: 10px; }
.share-btn { border-radius: 12px; padding: 13px; font-size: 15px; font-weight: 600; cursor: pointer; font-family: inherit; }
.share-btn.primary { border: none; background: var(--primary); color: #fff; }
.share-btn:not(.primary) { border: 1px solid var(--line); background: #fff; color: var(--text); }
.share-hint { margin: 12px 0 2px; font-size: 12px; color: var(--text-3); min-height: 16px; }

/* ---------- 降级底图 ---------- */
.fallback-tip {
  position: absolute; left: 50%; top: 50px; transform: translateX(-50%); z-index: 1100;
  background: rgba(255,255,255,.96); border: 1px solid #f5d99a; border-radius: 10px;
  padding: 8px 14px; font-size: 12px; color: #8a5a00; line-height: 1.55; text-align: center;
  box-shadow: 0 2px 8px rgba(180, 83, 9, .12); pointer-events: auto; max-width: 90%;
}
.fallback-tip a { color: #b45309; font-weight: 600; text-decoration: underline; }

/* ---------- HTTP 访问提示条（非安全上下文时浏览器禁用定位，提示切换 HTTPS）---------- */
.https-tip {
  position: fixed; left: 0; right: 0; top: 0; z-index: 2000;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-top, 0px));
  background: #fff7e6; border-bottom: 1px solid #f5d99a;
  box-shadow: 0 2px 10px rgba(180, 83, 9, .13);
}
.https-tip[hidden] { display: none !important; }
.https-tip svg { width: 20px; height: 20px; flex: none; fill: none; stroke: #b45309; stroke-width: 1.7; }
.https-tip-text { flex: 1; min-width: 0; }
.https-tip-text strong { display: block; font-size: 12.5px; font-weight: 600; color: #7c4a03; line-height: 1.4; }
.https-tip-text small { display: block; font-size: 11px; color: #a1670a; margin-top: 1px; }
.https-tip-btn {
  flex: none; border: 0; border-radius: 8px; padding: 7px 14px;
  background: #b45309; color: #fff; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.https-tip-btn:active { background: #92400e; }
/* 提示条显示时把页面整体下推，避免遮住顶栏；--tip-h 由 JS 按实际高度写入 */
body.has-https-tip #app { padding-top: var(--tip-h, 56px); }

/* ---------- 抽屉打开时：让出被 1100 覆盖层挡住的控件 ----------
   之前 sheet 是 z-index:50，而 legend / live-badge / viewswitch / fallback-tip 都是 1100，
   浮在 sheet 之上遮挡底部「提交上报」按钮与右上角内容。抽屉打开时整组隐藏，
   但保留 .map-tools（含定位按钮）与 .fab（FAB 已经在 setMaskFromSheet 里单独 hidden）。 */
body.sheet-open .legend,
body.sheet-open .live-badge,
body.sheet-open .viewswitch,
body.sheet-open .fallback-tip { display: none !important; }

@media (min-width: 560px) {
  #app { box-shadow: 0 0 24px rgba(0,0,0,.06); }
  .fab { right: 20px; bottom: calc(22px + var(--safe-b)); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
