:root {
  --bg: #0b0f14;
  --bg-raised: #131a22;
  --bg-card: #161e27;
  --border: #253140;
  --text: #eef2f6;
  --text-dim: #9fb0c0;
  --text-faint: #5c6b7a;
  --accent: #4fc3f7;
  --accent-dim: #1c3a4a;
  --warn: #ffb74d;
  --warn-bg: #3a2a12;
  --good: #66bb6a;
  --good-bg: #123a1a;
  --danger: #ef5350;
  --danger-bg: #3a1414;
  --radius: 14px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8;
    --bg-raised: #ffffff;
    --bg-card: #ffffff;
    --border: #dde3ea;
    --text: #14202b;
    --text-dim: #4b5b6b;
    --text-faint: #8a97a4;
    --accent: #0277bd;
    --accent-dim: #d6ecfa;
    --warn: #a15c00;
    --warn-bg: #fff2df;
    --good: #2e7d32;
    --good-bg: #e6f4e8;
    --danger: #c62828;
    --danger-bg: #fceaea;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

/* #unlock/#app set their own `display` (flex), which otherwise outranks the
   UA default `[hidden] { display: none }` by specificity (ID > attribute).
   Force it explicitly so toggling the `hidden` property actually hides them. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
}

/* --- Unlock screen --- */
#unlock {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.unlock-box {
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.unlock-box h1 {
  font-size: 1.6rem;
  margin: 0 0 4px;
}
.muted { color: var(--text-dim); font-size: 0.9rem; }
#unlock-form {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}
#pass-input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  font-size: 1rem;
}
button {
  padding: 12px 18px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #001018;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  font-family: inherit;
}
button:active { opacity: 0.8; }
.error { color: var(--danger); margin-top: 14px; font-size: 0.9rem; }
.shake { animation: shake 0.3s; }
@keyframes shake {
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* --- App shell --- */
#app { padding: 0 0 40px; position: relative; }

/* --- Test mode banner --- */
.testmode-banner {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--warn);
}
.testmode-banner:active { opacity: 0.85; }

#hero {
  position: relative;
  padding: 20px 52px 16px 16px;
  background: linear-gradient(180deg, var(--accent-dim), transparent);
  border-bottom: 1px solid var(--border);
}
#hero .day-count { font-size: 0.85rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
#hero .status-line { font-size: 1.3rem; font-weight: 700; margin: 6px 0 10px; }
#hero .clocks { display: flex; gap: 18px; font-size: 0.9rem; color: var(--text-dim); flex-wrap: wrap; }
#hero .clocks strong { color: var(--text); font-variant-numeric: tabular-nums; }

.testmode-btn {
  position: absolute;
  top: 16px;
  right: 12px;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* --- Trip progress bar --- */
.trip-progress {
  margin-top: 12px;
  position: relative;
}
.trip-progress-track {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
  position: relative;
}
.trip-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
}
.trip-progress-marks {
  position: relative;
  height: 6px;
}
.trip-progress-mark {
  position: absolute;
  top: -8px;
  width: 2px;
  height: 14px;
  background: var(--text-faint);
  opacity: 0.6;
}
.trip-progress-label {
  font-size: 0.72rem;
  color: var(--text-faint);
  margin-top: 4px;
}

/* --- Section nav (scroll-spy) --- */
.section-nav {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.section-nav a {
  flex: 1;
  text-align: center;
  padding: 6px 4px;
  border-radius: 8px;
  font-size: 1.05rem;
  color: var(--text-dim);
  text-decoration: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
}
.section-nav a:active { background: var(--accent-dim); }
.section-nav a.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}

