:root {
  --bg: #0e1117;
  --card: #161b22;
  --border: #30363d;
  --fg: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --good: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
}
header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 10;
}
header h1 { margin: 0; font-size: 20px; }
.sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.runs { font-size: 11px; color: var(--muted); margin-top: 6px; }
.runs .ok { color: var(--good); }
.runs .warn { color: var(--warn); }
.runs .bad { color: var(--bad); }
.runs .muted { color: var(--muted); }
.runs .inflight { color: var(--accent); }
main { padding: 16px 24px 60px; }
section { margin-bottom: 32px; }
.tabs { display: flex; gap: 4px; margin-top: 12px; flex-wrap: wrap; }
.tab {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 14px; cursor: pointer; font-size: 13px;
  text-decoration: none; display: inline-block;
  transition: all 0.15s;
}
.tab:hover, .tab:visited { color: var(--fg); text-decoration: none; }
.tab:hover { border-color: var(--accent); }
.tab.active { background: var(--card); color: var(--accent); border-color: var(--accent); }
.head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.head h2 { margin: 0; font-size: 16px; }
.refresh {
  background: transparent; color: var(--accent); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 12px;
}
.refresh:hover { border-color: var(--accent); }
.refresh:disabled { opacity: 0.5; cursor: wait; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
  gap: 12px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 6px;
  text-decoration: none; color: inherit;
  transition: border-color 0.15s;
}
.card:hover { border-color: var(--accent); }
.card .title { font-weight: 600; font-size: 13px; line-height: 1.4; }
.card .sub  { color: var(--muted); font-size: 12px; }
.card .price { font-size: 18px; font-weight: 700; color: var(--good); }
.card .price.warn { color: var(--warn); }
.card .meta { font-size: 11px; color: var(--muted); }
.empty { color: var(--muted); padding: 12px; font-size: 12px; }
.flight-warning {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid rgba(210,153,34,0.45);
  border-left: 4px solid var(--warn);
  border-radius: 8px;
  background: rgba(210,153,34,0.10);
  color: #f0d28a;
  font-size: 12px;
  line-height: 1.6;
}
.flight-warning strong { color: #ffd166; }
@media (max-width: 600px) {
  main { padding: 12px; }
  .grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .card { padding: 10px; }
}

/* ---- Route manager (flights page) ---- */
.routes { background: var(--card); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 20px; }
.routes summary { padding: 10px 14px; cursor: pointer; font-size: 13px; color: var(--accent); user-select: none; }
.routes summary:hover { background: rgba(88,166,255,0.05); }
/* Swap the "点击展开" / "点击收起" hint based on <details open> state.
   Avoids the dogfood-found bug where summary text said "click to expand"
   even when already expanded. */
.routes summary .hint-collapsed { display: inline; }
.routes summary .hint-expanded  { display: none; }
.routes[open] summary .hint-collapsed { display: none; }
.routes[open] summary .hint-expanded  { display: inline; }
.routes-body { padding: 12px 14px 16px; border-top: 1px solid var(--border); }
.route-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 16px; }
.route-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--border); font-size: 11px; text-transform: uppercase; }
.route-table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.route-table tr:last-child td { border-bottom: none; }
.route-table code { background: rgba(255,255,255,0.05); padding: 2px 6px; border-radius: 3px; font-size: 11px; }
.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.switch input { cursor: pointer; }
.switch span { color: var(--muted); font-size: 12px; }
.switch input:checked + span { color: var(--good); }
.add-route { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding-top: 12px; border-top: 1px dashed var(--border); }
.add-route input[type=text], .add-route input:not([type]) {
  background: var(--bg); color: var(--fg); border: 1px solid var(--border);
  border-radius: 4px; padding: 5px 8px; font-size: 12px; font-family: inherit;
}
.add-route input[name=origin], .add-route input[name=dest] { width: 90px; text-transform: uppercase; }
.add-route input[name=label] { width: 180px; }
.route-window { color: var(--muted); font-size: 12px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 4px; }
.mini-btn { background: transparent; color: var(--accent); border: 1px solid var(--border); border-radius: 4px; padding: 5px 12px; cursor: pointer; font-size: 12px; }
.mini-btn:hover:not(:disabled) { border-color: var(--accent); background: rgba(88,166,255,0.08); }
.mini-btn:disabled { opacity: 0.5; cursor: wait; }
.mini-btn.danger { color: var(--bad); }
.mini-btn.danger:hover:not(:disabled) { border-color: var(--bad); background: rgba(248,81,73,0.08); }
.route-msg { margin-top: 8px; font-size: 12px; min-height: 16px; }
.route-msg.ok { color: var(--good); }
.route-msg.bad { color: var(--bad); }

