:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #657282;
  --line: #d8dee8;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --warn: #fff8df;
  --warn-line: #e9cd78;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  line-height: 1.5;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 58px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex-wrap: wrap;
}

.top-actions a,
.link-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  min-height: 34px;
  padding: 6px 10px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 800;
}

.top-actions form {
  margin: 0;
}

.link-button {
  cursor: pointer;
}

.top-actions a:hover,
.link-button:hover {
  border-color: var(--accent);
  background: rgba(15, 118, 110, 0.08);
  color: var(--accent-dark);
}

.user-pill {
  border: 1px solid rgba(15, 118, 110, 0.22);
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.08);
  padding: 5px 10px;
  color: var(--accent-dark) !important;
  font-size: 13px;
  font-weight: 800;
}

.brand {
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
  text-decoration: none;
}

.topbar span,
p,
label,
.route-head span,
.leg-meta,
.summary span,
.ai-summary span,
.ai-summary p {
  color: var(--muted);
}

.page {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.panel,
.notice,
.route-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel {
  padding: 22px;
  margin-bottom: 18px;
}

.search-panel {
  position: sticky;
  top: 70px;
  z-index: 40;
  padding-bottom: 22px;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.06);
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

h1,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: 28px;
}

.search-form-shell {
  max-height: 520px;
  overflow: visible;
  opacity: 1;
  transform: translateY(0);
  transition: max-height 180ms linear, opacity 180ms linear, transform 180ms linear;
}

.search-panel.is-filter-collapsed .search-form-shell {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
}

.search-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 14px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea,
button {
  min-height: 42px;
  border-radius: 6px;
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  padding: 8px 10px;
  color: var(--ink);
  background: #ffffff;
}

.station-picker {
  position: relative;
  display: block;
}

.station-panel {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 1000;
  width: min(760px, calc(100vw - 56px));
  max-height: 460px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.16);
  padding: 12px 14px;
}

.station-panel[hidden] {
  display: none;
}

.station-panel-title {
  border-bottom: 1px solid #eef1f5;
  padding: 4px 0 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.station-panel-title strong {
  color: #2f80ff;
}

.station-tabs {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin: 0 -14px 10px;
  background: #eef6ff;
}

.station-tabs button {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 9px 6px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  font-weight: 800;
  min-height: 40px;
}

.station-tabs button:hover {
  background: rgba(47, 128, 255, 0.08);
  color: #2f80ff;
}

.station-tabs .is-active {
  border-bottom: 3px solid #2f80ff;
  color: #2f80ff;
}

.station-hot-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(62px, 1fr));
  gap: 6px 10px;
}

.station-directory-grid {
  display: grid;
  gap: 10px;
}

.station-letter-group {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.station-letter-group > strong {
  color: #2f80ff;
  font-size: 14px;
  line-height: 34px;
}

.station-letter-group > div {
  display: grid;
  grid-template-columns: repeat(6, minmax(72px, 1fr));
  gap: 4px 10px;
}

.station-hot-grid button,
.station-letter-group button,
.station-match {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  min-height: 34px;
  padding: 6px 8px;
  text-align: left;
  font-weight: 700;
}

.station-hot-grid button:hover,
.station-letter-group button:hover,
.station-match:hover {
  background: #e7f2ff;
  color: #2f80ff;
}

.station-match {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  width: 100%;
  border-bottom: 1px solid #f0f3f7;
  border-radius: 0;
  font-size: 15px;
}

.station-match em {
  color: var(--muted);
  font-style: normal;
  font-weight: 600;
}

.station-empty {
  padding: 16px 4px;
  color: var(--muted);
}

textarea {
  min-height: 86px;
  resize: vertical;
}

textarea:disabled {
  background: #f3f5f8;
  color: var(--muted);
  cursor: not-allowed;
}

.ai-field {
  grid-column: span 4;
}

.form-hint {
  grid-column: 1 / -1;
  margin: 0;
  border-radius: 6px;
  background: rgba(15, 118, 110, 0.08);
  padding: 9px 10px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
}

.ai-login-hint {
  background: #f8fbff;
  color: var(--muted);
}

.filter-collapse-bar {
  display: flex;
  justify-content: center;
  margin: 18px 0 0;
}

.filter-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 999px;
  background: #ffffff !important;
  color: var(--accent-dark) !important;
  padding: 4px 12px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.filter-toggle:hover {
  border-color: rgba(15, 118, 110, 0.25);
  background: rgba(15, 118, 110, 0.08) !important;
}

.search-panel.is-filter-collapsed {
  padding-top: 16px;
  padding-bottom: 16px;
}

.search-panel.is-filter-collapsed .section-head {
  margin-bottom: 0;
}

.search-panel.is-filter-collapsed h1 {
  margin-bottom: 0;
  font-size: 22px;
}

.search-panel.is-filter-collapsed .section-head p {
  display: none;
}

.search-panel.is-filter-collapsed .filter-collapse-bar {
  margin-top: 12px;
}

.filter-toggle-text {
  font-size: 13px;
  font-weight: 800;
  color: var(--accent-dark) !important;
}

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font-weight: 800;
  padding: 9px 14px;
}

