/* SideTrip — chassis + app-specific styles.
   Brand tokens and theme variables at top; everything else is structure. */

/* >>> tokens / theme system
   Scoped to :root — the theme-toggle buttons in settings also carry
   data-theme attributes, and must not match these blocks. */
:root,
:root[data-theme="dark"] {
  --bg: #1B3A2E;
  --surface: #1b1b24;
  --surface-elevated: #242436;
  --text: #f2f2f7;
  --dim: #9a9aa8;
  --accent: #F4A261;
  --accent-dim: rgba(244, 162, 97, 0.15);
  --danger: #e85d5d;
  --success: #5dd87a;
  --radius: 14px;
  --pad: 16px;
}

:root[data-theme="light"] {
  --bg: #FEFAE0;
  --surface: #ffffff;
  --surface-elevated: #f8f6ed;
  --text: #1B3A2E;
  --dim: #5c5c5c;
  --accent: #D4842F;
  --accent-dim: rgba(212, 132, 47, 0.12);
  --danger: #c43c3c;
  --success: #3a9a50;
}
/* <<< tokens */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: var(--app-height, 100dvh);
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#appBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--pad);
  padding: var(--pad);
  flex: 0 0 auto;
  position: relative;
  z-index: 20;
  background: linear-gradient(to bottom, var(--bg), transparent);
}

#appTitle { font-size: 1.15rem; margin: 0; font-weight: 650; }

.screen { flex: 1 1 auto; overflow-y: auto; padding: 0 var(--pad) var(--pad); position: relative; }
.screen { display: flex; flex-direction: column; gap: 12px; padding-top: 4px; }
.screen[hidden] { display: none !important; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: var(--pad);
}
.card h2 { margin: 0 0 .5rem; font-size: 1.05rem; }
.card p { margin: 0 0 .75rem; }
.dim { color: var(--dim); }
code { background: rgba(128,128,128,.1); padding: .1em .4em; border-radius: 6px; font-size: .9em; }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-size: 1.1rem;
  min-width: 36px;
  min-height: 36px;
}
.icon-btn:active { background: rgba(128,128,128,.15); }

/* --- sheets --------------------------------------------------------------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: flex-end;
  z-index: 40;
}
.sheet-backdrop[hidden] { display: none; }

.sheet {
  background: var(--surface);
  width: 100%;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: var(--pad);
  padding-bottom: calc(var(--pad) + env(safe-area-inset-bottom));
  max-height: 85%;
  overflow-y: auto;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 1.05rem; }
.sheet-foot { margin-top: var(--pad); display: flex; gap: .5rem; align-items: center; font-size: .85rem; flex-wrap: wrap; }
.sheet-foot a { color: var(--dim); text-decoration: none; }
.sheet-foot a:hover { text-decoration: underline; }
#appVersion { margin-left: auto; font-variant-numeric: tabular-nums; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid rgba(128,128,128,.08);
}
.row:last-of-type { border-bottom: 0; }

[data-theme="light"] .row { border-bottom-color: rgba(0,0,0,.06); }

/* --- floating pills ------------------------------------------------------- */
.pill {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  border: 0;
  border-radius: 999px;
  padding: 12px 20px;
  font: inherit;
  font-size: .9rem;
  cursor: pointer;
  z-index: 60;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.pill[hidden] { display: none; }

/* Hide floating pills while a sheet is open — they'd float over sheet content. */
.sheet-backdrop:not([hidden]) ~ .pill { display: none; }

.update-toast { bottom: calc(18px + env(safe-area-inset-bottom)); background: var(--accent); color: #fff; }
.install-hint { bottom: calc(74px + env(safe-area-inset-bottom)); background: var(--surface); color: var(--text); }

#toast, #syncStatus {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: calc(12px + env(safe-area-inset-top));
  background: rgba(0,0,0,.85);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: .9rem;
  z-index: 70;
  pointer-events: none;
}
#toast[hidden], #syncStatus[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* >>> SideTrip App Styles <<< */

/* ─── Text Input & Search ────────────────────────────────────────────── */

.text-input {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  background: rgba(128,128,128,.08);
  border: 1px solid rgba(128,128,128,.14);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 8px;
  transition: border-color .2s, box-shadow .2s;
}
.text-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.text-input::placeholder { color: var(--dim); }

.input-wrapper {
  position: relative;
}
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
  pointer-events: none;
  z-index: 1;
}
.input-wrapper .text-input { padding-left: 40px; }

