:root {
  color-scheme: light;
  --page:        #f9f9f7;
  --surface:     #fcfcfb;
  --surface-2:   #f3f3f0;
  --ink:         #0b0b0b;
  --ink-2:       #52514e;
  --muted:       #898781;
  --grid:        #e1e0d9;
  --baseline:    #c3c2b7;
  --border:      rgba(11,11,11,0.10);
  --series-1:    #2a78d6;
  --series-2:    #eb6834;
  --good-text:   #006300;
  --good-bg:     rgba(12,163,12,0.10);
  --warn-text:   #8a3d1e;
  --warn-bg:     rgba(236,131,90,0.14);
  --neutral-bg:  rgba(11,11,11,0.05);
  --hover:       rgba(11,11,11,0.035);
  --selected:    rgba(42,120,214,0.08);
  --accent:      #2a78d6;
  --shadow:      0 1px 2px rgba(11,11,11,0.04), 0 8px 24px rgba(11,11,11,0.05);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:        #0d0d0d;
    --surface:     #1a1a19;
    --surface-2:   #232322;
    --ink:         #ffffff;
    --ink-2:       #c3c2b7;
    --muted:       #898781;
    --grid:        #2c2c2a;
    --baseline:    #383835;
    --border:      rgba(255,255,255,0.10);
    --series-1:    #3987e5;
    --series-2:    #d95926;
    --good-text:   #0ca30c;
    --good-bg:     rgba(12,163,12,0.14);
    --warn-text:   #ec835a;
    --warn-bg:     rgba(236,131,90,0.14);
    --neutral-bg:  rgba(255,255,255,0.06);
    --hover:       rgba(255,255,255,0.04);
    --selected:    rgba(57,135,229,0.12);
    --accent:      #3987e5;
    --shadow:      0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:        #0d0d0d;
  --surface:     #1a1a19;
  --surface-2:   #232322;
  --ink:         #ffffff;
  --ink-2:       #c3c2b7;
  --muted:       #898781;
  --grid:        #2c2c2a;
  --baseline:    #383835;
  --border:      rgba(255,255,255,0.10);
  --series-1:    #3987e5;
  --series-2:    #d95926;
  --good-text:   #0ca30c;
  --good-bg:     rgba(12,163,12,0.14);
  --warn-text:   #ec835a;
  --warn-bg:     rgba(236,131,90,0.14);
  --neutral-bg:  rgba(255,255,255,0.06);
  --hover:       rgba(255,255,255,0.04);
  --selected:    rgba(57,135,229,0.12);
  --accent:      #3987e5;
  --shadow:      0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.25);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  -webkit-tap-highlight-color: transparent;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ============================================================
   App shell — collapsible sidebar + topbar + content
   ============================================================ */

