/* ═══════════════════════════════════════════════
   TRAVEL TRACKER v2 — Direction-aware + Custom Pickers
   ═══════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ── Design Tokens ── */
:root {
  --bg-base: hsl(222, 28%, 8%);
  --bg-surface: hsl(225, 24%, 12%);
  --bg-elevated: hsl(226, 22%, 16%);
  --bg-hover: hsl(226, 20%, 20%);
  --border: hsl(225, 18%, 22%);

  --text-primary: hsl(210, 40%, 96%);
  --text-secondary: hsl(215, 20%, 65%);
  --text-muted: hsl(215, 15%, 45%);

  /* Direction colours */
  --h2o-color: hsl(28, 95%, 62%);
  /* amber  — Home→Office */
  --h2o-bg: hsl(28, 70%, 13%);
  --h2o-border: hsl(28, 55%, 28%);
  --o2h-color: hsl(180, 85%, 55%);
  /* teal   — Office→Home */
  --o2h-bg: hsl(180, 55%, 11%);
  --o2h-border: hsl(180, 45%, 24%);
  --h2t-color: hsl(340, 90%, 65%);
  /* rose   — Home→Trip */
  --h2t-bg: hsl(340, 65%, 13%);
  --h2t-border: hsl(340, 55%, 28%);
  --t2h-color: hsl(260, 85%, 72%);
  /* violet — Trip→Home */
  --t2h-bg: hsl(260, 55%, 13%);
  --t2h-border: hsl(260, 50%, 28%);
  --both-color: hsl(280, 75%, 70%);
  /* purple — both in one day */
  --both-bg: hsl(280, 50%, 15%);
  --home-color: hsl(145, 65%, 55%);
  /* green  — at home */
  --home-bg: hsl(145, 45%, 11%);
  --today-color: hsl(200, 100%, 65%);

  --accent: hsl(258, 80%, 68%);
  --danger: hsl(356, 75%, 60%);
  --danger-dark: hsl(356, 65%, 48%);

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 4px 24px rgba(0, 0, 0, .45);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, .65);
}

/* ── Light Theme ── */
:root.light {
  --bg-base: hsl(210, 30%, 96%);
  --bg-surface: hsl(0, 0%, 100%);
  --bg-elevated: hsl(210, 25%, 92%);
  --bg-hover: hsl(210, 20%, 86%);
  --border: hsl(210, 18%, 80%);

  --text-primary: hsl(220, 30%, 12%);
  --text-secondary: hsl(215, 18%, 38%);
  --text-muted: hsl(215, 14%, 58%);

  --h2o-bg: hsl(28, 80%, 92%);
  --h2o-border: hsl(28, 60%, 72%);
  --o2h-bg: hsl(180, 60%, 90%);
  --o2h-border: hsl(180, 50%, 62%);
  --h2t-bg: hsl(340, 70%, 93%);
  --h2t-border: hsl(340, 55%, 70%);
  --t2h-bg: hsl(260, 60%, 93%);
  --t2h-border: hsl(260, 50%, 70%);
  --both-bg: hsl(280, 50%, 93%);
  --home-bg: hsl(145, 50%, 90%);

  --shadow: 0 4px 24px rgba(0, 0, 0, .10);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, .16);
}

:root.light body {
  background-color: hsl(210, 30%, 96%);
  background-image:
    radial-gradient(ellipse 80% 50% at 20% -10%, hsl(258, 60%, 92%), transparent),
    radial-gradient(ellipse 60% 40% at 80% 110%, hsl(180, 50%, 88%), transparent);
}

:root.light .app-header {
  background: rgba(255, 255, 255, .75);
}

:root.light select option {
  background: hsl(210, 25%, 92%);
  color: hsl(220, 30%, 12%);
}

:root.light .cal-day.untracked-day {
  background: hsl(210, 20%, 88%);
  color: hsl(215, 15%, 55%);
}

:root.light .cal-day.at-home-day {
  background: hsl(145, 50%, 86%);
  border-color: hsl(145, 45%, 65%);
  color: hsl(145, 55%, 28%);
}

