/**
 * The Fallback v2 - Layout Styles
 * App shell, navigation, views, and panels
 */

/* ═══════════════════════════════════════════════════════════════════════════
   APP SHELL
   ═══════════════════════════════════════════════════════════════════════════ */

#app {
  display: none; /* Hidden until auth */
  height: 100%;
  overflow: hidden;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

#app.authenticated {
  display: flex;
  flex-direction: column;
}

/* Mobile: column layout with bottom nav */
@media (max-width: 767px) {
  #app.authenticated {
    flex-direction: column;
  }
}

/* Desktop: row layout with sidebar */
@media (min-width: 768px) {
  #app.authenticated {
    flex-direction: row;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   LOADING SCREEN
   ═══════════════════════════════════════════════════════════════════════════ */

#loading-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  background: var(--color-primary);
  z-index: 9999;
}

#loading-screen .logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

#loading-screen .logo img {
  height: 60px;
  width: auto;
}

#loading-screen .logo-text {
  font-family: var(--font-family-display);
  font-size: var(--text-3xl);
  font-weight: var(--font-bold);
}

#loading-screen .logo-text .the {
  color: var(--color-text-inverse);
}

#loading-screen .logo-text .fallback {
  color: var(--color-accent);
}

#loading-screen .spinner {
  border-color: rgba(255, 255, 255, 0.2);
  border-top-color: var(--color-accent);
}

#loading-screen .loading-text {
  color: rgba(255, 255, 255, 0.7);
  font-size: var(--text-base);
}

/* ═══════════════════════════════════════════════════════════════════════════
   LOGIN SCREEN
   ═══════════════════════════════════════════════════════════════════════════ */

#login-screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-6);
  padding: var(--space-6);
  background: var(--color-primary);
}

#login-screen.visible {
  display: flex;
}

#login-screen .logo {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

#login-screen .logo img {
  height: 80px;
  width: auto;
}

#login-screen .logo-text {
  font-family: var(--font-family-display);
  font-size: 36px;
  font-weight: var(--font-bold);
}

#login-screen .logo-text .the {
  color: var(--color-text-inverse);
}

#login-screen .logo-text .fallback {
  color: var(--color-accent);
}

#login-screen .tagline {
  color: rgba(255, 255, 255, 0.7);
  font-size: var(--text-lg);
  text-align: center;
}

#login-screen .google-btn {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--color-text);
  box-shadow: var(--shadow-lg);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

#login-screen .google-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-xl);
}

#login-screen .google-btn:active {
  transform: translateY(0);
}

#login-screen .login-error {
  display: none;
  max-width: 320px;
  padding: var(--space-3) var(--space-4);
  background: rgba(255, 100, 80, 0.15);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: #ffb4a9;
}

#login-screen .privacy-note {
  color: rgba(255, 255, 255, 0.5);
  font-size: var(--text-sm);
  text-align: center;
}

/* ═══════════════════════════════════════════════════════════════════════════
   BOTTOM NAVIGATION (Mobile)
   ═══════════════════════════════════════════════════════════════════════════ */

#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  height: var(--nav-height-mobile);
  padding-bottom: var(--safe-bottom);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  z-index: var(--z-nav);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-4);
  color: var(--color-text-muted);
  transition: color var(--transition-fast);
}

.nav-item.active {
  color: var(--color-primary);
}

.nav-item .nav-icon {
  width: 24px;
  height: 24px;
}

.nav-item .nav-icon svg {
  width: 100%;
  height: 100%;
}

.nav-item .nav-label {
  font-size: 10px;
  font-weight: var(--font-medium);
}

/* Floating Add Button */
.nav-item-add {
  position: relative;
  margin-top: -20px;
}

.nav-item-add .add-btn {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-accent);
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(201, 164, 92, 0.4);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.nav-item-add .add-btn:hover {
  transform: scale(1.05);
}

.nav-item-add .add-btn:active {
  transform: scale(0.95);
}

.nav-item-add .add-btn svg {
  width: 28px;
  height: 28px;
  stroke: var(--color-surface);
  stroke-width: 2.5;
}

/* Hide bottom nav on desktop */
@media (min-width: 768px) {
  #bottom-nav {
    display: none;
  }
}

/* Search This Area Button */
.search-area-btn {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--color-surface);
  color: var(--color-primary);
  border: 1px solid var(--color-primary-muted);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
  cursor: pointer;
  transition: all 0.2s ease;
}
.search-area-btn:hover {
  background: var(--color-primary);
  color: #fff;
}
.search-area-btn:disabled {
  background: var(--color-surface-alt);
  color: var(--color-text-muted);
  border-color: var(--color-border);
  cursor: not-allowed;
}

/* ═══════════════════════════════════════════════════════════════════════════
   SIDEBAR NAVIGATION (Desktop)
   ═══════════════════════════════════════════════════════════════════════════ */

