:root {
  --bg: #0f1216;
  --bg-elev: #161b22;
  --bg-elev-2: #1c232c;
  --border: #262e39;
  --border-strong: #364150;
  --text: #e6edf3;
  --text-dim: #8b97a6;
  --text-faint: #6b7684;
  --accent: #4a9eff;
  --accent-soft: rgba(74, 158, 255, .12);
  --up: #e5534b;      /* 涨（红色，中国市场惯例） */
  --down: #3fb950;    /* 跌（绿色） */
  --warn: #d29922;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --radius: 10px;
}

body.light {
  --bg: #f4f6f9;
  --bg-elev: #ffffff;
  --bg-elev-2: #f7f9fb;
  --border: #dfe4ea;
  --border-strong: #c6ced8;
  --text: #1a2029;
  --text-dim: #5b6774;
  --text-faint: #808b98;
  --accent: #1a6fd4;
  --accent-soft: rgba(26, 111, 212, .1);
  --up: #cf3a30;
  --down: #2a8a3e;
  --shadow: 0 1px 3px rgba(16,24,40,.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.icon { width: 16px; height: 16px; fill: currentColor; flex: none; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 22px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 30px; height: 30px; fill: var(--accent); flex: none; }
.brand-text h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: .3px; }
.brand-text p { margin: 1px 0 0; font-size: 12px; color: var(--text-faint); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.status-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 12px; border-radius: 999px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim); white-space: nowrap;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); flex: none; }
.dot.ok { background: var(--down); }
.dot.busy { background: var(--accent); animation: pulse 1s infinite; }
.dot.err { background: var(--up); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.ro-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: 999px;
  background: var(--accent-soft); border: 1px solid var(--accent);
  color: var(--accent); font-size: 12px; font-weight: 500; white-space: nowrap;
}
.ro-badge .icon { width: 13px; height: 13px; }