:root.light .cal-day.at-office-day {
  background: hsl(265, 45%, 88%);
  border-color: hsl(265, 45%, 65%);
  color: hsl(265, 55%, 32%);
}

:root.light .ticket-card {
  background: hsl(0, 0%, 99%);
}

:root.light .modal {
  background: hsl(0, 0%, 100%);
}

:root.light .modal-overlay {
  background: rgba(0, 0, 50, .4);
}


/* ── Reset ── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  background-image:
    radial-gradient(ellipse 80% 50% at 20% -10%, hsl(258, 55%, 18%), transparent),
    radial-gradient(ellipse 60% 40% at 80% 110%, hsl(180, 45%, 10%), transparent);
}

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ══════════
   HEADER
══════════ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .9rem 2rem;
  background: rgba(0, 0, 0, .25);
  backdrop-filter: blur(2.5px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1.2rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: .6rem;
}

.logo-icon {
  font-size: 1.5rem;
}

.logo-icon-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
}

.logo-text {
  font-size: 1.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--h2o-color), var(--o2h-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  font-size: .78rem;
  color: var(--text-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.current-date {
  font-size: .82rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ══════════
   BUTTONS
══════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.2rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), hsl(220, 80%, 65%));
  color: #fff;
  box-shadow: 0 4px 16px rgba(130, 88, 255, .4);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(130, 88, 255, .55);
}

.btn-ghost {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger), var(--danger-dark));
  color: #fff;
}

.btn-danger:hover {
  transform: translateY(-1px);
}

.btn-sm {
  padding: .38rem .85rem;
  font-size: .8rem;
}

.btn-icon {
  padding: .38rem .5rem;
  font-size: .76rem;
  border-radius: 6px;
}

/* ══════════
   MAIN GRID
══════════ */
.app-main {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  gap: 1.25rem;
  padding: 1.25rem 1.5rem;
  align-items: start;
}

.panel-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
  transition: box-shadow .25s;
}

.panel-card:hover {
  box-shadow: var(--shadow-lg);
}

.card-title {
  font-size: .85rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 1rem;
}

/* ── Stats ── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .7rem;
  margin-bottom: 1rem;
}

.stat-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .8rem .65rem;
  text-align: center;
  transition: transform .2s;
}

.stat-item:hover {
  transform: scale(1.04);
}

.stat-item.home {
  border-color: hsl(145, 40%, 22%);
}

.stat-item.away {
  border-color: hsl(280, 40%, 28%);
}

.stat-item.h2o {
  border-color: var(--h2o-border);
}

.stat-item.o2h {
  border-color: var(--o2h-border);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1;
  margin-bottom: .3rem;
}

.stat-item.home .stat-value {
  color: var(--home-color);
}

.stat-item.away .stat-value {
  color: var(--both-color);
}

.stat-item.h2o .stat-value {
  color: var(--h2o-color);
}

.stat-item.o2h .stat-value {
  color: var(--o2h-color);
}

.stat-label {
  font-size: .68rem;
  color: var(--text-muted);
  font-weight: 500;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: .76rem;
  color: var(--text-secondary);
  margin-bottom: .4rem;
}

.progress-track {
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--home-color), hsl(160, 60%, 55%));
  transition: width .6s cubic-bezier(.34, 1.56, .64, 1);
}

/* ── Next Trip ── */
.next-trip-info {
  display: flex;
  flex-direction: column;
  gap: .45rem;
  font-size: .875rem;
}

.trip-route {
  font-size: .95rem;
  font-weight: 700;
}

.trip-countdown {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--h2o-color);
  letter-spacing: -.02em;
}

.trip-meta {
  font-size: .78rem;
  color: var(--text-muted);
}

.trip-badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 700;
  margin-bottom: .2rem;
}

.trip-badge.h2o {
  background: var(--h2o-bg);
  color: var(--h2o-color);
  border: 1px solid var(--h2o-border);
}

