/* インフルエンザ定点報告モニター
   配色はデジタル庁デザインシステム（Blueキーパレット + セマンティックカラー）に準拠。
   グラフ色面は背景に対して3:1以上、テキストは4.5:1以上を確保する。 */

:root {
  color-scheme: light;

  --bg: #f8f8fb;
  --surface: #ffffff;
  --surface-alt: #f1f1f4;
  --border: #d9d9de;
  --border-strong: #b7b7bf;

  --text: #17171a;
  --text-muted: #5b5b63;
  --text-faint: #767676;

  --primary: #0017c1;      /* Blue 900  — 主要系列・リンク */
  --primary-mid: #3460fb;  /* Blue 600  — 副系列 */
  --primary-soft: #7096f8; /* Blue 400 */
  --primary-pale: #d9e6ff; /* Blue 50   — 強調背景 */

  --negative: #ce0000;     /* Red 900   — 悪化・警報 */
  --negative-mid: #fe3939; /* Red 600 */
  --negative-pale: #fdeeee;
  --positive: #0d5c8a;     /* 低下（好転）は赤緑を避けて濃い青系 */
  --positive-pale: #e8f1fe;
  --attention: #ac3e00;    /* Orange 900 — 流行開始の目安 */
  --attention-mid: #fb5b01;
  --attention-pale: #ffeee2;

  --grid: #cccccc;
  --neutral: #999999;

  /* 検出ウイルスの型・亜型（A=寒色 / B=暖色 / C=紫）。
     いずれも背景に対して3:1以上。隣り合う色は明度が近いので、
     積み上げの境目は背景色の細い線で割り、凡例と表で名前と数値も併記する。 */
  --virus-a_h1pdm09: #0017c1;
  --virus-a_h1_seasonal: #5b6fd8;
  --virus-a_h3:      #0086b3;
  --virus-a_nt:      #7e8aa3;
  --virus-b_victoria:#c43c00;
  --virus-b_yamagata:#8a6300;
  --virus-b_nt:      #a87c4e;
  --virus-c:         #6a2a9e;

  /* 学校の休業措置。重い順に濃くする（休校 > 学年閉鎖 > 学級閉鎖）。 */
  --school-closed:       #7a1f6e;
  --school-grade_closed: #b8560b;
  --school-class_closed: #3f7fa6;

  /* 地図の塗り分け（0 → 警報レベル）。灰 → 青 → 橙 → 赤の段階色 */
  --scale-0: #eceef2;
  --scale-1: #c5d7fb;
  --scale-2: #ffc199;
  --scale-3: #fb5b01;
  --scale-4: #ce0000;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 1px 8px rgba(0, 0, 0, .04);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI",
          "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #14161a;
    --surface: #1c1f25;
    --surface-alt: #23272e;
    --border: #343943;
    --border-strong: #4a505c;
    --text: #f2f3f5;
    --text-muted: #b3b8c2;
    --text-faint: #8b919c;
    --primary: #93b0ff;
    --primary-mid: #7096f8;
    --primary-soft: #4b74e8;
    --primary-pale: #1d2740;
    --negative: #ff8a8a;
    --negative-mid: #ff5c5c;
    --negative-pale: #3a1d1d;
    --positive: #7ec6f0;
    --positive-pale: #16303f;
    --attention: #ffab6b;
    --attention-mid: #ff8d44;
    --attention-pale: #3a2415;
    --grid: #3d434d;
    --neutral: #8b919c;
    --virus-a_h1pdm09: #8fa9ff;
    --virus-a_h1_seasonal: #6f81c9;
    --virus-a_h3:      #39c2e8;
    --virus-a_nt:      #9ba7c0;
    --virus-b_victoria:#ff8a4c;
    --virus-b_yamagata:#e0b44a;
    --virus-b_nt:      #c9a183;
    --virus-c:         #c79bee;
    --school-closed:       #e79ad8;
    --school-grade_closed: #ffa863;
    --school-class_closed: #7cc3e6;
    --scale-0: #2b303a;
    --scale-1: #2f4a86;
    --scale-2: #8a5024;
    --scale-3: #d1590a;
    --scale-4: #ff5c5c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }

/* class側で display を指定すると、UAスタイルの [hidden]{display:none} に勝ってしまう
   （.split の #virus-section、.tag-provisional の暫定タグが該当した）。
   hidden 属性は常に効かせる。 */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.35; margin: 0; font-weight: 700; }