button:hover {
  background: var(--accent-dark);
}

.notice {
  margin-bottom: 18px;
  padding: 12px 14px;
  border-color: var(--warn-line);
  background: var(--warn);
}

.notice p {
  margin: 0;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  gap: 12px;
}

.summary div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.summary span,
.summary strong {
  display: block;
}

.summary strong {
  margin-top: 4px;
  font-size: 18px;
}

.ai-summary {
  display: grid;
  gap: 12px;
}

.ai-summary strong {
  display: block;
  margin-top: 4px;
}

.ai-notes {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
}

.ai-notes li + li {
  margin-top: 4px;
}

.results {
  display: grid;
  gap: 14px;
}

.route-card {
  overflow: hidden;
}

.route-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 16px 18px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.route-head:hover {
  background: #f4f8fb;
}

.detail-cue {
  flex: 0 0 auto;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
}

.route-overview {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(180px, 1.2fr) minmax(120px, 1fr);
  align-items: center;
  gap: 18px;
  width: 100%;
}

.route-endpoint strong {
  display: block;
  color: var(--ink);
  font-size: 34px;
  line-height: 1;
}

.route-endpoint span {
  display: block;
  margin-top: 8px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
}

.route-end {
  text-align: right;
}

.route-mid {
  display: grid;
  justify-items: center;
  gap: 6px;
  color: var(--muted);
  text-align: center;
}

.route-duration {
  color: var(--muted);
  font-size: 15px;
  font-weight: 800;
}

.transfer-points {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.transfer-chip,
.direct-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid rgba(15, 118, 110, 0.25);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 2px 10px;
  font-size: 17px;
  font-weight: 900;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.transfer-waits {
  color: var(--muted);
  font-size: 15px;
  font-weight: 800;
}

.route-card.is-open .detail-cue::after {
  content: "（收起）";
  color: var(--muted);
  font-weight: 600;
}

.legs {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.legs li {
  display: grid;
  grid-template-columns: minmax(112px, max-content) minmax(0, 1fr);
  gap: 16px;
  padding: 14px 18px;
  border-top: 1px solid #eef1f5;
  align-items: start;
}

.legs li:first-child {
  border-top: 0;
}

.leg-train {
  align-self: start;
  min-width: 76px;
  max-width: 168px;
  border: 1px solid rgba(15, 118, 110, 0.24);
  border-radius: 6px;
  background: rgba(15, 118, 110, 0.08);
  padding: 8px 10px;
  color: var(--accent-dark);
  text-align: center;
  font-weight: 900;
  line-height: 1.2;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.leg-main {
  min-width: 0;
}

.station-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  font-size: 16px;
}

.station-row strong {
  font-size: 18px;
}

.arrow {
  color: var(--muted);
}

.leg-meta {
  margin-top: 4px;
  font-size: 13px;
}

.leg-meta em {
  display: inline-block;
  margin-left: 10px;
  color: var(--accent-dark);
  font-style: normal;
  font-weight: 800;
}

.route-detail {
  display: grid;
  gap: 12px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  padding: 18px;
  padding-top: 0;
  padding-bottom: 0;
  border-top: 1px solid var(--line);
  background: #fff;
  transform: translateY(-8px);
  transition: max-height 180ms linear, opacity 180ms linear, transform 180ms linear, padding-top 180ms linear, padding-bottom 180ms linear;
}

.route-card.is-open .route-detail {
  max-height: 1100px;
  opacity: 1;
  padding-top: 18px;
  padding-bottom: 18px;
  transform: translateY(0);
}

.detail-leg {
  min-width: 0;
  margin-top: 6px;
}

.detail-leg h3 {
  margin: 0 0 14px;
  font-size: 16px;
  line-height: 1.35;
}

.rail-train-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -2px 0 12px;
}

.rail-train-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid color-mix(in srgb, var(--leg-color) 28%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--leg-color) 8%, #ffffff);
  padding: 6px 10px;
}

