:root {
  --bg: #0d0f14;
  --panel: #161a23;
  --panel-2: #1d222e;
  --border: #2a3140;
  --text: #e6e9ef;
  --muted: #9aa4b6;
  --accent: #4ade80;

  --c-accident: #ef4444;
  --c-manufacturing: #a855f7;
  --c-distribution: #f59e0b;
  --c-possession: #38bdf8;
  --c-seizure: #14b8a6;

  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Noto Sans TC", "Hiragino Sans", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
#sidebar {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.brand {
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #1a1f2b, var(--panel));
}
.brand h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: 0.3px;
}
.subtitle {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}
.topnav { display: flex; gap: 8px; margin-top: 12px; }
.navlink {
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  transition: all 0.15s ease;
}
.navlink:hover { color: var(--text); border-color: var(--muted); }
.navlink.active { color: var(--text); background: var(--panel-2); border-color: var(--accent); }

/* Stats */
.stats-block { padding: 16px 20px 6px; }
.stats-period {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.2px;
}
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.stat-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.stat-value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.1;
}
.stat-label {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 4px;
}
.stat-card.accent .stat-value { color: var(--c-accident); }
.stat-card.warn .stat-value { color: var(--c-manufacturing); }

/* Layers */
.layers {
  padding: 4px 20px 16px;
}
.layers .filter-label { margin-bottom: 8px; }
.layer-note {
  margin: 10px 0 0;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

/* Filters */
.filters {
  padding: 6px 20px 18px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.filter-group { margin-top: 14px; }
.filter-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 7px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}
.chip .dot {
  width: 9px; height: 9px; border-radius: 50%;
  display: inline-block;
}
.chip.active {
  color: var(--text);
  border-color: transparent;
  background: var(--panel);
  box-shadow: inset 0 0 0 1.5px currentColor;
}
.chip:hover { color: var(--text); }

select, input[type="search"], input[type="date"] {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 13px;
  font-family: inherit;
}
select:focus, input:focus { outline: none; border-color: var(--accent); }

.date-inputs { display: flex; align-items: center; gap: 8px; }
.date-inputs input { flex: 1; }
.dash { color: var(--muted); }

.reset-btn {
  margin-top: 16px;
  width: 100%;
  padding: 9px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  font-size: 12.5px;
  font-family: inherit;
}
.reset-btn:hover { color: var(--text); border-color: var(--muted); }

/* Incident list */
.incident-list { padding: 14px 20px; flex: 1; }
.list-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.list-header h2 { font-size: 14px; margin: 0; }
.result-count { font-size: 12px; color: var(--muted); }
.list-period { margin: 0 0 10px; font-size: 11.5px; color: var(--accent); font-weight: 600; }
#incident-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.incident-item {
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel-2);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
.incident-item:hover { background: #232a39; }
.incident-item:active { transform: scale(0.995); }
.ii-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.ii-type {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
  color: #0d0f14;
}
.ii-date { font-size: 11px; color: var(--muted); }
.ii-place { font-size: 13px; font-weight: 600; }
.ii-summary {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ii-badges { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
  font-size: 10.5px;
  padding: 1px 7px;
  border-radius: 5px;
  background: rgba(255,255,255,0.06);
  color: var(--muted);
}
.badge.death { background: rgba(239,68,68,0.15); color: #fca5a5; }
.badge.injury { background: rgba(245,158,11,0.15); color: #fcd34d; }

.sidebar-footer {
  padding: 14px 20px 20px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}
.sidebar-footer p { margin: 0 0 6px; }
.sidebar-footer a { color: var(--accent); text-decoration: none; }
.sidebar-footer a:hover { text-decoration: underline; }
.seo-intro { color: #aab3c5; }
.seo-intro strong { color: var(--text); }
.disclaimer { color: #6b7384; }

/* ---------- Map ---------- */
#map-wrap { position: relative; }
#map { height: 100%; width: 100%; background: #0a0c10; z-index: 1; }

.legend {
  position: absolute;
  bottom: 22px;
  right: 16px;
  z-index: 500;
  background: rgba(22, 26, 35, 0.92);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}
.legend h3 { margin: 0 0 8px; font-size: 12px; color: var(--muted); font-weight: 600; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-top: 6px; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; }

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 15, 20, 0.85);
  z-index: 600;
  font-size: 14px;
  color: var(--muted);
}
.loading.hidden { display: none; }

/* Map markers */
.pin {
  width: 18px; height: 18px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid rgba(255,255,255,0.85);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.3);
}

/* Leaflet popup theming */
.leaflet-popup-content-wrapper {
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  border: 1px solid var(--border);
}
.leaflet-popup-tip { background: var(--panel); border: 1px solid var(--border); }
.leaflet-popup-content { margin: 14px 16px; font-size: 13px; line-height: 1.55; }
.popup-type {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 5px;
  color: #0d0f14;
  margin-bottom: 8px;
}
.popup-title { font-size: 14px; font-weight: 700; margin: 0 0 2px; }
.popup-meta { font-size: 11.5px; color: var(--muted); margin-bottom: 8px; }
.popup-summary { color: #cdd3df; }
.popup-note {
  margin-top: 8px; font-size: 11px; line-height: 1.5; color: var(--muted);
  background: rgba(251, 146, 60, 0.10);
  border-left: 3px solid #fb923c;
  padding: 6px 8px; border-radius: 4px;
}
.popup-stats { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.popup-quantity {
  margin-top: 8px; font-size: 11.5px; color: var(--muted);
  border-top: 1px dashed var(--border); padding-top: 8px;
}
.popup-source a { color: var(--accent); text-decoration: none; font-size: 12px; }
.popup-source a:hover { text-decoration: underline; }

/* County aggregate labels */
.county-label {
  background: transparent;
  border: none;
  box-shadow: none;
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
}
.county-label::before { display: none; }

/* Cluster color tweak */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large { background: rgba(74, 222, 128, 0.25); }
.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div { background: rgba(74, 222, 128, 0.7); color: #07120b; font-weight: 700; }

/* ---------- About / sources page ---------- */
.page { min-height: 100vh; overflow-y: auto; display: block; }
.page-wrap { max-width: 860px; margin: 0 auto; padding: 40px 24px 80px; }
.page-wrap h1 { font-size: 26px; margin: 0 0 6px; }
.page-wrap .lead { color: var(--muted); margin: 0 0 8px; font-size: 14px; line-height: 1.6; }
.page-wrap .topnav { margin: 18px 0 28px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px 24px;
  margin-bottom: 18px;
}
.card h2 { font-size: 17px; margin: 0 0 12px; display: flex; align-items: center; gap: 9px; }
.card h2 .tag { font-size: 11px; padding: 2px 8px; border-radius: 6px; color: #0d0f14; font-weight: 700; }
.card h3 { font-size: 14px; margin: 16px 0 6px; }
.card p, .card li { font-size: 13.5px; line-height: 1.7; color: #cdd3df; }
.card a { color: var(--accent); text-decoration: none; }
.card a:hover { text-decoration: underline; }
.card ul { margin: 8px 0; padding-left: 20px; }
.card .muted { color: var(--muted); font-size: 12.5px; }
.callout {
  border-left: 3px solid #f59e0b;
  background: rgba(245, 158, 11, 0.08);
  padding: 14px 18px;
  border-radius: 0 10px 10px 0;
}
.callout.ai { border-left-color: var(--accent); background: rgba(74, 222, 128, 0.08); }
.src-table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 13px; }
.src-table th, .src-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.src-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.dot-inline { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; vertical-align: middle; }
.page-credit {
  text-align: center;
  margin: 28px 0 0;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.page-credit a { color: var(--accent); text-decoration: none; }
.page-credit a:hover { text-decoration: underline; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 46vh 54vh; }
  #sidebar { border-right: none; border-bottom: 1px solid var(--border); }
}
