:root {
  --bg: #0d0f14;
  --panel: #161a23;
  --panel-2: #1d222e;
  --border: #2a3140;
  --text: #e6e9ef;
  --muted: #9aa4b6;
  --accent: #3b82f6;
  --c-a1: #dc2626;
  --c-a2: #f97316;
  --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: 400px 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Grid 子要素で Leaflet タイルがズーム時に欠けるのを防ぐ */
#map-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#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, #1a2030, 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;
}
.subtitle strong { color: var(--text); }
.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-block { padding: 16px 20px 6px; }
.stats-period {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
}
.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: 20px; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: 11px; color: var(--muted); margin-top: 4px; }
.stat-card.accent .stat-value { color: var(--c-a1); }
.stat-card.warn .stat-value { color: var(--c-a2); }

.layers { padding: 4px 20px 12px; }
.layer-note {
  margin: 10px 0 0;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

.hour-section {
  padding: 0 20px 16px;
  border-bottom: 1px solid var(--border);
}
.hour-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 72px;
  margin-top: 6px;
}
.hour-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}
.hour-col.dim { opacity: 0.35; }
.hour-bars {
  display: flex;
  align-items: flex-end;
  gap: 1px;
  height: 56px;
  width: 100%;
}
.hour-bars .bar {
  flex: 1;
  min-height: 2px;
  border-radius: 2px 2px 0 0;
}
.hour-bars .bar.a1 { background: var(--c-a1); opacity: 0.85; }
.hour-bars .bar.a2 { background: var(--c-a2); opacity: 0.7; }
.hour-lbl { font-size: 9px; color: var(--muted); margin-top: 2px; }

.filters {
  padding: 6px 20px 18px;
  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;
}
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.cause-chips .chip { font-size: 11px; max-width: 100%; }
.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%; }
.chip.active {
  color: var(--text);
  border-color: transparent;
  background: var(--panel);
  box-shadow: inset 0 0 0 1.5px var(--accent);
}
.chip:hover { color: var(--text); }
#time-filters .chip { color: #7dd3fc; }
#time-filters .chip.active { color: #38bdf8; box-shadow: inset 0 0 0 1.5px #38bdf8; }

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 { 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;
}
.incident-item:hover { background: #232a39; }
.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(220,38,38,0.15); color: #fca5a5; }
.badge.injury { background: rgba(249,115,22,0.15); color: #fdba74; }

.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; }
.seo-intro strong { color: var(--text); }
.disclaimer { color: #6b7384; }

#map {
  height: 100%;
  width: 100%;
  background: #0a0c10;
}

.leaflet-container {
  background: #1a1f2e;
  font-family: inherit;
}

/* OSM タイルをやや暗めに（欠損タイルの黒穴を減らすため CARTO から OSM に変更） */
.leaflet-tile-pane img {
  filter: brightness(0.72) contrast(1.08) saturate(0.85);
}

.a2-tip {
  background: rgba(22, 26, 35, 0.92);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
}
.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; }

.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-content-wrapper {
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  border: 1px solid var(--border);
}
.leaflet-popup-tip { background: var(--panel); }
.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-stats { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.popup-source a { color: var(--accent); text-decoration: none; font-size: 12px; }

.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; }

.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large { background: rgba(59, 130, 246, 0.25); }
.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div { background: rgba(59, 130, 246, 0.75); color: #0c1425; font-weight: 700; }

.page { min-height: 100vh; overflow-y: auto; }
.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; }
.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; }
.callout {
  border-left: 3px solid #f59e0b;
  background: rgba(245, 158, 11, 0.08);
  padding: 14px 18px;
  border-radius: 0 10px 10px 0;
  margin: 12px 0;
}
.callout.ai { border-left-color: var(--accent); background: rgba(59, 130, 246, 0.08); }
.card .tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  color: #0d0f14;
  font-weight: 700;
  margin-right: 6px;
}
.card .muted { color: var(--muted); font-size: 12.5px; }
.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; }

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 48vh 52vh; }
  #sidebar { border-right: none; border-bottom: 1px solid var(--border); min-height: 0; }
  #map-wrap { min-height: 0; }
}