:root {
  --sidebar-w: 220px;
  --sidebar-w-collapsed: 60px;
  --topbar-h: 56px;
  --bottomnav-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

.shell { display: flex; min-height: 100%; }

/* ---------- sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  transition: width .18s ease, flex-basis .18s ease;
  z-index: 30;
}
body.nav-collapsed .sidebar {
  width: var(--sidebar-w-collapsed);
  flex-basis: var(--sidebar-w-collapsed);
}

.sidebar .brand {
  display: flex; align-items: center; gap: 9px;
  height: var(--topbar-h); padding: 0 16px;
  border-bottom: 1px solid var(--border);
  overflow: hidden; white-space: nowrap;
}
.sidebar .brand .mark {
  flex: 0 0 26px; width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 14px;
}
.sidebar .brand b { font-size: 15px; font-weight: 640; letter-spacing: -0.015em; }
body.nav-collapsed .sidebar .brand b { display: none; }

.sidebar .nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; }
.sidebar .nav .group {
  color: var(--muted); font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 12px 10px 5px;
}
body.nav-collapsed .sidebar .nav .group { opacity: 0; height: 12px; padding: 0; overflow: hidden; }

.sidebar .nav a, .sidebar .nav button, .foot button {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  background: none; border: none; cursor: pointer;
  color: var(--ink-2); font-size: 13.5px; text-align: left;
  text-decoration: none; white-space: nowrap; overflow: hidden;
  width: 100%;
}
.sidebar .nav a:hover, .sidebar .nav button:hover, .foot button:hover {
  background: var(--hover); color: var(--ink);
}
.sidebar .nav .active { background: var(--selected); color: var(--accent); font-weight: 550; }
.sidebar .nav .ico {
  flex: 0 0 18px; width: 18px; text-align: center; font-size: 14px;
  display: inline-grid; place-items: center;
}
.sidebar .nav .badge-count {
  margin-left: auto; font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
body.nav-collapsed .sidebar .nav .label,
body.nav-collapsed .foot .label,
body.nav-collapsed .sidebar .nav .badge-count { display: none; }
body.nav-collapsed .sidebar .nav a,
body.nav-collapsed .sidebar .nav button,
body.nav-collapsed .foot button { justify-content: center; padding: 9px 0; }

.sidebar .foot {
  margin-top: auto; padding: 10px 8px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px;
}

/* Tooltip for collapsed items */
body.nav-collapsed .sidebar .nav a[data-tip]:hover::after,
body.nav-collapsed .sidebar .nav button[data-tip]:hover::after,
body.nav-collapsed .foot button[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; left: calc(var(--sidebar-w-collapsed) + 6px);
  background: var(--ink); color: var(--page);
  padding: 4px 9px; border-radius: 6px; font-size: 12px;
  white-space: nowrap; z-index: 60; pointer-events: none;
}
body.nav-collapsed .sidebar .nav a, body.nav-collapsed .sidebar .nav button,
body.nav-collapsed .foot button { position: relative; }

/* ---------- main + topbar ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px; height: var(--topbar-h);
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 15px; font-weight: 620; margin: 0; letter-spacing: -0.01em; }
.topbar .meta { color: var(--muted); font-size: 12px; }
.topbar .grow { flex: 1; }

.icon-btn {
  background: none; border: 1px solid transparent; border-radius: 8px;
  padding: 6px 9px; cursor: pointer; color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 7px; font-size: 13px;
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn.primary {
  border-color: var(--border); background: var(--surface);
}
.icon-btn.primary:hover { border-color: var(--accent); color: var(--accent); }

.content { padding: 22px 24px 56px; max-width: 1280px; }

/* ---------- theme menu ---------- */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow);
  padding: 5px; min-width: 168px; z-index: 50; display: none;
}
.menu.open { display: block; }
.menu button {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 7px 9px; border-radius: 7px; border: none; background: none;
  cursor: pointer; color: var(--ink-2); font-size: 13px; text-align: left;
}
.menu button:hover { background: var(--hover); color: var(--ink); }
.menu button .check { margin-left: auto; color: var(--accent); }
/* ---------- tiles ---------- */
.tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 15px 17px;
}
.tile .k {
  color: var(--muted); font-size: 11px; font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase; margin-bottom: 7px;
}
.tile .v { font-size: 26px; font-weight: 640; letter-spacing: -0.02em; line-height: 1.1; }
.tile .d { color: var(--ink-2); font-size: 12.5px; margin-top: 5px; }

/* ---------- filters ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: end; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 13px 16px; margin-bottom: 16px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span:first-child {
  color: var(--muted); font-size: 11px; font-weight: 600;
  letter-spacing: 0.03em; text-transform: uppercase;
}
.field select, .field input[type=number] {
  background: var(--page); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 118px;
}
.field select:focus, .field input:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  outline-offset: -1px;
}
.field input.narrow { min-width: 62px; width: 62px; }
/* Sorting lives in the table header on a wide screen; the phone layout has no
   header row, so this stand-in only shows up there. */
#lSort { display: none; }
.sortwrap { display: flex; gap: 6px; }
.sortwrap select { flex: 1; min-width: 0; }
.sortwrap button {
  flex: none; width: 44px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--page); color: var(--ink-2); cursor: pointer;
}
.nights { display: flex; gap: 5px; align-items: center; }
.nights span { color: var(--muted); }
.toggle {
  display: flex; align-items: center; gap: 7px; cursor: pointer;
  padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--page); font-size: 13px; user-select: none;
}
.toggle:hover { background: var(--hover); }
.toggle input { accent-color: var(--accent); margin: 0; }
.toolbar .grow { flex: 1; }
.toolbar .count { color: var(--muted); font-size: 12.5px; padding-bottom: 9px; }

