:root {
  color-scheme: light;
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f5f7fa;
  --border: #dde3ea;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #8a8f98;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --down: #12805c;   /* price went down: good */
  --up: #c2410c;     /* price went up: bad */
  --danger: #c62828;
  --radius: 14px;
  --tabbar: 64px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.num, .price { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── Layout ── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: rgba(238, 242, 247, 0.92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  display: flex; align-items: center; gap: 10px; min-width: 0;
}
@media (min-width: 640px) { .topbar { padding-left: max(24px, calc((100vw - 760px) / 2 + 24px)); padding-right: max(24px, calc((100vw - 760px) / 2 + 24px)); } }
.topbar h1 { font-size: 22px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .back { border: 0; background: none; font-size: 26px; padding: 0 6px 0 0; line-height: 1; color: var(--accent); }
main {
  flex: 1;
  width: 100%; max-width: 760px; margin: 0 auto;
  padding: 4px 16px calc(var(--tabbar) + env(safe-area-inset-bottom) + 24px);
}
@media (min-width: 640px) { main { padding-left: 24px; padding-right: 24px; } }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; justify-content: center; gap: 8px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 0 1 160px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 500;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--accent); }

/* ── Cards & forms ── */
.card {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 14px; margin-bottom: 12px;
}
.section-title { font-size: 13px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; margin: 18px 4px 8px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); font-weight: 500; min-width: 0; }
.field input, .field select {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); font-size: 16px; color: var(--text); min-width: 0;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: #fff; }
.row { display: flex; gap: 10px; align-items: flex-end; min-width: 0; position: relative; }
.row > * { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.btn {
  border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 600;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
  white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.small { padding: 7px 12px; font-size: 14px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.block { width: 100%; }
.swap { flex: 0 0 40px !important; height: 44px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); font-size: 18px; }

.toggle { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 3px; }
.toggle button { border: 0; background: none; padding: 7px 12px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--text-2); }
.toggle button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.stepper { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); height: 44px; }
.stepper button { border: 0; background: none; width: 40px; height: 100%; font-size: 20px; color: var(--accent); }
.stepper span { flex: 1; text-align: center; font-weight: 600; }

/* Airport autocomplete: the list spans the whole Desde/Hasta row */
.ac { position: static; }
.ac-list {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 20; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 300px; overflow-y: auto;
}
.ac-list button { display: flex; gap: 10px; width: 100%; text-align: left; border: 0; background: none; padding: 10px 12px; align-items: baseline; }
.ac-list button:hover, .ac-list button.hl { background: var(--surface-2); }
.ac-list b { flex: 0 0 38px; color: var(--accent); }
.ac-list span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.ac-list small { color: var(--muted); }

/* ── Offers ── */
.results-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 16px 4px 8px; flex-wrap: wrap; }
.results-head .meta { font-size: 13px; color: var(--text-2); }
.offer { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); min-width: 0; }
.offer:last-child { border-bottom: 0; }
.offer .main { flex: 1; min-width: 0; }
.offer .times { font-weight: 600; font-size: 16px; white-space: nowrap; }
.offer .times sup { color: var(--up); font-size: 11px; font-weight: 600; }
.offer .sub { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.offer .price { font-size: 18px; font-weight: 700; text-align: right; }
.offer .price small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }
.offers.card { padding: 0; overflow: hidden; }
.cheapest { color: var(--down); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

/* ── Watched routes ── */
.route { display: block; text-decoration: none; color: inherit; }
.route .top { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
.route .what { flex: 1; min-width: 0; }
.route .codes { font-size: 18px; font-weight: 700; white-space: nowrap; }
.route .when { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.route .now { text-align: right; }
.route .now .price { font-size: 20px; font-weight: 700; }
.route .bottom { display: flex; align-items: center; gap: 12px; margin-top: 10px; min-width: 0; }
.route .bottom .facts { flex: 1; min-width: 0; font-size: 13px; color: var(--text-2); }
.route.paused { opacity: .6; }
.delta { font-size: 13px; font-weight: 600; white-space: nowrap; }
.delta.down { color: var(--down); }
.delta.up { color: var(--up); }
.delta.flat { color: var(--muted); }
.spark { flex: 0 0 110px; height: 32px; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark circle { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.pill.warn { color: var(--up); border-color: #f3c9b3; background: #fff5ef; }

/* ── Route detail ── */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 480px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.stat .k { font-size: 12px; color: var(--text-2); }
.stat .v { font-size: 20px; font-weight: 700; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 220px; overflow: visible; touch-action: pan-y; }
.chart .grid line { stroke: #e7ebf0; stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .end-label { fill: var(--text); font-size: 12px; font-weight: 600; }
.chart .min-label { fill: var(--text-2); font-size: 11px; }
.chart .cross { stroke: var(--text-2); stroke-width: 1; }
.tip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; box-shadow: 0 4px 14px rgba(0,0,0,.12); font-size: 12px; white-space: nowrap;
  transform: translateX(-50%);
}
.tip b { font-size: 14px; display: block; }
.tip span { color: var(--text-2); }

table.dense { width: 100%; border-collapse: collapse; font-size: 13px; }
table.dense th { text-align: left; font-weight: 600; color: var(--text-2); padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.dense td { padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.dense td.r, table.dense th.r { text-align: right; }
.table-wrap { overflow-x: auto; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding-top: 10px; font-size: 13px; color: var(--text-2); }

/* ── Misc ── */
.empty { text-align: center; color: var(--text-2); padding: 32px 16px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }
.error-box { background: #fff1f1; border: 1px solid #f3c2c2; color: var(--danger); border-radius: 12px; padding: 12px 14px; margin: 12px 0; font-size: 14px; }
.loading { text-align: center; color: var(--text-2); padding: 28px; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 16px); transform: translateX(-50%);
  background: #1d1d1f; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 50;
  max-width: calc(100vw - 32px);
}
.hint { font-size: 12px; color: var(--muted); margin: 8px 4px 0; }

/* Centered modal (never a slide-over) */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 16px; padding: 18px; width: min(420px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; }
.modal h3 { margin: 0 0 8px; font-size: 18px; }
.modal p { margin: 0 0 14px; color: var(--text-2); font-size: 14px; }
.modal .btns { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
