/* ═══════════════════════════════════════════════════
   BUSLENS — Kyoto Bus Access
   ═══════════════════════════════════════════════════ */

:root {
  --kb-bg: #e8eaef;
  --kb-surface: #ffffff;
  --kb-surface-2: #f6f7f9;
  --kb-text: #1a1d24;
  --kb-text-muted: #5c6370;

  /* 意味のある色 */
  --kb-walk: #2563eb;
  --kb-walk-soft: #dbeafe;
  --kb-bus: #6d28d9;
  --kb-bus-soft: #ede9fe;
  --kb-pin: #dc2626;
  --kb-radius-map: #2563eb;
  --kb-score-high: #15803d;
  --kb-score-high-bg: #dcfce7;
  --kb-score-mid: #a16207;
  --kb-score-mid-bg: #fef9c3;
  --kb-score-low: #b91c1c;
  --kb-score-low-bg: #fee2e2;
  --kb-night: #1e3a8a;
  --kb-night-bg: #dbeafe;
  --kb-early: #c2410c;
  --kb-early-bg: #ffedd5;

  --kb-accent: var(--kb-walk);
  --kb-accent-hover: #1d4ed8;
  --kb-accent-soft: var(--kb-walk-soft);
  --kb-accent-fg: #1e40af;
  --kb-border: #dde1e8;
  --kb-border-strong: #c5cad4;
  --kb-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
  --kb-shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.1);
  --kb-radius: 12px;
  --kb-radius-sm: 8px;
  --kb-radius-pill: 999px;
  --kb-font: 'Inter', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  --kb-header-h: 52px;
  --kb-shell-pad: 18px;
  --kb-sidebar-w: 400px;
}

.kb-hidden { display: none !important; }

/* ─── Page chrome ───────────────────────────────── */
body.page-kyoto-bus {
  padding: 0 !important;
  align-items: stretch !important;
  overflow: hidden;
  height: 100dvh;
  background: var(--kb-bg);
}

body.page-kyoto-bus .site-wrapper {
  align-items: stretch;
  overflow: hidden;
  height: 100%;
  max-width: none;
  width: 100%;
}

body.page-kyoto-bus .lang-switcher-container { display: none; }

body.page-kyoto-bus .site-header.site-container {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  max-width: none;
  width: 100%;
  padding: 0 var(--kb-shell-pad);
  height: var(--kb-header-h);
  min-height: var(--kb-header-h);
  margin-bottom: 0;
  border-bottom: 1px solid var(--kb-border);
  background: var(--kb-surface);
  box-sizing: border-box;
}

body.page-kyoto-bus .site-header-left {
  width: 100%;
  max-width: 1680px;
  height: 100%;
  display: flex;
  align-items: center;
}

body.page-kyoto-bus .site-main {
  align-items: stretch !important;
  flex-grow: 1;
  overflow: hidden;
  padding: var(--kb-shell-pad) !important;
  max-width: none !important;
  width: 100%;
  box-sizing: border-box;
}

body.page-kyoto-bus .site-footer { display: none; }

/* ─── App header ────────────────────────────────── */
.kb-header-inner {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 24px;
  width: 100%;
  height: 100%;
}

.kb-header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.kb-header-end {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.kb-header-sep {
  width: 1px;
  height: 22px;
  background: var(--kb-border-strong);
  flex-shrink: 0;
}

.kb-back-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--kb-text-muted);
  text-decoration: none;
  border-radius: var(--kb-radius-sm);
  flex-shrink: 0;
  transition: color .12s, background .12s;
  white-space: nowrap;
}
.kb-back-link:hover {
  color: var(--kb-text);
  background: var(--kb-surface-2);
}

.kb-back-link::before {
  content: '←';
  font-size: 11px;
  opacity: .6;
  line-height: 1;
}

.kb-site-title {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--kb-text);
  margin: 0;
  line-height: 1;
}

.kb-site-tag {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  font-size: 10px;
  font-weight: 600;
  color: var(--kb-accent-fg);
  letter-spacing: 0.02em;
  background: var(--kb-walk-soft);
  border: 1px solid #bfdbfe;
  border-radius: 4px;
}

.kb-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ─── Shell (inset card) ────────────────────────── */
.kb-shell {
  width: 100%;
  height: 100%;
  max-width: 1680px;
  margin: 0 auto;
}

.kb {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--kb-font);
  font-size: 13px;
  color: var(--kb-text);
  background: var(--kb-surface);
  border: 1px solid var(--kb-border);
  border-radius: var(--kb-radius);
  box-shadow: var(--kb-shadow-lg);
}

