/* ============================================================
   EvoLiNQ 公共交通アナライザー（Beta） — レイアウトとテーマ
   色は light / dark の両方を明示的に定義する（自動反転はしない）
   ============================================================ */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #f9f9f7;
  --surface-3: #f1f1ed;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --street: #c94908;
  --good: #0ca30c;
  --critical: #d03b3b;
  --warning: #fab219;
  --shadow: 0 1px 2px rgba(11, 11, 11, .06), 0 8px 24px rgba(11, 11, 11, .08);
  --radius: 8px;
  --sidebar-w: 384px;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --surface-2: #0d0d0d;
    --surface-3: #232322;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --line: #2c2c2a;
    --line-strong: #383835;
    --accent: #3987e5;
    --accent-ink: #0b0b0b;
    --street: #d95923;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }

/* label などに display を指定しているので hidden を効かせる */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}
body.is-resizing-sidebar { cursor: col-resize; }

.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- サイドバー ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface-1);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
}

.sidebar__head {
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--surface-1);
  z-index: 2;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.sidebar__head-copy {
  min-width: 0;
  flex: 1 1 auto;
}
.sidebar__head h1 { font-size: 16px; margin: 0; letter-spacing: .01em; }
.sidebar__head p { margin: 2px 0 0; font-size: 12px; }

.sidebar__foot {
  margin-top: auto;
  padding: 10px 16px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-top: 1px solid var(--line);
}

.panel {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.panel h2 {
  font-size: 13px;
  margin: 0 0 10px;
  text-transform: none;
  letter-spacing: .02em;
  color: var(--text-primary);
}

.analysis-subpanel {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.analysis-subpanel h2 {
  margin-bottom: 8px;
}

/* ---------- 分析の切り替え ---------- */
.mode-select { display: grid; gap: 2px; }
.mode-select__item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
}
.mode-select__item:hover { border-color: var(--line-strong); }
.mode-select__item:has(input:checked) {
  border-color: var(--accent);
  box-shadow: inset 2px 0 0 var(--accent);
  font-weight: 600;
}
.mode-select input[type="radio"] { width: 15px; height: 15px; accent-color: var(--accent); }

.muted { color: var(--text-secondary); }
.small { font-size: 12px; }
.hint { font-size: 12px; color: var(--accent); margin: 8px 0 0; }
.help-details { margin: 4px 0 10px; }
.help-details summary {
  width: fit-content;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.help-details[open] summary { margin-bottom: 6px; }
.help-details p { margin: 0; }
.session-gtfs .check { margin: 8px 0; }
.session-gtfs__upload { margin-top: 4px; }
.session-gtfs__feeds { list-style: none; margin: 6px 0 0; padding: 0; font-size: 12px; }
.session-gtfs__feeds li {
  display: flex; align-items: center; justify-content: space-between;
  gap: 6px; padding: 2px 0; color: var(--text-secondary);
}
.session-gtfs__feeds li span { overflow-wrap: anywhere; }
.session-gtfs__remove {
  flex: none; border: none; background: none; cursor: pointer;
  color: var(--text-secondary); font-size: 14px; line-height: 1; padding: 0 4px;
}
.session-gtfs__remove:hover { color: var(--critical); }

/* ---------- フォーム ---------- */
label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}
.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
}
.grid2 .span2 { grid-column: 1 / -1; }
label.check {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

input, select, button {
  font: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 6px 8px;
  min-width: 0;
}
input[type="checkbox"] { width: 16px; height: 16px; padding: 0; accent-color: var(--accent); }
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  cursor: pointer;
  background: var(--surface-3);
  border-color: var(--line-strong);
  white-space: nowrap;
}
button:hover { border-color: var(--text-muted); }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
button.primary:disabled, button:disabled { opacity: .55; cursor: progress; }

.actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.actions .primary { flex: 1; }

.status {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--text-secondary);
  min-height: 1.2em;
  white-space: pre-wrap;
}
.status[data-tone="error"] { color: var(--critical); }
.status[data-tone="ok"] { color: var(--text-secondary); }
.status[data-tone="busy"] { color: var(--accent); }

.compare-log {
  max-height: 180px;
  margin: 6px 0 0;
  padding: 8px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 11px;
  white-space: pre-wrap;
}

/* ---------- 地点 ---------- */
.search-row { display: flex; gap: 6px; }
.search-row input { flex: 1; }