.rail-train-legend i {
  width: 18px;
  border-top: 3px dashed var(--leg-color);
}

.rail-train-legend strong {
  color: var(--leg-color);
  font-size: 14px;
  font-weight: 900;
}

.rail-train-legend em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
}

.detail-transfer {
  display: inline-flex;
  margin-bottom: 10px;
  border-radius: 6px;
  background: rgba(15, 118, 110, 0.08);
  padding: 5px 8px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
}

.rail-scroll {
  overflow-x: auto;
  padding: 4px 0 10px;
}

.rail-map {
  --rail-stop-width: 156px;
  display: grid;
  grid-template-rows: auto 28px auto;
  min-width: max(100%, calc(var(--stop-count) * var(--rail-stop-width)));
}

.rail-run-row,
.rail-line-row,
.rail-time-row {
  display: grid;
  grid-template-columns: repeat(var(--stop-count), var(--rail-stop-width));
}

.rail-stop-name {
  min-width: 0;
  padding-right: 16px;
  font-size: 14px;
  line-height: 1.35;
}

.rail-stop-name strong,
.rail-stop-name span,
.rail-time strong,
.rail-time span,
.rail-time em {
  display: block;
}

.rail-stop-name strong {
  color: var(--text);
}

.rail-stop-name span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.rail-transfer-note {
  color: var(--accent-dark) !important;
  font-weight: 800;
}

.rail-line-row {
  align-items: center;
}

.rail-segment {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 28px;
}

.rail-segment::after {
  content: "";
  position: absolute;
  left: 10px;
  right: -2px;
  top: 50%;
  border-top: 3px dashed var(--segment-color);
  transform: translateY(-50%);
}

.rail-segment:last-child::after {
  display: none;
}

.rail-node {
  position: relative;
  z-index: 2;
  width: 10px;
  height: 10px;
  border: 2px solid var(--leg-color);
  border-radius: 50%;
  background: #fff;
}

.rail-node.is-transfer {
  width: 14px;
  height: 14px;
  background: var(--leg-color);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--leg-color) 14%, transparent);
}

.rail-time {
  padding-right: 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.rail-time strong {
  color: var(--text);
  font-size: 16px;
}

.rail-time em {
  color: var(--accent-dark);
  font-style: normal;
  font-weight: 900;
}

.detail-empty {
  margin: 0;
  color: var(--muted);
}

.auth-page {
  display: grid;
  min-height: calc(100vh - 58px);
  place-items: start center;
}

.auth-card {
  width: min(460px, 100%);
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-switch {
  margin: 16px 0 0;
}

.auth-switch a {
  color: var(--accent-dark);
  font-weight: 800;
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.admin-table th,
.admin-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  white-space: nowrap;
}

.admin-table th {
  color: var(--muted);
  font-size: 13px;
}

.small-button {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 13px;
}

.muted-text {
  color: var(--muted);
}

@media (max-width: 900px) {
  .search-form,
  .summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ai-field {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
    padding: 12px 18px;
  }

  .top-actions {
    margin-left: 0;
  }

  .page {
    padding: 18px;
  }

  .search-panel {
    top: 110px;
  }

  .search-form,
  .summary {
    grid-template-columns: 1fr;
  }

  .legs li {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .leg-train {
    min-width: 0;
    max-width: 100%;
    justify-self: start;
  }

  .route-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .route-overview {
    grid-template-columns: 1fr auto 1fr;
    gap: 10px;
  }

  .route-endpoint strong {
    font-size: 26px;
  }

  .route-endpoint span {
    font-size: 15px;
  }

  .route-duration,
  .transfer-waits {
    font-size: 13px;
  }

  .transfer-chip,
  .direct-chip {
    min-height: 24px;
    padding: 1px 8px;
    font-size: 15px;
  }

  .route-detail {
    padding: 14px;
  }

  .rail-map {
    --rail-stop-width: 138px;
  }
}