.trip-badge.o2h {
  background: var(--o2h-bg);
  color: var(--o2h-color);
  border: 1px solid var(--o2h-border);
}

.trip-badge.h2t {
  background: var(--h2t-bg);
  color: var(--h2t-color);
  border: 1px solid var(--h2t-border);
}

.trip-badge.t2h {
  background: var(--t2h-bg);
  color: var(--t2h-color);
  border: 1px solid var(--t2h-border);
}

/* ── All-Time ── */
.all-time-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  text-align: center;
}

.all-stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
}

.all-stat-label {
  font-size: .73rem;
  color: var(--text-muted);
  margin-top: .2rem;
}

/* ════════════
   CALENDAR
════════════ */
.calendar-card {
  margin-bottom: 0;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.cal-nav {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
}

.cal-nav:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.cal-month-label {
  font-size: 1.05rem;
  font-weight: 700;
}

.calendar-legend {
  display: flex;
  align-items: center;
  gap: .55rem;
  flex-wrap: wrap;
  font-size: .73rem;
  color: var(--text-muted);
  margin-bottom: .85rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-dot.home-dot {
  background: var(--home-color);
}

.legend-dot.h2o-dot {
  background: var(--h2o-color);
}

.legend-dot.o2h-dot {
  background: var(--o2h-color);
}

.legend-dot.both-dot {
  background: var(--both-color);
}

.legend-dot.h2t-dot {
  background: var(--h2t-color);
}

.legend-dot.t2h-dot {
  background: var(--t2h-color);
}

.legend-dot.today-dot {
  background: var(--today-color);
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
}

.calendar-weekdays div {
  text-align: center;
  font-size: .68rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: .3rem 0;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 500;
  position: relative;
  transition: all .18s;
  border: 1px solid transparent;
  user-select: none;
}

.cal-day.empty {
  cursor: default;
}

.cal-day.past {
  opacity: .45;
}

.cal-day:not(.empty):hover {
  border-color: var(--border);
  transform: scale(1.12);
  z-index: 2;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
}

.cal-day.home-day {
  background: var(--home-bg);
  border-color: hsl(145, 35%, 18%);
  color: var(--home-color);
}

.cal-day.h2o-day {
  background: var(--h2o-bg);
  border-color: var(--h2o-border);
  color: var(--h2o-color);
}

.cal-day.o2h-day {
  background: var(--o2h-bg);
  border-color: var(--o2h-border);
  color: var(--o2h-color);
}

.cal-day.both-day {
  background: var(--both-bg);
  border-color: hsl(280, 40%, 30%);
  color: var(--both-color);
}

/* ── New 5-state classes (used by CalendarEngine v2) ── */
.cal-day.untracked-day {
  background: var(--bg-elevated);
  border-color: transparent;
  color: var(--text-muted);
}

.cal-day.at-home-day {
  background: hsl(145, 45%, 12%);
  border-color: hsl(145, 45%, 24%);
  color: hsl(145, 65%, 62%);
}

.cal-day.at-office-day {
  background: hsl(265, 45%, 14%);
  border-color: hsl(265, 45%, 30%);
  color: hsl(265, 70%, 72%);
}

.cal-day.at-trip-day {
  background: hsl(340, 45%, 14%);
  border-color: hsl(340, 45%, 30%);
  color: hsl(340, 70%, 72%);
}

.cal-day.h2t-day {
  background: var(--h2t-bg);
  border-color: var(--h2t-border);
  color: var(--h2t-color);
}

.cal-day.t2h-day {
  background: var(--t2h-bg);
  border-color: var(--t2h-border);
  color: var(--t2h-color);
}

.cal-day.today-day {
  border-color: var(--today-color) !important;
  box-shadow: 0 0 0 2px hsla(200, 100%, 65%, .3);
}

.cal-day .day-num {
  font-weight: 700;
  line-height: 1;
}

.cal-day .day-icon {
  font-size: .65rem;
  margin-top: 1px;
}

.cal-day .day-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  margin-top: 2px;
  opacity: .8;
}

/* ════════════
   DIRECTION TOGGLE
════════════ */
.direction-toggle {
  display: flex;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}

.dir-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .2rem;
  padding: .55rem .4rem;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .22s;
  line-height: 1.2;
}