p { margin: 0; }
a { color: var(--primary); }
a:hover { text-decoration: none; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 20px; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 20;
  background: var(--primary); color: #fff; padding: 8px 16px;
}
.skip-link:focus { left: 8px; top: 8px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---------- ヘッダー ---------- */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 0;
  margin-bottom: 22px;
}
.header-inner {
  display: flex; flex-wrap: wrap; gap: 18px 32px;
  align-items: flex-end; justify-content: space-between;
}
.header-title { flex: 1 1 380px; min-width: 0; }
.site-header h1 { font-size: 1.32rem; letter-spacing: .01em; }

.header-meta { display: flex; gap: 26px; margin: 0; flex-wrap: wrap; }
.header-meta dt { font-size: .72rem; color: var(--text-faint); letter-spacing: .04em; }
.header-meta dd { margin: 0; font-size: .95rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- カード共通 ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.card > h2, .card-head h2 { font-size: .98rem; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}
.card-tools { display: flex; gap: 6px; align-items: center; }

.note { color: var(--text-faint); font-size: .76rem; margin-top: 8px; }
.collection-note { margin-bottom: 10px; }
.collection-stale {
  color: var(--attention); background: var(--attention-pale);
  border-left: 3px solid var(--attention); border-radius: 4px; padding: 8px 10px;
}

.banner {
  border-radius: 8px; padding: 9px 13px; font-size: .82rem; margin: 0 0 14px;
}
.banner-error { background: var(--negative-pale); color: var(--negative); border: 1px solid var(--negative-mid); }
.banner-info { background: var(--surface-alt); color: var(--text-muted); border: 1px solid var(--border); }
.loading { color: var(--text-muted); padding: 40px 0; text-align: center; }

/* ---------- KPI ---------- */

.kpi-row {
  display: grid; gap: 14px; margin-bottom: 18px;
  grid-template-columns: 1.35fr 1fr 1fr 1fr;
}
.kpi h2 { font-size: .78rem; color: var(--text-muted); font-weight: 600; letter-spacing: .02em; }
.kpi-value {
  font-size: 2.3rem; font-weight: 700; line-height: 1.15;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em; margin-top: 2px;
}
.kpi-unit { font-size: .74rem; font-weight: 600; color: var(--text-muted); margin-left: 6px; }
.kpi-sub { font-size: .76rem; color: var(--text-muted); margin-top: 2px; min-height: 1.7em; }
.kpi-primary { background: var(--primary-pale); border-color: var(--primary-soft); }
.kpi-primary h2, .kpi-primary .kpi-sub { color: var(--text); }
.kpi-spark { width: 100%; height: 44px; margin-top: 6px; display: block; }
.kpi[data-alert="rise3"] .kpi-value { color: var(--negative); }
.kpi[data-alert="fall3"] .kpi-value { color: var(--positive); }
.kpi[data-alert="over1"] .kpi-value { color: var(--attention); }

/* ---------- 推移 + 地図 ---------- */

.card-sub {
  font-size: .82rem; font-weight: 700; color: var(--text-muted);
  margin: 14px 0 6px; letter-spacing: .01em;
}
.card-sub:first-of-type { margin-top: 4px; }

.split { display: grid; grid-template-columns: 1.5fr 1fr; gap: 14px; margin-bottom: 18px; align-items: start; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }

.legend {
  display: flex; flex-wrap: wrap; gap: 6px 16px;
  font-size: .76rem; color: var(--text-muted); margin-top: 8px;
  list-style: none; padding: 0;
}
.legend .swatch {
  display: inline-block; width: 11px; height: 11px; border-radius: 2px;
  margin-right: 5px; vertical-align: -1px; border: 1px solid rgba(0, 0, 0, .18);
}
/* 地図の丸印（自治体の注意喚起）に対応する凡例。塗り分けの四角と区別する。 */
.legend .swatch-dot { border-radius: 50%; }
.legend .dash {
  display: inline-block; width: 16px; height: 0; margin-right: 5px; vertical-align: 3px;
  border-top: 2px dashed var(--neutral);
}

/* ---------- 検出ウイルス ---------- */

.virus-lead {
  font-size: .84rem; color: var(--text); margin: 0 0 10px;
  line-height: 1.6;
}
.virus-lead .virus-dominant { font-weight: 700; }
.virus-lead .virus-weak { color: var(--text-muted); }

.virus-table td, .virus-table th { padding: 6px 8px; }
.virus-table .virus-name { white-space: nowrap; font-weight: 600; }
.virus-table .virus-name .swatch {
  display: inline-block; width: 11px; height: 11px; border-radius: 2px;
  margin-right: 6px; vertical-align: -1px; border: 1px solid rgba(0, 0, 0, .18);
}
.virus-bar {
  position: relative; height: 9px; border-radius: 3px;
  background: var(--surface-alt); min-width: 54px;
}
.virus-bar > span { position: absolute; inset: 0 auto 0 0; border-radius: 3px; }
.virus-share { font-size: .74rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.virus-table tbody tr.is-zero { color: var(--text-faint); }
.virus-table tbody tr.is-zero .virus-name { font-weight: 500; }

#school-section { margin-bottom: 18px; }
.school-total td { border-top: 1px solid var(--border-strong); font-weight: 700; }

.map-wrap { position: relative; }
#map { width: 100%; height: auto; display: block; }
#map .pref { cursor: pointer; stroke: var(--surface); stroke-width: .7; stroke-linejoin: round; }
#map .pref:hover, #map .pref:focus { stroke: var(--text); stroke-width: 1.6; outline: none; }
#map .marker { pointer-events: none; }

.map-tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--text); color: var(--bg);
  padding: 6px 10px; border-radius: 6px; font-size: .78rem; line-height: 1.5;
  white-space: nowrap; transform: translate(-50%, -115%); box-shadow: var(--shadow);
}
.map-tooltip b { font-variant-numeric: tabular-nums; }
.map-legend { gap: 4px 14px; }

