:root, [data-theme="dark"] {
  --bg: #041226;
  --glass: rgba(6, 22, 48, 0.88);
  --glass-border: rgba(62, 200, 232, 0.28);
  --text: #e8f4ff;
  --text-dim: #7eb0d0;
  --accent: #3de0ff;
  --panel-input-bg: rgba(17, 26, 42, 0.9);
  --surface-2: rgba(17, 26, 42, 0.92);
  --chip-bg: rgba(13, 30, 54, 0.7);
  --chip-active-bg: rgba(61, 224, 255, 0.12);
  --chip-active-border: rgba(61, 224, 255, 0.55);
  --hover-tint: rgba(61, 224, 255, 0.08);
  --badge-cat-bg: #1a2740;
  --badge-cat-fg: #7fa8d9;
  --ai-btn-bg: linear-gradient(90deg, #0a3d4d, #114b63);
  --ai-btn-border: #17607a;
  --msg-user-bg: #123a52;
  --send-fg: #04222b;
  --bar-track: rgba(17, 26, 42, 0.9);
  --rail-w: 56px;
  --panel-w: 360px;
  --topbar-h: 58px;
  --risk-1: #2ecc71;
  --risk-2: #f1c40f;
  --risk-3: #e67e22;
  --risk-4: #e74c3c;
  --shadow: rgba(0, 0, 0, 0.35);
}

[data-theme="light"] {
  --bg: #e8eef5;
  --glass: rgba(255, 255, 255, 0.92);
  --glass-border: rgba(40, 90, 140, 0.22);
  --text: #152536;
  --text-dim: #5a738c;
  --accent: #0b7ea8;
  --panel-input-bg: rgba(245, 249, 252, 0.95);
  --surface-2: #eef3f8;
  --chip-bg: #e8eef5;
  --chip-active-bg: rgba(11, 126, 168, 0.12);
  --chip-active-border: rgba(11, 126, 168, 0.45);
  --hover-tint: rgba(11, 126, 168, 0.08);
  --badge-cat-bg: #e2edf5;
  --badge-cat-fg: #3a6a8c;
  --ai-btn-bg: linear-gradient(90deg, #d8ebf3, #c4e0ec);
  --ai-btn-border: #7ab3c9;
  --msg-user-bg: #d5eaf3;
  --send-fg: #ffffff;
  --bar-track: rgba(200, 215, 230, 0.85);
  --shadow: rgba(20, 40, 70, 0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  width: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 13.5px;
  overflow: hidden;
  position: relative;
}

.glass {
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid var(--glass-border);
}

#map {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
}

.maplibregl-ctrl-attrib,
.maplibregl-ctrl-bottom-right,
.maplibregl-ctrl-top-right,
.maplibregl-ctrl-top-left .maplibregl-ctrl-group,
.maplibregl-ctrl-group {
  display: none !important;
}

/* ===== 顶栏 ===== */
#topbar {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 20;
  display: flex; align-items: center; gap: 20px;
  height: var(--topbar-h); padding: 0 16px;
  border-radius: 14px;
  max-width: calc(100vw - 140px);
  box-shadow: 0 8px 32px var(--shadow);
}

.theme-toggle {
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--text-dim);
  width: 30px; height: 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }

.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-mark { color: var(--accent); font-size: 18px; animation: glow 2.4s ease-in-out infinite; }
.brand h1 { font-size: 15px; font-weight: 650; letter-spacing: 0.5px; line-height: 1.1; }
.brand-sub { font-size: 9px; color: var(--text-dim); letter-spacing: 1.5px; margin-top: 2px; }
@keyframes glow { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.topbar-stats { display: flex; align-items: flex-end; gap: 18px; }
.stat {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  min-width: 4.2em; gap: 3px; cursor: default;
}
.stat-num {
  height: 18px; line-height: 18px;
  font-size: 15px; font-weight: 700; color: var(--accent);
  font-variant-numeric: tabular-nums; white-space: nowrap;
  display: flex; align-items: center; justify-content: center;
}
.stat-num.stat-flash { animation: stat-flash 0.7s ease; }
.stat-label {
  height: 14px; line-height: 14px; margin: 0;
  font-size: 10px; color: var(--text-dim); white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
@keyframes stat-flash {
  0% { filter: brightness(1.35); transform: scale(1.06); }
  100% { filter: none; transform: scale(1); }
}

.ai-status {
  display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-dim); white-space: nowrap;
}
.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot-green { background: var(--risk-1); box-shadow: 0 0 6px var(--risk-1); }
.dot-red { background: var(--risk-4); }
.dot-gray { background: var(--text-dim); }
.dot-amber { background: #f1c40f; box-shadow: 0 0 6px #f1c40f; animation: pulse-dot 1.4s ease-in-out infinite; }
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.risk-window-bar {
  display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px;
}
.risk-window-chip {
  border: 1px solid var(--glass-border);
  background: var(--chip-bg);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.risk-window-chip:hover { color: var(--text); border-color: var(--accent); }
.risk-window-chip.active {
  color: var(--accent);
  border-color: var(--chip-active-border);
  background: var(--chip-active-bg);
}

/* ===== 左右图标轨 ===== */
.rail {
  position: fixed; top: 50%; transform: translateY(-50%);
  z-index: 25;
  display: flex; flex-direction: column; gap: 8px;
  padding: 8px;
  border-radius: 14px;
  background: var(--glass);
  backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
}
#left-rail { left: 12px; }
#right-rail.rail.right { right: 12px; left: auto; }

.rail-btn {
  width: 44px; min-height: 48px; padding: 6px 0;
  border: none; border-radius: 10px; cursor: pointer;
  background: transparent; color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: background 0.15s, color 0.15s;
}
.rail-btn:hover { color: var(--text); background: var(--hover-tint); }
.rail-btn.active { color: var(--accent); background: var(--chip-active-bg); }
.rail-ico { font-size: 16px; line-height: 1; }
.rail-txt { font-size: 10px; letter-spacing: 0.5px; }

/* ===== 悬浮面板 ===== */
.float-panel {
  position: fixed; top: 84px; bottom: 24px;
  z-index: 22;
  width: var(--panel-w);
  border-radius: 14px;
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(1.2);
  border: 1px solid var(--glass-border);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  display: flex; flex-direction: column;
  overflow: hidden;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease, transform 0.22s ease;
}
.float-panel.left { left: 76px; transform: translateX(-12px); }
.float-panel.right { right: 76px; transform: translateX(12px); }
.float-panel.open { opacity: 1; pointer-events: auto; transform: translateX(0); }

.panel-view { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.panel-view.hidden { display: none; }

.panel-head {
  display: flex; align-items: center; gap: 6px;
  padding: 12px 14px; border-bottom: 1px solid var(--glass-border); flex-shrink: 0;
}
.panel-head h2 { flex: 1; font-size: 13px; font-weight: 600; letter-spacing: 1px; color: var(--accent); }

.icon-btn {
  background: none; border: 1px solid var(--glass-border); color: var(--text-dim);
  width: 26px; height: 26px; border-radius: 6px; cursor: pointer; font-size: 12px;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

.panel-scroll, .feed-list, .sources-list, .chat-messages {
  flex: 1; overflow-y: auto; min-height: 0; padding: 10px 12px;
}

.feed-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--glass-border); }
.feed-filters select {
  flex: 1 1 42%; min-width: 0; background: var(--panel-input-bg); color: var(--text);
  border: 1px solid var(--glass-border); border-radius: 6px; padding: 5px 6px; font-size: 12px;
}
.feed-filters select option {
  background: var(--panel-input-bg);
  color: var(--text);
}

.scope-chip {
  margin: 8px 12px 0; padding: 6px 10px; border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--accent); font-size: 12px;
}
.scope-chip.hidden { display: none; }
.scope-chip button {
  margin-left: 8px; border: none; background: none; color: var(--text-dim); cursor: pointer;
}

.feed-card {
  background: var(--panel-input-bg); border: 1px solid var(--glass-border);
  border-left: 3px solid var(--text-dim);
  border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.feed-card:hover { border-color: var(--accent); background: var(--hover-tint); }
.fc-meta { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-dim); margin-bottom: 4px; flex-wrap: wrap; }
.fc-title { font-size: 13px; line-height: 1.45; }
.fc-summary { font-size: 12px; color: var(--text-dim); line-height: 1.4; margin-top: 4px; }
.fc-link { color: var(--accent); font-size: 11px; text-decoration: none; }
.fc-link:hover { text-decoration: underline; }

.badge { display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 10px; font-weight: 600; }
.badge-cat { background: var(--badge-cat-bg); color: var(--badge-cat-fg); }
.badge-risk { color: #fff; }
.badge-geo { border: 1px solid var(--glass-border); color: var(--text-dim); }

.src-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 0;
  border-bottom: 1px solid var(--glass-border); font-size: 12.5px;
}
.src-count { margin-left: auto; color: var(--accent); font-variant-numeric: tabular-nums; }
.src-status { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* 风险面板 */
.risk-overview { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.risk-score-big { font-size: 36px; font-weight: 800; font-variant-numeric: tabular-nums; }
.risk-overview-info { font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.dim-row { margin-bottom: 10px; }
.dim-head { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 3px; }
.dim-head .dim-score { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.dim-bar { height: 6px; background: var(--bar-track); border-radius: 3px; overflow: hidden; }
.dim-fill { height: 100%; border-radius: 3px; transition: width 0.45s ease; }
.detail-section-title {
  font-size: 12px; color: var(--accent); margin: 14px 0 8px;
  letter-spacing: 1px; border-bottom: 1px solid var(--glass-border); padding-bottom: 4px;
}
.country-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid var(--glass-border); cursor: pointer;
}
.country-row:hover { color: var(--accent); }
.country-row .score { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.ai-brief {
  background: var(--surface-2); border: 1px solid var(--glass-border); border-radius: 8px;
  padding: 10px; font-size: 12.5px; line-height: 1.65; color: var(--text);
}
.ai-brief-btn {
  width: 100%; background: var(--ai-btn-bg); color: var(--accent);
  border: 1px solid var(--ai-btn-border); border-radius: 8px; padding: 8px; cursor: pointer; font-size: 12.5px;
}
.ai-brief-btn:hover { filter: brightness(1.08); }
.ai-brief-btn:disabled { opacity: 0.5; cursor: wait; }

/* 对话：预置问题 2×2 */
.chat-presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--glass-border);
}
.chat-presets button {
  background: var(--surface-2); border: 1px solid var(--glass-border); color: var(--text-dim);
  border-radius: 8px; padding: 8px 6px; font-size: 11px; cursor: pointer;
  text-align: center; line-height: 1.35;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-presets button:hover { color: var(--accent); border-color: var(--accent); }
.chat-messages { display: flex; flex-direction: column; gap: 8px; }
.chat-msg { max-width: 95%; padding: 8px 11px; border-radius: 10px; font-size: 13px; line-height: 1.65; word-break: break-word; }
.chat-msg.user { align-self: flex-end; background: var(--msg-user-bg); color: var(--text); }
.chat-msg.assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--glass-border); color: var(--text); }
.chat-msg ul, .ai-brief ul { margin: 4px 0 4px 18px; }
.md-h { font-weight: 700; color: var(--accent); margin: 6px 0 2px; }
.md-gap { height: 6px; }
.chat-input-row {
  display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--glass-border); flex-shrink: 0;
}
#chat-input {
  flex: 1; background: var(--panel-input-bg); border: 1px solid var(--glass-border); color: var(--text);
  border-radius: 8px; padding: 9px 12px; font-size: 13px; outline: none;
}
#chat-input:focus { border-color: var(--accent); }
#chat-send, #cfg-save {
  background: var(--accent); color: var(--send-fg); font-weight: 700; border: none;
  border-radius: 8px; padding: 9px 16px; cursor: pointer; font-size: 13px;
}
#chat-send:disabled { opacity: 0.5; cursor: wait; }