#sidebar-nav {
  display: none;
  flex-direction: column;
  align-items: center;
  width: var(--sidebar-width);
  padding: var(--space-5) 0;
  background: var(--color-primary);
  flex-shrink: 0;
}

@media (min-width: 768px) {
  #sidebar-nav {
    display: flex;
  }
}

#sidebar-nav .sidebar-logo {
  width: 44px;
  height: 44px;
  margin-bottom: var(--space-8);
  display: flex;
  align-items: center;
  justify-content: center;
}

#sidebar-nav .sidebar-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.sidebar-nav-items {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  flex: 1;
}

.sidebar-nav-item {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: rgba(255, 255, 255, 0.6);
  transition: all var(--transition-fast);
}

.sidebar-nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.9);
}

.sidebar-nav-item.active {
  background: rgba(255, 255, 255, 0.15);
  color: white;
}

.sidebar-nav-item svg {
  width: 22px;
  height: 22px;
}

.sidebar-nav-bottom {
  margin-top: auto;
}

/* ═══════════════════════════════════════════════════════════════════════════
   MAIN CONTENT AREA
   ═══════════════════════════════════════════════════════════════════════════ */

#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

@media (max-width: 767px) {
  #main-content {
    padding-bottom: var(--nav-height-mobile);
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   VIEWS (Explore, Saved, Trips, Settings)
   ═══════════════════════════════════════════════════════════════════════════ */

.view {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.view.active {
  display: flex;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  background: var(--color-base);
  flex-shrink: 0;
}

.view-title {
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  color: var(--color-text);
}

.view-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ═══════════════════════════════════════════════════════════════════════════
   EXPLORE VIEW
   ═══════════════════════════════════════════════════════════════════════════ */

#view-explore .view-header {
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-3);
  padding: var(--space-4);
}

#view-explore .header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#view-explore .brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

#view-explore .brand-logo {
  height: 36px;
  width: auto;
}

#view-explore .brand-text {
  font-family: var(--font-family-display);
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
}

#view-explore .brand-text .the {
  color: var(--color-text);
}

#view-explore .brand-text .fallback {
  color: var(--color-primary);
}

/* Trip status card — styles in components.css (.trip-status-card / .ts-*) */

/* Nearby section */
.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: var(--space-4);
}

.section-title {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--color-text);
}

.section-action {
  font-size: var(--text-sm);
  color: var(--color-primary);
  font-weight: var(--font-medium);
}

/* ═══════════════════════════════════════════════════════════════════════════
   EXPLORE — Two-pane layout: left column (brand/summary/nearby), right map
   ═══════════════════════════════════════════════════════════════════════════ */

#view-explore {
  flex-direction: row !important;
  background: var(--color-base);
  z-index: 5;
}