.geocode-results {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-height: 180px;
  overflow-y: auto;
}
.geocode-results li {
  padding: 6px 8px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.geocode-results li:last-child { border-bottom: 0; }
.geocode-results li:hover { background: var(--surface-3); }

.point-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.point {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.point.is-picking { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.point__dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--surface-1); }
.point__dot[data-role="origin"] { background: #2a78d6; }
.point__dot[data-role="destination"] { background: #eb6834; }
.point__body { display: flex; flex-direction: column; }
.point__body strong { font-size: 12px; font-weight: 600; }
.point__coord { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.point__name { font-size: 11px; color: var(--accent); }
.point__name:empty { display: none; }
.snap-toggle { margin-top: 8px; font-size: 12px; color: var(--text-primary); }
.pick { padding: 4px 8px; font-size: 12px; }

/* ---------- GTFS 一覧 ---------- */
/* ---------- 選択中フィードの要約（サイドバー） ---------- */
.selected-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 8px 10px;
  margin: 8px 0 0;
}
.selected-box__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.selected-box__head strong { font-size: 13px; }
.selected-box__head button { font-size: 12px; padding: 4px 9px; }
.selected-box__buttons { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.selected-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  max-height: 190px;
  overflow-y: auto;
  display: grid;
  gap: 4px;
}
.selected-list:empty { display: none; }
.selected-list li {
  font-size: 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: baseline;
  padding: 3px 0;
  border-top: 1px solid var(--line);
}
.selected-list li span { color: var(--text-muted); font-size: 11px; }
.selected-list li button {
  border: 0;
  background: none;
  color: var(--text-muted);
  padding: 0 4px;
  font-size: 14px;
  line-height: 1;
}
.selected-list li button:hover { color: var(--critical); }

.layer-toggles {
  display: grid;
  gap: 4px;
  margin: 10px 0 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.layer-toggles .check { font-size: 12px; color: var(--text-primary); }
.population-mesh-options,
.student-mesh-options,
.economic-mesh-options,
.school-options,
.school-district-options,
.store-options,
.hospital-options {
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.population-mesh-options .muted,
.student-mesh-options .muted,
.economic-mesh-options .muted,
.school-options .muted,
.school-district-options .muted,
.store-options .muted { margin: 0; }
.hospital-options .muted { margin: 0 0 4px; }
.check-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2px 8px;
  margin-bottom: 6px;
}
.check-grid .check { font-size: 12px; }

/* 地図右上、レイヤコントロールの直下に出す病院・診療所の絞り込み */
.hospital-filter-box {
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 220px;
  font-size: 12px;
}
.hospital-filter-box__head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.hospital-filter-box__title { flex: 1; font-weight: 600; }
.hospital-filter-box__toggle {
  padding: 2px 6px;
  font-size: 11px;
  white-space: nowrap;
}
.hospital-filter-box.is-collapsed { padding-bottom: 7px; }
.hospital-filter-box .check { font-size: 12px; }

.population-analysis {
  margin-top: 2px;
  padding-top: 2px;
  border-top: 1px solid var(--line);
}
.population-analysis h3 { margin: 0 0 2px; font-size: 14px; }
.table-scroll { overflow-x: auto; max-height: 320px; }
.table-scroll table { width: 100%; border-collapse: collapse; font-size: 12px; }
.table-scroll th,
.table-scroll td { padding: 5px 7px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.table-scroll th:first-child,
.table-scroll td:first-child { text-align: left; }
.table-scroll th { position: sticky; top: 0; background: var(--surface-2); }
.table-scroll tr.is-focused td { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.population-stop-link {
  appearance: none;
  border: 0;
  padding: 1px 0;
  background: none;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.population-stop-link:hover,
.population-stop-link:focus-visible { color: color-mix(in srgb, var(--accent) 75%, black); }

/* ---------- フィード選択ダイアログ ---------- */
.modal { position: fixed; inset: 0; z-index: 2000; display: flex; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(11, 11, 11, .45); }
.modal__panel {
  position: relative;
  margin: auto;
  width: min(860px, 94vw);
  max-height: min(88dvh, 900px);
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal__panel--small { width: min(560px, 94vw); }
.modal__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.modal__head h2 { margin: 0; font-size: 15px; }
.modal__head p { margin: 2px 0 0; }
.modal__head a { color: var(--accent); }
.modal__close {
  border: 0;
  background: none;
  font-size: 22px;
  line-height: 1;
  padding: 0 4px;
  color: var(--text-secondary);
}
.modal__foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}

.picker__filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: flex-end;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.picker__filters label { flex: 1 1 170px; }
.picker__filters label.check { flex: 0 0 auto; align-self: center; padding-top: 14px; }
.picker__filters button { align-self: flex-end; }
.picker__toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}
.picker__toolbar button { font-size: 12px; padding: 4px 9px; }
.picker__spacer { flex: 1; }

.feed-adder__body {
  display: grid;
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
}
.feed-adder__method {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.feed-adder__method legend { padding: 0 5px; font-size: 12px; color: var(--text-secondary); }
.feed-adder__method .check { color: var(--text-primary); }

.picker__list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 180px;
}
.picker__list > li { border-bottom: 1px solid var(--line); padding: 8px 16px; }
.picker__list > li.is-selected { background: var(--surface-3); }
.picker__list > li.muted { padding: 16px; }
.feed {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 10px;
  align-items: start;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
}
.feed__name { font-weight: 600; }
.feed__meta { font-size: 11px; color: var(--text-muted); display: block; }
.feed-group {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-3);
  padding: 4px 16px;
}

@media (max-width: 700px) {
  .modal__panel { width: 100vw; max-height: 100dvh; border-radius: 0; border: 0; }
  .picker__filters label { flex: 1 1 100%; }
}

.log { margin-top: 8px; }
.log summary { font-size: 12px; color: var(--text-secondary); cursor: pointer; }
.log pre {
  margin: 6px 0 0;
  padding: 8px;
  background: var(--surface-3);
  border-radius: 6px;
  max-height: 180px;
  overflow: auto;
  font-size: 11px;
  line-height: 1.4;
  white-space: pre-wrap;
}

/* ---------- 結果カード ---------- */
.cards { display: grid; gap: 8px; margin-top: 10px; }
.card {
  border: 1px solid var(--line);
  border-left: 3px solid var(--critical);
  border-radius: var(--radius);
  padding: 9px 10px;
  background: var(--surface-2);
  cursor: pointer;
}
/* 選択中＝地図で太い赤で描かれている候補 */
.card.is-active {
  border-color: var(--critical);
  background: var(--surface-3);
  box-shadow: inset 3px 0 0 var(--critical);
}
/* 徒歩のみの経路は公共交通の候補と区別して控えめに */
.card.is-direct { border-left-color: var(--line-strong); }
.card.is-direct .card__time { font-weight: 600; color: var(--text-secondary); }
.card__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.card__time { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.card__badge {
  font-size: 11px;
  color: var(--text-secondary);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 1px 7px;
}
.card__sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
/* 徒歩 0 分圏の停留所から探した経路であることの断り書き */
.card__via { font-size: 11px; color: var(--accent); margin: 3px 0 0; }
.card__legs { margin: 6px 0 0; padding: 0; list-style: none; display: grid; gap: 3px; }
.card__legs li { font-size: 12px; display: grid; grid-template-columns: 96px 1fr; gap: 6px; }
.card__legs time { color: var(--text-muted); font-variant-numeric: tabular-nums; }

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  color: var(--text-secondary);
}
.badge[data-tone="ok"] { border-color: var(--good); color: var(--good); }
.badge[data-tone="warn"] { border-color: var(--warning); }
.badge[data-tone="error"] { border-color: var(--critical); color: var(--critical); }

/* ---------- 地図 ---------- */
.map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--surface-3); }

.compare-maps {
  position: absolute;
  inset: 0;
  background: var(--line-strong);
}
.compare-map-page {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1px;
}
.compare-map-card {
  min-width: 0;
  position: relative;
  overflow: hidden;
  background: var(--surface-3);
}
.compare-map-card h2 {
  position: absolute;
  z-index: 1000;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 150px);
  margin: 0;
  padding: 5px 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  box-shadow: var(--shadow);
  color: var(--text-primary);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.compare-map-canvas { position: absolute; inset: 0; }
.compare-print-head, .compare-print-foot, .compare-legend-page { display: none; }

@media screen {
  /* 印刷前にLeafletへPDFと同じ実寸を認識させるための一時配置。 */
  body.compare-print-preparing .compare-maps {
    position: fixed !important;
    inset: 0 auto auto -10000px !important;
    width: 281mm !important;
    height: 194mm !important;
    display: block !important;
    overflow: hidden;
  }
  body.compare-print-preparing .compare-map-page {
    width: 281mm !important;
    height: 194mm !important;
    display: grid !important;
    grid-template: 12mm 174mm 8mm / 1fr 1fr !important;
    gap: 0 3mm !important;
  }
  body.compare-print-preparing .compare-print-head {
    display: flex;
    grid-column: 1 / -1;
  }
  body.compare-print-preparing .compare-print-foot {
    display: block;
    grid-column: 1 / -1;
  }
}

.leaflet-container { font-family: inherit; font-size: 12px; }

/* 運行本数のラベル。線の上に置くので、白フチで地図から浮かせる */
.freq-label {
  display: flex !important;
  align-items: center;
  gap: 3px;
  width: auto !important;
  height: auto !important;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  background: color-mix(in srgb, var(--surface-1) 82%, transparent);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 4px;
  transform: translate(-50%, -50%);
  cursor: pointer;
}
.freq-label:hover { border-color: var(--text-muted); }
.freq-label.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
/* 進行方向。line の向きに合わせて JS が回す */
.freq-label__arrow {
  display: inline-block;
  font-size: 9px;
  line-height: 1;
  color: var(--text-secondary);
}
/* 選択した線に並べる進行方向の矢印 */
.freq-arrow {
  width: auto !important;
  height: auto !important;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.freq-arrow span {
  display: inline-block;
  font-size: 13px;
  line-height: 1;
  color: var(--accent);
  text-shadow: 0 0 3px var(--surface-1), 0 0 3px var(--surface-1), 0 0 3px var(--surface-1);
}
/* 運行本数（全体表示）: 区間ごとの本数だけを、区間の角度に合わせて回転させて置く */
.freq-seg-label {
  width: auto !important;
  height: auto !important;
  transform: translate(-50%, -50%);
}
.freq-seg-label span {
  display: inline-block;
  font-size: 14px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--text-primary);
  text-shadow: 0 0 3px var(--surface-1), 0 0 3px var(--surface-1), 0 0 3px var(--surface-1),
    0 0 5px var(--surface-1), 0 0 5px var(--surface-1);
}

/* 凡例の開閉。畳んだときはこのボタンだけが地図の右下に残る
   （見た目は下の .legend と同じカードにそろえる） */
.legend-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 220px;  /* .legend と同じ幅に収める（ボタンだけ広くならないように） */
  margin: 0 0 6px;
  padding: 4px 9px;
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--surface-1);
  border-color: var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.legend-toggle:hover { color: var(--text-primary); border-color: var(--text-muted); }
.legend-toggle__mark { font-variant-numeric: tabular-nums; }
.legend-stack.is-collapsed .legend-toggle { margin-bottom: 0; }

.legend {
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 10px;
  max-width: 220px;
}
.legend h3 { margin: 0 0 6px; font-size: 11px; color: var(--text-secondary); font-weight: 600; }
.legend + .legend { margin-top: 6px; }
.legend__row { display: flex; align-items: center; gap: 7px; margin: 2px 0; font-size: 12px; }
.legend__swatch {
  width: 16px; height: 12px; border-radius: 3px; flex: none;
  box-shadow: inset 0 0 0 1px rgba(11, 11, 11, .18);
}
.legend__label { font-variant-numeric: tabular-nums; }
.legend__note { font-size: 11px; color: var(--text-muted); margin-top: 5px; }

/* ---------- 右上レイヤ一覧のグループ分け（地図・交通・人口・施設・エリア） ---------- */
/* Leaflet 標準の .leaflet-control-layers の見た目を流用し、中身だけ差し替える。
   既定は畳んでおき、アイコンをクリックしたときだけパネルを開く
   （本物の L.Control.Layers の collapsed:true と同じ挙動）。 */
.layer-groups__toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  font-size: 16px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text-primary);
}
.layer-groups__panel {
  padding: 6px 8px;
  max-width: 320px;
  max-height: 70vh;
  overflow-y: auto;
  font-size: 12px;
  text-align: left; /* Leaflet 標準 CSS の中央寄せを打ち消す */
  border-top: 1px solid var(--line);
}
.layer-groups__panel[hidden] { display: none; }
.layer-group + .layer-group { margin-top: 2px; }
.layer-group__title {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 3px 0;
  list-style: none;
  text-align: left;
}
.layer-group__title::-webkit-details-marker { display: none; }
.layer-group__title::before { content: '▸ '; }
details[open] > .layer-group__title::before { content: '▾ '; }
.layer-group__list {
  list-style: none;
  margin: 2px 0 6px;
  padding-left: 14px; /* 子項目の字下げ */
  text-align: left;
}
.layer-group__item { margin: 3px 0; text-align: left; }
.layer-group__item label {
  display: flex;
  flex-direction: row; /* 汎用の `label { flex-direction: column }` を上書きする */
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  cursor: pointer;
  text-align: left;
}
/* 地図の濃淡スライダー。チェックボックス/ラジオの行と幅をそろえつつ、
   スライダー本体だけ伸ばして掴みやすくする。 */