.dir-btn span {
  font-size: .62rem;
  font-weight: 400;
}

.dir-btn.active.h2o {
  background: var(--h2o-bg);
  color: var(--h2o-color);
}

.dir-btn.active.o2h {
  background: var(--o2h-bg);
  color: var(--o2h-color);
}

.dir-btn.active.h2t {
  background: var(--h2t-bg);
  color: var(--h2t-color);
}

.dir-btn.active.t2h {
  background: var(--t2h-bg);
  color: var(--t2h-color);
}

.dir-btn.active {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.dir-btn:not(.active):hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ════════════
   JOURNEY LIST
════════════ */
.tickets-panel {
  margin-bottom: 0;
}

.tickets-header {
  margin-bottom: 1rem;
}

.filter-chips {
  display: flex;
  gap: .4rem;
  margin-top: .6rem;
  flex-wrap: wrap;
}

.chip {
  padding: .25rem .7rem;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  transition: all .18s;
}

.chip.active,
.chip:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.ticket-list {
  display: flex;
  flex-direction: column;
  gap: .6rem;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: calc(100vh - 155px);
  padding-right: 4px;
  padding-bottom: .5rem;
  /* Custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.ticket-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .8rem .9rem;
  transition: all .2s;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
  /* ← never compress */
  cursor: pointer;
  /* ← signals click-to-navigate */
  word-break: break-word;
  /* ← long routes don't overflow */
}

.ticket-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: 3px 0 0 3px;
}

.ticket-card.h2o::before {
  background: var(--h2o-color);
}

.ticket-card.o2h::before {
  background: var(--o2h-color);
}

.ticket-card.h2t::before {
  background: var(--h2t-color);
}

.ticket-card.t2h::before {
  background: var(--t2h-color);
}

.ticket-card:hover {
  border-color: var(--accent);
  transform: translateX(2px);
}

.ticket-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .4rem;
}

.ticket-badge {
  font-size: .68rem;
  font-weight: 700;
}

.ticket-badge.h2o {
  color: var(--h2o-color);
}

.ticket-badge.o2h {
  color: var(--o2h-color);
}

.ticket-badge.h2t {
  color: var(--h2t-color);
}

.ticket-badge.t2h {
  color: var(--t2h-color);
}

.ticket-actions {
  display: flex;
  gap: .3rem;
  opacity: 0;
  transition: opacity .18s;
}

.ticket-card:hover .ticket-actions {
  opacity: 1;
}

.ticket-route {
  font-size: .88rem;
  font-weight: 600;
  margin-bottom: .28rem;
}

.ticket-dates {
  font-size: .74rem;
  color: var(--text-muted);
}

.ticket-duration {
  font-size: .7rem;
  font-weight: 600;
  color: var(--today-color);
  margin-top: .22rem;
}

/* ════════════
   TOOLTIP
════════════ */
.day-tooltip {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .65rem .9rem;
  font-size: .8rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s, visibility .15s;
  z-index: 9999;
  max-width: 240px;
  min-width: 160px;
  box-shadow: var(--shadow-lg);
  line-height: 1.6;
  word-break: break-word;
  visibility: hidden;
}

.day-tooltip.visible {
  opacity: 1;
  visibility: visible;
}

/* ════════════
   MODAL
════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .72);
  backdrop-filter: blur(6px);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  width: 90%;
  max-width: 540px;
  position: relative;
  box-shadow: var(--shadow-lg);
  transform: scale(.95) translateY(10px);
  transition: transform .28s cubic-bezier(.34, 1.56, .64, 1);
}

.modal-overlay.open .modal {
  transform: scale(1) translateY(0);
}

.modal-sm {
  max-width: 340px;
  text-align: center;
}

.modal-close {
  position: absolute;
  top: .9rem;
  right: .9rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: .78rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
}

.modal-close:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1.4rem;
}

/* ── Form ── */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: .38rem;
  margin-bottom: .8rem;
}