/* ---------- table ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
}
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; white-space: nowrap; }
th {
  font-size: 11px; font-weight: 600; color: var(--muted);
  letter-spacing: 0.04em; text-transform: uppercase;
  border-bottom: 1px solid var(--grid); background: var(--surface);
  cursor: pointer; user-select: none;
}
th:hover { color: var(--ink-2); }
th .arrow { color: var(--accent); font-size: 9px; margin-left: 2px; }
td { border-bottom: 1px solid var(--grid); }
tbody tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--hover); }
tbody tr.selected { background: var(--selected); }
td.num { font-variant-numeric: tabular-nums; text-align: right; }
th.num { text-align: right; }
.leg { display: flex; flex-direction: column; gap: 2px; }
.leg .code { font-weight: 600; letter-spacing: -0.01em; }
.leg .code .arr { color: var(--muted); font-weight: 400; margin: 0 3px; }
.leg .op { color: var(--muted); font-size: 11.5px; }
.leg .op .direct { color: var(--good-text); }
.when { display: flex; flex-direction: column; gap: 2px; }
.when .day { font-weight: 500; }
.when .time { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.eff { font-weight: 650; font-size: 14.5px; }
.adj { color: var(--muted); }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 550; background: var(--neutral-bg); color: var(--ink-2);
}
.badge.good { background: var(--good-bg); color: var(--good-text); }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }
.badges { display: flex; gap: 4px; flex-wrap: wrap; }
.src { color: var(--muted); font-size: 12px; }
.empty-row { padding: 40px 16px; text-align: center; color: var(--muted); }

/* ---------- favourites ---------- */
.star {
  background: none; border: none; cursor: pointer; padding: 3px 5px;
  border-radius: 6px; color: var(--muted); font-size: 15px; line-height: 1;
}
.star:hover { background: var(--hover); color: var(--ink); }
.star.on { color: #eda100; }
th.starcol, td.starcol { width: 34px; padding-left: 10px; padding-right: 0; }
.fav-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}
.fav {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 15px 16px; position: relative;
}
.fav h3 { margin: 0 0 3px; font-size: 14.5px; font-weight: 640; letter-spacing: -0.01em; }
.fav .sub { color: var(--muted); font-size: 12px; margin-bottom: 11px; }
.fav .leg {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 6px 0; border-top: 1px solid var(--grid); font-size: 12.5px;
}
.fav .leg .l { color: var(--ink-2); }
.fav .leg .r { font-variant-numeric: tabular-nums; }
.fav .total {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 11px; padding-top: 10px; border-top: 1px solid var(--grid);
}
.fav .total .v { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.fav .delta { font-size: 12.5px; font-weight: 600; }
.fav .delta.down { color: var(--good-text); }
.fav .delta.up { color: var(--warn-text); }
.fav .rm {
  position: absolute; top: 11px; right: 12px; background: none; border: none;
  color: var(--muted); cursor: pointer; padding: 4px 7px; border-radius: 6px; font-size: 13px;
}
.fav .rm:hover { background: var(--hover); color: var(--warn-text); }

/* ---------- calendar ---------- */
.cal-head {
  display: flex; align-items: center; gap: 12px; margin-bottom: 14px;
}
.cal-head h2 { margin: 0; font-size: 15px; font-weight: 640; }
.cal-head .nav { display: flex; gap: 4px; }
.cal-head .nav button {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 11px; cursor: pointer; color: var(--ink-2);
}
.cal-head .nav button:hover { background: var(--hover); color: var(--ink); }
.cal-legend { display: flex; gap: 14px; align-items: center; color: var(--muted); font-size: 12px; }
.cal-legend .ramp { display: flex; gap: 2px; }
.cal-legend .ramp i { width: 16px; height: 9px; border-radius: 2px; display: block; }
.cal-months { display: grid; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); gap: 16px; }
.month { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 15px; }
.month h3 {
  margin: 0 0 10px; font-size: 13px; font-weight: 620; text-transform: capitalize;
}
.dow, .days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.dow div {
  text-align: center; font-size: 10px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em; padding-bottom: 4px;
}
.days .day {
  aspect-ratio: 1 / 0.82; border-radius: 7px; padding: 4px 3px 3px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  font-size: 11px; border: 1px solid transparent;
}
.days .day.blank { visibility: hidden; }
.days .day.none { color: var(--muted); }
.days .day.has { cursor: pointer; }
.days .day.has:hover { border-color: var(--accent); }
.days .day .n { font-weight: 550; line-height: 1.2; }
.days .day .p { font-size: 9.5px; font-variant-numeric: tabular-nums; opacity: 0.9; line-height: 1.3; }
.days .day.wknd .n { color: var(--accent); }
.days .day.sel { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- chat trip cards ---------- */
.tripcard {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  margin: 8px 0; background: var(--page);
}
.tripcard .r { font-size: 12.5px; font-weight: 600; margin-bottom: 3px; }
.tripcard .d { color: var(--ink-2); font-size: 11.5px; line-height: 1.5; }
.tripcard .act { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tripcard .act button {
  background: var(--surface); border: 1px solid var(--border); border-radius: 7px;
  padding: 4px 10px; font-size: 11.5px; color: var(--ink-2); cursor: pointer;
}
.tripcard .act button:hover { border-color: var(--accent); color: var(--accent); }
.tripcard .act button.on { color: #eda100; border-color: #eda100; }

.pager {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 11px 16px; border-top: 1px solid var(--grid);
}
.pager .info { color: var(--muted); font-size: 12.5px; }
.pager .btns { display: flex; gap: 3px; }
.pager button {
  background: none; border: 1px solid transparent; border-radius: 8px;
  min-width: 32px; padding: 6px 9px; font-size: 13px;
  color: var(--ink-2); cursor: pointer;
}
.pager button:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
.pager button.current { background: var(--accent); color: #fff; font-weight: 600; }
.pager button:disabled { opacity: 0.35; cursor: default; }
.pager .ellip { color: var(--muted); padding: 6px 3px; }

/* ---------- detail ---------- */
.detail { margin-bottom: 16px; display: none; }
.detail.open { display: block; }
.detail .card { padding: 17px 19px; position: relative; }
.detail h2 { font-size: 15px; font-weight: 640; margin: 0 0 3px; letter-spacing: -0.01em; }
.detail .meta { color: var(--muted); font-size: 12.5px; margin-bottom: 14px; }
.detail .empty { color: var(--muted); font-size: 13px; padding: 22px 0; }
.detail .close {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; color: var(--muted);
  font-size: 15px; cursor: pointer; padding: 5px 9px; border-radius: 7px;
}
.detail .close:hover { background: var(--hover); color: var(--ink); }
.legend { display: flex; gap: 16px; margin-bottom: 10px; font-size: 12.5px; color: var(--ink-2); }
.legend .item { display: flex; align-items: center; gap: 6px; }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; }
#chart { width: 100%; height: auto; display: block; touch-action: pan-y; }
.tooltip {
  position: fixed; pointer-events: none; z-index: 60; display: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  padding: 8px 11px; font-size: 12.5px; box-shadow: var(--shadow);
}
.tooltip .t { color: var(--muted); font-size: 11.5px; margin-bottom: 2px; }
.tooltip .p { font-weight: 650; font-variant-numeric: tabular-nums; }
.footnote { color: var(--muted); font-size: 12px; margin-top: 16px; max-width: 760px; }
.footnote code {
  background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 11.5px;
}

/* ---------- chat ---------- */
.chat {
  width: 0; flex: none; overflow: hidden;
  border-left: 1px solid transparent;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  transition: width 0.18s ease;
}
.chat.open { width: 390px; border-left-color: var(--border); background: var(--surface); }
.chat-head {
  display: flex; align-items: center; gap: 9px;
  padding: 0 16px; height: 58px; border-bottom: 1px solid var(--border); flex: none;
}
.chat-head b { font-size: 14px; font-weight: 620; }
.chat-head .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--good-text); flex: none;
}
.chat-head .dot.off { background: var(--muted); }
.chat-head .grow { flex: 1; }
.chat-head button {
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 5px 8px; border-radius: 7px; font-size: 14px;
}
.chat-head button:hover { background: var(--hover); color: var(--ink); }
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; flex-direction: column; gap: 5px; }
.msg .who {
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--muted);
}
.msg .body { font-size: 13.5px; line-height: 1.6; word-wrap: break-word; }
.msg .body p { margin: 0 0 8px; }
.msg .body p:last-child { margin-bottom: 0; }
.msg .body ul { margin: 0 0 8px; padding-left: 18px; }
.msg .body li { margin-bottom: 3px; }
.msg .body strong { font-weight: 640; }
.msg .body p.h { font-weight: 640; margin-top: 12px; }
.msg .body p.h:first-child { margin-top: 0; }
.msg .body hr { border: none; border-top: 1px solid var(--grid); margin: 10px 0; }
.msg .body code {
  background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 12px;
}
.msg.user .body {
  background: var(--surface-2); border-radius: 10px; padding: 9px 12px;
}
.msg.error .body { color: var(--warn-text); }
.chat-empty { color: var(--muted); font-size: 13px; line-height: 1.6; }
.suggestions { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.suggestions button {
  text-align: left; background: var(--page); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 12px; font-size: 12.5px; color: var(--ink-2);
  cursor: pointer;
}
.suggestions button:hover { background: var(--hover); color: var(--ink); border-color: var(--accent); }
.chat-form {
  flex: none; border-top: 1px solid var(--border); padding: 12px 14px;
  display: flex; gap: 8px; align-items: flex-end;
}
.chat-form textarea {
  flex: 1; resize: none; background: var(--page); color: var(--ink);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 11px; font-size: 13.5px; line-height: 1.45;
  max-height: 130px; min-height: 38px;
}
.chat-form textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  outline-offset: -1px;
}
.chat-form button {
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  width: 38px; height: 38px; font-size: 15px; cursor: pointer; flex: none;
}
.chat-form button:disabled { opacity: 0.4; cursor: default; }
.typing { display: inline-block; width: 7px; height: 13px; background: var(--ink-2);
          vertical-align: text-bottom; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

@media (max-width: 1100px) {
  .chat.open { position: fixed; right: 0; top: 0; width: min(390px, 100%); z-index: 50; box-shadow: var(--shadow); }
}

/* ============================================================
   Documentation page
   ============================================================ */
.doc { max-width: 820px; padding: 30px 26px 80px; }
.doc h1 { font-size: 26px; font-weight: 650; letter-spacing: -0.025em; margin: 0 0 8px; }
.doc .lede { color: var(--ink-2); font-size: 15px; line-height: 1.6; margin: 0 0 30px; }
.doc h2 {
  font-size: 17px; font-weight: 640; letter-spacing: -0.015em;
  margin: 38px 0 10px; padding-top: 20px; border-top: 1px solid var(--grid);
}
.doc h3 { font-size: 14.5px; font-weight: 620; margin: 22px 0 6px; }
/* Anchor jumps must clear the sticky topbar. */
.doc h2, .doc h3 { scroll-margin-top: calc(var(--topbar-h) + 10px); }
.doc p { line-height: 1.65; margin: 0 0 12px; color: var(--ink-2); }
.doc li { line-height: 1.6; margin-bottom: 6px; color: var(--ink-2); }
.doc ul { padding-left: 20px; margin: 0 0 14px; }
.doc strong, .doc b { color: var(--ink); font-weight: 600; }
.doc code {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 5px; font-size: 12.5px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}
.doc pre {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 13px 15px; overflow-x: auto;
  font-size: 12.5px; line-height: 1.55; margin: 0 0 14px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}
.doc pre code { background: none; border: none; padding: 0; font-size: inherit; }
.doc a { color: var(--accent); text-decoration: none; }
.doc a:hover { text-decoration: underline; }

.doc table { margin: 0 0 16px; font-size: 13px; }
.doc th, .doc td {
  padding: 8px 12px; white-space: normal; vertical-align: top;
  border-bottom: 1px solid var(--grid);
}
.doc th { position: static; font-weight: 600; color: var(--ink-2); cursor: default; }
.doc thead th { border-bottom: 1px solid var(--baseline); }
.doc .tbl-wrap {
  border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; background: var(--surface); margin-bottom: 16px;
}

.note {
  border-left: 3px solid var(--accent); background: var(--surface);
  border-radius: 0 8px 8px 0; padding: 11px 15px; margin: 0 0 16px;
}
.note p:last-child { margin-bottom: 0; }
.note.warn { border-left-color: var(--warn-text); }

.figure {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px; margin: 0 0 18px; overflow-x: auto;
}
.figure svg { display: block; max-width: 100%; height: auto; }
.figure figcaption {
  color: var(--muted); font-size: 12px; margin-top: 10px; text-align: center;
}
.toc {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 13px 16px; margin: 0 0 26px;
}
.toc ol { margin: 0; padding-left: 20px; }
.toc li { margin-bottom: 3px; font-size: 13px; }

/* ============================================================
   Alerts
   ============================================================ */
.alerts-bar { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.alerts-bar p { margin: 0; color: var(--muted); font-size: 12.5px; flex: 1; }

.alert {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; margin-bottom: 14px; overflow: hidden;
}
.alert.off { opacity: 0.55; }
.alert-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--grid);
}
.alert-head h3 { margin: 0; font-size: 14px; font-weight: 620; letter-spacing: -0.01em; }
.alert-head .rules { color: var(--muted); font-size: 12px; }
.alert-head .grow { flex: 1; }
.alert-head .pill {
  font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: var(--neutral-bg); color: var(--ink-2);
}
.alert-head .pill.hit { background: var(--good-bg); color: var(--good-text); }
.alert-head .pill.new { background: var(--accent); color: #fff; }
.alert-head button {
  background: none; border: none; cursor: pointer; color: var(--muted);
  padding: 4px 7px; border-radius: 6px; font-size: 13px;
}
.alert-head button:hover { background: var(--hover); color: var(--ink); }

.alert-rows { display: flex; flex-direction: column; }
.alert-row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 16px; border-bottom: 1px solid var(--grid); font-size: 13px;
  cursor: pointer;
}
.alert-row:last-child { border-bottom: none; }
.alert-row:hover { background: var(--hover); }
.alert-row.is-new { background: var(--selected); }
.alert-row .route { font-weight: 600; min-width: 108px; }
.alert-row .dates { color: var(--ink-2); flex: 1; min-width: 0; }
.alert-row .tag {
  font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: var(--neutral-bg); color: var(--ink-2); white-space: nowrap;
}
.alert-row .tag.free { background: var(--good-bg); color: var(--good-text); }
.alert-row .price {
  font-weight: 650; font-variant-numeric: tabular-nums; min-width: 78px; text-align: right;
}
.alert-row .newdot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: 0 0 6px;
}
.alert-empty { padding: 16px; color: var(--muted); font-size: 13px; }