/* ══════════════════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════════════════ */
.kb-sidebar {
  width: var(--kb-sidebar-w);
  min-width: var(--kb-sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--kb-surface);
  border-right: 1px solid var(--kb-border);
  overflow: hidden;
}

.kb-panel {
  flex-shrink: 0;
  padding: 20px 20px 0;
}

.kb-panel-search {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--kb-border);
}

.kb-panel-results {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px 20px 12px;
}

/* ── Setup banner ───────────────────────────────── */
.kb-banner {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 7px 12px;
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
  font-size: 10.5px;
  color: #78350f;
  line-height: 1.5;
}
.kb-banner code {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 3px;
  padding: 0 3px;
  font-size: 10px;
}

/* ── Search ─────────────────────────────────────── */
.kb-search-section {
  position: relative;
  margin-top: 12px;
}
.kb-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.kb-input-icon {
  position: absolute;
  left: 10px;
  width: 15px;
  height: 15px;
  color: #9ca3af;
  pointer-events: none;
}
.kb-search-input {
  width: 100%;
  height: 44px;
  padding: 0 36px 0 36px;
  border: 1px solid var(--kb-border-strong);
  border-radius: var(--kb-radius-sm);
  font-size: 14px;
  background: var(--kb-surface);
  color: var(--kb-text);
  box-sizing: border-box;
  -webkit-appearance: none;
  transition: border-color .15s, box-shadow .15s;
}
.kb-search-input::placeholder { color: #a1a1aa; }
.kb-search-input:focus {
  outline: none;
  border-color: var(--kb-accent);
  box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.08);
}
.kb-search-spinner {
  position: absolute;
  right: 10px;
  display: flex;
  align-items: center;
}

/* Autocomplete */
.kb-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 10px; right: 10px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  z-index: 9999;
  max-height: 200px;
  overflow-y: auto;
  padding: 3px 0;
  list-style: none;
  margin: 0;
}
.kb-suggestions li {
  padding: 7px 12px;
  font-size: 12.5px;
  cursor: pointer;
  color: #374151;
  line-height: 1.4;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}
