/* ========== 基础 ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f7f8fa;
  --card-bg: #ffffff;
  --text: #1a1a1a;
  --text-sub: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --bargain: #dc2626;
  --lv1: #10b981;   /* 低于阈值 - 绿 */
  --lv2: #a7f3d0;   /* 阈值~1.3× - 浅绿 */
  --lv3: #fde68a;   /* 1.3~1.6× - 黄 */
  --lv4: #fca5a5;   /* >1.6× - 红 */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  min-height: 100vh;
}

/* ========== 顶部栏 ========== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #ffffff;   /* 实色，不用 backdrop-filter（iOS Safari 会破坏点击命中） */
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.topbar .title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 4px;
}
.status-line {
  font-size: 12px;
  color: var(--text-sub);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.status-line .dot { color: #d1d5db; }
.state-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}
.state-normal  { background: #d1fae5; color: #065f46; }
.state-slow    { background: #fef3c7; color: #92400e; }
.state-aborted { background: #fee2e2; color: #991b1b; }
.state-login_expired,
.state-captcha { background: #fee2e2; color: #991b1b; }

/* ========== Tab 栏 ========== */
.tabbar {
  position: sticky;
  top: 62px;   /* = topbar 高度，防遮挡 */
  z-index: 15;
  background: #ffffff;
  display: flex;
  justify-content: flex-start;   /* 不用 center（横滑会裁掉左侧项） */
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
}
.tab {
  background: none;
  border: none;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text-sub);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 500;
}

/* ========== 主内容 ========== */
.content {
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}
.view { display: none; }
.view.active { display: block; }

.view-header {
  margin-bottom: 16px;
}
.view-header h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.view-header .sub {
  font-size: 12px;
  color: var(--text-sub);
}
.count-badge {
  background: var(--bargain);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
}

/* ========== 捡漏榜 ========== */
.bargain-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 700px) {
  .bargain-list { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1000px) {
  .bargain-list { grid-template-columns: repeat(3, 1fr); }
}
.bargain-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.1s, box-shadow 0.1s;
}
.bargain-card:active { transform: scale(0.98); }
.bargain-card .route {
  font-size: 15px;
  font-weight: 600;
}
.bargain-card .date {
  font-size: 13px;
  color: var(--text-sub);
}
.bargain-card .price-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 4px;
}
.bargain-card .price {
  font-size: 24px;
  font-weight: 700;
  color: var(--bargain);
}
.bargain-card .threshold {
  font-size: 12px;
  color: var(--text-sub);
  text-decoration: line-through;
}
.bargain-card .discount {
  background: #fef2f2;
  color: var(--bargain);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}
.bargain-card .meta {
  font-size: 12px;
  color: var(--text-sub);
  display: flex;
  justify-content: space-between;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}
.bargain-card .direct-tag {
  background: #dbeafe;
  color: var(--accent-dark);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
}
.bargain-card .transit-tag {
  background: #f3f4f6;
  color: var(--text-sub);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
}
.bargain-card a.book-link {
  display: block;
  text-align: center;
  padding: 8px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  margin-top: 4px;
}
.bargain-card a.book-link:active { background: var(--accent-dark); }

.empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-sub);
  background: var(--card-bg);
  border-radius: 10px;
  border: 1px dashed var(--border);
}

/* ========== 热力图 ========== */
.heatmap-explain {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
  line-height: 1.6;
}
.heatmap-explain p {
  margin-bottom: 8px;
  color: var(--text);
}
.heatmap-explain ul {
  list-style: none;
  padding-left: 0;
}
.heatmap-explain li {
  margin-bottom: 4px;
  color: var(--text-sub);
}
.heatmap-explain li strong {
  color: var(--text);
}

.trip-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.trip-btn {
  padding: 6px 14px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 13px;
  color: var(--text-sub);
  cursor: pointer;
}
.trip-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.heatmap-wrap {
  overflow-x: auto;      /* 表格用 block + overflow-x 横滑 */
  -webkit-overflow-scrolling: touch;
  background: var(--card-bg);
  border-radius: 10px;
  padding: 12px;
  border: 1px solid var(--border);
}
.heatmap {
  display: grid;
  grid-template-columns: 80px repeat(90, minmax(28px, 1fr));
  gap: 2px;
  min-width: 2600px;   /* 保证横滑而不是压缩 */
}
.heatmap .row-label {
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  padding-right: 8px;
  color: var(--text);
  position: sticky;
  left: 0;
  background: var(--card-bg);
  z-index: 2;
}
.heatmap .col-label {
  font-size: 10px;
  color: var(--text-sub);
  text-align: center;
  padding-bottom: 4px;
}
.heatmap .cell {
  aspect-ratio: 1;
  border-radius: 3px;
  cursor: pointer;
  position: relative;
  min-height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: rgba(0,0,0,0.55);
  font-weight: 500;
}
.heatmap .cell.lv1 { background: var(--lv1); color: #fff; }
.heatmap .cell.lv2 { background: var(--lv2); }
.heatmap .cell.lv3 { background: var(--lv3); }
.heatmap .cell.lv4 { background: var(--lv4); }
.heatmap .cell.na  { background: #f3f4f6; color: #d1d5db; }
.heatmap .cell.peak::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 4px;
  height: 4px;
  background: rgba(0,0,0,0.4);
  border-radius: 50%;
}
.heatmap .cell:active { transform: scale(0.9); }

.legend {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-sub);
  flex-wrap: wrap;
}
.legend-item { display: flex; align-items: center; gap: 4px; }
.legend-item .cell {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

/* ========== 页脚 ========== */
.footer {
  padding: 20px 16px 30px;
  text-align: center;
  font-size: 12px;
  color: var(--text-sub);
  line-height: 1.8;
}