.explore-left {
  width: 380px;
  max-width: 500px;
  min-width: 0;
  flex-shrink: 0;
  background: var(--color-base);
  display: flex;
  flex-direction: column;
  overflow-y: auto;          /* whole column scrolls */
  -webkit-overflow-scrolling: touch;
  position: relative;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Discover resize handle hidden until the discover panel is open;
   Explore resize handle hidden while discover takes its place. */
.resize-handle[data-resize="modal-discover"] { display: none; }
body.discover-list-open .resize-handle[data-resize="modal-discover"] { display: block; }
body.discover-list-open .resize-handle[data-resize="explore-left"]   { display: none; }

@media (max-width: 767px) {
  .resize-handle[data-resize="explore-left"],
  .resize-handle[data-resize="modal-discover"] { display: none !important; }
}

@media (max-width: 767px) {
  .desktop-only { display: none !important; }
}

/* Inner scroll wrapper inside .explore-left. Holds trip-status, Nearby,
   and Discover. On mobile this is the scroll container so the grabber +
   brand above stay pinned. On desktop it's a regular block — the whole
   .explore-left column scrolls. The flex+gap reproduces the spacing that
   was previously coming from .explore-left's `gap` between direct
   children, since those children now live inside the wrapper. */
.explore-content-scroll {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
  padding: var(--space-4) var(--space-4) var(--space-5);
}

/* Sections size to their own content (no forced 50/50 split). When the
 * total exceeds the column height, the column itself scrolls. Each
 * section can be collapsed to header-only via the chevron toggle, giving
 * the other section the full column. */
.explore-nearby-wrap,
.explore-discover-wrap {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
}
.explore-nearby-wrap .section-header,
.explore-discover-wrap .section-header {
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
  gap: 8px;
  padding: 0 var(--space-1);
  align-items: baseline;
}
.explore-nearby-wrap .section-header .section-subtitle,
.explore-discover-wrap .section-header .section-subtitle {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.explore-nearby-wrap #nearby-list,
.explore-nearby-wrap .nearby-list,
.explore-discover-wrap #discover-list,
.explore-discover-wrap .discover-list {
  -webkit-overflow-scrolling: touch;
}
/* When a section is collapsed, hide everything below the header. The
 * section shrinks to header height, freeing the column for the other
 * section's content. */
.explore-nearby-wrap.collapsed > :not(.section-header):not(.section-divider),
.explore-discover-wrap.collapsed > :not(.section-header):not(.section-divider) {
  display: none !important;
}
/* Chevron in section header — points down when expanded, right when collapsed */
.section-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-left: auto;
  transition: transform 0.15s ease;
  color: var(--color-text-muted);
}
.collapsed .section-toggle-icon {
  transform: rotate(-90deg);
}
/* Thin divider between Nearby and Discover sections */
.section-divider {
  height: 1px;
  background: var(--color-border, rgba(0,0,0,0.08));
  margin: 6px 4px 0;
}
/* Show more / less button shared by both sections */
.show-more-btn {
  flex-shrink: 0;
  margin: 4px var(--space-1) 0;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid var(--color-border, rgba(0,0,0,0.12));
  border-radius: 8px;
  font-size: 13px;
  color: var(--color-primary);
  font-weight: 500;
  cursor: pointer;
}
.show-more-btn:hover { background: var(--color-surface-alt); }

/* Discover-specific styling */
.explore-discover-wrap {
  gap: var(--space-2);
}
.discover-mode {
  flex-shrink: 0;
  display: flex;
  gap: 4px;
  padding: 0 var(--space-1) 2px;
}
.discover-mode-btn {
  flex: 1 1 0;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--color-border, rgba(0,0,0,0.12));
  background: var(--color-surface, #fff);
  font-size: 12px;
  color: var(--color-text-muted);
  cursor: pointer;
  font-weight: 500;
}
.discover-mode-btn.active {
  background: var(--color-text);
  color: var(--color-surface, #fff);
  border-color: var(--color-text);
}
.discover-chips {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 var(--space-1) 4px;
}
.discover-chip {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--color-border, rgba(0,0,0,0.12));
  background: var(--color-surface, #fff);
  font-size: 12px;
  color: var(--color-text);
  cursor: pointer;
}
.discover-chip.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.discover-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 var(--space-1);
}
.discover-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border, rgba(0,0,0,0.08));
  border-radius: 10px;
}
.discover-card-content {
  flex: 1;
  min-width: 0;
}
.discover-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.discover-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
  font-size: 12px;
  color: var(--color-text-muted);
}
.discover-tag {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--color-surface-alt, rgba(0,0,0,0.04));
  font-size: 11px;
  color: var(--color-text);
}
.discover-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}
.discover-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--color-surface-alt, rgba(0,0,0,0.05));
  color: var(--color-text);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.discover-badge.good {
  background: rgba(34,197,94,0.15);
  color: #15803d;
}
.discover-badge.warn {
  background: rgba(234,179,8,0.18);
  color: #a16207;
}
.discover-badge.cost {
  background: rgba(59,130,246,0.15);
  color: #1d4ed8;
}
.discover-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.discover-save {
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--color-primary);
  background: var(--color-primary);
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
}
.discover-save.loading,
.discover-save:disabled {
  opacity: 0.6;
  cursor: default;
}
.discover-saved-badge {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-muted);
  padding: 4px 8px;
}
.discover-mapsbtn {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border, rgba(0,0,0,0.12));
  background: var(--color-surface, #fff);
  border-radius: 8px;
  cursor: pointer;
  color: var(--color-text-muted);
}
.discover-mapsbtn:hover { color: var(--color-primary); }

.explore-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) calc(var(--space-4) + var(--space-1)) 0;
  min-width: 0;
  flex-shrink: 0;
  overflow: hidden;
}
.explore-brand .brand-logo {
  height: 40px;
  width: auto;
}
.explore-brand .brand-text {
  font-family: var(--font-family-display);
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
}
.explore-brand .brand-text .the { color: var(--color-text); }
.explore-brand .brand-text .fallback { color: var(--color-primary); }

.explore-nearby-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.explore-nearby-wrap .section-header {
  padding: 0 var(--space-1);
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.explore-right {
  flex: 1;
  min-width: 0;
  position: relative;
  background: var(--color-surface-alt);
}

.explore-right #explore-map-container {
  position: absolute;
  inset: 0;
}
.explore-right #explore-map-container #map {
  width: 100%;
  height: 100%;
}