.kb-suggestions li:not(:last-child) { border-bottom: 1px solid #f9fafb; }
.kb-suggestions li:hover,
.kb-suggestions li.focus { background: var(--kb-accent-soft); color: var(--kb-accent-fg); }
.kb-suggestions li.kb-sugg-empty {
  cursor: default;
  color: #9ca3af;
  font-size: 12px;
  line-height: 1.5;
}
.kb-suggestions li.kb-sugg-empty:hover { background: transparent; color: #9ca3af; }
.kb-sugg-main { font-weight: 500; }
.kb-sugg-sub {
  width: 100%;
  font-size: 10.5px;
  color: #9ca3af;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kb-sugg-badge {
  font-size: 9.5px;
  font-weight: 600;
  color: #059669;
  background: #d1fae5;
  border-radius: 3px;
  padding: 1px 5px;
  flex-shrink: 0;
}

/* ── Filters row ────────────────────────────────── */
.kb-filters {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

/* ── Controls ───────────────────────────────────── */
.kb-controls {
  display: none;
}
.kb-control-group { display: flex; align-items: center; gap: 5px; }
.kb-micro-label {
  font-size: 10.5px;
  font-weight: 600;
  color: #9ca3af;
}
.kb-select {
  height: 28px;
  padding: 0 6px;
  border: 1.5px solid #e5e7eb;
  border-radius: 7px;
  font-size: 12px;
  background: #f9fafb;
  color: #374151;
  cursor: pointer;
}
.kb-select:focus { outline: none; border-color: var(--kb-accent-hover); }

/* Day tabs */
.kb-day-tabs {
  display: flex;
  margin-left: auto;
  background: var(--kb-surface-2);
  border-radius: var(--kb-radius-pill);
  padding: 3px;
  gap: 2px;
}
.kb-day-tab {
  height: 26px;
  padding: 0 11px;
  border: none;
  background: transparent;
  border-radius: var(--kb-radius-pill);
  font-size: 11px;
  font-weight: 700;
  color: var(--kb-text-muted);
  cursor: pointer;
  transition: all .15s;
}
.kb-day-tab:hover { background: #fff; color: var(--kb-text); }
.kb-day-tab.active {
  background: var(--kb-accent);
  color: #fff;
  box-shadow: none;
}

/* ── Status (inline) ────────────────────────────── */
.kb-status-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--kb-text-muted);
  margin: 8px 0 10px;
  min-height: 16px;
}
.kb-status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #d4d4d8;
  flex-shrink: 0;
}
.kb-status-inline.ready .kb-status-dot { background: #22c55e; }
.kb-status-inline.ready #status-text { color: #15803d; }
.kb-status-inline.error .kb-status-dot { background: #ef4444; }
.kb-status-inline.error #status-text { color: #b91c1c; }

.kb-status-bar { display: none; }

/* ── Results meta ───────────────────────────────── */
.kb-results-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.kb-score-bar { display: none; }
.kb-score-breakdown { display: none; }

/* ── Drawers (saved / export) ───────────────────── */
.kb-drawer {
  flex-shrink: 0;
  border-top: 1px solid var(--kb-border);
}
.kb-drawer-head {
  padding: 12px 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--kb-text-muted);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.kb-drawer-head::-webkit-details-marker { display: none; }
.kb-drawer-head::after {
  content: '＋';
  float: right;
  font-weight: 400;
  color: #a1a1aa;
}
.kb-drawer[open] .kb-drawer-head::after { content: '−'; }
.kb-drawer-body {
  padding: 0 20px 16px;
}
.kb-results-header {
  display: flex;
  align-items: center;
  gap: 8px;
}
.kb-results-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--kb-text);
  text-transform: none;
}
.kb-results-hint {
  font-size: 11px;
  color: var(--kb-text-muted);
  margin: 0 0 10px;
  line-height: 1.5;
}
.kb-badge-count {
  background: var(--kb-walk-soft);
  color: var(--kb-accent-fg);
  font-size: 12px;
  min-width: 22px;
  height: 22px;
  border-radius: 6px;
}

.kb-score-compact {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--kb-radius-sm);
  flex-shrink: 0;
  border: 1px solid transparent;
}
.kb-score-prefix {
  font-size: 10px;
  font-weight: 600;
  color: inherit;
  opacity: 0.85;
}
.kb-score-compact .kb-score-num {
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
}
.kb-score-compact .kb-score-lbl {
  font-size: 11px;
  font-weight: 600;
}
.kb-score--high {
  background: var(--kb-score-high-bg);
  color: var(--kb-score-high);
  border-color: #bbf7d0;
}
.kb-score--mid {
  background: var(--kb-score-mid-bg);
  color: var(--kb-score-mid);
  border-color: #fde68a;
}
.kb-score--low {
  background: var(--kb-score-low-bg);
  color: var(--kb-score-low);
  border-color: #fecaca;
}
.kb-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 17px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--kb-accent-soft);
  color: var(--kb-accent-fg);
  font-size: 10px;
  font-weight: 700;
}

.kb-results {
  flex: 1;
  overflow-y: auto;
  padding: 4px 2px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.kb-results::-webkit-scrollbar { width: 3px; }
.kb-results::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 2px; }

/* Empty state */
.kb-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 48px 24px;
  color: var(--kb-text-muted);
  text-align: center;
}
.kb-empty-state p { font-size: 13px; line-height: 1.7; margin: 0; }

/* ── Stop card ──────────────────────────────────── */
.kb-card {
  border: 1px solid var(--kb-border);
  border-radius: var(--kb-radius-sm);
  padding: 12px 14px;
  cursor: pointer;
  background: var(--kb-surface);
  transition: border-color .15s, box-shadow .15s;
  position: relative;
}
.kb-card:hover {
  border-color: var(--kb-border-strong);
  box-shadow: var(--kb-shadow);
}
.kb-card.on {
  border-color: var(--kb-accent);
  background: var(--kb-surface-2);
  box-shadow: var(--kb-shadow);
}