/* ─── Map Container ─────────────────────────────────────────────────── */

.map-container {
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: 0;
}
.map-container canvas,
.map-container img {
  border-radius: 0 !important;
}

.search-overlay {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 8px;
}

/* ─── Autocomplete Dropdown ─────────────────────────────────────────── */

.autocomplete-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  background: var(--surface-elevated);
  border-radius: 10px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.autocomplete-list[hidden] { display: none; }
.autocomplete-list li {
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-bottom: 1px solid rgba(128,128,128,.06);
  transition: background .15s;
}
.autocomplete-list li:last-child { border-bottom: none; }
.autocomplete-list li:hover,
.autocomplete-list li:focus {
  background: var(--accent-dim);
}
.autocomplete-list li.active {
  background: var(--accent-dim);
}
.autocomplete-list li .ac-main {
  font-weight: 500;
  font-size: .95rem;
}
.ac-secondary {
  font-size: .82rem;
  color: var(--dim);
}

/* ─── Interest Chips ───────────────────────────────────────────────── */

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.chip {
  appearance: none;
  border: 1px solid rgba(128,128,128,.18);
  background: rgba(128,128,128,.05);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  font-size: .92rem;
  min-height: 44px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all .2s;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-weight: 600;
}

/* ─── Buttons ──────────────────────────────────────────────────────── */

.btn {
  appearance: none;
  border: 1px solid rgba(128,128,128,.14);
  background: rgba(128,128,128,.04);
  color: var(--text);
  border-radius: 12px;
  padding: 14px;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  min-height: 48px;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.05); }
.btn-primary:active:not(:disabled) { transform: scale(.98); }
.btn-block { width: 100%; }
.btn-outline {
  background: transparent;
  border-color: rgba(128,128,128,.2);
  font-size: .88rem;
  min-height: 40px;
  padding: 10px 16px;
}

.search-card h2 { margin-bottom: 0; }

/* ─── Driving Screen ───────────────────────────────────────────────── */

.drive-status { text-align: center; }
.drive-status h2 { margin: 4px 0 16px; font-size: 1.4rem; }

.drive-stats-row {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin: 12px 0;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: baseline;
  gap: 2px;
}
.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.stat-label {
  font-size: .78rem;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: .03em;
}

.progress-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(128,128,128,.1);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width .6s linear;
  border-radius: 999px;
}

.drive-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto;
}

/* ─── Next Stop Preview Card ───────────────────────────────────────── */

.next-stop-card {
  margin-top: 16px;
  padding: 14px;
  background: var(--accent-dim);
  border-radius: 12px;
  border: 1px solid rgba(244, 162, 97, .25);
}
.next-stop-card[hidden] { display: none; }
.next-stop-label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin: 0 0 8px;
}
.next-stop-body {
  display: flex;
  align-items: center;
  gap: 12px;
}
.next-stop-emoji { font-size: 2rem; line-height: 1; }
.next-stop-info h4 { margin: 0; font-size: 1rem; }
.next-stop-info p { margin: 2px 0 0; font-size: .85rem; }

/* ─── Upcoming Stops Screen ────────────────────────────────────────── */

.screen-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  flex: 0 0 auto;
}
.screen-header h2 {
  margin: 0;
  font-size: 1.1rem;
}
.btn-back {
  font-size: .95rem;
  color: var(--accent);
  font-weight: 500;
  padding: 8px 4px;
}
.upcoming-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.upcoming-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--surface);
  border-radius: 12px;
  transition: opacity .2s;
  cursor: default;
}
.upcoming-item.passed {
  opacity: .4;
}
.upcoming-item.taken {
  border-left: 3px solid var(--success);
}
.upcoming-item.skipped {
  border-left: 3px solid var(--dim);
}
.upcoming-emoji { font-size: 1.8rem; flex-shrink: 0; }
.upcoming-info { flex: 1; min-width: 0; }
.upcoming-name { font-weight: 600; font-size: .95rem; margin: 0; }
.upcoming-meta { font-size: .82rem; color: var(--dim); margin: 2px 0 0; }
.upcoming-badge {
  font-size: .72rem;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .02em;
  white-space: nowrap;
}
.badge-upcoming { background: var(--accent-dim); color: var(--accent); }
.badge-passed { background: rgba(128,128,128,.1); color: var(--dim); }
.badge-taken { background: rgba(93, 216, 122, .15); color: var(--success); }
.badge-skipped { background: rgba(128,128,128,.08); color: var(--dim); }
.badge-filtered { background: rgba(128,128,128,.08); color: var(--dim); }

