/* ============================================================
   防災COP — スタイル
   ダーク（オペレーションルーム）基調。配色トークンは dataviz
   スキルの検証済みダークパレットに準拠。
   警報・危険度の色だけは気象庁公式配色（意味の互換性を優先）。
   ============================================================ */
:root {
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222220;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --blue: #3987e5;
  --aqua: #199e70;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  /* 気象庁公式配色（警報レベル） */
  --jma-advisory: #f2e700;   /* 注意報 */
  --jma-warning: #ff2800;    /* 警報 */
  --jma-emergency: #aa00aa;  /* 特別警報 */
}

* { box-sizing: border-box; }
html, body { height: 100%; }
/* 横スクロールを絶対に発生させない（スマホで地図やヘッダーがはみ出さないため） */
html, body { max-width: 100%; overflow-x: hidden; }
main, #map, #panels, header, footer { max-width: 100%; min-width: 0; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* ---------- ヘッダー ---------- */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
header h1 {
  font-size: 16px;
  margin: 0;
  letter-spacing: 0.06em;
  white-space: nowrap;
  flex-shrink: 0;
}
header h1 .sub { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 8px; }
#cop-level {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.1em;
  border: 1px solid var(--border);
  white-space: nowrap;
}
/* 警戒レベル相当の公式配色（内閣府ガイドライン: 2=黄 3=赤 4=紫 5=黒） */
#cop-level.lv1 { background: rgba(12,163,12,0.15); color: var(--status-good); }
#cop-level.lv2 { background: #f2e700; color: #1a1a00; }
#cop-level.lv3 { background: #ff2800; color: #fff; }
#cop-level.lv4 { background: #aa00aa; color: #fff; }
#cop-level.lv5 { background: #0c000c; color: #fff; border-color: #ff2800; }
#btn-about {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  padding: 3px 10px;
  cursor: pointer;
  white-space: nowrap;
}
#btn-about:hover { color: var(--ink); border-color: var(--muted); }
#clock {
  margin-left: auto;
  text-align: right;
  font-variant-numeric: tabular-nums;
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
}
#clock .dtg { font-weight: 700; letter-spacing: 0.08em; }
#clock .jst { color: var(--muted); font-size: 12px; }

/* ---------- レイアウト ---------- */
main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  height: calc(100vh - 57px - 34px);
}
#map { height: 100%; background: #0d0d0d; }
#panels {
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-left: 1px solid var(--border);
}
@media (max-width: 900px) {
  main { grid-template-columns: 1fr; height: auto; }
  #map { height: 55vh; }
  #panels { border-left: none; }
}

/* 狭い画面（スマホ）: ヘッダーが溢れないよう情報量を絞る */
@media (max-width: 700px) {
  header { padding: 8px 10px; gap: 8px; }
  header h1 { font-size: 15px; }
  header h1 .sub { display: none; }        /* 副題は畳む（タイトルで自明なため） */
  #cop-level { font-size: 13px; padding: 4px 10px; }
  #btn-about { font-size: 0; padding: 5px 9px; }  /* ⓘ アイコンのみ表示 */
  #btn-about::before { content: "ⓘ"; font-size: 14px; }
  #clock .dtg { font-size: 12px; }
  #clock .jst { font-size: 10px; }
}
/* 特に狭い端末: 日時本体だけ残し、「日本時間」のラベルは畳む */
@media (max-width: 420px) {
  #clock .jst { display: none; }
}