label {
  font-size: .74rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .05em;
}

input,
select,
textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: .875rem;
  padding: .58rem .85rem;
  transition: border-color .2s, box-shadow .2s;
  outline: none;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px hsla(258, 80%, 68%, .14);
}

select option {
  background: var(--bg-elevated);
}

textarea {
  resize: vertical;
}

/* ── Custom Picker Inputs ── */
.custom-date-input,
.custom-time-input {
  position: relative;
  display: flex;
  align-items: center;
}

.picker-input {
  cursor: pointer;
  padding-right: 2.2rem !important;
}

.picker-input:hover {
  border-color: var(--accent);
}

.picker-icon {
  position: absolute;
  right: .7rem;
  font-size: .95rem;
  pointer-events: none;
  opacity: .7;
}

.form-error {
  font-size: .8rem;
  color: var(--danger);
  min-height: 1.2em;
  margin-bottom: .5rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  margin-top: .5rem;
}

/* ════════════════════════════════
   CUSTOM DATE PICKER POPUP
════════════════════════════════ */
.dp-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: none;
}

.dp-overlay.open {
  display: block;
}

.dp-popup {
  position: absolute;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow-lg);
  width: 290px;
  animation: popIn .22s cubic-bezier(.34, 1.56, .64, 1);
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(.92) translateY(-6px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.dp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .75rem;
}

.dp-nav {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: 7px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .18s;
}

.dp-nav:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.dp-month-label {
  font-size: .9rem;
  font-weight: 700;
}

.dp-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  margin-bottom: 3px;
}

.dp-weekdays div {
  text-align: center;
  font-size: .65rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: .25rem 0;
}

.dp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.dp-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  color: var(--text-secondary);
}

.dp-day.empty {
  cursor: default;
}

.dp-day.other-m {
  color: var(--text-muted);
  opacity: .4;
}

.dp-day:not(.empty):hover {
  background: var(--bg-hover);
  border-color: var(--border);
  color: var(--text-primary);
  transform: scale(1.1);
}

.dp-day.today {
  border-color: var(--today-color);
  color: var(--today-color);
  font-weight: 700;
}

.dp-day.selected {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.dp-day.selected:hover {
  background: var(--accent);
}

.dp-day.has-trip {
  position: relative;
}

.dp-day.has-trip::after {
  content: '';
  position: absolute;
  bottom: 3px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--h2o-color);
}

.dp-day.past:not(.selected) {
  opacity: .4;
}

/* ════════════════════════════════
   CUSTOM TIME PICKER POPUP
════════════════════════════════ */
.tp-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
}

.tp-overlay.open {
  display: flex;
}

.tp-popup {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 280px;
  box-shadow: var(--shadow-lg);
  animation: popIn .25s cubic-bezier(.34, 1.56, .64, 1);
}

.tp-title {
  font-size: .78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 1rem;
  text-align: center;
}