.alert-form {
  padding: 14px 16px; border-bottom: 1px solid var(--grid);
  display: flex; flex-wrap: wrap; gap: 12px; align-items: end;
  background: var(--surface-2);
}
.alert-form .field input[type=text] {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 190px;
}
.alert-form .actions { display: flex; gap: 7px; margin-left: auto; }
.alert-form button {
  border-radius: 8px; padding: 7px 13px; cursor: pointer; font-size: 13px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-2);
}
.alert-form button.save { border-color: var(--accent); color: var(--accent); }
.alert-form button:hover { background: var(--hover); }

/* ---------- alert match views: grouped list / mini calendar ---------- */
.view-toggle {
  display: flex; background: var(--neutral-bg); border-radius: 8px; padding: 2px; gap: 1px;
}
.view-toggle button {
  border: none; background: none; padding: 4px 10px; border-radius: 6px;
  font-size: 11.5px; color: var(--ink-2); cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
}
.view-toggle button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.view-toggle button:hover:not(.active) { color: var(--ink); }

.alert-month {
  display: flex; align-items: baseline; gap: 7px;
  padding: 8px 16px 5px; font-size: 11px; font-weight: 650;
  text-transform: capitalize; color: var(--ink-2);
  background: var(--surface-2); letter-spacing: 0.02em;
}
.alert-month .n { color: var(--muted); font-weight: 500; text-transform: none; }

