/* 港铁下一班列车分析 —— 界面样式 */
:root {
  --mtr-red: #c8102e;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1c1f23;
  --muted: #6b7280;
  --accent: #185fa5;
  --teal: #0f6e56;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

/* 顶栏 */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 16px 28px;
  background: linear-gradient(90deg, #1c1f23 0%, #33383f 100%);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 52px; height: 52px; border-radius: 10px;
  background: var(--mtr-red); color: #fff;
  font-weight: 700; letter-spacing: 1px; font-size: 15px;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 600; }
.topbar .sub { margin: 2px 0 0; font-size: 12.5px; color: #b9bec6; }
.status {
  display: flex; align-items: center; gap: 9px; min-width: 126px;
  padding: 8px 12px; border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px; background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  white-space: nowrap;
}
.status-dot {
  width: 8px; height: 8px; flex: none; border-radius: 50%;
  background: #aeb4bd; box-shadow: 0 0 0 4px rgba(174, 180, 189, 0.12);
}
.status-copy { display: flex; flex-direction: column; line-height: 1.25; }
.status-copy strong { color: #f4f6f8; font-size: 12.5px; font-weight: 600; }
.status-copy small { color: #aeb4bd; font-size: 10.5px; }
.status.ok .status-dot {
  background: #63d6a5; box-shadow: 0 0 0 4px rgba(99, 214, 165, 0.14);
}
.status.bad .status-dot {
  background: #ff8585; box-shadow: 0 0 0 4px rgba(255, 133, 133, 0.14);
}
.status.bad .status-copy strong { color: #ffb0b0; }

/* 标签页 */
.tabs {
  display: flex; gap: 4px; padding: 0 28px;
  background: #fff; border-bottom: 1px solid var(--border);
}
.tab {
  border: none; background: none; cursor: pointer;
  padding: 13px 18px; font-size: 14px; color: var(--muted);
  border-bottom: 2px solid transparent; font-family: inherit;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--mtr-red); border-bottom-color: var(--mtr-red); font-weight: 600; }

main { max-width: 1180px; margin: 0 auto; padding: 22px 28px 48px; }
.panel { display: none; }
.panel.active { display: block; }

/* 卡片 */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px;
}
.card h2 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

/* 表单 */
.row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }
select, input {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; font-size: 13.5px; color: var(--text); font-family: inherit;
  min-width: 120px;
}
select:focus, input:focus { outline: 2px solid #cfe1f5; border-color: var(--accent); }

button {
  padding: 9px 18px; border-radius: 8px; font-size: 13.5px;
  cursor: pointer; font-family: inherit; border: 1px solid transparent;
}
button.primary { background: var(--mtr-red); color: #fff; font-weight: 600; }
button.primary:hover { background: #a80d26; }
button.ghost { background: #fff; border-color: var(--border); color: var(--text); }
button.ghost:hover { border-color: var(--muted); }
/* 采集按钮在采集期间 disabled，必须能一眼看出灰色（此前和普通状态几乎一样） */
button.ghost:disabled { background: #eceef2; border-color: #e3e6ea; color: var(--muted); cursor: default; }

.hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }

/* 指标卡 */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 860px) { .metrics { grid-template-columns: repeat(2, 1fr); } }
.metric {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.metric span { display: block; font-size: 12.5px; color: var(--muted); }
.metric strong { display: block; font-size: 24px; font-weight: 600; margin-top: 4px; }

/* 采集状态与最近数据时间 */
.collection-status-card { border-left: 4px solid var(--accent); }
.collection-status-actions { display: flex; align-items: center; gap: 10px; }
.collection-state {
  display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.collection-state.pending { color: #475467; background: #f2f4f7; }
.collection-state.ok { color: #067647; background: #eaf8f1; }
.collection-state.partial { color: #9a6700; background: #fff5d6; }
.collection-state.error { color: #b42318; background: #feeceb; }
.collection-state.stale { color: #9a6700; background: #fff1cc; }
.collection-status-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px;
}
.collection-status-grid > div {
  min-width: 0; padding: 11px 13px; border: 1px solid var(--border);
  border-radius: 9px; background: #fbfcfd;
}
.collection-status-grid span { display: block; color: var(--muted); font-size: 11.5px; }
.collection-status-grid strong {
  display: block; margin-top: 3px; overflow-wrap: anywhere; font-size: 14px; font-weight: 600;
}
.collection-history { margin-top: 15px; padding-top: 13px; border-top: 1px dashed var(--border); }
.collection-history-title { display: block; margin-bottom: 7px; font-size: 12.5px; }
.collection-history-scroll { overflow-x: auto; }
.collection-history-table { min-width: 590px; }
.collection-history-table td, .collection-history-table th { white-space: nowrap; }
.collection-history-empty { color: var(--muted); text-align: center; }
.history-status { font-weight: 600; }
.history-status.ok { color: #067647; }
.history-status.partial, .history-status.unknown { color: #9a6700; }
.history-status.error { color: #b42318; }
@media (max-width: 600px) {
  .collection-status-grid { grid-template-columns: 1fr; }
  .collection-status-card .card-head { align-items: flex-start; }
  .collection-status-actions { align-items: flex-end; flex-direction: column-reverse; gap: 5px; }
}

/* 数据表 */
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12.5px;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
}
table.data td { padding: 9px 10px; border-bottom: 1px solid #f0f2f5; }
table.data tr:last-child td { border-bottom: none; }
table.data td.ttnt { font-weight: 600; color: var(--mtr-red); }

.pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  background: #eef2f7; color: var(--accent); font-size: 11.5px; vertical-align: middle;
}

.result { margin-top: 16px; font-size: 14px; }
.result .big { font-size: 26px; font-weight: 600; }
.result .yes { color: var(--mtr-red); }
.result .no { color: var(--teal); }
.empty { color: var(--muted); padding: 18px 0; }

/* ---------- 多选线路选择器 ---------- */
.picker {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; background: #fbfcfd;
}
.picker-head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px;
}
.picker-title { font-size: 13px; font-weight: 600; }
.picker-count { font-size: 12.5px; color: var(--muted); margin-left: auto; padding-right: 4px; }
button.mini {
  padding: 4px 10px; font-size: 12px; border-radius: 6px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
}
button.mini:hover { border-color: var(--muted); }
.picker-lines {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(146px, 1fr));
  gap: 4px 12px;
}
.picker-lines label[hidden] { display: none; }
.picker-search-row { display: flex; gap: 8px; margin: 0 0 10px; }
.picker-search-input { flex: 1; min-width: 0; }
.picker-search-empty { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
label.chk {
  flex-direction: row; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text); cursor: pointer;
}
label.chk input[type="checkbox"] {
  min-width: 0; width: 14px; height: 14px; padding: 0; margin: 0; flex: none;
}
.inline-chk { align-items: center; padding-bottom: 9px; }

.picker-stations {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 10px; margin-top: 12px; padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.sta-row { display: flex; align-items: center; gap: 8px; }
.sta-line { font-size: 12.5px; color: var(--muted); white-space: nowrap; min-width: 96px; }
.sta-row select { flex: 1; min-width: 0; }

/* ---------- 图表容器 ---------- */
/* 高度由 JS 按分类行数动态设置，横向条形图才能一行行排开 */
.chart-box { position: relative; width: 100%; height: 260px; }
.chart-empty {
  position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center; text-align: center;
  padding: 0 20px;
}
.chart-note { font-size: 12px; color: var(--muted); margin: 10px 0 0; }
.min-sample-note { font-weight: 600; }

/* ---------- 实时到站 ---------- */
.live-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.live-head h2 { margin: 0; }
.live-meta { font-size: 12px; color: var(--muted); }
.live-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 860px) { .live-grid { grid-template-columns: 1fr; } }
.live-sub { font-size: 13px; font-weight: 600; margin: 0 0 8px; }

/* 常用查询与最近查询：仅保存在当前浏览器，不影响后端数据。 */
.query-shortcuts {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin-top: 14px; padding-top: 13px; border-top: 1px dashed var(--border);
}
.query-shortcuts section { min-width: 0; }
.shortcut-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 7px; color: var(--muted); font-size: 12px;
}
.shortcut-list { display: flex; flex-wrap: wrap; gap: 6px; }
.shortcut-chip {
  max-width: 100%; padding: 5px 9px; overflow: hidden; text-overflow: ellipsis;
  border: 1px solid #dbe2ea; border-radius: 999px; background: #f8fafc;
  color: #344054; font-size: 11.5px; white-space: nowrap;
}
.shortcut-chip:hover { border-color: var(--accent); color: var(--accent); }
.shortcut-empty { color: #9aa2ad; font-size: 11.5px; }
.text-button {
  padding: 0; border: 0; background: none; color: var(--accent); font-size: 11.5px;
}
.text-button:hover { text-decoration: underline; }
@media (max-width: 760px) { .query-shortcuts { grid-template-columns: 1fr; } }

/* ---------- 预测风险表 ---------- */
table.risk td.c-rank { color: var(--muted); width: 44px; }
table.risk td.c-prob { width: 170px; }
.prob-wrap { display: flex; align-items: center; gap: 8px; }
.prob-track {
  flex: 1; height: 6px; border-radius: 3px; background: #eef1f4; overflow: hidden;
}
.prob-fill { height: 100%; border-radius: 3px; background: var(--muted); }
.prob-fill.warm { background: #ba7517; }
.prob-fill.hot { background: var(--mtr-red); }
.badge {
  display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 11.5px;
  white-space: nowrap;
}
.badge.yes { background: #fcebeb; color: #a32d2d; }
.badge.no { background: #e1f5ee; color: #0f6e56; }
.badge.na { background: #f1efe8; color: #5f5e5a; }

/* ---------- 提示条 ---------- */
.hint.warn {
  color: #8a5a00; background: #fff8e6;
  border: 1px solid #f2e0b5; border-radius: 8px;
  padding: 9px 12px;
}

/* ---------- 卡片拖动排序 ---------- */
/* 只有 .drag-handle 是可拖的；整张卡片设 draggable 会抢走
   卡片里图表、下拉框、表格的正常交互 */
.sortable-stack { display: block; }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.card-head h2 { margin: 0; }

.drag-handle {
  flex: none; cursor: grab; user-select: none;
  padding: 4px 7px; border-radius: 6px;
  color: #b6bcc4; font-size: 15px; line-height: 1;
}
.drag-handle:hover { color: var(--muted); background: #f2f4f7; }
.drag-handle:active { cursor: grabbing; }
.drag-handle:focus-visible { outline: 2px solid #cfe1f5; }

/* 拖动中的卡片给一点反馈，方便看清落点 */
.card.dragging {
  opacity: 0.55;
  border-style: dashed;
  border-color: var(--accent);
}

/* 实时到站卡片：标题靠左，元信息与手柄靠右 */
.live-head h2 { margin-right: auto; }
.live-head .drag-handle { font-size: 14px; }

/* 正文里示范手柄长什么样 */
.handle-demo {
  display: inline-block; padding: 0 5px; border-radius: 4px;
  background: #f2f4f7; color: var(--muted); font-size: 12px;
}

/* 刷新按钮的忙碌态 */
button.primary:disabled { background: #cfd4da; cursor: default; }

/* ---------- 查询成功 / 失败反馈窗口 ---------- */
.notice-overlay[hidden] { display: none; }
.notice-overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(20, 25, 32, 0.42);
}
.notice-dialog {
  width: min(420px, 100%); background: #fff; border-radius: 14px;
  border: 1px solid var(--border); box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
  overflow: hidden;
}
.notice-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 18px 10px; border-left: 5px solid var(--accent);
}
.notice-dialog.success .notice-head { border-left-color: var(--teal); }
.notice-dialog.warning .notice-head { border-left-color: #ba7517; }
.notice-dialog.error .notice-head { border-left-color: var(--mtr-red); }
.notice-head h2 { margin: 0; font-size: 16px; }
.notice-close {
  padding: 0 5px; border: 0; background: transparent; color: var(--muted);
  font-size: 24px; line-height: 1; cursor: pointer;
}
.notice-close:hover { color: var(--text); }
.notice-dialog p { margin: 6px 22px 18px; color: var(--muted); line-height: 1.75; }
.notice-actions { display: flex; justify-content: flex-end; padding: 0 18px 16px; }

/* ---------- 回到顶部 ---------- */
.back-to-top {
  position: fixed; right: 24px; bottom: 24px; z-index: 12;
  display: flex; align-items: center; gap: 5px;
  padding: 10px 13px 10px 10px; border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px; background: #262b31; color: #fff;
  box-shadow: 0 8px 24px rgba(20, 25, 32, 0.2);
  opacity: 0; visibility: hidden; transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}
.back-to-top.visible { opacity: 1; visibility: visible; transform: translateY(0); }
.back-to-top:hover { background: var(--mtr-red); transform: translateY(-2px); }
.back-to-top:focus-visible { outline: 3px solid rgba(200, 16, 46, 0.28); outline-offset: 3px; }
.back-to-top svg {
  width: 19px; height: 19px; fill: none; stroke: currentColor;
  stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
}
.back-to-top span { font-size: 12.5px; font-weight: 600; }

@media (max-width: 600px) {
  .topbar { padding: 13px 16px; }
  .status { min-width: 0; padding: 8px 10px; }
  .status-copy small { display: none; }
  .back-to-top { right: 16px; bottom: 16px; padding: 10px; }
  .back-to-top span { display: none; }
}

/* ---------- 港铁总览 ---------- */
.overview-hero {
  display: flex; align-items: center; justify-content: space-between; gap: 22px;
  margin-bottom: 18px; padding: 22px 24px; border-radius: var(--radius);
  background: linear-gradient(118deg, #1c2735, #35465d); color: #fff;
}
.overview-eyebrow { margin: 0 0 4px; color: #a9c8f6; font-size: 11px; font-weight: 700; letter-spacing: 1.4px; }
.overview-hero h2 { margin: 0; font-size: 22px; }
.overview-hero p:not(.overview-eyebrow) { margin: 5px 0 0; color: #d5deea; font-size: 13px; }
.overview-summary {
  flex: none; min-width: 150px; padding: 12px 15px; border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px; background: rgba(255, 255, 255, 0.08); color: #dce9fb; font-size: 12.5px; line-height: 1.8;
}
.overview-summary strong { display: block; color: #fff; font-size: 17px; }
.overview-layout { display: grid; grid-template-columns: 1fr; gap: 18px; align-items: start; }
.overview-map-card, .overview-detail-card { margin-bottom: 0; }
.map-legend { color: var(--muted); font-size: 12px; }
.network-map-scroll { overflow-x: auto; border: 1px solid #e9edf2; border-radius: 10px; background: #f9fafc; }
.official-system-map { margin: 0; min-width: 760px; padding: 8px; }
.map-zoom-trigger { position: relative; display: block; width: 100%; padding: 0; border: 0; background: transparent; }
.official-system-map img { display: block; width: 100%; height: auto; border-radius: 5px; }
.map-zoom-trigger span {
  position: absolute; right: 12px; bottom: 12px; padding: 5px 9px; border-radius: 999px;
  background: rgba(25, 35, 49, 0.78); color: #fff; font-size: 11.5px; opacity: 0; transition: opacity 0.18s ease;
}
.map-zoom-trigger:hover span, .map-zoom-trigger:focus-visible span { opacity: 1; }
.map-zoom-trigger:focus-visible { outline: 3px solid rgba(24, 95, 165, 0.32); outline-offset: 3px; }
.official-system-map figcaption { padding: 8px 4px 1px; color: var(--muted); font-size: 11.5px; }
.official-system-map a { color: var(--accent); }
.map-overlay[hidden] { display: none; }
.map-overlay {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(16, 23, 32, 0.72);
}
.map-dialog { width: min(1480px, 100%); max-height: 100%; overflow: hidden; border-radius: 14px; background: #fff; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3); }
.map-dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.map-dialog-head h2 { margin: 0; font-size: 16px; }
.map-controls { display: flex; align-items: center; gap: 6px; }
.map-control { min-width: 31px; padding: 3px 8px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text); font-size: 17px; line-height: 1.2; }
.map-control:hover { border-color: var(--accent); color: var(--accent); }
.map-control.map-zoom-label { min-width: 54px; font-size: 12px; }
.map-dialog-body { max-height: calc(100vh - 145px); overflow: auto; padding: 12px; background: #f5f7fa; }
.map-dialog-body img { display: block; width: 100%; height: auto; min-width: 760px; max-width: none; }
.map-dialog p { margin: 0; padding: 9px 16px 12px; color: var(--muted); font-size: 11.5px; }
.overview-line-list { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 16px; }
.overview-line-button {
  padding: 5px 9px; border: 1px solid var(--line-color); border-radius: 999px;
  background: #fff; color: var(--line-color); font-size: 12px; font-weight: 700;
}
.overview-line-button:hover, .overview-line-button.active { background: var(--line-color); color: #fff; }
.overview-detail { border-top: 1px solid var(--border); padding-top: 16px; }
.overview-detail h3 { margin: 0; font-size: 18px; }
.overview-detail .en { margin: 1px 0 12px; color: var(--muted); font-size: 12px; }
.overview-facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; margin-bottom: 15px; }
.overview-fact { padding: 9px 10px; border-radius: 8px; background: #f5f7fa; }
.overview-fact span { display: block; color: var(--muted); font-size: 11px; }
.overview-fact strong { display: block; margin-top: 2px; color: var(--text); font-size: 13px; }
.station-flow { display: flex; flex-wrap: wrap; gap: 7px 5px; margin: 8px 0 15px; }
.station-chip { display: inline-flex; align-items: center; gap: 5px; color: #414b58; font-size: 12px; }
.station-chip:not(:last-child)::after { content: '→'; color: #aeb6c1; }
.station-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--line-color); }
.overview-open-live { width: 100%; }
@media (max-width: 860px) {
  .overview-hero { align-items: flex-start; flex-direction: column; }
}

/* 采集进度条（数据看板「立即采集一轮」下方） */
.collect-progress { margin-top: 4px; }
.collect-progress-track {
  height: 10px; border-radius: 6px; overflow: hidden;
  background: #e8ecf1; border: 1px solid var(--border);
}
.collect-progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), #38bdf8);
  border-radius: 6px;
  transition: width 0.45s ease;
}
.collect-progress p { margin: 6px 0 0; }