.tp-display {
  text-align: center;
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: .05em;
  background: linear-gradient(135deg, var(--h2o-color), var(--o2h-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: .8rem;
  line-height: 1;
}

.tp-mode-btns {
  display: flex;
  gap: .4rem;
  justify-content: center;
  margin-bottom: 1rem;
}

.tp-mode {
  padding: .28rem .85rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-family: inherit;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .18s;
}

.tp-mode.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Drum / scroll wheel */
.tp-drum-wrap {
  height: 180px;
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid var(--border);
  position: relative;
  margin-bottom: 1rem;
  background: var(--bg-elevated);
}

.tp-drum-wrap::before,
.tp-drum-wrap::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 54px;
  z-index: 2;
  pointer-events: none;
}

.tp-drum-wrap::before {
  top: 0;
  background: linear-gradient(to bottom, var(--bg-elevated), transparent);
}

.tp-drum-wrap::after {
  bottom: 0;
  background: linear-gradient(to top, var(--bg-elevated), transparent);
}

.tp-drum-wrap .selector-highlight {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  height: 40px;
  background: rgba(130, 88, 255, .15);
  border: 1px solid hsla(258, 80%, 68%, .3);
  border-radius: 8px;
  z-index: 1;
  pointer-events: none;
}

.tp-drum {
  display: flex;
  flex-direction: column;
  overflow-y: scroll;
  height: 100%;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 70px 0;
}

.tp-drum::-webkit-scrollbar {
  display: none;
}

.tp-item {
  flex-shrink: 0;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  scroll-snap-align: center;
  transition: color .15s, transform .15s;
}

.tp-item.selected {
  color: var(--text-primary);
  font-size: 1.25rem;
  transform: scale(1.1);
}

.tp-item:hover {
  color: var(--text-primary);
}

.tp-actions {
  display: flex;
  justify-content: flex-end;
  gap: .6rem;
}

.hidden {
  display: none !important;
}

/* ════════════
   UTILITIES
════════════ */
.muted {
  color: var(--text-muted);
  font-size: .875rem;
}

.center-text {
  text-align: center;
  padding: 1.5rem 0;
  line-height: 1.8;
}

/* ════════════
   RESPONSIVE
════════════ */

/* ── Tablet (≤ 1000px) ── */
@media (max-width: 1000px) {
  .app-main {
    grid-template-columns: 1fr 1fr;
    padding: 1rem;
  }

  .centre-panel {
    grid-column: 1 / -1;
    /* calendar spans full width */
    order: -1;
    /* calendar first */
  }

  .right-panel {
    grid-column: 1 / -1;
  }

  .ticket-list {
    max-height: 60vh;
  }
}

/* ── Mobile (≤ 640px) ── */
@media (max-width: 640px) {

  /* Header: 2 rows
     Row 1: logo ← → + Add Journey
     Row 2: Export · Import (smaller)          */
  .app-header {
    flex-wrap: wrap;
    padding: .65rem 1rem;
    gap: .5rem;
  }

  .header-left {
    flex: 1 1 auto;
    min-width: 0;
    gap: .6rem;
  }

  .logo-text {
    font-size: 1rem;
  }

  .logo-icon-img {
    width: 26px;
    height: 26px;
  }

  /* Hide current date on mobile – saves space */
  .current-date {
    display: none;
  }

  .header-right {
    display: flex;
    align-items: center;
    gap: .4rem;
    flex-wrap: nowrap;
  }

  /* Shrink Export / Import labels */
  #exportBtn,
  label.btn.btn-ghost {
    font-size: .72rem;
    padding: .4rem .65rem;
  }

  /* Add Journey button: stays full accent, readable size */
  #openAddModal {
    font-size: .8rem;
    padding: .45rem .85rem;
    white-space: nowrap;
  }

  /* Main: single column, tight padding */
  .app-main {
    grid-template-columns: 1fr;
    padding: .65rem;
    gap: .75rem;
  }

  /* Order: Stats · Next Journey · All-Time · Calendar · Tickets */
  .left-panel {
    order: 1;
  }

  .centre-panel {
    order: 2;
  }

  .right-panel {
    order: 3;
  }

  /* Panels: remove extra margin */
  .panel-card {
    padding: 1rem;
    margin-bottom: 0;
  }

  /* Stats grid stays 2x2 */
  .stat-grid {
    gap: .5rem;
  }

  /* Ticket list: natural height on mobile, scrolls within viewport */
  .ticket-list {
    max-height: 70vh;
    overflow-y: auto;
  }

  /* Calendar cells: a bit larger text on small screens */
  .cal-day {
    font-size: .78rem;
    border-radius: 6px;
  }

  .cal-day .day-icon {
    font-size: .6rem;
  }

  /* Calendar legend: wrap naturally */
  .calendar-legend {
    font-size: .68rem;
    gap: .35rem .55rem;
  }

  /* Form: all fields single column */
  .form-row {
    grid-template-columns: 1fr;
  }

  /* Modal: full-width on small screens */
  .modal {
    width: 96%;
    padding: 1.2rem;
  }

  /* Date/time picker popup: slightly wider */
  .dp-popup,
  .tp-popup {
    width: min(340px, 95vw);
  }

  /* Filter chips: allow wrap */
  .filter-chips {
    flex-wrap: wrap;
  }
}