/* ─── Trip Summary ─────────────────────────────────────────────────── */

.stats-card {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 16px;
}
.stat-tile {
  text-align: center;
  padding: 10px;
  background: rgba(128,128,128,.04);
  border-radius: 10px;
}
.stat-tile-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.stat-tile-label {
  font-size: .75rem;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: .02em;
  margin-top: 2px;
}
.stat-tile.full-width {
  grid-column: span 2;
}
.level-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 999px;
  font-weight: 600;
  font-size: .9rem;
  margin-top: 4px;
}

.summary-stop {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(128,128,128,.07);
}
.summary-stop:last-child { border-bottom: 0; }
.summary-stop .emoji { font-size: 1.4rem; }
.summary-empty { color: var(--dim); padding: 8px 0; }
.summary-rating {
  font-size: .85rem;
}
.summary-fav {
  color: var(--accent);
  font-size: 1.1rem;
  cursor: pointer;
  background: none;
  border: none;
  padding: 4px;
}
.summary-fav.is-fav { filter: brightness(1.3); }

/* ─── History ──────────────────────────────────────────────────────── */

.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid rgba(128,128,128,.07);
  font-size: .92rem;
  cursor: pointer;
  transition: background .15s;
  border-radius: 8px;
  margin: 0 -8px;
  padding-left: 8px;
  padding-right: 8px;
}
.history-row:hover { background: rgba(128,128,128,.06); }
.history-row:last-child { border-bottom: 0; }
.history-date {
  font-size: .78rem;
  color: var(--dim);
}

/* ─── Detour Alert ─────────────────────────────────────────────────── */

.detour-alert {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 80;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: var(--pad);
  padding-bottom: calc(var(--pad) + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 32px rgba(0,0,0,.5);
  animation: slide-up .25s ease-out;
}
.detour-alert[hidden] { display: none; }

@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.detour-card {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.detour-photo {
  width: 60px;
  height: 60px;
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
  background: rgba(128,128,128,.1);
}
.detour-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.detour-photo[hidden],
.detour-photo:empty {
  display: none;
}
.detour-photo:not([hidden]):not(:empty) + .detour-emoji,
.detour-photo:not(:empty) ~ .detour-body .detour-emoji {
  display: none;
}
.detour-emoji {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  line-height: 1;
  background: rgba(128,128,128,.06);
  border-radius: 12px;
  flex-shrink: 0;
}
.detour-body { flex: 1; min-width: 0; }
.detour-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.detour-header h3 { margin: 0; font-size: 1.1rem; }
.detour-body p { margin: 0 0 4px; font-size: .92rem; }
.detour-meta { color: var(--accent) !important; font-weight: 600; font-size: .85rem !important; }
.detour-hours { font-size: .84rem !important; }
.detour-rating { font-size: .86rem !important; }

.fav-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--dim);
  padding: 4px;
  line-height: 1;
  transition: color .15s, transform .15s;
}
.fav-btn:hover { color: var(--accent); transform: scale(1.15); }
.fav-btn.is-fav { color: var(--accent); }

.detour-actions { display: flex; gap: 10px; margin-top: 14px; }
.detour-actions .btn { flex: 1; }

/* ─── Settings: Range Slider ───────────────────────────────────────── */

.row-range {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.range-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}
.range-wrap input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: rgba(128,128,128,.15);
  outline: none;
}
.range-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--surface);
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.range-value {
  font-size: .85rem;
  font-weight: 600;
  color: var(--accent);
  min-width: 48px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ─── Settings: Theme Toggle ───────────────────────────────────────── */

.row-theme {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.theme-toggle {
  display: flex;
  gap: 6px;
  background: rgba(128,128,128,.08);
  border-radius: 10px;
  padding: 4px;
}
.theme-btn {
  flex: 1;
  background: none;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
  color: var(--dim);
  transition: all .2s;
  font-weight: 500;
}
.theme-btn:hover { color: var(--text); }
.theme-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
}

/* >>> addon-styles */
/* <<< addon-styles */