/* Mobile: hide the map pane, stack everything */
@media (max-width: 767px) {
  #view-explore {
    flex-direction: column !important;
    position: relative;
    background: transparent !important;
    pointer-events: none; /* Pass touches to the global map below; drawer re-enables */
  }
  /* Convert .explore-left into a mobile drawer over the global map */
  .explore-left {
    width: 100%;
    max-width: none;
    min-width: 0;
    flex: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 40;
    background: var(--color-surface);
    border-top: 0.5px solid var(--color-border);
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.12);
    transition: height 180ms ease;
    overflow-y: auto;          /* mobile drawer body scrolls */
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }
  .explore-right {
    display: none;
  }
  /* Map visible on Explore too on mobile */
  body[data-view="explore"] #app.authenticated #map-global {
    display: block;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   EXPLORE — Backup detail panel (third flex column between .explore-left and map)
   ═══════════════════════════════════════════════════════════════════════════ */

.explore-backup-panel {
  width: 380px;
  max-width: 40vw;
  min-width: 320px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-left: 0.5px solid var(--color-border);
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: explore-backup-slide-in 180ms ease-out;
  z-index: 6;
}

@keyframes explore-backup-slide-in {
  from { transform: translateX(-8px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.explore-backup-panel .side-panel-hd {
  padding: var(--space-4);
  border-bottom: 0.5px solid var(--color-border);
  flex-shrink: 0;
}
.explore-backup-panel .side-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  -webkit-overflow-scrolling: touch;
}
.explore-backup-panel .side-panel-footer {
  padding: var(--space-4);
  border-top: 0.5px solid var(--color-border);
  flex-shrink: 0;
  background: var(--color-surface);
}

/* Mobile: panel takes over full screen */
@media (max-width: 767px) {
  .explore-backup-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
    min-width: 0;
    z-index: 100;
  }
}

/* Nearby list (vertical) */
.nearby-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.nearby-card {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--color-border);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.nearby-card:hover { background: var(--color-surface-alt); }

.nearby-card-thumb {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--color-primary-light) 0%, var(--color-primary) 100%);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
}

.nearby-card-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.nearby-card-name {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nearby-card-meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
}

.nearby-card-tags {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.nearby-tag {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--color-surface-alt);
  color: var(--color-text-secondary);
}
.nearby-tag.free { background: #e8f5e9; color: #2d5a47; }
.nearby-tag.cost { background: #e8f5e9; color: #2d5a47; }
.nearby-tag.warn { background: #fff3e0; color: #e65100; }

.section-subtitle {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: var(--font-normal);
}

/* Map preview card */
.map-preview {
  margin: 0 var(--space-4) var(--space-4);
  height: 160px;
  background: var(--color-surface-alt);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.map-preview-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--color-text);
  box-shadow: var(--shadow-md);
}

/* ═══════════════════════════════════════════════════════════════════════════
   SAVED VIEW (Map + List)
   ═══════════════════════════════════════════════════════════════════════════ */

#view-saved {
  position: relative;
}

#view-saved .map-container {
  position: absolute;
  inset: 0;
  z-index: var(--z-map);
}

#view-saved .map-container #map {
  width: 100%;
  height: 100%;
}

/* Map floating controls */
.map-header {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  right: var(--space-3);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: var(--z-controls);
  pointer-events: none;
}

.map-header > * {
  pointer-events: auto;
}

.map-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-float);
}

.map-brand-menu {
  display: flex;
  align-items: center;
  justify-content: center;
}

.map-brand-menu svg {
  width: 20px;
  height: 20px;
  stroke: var(--color-text);
}

.map-brand-text {
  font-family: var(--font-family-display);
  font-size: var(--text-base);
  font-weight: var(--font-bold);
}

.map-count {
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-float);
  font-size: var(--text-sm);
}

.map-count strong {
  color: var(--color-text);
}

.map-count span {
  color: var(--color-text-muted);
}

/* Map controls (right side) */
.map-controls {
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: var(--z-controls);
}

.map-control-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  box-shadow: var(--shadow-md);
}

.map-control-btn:first-child {
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.map-control-btn:last-child {
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.map-control-btn svg {
  width: 20px;
  height: 20px;
  stroke: var(--color-text);
}

/* Bottom sheet for location list */
.locations-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
  z-index: var(--z-panel);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  margin: var(--space-3) auto var(--space-2);
  flex-shrink: 0;
}

.sheet-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-3);
  padding: 0 var(--space-4) var(--space-3);
  flex-shrink: 0;
}

.sheet-title {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
}

.filter-chips {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  scrollbar-width: none;
}

.filter-chips::-webkit-scrollbar {
  display: none;
}

.sheet-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) var(--space-4);
}

/* ═══════════════════════════════════════════════════════════════════════════
   TRIPS VIEW
   ═══════════════════════════════════════════════════════════════════════════ */

#view-trips .view-header {
  padding: var(--space-4);
}

.trips-list {
  padding: 0 var(--space-4) var(--space-4);
}

/* Current trip card */
.current-trip-card {
  background: linear-gradient(135deg, var(--color-primary) 0%, #1e3d30 100%);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  color: white;
  position: relative;
}

.current-trip-badge {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  padding: var(--space-1) var(--space-2);
  background: var(--color-accent);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--color-text);
}

