* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #dbe2ea;
  --brand: #0f766e;
  --brand-soft: #e3f5f2;
  --warm: #fff1db;
}
body {
  font-family: "Segoe UI", "Hiragino Sans", sans-serif;
  background: linear-gradient(180deg, #eef6f4 0%, var(--bg) 100%);
  color: var(--ink);
}
.container { max-width: 1440px; margin: 0 auto; padding: 24px 18px 40px; }
h1 { text-align: center; margin: 18px 0 22px; font-size: 1.8rem; letter-spacing: 0.03em; }

/* --- タブ --- */
.tab-nav {
  display: flex;
  gap: 4px;
  margin-bottom: -1px;
  padding: 0 2px;
}
.tab-btn {
  padding: 10px 22px;
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  background: #eef2f6;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tab-btn.active {
  background: var(--card);
  color: var(--brand);
  border-color: var(--line);
}
.tab-btn:hover:not(.active) { background: #e2e8f0; color: var(--ink); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* --- カード --- */
.form-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 0 18px 18px 18px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.06);
  padding: 22px;
  margin-bottom: 18px;
}
.result-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.06);
  padding: 18px;
}

/* --- フォーム --- */
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.form-group { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 150px; }
.form-group label { font-size: 0.85rem; font-weight: 700; color: var(--muted); }
.service-group { min-width: 0; }
.service-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0;
  border: none;
  background: none;
}
.service-option {
  cursor: pointer;
  user-select: none;
}
.service-option input {
  display: none;
}
.service-option span {
  display: inline-block;
  padding: 5px 13px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--muted);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.service-option:hover span {
  border-color: var(--brand);
  color: var(--brand);
}
.service-option:has(input:checked) span {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
  box-shadow: 0 1px 4px rgba(15,118,110,0.25);
}
.input-wrap { position: relative; flex: 1.4; min-width: 180px; }
.sug-item { padding: 10px 14px; cursor: pointer; font-size: 0.95rem; }
.sug-item:hover, .sug-item.active { background: #f0f7ff; }
input, select {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 0.98rem;
  background: #fff;
  width: 100%;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12);
}
input::placeholder { color: #c0c8d2; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }
select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7' viewBox='0 0 12 7'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}
#target, [id^="between-target-"] {
  padding-left: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
  background-size: 16px 16px;
}
#multi-address {
  padding-left: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z'/%3E%3Ccircle cx='12' cy='10' r='3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
  background-size: 16px 16px;
}
button {
  padding: 12px 22px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.15s, background 0.15s, opacity 0.15s;
}
button:hover:not(:disabled) { filter: brightness(0.93); }
button:disabled {
  background: #d1d5db;
  color: #9ca3af;
  cursor: not-allowed;
  filter: none;
}

/* --- サジェスト --- */
#suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 10;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
}
#suggestions div { padding: 10px 12px; cursor: pointer; }
#suggestions div:hover { background: #f2fbfa; }

/* --- 多重・駅間フォーム --- */
.multi-origin-head {
  display: none;
  grid-template-columns: minmax(0, 0.82fr) 96px 132px;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}
.multi-origin-list { display: grid; gap: 10px; }
.multi-origin-row {
  display: grid;
  grid-template-columns: minmax(0, 0.82fr) 96px 132px;
  gap: 10px;
  align-items: end;
}
.multi-origin-row .form-group,
.multi-origin-head > span { min-width: 0; }
/* .compact-col label { display: none; } */
.multi-origin-row input,
.multi-origin-row select { width: 100%; }
.compact-col { flex: 0 0 auto; min-width: 90px; max-width: 140px; }
.area-status { font-size: 0.8rem; color: var(--muted); display: block; margin-top: 4px; }
.stack-note { font-size: 0.82rem; color: var(--muted); margin-top: 10px; }
.meta-note { font-size: 0.9rem; color: var(--muted); margin-bottom: 10px; }