/* --- Layout grid --- */
.layout {
  padding: 14px 12px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
@media (min-width: 900px) {
  .layout {
    grid-template-columns: 1fr 400px;
    grid-template-areas:
      "nextup   map"
      "timeline map"
      "payments map"
      "split    map"
      "bookings map"
      "bars     map"
      "places   map";
    align-items: start;
    max-width: 1200px;
    margin: 0 auto;
  }
  #next-up   { grid-area: nextup; }
  #map-section { grid-area: map; position: sticky; top: 54px; align-self: start; }
  #timeline  { grid-area: timeline; }
  #payments  { grid-area: payments; }
  #split     { grid-area: split; }
  #bookings  { grid-area: bookings; }
  #bars      { grid-area: bars; }
  #places    { grid-area: places; }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 0 0 10px;
}

/* --- Where you should be (right now) strip --- */
.whereabouts {
  border-left: 3px solid var(--accent);
}
.whereabouts .wb-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.whereabouts .wb-head { font-size: 1.02rem; font-weight: 650; margin-top: 4px; }
.whereabouts .wb-sub { color: var(--text-dim); font-size: 0.88rem; margin-top: 4px; }

/* --- Next up card --- */
#next-up .countdown {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
#next-up .title { font-size: 1.05rem; font-weight: 600; margin-top: 2px; }
#next-up .meta { color: var(--text-dim); font-size: 0.88rem; margin-top: 4px; }
#next-up .then { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); color: var(--text-dim); font-size: 0.88rem; }
#next-up .then .title { color: var(--text); font-weight: 500; font-size: 0.95rem; }
#next-up .pay-note { margin-top: 10px; padding: 8px 10px; background: var(--warn-bg); border-radius: 8px; font-size: 0.85rem; color: var(--warn); }
#next-up .nu-nominal { color: var(--text-faint); font-size: 0.82rem; }

/* --- Staleness warning --- */
.staleness-warn {
  margin-top: 10px;
  padding: 8px 10px;
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: 8px;
  font-size: 0.78rem;
}

/* --- Timeline --- */
#timeline { display: flex; flex-direction: column; gap: 8px; }
.tl-item {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  align-items: flex-start;
  cursor: pointer;
}
.tl-item:active { background: var(--accent-dim); }
.tl-item.past { opacity: 0.45; }
.tl-item.current {
  border-color: var(--accent);
  background: var(--accent-dim);
  opacity: 1;
}
.tl-item.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.tl-item.warn { border-color: var(--warn); background: var(--warn-bg); }
.tl-icon { font-size: 1.3rem; line-height: 1.4; flex-shrink: 0; }
.tl-body { flex: 1; min-width: 0; }
.tl-title { font-weight: 600; font-size: 0.95rem; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.tl-when { color: var(--text-dim); font-size: 0.82rem; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tl-detail { color: var(--text-dim); font-size: 0.82rem; margin-top: 4px; }
.tl-guide { color: var(--accent); font-size: 0.8rem; margin-top: 4px; }
.tl-check { color: var(--good); }
.tl-stay-span { font-size: 0.78rem; color: var(--text-faint); margin-top: 2px; }

.tl-outstanding-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--danger-bg);
  color: var(--danger);
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
}

/* Pay-on-the-day badge — always visible on the tile face */
.pay-badge {
  margin-top: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  border-left-width: 3px;
}
.pay-badge-head {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  opacity: 0.85;
}
.pay-badge-amt {
  font-size: 0.9rem;
  font-weight: 700;
  margin-top: 1px;
  font-variant-numeric: tabular-nums;
}
.pay-badge-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin-top: 3px;
  font-size: 0.78rem;
}
.pay-badge-method { font-weight: 600; }
.pay-badge-split { opacity: 0.85; }
.pay-badge-split::before { content: "· "; opacity: 0.6; }

/* Joint = even by default (green) */
.pay-badge.pay-joint {
  background: var(--good-bg);
  border-color: var(--good);
  color: var(--good);
}
/* Personal card fronted = settle later to stay even (amber) */
.pay-badge.pay-personal {
  background: var(--warn-bg);
  border-color: var(--warn);
  color: var(--warn);
}
/* Refundable deposit hold = nothing to split (neutral) */
.pay-badge.pay-hold {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--text-dim);
}