.current-trip-name {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  margin-bottom: var(--space-1);
}

.current-trip-meta {
  font-size: var(--text-sm);
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: var(--space-3);
}

.trip-progress {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}

.trip-progress-stop {
  width: 28px;
  height: 28px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.trip-progress-stop .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
}

.trip-progress-stop.visited .dot {
  background: var(--color-accent);
}

.trip-progress-line {
  flex: 1;
  height: 2px;
  background: rgba(255, 255, 255, 0.2);
}

.current-trip-footer {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: rgba(255, 255, 255, 0.5);
}

/* Trip cards */
.trips-section-title {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--color-text-muted);
  margin-bottom: var(--space-3);
}

.trip-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  box-shadow: var(--shadow-sm);
}

.trip-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-2);
}

.trip-card-name {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--color-text);
}

.trip-card-meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

.trip-card-stats {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.trip-card-stat {
  font-size: var(--text-xs);
  padding: var(--space-1) var(--space-2);
  background: var(--color-accent-muted);
  color: var(--color-accent);
  border-radius: var(--radius-sm);
}

/* ═══════════════════════════════════════════════════════════════════════════
   SETTINGS VIEW
   ═══════════════════════════════════════════════════════════════════════════ */

#view-settings .view-content {
  padding: var(--space-4);
}

.settings-section {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.settings-section-title {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-3);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border-light);
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-row-label {
  font-size: var(--text-base);
  color: var(--color-text);
}

.settings-row-value {
  font-size: var(--text-base);
  color: var(--color-text-muted);
}

.user-info {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-surface-alt);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
}

.user-avatar {
  width: 48px;
  height: 48px;
  background: var(--color-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: var(--font-semibold);
}

.user-details {
  flex: 1;
}

.user-name {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--color-text);
}

.user-email {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ═══════════════════════════════════════════════════════════════════════════
   GLOBAL MAP — shared background for saved + trips views
   ═══════════════════════════════════════════════════════════════════════════ */

#main-content {
  position: relative; /* Override: needed for absolute map-global */
}

#map-global {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: none;
}

/* Show global map only on saved + trips views */
body[data-view="saved"] #app.authenticated #map-global,
body[data-view="trips"] #app.authenticated #map-global {
  display: block;
}

#map-global #map {
  width: 100%;
  height: 100%;
}

/* Map floating controls (bottom-right tray) — fixed to viewport so it's
   always visible regardless of which container currently hosts #map.
   Hidden on views without a map via body[data-view=...] below. */
.map-controls-global {
  position: fixed;
  right: 12px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 500;
}

/* Hide tray on views that don't show a map */
body[data-view="settings"] .map-controls-global,
body[data-view="login"] .map-controls-global {
  display: none;
}

/* On mobile, Explore view hides the map; hide the tray too */
@media (max-width: 767px) {
  body[data-view="explore"] .map-controls-global {
    display: none;
  }
}

/* Map Layers panel (fixed, opens from tray) */
.map-layers-panel {
  position: fixed;
  right: calc(var(--space-3) + 48px);
  bottom: var(--space-6);
  background: var(--color-surface);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  padding: var(--space-4);
  z-index: 51;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
body[data-view="settings"] .map-layers-panel,
body[data-view="login"] .map-layers-panel { display: none !important; }
@media (max-width: 767px) {
  /* Lift the panel above the bottom nav (72px + safe-area) and cap its
     height so the longer 3-style + overlay list scrolls instead of clipping
     under the nav. */
  .map-layers-panel {
    bottom: calc(var(--nav-height-mobile) + var(--space-3));
    max-height: calc(100vh - var(--nav-height-mobile) - var(--space-6) - 80px);
    overflow-y: auto;
  }
}
.map-layers-hd {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.map-layers-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
}
.map-layers-section { }
.map-layers-label {
  font-size: 10px;
  color: var(--color-text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.map-layers-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 4px 0;
  font-size: 13px;
  color: var(--color-text);
}
.map-layers-opt input { accent-color: var(--color-primary); }

.map-layers-legend {
  margin-left: 26px;
  margin-top: 2px;
  margin-bottom: 6px;
  font-size: 11px;
  color: var(--color-text-muted);
}
.map-layers-legend .lg-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0;
}
.map-layers-legend .lg-sw {
  width: 12px;
  height: 12px;
  border: 1px solid #ccc;
  border-radius: 2px;
  display: inline-block;
}

.map-control-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  border: none;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: background var(--transition-fast);
  color: var(--color-text);
}
.map-control-btn:hover { background: var(--color-surface-alt); }
.map-control-btn svg { width: 22px; height: 22px; stroke: currentColor; }

