:root {
  color-scheme: light;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-glass: rgba(255, 255, 255, 0.9);
  --ink: #0f2942;
  --muted: #52677a;
  --border: #dce5ee;
  --accent: #1d6fa5;
  --accent-soft: #e6f2fa;
  --walk: #0d8a67;
  --drive: #c46210;
  --transit: #2563eb;
  --flight: #7c3aed;
  --shadow: 0 4px 16px rgba(15, 41, 66, 0.12);
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

/* Header */
.app-header {
  height: 58px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--ink);
  color: #fff;
  z-index: 1000;
  position: relative;
}
.app-header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.app-header .subtitle {
  font-size: 12px;
  color: #b7cde0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-block { min-width: 0; }
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.install-btn {
  background: #38bdf8;
  color: #0f2942;
  border: 0;
  border-radius: 8px;
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.install-btn:hover { background: #7dd3fc; }
.basemap-control select {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}
.basemap-control select option { color: var(--ink); background: #fff; }

/* Main Layout */
.app-main {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  height: calc(100vh - 58px);
  height: calc(100dvh - 58px);
}

.map-panel {
  grid-column: 2;
  grid-row: 1;
  position: relative;
  height: 100%;
}
#map { height: 100%; width: 100%; background: #dceaf0; }

/* Floating Map Controls */
.map-tools, .map-status, .playback-bar {
  position: absolute;
  z-index: 800;
}
.map-tools {
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
}
.map-tools button, .playback-bar button {
  background: var(--surface-glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.15s, transform 0.1s;
}
.map-tools button:hover, .playback-bar button:hover { background: #fff; }
.map-tools button:active, .playback-bar button:active { transform: scale(0.97); }

/* Playback Bar */
.playback-bar {
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--surface-glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  max-width: calc(100% - 24px);
}
.playback-bar button {
  box-shadow: none;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
}
.playback-bar button.primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
  padding: 5px 14px;
}
.playback-bar button.primary:hover { background: #194166; }
.pb-status {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 0 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.map-status {
  top: 12px;
  left: 54px;
  background: var(--surface-glass);
  backdrop-filter: blur(8px);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  color: var(--ink);
  box-shadow: var(--shadow);
  max-width: calc(100% - 140px);
}

/* Sidebar / Drawer */
.drawer {
  grid-column: 1;
  grid-row: 1;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.drawer-handle { display: none; }
.drawer-content {
  padding: 14px 16px 24px;
  overflow-y: auto;
  flex: 1;
}

/* Filters & Search */
.filter-section { position: relative; margin-bottom: 12px; }
.region-pills {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.pill {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.pill.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
#place-search {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: var(--bg);
}
#place-search:focus { outline: 2px solid var(--accent); background: #fff; }

.search-results {
  position: absolute;
  left: 0; right: 0;
  top: calc(100% + 4px);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  list-style: none;
  margin: 0; padding: 4px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 900;
}
.search-results li button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 7px 9px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}
.search-results li button:hover { background: var(--accent-soft); }
.search-results .sr-day { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* Day Selector */
.day-controls select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  background: #fff;
}
.day-controls nav { display: flex; gap: 8px; margin-top: 8px; }
.day-controls nav button {
  flex: 1;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.day-controls nav button:hover:enabled { background: var(--bg); }
.day-controls nav button:disabled { opacity: 0.4; cursor: default; }

.day-header { margin: 14px 0 10px; }
.day-header h2 { margin: 0; font-size: 18px; letter-spacing: -0.02em; }
.day-stats { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Mode Filter Chips */
.mode-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.mode-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  opacity: 0.45;
}
.mode-chip.active { opacity: 1; background: var(--bg); }
.swatch { width: 14px; border-top: 3px solid; }
.swatch.w { border-color: var(--walk); }
.swatch.c { border-color: var(--drive); }
.swatch.t { border-color: var(--transit); border-top-style: dashed; }
.swatch.f { border-color: var(--flight); border-top-style: dashed; }

.day-note {
  font-size: 12px;
  color: #714b14;
  background: #fef3c7;
  padding: 8px 10px;
  border-radius: 8px;
  margin: 0 0 12px;
}

/* Timeline Stops */
.timeline {
  list-style: none;
  padding: 0;
  margin: 0;
  position: relative;
}
.stop {
  position: relative;
  padding: 10px 10px 10px 38px;
  border-radius: 10px;
  margin-bottom: 4px;
  transition: background 0.15s;
}
.stop::before {
  content: "";
  position: absolute;
  left: 16px;
  top: 32px;
  bottom: -14px;
  width: 2px;
  background: var(--border);
}
.stop:last-child::before { display: none; }
.stop.active { background: var(--accent-soft); }
.stop-number {
  position: absolute;
  left: 5px;
  top: 10px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
}
.stop.active .stop-number { background: var(--accent); box-shadow: 0 0 0 3px rgba(29, 111, 165, 0.25); }
.stop-title {
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}
.stop-title:hover { color: var(--accent); text-decoration: underline; }
.stop-detail { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stop-links { font-size: 12px; margin-top: 4px; }
.stop-links a { color: var(--accent); text-decoration: none; font-weight: 500; }
.stop-links a:hover { text-decoration: underline; }
.stop-links a + a { margin-left: 10px; }

/* Map Pins */
.pin {
  border-radius: 15px;
  min-width: 28px;
  width: max-content;
  height: 28px;
  padding: 0 7px;
  display: grid;
  place-items: center;
  background: var(--ink);
  border: 2px solid #fff;
  color: #fff;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(15, 41, 66, 0.45);
  position: absolute;
  bottom: 0;
  left: 0;
  transform: translateX(-50%);
  transition: transform 0.2s, background 0.2s;
}
.pin.area { background: #fff; color: var(--ink); border: 2px dashed var(--accent); }
.pin.active { background: var(--accent); color: #fff; transform: translateX(-50%) scale(1.22); z-index: 999; }

.source-line { font-size: 11px; color: var(--muted); margin-top: 5px; }
.mapbox-brand { display: block; width: 73px; height: 19px; background: center/contain no-repeat url(vendor/mapbox.svg); }
.map-panel:fullscreen { height: 100%; }

/* Mobile Web App Layout (Bottom Sheet Drawer) */
@media (max-width: 768px) {
  .app-main {
    display: block;
    position: relative;
  }
  .map-panel {
    position: absolute;
    inset: 0;
  }
  .playback-bar {
    bottom: 76px;
    padding: 5px 8px;
  }
  .pb-status { display: none; }
  .drawer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 76dvh;
    border-right: 0;
    border-top: 1px solid var(--border);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -6px 24px rgba(15, 41, 66, 0.18);
    transform: translateY(calc(100% - 58px));
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 950;
  }
  .drawer.open { transform: translateY(0); }
  .drawer-handle {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    height: 58px;
    width: 100%;
    border: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    flex-shrink: 0;
    padding: 6px 16px;
  }
  .handle-pill {
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: #cbd5e1;
  }
  .drawer-summary {
    font-size: 13px;
    font-weight: 700;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
}