/* --- Past-collapse summary row --- */
.tl-collapsed-summary {
  padding: 10px 14px;
  background: var(--bg-raised);
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--text-dim);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.tl-collapsed-summary:active { background: var(--accent-dim); }
.tl-collapsed-group { display: flex; flex-direction: column; gap: 6px; }
.tl-compact {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.82rem;
  color: var(--text-dim);
  cursor: pointer;
  opacity: 0.65;
}
.tl-compact:active { opacity: 1; }
.tl-compact .tl-compact-title { color: var(--text); flex: 1; }

/* --- Refs --- */
.ref {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  cursor: pointer;
}
.ref:active { background: var(--accent-dim); }

.gmaps-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
  font-size: 0.82rem;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  margin-top: 8px;
}
.gmaps-link:active { background: var(--accent-dim); }

/* --- Payments --- */
.pay-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.pay-row:last-of-type { border-bottom: none; }
.pay-row .pay-where { font-weight: 600; font-size: 0.9rem; }
.pay-row .pay-meta { color: var(--text-dim); font-size: 0.8rem; margin-top: 2px; }
.pay-row .pay-amount { text-align: right; font-weight: 700; white-space: nowrap; }
.pay-check { flex-shrink: 0; width: 20px; height: 20px; margin-top: 2px; }
.pay-note { color: var(--warn); font-size: 0.78rem; margin-top: 2px; }
.balance-note { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); font-size: 0.82rem; color: var(--text-dim); }
.small-print { font-size: 0.72rem; color: var(--text-faint); margin-top: 10px; }

/* --- Split & settlement panel --- */
.split-net {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent);
}
.split-asat { font-size: 0.78rem; color: var(--text-faint); margin-top: 2px; }
.split-outstanding { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.split-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.split-row:active { background: var(--accent-dim); }
.split-row .split-what { font-size: 0.88rem; font-weight: 600; }
.split-row .split-direction { font-size: 0.78rem; color: var(--text-dim); margin-top: 2px; }
.split-row .split-amount { font-weight: 700; white-space: nowrap; }
.split-totals {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.split-totals strong { color: var(--text); }

.insurance-card {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.82rem;
  color: var(--text-dim);
}

/* --- Bookings tables --- */
.bookings-group { margin-top: 18px; }
.bookings-group:first-of-type { margin-top: 0; }
.bookings-group h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin: 0 0 8px;
}
.bookings-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}
table.bookings-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 0.82rem;
}
table.bookings-table th,
table.bookings-table td {
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
table.bookings-table td.wrap { white-space: normal; min-width: 180px; }
table.bookings-table th {
  position: sticky;
  top: 0;
  background: var(--bg-raised);
  color: var(--text-faint);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
}
table.bookings-table tr:last-child td { border-bottom: none; }
table.bookings-table tr:hover td { background: var(--accent-dim); }
table.bookings-table .id-cell { color: var(--text-faint); font-variant-numeric: tabular-nums; }
table.bookings-table .amount-cell { font-weight: 700; white-space: nowrap; }
table.bookings-table .note-cell { color: var(--text-dim); font-size: 0.78rem; white-space: normal; min-width: 220px; }
.insurance-card .insurance-title { font-weight: 700; color: var(--text); margin-bottom: 2px; }

/* --- Settled badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}
.badge-good { background: var(--good-bg); color: var(--good); }
.badge-bad { background: var(--danger-bg); color: var(--danger); }
.badge-neutral { background: var(--border); color: var(--text-dim); }

/* --- Bars --- */
.bar-city-group { margin-bottom: 14px; }
.bar-city-group:last-child { margin-bottom: 0; }
.bar-city-group h3 { font-size: 0.85rem; margin: 0 0 6px; color: var(--text); display: flex; align-items: center; gap: 6px; }
.bar-row { display: flex; align-items: baseline; gap: 8px; padding: 5px 0; font-size: 0.88rem; }
.bar-row.visited { opacity: 0.55; }
.bar-rank { color: var(--accent); font-weight: 700; font-size: 0.78rem; width: 2.4em; flex-shrink: 0; }
.bar-name { font-weight: 500; }
.bar-area { color: var(--text-dim); font-size: 0.8rem; }
.bar-note { color: var(--text-faint); font-size: 0.78rem; }
.bar-gmaps { margin-left: auto; color: var(--accent); text-decoration: none; font-size: 0.85rem; flex-shrink: 0; }

/* --- Places --- */
.place-city-group { margin-bottom: 10px; }
.place-city-group h3 { font-size: 0.85rem; margin: 0 0 4px; }
.place-empty { color: var(--text-faint); font-size: 0.82rem; }

footer#footer {
  text-align: center;
  color: var(--text-faint);
  font-size: 0.75rem;
  padding: 18px 16px 6px;
}
footer#footer button {
  margin-top: 10px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-weight: 500;
  padding: 6px 14px;
  font-size: 0.8rem;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 100;
}