/* ---------- チップ・フォーム ---------- */

.chip {
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text-muted); border-radius: 999px; padding: 4px 11px;
  font-size: .76rem; cursor: pointer; font-family: inherit;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.is-on { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

select, input[type="search"] {
  font-family: inherit; font-size: .82rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 6px; padding: 5px 9px; max-width: 100%;
}
select:focus-visible, input:focus-visible, button:focus-visible, .pref:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
  padding: 12px 0; font-size: .82rem; color: var(--text-muted);
}
.filter-check { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }

/* ---------- タブ ---------- */

.tabs-card { padding-top: 0; }
.tabs {
  display: flex; gap: 2px; border-bottom: 1px solid var(--border);
  margin: 0 -20px 0; padding: 0 20px; overflow-x: auto;
}
.tabs button {
  border: none; background: none; font-family: inherit; font-size: .87rem;
  color: var(--text-muted); padding: 14px 14px 11px; cursor: pointer;
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] {
  color: var(--primary); border-bottom-color: var(--primary); font-weight: 700;
}

/* ---------- 表 ---------- */

.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.data-table th, .data-table td {
  padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table thead th {
  position: sticky; top: 0; background: var(--surface); z-index: 1;
  font-size: .74rem; color: var(--text-muted); font-weight: 600;
  border-bottom: 1px solid var(--border-strong); white-space: nowrap;
}
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody tr:hover { background: var(--surface-alt); }
.data-table .name-cell { font-weight: 600; white-space: nowrap; }
.data-table .name-cell button {
  background: none; border: none; padding: 0; font: inherit; color: var(--primary);
  cursor: pointer; text-align: left;
}
.data-table .name-cell button:hover { text-decoration: underline; }
.value-strong { font-weight: 700; }
.delta-up { color: var(--negative); }
.delta-down { color: var(--positive); }
.spark-cell svg { display: block; width: 116px; height: 26px; }
/* 全体の行より古い週の値（流行期しか保健所別を公表しない自治体など） */
.stale-row td { color: var(--text-muted); }
.stale-week { display: block; font-size: .7rem; color: var(--text-faint); white-space: nowrap; }
.empty-row td { color: var(--text-faint); text-align: center; padding: 26px 10px; }

/* ---------- バッジ ---------- */

.badge-row { display: flex; flex-wrap: wrap; gap: 5px; }
.badge {
  display: inline-block; font-size: .71rem; font-weight: 700; line-height: 1.6;
  padding: 1px 8px; border-radius: 999px; white-space: nowrap; border: 1px solid transparent;
}
.badge-rise3 { background: var(--negative-pale); color: var(--negative); border-color: var(--negative-mid); }
.badge-fall3 { background: var(--positive-pale); color: var(--positive); border-color: var(--positive); }
.badge-over1 { background: var(--attention-pale); color: var(--attention); border-color: var(--attention-mid); }
.badge-caution { background: var(--negative-pale); color: var(--negative); border-color: var(--negative); }
.badge-warning { background: var(--negative); color: #fff; border-color: var(--negative); }
.badge-quiet { background: var(--surface-alt); color: var(--text-faint); border-color: var(--border); }

/* 初出値（翌週の公表で改訂されうる値）に添える印。数値そのものより
   目立たせず、しかし見落とさない程度の強さにする。 */
.tag-provisional {
  display: inline-block; margin-left: 6px; padding: 0 6px;
  font-size: .66rem; font-weight: 700; line-height: 1.7; border-radius: 999px;
  background: var(--surface-alt); color: var(--text-muted);
  border: 1px dashed var(--border); vertical-align: middle; white-space: nowrap;
}

/* ---------- ニュース・注意喚起 ---------- */

.news-groups, .advisory-groups { padding-bottom: 12px; }
.news-group { border-top: 1px solid var(--border); padding: 12px 0 4px; }
.news-group:first-child { border-top: none; }
.news-group > h3 {
  font-size: .84rem; display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px;
}
.news-group .count { font-size: .74rem; color: var(--text-faint); font-weight: 400; }
.news-item { display: flex; gap: 10px; padding: 5px 0; align-items: baseline; font-size: .84rem; }
.news-item time {
  font-variant-numeric: tabular-nums; color: var(--text-faint);
  font-size: .74rem; white-space: nowrap; min-width: 5.2em;
}
.news-item time.unverified { font-style: italic; cursor: help; }
.news-item .source { color: var(--text-faint); font-size: .74rem; white-space: nowrap; }
/* 自治体の原文（原本アーカイブ由来）と、それを報じた記事とを見分けるための印。 */
.news-item .origin-tag {
  font-size: .68rem; color: var(--primary); border: 1px solid var(--primary-pale);
  background: var(--primary-pale); border-radius: 3px; padding: 0 4px;
  white-space: nowrap; cursor: help;
}
.news-item a { text-decoration: none; }
.news-item a:hover { text-decoration: underline; }

.official-link { font-size: .78rem; }
.advisory-groups .news-group > h3 a { font-size: .74rem; font-weight: 400; }

/* ---------- 出典 ---------- */

.sources-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 32px; margin-top: 10px; }
.sources-grid h3 { font-size: .82rem; color: var(--text-muted); margin-bottom: 6px; }
.def-list { margin: 0; padding-left: 1.1em; font-size: .8rem; color: var(--text-muted); }
.def-list li { margin-bottom: 5px; }
.def-list strong { color: var(--text); }
.caveats { margin-top: 16px; font-size: .8rem; color: var(--text-muted); }
.caveats summary { cursor: pointer; font-weight: 600; color: var(--text); }
.caveats ul { margin: 8px 0 0; padding-left: 1.2em; }
.caveats li { margin-bottom: 5px; }

/* ---------- 詳細ダイアログ ---------- */

.detail-dialog {
  width: min(760px, calc(100vw - 32px)); max-height: 88vh; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 12px; padding: 22px 24px 26px;
  background: var(--surface); color: var(--text); box-shadow: 0 12px 48px rgba(0, 0, 0, .28);
}
.detail-dialog::backdrop { background: rgba(10, 12, 16, .48); }
.detail-close-form { float: right; margin: -8px -8px 0 0; }
.detail-close {
  border: none; background: none; font-size: 1.5rem; line-height: 1;
  color: var(--text-muted); cursor: pointer; padding: 4px 8px;
}
.detail-dialog h2 { font-size: 1.15rem; }
.detail-sub { color: var(--text-muted); font-size: .82rem; margin-bottom: 10px; }
.detail-dialog .chart { margin: 14px 0 4px; }
.detail-section { margin-top: 18px; }
.detail-section h3 {
  font-size: .82rem; color: var(--text-muted); margin-bottom: 6px;
  border-bottom: 1px solid var(--border); padding-bottom: 4px;
}
.detail-section .data-table { font-size: .8rem; }
/* 期間の取り違えを防ぐため、暦年である旨の断りを本文より先に目立たせる。 */
.detail-virus-period {
  margin-top: 0; padding: 6px 9px; border-radius: 6px;
  background: var(--surface-alt); color: var(--text-muted);
}

/* ---------- フッター ---------- */

.footer-credit {
  color: var(--text-muted); margin-bottom: 6px;
  padding-left: 10px; border-left: 3px solid var(--primary-soft);
}
.scale-toggle { display: inline-flex; gap: 4px; }
.detail-scale-note { font-size: .74rem; color: var(--text-faint); margin-top: 8px; }

.site-footer {
  margin-top: 34px; padding: 20px 0 40px; border-top: 1px solid var(--border);
  color: var(--text-faint); font-size: .76rem;
}
.footer-meta { margin-top: 6px; }

/* ---------- レスポンシブ ---------- */

@media (max-width: 1080px) {
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .split { grid-template-columns: 1fr; }
  .sources-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  body { font-size: 14px; }
  .wrap { padding: 0 12px; }
  .kpi-row { grid-template-columns: 1fr; }
  .kpi-value { font-size: 2rem; }
  .header-inner { align-items: flex-start; }
  .header-meta { gap: 16px; }
  .spark-cell { display: none; }
  .data-table thead th:nth-child(5), .data-table td:nth-child(5) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