/* ---------- パネル共通 ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.panel h2 {
  font-size: 12px;
  margin: 0 0 8px;
  color: var(--ink-2);
  letter-spacing: 0.12em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.panel h2 .upd {
  margin-left: auto;
  font-weight: 400;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.ok { background: var(--status-good); }
.dot.stale { background: var(--status-warning); }
.dot.err { background: var(--status-critical); }

/* ---------- 状況判断: 警戒レベルバナー ---------- */
.judge-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
}
.judge-banner .num {
  font-size: 36px;
  font-weight: 800;
  line-height: 1;
  width: 44px;
  text-align: center;
  flex: none;
}
.judge-banner .lbl { font-weight: 700; font-size: 15px; letter-spacing: 0.08em; }
.judge-banner .act { font-size: 13px; margin-top: 2px; }
.judge-banner.b1 { background: rgba(12, 163, 12, 0.10); color: var(--status-good); }
.judge-banner.b2 { background: #f2e700; color: #1a1a00; }
.judge-banner.b3 { background: #ff2800; color: #fff; }
.judge-banner.b4 { background: #aa00aa; color: #fff; }
.judge-banner.b5 { background: #0c000c; color: #fff; border: 2px solid #ff2800; }
.judge-banner.b3 { animation: cop-pulse 2s ease-in-out infinite; }
.judge-banner.b4, .judge-banner.b5 { animation: cop-pulse 1.2s ease-in-out infinite; }
@keyframes cop-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 40, 0, 0.65); }
  50% { box-shadow: 0 0 0 9px rgba(255, 40, 0, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .judge-banner { animation: none !important; }
}

/* ---------- 状況判断 ---------- */
#judge-reasons { margin: 0; padding: 0; list-style: none; }
#judge-reasons li {
  padding: 3px 0;
  border-bottom: 1px solid var(--grid);
  display: flex;
  gap: 8px;
  align-items: baseline;
}
#judge-reasons li:last-child { border-bottom: none; }
#judge-reasons .tag {
  flex: none;
  font-size: 11px;
  color: var(--muted);
  width: 44px;
}

/* ---------- パネル折りたたみ（詳細情報。既定は非表示） ---------- */
.collapsible .panel-body { display: none; }
.collapsible.expanded .panel-body { display: block; }
.panel-toggle {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  padding: 0 0 0 8px;
  flex: none;
}
.panel-toggle:hover { color: var(--ink-2); }

/* ---------- パネル優先表示（NERV式） ---------- */
.panel.promoted { border-left: 3px solid var(--status-warning); }
.prio-chip {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--status-warning);
  border: 1px solid var(--status-warning);
  border-radius: 3px;
  padding: 0 5px;
}

/* ---------- 警報連動の避難所サジェスト（Yahoo式） ---------- */
#shelter-suggest { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
#shelter-suggest:not(:empty) { margin-bottom: 8px; }
.suggest-label { font-size: 11px; color: var(--status-warning); }
.suggest-chip {
  background: rgba(250, 178, 25, 0.12);
  color: var(--status-warning);
  border: 1px solid var(--status-warning);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 11px;
  cursor: pointer;
}
.suggest-chip:hover { background: rgba(250, 178, 25, 0.25); }

/* ---------- 現在地レポート一文要約 ---------- */
.loc-verdict {
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 8px;
  font-size: 13px;
  line-height: 1.6;
  border: 1px solid var(--border);
}
.loc-verdict.v-safe { background: rgba(12,163,12,0.10); }
.loc-verdict.v-info { background: rgba(57,135,229,0.12); }
.loc-verdict.v-caution { background: rgba(250,178,25,0.12); border-color: var(--status-warning); }
.loc-verdict.v-danger { background: rgba(208,59,59,0.16); border-color: var(--status-critical); }
.loc-verdict b { color: var(--ink); }

