/* ========================================================================
   Nunito — vendored locally so the UI works fully offline.
   Variable font (weights 400–800), Latin subsets only. Files in static/fonts.
   ===================================================================== */
@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("/static/fonts/nunito-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("/static/fonts/nunito-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ========================================================================
   Design tokens — edit the palette here to re-theme the whole UI.
   Current theme: "Peach & Sage" pastels on a soft-dark warm base.
   ===================================================================== */
:root {
  /* === Palette === */
  --bg:          #221f1c;  /* warm near-black page background */
  --surface:     #2e2a26;  /* cards / bar / panel */
  --surface-2:   #38332e;  /* inputs, hover rows */
  --border:      #45403a;  /* subtle warm border */
  --text:        #f2ece4;  /* primary text (high contrast for TV) */
  --text-dim:    #b8ad9f;  /* secondary text */
  --text-mute:   #897f72;  /* hints / muted */

  --primary:     #f6c2a8;  /* peach — primary actions / labels */
  --primary-ink: #3d2a1e;  /* text on peach */
  --accent:      #b3d4b8;  /* sage — success / points / selected */
  --accent-ink:  #1f2e22;  /* text on sage */
  --cool:        #bcd4e6;  /* cool blue — secondary accent */
  --cool-ink:    #1d2a33;  /* text on cool blue */
  --danger:      #e8a0a0;  /* soft red — remove / errors */

  /* tinted glows derived from accents (used for focus rings / hovers) */
  --primary-glow: rgba(246, 194, 168, 0.30);
  --accent-tint:  rgba(179, 212, 184, 0.16);

  /* === Scale === */
  --font: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --fs-base: 1.15rem;   /* bumped up for TV legibility */
  --fs-sm:   1rem;
  --fs-lg:   1.4rem;

  --radius:    14px;
  --radius-sm: 9px;

  --shadow:    0 6px 22px rgba(0, 0, 0, 0.30);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.22);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

body {
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.5;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  display: flex;
  -webkit-font-smoothing: antialiased;
}

#app { flex: 1; padding: 1.5rem; min-width: 0; }

/* ====================== Forms & buttons (shared) ====================== */
input {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

button {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.85rem;
  transition: transform 0.12s var(--ease), background 0.15s, box-shadow 0.15s, color 0.15s;
}
button:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
button:active { transform: translateY(0); box-shadow: none; }
button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* ============================== Top bar ============================== */
.bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.1rem;
}
.bar .budget-form { display: flex; align-items: center; gap: 0.6rem; flex: 1; flex-wrap: wrap; }
.bar label { color: var(--text-dim); font-weight: 600; }
.bar input { width: 7rem; }

.bar .remaining {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--accent);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
}
.bar .loaded-plan {
  color: var(--cool-ink);
  background: var(--cool);
  font-weight: 600;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
}
.bar .err { color: var(--danger); font-weight: 600; }
.bar .actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

/* Nav link styled to match the button row it sits in. */
.btn-link {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.85rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: transform 0.12s var(--ease), background 0.15s, box-shadow 0.15s, color 0.15s;
}
.btn-link:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-link:active { transform: translateY(0); box-shadow: none; }
.btn-link:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* "+ Add trip" — the primary call to action */
.bar .actions button:last-of-type {
  background: var(--primary);
  color: var(--primary-ink);
  border-color: transparent;
}

/* ============================ Trip cards ============================ */
.trip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.1rem;
  padding: 1rem 1.2rem;
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease);
  animation: fade-in-up 0.22s var(--ease) both;
}
.trip:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(0, 0, 0, 0.34); }
.trip.collapsed { padding: 0.6rem 1.2rem; box-shadow: var(--shadow-sm); }

.trip-header { display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; }
.trip.collapsed .trip-header { flex-wrap: nowrap; }

.trip-label {
  font-weight: 800;
  font-size: var(--fs-sm);
  letter-spacing: 0.08em;
  color: var(--primary);
}

.trip-toggle {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1.05rem;
  color: var(--text-dim);
  padding: 0 0.25rem;
  line-height: 1;
  transition: color 0.15s, transform 0.2s var(--ease);
}
.trip-toggle:hover { color: var(--primary); transform: none; box-shadow: none; }

.trip-form { display: flex; align-items: center; gap: 0.75rem; flex: 1; flex-wrap: wrap; }
.trip-form label { display: flex; align-items: center; gap: 0.4rem; color: var(--text-dim); font-weight: 600; }
.trip-form input { width: 7.5rem; }

.trip-budget {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-weight: 600;
}
/* Per-trip filter chip: bold for override, faint for inherit. */
.filters-chip {
  font-size: var(--fs-sm);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.filters-chip.override { color: var(--primary); font-weight: 800; }
.filters-chip.inherit { color: var(--text-mute); font-weight: 400; }

.trip-filters {
  font-size: var(--fs-sm);
  padding: 0.3rem 0.7rem;
}

.trip-remove {
  color: var(--danger);
  border: none;
  background: transparent;
  font-size: 1.3rem;
  line-height: 1;
  padding: 0 0.4rem;
}
.trip-remove:hover { background: rgba(232, 160, 160, 0.16); box-shadow: none; }

/* Collapsed summary line */
.trip-summary {
  display: flex;
  gap: 0.9rem;
  align-items: center;
  flex: 1;
  min-width: 0;
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-sm);
  overflow: hidden;
}
.trip-summary .summary-dates { color: var(--text); white-space: nowrap; }
.trip-summary .summary-room { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trip-summary .summary-points {
  color: var(--accent-ink);
  background: var(--accent);
  font-weight: 700;
  white-space: nowrap;
  margin-left: auto;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
}
.trip-summary .muted { color: var(--text-mute); font-style: italic; }
.trip-summary .summary-points.muted { color: var(--text-mute); background: var(--surface-2); }

/* ============================ Results table ============================ */
.results { margin-top: 0.9rem; }
.results-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.results-table th,
.results-table td {
  padding: 0.5rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm);
}
.results-table th {
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  text-transform: uppercase;
  border-bottom-width: 2px;
}
.results-table tbody tr {
  transition: background 0.15s;
  animation: fade-in-up 0.2s var(--ease) both;
}
.results-table tbody tr:hover { background: var(--surface-2); }
.results-table tr.selected {
  background: var(--accent-tint);
  box-shadow: inset 4px 0 0 var(--accent);
}