/* Card top row */
.kb-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.kb-card-num {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  color: var(--kb-accent-fg);
  background: var(--kb-walk-soft);
  border: 1.5px solid #93c5fd;
  border-radius: 50%;
}
.kb-card-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--kb-text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kb-card-walk {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  color: var(--kb-accent-fg);
  background: var(--kb-walk-soft);
  border: 1px solid #bfdbfe;
  padding: 5px 10px;
  border-radius: var(--kb-radius-sm);
  margin-bottom: 8px;
}
.kb-walk-time { font-weight: 700; }
.kb-walk-dist { font-variant-numeric: tabular-nums; }
.kb-walk-sep { color: #93c5fd; font-weight: 400; }
.kb-walk-routed,
.kb-walk-est {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  height: 18px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}
.kb-walk-routed {
  background: var(--kb-walk);
  color: #fff;
}
.kb-walk-est {
  background: #fff;
  color: var(--kb-text-muted);
  border: 1px solid var(--kb-border);
}

/* Route rows */
.kb-routes-head {
  font-size: 10px;
  font-weight: 700;
  color: var(--kb-text-muted);
  margin: 4px 0 4px;
}
.kb-routes { display: flex; flex-direction: column; gap: 4px; }
.kb-route-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  min-width: 0;
  padding: 4px 0;
  border-top: 1px solid var(--kb-border);
}
.kb-routes > .kb-route-row:first-child { border-top: none; padding-top: 0; }
.kb-route-tag {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 0 6px;
  height: 18px;
  border-radius: 4px;
  background: var(--kb-bus-soft);
  color: var(--kb-bus);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}
