/* ============================================================
   到達圏アナライザ — レイアウトとテーマ
   色は 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;
}

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

.sidebar__head {
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--surface-1);
  z-index: 2;
}
.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);
}

/* ---------- 分析の切り替え ---------- */
.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; }

/* ---------- フォーム ---------- */
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); }

/* ---------- 地点 ---------- */
.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); }

/* ---------- フィード選択ダイアログ ---------- */
.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); }

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

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

.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: none;
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1000;
  box-shadow: var(--shadow);
}

@media (max-width: 900px) {
  .app { position: relative; }
  .drawer-toggle { display: block; }
  .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; }
}

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