/* ---- Airport autocomplete ---- */
.ac-wrap { position: relative; display: inline-block; }
.ac-input {
  background: var(--bg); color: var(--fg); border: 1px solid var(--border);
  border-radius: 4px; padding: 5px 8px; font-size: 12px; font-family: inherit;
  width: 240px;
}
.ac-input:focus { outline: none; border-color: var(--accent); }
.ac-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 100;
  background: var(--card); border: 1px solid var(--border); border-radius: 4px;
  margin-top: 2px; max-height: 280px; overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.ac-item {
  padding: 8px 10px; cursor: pointer; display: flex; gap: 8px; align-items: baseline;
  border-bottom: 1px solid var(--border); font-size: 12px;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.active { background: rgba(88,166,255,0.12); }
.ac-iata { color: var(--accent); font-weight: 700; font-family: monospace; min-width: 40px; }
.ac-city { color: var(--fg); font-weight: 500; }
.ac-name { color: var(--muted); font-size: 11px; margin-left: auto; }

/* ---- Flight card tags ---- */
.tag { display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 11px; font-weight: 500; }
.tag-good { background: rgba(63,185,80,0.15); color: var(--good); border: 1px solid rgba(63,185,80,0.3); }
.tag-warn { background: rgba(210,153,34,0.15); color: var(--warn); border: 1px solid rgba(210,153,34,0.3); }

/* ---- Flight route summary card (1 per route, /api/flights/best) ---- */
.flight-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px 18px; margin-bottom: 12px;
}
.fc-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px;
}
.fc-title {
  font-size: 16px; font-weight: 600; color: var(--fg);
  /* Long titles like "Sydney → Hong Kong" should wrap before they squeeze the
     price into a wrap. min-height locks short titles ("Beijing → Sydney") to the
     same two-line height as long ones; align-items:center on .fc-head vertically
     centers short titles in that reserved space so they don't look top-floated. */
  min-width: 0; flex: 1 1 auto;
  min-height: 48px;  /* 2 lines × 24px line-height at 16px/1.5 */
  display: flex; align-items: center;
}
.fc-best-price {
  font-size: 22px; font-weight: 700; color: var(--good);
  /* Lock to one line — wrapping made the price block 66px tall in narrow cards
     and 33px tall in wider cards, breaking visual consistency. */
  white-space: nowrap;
}
.fc-best-sub {
  margin-top: 6px; font-size: 13px;
  /* Reserve two-line height so short trophy text (e.g. "THAI · 9 hr") doesn't
     leave a single-line card visually shorter than its peers (issue #6). */
  min-height: 40px;
}
.fc-best-link { color: var(--muted); text-decoration: none; }
.fc-best-link:hover { color: var(--accent); }
.fc-stats { font-size: 11px; color: var(--muted); margin-top: 4px; }
.pair-directions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}
.direction-card {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.025);
  min-width: 0;
}
.dir-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.dir-label { font-size: 13px; font-weight: 600; color: var(--fg); min-width: 0; }
.dir-price {
  color: var(--good);
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.dir-price:hover { color: var(--accent); }
.dir-best-sub { margin-top: 6px; font-size: 12px; min-height: 38px; }
.dir-stats { font-size: 11px; color: var(--muted); margin-top: 4px; }
.pair-top-section { margin-top: 10px; }
.pair-top-title { color: var(--fg); font-size: 12px; font-weight: 600; margin: 8px 0 4px; }
.fc-top { margin-top: 10px; }
.fc-top summary { font-size: 12px; color: var(--accent); cursor: pointer; padding: 4px 0; user-select: none; }
.fc-top summary:hover { text-decoration: underline; }
.top-list { margin-top: 6px; border-top: 1px solid var(--border); }
.top-row {
  display: grid; grid-template-columns: 120px 1fr auto;
  gap: 10px; padding: 6px 4px; align-items: center;
  border-bottom: 1px solid var(--border);
  text-decoration: none; color: var(--fg); font-size: 12px;
}
.top-row:last-child { border-bottom: none; }
.top-row:hover { background: rgba(88,166,255,0.05); }
.top-row.best { background: rgba(63,185,80,0.05); }
.td-date { color: var(--muted); font-family: monospace; font-size: 11px; }
.td-meta { color: var(--fg); font-size: 12px; }
.td-price { color: var(--good); font-weight: 600; }

@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; }
  .pair-directions { grid-template-columns: 1fr; }
  .top-row { grid-template-columns: 1fr; gap: 2px; }
}