/* --- 結果 --- */
.loading, .info, .error { text-align: center; padding: 36px 0; color: var(--muted); }
.error { color: #b91c1c; }
.loading-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 40px 0;
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--brand-soft);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-steps-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  font-size: 0.9rem;
}
.loading-step-item {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}
.loading-step-item.done { color: var(--brand); }
.loading-step-item.active { color: var(--ink); font-weight: 600; }
.step-icon { font-size: 1rem; width: 18px; text-align: center; }
.results-shell {
  display: grid;
  grid-template-columns: minmax(340px, 0.95fr) minmax(520px, 1.45fr);
  gap: 18px;
  align-items: start;
}
.result-main { min-width: 0; }
.result-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--brand-soft);
}
.result-header h2 { font-size: 1.5rem; line-height: 1.5; }
.count {
  background: var(--brand);
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 700;
}
.result-filter-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px 10px; margin: 10px 0 4px; }
.result-filter-bar label { font-size: 0.84rem; color: var(--muted); font-weight: 700; }
.result-filter-bar select { width: auto; min-width: 140px; max-width: 100%; }
.group-card { border: 1px solid var(--line); border-radius: 16px; margin-top: 14px; overflow: hidden; }
.group-card[data-line] > .group-head { cursor: pointer; }
.group-card[data-line] > .group-head::before {
  content: "▾";
  display: inline-block;
  font-size: 0.8rem;
  color: var(--muted);
  transition: transform 0.15s;
  margin-right: 4px;
}
.group-card[data-line].collapsed > .group-head::before { transform: rotate(-90deg); }
.group-card[data-line].collapsed > .group-head { border-bottom: none; }
.group-card[data-line].collapsed > *:not(.group-head) { display: none !important; }
.group-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #f8fbfb;
  border-bottom: 1px solid var(--line);
}
.group-title { display: flex; gap: 8px; align-items: center; font-weight: 700; flex-wrap: wrap; }
.service-badge {
  background: var(--brand-soft);
  color: var(--brand);
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
}
.line-service-select {
  width: auto;
  background: var(--brand-soft);
  color: var(--brand);
  border: 1px solid transparent;
  padding: 6px 24px 6px 12px;
  border-radius: 999px;
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path fill='%230891b2' d='M1 3l4 4 4-4z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.line-service-select:focus { outline: 2px solid var(--brand); outline-offset: 1px; box-shadow: none; }
table { width: 100%; border-collapse: collapse; }
th { background: #fbfcfd; text-align: left; padding: 10px 12px; font-size: 0.84rem; color: var(--muted); }
td { padding: 10px 12px; border-top: 1px solid #eef2f7; font-size: 0.92rem; vertical-align: top; }
tr:hover td { background: #fcfefe; }
.time-badge { background: #e8f7ef; color: #166534; padding: 2px 8px; border-radius: 8px; font-weight: 700; }
.transfer-badge { background: var(--warm); color: #9a3412; padding: 2px 8px; border-radius: 8px; font-weight: 700; }
.route { color: var(--muted); font-size: 0.84rem; word-break: break-word; }
.route-details summary { cursor: pointer; color: #2563eb; font-size: 0.82rem; list-style: none; display: inline-block; }
.route-details summary::-webkit-details-marker { display: none; }
.route-details summary::after { content: " ▼"; font-size: 0.7rem; }
.route-details[open] summary::after { content: " ▲"; }
.route-details .route { margin-top: 4px; }
.row-unreached td { color: #9ca3af; background: #fafbfc; }
.row-unreached-note { font-size: 0.84rem; }

/* --- マップ --- */
.map-panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fcfefe;
  overflow: hidden;
  position: sticky;
  top: 18px;
}
.map-panel h3 {
  padding: 12px 14px;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--line);
  background: #f8fbfb;
}
#map { height: 680px; width: 100%; }
.map-note {
  padding: 10px 14px;
  color: var(--muted);
  font-size: 0.84rem;
  border-top: 1px solid var(--line);
}
.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 10px 14px 0;
  color: var(--ink);
  font-size: 0.82rem;
}
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 2px solid #0f172a;
  display: inline-block;
}
.target-popup strong { color: var(--brand); }

/* --- 表示切替（multi） --- */
.view-switcher {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.view-btn {
  padding: 7px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
}
.view-btn.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.view-btn:hover:not(.active) { background: var(--brand-soft); color: var(--brand); }

/* --- テーブル/路線図切替 --- */
.view-mode-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
}
.view-mode-btn {
  padding: 6px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
}
.view-mode-btn.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.view-mode-btn:hover:not(.active) { background: var(--brand-soft); color: var(--brand); }

/* --- 路線図ビュー --- */
.lv-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}
.lv-chip {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
}
.lv-line {
  margin-bottom: 14px;
}
.lv-line[data-line] > .lv-line-name { cursor: pointer; }
.lv-line[data-line] > .lv-line-name::before {
  content: "▾";
  display: inline-block;
  font-size: 0.9rem;
  color: var(--muted);
  transition: transform 0.15s;
}
.lv-line[data-line].collapsed > .lv-line-name::before { transform: rotate(-90deg); }
.lv-line[data-line].collapsed > *:not(.lv-line-name) { display: none !important; }
.lv-line-name {
  font-size: 1.38rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.lv-stations {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.lv-station {
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: default;
  white-space: nowrap;
}
.lv-station:hover { opacity: 0.8; }
.lv-station-clickable { cursor: pointer; }

.popup-route-steps {
  margin-top: 4px;
  padding-left: 8px;
  border-left: 2px solid #cbd5e1;
  font-size: 0.82rem;
  line-height: 1.5;
  color: #475569;
}

.union-mode-toggle {
  display: inline-flex;
  gap: 4px;
  margin: 4px 0 12px;
  padding: 4px;
  border-radius: 999px;
  background: #f1f5f9;
}
.union-mode-btn {
  width: auto;
  padding: 6px 14px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.union-mode-btn:hover { filter: none; background: #e2e8f0; color: var(--ink); }
.union-mode-btn.active { background: var(--brand); color: #fff; }
.union-mode-btn.active:hover { background: var(--brand); color: #fff; }

/* --- レスポンシブ --- */
@media (max-width: 720px) {
  .results-shell { grid-template-columns: 1fr; }
  .multi-origin-head { display: none; }
  .multi-origin-row { grid-template-columns: 1fr; }
  .compact-col { max-width: 100%; }
  .compact-col label { display: flex; }
  .map-panel { position: static; }
  #map { height: 380px; }
  .result-header, .group-head { align-items: flex-start; flex-direction: column; }
  table, thead, tbody, tr, th, td { display: block; width: 100%; }
  thead { display: none; }
  td { padding: 8px 12px; }
  td::before { display: inline-block; width: 72px; color: var(--muted); font-weight: 700; }
  td:nth-child(1)::before { content: "駅名"; }
  td:nth-child(2)::before { content: "時間"; }
  td:nth-child(3)::before { content: "乗換"; }
  td:nth-child(4)::before { content: "経路"; }
  .result-filter-bar { flex-wrap: wrap; justify-content: flex-start; }
  .result-filter-bar select { min-width: 0; width: 100%; }
  .tab-btn { padding: 9px 12px; font-size: 0.82rem; }
  .tab-btn .full-label { display: none; }
  .tab-btn .short-label { display: inline; }
}