/* Backups toggle button (inside the tray, shown when journey active) */
.map-control-backups {
  color: var(--color-text);
}
.map-control-backups.active {
  background: var(--color-accent);
  color: white;
}

/* Top-right count overlay (entries count / journeys count) */
.map-count-overlay {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  padding: 6px 12px;
  background: var(--color-surface);
  border-radius: var(--radius-full);
  border: 0.5px solid var(--color-border);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--color-text);
  z-index: 10;
  box-shadow: var(--shadow-sm);
  pointer-events: auto;
}

/* ═══════════════════════════════════════════════════════════════════════════
   MAP OVERLAY VIEWS (saved + trips)
   These float over the map with transparent backgrounds
   ═══════════════════════════════════════════════════════════════════════════ */

.map-overlay-view {
  flex-direction: row !important;
  background: transparent !important;
  pointer-events: none; /* Pass clicks to map in empty areas */
}

/* Override: solid-bg views (explore, settings) need to cover map */
#view-explore,
#view-settings {
  background: var(--color-base);
  z-index: 5;
}

/* ═══════════════════════════════════════════════════════════════════════════
   SIDE PANELS (locations panel, trips panels)
   ═══════════════════════════════════════════════════════════════════════════ */

.map-side-panel {
  width: 320px;
  min-width: 220px;
  max-width: 500px;
  height: 100%;
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 0.5px solid var(--color-border);
  pointer-events: auto; /* Panels receive clicks */
  overflow: hidden;
  z-index: 1;
}

/* Panel sections */
.side-panel-hd {
  padding: 14px 16px 12px;
  border-bottom: 0.5px solid var(--color-border);
  flex-shrink: 0;
  background: var(--color-surface);
}

.side-panel-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--color-text);
  margin-bottom: var(--space-3);
}

.side-panel-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-3) var(--space-3);
}

.side-panel-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 0.5px solid var(--color-border);
  flex-shrink: 0;
  background: var(--color-surface);
}

/* Resize handle between panels */
.resize-handle {
  width: 4px;
  background: var(--color-border);
  cursor: col-resize;
  flex-shrink: 0;
  position: relative;
  pointer-events: auto;
  z-index: 2;
  transition: background var(--transition-fast);
}
.resize-handle:hover,
.resize-handle.dragging {
  background: var(--color-primary);
}
.resize-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 40px;
  background: var(--color-text-muted);
  border-radius: 1px;
  opacity: 0.35;
}

/* ═══════════════════════════════════════════════════════════════════════════
   TRIPS-SPECIFIC PANELS
   ═══════════════════════════════════════════════════════════════════════════ */

.trips-hd-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}

/* Journey detail panel — hidden until open */
.trips-detail-panel {
  width: 0;
  min-width: 0;
  overflow: hidden;
  transition: width 0.22s cubic-bezier(0.32, 0.72, 0, 1),
              min-width 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}

.trips-detail-panel.open {
  width: 340px;
  min-width: 240px;
  overflow: hidden; /* panel body scrolls internally */
}