/* ---------- 最后查询时间（实时心跳） ---------- */
.lastrun {
  display: inline-flex; align-items: baseline; gap: 7px;
  padding: 5px 12px; border-radius: 999px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  font-size: 12px; white-space: nowrap;
  transition: border-color .25s, background .25s;
}
.lastrun .lr-label { color: var(--text-faint); font-size: 11.5px; }
.lastrun .lr-time {
  color: var(--text); font-weight: 600;
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum";
}
.lastrun .lr-ago {
  color: var(--text-dim); font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
/* 数据新鲜：绿色边 */
.lastrun:not(.idle):not(.stale):not(.stale-bad) { border-color: rgba(63,185,80,.5); }
.lastrun:not(.idle) .lr-ago { color: var(--down); }
/* 数据偏旧：黄色边 */
.lastrun.stale { border-color: rgba(210,153,34,.6); }
.lastrun.stale .lr-ago { color: var(--warn); }
/* 数据陈旧（疑似中断）：红色边 */
.lastrun.stale-bad { border-color: rgba(229,83,75,.7); background: rgba(229,83,75,.08); }
.lastrun.stale-bad .lr-ago { color: var(--up); font-weight: 600; }
.lastrun.idle { opacity: .65; }

/* 只读模式：条件区改为只读观感 */
body.readonly .card:first-of-type { background: var(--bg-elev); }
body.readonly .card:first-of-type .grid { opacity: .78; }

/* ---------- 布局 ---------- */
.layout {
  max-width: 1180px; margin: 0 auto; padding: 20px 22px 48px;
  display: flex; flex-direction: column; gap: 16px;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px 20px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.card-head h2 {
  margin: 0; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 8px; color: var(--text);
}
.card-head h2 .icon { fill: var(--text-faint); }
.hint { font-size: 12px; color: var(--text-faint); }

/* 查询记录的口径说明 */
.rec-note {
  margin: -6px 0 12px;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--text-faint);
}
.rec-note:empty { display: none; }
.head-tools { display: flex; align-items: center; gap: 10px; }

/* ---------- 表单 ---------- */
.grid {
  display: grid; gap: 12px 14px;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field-wide { grid-column: span 2; }
.field > span { font-size: 12px; color: var(--text-dim); }
input, select {
  width: 100%; padding: 8px 10px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 6px;
  font: inherit; font-size: 13px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.actions { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.msg { font-size: 12px; color: var(--text-dim); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 15px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: var(--bg-elev-2);
  color: var(--text); font: inherit; font-size: 13px; cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.btn-primary:hover:not(:disabled) { opacity: .88; color: #fff; }
.btn-ghost { padding: 7px; border-radius: 6px; }
.btn-sm { padding: 5px 11px; font-size: 12px; }

.seg { display: inline-flex; background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 6px; padding: 2px; }
.seg-btn {
  padding: 5px 12px; border: 0; border-radius: 4px; background: transparent;
  color: var(--text-dim); font: inherit; font-size: 12px; cursor: pointer;
}
.seg-btn.is-on { background: var(--accent); color: #fff; }

/* ---------- 最新价格 ---------- */
.latest-body { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.price-card {
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg-elev-2); padding: 15px 17px;
}
.price-card.is-low { border-color: var(--down); }
.price-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 3px; }
.flight-no { font-size: 19px; font-weight: 650; letter-spacing: .5px; }
.price-total { font-size: 23px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.price-total .cur { font-size: 14px; font-weight: 600; margin-right: 1px; }
.price-meta { font-size: 12px; color: var(--text-faint); margin-bottom: 12px; }
.price-break { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 5px; font-size: 11.5px;
  background: var(--bg); border: 1px solid var(--border); color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.chip b { color: var(--text); font-weight: 600; }
.tag { padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.tag.low { background: rgba(63,185,80,.15); color: var(--down); }
.tag.high { background: rgba(229,83,75,.15); color: var(--up); }
.delta { font-size: 12px; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.flat { color: var(--text-faint); }

.alert {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 11px 13px; border-radius: 7px; font-size: 12.5px;
  background: rgba(210,153,34,.1); border: 1px solid rgba(210,153,34,.3);
  color: var(--warn);
}
.alert.err { background: rgba(229,83,75,.1); border-color: rgba(229,83,75,.32); color: var(--up); }
.alert svg { width: 15px; height: 15px; fill: currentColor; flex: none; margin-top: 2px; }

.empty { color: var(--text-faint); font-size: 13px; text-align: center; padding: 22px 0; margin: 0; }

/* ---------- 图表 ---------- */
.chart-wrap { position: relative; height: 290px; }
.chart-wrap canvas { width: 100% !important; }

/* 极值标识条 */
.extremes {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-top: 14px; padding-top: 14px;
  border-top: 1px solid var(--border);
}
.ex-item {
  display: flex; flex-direction: column; gap: 3px;
  padding: 9px 13px; border-radius: 8px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-left-width: 3px;
}
.ex-hi { border-left-color: var(--up); }
.ex-lo { border-left-color: var(--down); }
.ex-gap { border-left-color: var(--text-faint); }
.ex-tag { font-size: 11.5px; color: var(--text-dim); }
.ex-val { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.25; }
.ex-hi .ex-val { color: var(--up); }
.ex-lo .ex-val { color: var(--down); }
.ex-flight { font-size: 11.5px; color: var(--text-faint); }

/* ---------- 记录表 ---------- */
.table-scroll { overflow-x: auto; }
.rec-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.rec-table th {
  text-align: left; font-weight: 600; color: var(--text-dim);
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.rec-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.rec-table tr:last-child td { border-bottom: 0; }
.rec-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.status { font-size: 11.5px; padding: 2px 7px; border-radius: 4px; }
.status.ok { background: rgba(63,185,80,.14); color: var(--down); }
.status.partial { background: rgba(210,153,34,.14); color: var(--warn); }
.status.failed { background: rgba(229,83,75,.14); color: var(--up); }
.trigger { font-size: 11px; color: var(--text-faint); }

.foot {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  color: var(--text-faint); font-size: 11.5px; padding: 2px 4px;
}

@media (max-width: 640px) {
  .layout { padding: 14px 12px 40px; }
  .topbar { padding: 10px 14px; }
  .field-wide { grid-column: span 1; }
  .card { padding: 15px 14px 17px; }
}

/* ---------- 移动端顶栏 ----------
   问题：右侧新增「最后查询」块后，横向 flex 把左侧标题挤成竖排（一字一行）。
   方案：品牌区独占第一行并禁止换行，状态区整体换到第二行，
        主题按钮作为 topbar 直接子元素留在第一行末尾。
   -------------------------------------------------------------------------- */
@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 10px;
    padding: 10px 14px;
  }
  /* 品牌区：占满第一行，内部标题永不换行 */
  .brand {
    flex: 1 1 auto;
    min-width: 0;
    order: 1;
  }
  .brand-text { min-width: 0; }
  .brand-text h1 {
    font-size: 15px;
    white-space: nowrap;          /* 关键：禁止标题被压成竖排 */
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .brand-text p {
    font-size: 11.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .logo { width: 26px; height: 26px; }

  /* 主题按钮：第一行末尾 */
  .btn-theme {
    order: 2;
    flex: none;
    margin-left: auto;
    width: 32px; height: 32px;
    padding: 0;
  }

  /* 状态区：整体换到第二行 */
  .topbar-right {
    order: 3;
    flex: 1 0 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 6px 8px;
    min-width: 0;
  }
  .topbar-right > * { min-width: 0; }

  /* 「最后查询」块：压缩为一行，隐藏标签文字 */
  .lastrun {
    padding: 4px 10px;
    font-size: 11.5px;
    gap: 5px;
    max-width: 100%;
  }
  .lastrun .lr-label { display: none; }
  .lastrun .lr-time { font-size: 11.5px; }

  .status-pill { padding: 4px 10px; font-size: 11.5px; }
  .ro-badge { padding: 3px 9px; font-size: 11.5px; }
}

/* 极窄屏（iPhone SE 等）：进一步精简 */
@media (max-width: 380px) {
  .topbar { padding: 9px 12px; }
  .brand-text h1 { font-size: 14px; }
  .lastrun .lr-time { display: none; }   /* 只留相对时间 */
}