.kb-route-dest {
  color: var(--kb-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.kb-route-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}
.kb-route-count {
  color: var(--kb-text);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.kb-route-count small {
  font-size: 9px;
  font-weight: 600;
  color: var(--kb-text-muted);
  margin-left: 1px;
}
.kb-route-time {
  font-size: 10px;
  color: var(--kb-text-muted);
  white-space: nowrap;
}
.kb-route-more { font-size: 10px; color: #9ca3af; margin-top: 2px; padding-left: 2px; }

/* ── Export drawer ──────────────────────────────── */
.kb-export {
  flex-shrink: 0;
  border-top: 1px solid #e9ecef;
}
.kb-export-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 11.5px;
  font-weight: 600;
  color: #6b7280;
  cursor: pointer;
  user-select: none;
  background: #f9fafb;
  transition: background .1s, color .1s;
}
.kb-export-header:hover { background: #f3f4f6; color: #374151; }
.kb-chevron { margin-left: auto; transition: transform .2s; }
.kb-export-header[aria-expanded="true"] .kb-chevron { transform: rotate(180deg); }

.kb-export-body {
  display: none;
  flex-direction: column;
  gap: 7px;
  padding: 0 9px 10px;
}
.kb-export-body.open { display: flex; }

.kb-textarea {
  width: 100%;
  border: 1.5px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 11.5px;
  line-height: 1.7;
  resize: vertical;
  background: #f9fafb;
  color: #1f2937;
  font-family: inherit;
  box-sizing: border-box;
  min-height: 100px;
}
.kb-textarea:focus {
  outline: none;
  background: #fff;
  border-color: var(--kb-accent-hover);
  box-shadow: 0 0 0 3px rgba(99,102,241,.1);
}

.kb-export-btns { display: flex; gap: 5px; flex-wrap: wrap; }
.kb-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
  height: 32px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  white-space: nowrap;
  transition: opacity .12s, transform .1s, box-shadow .12s;
}
.kb-btn:hover  { opacity: .88; }
.kb-btn:active { transform: scale(.97); }
.kb-btn.primary {
  background: var(--kb-accent);
  color: #fff;
  box-shadow: none;
  border-radius: var(--kb-radius-sm);
}
.kb-btn.primary:hover { background: var(--kb-accent-hover); }
.kb-btn.secondary {
  background: #fff;
  color: #374151;
  border: 1.5px solid #e5e7eb;
}

/* ══════════════════════════════════════════════════
   MAP AREA
   ══════════════════════════════════════════════════ */
.kb-map-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-width: 0;
}
.kb-map {
  width: 100%;
  height: 100%;
  background: #e9ecef;
}
.kb-map-veil {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  pointer-events: none;
}

/* Coord HUD */
.kb-coord-hud {
  position: absolute;
  bottom: 28px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 2px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(6px);
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 4px 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
  z-index: 400;
}
.kb-coord-input {
  width: 88px;
  border: none;
  background: transparent;
  font-size: 11px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  color: #374151;
  text-align: center;
}
.kb-coord-input:focus { outline: none; color: var(--kb-accent); }
.kb-coord-sep { font-size: 11px; color: #d1d5db; }

/* ── Leaflet control overrides (Google Maps 風) ──── */
.leaflet-control-zoom {
  border: none !important;
  box-shadow: 0 1px 4px rgba(0,0,0,.18) !important;
}
.leaflet-control-zoom-in,
.leaflet-control-zoom-out {
  width: 30px !important;
  height: 30px !important;
  line-height: 30px !important;
  font-size: 16px !important;
  font-weight: 400 !important;
  color: #374151 !important;
  background: #fff !important;
  border-radius: 6px !important;
  border: 1px solid rgba(0,0,0,.15) !important;
  transition: background .12s !important;
}
.leaflet-control-zoom-in { margin-bottom: 2px !important; }
.leaflet-control-zoom-in:hover,
.leaflet-control-zoom-out:hover { background: #f3f4f6 !important; }
.leaflet-control-scale-line {
  border: 1.5px solid #374151 !important;
  border-top: none !important;
  background: rgba(255,255,255,.8) !important;
  backdrop-filter: blur(4px) !important;
  padding: 2px 5px !important;
  font-size: 10px !important;
  font-weight: 600 !important;
  color: #374151 !important;
  border-radius: 0 0 4px 4px !important;
}

/* ── Map action buttons ─────────────────────────── */
.kb-map-btns {
  position: absolute;
  top: 82px;          /* ズームコントロールの下 */
  left: 10px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.kb-map-ctrl-btn {
  width: 30px;
  height: 30px;
  background: #fff;
  border: 1px solid rgba(0,0,0,.18);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #374151;
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
  transition: background .12s, box-shadow .12s;
  padding: 0;
}
.kb-map-ctrl-btn:hover:not(:disabled) {
  background: #f3f4f6;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
}
.kb-map-ctrl-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── Context menu ────────────────────────────────── */
.kb-ctx-menu {
  position: fixed;
  z-index: 9000;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
  padding: 4px 0;
  min-width: 168px;
  font-size: 12.5px;
}
.kb-ctx-item {
  width: 100%;
  padding: 7px 14px;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  color: #1f2937;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
}
.kb-ctx-item:hover { background: #f5f3ff; color: var(--kb-accent); }
.kb-ctx-sep {
  height: 1px;
  background: #f3f4f6;
  margin: 3px 0;
}
.kb-ctx-coords {
  padding: 4px 14px 5px;
  font-size: 10.5px;
  color: #9ca3af;
  font-family: 'JetBrains Mono', monospace;
}

/* ── Scroll hint overlay ─────────────────────────── */
.kb-scroll-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 800;
  background: rgba(0,0,0,.65);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  pointer-events: none;
  white-space: nowrap;
  backdrop-filter: blur(4px);
  transition: opacity .3s;
}

/* ── Map style switcher ──────────────────────────── */
.kb-style-switcher {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 2px;
  z-index: 400;
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(8px);
  border: 1px solid #e5e7eb;
  border-radius: 9px;
  padding: 3px;
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
}
.kb-style-btn {
  height: 24px;
  padding: 0 6px;
  border: none;
  background: transparent;
  border-radius: 5px;
  font-size: 10.5px;
  font-weight: 600;
  color: #6b7280;
  cursor: pointer;
  transition: background .12s, color .12s;
  white-space: nowrap;
  flex: 1;
  text-align: center;
}
.kb-style-btn:hover { background: #f0f0f0; color: #374151; }
.kb-style-btn.active                           { background: var(--kb-accent); color: #fff; }
.kb-style-btn[data-style="dark"].active        { background: #1e1b4b; color: #a5b4fc; }
.kb-style-btn[data-style="satellite"].active   { background: #374151; color: #fbbf24; }

/* ── Location info bar ──────────────────────────── */
.kb-loc-info {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 10px 12px;
  margin-top: 12px;
  background: var(--kb-surface-2);
  border: 1px solid var(--kb-border);
  border-radius: var(--kb-radius-sm);
}
.kb-loc-text { min-width: 0; }
.kb-loc-place {
  font-size: 12px;
  font-weight: 600;
  color: #1f2937;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kb-loc-coords {
  font-size: 10.5px;
  color: #6b7280;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  margin-top: 1px;
}

/* ── Expand button ──────────────────────────────── */
.kb-expand-btn {
  width: 100%;
  padding: 4px 0;
  border: none;
  background: none;
  font-size: 10.5px;
  color: var(--kb-accent-hover);
  cursor: pointer;
  text-align: center;
  font-weight: 500;
}
.kb-expand-btn:hover { text-decoration: underline; }
.kb-routes-extra { border-top: 1px dashed #e5e7eb; padding-top: 2px; }

/* ── Search mode tabs ───────────────────────────── */
.kb-search-mode {
  display: flex;
  padding: 0 12px 8px;
  gap: 0;
}
.kb-mode-tab {
  flex: 1;
  height: 28px;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  font-size: 11.5px;
  font-weight: 500;
  color: #6b7280;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
  line-height: 1;
}
.kb-mode-tab:first-child { border-radius: 6px 0 0 6px; }
.kb-mode-tab:last-child  { border-radius: 0 6px 6px 0; border-left: none; }
.kb-mode-tab.active {
  background: var(--kb-accent);
  color: #fff;
  border-color: var(--kb-accent);
}

/* ── Saved properties ───────────────────────────── */
.kb-props-section {
  padding: 6px 12px 8px;
  border-bottom: 1px solid #f0f0f0;
}
.kb-props-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}
.kb-btn-xs {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 22px;
  padding: 0 8px;
  border: 1px solid #d1d5db;
  background: #fff;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 500;
  color: #4b5563;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.kb-btn-xs:hover { background: #f3f4f6; border-color: #9ca3af; }
.kb-btn-xs.primary {
  background: var(--kb-accent);
  color: #fff;
  border-color: var(--kb-accent);
}
.kb-btn-xs.primary:hover { background: var(--kb-accent-fg); }

.kb-save-form {
  display: flex;
  gap: 5px;
  align-items: center;
  margin-bottom: 6px;
}
.kb-prop-input {
  flex: 1;
  height: 26px;
  padding: 0 8px;
  border: 1px solid #d1d5db;
  border-radius: 5px;
  font-size: 12px;
  outline: none;
}
.kb-prop-input:focus { border-color: var(--kb-accent-hover); box-shadow: 0 0 0 2px rgba(99,102,241,.15); }

.kb-props-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 130px;
  overflow-y: auto;
}
.kb-props-empty {
  font-size: 11px;
  color: #9ca3af;
  padding: 2px 0;
}
.kb-prop-chip {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
  transition: box-shadow .12s;
}
.kb-prop-chip:hover { box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.kb-prop-name {
  flex: 1;
  min-width: 0;
  height: 28px;
  padding: 0 10px;
  background: transparent;
  border: none;
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: #1f2937;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kb-prop-name:hover { background: #f5f3ff; color: var(--kb-accent); }
.kb-prop-del {
  width: 28px;
  height: 28px;
  border: none;
  border-left: 1px solid #f0f0f0;
  background: transparent;
  font-size: 13px;
  color: #9ca3af;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.kb-prop-del:hover { background: #fee2e2; color: #ef4444; }

/* ── Spinners ────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }

.kb-spin-xs {
  display: inline-block;
  width: 12px; height: 12px;
  border: 1.5px solid #e5e7eb;
  border-top-color: var(--kb-accent-hover);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
.kb-spin-md {
  display: inline-block;
  width: 28px; height: 28px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--kb-accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ── Toast ───────────────────────────────────────── */
.kb-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  z-index: 9999;
  pointer-events: none;
  transition: opacity .25s;
  white-space: nowrap;
}
.kb-toast.fade { opacity: 0; }

/* ── Walk route badge (legacy; walk info in .kb-card-walk) ─ */
.kb-walk-line { filter: drop-shadow(0 2px 4px rgba(37, 99, 235, 0.35)); }

/* ── Icon buttons (title bar) ────────────────────── */
.kb-icon-btn {
  width: 28px;
  height: 28px;
  border: 1.5px solid var(--kb-border);
  background: #fff;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--kb-text-muted);
  transition: background .12s, color .12s, border-color .12s, transform .1s;
  padding: 0;
}
.kb-icon-btn:hover {
  background: var(--kb-accent-soft);
  color: var(--kb-accent-fg);
  border-color: #93c5fd;
  transform: scale(1.04);
}

/* ── History panel ───────────────────────────────── */
.kb-history-panel {
  position: fixed;
  top: calc(var(--kb-header-h) + var(--kb-shell-pad));
  left: var(--kb-shell-pad);
  width: min(320px, calc(100vw - var(--kb-shell-pad) * 2));
  z-index: 800;
  background: var(--kb-surface);
  border: 1px solid var(--kb-border);
  border-radius: var(--kb-radius);
  box-shadow: var(--kb-shadow-lg);
  padding: 12px 14px 14px;
  max-height: 240px;
  overflow-y: auto;
}
.kb-history-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: #9ca3af;
  margin-bottom: 5px;
}
.kb-history-empty { font-size: 11px; color: #9ca3af; }
.kb-history-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: #374151;
  transition: background .1s;
}
.kb-history-item:hover { background: var(--kb-accent-soft); color: var(--kb-accent); }
.kb-history-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.kb-history-item-coords { font-size: 10px; color: #9ca3af; flex-shrink: 0; }
.kb-history-clear {
  width: 100%;
  margin-top: 5px;
  font-size: 10.5px;
  color: #9ca3af;
  background: none;
  border: none;
  cursor: pointer;
  text-align: right;
  padding: 0;
}
.kb-history-clear:hover { color: #ef4444; }

/* ── Transit Score bar ───────────────────────────── */
.kb-score-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 9px;
  background: linear-gradient(135deg, #fff5f9 0%, #f0f9ff 100%);
  border-bottom: 1px solid var(--kb-border);
}
.kb-score-left { flex-shrink: 0; text-align: center; min-width: 36px; }
.kb-score-num {
  font-size: 24px;
  font-weight: 900;
  color: var(--kb-accent);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.kb-score-lbl { font-size: 9px; color: var(--kb-accent-fg); font-weight: 700; margin-top: 2px; white-space: nowrap; }
.kb-score-breakdown { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.kb-score-seg { display: grid; grid-template-columns: 28px 1fr 22px; align-items: center; gap: 5px; }
.kb-score-seg-label { font-size: 9.5px; color: var(--kb-text-muted); font-weight: 600; }
.kb-score-seg-bar {
  height: 6px;
  background: #fce7f3;
  border-radius: var(--kb-radius-pill);
  overflow: hidden;
}
.kb-score-seg-fill {
  height: 100%;
  border-radius: 99px;
  transition: width .4s ease;
  width: 0%;
}
.kb-score-seg-val { font-size: 9px; color: #6b7280; text-align: right; font-variant-numeric: tabular-nums; }

/* ── Night bus / early bus badges ───────────────── */
.kb-badge-night {
  display: inline-flex;
  align-items: center;
  padding: 0 5px;
  height: 16px;
  border-radius: 4px;
  background: var(--kb-night-bg);
  color: var(--kb-night);
  font-size: 9px;
  font-weight: 700;
  flex-shrink: 0;
}
.kb-badge-early {
  display: inline-flex;
  align-items: center;
  padding: 0 5px;
  height: 16px;
  border-radius: 4px;
  background: var(--kb-early-bg);
  color: var(--kb-early);
  font-size: 9px;
  font-weight: 700;
  flex-shrink: 0;
}
.kb-badge-service {
  display: inline-flex;
  align-items: center;
  padding: 0 5px;
  height: 16px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--kb-night-bg) 50%, var(--kb-early-bg) 50%);
  color: var(--kb-night);
  font-size: 9px;
  font-weight: 700;
  flex-shrink: 0;
  white-space: nowrap;
}
.kb-badge-cluster {
  display: inline-flex;
  align-items: center;
  padding: 0 4px;
  height: 14px;
  border-radius: 3px;
  background: #e0f2fe;
  color: #0369a1;
  font-size: 8.5px;
  font-weight: 700;
  flex-shrink: 0;
}

/* ── Hourly frequency chart ──────────────────────── */
.kb-freq-wrap {
  margin-bottom: 8px;
  padding: 6px 8px;
  background: var(--kb-surface-2);
  border: 1px solid var(--kb-border);
  border-radius: var(--kb-radius-sm);
}
.kb-freq-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--kb-text-muted);
  margin-bottom: 4px;
}
.kb-freq-chart {
  display: flex;
  align-items: flex-end;
  gap: 1px;
  height: 28px;
}
.kb-freq-bar {
  flex: 1;
  background: #bfdbfe;
  border-radius: 2px 2px 0 0;
  min-height: 1px;
  cursor: default;
  transition: background .1s;
}
.kb-freq-bar.peak { background: var(--kb-walk); }
.kb-freq-bar:hover { background: #1d4ed8; }
.kb-freq-hours {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--kb-text-muted);
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

/* ── Output tabs ─────────────────────────────────── */
.kb-out-tabs {
  display: flex;
  gap: 0;
  padding: 0 0 7px;
  border-bottom: 1px solid #f0f0f0;
  margin-bottom: 7px;
}
.kb-out-tab {
  flex: 1;
  height: 26px;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
  cursor: pointer;
  transition: all .12s;
  line-height: 1;
}
.kb-out-tab:first-child { border-radius: 5px 0 0 5px; }
.kb-out-tab:not(:first-child) { border-left: none; }
.kb-out-tab:last-child { border-radius: 0 5px 5px 0; }
.kb-out-tab.active { background: var(--kb-accent); color: #fff; border-color: var(--kb-accent); }

.kb-out-panel { display: flex; flex-direction: column; gap: 6px; }
.kb-out-desc { font-size: 11px; color: #6b7280; line-height: 1.6; margin: 0; }
.kb-mono { font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace; font-size: 10.5px; }

/* ── QR area ─────────────────────────────────────── */
.kb-qr-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px;
  background: #f9fafb;
  border: 1px dashed #e5e7eb;
  border-radius: 8px;
}
.kb-qr-img { width: 120px; height: 120px; border-radius: 4px; }
.kb-qr-hint { font-size: 10px; color: #9ca3af; margin: 0; text-align: center; }

/* ── Command Palette ─────────────────────────────── */
.kb-cmd-palette {
  position: fixed;
  inset: 0;
  z-index: 99000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
}
.kb-cmd-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(2px);
}
.kb-cmd-box {
  position: relative;
  width: 480px;
  max-width: calc(100vw - 32px);
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,.25), 0 0 0 1px rgba(0,0,0,.08);
  overflow: hidden;
}
.kb-cmd-search-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid #f3f4f6;
}
.kb-cmd-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  color: #111827;
  background: transparent;
}
.kb-cmd-input::placeholder { color: #9ca3af; }
.kb-cmd-list {
  list-style: none;
  margin: 0;
  padding: 6px 0;
  max-height: 320px;
  overflow-y: auto;
}
.kb-cmd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  cursor: pointer;
  font-size: 13px;
  color: #1f2937;
  transition: background .08s;
}
.kb-cmd-item:hover,
.kb-cmd-item.focus { background: #f5f3ff; color: var(--kb-accent); }
.kb-cmd-item svg { flex-shrink: 0; opacity: .6; }
.kb-cmd-item:hover svg,
.kb-cmd-item.focus svg { opacity: 1; }
.kb-cmd-item-hint { margin-left: auto; font-size: 10.5px; color: #9ca3af; }
.kb-cmd-footer {
  padding: 8px 16px;
  font-size: 10.5px;
  color: #9ca3af;
  border-top: 1px solid #f3f4f6;
  text-align: center;
}

/* ── Route shape highlight button on route tag ───── */
.kb-route-tag.clickable { cursor: pointer; }
.kb-route-tag.clickable:hover { background: var(--kb-bus); color: #fff; }

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 700px) {
  body.page-kyoto-bus { overflow: auto; height: auto; }
  body.page-kyoto-bus .site-wrapper { height: auto; }
  body.page-kyoto-bus .site-main { padding: 10px !important; }
  .kb-shell { height: auto; }
  .kb { flex-direction: column; height: auto; min-height: 70vh; }
  .kb-sidebar { width: 100%; min-width: unset; }
  .kb-map-area { height: 360px; }
  .kb-results { max-height: 280px; }
  .kb-coord-hud { display: none; }
}

/* ── About page ───────────────────────────────────── */
body.page-kyoto-bus-about .site-main {
  overflow: auto !important;
  padding: var(--kb-shell-pad) !important;
}

.kb-site-title-link {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--kb-text);
  text-decoration: none;
}
.kb-site-title-link:hover { color: var(--kb-accent-fg); }

.kb-about {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 4px 48px;
  font-family: var(--kb-font);
  color: var(--kb-text);
  line-height: 1.7;
}
.kb-about-title {
  font-size: 22px;
  font-weight: 800;
  margin: 0 0 12px;
}
.kb-about-lead {
  font-size: 15px;
  color: var(--kb-text-muted);
  margin: 0 0 28px;
}
.kb-about-section {
  margin-bottom: 24px;
}
.kb-about-section h2 {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--kb-text);
}
.kb-about-section ul {
  margin: 0;
  padding-left: 1.2em;
  font-size: 14px;
}
.kb-about-section li { margin-bottom: 4px; }
.kb-about-section p {
  font-size: 14px;
  margin: 0;
  color: var(--kb-text-muted);
}
.kb-about-note {
  margin-top: 8px !important;
  font-size: 13px !important;
}
.kb-about-code {
  margin: 8px 0 0;
  padding: 12px 14px;
  background: #f4f4f5;
  border: 1px solid #e4e4e7;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.5;
}
.kb-about-code code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #18181b;
  white-space: pre;
}
.kb-about-section a {
  color: var(--kb-accent-fg);
}
.kb-about-footer {
  margin-top: 32px;
}