.select-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  min-width: 2rem;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  text-align: center;
}
.results-table tr.selected .select-btn {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.empty, .err { color: var(--text-mute); padding: 0.6rem 0; }
.err { color: var(--danger); }

/* ============================== Side panel ============================== */
#panel { width: 0; transition: width 0.28s var(--ease); overflow-x: hidden; }
#panel.panel { width: 400px; }

.panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  height: 100vh;
  padding: 1.5rem;
  overflow-y: auto;
}
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.panel-header h2 { margin: 0; font-size: var(--fs-lg); font-weight: 800; color: var(--primary); }
.panel h3 {
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 1.2rem 0 0.5rem;
}
.panel form { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.panel form label { display: flex; align-items: center; gap: 0.4rem; color: var(--text-dim); font-weight: 600; }

/* Per-trip filter panel: inherit/override mode switch + reset. */
.filter-mode-switch {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}
.filter-mode-switch .mode-btn { font-size: var(--fs-sm); }
.filter-mode-switch .mode-btn.active {
  background: var(--primary);
  color: var(--primary-ink);
  border-color: transparent;
}
.filter-list li button[disabled] {
  color: var(--text-mute);
  cursor: not-allowed;
  opacity: 0.6;
}
.filter-reset { margin: 0 0 1rem 0; }

.filter-list, .plan-list { list-style: none; padding: 0; margin: 0 0 1rem 0; }
.filter-list li button {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
}
.filter-list li button:hover { background: var(--surface-2); transform: none; box-shadow: none; }
.filter-list li.excluded button { color: var(--text-mute); font-weight: 400; }

.plan-list li {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
}
.plan-list strong { font-weight: 800; }
.plan-list .meta { color: var(--text-mute); font-size: var(--fs-sm); }
.panel-hint { color: var(--text-mute); font-size: var(--fs-sm); line-height: 1.45; }

/* ============================== Motion ============================== */
@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ============================== Points ledger ============================== */
.ledger-body section { margin-bottom: 1.6rem; }
.ledger-body table {
  border-collapse: collapse;
  width: 100%;
}
.ledger-body th,
.ledger-body td {
  border: 1px solid var(--border);
  padding: 0.3rem 0.5rem;
  text-align: left;
}
.ledger-body th { color: var(--text-mute); font-size: var(--fs-sm); }
.ledger-body tr.negative td,
.ledger-body .negative { color: var(--danger); }
.ledger-body tr.over-borrowed td { background: rgba(232, 160, 160, 0.12); }
.ledger-body .entry-form {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 0.6rem;
}
.ledger-body .err { color: var(--danger); }

/* ============================== Narrow viewport ============================== */
@media (max-width: 640px) {
  :root {
    --fs-base: 1rem;  /* TV-legible base is too large on a phone */
    --fs-lg:   1.25rem;
  }

  body { flex-direction: column; }
  #app { padding: 0.9rem; }

  /* Side panel (Filters/Plans) takes the full width instead of a fixed
     400px column, and no longer forces a full-height viewport slab. */
  #panel.panel { width: 100%; height: auto; max-height: 80vh; }

  /* Budget bar + button row wrap onto multiple lines instead of
     overflowing the viewport. */
  .bar { flex-wrap: wrap; }
  .bar .actions { width: 100%; }
  .bar .actions button,
  .bar .actions .btn-link { flex: 1 1 auto; text-align: center; }

  /* Trip card: from/to/min-nights form stacks vertically, full width. */
  .trip { padding: 0.85rem 1rem; }
  .trip-form { flex-direction: column; align-items: stretch; gap: 0.6rem; }
  .trip-form label { justify-content: space-between; gap: 0.6rem; }
  .trip-form input { width: 100%; }

  /* Comfortable tap targets. */
  button, .btn-link { padding: 0.55rem 0.9rem; }
  .trip-toggle, .trip-remove { padding: 0.45rem 0.55rem; }
  .select-btn { min-width: 2.5rem; padding: 0.45rem 0.6rem; }

  /* Results and ledger tables scroll horizontally in their own
     container rather than squeezing columns unreadably thin. */
  .results { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .results-table { min-width: 560px; }

  .ledger-body section { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .ledger-body table { min-width: 520px; }
}

/* ============================ Login page ============================ */
.login-page {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 22rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.login-form h1 {
  margin: 0 0 0.4rem;
  font-size: var(--fs-lg);
  font-weight: 800;
  color: var(--primary);
}
.login-form label { color: var(--text-dim); font-weight: 600; }
.login-form input { width: 100%; }
.login-form button { align-self: flex-start; }