.layer-group__item--slider label { cursor: default; }
.layer-group__item--slider input[type="range"] { flex: 1; min-width: 0; }
.layer-group__slider-value {
  min-width: 3em;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.map-cursor-pick { cursor: crosshair !important; }

/* ---------- バス停の時刻表ポップアップ ---------- */
.tt-popup .leaflet-popup-content-wrapper {
  background: var(--surface-1);
  color: var(--text-primary);
  border-radius: var(--radius);
}
.tt-popup .leaflet-popup-tip { background: var(--surface-1); }
.tt-popup .leaflet-popup-content { margin: 10px 12px; max-height: 60vh; overflow-y: auto; }

.tt__head {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-bottom: 6px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.tt__head strong { font-size: 14px; }
.tt__head span { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.tt__actions {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.tt__actions button { font-size: 11px; padding: 3px 8px; flex: 1; }

.tt__pattern + .tt__pattern { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.tt__route {
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 4px;
}
.tt__swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.tt__kind {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-secondary);
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 0 4px;
}
.tt__count { font-size: 11px; font-weight: 400; color: var(--text-muted); margin-left: auto; }

.tt__grid { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.tt__grid th {
  width: 26px;
  text-align: right;
  padding: 1px 6px 1px 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  border-right: 1px solid var(--line);
  vertical-align: top;
}
.tt__grid td { padding: 1px 0 1px 6px; font-size: 12px; line-height: 1.6; }
.tt__grid tr + tr th, .tt__grid tr + tr td { border-top: 1px solid var(--line); }

.tt__empty { font-size: 12px; color: var(--text-secondary); margin: 6px 0; }
.tt__error { color: var(--critical); }
.tt__nearby { font-size: 11px; color: var(--text-muted); margin: 8px 0 0; }

/* 地図で選択中の路線に属する便 */
.tt__pattern.is-highlight {
  margin-left: -6px;
  padding-left: 6px;
  border-left: 3px solid var(--critical);
}
.tt__pattern.is-highlight .tt__route { color: var(--critical); }
.tt__pattern.is-highlight .tt__grid td { color: var(--critical); font-weight: 700; }
.tt__pattern.is-highlight .tt__grid th { color: var(--critical); }
.tt__selected {
  font-size: 10px;
  font-weight: 600;
  color: var(--critical);
  border: 1px solid var(--critical);
  border-radius: 3px;
  padding: 0 4px;
}
/* 経路検索で選んだ便そのもの */
.tt__now {
  font-style: normal;
  background: var(--critical);
  color: #ffffff;
  border-radius: 3px;
  padding: 0 3px;
}

/* ---------- 路線の停車駅・時刻パネル ---------- */
.pattern-panel {
  position: relative;
  width: min(300px, 42vw);
  max-height: 46vh;
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 9px 11px;
  overflow: hidden;
}
.pattern-panel__close {
  position: absolute;
  top: 4px;
  right: 6px;
  border: 0;
  background: none;
  font-size: 17px;
  line-height: 1;
  padding: 0 3px;
  color: var(--text-secondary);
}
.pp__head { padding-right: 18px; }
.pp__title { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; font-size: 13px; }
.pp__swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.pp__headsign { font-weight: 400; color: var(--text-secondary); }
.pp__meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.pp__pin {
  color: var(--critical);
  border: 1px solid var(--critical);
  border-radius: 3px;
  padding: 0 4px;
  margin-left: 4px;
}
.pp__trip {
  font-size: 12px;
  margin: 7px 0 4px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}
.pp__because {
  display: inline-block;
  font-size: 10px;
  color: var(--text-secondary);
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 0 4px;
  margin-left: 4px;
}
.pp__because.is-trip { color: var(--critical); border-color: var(--critical); }

.pp__warn { font-size: 11px; color: var(--critical); margin: 4px 0 0; }
.pp__scroll { overflow-y: auto; min-height: 0; }
.pp__stops { border-collapse: collapse; width: 100%; font-size: 12px; }
.pp__stops td { padding: 1px 0; }
.pp__time {
  width: 44px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  padding-right: 8px !important;
}
.pp__others {
  font-size: 11px;
  color: var(--text-muted);
  margin: 6px 0 0;
  font-variant-numeric: tabular-nums;
}
.pp__hint { font-size: 10px; color: var(--text-muted); margin: 4px 0 0; }
.pp__empty { font-size: 12px; color: var(--text-secondary); margin: 6px 0; }
.pp__error { color: var(--critical); }

@media (max-width: 700px) {
  .pattern-panel { width: min(280px, 72vw); max-height: 38vh; }
}

/* ---------- レスポンシブ ---------- */
.drawer-toggle {
  display: block;
  position: absolute;
  top: 10px;
  left: 56px;
  z-index: 1000;
  box-shadow: var(--shadow);
}

.drawer-toggle--close {
  position: static;
  margin-left: auto;
  flex: 0 0 auto;
  box-shadow: none;
}

.sidebar__resize {
  display: none;
}

@media (max-width: 900px) {
  .app { position: relative; }
  .sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    width: min(92vw, var(--sidebar-w));
    flex-basis: auto;
    z-index: 1100;
    transform: translateX(-102%);
    transition: transform .18s ease-out;
    box-shadow: var(--shadow);
  }
  .sidebar.is-open { transform: none; }
  .map-wrap { flex: 1 1 auto; }
  .compare-map-page { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .sidebar__resize { display: none !important; }
}

@media (min-width: 901px) {
  .drawer-toggle {
    top: 10px;
  }
  .sidebar.is-collapsed {
    display: none;
  }
  .sidebar__resize {
    display: block;
    position: fixed;
    top: 0;
    left: calc(var(--sidebar-w) - 4px);
    width: 8px;
    height: 100dvh;
    z-index: 1200;
    cursor: col-resize;
    touch-action: none;
    user-select: none;
    background: linear-gradient(to right, transparent, rgba(42, 120, 214, .16), transparent);
  }
  .sidebar__resize::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 3px;
    width: 2px;
    border-radius: 999px;
    background: rgba(42, 120, 214, .42);
    opacity: 0;
    transition: opacity .12s ease;
  }
  .sidebar__resize:hover::after,
  .sidebar__resize:focus-visible::after {
    opacity: 1;
  }
}

@page { size: A4 landscape; margin: 8mm; }

@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #111; }
  .drawer-toggle, .sidebar, #map { display: none !important; }
  .app { display: block; width: 281mm; height: auto; overflow: visible; }
  .map-wrap { width: 281mm; height: auto; overflow: visible; }
  .compare-maps {
    position: relative;
    width: 281mm;
    height: auto;
    display: block !important;
    background: #fff;
  }
  .compare-map-page {
    width: 281mm;
    height: 194mm;
    display: grid;
    grid-template: 12mm 174mm 8mm / 1fr 1fr;
    gap: 0 3mm;
    background: #fff;
    break-after: page;
    page-break-after: always;
  }
  .compare-print-head {
    display: flex;
    grid-column: 1 / -1;
    align-items: baseline;
    justify-content: space-between;
    gap: 8mm;
    color: #111;
  }
  .compare-print-head h1 { margin: 0; font-size: 16pt; }
  .compare-print-head p { margin: 0; font-size: 8pt; text-align: right; }
  .compare-map-card {
    border: .3mm solid #777;
    background: #fff;
    break-inside: avoid;
  }
  .compare-map-card h2 {
    top: 3mm;
    max-width: calc(100% - 20mm);
    color: #111;
    background: rgba(255, 255, 255, .92);
    border-color: #999;
    box-shadow: none;
    font-size: 10pt;
  }
  .compare-print-foot {
    display: block;
    grid-column: 1 / -1;
    align-self: end;
    color: #444;
    font-size: 7.5pt;
    text-align: right;
  }
  .compare-legend-page {
    width: 281mm;
    height: 194mm;
    display: grid;
    grid-template: 18mm 1fr / 1fr 1fr;
    gap: 8mm;
    padding: 0;
    overflow: hidden;
    background: #fff;
    color: #111;
    break-before: page;
    page-break-before: always;
  }
  .compare-legend-page > header {
    display: flex;
    grid-column: 1 / -1;
    align-items: baseline;
    justify-content: space-between;
    gap: 8mm;
    border-bottom: .3mm solid #999;
  }
  .compare-legend-page > header h1 { margin: 0; font-size: 16pt; }
  .compare-legend-page > header p { margin: 0; font-size: 8pt; text-align: right; }
  .compare-print-legend {
    align-self: start;
    padding: 8mm;
    border: .3mm solid #999;
    break-inside: avoid;
  }
  .compare-print-legend h2 { margin: 0 0 4mm; font-size: 13pt; }
  .compare-print-conditions {
    display: grid;
    grid-template-columns: 24mm 1fr;
    gap: 1.5mm 4mm;
    margin: 0 0 7mm;
    padding: 4mm;
    background: #f4f6f8;
    border: .25mm solid #c7ccd1;
    font-size: 9.5pt;
  }
  .compare-print-conditions dt { margin: 0; color: #555; font-weight: 700; }
  .compare-print-conditions dd { margin: 0; color: #111; }
  .compare-print-legend-row {
    display: grid;
    grid-template-columns: 14mm 1fr;
    align-items: center;
    gap: 5mm;
    margin: 4mm 0;
    font-size: 11pt;
  }
  .compare-print-legend-swatch {
    width: 14mm;
    height: 7mm;
    border: .25mm solid rgba(0,0,0,.25);
    border-radius: 1mm;
  }
  .leaflet-control-zoom, .leaflet-control-layers, .leaflet-control-scale { display: none !important; }
  .compare-map-page .legend-stack { display: none !important; }
  /* 畳んだままでも印刷には凡例そのものを載せる（開閉ボタンは紙では意味がない） */
  .legend-toggle { display: none !important; }
  .legend-stack__body[hidden] { display: block !important; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

/* textLines() が作る複数行のツールチップ。<br> を組まずに済ませるため。
   `width: max-content` が要る。日本語はどこでも改行できるので、これが無いと
   最小幅が 1 文字ぶんまで縮み、「春葉ガ／ーデン／店舗面／積:」のように
   縦一列に折り返される（実際にそうなっていた）。 */
.text-lines {
  white-space: pre-line;
  display: block;
  width: max-content;
  max-width: 24em;
}

/* 店舗の位置の手直し（/admin/ でのみ表示） */
.store-edit-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 6px;
}
.store-edit-row select {
  flex: 1 1 auto;
  min-width: 0;
}

/* 店舗の位置を直すときの目印。出発地・目的地のピンと見分けが付くようにする */
.store-drag-marker {
  filter: hue-rotate(150deg) saturate(1.4);
}

/* 地図側に出す店舗編集の枠。中身の幅が枠を割らないようにする */
.store-edit-box select,
.store-edit-box button {
  display: block;
  width: 100%;
  margin-top: 6px;
  max-width: 280px;
}

/* 店舗の位置を直す枠。**modal ではない。**
   地図の目印を掴みながら入力するので、全画面の覆いを敷くと目印が隠れて掴めなくなる。
   地図の右側に浮かせ、地図はそのまま触れるようにする。 */
.store-editor {
  position: fixed;
  right: 12px;
  top: 300px;
  z-index: 1200;
  width: 320px;
  max-width: calc(100vw - 24px);
}
.store-editor[hidden] {
  display: none;
}
.store-editor__panel {
  background: var(--panel, #fff);
  border: 1px solid var(--line, #d8dde3);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(11, 11, 11, 0.22);
  padding: 12px 14px;
  max-height: calc(100vh - 320px);
  overflow-y: auto;
}
@media (max-width: 900px) {
  /* 画面が狭いときは地図の下側へ回す（地図を覆い切らないように） */
  .store-editor {
    top: auto;
    bottom: 12px;
    left: 12px;
    right: 12px;
    width: auto;
  }
  .store-editor__panel {
    max-height: 50vh;
  }
}