.settings-body label { display: block; font-size: 12px; color: var(--text-dim); margin: 12px 0 4px; }
.settings-body input {
  display: block; width: 100%;
  background: var(--panel-input-bg); border: 1px solid var(--glass-border); color: var(--text);
  border-radius: 6px; padding: 8px 10px; font-size: 13px;
}
.modal-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 14px; }
#cfg-status { font-size: 12px; color: var(--text-dim); }
.modal-note { font-size: 11px; color: var(--text-dim); margin-top: 14px; line-height: 1.6; }

/* 图例：固定在左侧轨正下方窄条，不随面板开合移动，互不挤占 */
.map-legend {
  position: fixed;
  bottom: 14px;
  left: 12px;
  width: var(--rail-w);
  z-index: 26;
  border-radius: 12px;
  padding: 8px 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  box-shadow: 0 6px 20px var(--shadow);
  cursor: pointer;
  border: 1px solid var(--glass-border);
  color: inherit;
  font: inherit;
  text-align: center;
  box-sizing: border-box;
}
.map-legend:hover { border-color: var(--accent); }
.legend-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 100%;
}
.legend-title {
  color: var(--text-dim);
  font-size: 9px;
  letter-spacing: 0.5px;
  line-height: 1.2;
  margin: 0;
}
.legend-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--text);
  font-size: 9px;
  line-height: 1.1;
}
.lg-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.pager {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 8px 12px 12px; border-top: 1px solid var(--glass-border);
  font-size: 11px; color: var(--text-dim); flex-shrink: 0;
}
.pager button {
  border: 1px solid var(--glass-border);
  background: transparent; color: var(--text);
  border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 11px;
}
.pager button:disabled { opacity: 0.4; cursor: default; }
.pager button:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }

#detail-back:not(.hidden) { display: inline-flex; }

/* 地图标记：城市名 + 风险分，不再是大数字堆 */
.risk-pin {
  display: flex; flex-direction: column; align-items: center;
  transform: translateY(-4px); cursor: pointer; pointer-events: auto;
}
.risk-pin-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 12px var(--pin-glow, transparent), 0 2px 6px rgba(0, 0, 0, 0.5);
}
.risk-pin.country .risk-pin-dot {
  width: 22px; height: 22px; border-width: 2.5px;
}
.risk-pin-label {
  margin-top: 4px; padding: 2px 7px; border-radius: 6px;
  background: rgba(4, 22, 48, 0.92); border: 1px solid rgba(61, 224, 255, 0.22);
  white-space: nowrap; line-height: 1.25; text-align: center;
  box-shadow: 0 4px 14px rgba(0, 20, 40, 0.45);
  pointer-events: none;
}
.risk-pin-label .name { display: block; font-size: 12px; font-weight: 650; color: #f0f6ff; }
.risk-pin-label .meta { display: block; font-size: 10px; color: var(--pin-color, var(--accent)); font-variant-numeric: tabular-nums; }
.risk-pin.active .risk-pin-dot { transform: scale(1.25); }
.risk-pin.active .risk-pin-label { border-color: var(--accent); }

.country-label {
  padding: 3px 9px; border-radius: 6px;
  background: rgba(4, 24, 52, 0.72); border: 1px solid rgba(61, 224, 255, 0.22);
  color: rgba(180, 230, 255, 0.78); font-size: 11px; font-weight: 600;
  letter-spacing: 1.2px; pointer-events: none; white-space: nowrap;
  text-shadow: 0 0 12px rgba(61, 224, 255, 0.25);
}

.maplibregl-canvas { outline: none; }
#map .maplibregl-ctrl-bottom-right { bottom: 52px; right: 12px; }

::-webkit-scrollbar { width: 7px; }
::-webkit-scrollbar-thumb { background: rgba(80, 120, 180, 0.35); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 960px) {
  #topbar { left: 12px; right: 12px; transform: none; max-width: none; gap: 12px; overflow-x: auto; }
  .topbar-stats { display: none; }
  .float-panel { width: min(var(--panel-w), calc(100vw - 88px)); }
}

.city-crosshair { display: none !important; }

/* 悬停提示 */
.map-hover-tip {
  position: fixed; z-index: 40; pointer-events: none;
  max-width: 240px; padding: 8px 10px; border-radius: 8px;
  background: rgba(4, 18, 36, 0.92); border: 1px solid rgba(160, 210, 255, 0.35);
  box-shadow: 0 8px 24px rgba(0,0,0,0.45); color: #e8f4ff; font-size: 12px; line-height: 1.4;
}
.map-hover-tip .tip-title { font-weight: 700; font-size: 13px; margin-bottom: 2px; }
.map-hover-tip .tip-sub { color: #9ec8e0; font-size: 11px; }
.map-hover-tip .tip-cities { margin-top: 4px; color: #d8ecff; }
.map-hover-tip .tip-risk { margin-top: 4px; font-variant-numeric: tabular-nums; font-weight: 650; }
.map-hover-tip .tip-muted { color: #7a90ad; font-size: 11px; margin-top: 3px; }

/* 名称标签：圆点由 MapLibre circle 矢量层绘制，这里只挂中文名 */
.risk-name-label {
  padding: 1px 6px; border-radius: 4px;
  background: rgba(8, 22, 40, 0.82); border: 1px solid rgba(255,255,255,0.16);
  color: #f2f7ff; font-size: 11px; font-weight: 650; line-height: 1.3;
  white-space: nowrap; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.28);
  pointer-events: auto;
}
.risk-name-label.active {
  border-color: rgba(255, 220, 120, 0.65);
}
.risk-name-label.is-hidden { visibility: hidden !important; opacity: 0 !important; }

.risk-dot-marker, .country-flag-marker, .city-pin { display: none !important; }