/* ── Very small (≤ 380px) ── */
@media (max-width: 380px) {
  .logo-text {
    font-size: .88rem;
  }

  /* Stack header buttons onto 2nd row fully */
  .header-right {
    width: 100%;
    justify-content: flex-end;
  }

  .app-header {
    align-items: flex-start;
  }
}

/* ════════════
   ANIMATIONS
════════════ */
@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ticket-card,
.stat-item {
  animation: fadeSlideIn .3s ease both;
}

/* ── Date cell pulse when navigating from ticket list ── */
@keyframes datePulse {
  0% {
    box-shadow: 0 0 0 0 hsla(258, 80%, 68%, 0);
    transform: scale(1);
  }

  20% {
    box-shadow: 0 0 0 7px hsla(258, 80%, 68%, .75);
    transform: scale(1.18);
  }

  45% {
    box-shadow: 0 0 0 3px hsla(258, 80%, 68%, .35);
    transform: scale(1.08);
  }

  65% {
    box-shadow: 0 0 0 7px hsla(258, 80%, 68%, .65);
    transform: scale(1.15);
  }

  85% {
    box-shadow: 0 0 0 3px hsla(258, 80%, 68%, .2);
    transform: scale(1.05);
  }

  100% {
    box-shadow: 0 0 0 0 hsla(258, 80%, 68%, 0);
    transform: scale(1);
  }
}

.cal-day.date-highlight {
  animation: datePulse 1s ease forwards;
  z-index: 10;
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ════════════
   THEME TOGGLE
════════════ */
.theme-toggle {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all .2s;
  flex-shrink: 0;
}
.theme-toggle:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  transform: rotate(20deg);
}

/* ════════════
   TOAST (Undo Delete)
════════════ */
#toastContainer {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9000;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  align-items: center;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: .75rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .65rem 1rem .65rem 1.1rem;
  box-shadow: var(--shadow-lg);
  font-size: .88rem;
  color: var(--text-primary);
  pointer-events: all;
  animation: toastIn .3s cubic-bezier(.34, 1.56, .64, 1);
  min-width: 260px;
  max-width: 90vw;
}

.toast.removing {
  animation: toastOut .25s ease forwards;
}

.toast-msg {
  flex: 1;
}

.toast-undo {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: .8rem;
  font-weight: 700;
  padding: .28rem .7rem;
  cursor: pointer;
  transition: opacity .15s;
  white-space: nowrap;
}

.toast-undo:hover { opacity: .85; }

.toast-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: var(--accent);
  border-radius: 0 0 var(--radius) var(--radius);
  animation: toastProgress 5s linear forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(14px) scale(.94); }
  to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateY(12px) scale(.94); }
}

@keyframes toastProgress {
  from { width: 100%; }
  to   { width: 0%;   }
}

/* ════════════
   TREND CHART
════════════ */
.trend-chart {
  display: flex;
  align-items: flex-end;
  gap: .35rem;
  height: 80px;
  margin-top: .85rem;
}

.trend-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  height: 100%;
  justify-content: flex-end;
}

.trend-bars {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1px;
  align-items: center;
}

.trend-bar {
  width: 100%;
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: height .5s cubic-bezier(.34,1.56,.64,1);
}

.trend-bar.home  { background: var(--home-color);  }
.trend-bar.away  { background: var(--both-color);  }

.trend-label {
  font-size: .58rem;
  color: var(--text-muted);
  font-weight: 600;
  text-align: center;
  letter-spacing: .02em;
}

.trend-legend {
  display: flex;
  gap: .9rem;
  font-size: .7rem;
  color: var(--text-muted);
  margin-top: .65rem;
  align-items: center;
}