/* --- Bottom sheet / side panel (detail sheet + test mode panel) --- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 18px 18px 0 0;
  padding: 10px 18px 20px;
}
.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 4px auto 14px;
}
.sheet-close {
  width: 100%;
  margin-top: 16px;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
}
@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 18px; border-bottom: 1px solid var(--border); }
}

.sheet-title { font-size: 1.15rem; font-weight: 700; margin-bottom: 2px; }
.sheet-sub { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 14px; }
.sheet-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.sheet-row:last-of-type { border-bottom: none; }
.sheet-row .sheet-label { color: var(--text-dim); }
.sheet-row .sheet-value { font-weight: 600; text-align: right; }
.sheet-note {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--bg-raised);
  border-radius: 10px;
  font-size: 0.82rem;
  color: var(--text-dim);
}

/* --- Test mode panel --- */
.tm-presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.tm-chip {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.8rem;
  padding: 8px 12px;
  border-radius: 999px;
}
.tm-chip:active { background: var(--accent-dim); }
.tm-custom { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.tm-custom label { font-size: 0.78rem; color: var(--text-dim); }
.tm-custom input, .tm-custom select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  font-size: 0.95rem;
}
.tm-live-btn { width: 100%; background: var(--bg-raised); color: var(--text); border: 1px solid var(--border); }

/* --- Map --- */
.map-card { padding: 0; overflow: hidden; }
.map-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.map-toolbar h2 { margin: 0; }
.map-toolbar-btns { display: flex; gap: 6px; }
.map-toolbar button {
  background: var(--bg-raised);
  color: var(--text-dim);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  padding: 5px 9px;
}
.map-viewport {
  height: 190px;
  transition: height 0.25s ease;
  background: var(--bg-raised);
}
.map-card.map-expanded .map-viewport { height: 360px; }
@media (min-width: 900px) {
  .map-viewport { height: min(72vh, 640px); }
  #map-expand-btn { display: none; }
}
.map-viewport svg { width: 100%; height: 100%; display: block; }

.map-coastline { fill: var(--bg); stroke: var(--border); stroke-width: 0.4; }
.map-route-past { stroke: var(--text-faint); stroke-width: 1.4; fill: none; opacity: 0.7; }
.map-route-future { stroke: var(--text-dim); stroke-width: 1.2; fill: none; stroke-dasharray: 3 3; opacity: 0.6; }
.map-route-current { stroke: var(--accent); stroke-width: 2.2; fill: none; }
.map-marker-dot { fill: var(--text-faint); stroke: var(--bg); stroke-width: 1; cursor: pointer; }
.map-marker-dot.future { fill: none; stroke: var(--text-dim); stroke-width: 1.2; }
.map-marker-dot.current { fill: var(--accent); }
.map-marker-dot.selected { stroke: var(--accent); stroke-width: 2; }
.map-marker-pulse {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  opacity: 0.7;
  animation: map-pulse 1.8s ease-out infinite;
  transform-origin: center;
}
@keyframes map-pulse {
  0% { r: 4; opacity: 0.7; }
  100% { r: 12; opacity: 0; }
}
.map-marker-label {
  font-size: 3.6px;
  fill: var(--text-dim);
  pointer-events: none;
}
.map-marker-label.current { fill: var(--text); font-weight: 700; }
.map-home-chip {
  font-size: 3.2px;
  fill: var(--text-faint);
}
