/* =========================================================
   方域大陆 Leon's 地铁换乘系统 —— 样式表
   ========================================================= */
:root {
  --bg: #eef1f6;
  --panel: #ffffff;
  --ink: #1f2733;
  --ink-soft: #5b6675;
  --ink-faint: #98a2b3;
  --line: #e3e8ef;
  --brand: #0044e3;
  --brand-soft: #e8efff;
  --accent: #ff3d71;
  --ok: #00a862;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(20, 30, 60, .08);
  --shadow-sm: 0 2px 8px rgba(20, 30, 60, .06);
}

* { box-sizing: border-box; }

/* 所有线路徐章 / 色块上的文字统一为白色（并加轻微阴影，保证在浅色线路上也清晰） */
.badge, .chip {
  color: #fff !important;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB",
               "Noto Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 顶栏 ---------- */
.app-header {
  height: 60px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  background: linear-gradient(90deg, #0033b8, #0055ff 55%, #2f7bff);
  color: #fff;
  box-shadow: 0 2px 12px rgba(0, 40, 140, .25);
  position: relative;
  z-index: 20;
}
.app-header .logo {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: rgba(255, 255, 255, .18);
  display: grid; place-items: center;
  font-size: 19px;
  flex: 0 0 auto;
}
.app-header h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 700;
  letter-spacing: .5px;
}
.app-header .sub {
  font-size: 12px;
  opacity: .78;
  font-weight: 400;
  letter-spacing: 1px;
}
.app-header .spacer { flex: 1; }
.app-header .hint {
  font-size: 12.5px;
  opacity: .9;
  background: rgba(255, 255, 255, .12);
  padding: 6px 12px;
  border-radius: 20px;
}

/* ---------- 主体布局 ---------- */
.app-body {
  display: flex;
  height: calc(100% - 60px);
}

.sidebar {
  width: 384px;
  flex: 0 0 384px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
}

/* ---------- 查询控件 ---------- */
.controls {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fbfcff, #ffffff);
}

.station-field {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  padding: 9px 12px;
  transition: border-color .18s, box-shadow .18s;
}
.station-field:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.station-field + .station-field { margin-top: 10px; }
.station-field .dot {
  width: 13px; height: 13px;
  border-radius: 50%;
  border: 3px solid var(--ink-faint);
  flex: 0 0 auto;
}
.station-field.origin .dot { border-color: var(--ok); background: #d8f7e7; }
.station-field.dest .dot { border-color: var(--accent); background: #ffe1ea; }
.station-field input {
  flex: 1;
  border: 0;
  outline: 0;
  font-size: 15px;
  font-family: inherit;
  color: var(--ink);
  background: transparent;
  min-width: 0;
}
.station-field input::placeholder { color: var(--ink-faint); }
.station-field .clear {
  border: 0; background: transparent; cursor: pointer;
  color: var(--ink-faint); font-size: 16px; line-height: 1;
  padding: 2px 4px; border-radius: 6px; visibility: hidden;
}
.station-field .clear:hover { background: #f0f2f6; color: var(--ink); }
.station-field.filled .clear { visibility: visible; }

/* 起终点 + 交换按钮 */
.od-wrap { display: flex; align-items: center; gap: 10px; }
.od-fields { flex: 1; min-width: 0; }
.swap-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  display: grid; place-items: center;
  color: var(--ink-soft);
  box-shadow: var(--shadow-sm);
  transition: transform .3s, color .18s, border-color .18s;
  flex: 0 0 auto;
  font-size: 17px;
}
.swap-btn:hover { color: var(--brand); border-color: var(--brand); transform: rotate(180deg); }

/* 自动补全下拉 */
.ac-list {
  position: absolute;
  left: 0; right: 0;
  top: calc(100% + 6px);
  max-height: 288px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(20, 30, 60, .16);
  z-index: 30;
  padding: 5px;
}
.ac-list[hidden] { display: none; }
.ac-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 9px;
  cursor: pointer;
}
.ac-item.active, .ac-item:hover { background: var(--brand-soft); }
.ac-item .ac-name { font-size: 14.5px; font-weight: 600; color: var(--ink); }
.ac-item .ac-id { font-size: 11px; color: var(--ink-faint); font-family: ui-monospace, Menlo, Consolas, monospace; }
.ac-item .ac-lines { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; max-width: 52%; }
.ac-empty { padding: 16px; text-align: center; color: var(--ink-faint); font-size: 13.5px; }

/* 偏好设置 */
.prefs {
  margin-top: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.prefs .label { font-size: 13px; color: var(--ink-soft); flex: 0 0 auto; }
.seg {
  display: inline-flex;
  background: #f1f3f7;
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
  flex: 1;
}
.seg button {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 7px 4px;
  border-radius: 7px;
  font-size: 13px;
  font-family: inherit;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all .18s;
  white-space: nowrap;
}
.seg button.active {
  background: #fff;
  color: var(--brand);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

/* ---------- 结果区 ---------- */
.result {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px 28px;
}
.result::-webkit-scrollbar, .ac-list::-webkit-scrollbar { width: 9px; }
.result::-webkit-scrollbar-thumb, .ac-list::-webkit-scrollbar-thumb {
  background: #d3d9e3; border-radius: 6px; border: 2px solid #fff;
}
.result::-webkit-scrollbar-thumb:hover { background: #bcc4d1; }

.empty-state {
  text-align: center;
  color: var(--ink-faint);
  padding: 60px 20px;
}
.empty-state .emoji { font-size: 46px; margin-bottom: 14px; opacity: .55; }
.empty-state p { font-size: 14px; line-height: 1.9; margin: 0; }
.empty-state b { color: var(--ink-soft); font-weight: 600; }

.error-card {
  background: #fff4f4;
  border: 1px solid #ffd6d6;
  color: #d33;
  padding: 16px;
  border-radius: 12px;
  font-size: 14px;
  text-align: center;
  line-height: 1.7;
}

/* 概览卡片 */
.summary {
  display: flex;
  align-items: stretch;
  gap: 1px;
  background: var(--line);
  border-radius: 13px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-bottom: 8px;
}
.summary .cell {
  flex: 1;
  background: #fff;
  padding: 13px 8px;
  text-align: center;
}
.summary .cell .v { font-size: 21px; font-weight: 800; color: var(--ink); line-height: 1.1; }
.summary .cell .v small { font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-left: 1px; }
.summary .cell .k { font-size: 11.5px; color: var(--ink-faint); margin-top: 5px; }
.summary .cell.hl .v { color: var(--brand); }

.route-od {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-soft);
  margin: 14px 2px 6px;
}
.route-od b { color: var(--ink); font-size: 15px; font-weight: 700; }
.route-od .arrow { color: var(--ink-faint); }

/* 线路预览条 */
.line-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  padding: 12px 2px 6px;
  margin-bottom: 6px;
}
.line-strip .chip {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 11px;
  border-radius: 12px;
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .3px;
  box-shadow: var(--shadow-sm);
}
.line-strip .walk-chip {
  background: #8a94a6;
  display: inline-flex; align-items: center; gap: 4px;
}
.line-strip .sep { color: var(--ink-faint); font-size: 12px; }

/* 行程步骤 */
.steps { margin-top: 6px; }
.step { display: flex; gap: 0; }

.step-node {
  flex: 0 0 34px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.step-node .marker {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 3.5px solid var(--ink-faint);
  background: #fff;
  flex: 0 0 auto;
  z-index: 1;
}
.step.start .marker { border-color: var(--ok); background: #d8f7e7; }
.step.end .marker { border-color: var(--accent); background: #ffe1ea; }
.step.transfer .marker { border-color: #f5a623; background: #fff2d8; width: 18px; height: 18px; }
.step-node .track {
  width: 5px;
  flex: 1;
  min-height: 14px;
  margin: 2px 0;
  border-radius: 3px;
  background: #dfe4ec;
}
.step:last-child .step-node .track { display: none; }

.step-body { flex: 1; padding: 0 0 18px 6px; min-width: 0; }

.step-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}
.step-head .badge {
  display: inline-flex;
  align-items: center;
  height: 21px;
  padding: 0 9px;
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}
.step-head .sid {
  font-size: 11px;
  color: var(--ink-faint);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-weight: 500;
}

.step-desc {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 5px;
  line-height: 1.6;
}
.step-desc .walk { color: #6b7280; }
.step-desc .toward { color: var(--ink); font-weight: 600; }
.step-head .ride-n { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.step-head .ep-label { font-size: 12.5px; font-weight: 800; margin-right: 2px; }
.xfer-tag {
  display: inline-flex; align-items: center; height: 20px; padding: 0 8px;
  border-radius: 6px; font-size: 11.5px; font-weight: 700;
}
.xfer-tag.in { background: #fff2d8; color: #b8791a; }
.step-node .track.walk-track {
  background: repeating-linear-gradient(#ff8fab 0 6px, #ffffff 6px 12px);
}

/* 途经站折叠 */
.via-toggle {
  margin-top: 8px;
  border: 0;
  background: #f3f5f9;
  color: var(--ink-soft);
  font-size: 12.5px;
  font-family: inherit;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .18s;
}
.via-toggle:hover { background: #e9edf4; }
.via-toggle .caret { transition: transform .2s; font-size: 10px; }
.via-toggle.open .caret { transform: rotate(90deg); }
.via-list { margin-top: 9px; padding-left: 4px; }
.via-list[hidden] { display: none; }
.via-item {
  position: relative;
  padding: 4px 0 4px 20px;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  border-radius: 6px;
}
.via-item::before {
  content: "";
  position: absolute;
  left: 5px; top: 50%;
  transform: translateY(-50%);
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #fff;
  border: 2.5px solid currentColor;
  opacity: .5;
}
.via-item::after {
  content: "";
  position: absolute;
  left: 8.5px; top: -6px;
  width: 2px; height: 12px;
  background: currentColor; opacity: .25;
}
.via-item:first-child::after { display: none; }
.via-item:hover { background: #f5f7fb; color: var(--ink); }

/* ---------- 地图 ---------- */
.map-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  user-select: none;               /* 拖动地图时不选中站名等文字 */
  -webkit-user-select: none;
  background:
    radial-gradient(circle at 30% 20%, #f7f9fc, #e9edf4 70%);
}
#map-container { position: absolute; inset: 0; }
.map-wrap svg {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}
.map-wrap svg.dragging { cursor: grabbing; }

/* 可点击的站点 */
#metro-map [data-station-id] { cursor: pointer; }

/* 站点悬浮光晕 */
.station-halo {
  fill: var(--brand);
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
}
.station-halo.show { opacity: .22; }

/* 路线高亮：底衬光晕 */
.route-glow {
  fill: none;
  stroke: #ffd400;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .55;
  pointer-events: none;
}
.route-glow.walk {
  stroke: #ff5c8a;
  stroke-dasharray: 16 12;
  opacity: .8;
}
/* 路线高亮：主描边 */
.route-stroke {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
.route-stroke.walk { stroke-dasharray: 14 10; }

/* 端点大标记 */
.endpoint-ring {
  fill: none;
  stroke-width: 6;
  pointer-events: none;
}
.endpoint-ring.origin { stroke: var(--ok); }
.endpoint-ring.dest { stroke: var(--accent); }

/* 有路线时淡化其余元素 */
#metro-map.has-route [data-line-type],
#metro-map.has-route [data-station-id] {
  opacity: .16;
  transition: opacity .3s;
}
#metro-map.has-route [data-station-id].on-route,
#metro-map.has-route g[data-line-type].on-route,
#metro-map.has-route line[data-line-type].on-route,
#metro-map.has-route path[data-line-type].on-route {
  opacity: 1;
}
#metro-map [data-line-type],
#metro-map [data-station-id] { transition: opacity .3s; }

/* 地图工具按钮 */
.map-tools {
  position: absolute;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 5;
}
.map-tools button {
  width: 42px; height: 42px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .95);
  backdrop-filter: blur(6px);
  cursor: pointer;
  font-size: 20px;
  color: var(--ink-soft);
  box-shadow: var(--shadow);
  display: grid; place-items: center;
  transition: all .15s;
  font-family: inherit;
}
.map-tools button:hover { color: var(--brand); border-color: var(--brand); transform: translateY(-1px); }
.map-tools button:active { transform: translateY(0); }
.map-tools button.text-btn { font-size: 14px; font-weight: 700; }

/* 地图提示气泡 */
.map-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(28, 34, 46, .94);
  color: #fff;
  padding: 7px 11px;
  border-radius: 9px;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
  z-index: 15;
  opacity: 0;
  transform: translate(-50%, -120%);
  transition: opacity .12s;
  white-space: nowrap;
}
.map-tooltip.show { opacity: 1; }
.map-tooltip .tt-name { font-weight: 700; font-size: 13.5px; }
.map-tooltip .tt-lines { opacity: .82; font-size: 11.5px; margin-top: 2px; }
.map-tooltip .tt-hint { opacity: .6; font-size: 11px; margin-top: 3px; }

.map-legend {
  position: absolute;
  left: 18px;
  bottom: 18px;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 13px;
  font-size: 12px;
  color: var(--ink-soft);
  box-shadow: var(--shadow-sm);
  z-index: 5;
  line-height: 1.9;
}
.map-legend .row { display: flex; align-items: center; gap: 7px; }
.map-legend .swatch { width: 20px; height: 0; border-top-width: 4px; border-top-style: solid; border-radius: 2px; }
.map-legend .swatch.walk { border-top-style: dashed; border-top-color: #ff5c8a; }
.map-legend .swatch.ride { border-top-color: #ffd400; }

/* 加载遮罩 */
.loading-mask {
  position: absolute;
  inset: 0;
  background: rgba(238, 241, 246, .82);
  display: grid;
  place-items: center;
  z-index: 40;
  font-size: 15px;
  color: var(--ink-soft);
  gap: 12px;
}
.loading-mask[hidden] { display: none; }
.spinner {
  width: 34px; height: 34px;
  border: 3.5px solid var(--brand-soft);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  body { overflow: auto; }
  .app-body { flex-direction: column; height: auto; }
  .sidebar { width: 100%; flex: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .result { max-height: none; }
  .map-wrap { height: 70vh; flex: none; }
  .app-header .hint { display: none; }
}