.trend-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ════════════
   COST FIELD
════════════ */
.cost-stat {
  border-color: hsl(48, 80%, 28%) !important;
}
.cost-stat .stat-value { color: hsl(48, 90%, 60%); }

.ticket-cost {
  font-size: .7rem;
  font-weight: 600;
  color: hsl(48, 90%, 60%);
  margin-top: .2rem;
}

/* ════════════
   KEYBOARD HINTS
════════════ */
.kbd-hint {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .5rem .8rem;
  font-size: .7rem;
  color: var(--text-muted);
  z-index: 200;
  animation: fadeSlideIn .4s ease both;
  pointer-events: none;
  line-height: 1.8;
}

kbd {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .05rem .35rem;
  font-size: .65rem;
  font-family: inherit;
  color: var(--text-secondary);
}

/* ════════════
   SCAN TICKET
════════════ */
.scan-banner {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1.2rem;
  padding: .7rem 1rem;
  background: linear-gradient(135deg, hsl(258, 50%, 14%), hsl(220, 50%, 14%));
  border: 1px solid hsl(258, 40%, 28%);
  border-radius: var(--radius-sm);
}

.scan-btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem 1rem;
  background: linear-gradient(135deg, var(--accent), hsl(220, 80%, 65%));
  color: #fff;
  border-radius: 7px;
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all .2s;
  box-shadow: 0 3px 12px rgba(130, 88, 255, .4);
  flex-shrink: 0;
}

.scan-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 18px rgba(130, 88, 255, .55);
}

.scan-status {
  font-size: .8rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.scan-status.loading {
  color: var(--accent);
}

.scan-status.success {
  color: var(--home-color);
}

.scan-status.error {
  color: var(--danger);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid hsla(258, 80%, 68%, .3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
  margin-right: .35rem;
}


:root.light .scan-banner {
  background: linear-gradient(135deg, hsl(258, 60%, 94%), hsl(220, 60%, 94%));
  border-color: hsl(258, 40%, 75%);
}

/* ════════════
   DAY DETAIL MODAL
════════════ */
.modal-day-detail {
  max-width: 420px;
  width: 95%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  animation: slideUpIn .22s ease;
}

@keyframes slideUpIn {
  from { opacity: 0; transform: translateY(30px) scale(.97); }
  to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

.day-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  padding-right: 2.5rem; /* leave room for the ✕ close button */
}

.day-detail-date {
  font-size: 1.05rem;
  font-weight: 700;
}

.day-detail-badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .22rem .65rem;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 700;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  white-space: nowrap;
}

.day-detail-badge.at-home  { background: hsl(145,45%,12%); color: hsl(145,65%,62%); border-color: hsl(145,45%,24%); }
.day-detail-badge.at-office{ background: hsl(265,45%,14%); color: hsl(265,70%,72%); border-color: hsl(265,45%,30%); }
.day-detail-badge.h2o      { background: var(--h2o-bg); color: var(--h2o-color); border-color: var(--h2o-border); }
.day-detail-badge.o2h      { background: var(--o2h-bg); color: var(--o2h-color); border-color: var(--o2h-border); }

.day-detail-content {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.day-detail-ticket {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .75rem .9rem;
  position: relative;
  overflow: hidden;
}

.day-detail-ticket::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  border-radius: 3px 0 0 3px;
}

.day-detail-ticket.h2o::before { background: var(--h2o-color); }
.day-detail-ticket.o2h::before { background: var(--o2h-color); }

.day-detail-ticket-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .35rem;
}

.day-detail-ticket-route {
  font-weight: 700;
  font-size: .9rem;
}

.day-detail-ticket-meta {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: .2rem;
}

.day-detail-no-tickets {
  color: var(--text-muted);
  font-size: .875rem;
  text-align: center;
  padding: 1.5rem 0;
}

/* Calendar cells are now clickable — show pointer on non-empty cells */
.cal-day:not(.empty) {
  cursor: pointer;
}