.trips-detail-panel.open > * {
  animation: panelSlideIn 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes panelSlideIn {
  from { opacity: 0; transform: translateX(-16px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Location detail panel — hidden until open */
.trips-location-panel {
  width: 0;
  min-width: 0;
  overflow: hidden;
  transition: width 0.22s cubic-bezier(0.32, 0.72, 0, 1),
              min-width 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}

.trips-location-panel.open {
  width: 320px;
  min-width: 240px;
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════════════════
   TRIPS VIEW — detail panel internal layout
   ═══════════════════════════════════════════════════════════════════════════ */

#trips-panel-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.detail-panel-hd {
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--color-border);
  flex-shrink: 0;
  background: var(--color-surface);
}

.detail-panel-footer {
  flex-shrink: 0;
  padding: 10px 12px;
  border-top: 0.5px solid var(--color-border);
  background: var(--color-surface);
}

.detail-panel-footer .add-stop-btn {
  margin: 0;
  width: 100%;
}

.detail-panel-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.detail-back-btn {
  font-size: 13px;
  font-weight: var(--font-medium);
  color: var(--color-primary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.detail-actions {
  margin-left: auto;
  display: flex;
  gap: 10px;
  align-items: center;
}

.detail-maps-btn {
  font-size: 13px;
  font-weight: var(--font-medium);
  color: var(--color-primary);
  background: none;
  border: none;
  cursor: pointer;
}

.detail-journey-name {
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  color: var(--color-text);
  margin-bottom: 2px;
}

.detail-journey-meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.detail-cost-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.detail-cost-card {
  flex: 1;
  border-radius: var(--radius-md);
  padding: 8px 10px;
  text-align: center;
}
.detail-cost-card.muted {
  background: var(--color-surface-alt);
}
.detail-cost-card.accent {
  background: var(--color-primary);
}
.detail-cost-label {
  font-size: 10px;
  color: var(--color-text-muted);
  margin-bottom: 2px;
}
.detail-cost-card.accent .detail-cost-label { color: rgba(255,255,255,0.7); }
.detail-cost-value {
  font-size: 16px;
  font-weight: var(--font-semibold);
  color: var(--color-text);
}
.detail-cost-card.accent .detail-cost-value { color: white; }

/* Itinerary list */
.itin-section-title {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--color-text);
  margin-bottom: 12px;
  padding: 14px 16px 0;
}

.leg-stop {
  position: relative;
  padding: 0 16px 14px 36px;
}
.leg-stop:last-child { padding-bottom: 4px; }

.leg-stop-line {
  position: absolute;
  left: 20px;
  top: 14px;
  bottom: 0;
  width: 1.5px;
  background: var(--color-primary);
  opacity: 0.3;
}
.leg-stop:last-child .leg-stop-line { display: none; }

.leg-stop-dot {
  position: absolute;
  left: 14px;
  top: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 2.5px solid var(--color-surface);
  box-shadow: 0 0 0 1.5px var(--color-primary);
}
.leg-stop-dot.here {
  box-shadow: 0 0 0 4px rgba(45, 90, 71, 0.2);
}
.leg-stop-dot.start {
  background: var(--color-text-muted);
  box-shadow: 0 0 0 1.5px var(--color-text-muted);
}

.drag-handle {
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  line-height: 1;
  padding: 4px 6px;
  color: var(--color-text-muted);
  cursor: grab;
  opacity: 0;
  transition: opacity 150ms ease;
  user-select: none;
  touch-action: none;
  z-index: 2;
}
.drag-handle:active { cursor: grabbing; }
.leg-item:hover .drag-handle,
.leg-item.leg-sort-chosen .drag-handle { opacity: 1; }

@media (max-width: 767px) {
  /* No hover state on touch devices — keep the handle visible so reorder is discoverable */
  .drag-handle { opacity: 0.6; }
}

/* Sortable.js drag visuals */
.leg-item.leg-sort-ghost {
  opacity: 0.35;
  background: var(--color-primary-muted);
  border-radius: var(--radius-md);
}
.leg-item.leg-sort-chosen {
  background: var(--color-surface);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14);
  border-radius: var(--radius-md);
}
.leg-item.leg-sort-drag { cursor: grabbing; }

/* Stale-route nudge after reorder */
.leg-drive-info.stale {
  font-style: italic;
  color: var(--color-text-muted);
}
.stale-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  font-size: 10px;
  font-weight: 600;
  color: var(--color-warning);
  background: var(--color-warning-light);
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
}
.stale-badge:hover { filter: brightness(0.95); }

.leg-stop-name {
  font-size: 13px;
  font-weight: var(--font-medium);
  color: var(--color-primary);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: rgba(45, 90, 71, 0.3);
}
.leg-stop-name.muted {
  color: var(--color-text-secondary);
  text-decoration: none;
  cursor: default;
}
.leg-stop-here {
  font-size: 11px;
  color: var(--color-primary);
  font-weight: var(--font-medium);
  margin-top: 1px;
}
.leg-stop-dates {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 1px;
}

.leg-stop-actions {
  position: absolute;
  right: 16px;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-end;
}
.leg-stop-cost {
  font-size: 12px;
  font-weight: var(--font-medium);
  color: var(--color-text);
}
.leg-stop-cost.free { color: var(--color-primary); }
.leg-stop-edit-btns {
  display: flex;
  gap: 2px;
}

.leg-drive-info {
  font-size: 11px;
  color: var(--color-text-muted);
  background: var(--color-surface-alt);
  border-radius: 5px;
  padding: 3px 8px;
  margin-top: 5px;
  display: inline-block;
}

.add-stop-btn {
  width: calc(100% - 32px);
  margin: 10px 16px 16px;
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1.5px dashed rgba(45, 90, 71, 0.3);
  background: transparent;
  color: var(--color-primary);
  font-size: 13px;
  font-weight: var(--font-medium);
  cursor: pointer;
  text-align: center;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.add-stop-btn:hover {
  background: var(--color-primary-muted);
  border-color: var(--color-primary);
}

/* Context menu for journey cards */
.journey-context-menu {
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--color-surface);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 160px;
  z-index: 200;
  overflow: hidden;
  display: none;
}
.journey-context-menu.open { display: block; }

/* Mobile: panels become bottom sheets */
@media (max-width: 767px) {
  .map-overlay-view {
    flex-direction: column !important;
  }

  .map-side-panel,
  #location-detail-panel,
  #explore-backup-panel,
  #discover-detail-panel,
  #modal-discover,
  .explore-left,
  #modal-add-location {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    border-right: none;
    border-top: 0.5px solid var(--color-border);
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 40;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    height: calc(100vh - 48px);
    transform: translateY(calc(100vh - 48px - 55vh)); /* default: half */
    transition: transform 300ms ease-out;
    pointer-events: auto;
  }

  /* Mobile: .explore-left stops scrolling itself. Grabber + brand sit at
     the top as fixed-size flex items; .explore-content-scroll inside is
     the actual scroll surface. This keeps the grabber visually attached
     to the brand header (matches the Locations drawer pattern) instead of
     floating over scrolled content. */
  .explore-left {
    overflow: hidden !important;
  }
  .explore-content-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    /* Bottom nav (z 300) overlays the drawer (z 40) and covers ~72px+safe-area
       at the bottom. Pad scrollable content so trailing buttons (Show more,
       discover-more) can scroll above the nav and remain tappable. */
    padding-bottom: calc(var(--nav-height-mobile) + var(--space-4));
    /* Allow this flex item to shrink below its content height so its own
       overflow scroll actually activates. */
    min-height: 0;
  }

  /* Snap anchors via translateY. JS inline-transform overrides during drag. */
  body[data-drawer-snap="full"] .map-side-panel,
  body[data-drawer-snap="full"] #location-detail-panel,
  body[data-drawer-snap="full"] #explore-backup-panel,
  body[data-drawer-snap="full"] #discover-detail-panel,
  body[data-drawer-snap="full"] #modal-discover,
  body[data-drawer-snap="full"] .explore-left,
  body[data-drawer-snap="full"] #modal-add-location { transform: translateY(0); }

  body[data-drawer-snap="half"] .map-side-panel,
  body[data-drawer-snap="half"] #location-detail-panel,
  body[data-drawer-snap="half"] #explore-backup-panel,
  body[data-drawer-snap="half"] #discover-detail-panel,
  body[data-drawer-snap="half"] #modal-discover,
  body[data-drawer-snap="half"] .explore-left,
  body[data-drawer-snap="half"] #modal-add-location { transform: translateY(calc(100vh - 48px - 55vh)); }

  body[data-drawer-snap="peek"] .map-side-panel,
  body[data-drawer-snap="peek"] #location-detail-panel,
  body[data-drawer-snap="peek"] #explore-backup-panel,
  body[data-drawer-snap="peek"] #discover-detail-panel,
  body[data-drawer-snap="peek"] #modal-discover,
  body[data-drawer-snap="peek"] .explore-left,
  body[data-drawer-snap="peek"] #modal-add-location { transform: translateY(calc(100vh - 48px - 140px)); }

  /* Grab handle. Sits as a non-scrolling first child of each drawer panel —
     drawers either don't scroll themselves (their inner .side-panel-body
     does) or, in the case of .explore-left, use an inner .explore-content-
     scroll wrapper so the grabber + header stay pinned together at the top.
     Either way, no sticky positioning needed. */
  .drawer-grabber {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 0 6px;
    cursor: grab;
    flex-shrink: 0;
    user-select: none;
    touch-action: none;
    position: relative;
    z-index: 10;
  }
  .drawer-grabber::before {
    content: '';
    width: 40px;
    height: 4px;
    background: var(--color-border);
    border-radius: 2px;
  }
  .drawer-grabber:active { cursor: grabbing; }

  .trips-detail-panel.open {
    width: 100% !important;
    height: 85vh;
  }

  .resize-handle {
    display: none !important;
  }

  /* Tray settles at the drawer's anchor position — only moves on snap change,
     never during drag. */
  .map-controls-global {
    z-index: 500;
    transition: bottom 300ms ease-out;
  }
  body[data-drawer-snap="peek"] .map-controls-global { bottom: 160px; }
  body[data-drawer-snap="half"] .map-controls-global { bottom: calc(55vh + 16px); }
  body[data-drawer-snap="full"] .map-controls-global { bottom: calc(100vh - 48px + 16px); }
  body:not([data-drawer-snap]) .map-controls-global { bottom: calc(55vh + 16px); }

  body[data-view="explore"] .map-controls-global,
  body[data-view="saved"] .map-controls-global,
  body[data-view="trips"] .map-controls-global {
    display: flex !important;
  }
  body[data-view="settings"] .map-controls-global,
  body[data-view="login"] .map-controls-global {
    display: none !important;
  }

  /* Drawer pinned footers (Location Detail "Edit destination / Edit location
     details", Journey Detail "+ Add next destination") sit at bottom: 0 of
     the drawer, but #bottom-nav is fixed at viewport bottom with z-index 300
     and covers ~72px. Push footer content up by the nav height so the
     buttons are visible above the nav. */
  #location-detail-panel .side-panel-footer,
  #explore-backup-panel .side-panel-footer,
  #discover-detail-panel .side-panel-footer,
  #trips-panel-content .detail-panel-footer {
    padding-bottom: calc(var(--space-3) + var(--nav-height-mobile));
  }
}
}