.alert-cal {
  padding: 14px 16px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px;
}
.alert-cal .month { padding: 12px 13px; }
.alert-cal .month h3 { font-size: 12px; margin-bottom: 8px; }
.alert-cal .day .p { font-size: 9px; }

/* ---------- booking links ---------- */
.book-links { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.book-link {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--accent); color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border-radius: 8px; padding: 6px 12px; font-size: 12.5px; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.book-link:hover { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.book-link.muted {
  border-color: var(--border); color: var(--ink-2); background: var(--neutral-bg);
}
.book-link.small {
  padding: 2px 8px; font-size: 11px; border-radius: 6px; gap: 4px;
}

/* ============================================================
   Narrow screens
   ============================================================ */

/* The chat panel stops splitting the layout and floats over it instead.
   While closed it must stay 0-wide: it is fixed and full-height here, so any
   width would leave an invisible sheet swallowing every tap on the page. */
@media (max-width: 1000px) {
  .chat {
    position: fixed; top: 0; right: 0; bottom: 0; height: 100dvh;
    box-shadow: -8px 0 32px rgba(0,0,0,0.28);
  }
  .chat:not(.open) {
    width: 0; border-left-color: transparent;
    box-shadow: none; pointer-events: none;
  }
}

/* ------------------------------------------------------------
   Phones: the sidebar becomes a bottom tab bar, the table becomes
   cards, and every control grows to a thumb-sized target.
   ------------------------------------------------------------ */
@media (max-width: 760px) {
  :root { --topbar-h: 52px; }

  .shell { display: block; }
  .main { display: block; }

  /* ---------- bottom tab bar ---------- */
  .sidebar, body.nav-collapsed .sidebar {
    position: fixed; inset: auto 0 0 0; top: auto;
    width: 100%; flex-basis: auto; height: auto;
    flex-direction: row; align-items: stretch;
    border-right: none; border-top: 1px solid var(--border);
    padding-bottom: var(--safe-b);
    transition: none; z-index: 40;
  }
  .sidebar .brand, .sidebar .foot, .sidebar .nav .group,
  body.nav-collapsed .sidebar .nav .group { display: none; }
  .sidebar .nav, body.nav-collapsed .sidebar .nav {
    flex-direction: row; width: 100%; padding: 5px 2px 4px; gap: 0;
  }
  .sidebar .nav a, .sidebar .nav button,
  body.nav-collapsed .sidebar .nav a, body.nav-collapsed .sidebar .nav button {
    position: relative;
    flex: 1 1 0; min-width: 0; width: auto;
    flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 5px 2px; border-radius: 10px;
    font-size: 10px; text-align: center; min-height: 50px;
  }
  .sidebar .nav .ico, body.nav-collapsed .sidebar .nav .ico { font-size: 17px; }
  .sidebar .nav .label,
  body.nav-collapsed .sidebar .nav .label {
    display: block; font-size: 10px; line-height: 1.15;
    max-width: 100%; overflow: hidden; text-overflow: ellipsis;
  }
  .sidebar .nav .active { background: none; color: var(--accent); font-weight: 600; }
  /* Unread counts ride on the icon instead of sitting at the end of a row. */
  .sidebar .nav .badge-count,
  body.nav-collapsed .sidebar .nav .badge-count {
    display: block; position: absolute; top: 2px; left: 50%; margin-left: 4px;
    background: var(--accent); color: #fff;
    font-size: 9px; font-weight: 700; line-height: 15px;
    min-width: 15px; padding: 0 4px; border-radius: 999px; text-align: center;
  }
  .sidebar .nav .badge-count:empty { display: none; }
  /* Hover tooltips never fire on touch — the labels say it all now. */
  body.nav-collapsed .sidebar .nav a[data-tip]:hover::after,
  body.nav-collapsed .sidebar .nav button[data-tip]:hover::after,
  body.nav-collapsed .foot button[data-tip]:hover::after { content: none; }

  /* ---------- topbar ---------- */
  .topbar { position: sticky; padding: 0 12px; gap: 8px; }
  .topbar h1 {
    font-size: 15px; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .topbar .meta { display: none; }
  .icon-btn { padding: 8px 10px; min-height: 40px; }
  .icon-btn span:not(:first-child) { display: none; }
  .menu button { padding: 10px 11px; }

  /* Room for the tab bar under everything that scrolls. */
  .content { padding: 14px 12px calc(var(--bottomnav-h) + var(--safe-b) + 24px); }
  body.chat-open { overflow: hidden; }

  /* ---------- tiles ---------- */
  .tiles { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 14px; }
  .tile { padding: 11px 12px; border-radius: 10px; }
  .tile:nth-child(3) { grid-column: 1 / -1; }
  .tile .k { font-size: 10px; margin-bottom: 4px; }
  .tile .v { font-size: 21px; }
  .tile .d { font-size: 11.5px; margin-top: 3px; }

  /* ---------- filters ---------- */
  .toolbar { padding: 11px; gap: 10px; border-radius: 10px; }
  .toolbar .field, .alert-form .field { flex: 1 1 calc(50% - 5px); min-width: 0; }
  .field select, .field input[type=number], .field input[type=text] {
    width: 100%; min-width: 0; padding: 9px 10px;
    font-size: 16px;                    /* stops iOS zooming in on focus */
  }
  .field input.narrow { width: 100%; min-width: 0; }
  .nights { width: 100%; }
  #lSort { display: flex; }
  .toolbar .grow { display: none; }
  .toggle { flex: 1 1 calc(50% - 5px); justify-content: center; padding: 11px 10px; }
  .toolbar .count { flex: 1 1 100%; padding-bottom: 0; }

  /* ---------- table becomes cards ---------- */
  #tableView { background: none; border: none; border-radius: 0; overflow: visible; }
  .tablewrap { overflow: visible; }
  #tbl, #tbl tbody, #tbl tr, #tbl td { display: block; width: auto; }
  #tbl thead { display: none; }
  #tbl tbody tr {
    position: relative; margin-bottom: 10px; padding: 9px 12px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  }
  #tbl tbody tr:hover { background: var(--surface); }
  #tbl tbody tr.selected { background: var(--selected); border-color: var(--accent); }
  #tbl td {
    border: none; padding: 3px 0; white-space: normal;
    display: flex; align-items: baseline; justify-content: flex-end; gap: 8px;
  }
  /* margin-right:auto keeps every part of a multi-piece value (price + badge)
     together on the right instead of spreading it across the card. */
  #tbl td::before {
    content: attr(data-t); flex: 0 0 auto; margin-right: auto;
    color: var(--muted); font-size: 10.5px; font-weight: 600;
    letter-spacing: 0.04em; text-transform: uppercase;
  }
  /* First cell of each card leaves room for the star in the corner. */
  #tbl td:nth-child(2) { padding-right: 32px; }
  #tbl td.num { text-align: right; }
  #tbl td .leg, #tbl td .when { align-items: flex-end; text-align: right; }
  #tbl td .badges { justify-content: flex-end; }
  /* The star floats in the card corner; a label for it would be noise. */
  #tbl td.starcol {
    position: absolute; top: 4px; right: 4px;
    width: auto; padding: 0; display: block;
  }
  #tbl td.starcol::before { content: none; }
  #tbl td.empty-row { padding: 26px 0; text-align: center; }
  #tbl td.empty-row::before { content: none; }
  .star { padding: 7px 9px; font-size: 17px; }

  .pager {
    flex-direction: column; align-items: stretch;
    gap: 8px; padding: 2px 0 0; border-top: none;
  }
  .pager .info { text-align: center; }
  .pager .btns { flex-wrap: wrap; justify-content: center; gap: 4px; }
  .pager button { min-width: 40px; min-height: 40px; }

  /* ---------- detail + chart ---------- */
  .detail .card { padding: 14px 12px; }
  .detail .close { top: 8px; right: 8px; padding: 8px 10px; }
  .detail h2 { font-size: 14.5px; padding-right: 34px; }
  .detail .meta { font-size: 12px; margin-bottom: 10px; }
  .book-link { padding: 9px 13px; font-size: 13px; }

  /* ---------- calendar ---------- */
  .cal-head { flex-wrap: wrap; gap: 8px 10px; }
  .cal-head h2 { flex: 1 1 100%; font-size: 14px; }
  .cal-head .nav button { min-width: 46px; min-height: 38px; }
  .cal-head .grow { display: none; }
  .cal-legend { margin-left: auto; gap: 7px; font-size: 11px; }
  .cal-months { grid-template-columns: 1fr; gap: 12px; }
  .month { padding: 12px 10px; }
  .days, .dow { gap: 2px; }
  .days .day { aspect-ratio: 1 / 0.95; border-radius: 6px; padding: 3px 1px 2px; }
  .days .day .p { font-size: 9px; }

  /* ---------- favourites ---------- */
  .fav-grid { grid-template-columns: 1fr; }
  .fav { padding: 14px 13px; }
  .fav .rm { top: 8px; right: 8px; padding: 7px 9px; }
  .fav h3 { padding-right: 30px; }

  /* ---------- alerts ---------- */
  .alerts-bar { flex-wrap: wrap; gap: 10px; }
  .alerts-bar p { flex: 1 1 100%; order: 2; }
  .alerts-bar .icon-btn { order: 1; }
  .alerts-bar .icon-btn span:not(:first-child) { display: inline; }
  .alert-head { flex-wrap: wrap; gap: 8px; padding: 12px; }
  .alert-head > div:first-child { flex: 1 1 100%; }
  .alert-head .grow { display: none; }
  .alert-head .view-toggle { margin-right: auto; }
  .alert-head button { min-width: 36px; min-height: 36px; }
  /* Icons only, so the pills, the toggle and the three actions share one row. */
  .view-toggle button { padding: 8px 11px; font-size: 13px; }
  .view-toggle button span:not(:first-child) { display: none; }
  .alert-row { flex-wrap: wrap; gap: 5px 8px; padding: 11px 12px; }
  .alert-row .route { flex: 0 1 auto; min-width: 0; }
  .alert-row .price { margin-left: auto; min-width: 0; }
  .alert-row .dates { flex: 1 1 100%; font-size: 12px; }
  .alert-row .book-links { flex: 1 1 100%; margin: 2px 0 0; }
  .alert-form { padding: 12px; gap: 10px; }
  .alert-form .actions { margin-left: 0; width: 100%; }
  .alert-form .actions button { flex: 1; min-height: 42px; }
  .alert-cal { grid-template-columns: 1fr; padding: 12px 10px; }

  /* ---------- chat ---------- */
  .chat.open { width: 100%; }
  .chat-head { padding: 0 10px 0 14px; }
  .chat-head button { min-width: 38px; min-height: 38px; }
  .chat-log { padding: 14px; }
  .chat-form { padding: 10px 12px calc(10px + var(--safe-b)); }
  .chat-form textarea { font-size: 16px; min-height: 42px; }
  .chat-form button { width: 42px; height: 42px; }
  .suggestions button { padding: 11px 12px; }

  /* ---------- documentation page ---------- */
  .doc { padding: 20px 14px calc(var(--bottomnav-h) + var(--safe-b) + 32px); }
  .doc h1 { font-size: 22px; }
  .doc .lede { font-size: 14px; margin-bottom: 22px; }
  .doc h2 { font-size: 16px; margin: 30px 0 8px; padding-top: 16px; }
  .doc h3 { font-size: 14px; }
  .doc .tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .doc table { font-size: 12.5px; }
  .doc th, .doc td { padding: 7px 9px; }
  .doc pre { font-size: 11.5px; padding: 11px 12px; }
  .figure { padding: 12px 10px; }
  .toc { padding: 12px 14px; }
  .footnote { font-size: 11.5px; }
}

/* Very small phones: two-up cells get too cramped, so go single column. */
@media (max-width: 359px) {
  .toolbar .field, .alert-form .field, .toggle { flex-basis: 100%; }
  .tiles { grid-template-columns: 1fr; }
  .tile:nth-child(3) { grid-column: auto; }
  .sidebar .nav .label, body.nav-collapsed .sidebar .nav .label { font-size: 9px; }
}

/* ============================================================
   Grouped rows — the best of a week, with its siblings folded in
   ============================================================ */
.more {
  display: inline-block; margin-left: 6px; padding: 0 6px;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--neutral-bg); color: var(--ink-2);
  font-size: 10.5px; font-weight: 600; line-height: 17px;
  cursor: pointer; vertical-align: middle;
}
.more:hover { border-color: var(--accent); color: var(--accent); }
#tbl tbody tr.child > td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
#tbl tbody tr.child { background: var(--hover); }

@media (max-width: 760px) {
  #tbl tbody tr.child { margin-left: 14px; }
  #tbl tbody tr.child > td:first-child { box-shadow: none; }
}