/* ---------- 現在地の状況 ---------- */
.loc-buttons { display: flex; gap: 6px; margin-bottom: 8px; }
.loc-buttons button {
  flex: 1;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  cursor: pointer;
}
.loc-buttons button:hover { border-color: var(--blue); }
.loc-buttons button.active { border-color: var(--blue); color: var(--blue); }
.loc-hint { color: var(--muted); font-size: 12px; }
.loc-summary {
  background: var(--surface-2);
  border-radius: 6px;
  padding: 6px 8px;
  margin-bottom: 8px;
  font-size: 12px;
}
.loc-summary .place { color: var(--ink-2); }
.loc-summary .elev { font-weight: 700; }
.hz-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid var(--grid);
  font-size: 12px;
}
.hz-row:last-child { border-bottom: none; }
.hz-row .hz-name { flex: none; width: 108px; color: var(--ink-2); }
.hz-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 4px;
}
.hz-badge.safe { background: var(--surface-2); color: var(--muted); font-weight: 400; }
.hz-badge.info { background: rgba(57,135,229,0.2); color: #86b6ef; }
.hz-badge.caution { background: var(--jma-advisory); color: #1a1a00; }
.hz-badge.danger { background: var(--jma-warning); color: #fff; }
.hz-badge.extreme { background: var(--jma-emergency); color: #fff; }
.hz-badge.unknown { background: var(--surface-2); color: var(--muted); font-weight: 400; }
.loc-sec { color: var(--muted); font-size: 11px; letter-spacing: 0.1em; margin: 8px 0 2px; }
.near-row {
  display: flex;
  gap: 8px;
  padding: 4px 2px;
  border-bottom: 1px solid var(--grid);
  cursor: pointer;
  font-size: 12px;
  align-items: baseline;
}
.near-row:hover { background: var(--surface-2); }
.near-row:last-child { border-bottom: none; }
.near-row .dist { flex: none; width: 56px; font-variant-numeric: tabular-nums; color: var(--aqua); font-weight: 700; }
.near-row .ad { color: var(--muted); font-size: 11px; }

/* ---------- 警報・注意報 ---------- */
.warn-row { display: flex; align-items: flex-start; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--grid); }
.warn-row:last-child { border-bottom: none; }
.warn-row .muni { flex: none; width: 108px; color: var(--ink-2); }
.warn-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 4px;
}
.chip.none { background: var(--surface-2); color: var(--muted); font-weight: 400; }
.chip.advisory { background: var(--jma-advisory); color: #1a1a00; }
.chip.warning { background: var(--jma-warning); color: #fff; }
.chip.emergency { background: var(--jma-emergency); color: #fff; }
.headline { color: var(--muted); font-size: 12px; margin-top: 6px; }

/* ---------- アメダス ---------- */
.obs-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.obs-tile { background: var(--surface-2); border-radius: 6px; padding: 8px; }
.obs-tile .name { color: var(--ink-2); font-size: 12px; margin-bottom: 4px; }
.obs-tile .temp { font-size: 22px; font-weight: 700; }
.obs-tile .temp .unit { font-size: 12px; color: var(--muted); font-weight: 400; }
.obs-tile .row { font-size: 12px; color: var(--ink-2); display: flex; justify-content: space-between; }
.obs-tile .row .v { font-variant-numeric: tabular-nums; }
.obs-tile .rain-warn { color: var(--status-warning); font-weight: 700; }

/* ---------- 予報 ---------- */
.fc-days { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.fc-day { background: var(--surface-2); border-radius: 6px; padding: 8px; }
.fc-day .d { color: var(--muted); font-size: 11px; }
.fc-day .wx { font-size: 13px; margin: 2px 0; min-height: 2.8em; }
.fc-day .tt { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.fc-day .tt .max { color: var(--status-serious); font-weight: 700; }
.fc-day .tt .min { color: var(--blue); font-weight: 700; }
.pops { display: flex; gap: 4px; align-items: flex-end; }
.pop { flex: 1; text-align: center; font-size: 10px; color: var(--muted); }
.pop .bar-wrap { height: 36px; display: flex; align-items: flex-end; justify-content: center; }
.pop .bar { width: 70%; background: var(--blue); border-radius: 3px 3px 0 0; min-height: 2px; }
.pop .val { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: 11px; }

/* ---------- 地震 ---------- */
.quake-row { display: flex; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--grid); font-size: 12px; align-items: center; }
.quake-row:last-child { border-bottom: none; }
.quake-row .int {
  flex: none; width: 34px; height: 24px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; background: var(--surface-2); color: var(--ink-2);
}
.quake-row .int.i3 { background: var(--jma-advisory); color: #1a1a00; }
.quake-row .int.i4 { background: #ff9900; color: #1a1a00; }
.quake-row .int.i5 { background: var(--jma-warning); color: #fff; }
.quake-row .int.i6 { background: var(--jma-emergency); color: #fff; }
.quake-row .meta { color: var(--muted); }
.quake-row.near { outline: 1px solid var(--status-warning); outline-offset: -1px; border-radius: 4px; }

/* ---------- 避難所 ---------- */
.shelter-controls { display: flex; gap: 6px; margin-bottom: 8px; }
.shelter-controls input, .shelter-controls select {
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  min-width: 0;
}
.shelter-controls input { flex: 1; }
#shelter-list { max-height: 260px; overflow-y: auto; }
.shelter-row { padding: 4px 2px; border-bottom: 1px solid var(--grid); cursor: pointer; font-size: 12px; }
.shelter-row:hover { background: var(--surface-2); }
.shelter-row .nm { color: var(--ink); }
.shelter-row .ad { color: var(--muted); font-size: 11px; }
.shelter-row .kd { font-size: 10px; padding: 0 5px; border-radius: 3px; margin-right: 4px; }
.shelter-row .kd.em { background: rgba(25,158,112,0.25); color: #4cd7a4; }
.shelter-row .kd.sh { background: rgba(57,135,229,0.25); color: #86b6ef; }
.shelter-row .dist { float: right; font-variant-numeric: tabular-nums; color: var(--aqua); font-weight: 700; font-size: 11px; }
.shelter-count { color: var(--muted); font-size: 11px; margin-bottom: 4px; }

/* ---------- 凡例（地図内） ---------- */
.legend {
  background: rgba(26, 26, 25, 0.92);
  color: var(--ink-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.7;
  max-width: 60vw;
}
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 5px; }
.legend-toggle {
  display: none;              /* 広い画面では常時展開なのでボタン自体を出さない */
  width: 100%;
  background: none;
  border: none;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  padding: 7px 12px;
  cursor: pointer;
  text-align: left;
}
.legend-toggle .caret {
  float: right;
  margin-left: 8px;
  border: 4px solid transparent;
  border-top-color: currentColor;
  margin-top: 7px;
}
.legend.collapsed .legend-toggle .caret { border-top-color: transparent; border-bottom-color: currentColor; margin-top: 3px; }
.legend-body { padding: 6px 10px; }
.legend.collapsed .legend-body { display: none; }

/* 狭い画面（スマホ）: 凡例は畳んでボタン表示にし、地図を隠さない */
@media (max-width: 700px) {
  .legend-toggle { display: block; }
  .legend { max-width: 78vw; }
  .legend.collapsed { background: rgba(26, 26, 25, 0.95); }
  /* Leafletのレイヤー切替ボタンをタップしやすい大きさに */
  .leaflet-control-layers-toggle { width: 42px !important; height: 42px !important; background-size: 24px 24px !important; }
  .leaflet-control-layers-expanded { max-height: 62vh; overflow-y: auto; max-width: 78vw; }
  .leaflet-touch .leaflet-bar a { width: 34px; height: 34px; line-height: 34px; }
}

/* ---------- フッター ---------- */
footer {
  height: 34px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  font-size: 11px;
  color: var(--muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
  overflow: hidden;
  white-space: nowrap;
}
footer a { color: var(--muted); }
footer .disclaimer { color: var(--status-warning); }

/* ---------- パネル内注記・WBGT ---------- */
.panel-note {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
  margin-top: 8px;
  border-top: 1px solid var(--grid);
  padding-top: 6px;
}
.panel-note a { color: var(--ink-2); }
.wbgt-chip {
  display: inline-block;
  padding: 0 6px;
  border-radius: 4px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- このサイトについて（モーダル） ---------- */
#about-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#about-overlay[hidden] { display: none; }
#about-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 620px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 18px 22px;
  font-size: 13px;
  line-height: 1.7;
}
#about-modal h3 {
  margin: 0 0 10px;
  font-size: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#about-modal h4 {
  margin: 14px 0 4px;
  font-size: 12px;
  color: var(--ink-2);
  letter-spacing: 0.1em;
  border-bottom: 1px solid var(--grid);
  padding-bottom: 3px;
}
#about-modal p, #about-modal ul { margin: 4px 0; color: var(--ink-2); }
#about-modal ul { padding-left: 18px; }
#about-modal li { margin: 3px 0; }
#about-modal b { color: var(--ink); }
#about-modal a { color: #86b6ef; }
#about-modal table { border-collapse: collapse; width: 100%; font-size: 12px; }
#about-modal td { border-bottom: 1px solid var(--grid); padding: 3px 8px 3px 0; color: var(--ink-2); vertical-align: top; }
#about-close {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 10px;
  font-size: 13px;
}
#about-close:hover { color: var(--ink); }

/* ---------- Leaflet ダーク調整 ---------- */
.leaflet-container { font: inherit; }
.leaflet-control-layers, .leaflet-control-zoom a {
  background: var(--surface) !important;
  color: var(--ink) !important;
  border-color: var(--border) !important;
}
.leaflet-control-layers-expanded { color: var(--ink); padding: 8px 12px; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--surface);
  color: var(--ink);
}
.leaflet-popup-content { margin: 10px 14px; font-size: 12px; }
.popup-hazards { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 3px; }
.popup-hazards span {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 5px;
  font-size: 10px;
  color: var(--ink-2);
}
.leaflet-bar a { border-bottom-color: var(--border) !important; }
