:root {
  --surface: rgba(255, 255, 255, 0.96);
  --surface-solid: #ffffff;
  --surface-subtle: #f4f6f4;
  --surface-hover: #ebf0ec;
  --border: rgba(17, 28, 23, 0.11);
  --border-strong: rgba(17, 28, 23, 0.2);
  --ink: #111c17;
  --ink-muted: #506159;
  --accent: #0b7a4b;
  --accent-hover: #09643d;
  --accent-soft: rgba(11, 122, 75, 0.1);
  --danger: #c92a2a;
  --shadow-sheet: 0 12px 36px rgba(15, 28, 22, 0.14), 0 2px 8px rgba(15, 28, 22, 0.08);
  --shadow-pill: 0 4px 16px rgba(15, 28, 22, 0.12), 0 1px 3px rgba(15, 28, 22, 0.08);

  /* Strict 3-size body scale */
  --text-lg: 1rem;       /* 16px */
  --text-base: 0.875rem; /* 14px */
  --text-sm: 0.8125rem;  /* 13px */

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body,
#app {
  height: 100%;
  width: 100%;
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  color: var(--ink);
  background: #e9eeeb;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#map {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Floating Left Route Sheet */
.route-sheet {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 384px;
  max-width: calc(100vw - 32px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-sheet);
  z-index: 20;
  overflow: visible;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.brand-wordmark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--ink);
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.brand-mark {
  width: 22px;
  height: 22px;
  color: var(--accent);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ghost-action {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 5px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 160ms var(--ease-out), color 160ms var(--ease-out);
}

.ghost-action:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

/* Search Stack */
.search-stack {
  padding: 14px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.waypoints-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.waypoints-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
}

.wp-row {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

.wp-marker-col {
  width: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.wp-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2.5px solid var(--accent);
  background: var(--surface-solid);
}

.wp-dot.via {
  width: 9px;
  height: 9px;
  border-color: var(--ink-muted);
}

.wp-dot.end {
  width: 12px;
  height: 12px;
  border-color: var(--danger);
  background: var(--danger);
}

.wp-input-wrap {
  position: relative;
  flex: 1;
}

.wp-input {
  width: 100%;
  height: 40px;
  padding: 0 32px 0 12px;
  background: var(--surface-subtle);
  border: 1px solid transparent;
  border-radius: 10px;
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--ink);
  outline: none;
  transition: background-color 160ms var(--ease-out), border-color 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}

.wp-input::placeholder {
  color: var(--ink-muted);
  font-weight: 400;
}

.wp-input:hover {
  background: var(--surface-hover);
}

.wp-input:focus {
  background: var(--surface-solid);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.wp-clear-input {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--ink-muted);
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color 140ms var(--ease-out), color 140ms var(--ease-out);
}

.wp-clear-input:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.wp-clear-input svg {
  width: 14px;
  height: 14px;
}

.swap-btn {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface-solid);
  color: var(--ink-muted);
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color 160ms var(--ease-out), color 160ms var(--ease-out), border-color 160ms var(--ease-out);
}

.swap-btn:hover {
  background: var(--surface-subtle);
  color: var(--ink);
  border-color: var(--border-strong);
}

.swap-btn svg {
  width: 16px;
  height: 16px;
}

/* Autocomplete Dropdown */
.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 14px 32px rgba(15, 28, 22, 0.16);
  max-height: 260px;
  overflow-y: auto;
  z-index: 50;
  padding: 4px;
}

.search-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 120ms var(--ease-out);
}

.search-item:hover,
.search-item.active {
  background: var(--surface-subtle);
}

.search-item-icon {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  color: var(--ink-muted);
  flex-shrink: 0;
}

.search-item-icon.accent {
  color: var(--accent);
}

.search-item-text {
  min-width: 0;
}

.search-item-name {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-item-addr {
  font-size: var(--text-sm);
  color: var(--ink-muted);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-empty {
  padding: 12px;
  font-size: var(--text-sm);
  color: var(--ink-muted);
  text-align: center;
}

.search-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 28px;
}

.inline-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  padding: 3px 0;
  transition: color 140ms var(--ease-out);
}

.inline-link:hover {
  color: var(--accent-hover);
}

.inline-link svg {
  width: 14px;
  height: 14px;
}

.search-hint {
  font-size: var(--text-sm);
  color: var(--ink-muted);
}

/* Error Notice */
.error-banner {
  margin: 0 16px 14px;
  padding: 10px 12px;
  background: #fef2f2;
  border: 1px solid rgba(201, 42, 42, 0.22);
  color: var(--danger);
  border-radius: 10px;
  font-size: var(--text-sm);
  font-weight: 500;
}

/* Results Section */
.results-section {
  border-top: 1px solid var(--border);
  padding: 16px;
  max-height: calc(100dvh - 240px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-radius: 0 0 16px 16px;
}

.results-section::-webkit-scrollbar {
  width: 5px;
}

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

.route-headline {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.route-primary-metrics {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}

.metric-time {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--accent);
}

.metric-sep {
  font-size: var(--text-lg);
  color: var(--border-strong);
}

.metric-dist {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.route-subline {
  font-size: var(--text-sm);
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}

/* Stacked Bar & Breakdown */
.composition-block,
.surface-block,
.corridors-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-heading {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--ink);
}

.stacked-bar {
  display: flex;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-subtle);
  gap: 2px;
}

.breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bd-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.bd-left {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 500;
}

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

.bd-right {
  color: var(--ink-muted);
}

.bd-right strong {
  color: var(--ink);
  font-weight: 600;
}

.corridors-text {
  font-size: var(--text-sm);
  color: var(--ink-muted);
  line-height: 1.5;
}

/* Primary CTA */
.primary-cta {
  width: 100%;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 160ms var(--ease-out), transform 140ms var(--ease-out);
}

.primary-cta:hover {
  background: var(--accent-hover);
}

.primary-cta:active {
  transform: scale(0.99);
}

.primary-cta svg {
  width: 17px;
  height: 17px;
}

/* Top-Right Floating Map Controls */
.map-controls-top {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 15;
}

.layer-switch {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 40px;
  padding: 0 14px;
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-pill);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}

.layer-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  width: 32px;
  height: 18px;
  border-radius: 999px;
  background: #cbd5cf;
  position: relative;
  transition: background-color 180ms var(--ease-out);
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 180ms var(--ease-out);
}

.layer-switch input:checked + .switch-track {
  background: var(--accent);
}

.layer-switch input:checked + .switch-track::after {
  transform: translateX(14px);
}

/* Connected Segmented Control (Radio Inputs) */
.segmented-control {
  display: inline-flex;
  align-items: center;
  height: 40px;
  padding: 3px;
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-pill);
}

.seg-option {
  position: relative;
  cursor: pointer;
  user-select: none;
}

.seg-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg-option span {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-muted);
  transition: background-color 160ms var(--ease-out), color 160ms var(--ease-out);
}

.seg-option input:checked + span {
  background: var(--ink);
  color: #ffffff;
}

/* Floating Bottom Legend (sits cleanly beside route sheet, clear of zoom/attribution) */
.map-legend {
  position: fixed;
  bottom: 20px;
  left: 416px;
  max-width: calc(100vw - 490px);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  padding: 9px 14px;
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-pill);
  z-index: 15;
}

@media (max-width: 1080px) {
  .map-legend {
    display: none;
  }
}

.leg-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ink);
}

.leg-item i {
  display: inline-block;
  width: 12px;
  height: 4px;
  border-radius: 2px;
}

/* Status Toast */
.routing-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 38px;
  padding: 0 16px;
  background: var(--ink);
  color: #ffffff;
  border-radius: 999px;
  box-shadow: var(--shadow-pill);
  font-size: var(--text-sm);
  font-weight: 600;
  z-index: 30;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* MapLibre Popup */
.maplibregl-popup-content {
  background: var(--ink) !important;
  color: #ffffff !important;
  border-radius: 10px !important;
  padding: 9px 12px !important;
  font-family: "Plus Jakarta Sans", sans-serif;
  font-size: var(--text-sm);
  line-height: 1.4;
  box-shadow: 0 10px 24px rgba(15, 28, 22, 0.25) !important;
}

.maplibregl-popup-tip {
  border-top-color: var(--ink) !important;
  border-bottom-color: var(--ink) !important;
}

.hidden {
  display: none !important;
}

.mobile-only {
  display: none;
}

.icon-action {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--ink-muted);
  border-radius: 8px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-action svg {
  width: 18px;
  height: 18px;
}

/* Mobile Layout (390px+) */
@media (max-width: 768px) {
  .mobile-only {
    display: grid;
  }

  .route-sheet {
    top: 10px;
    left: 10px;
    right: 10px;
    width: auto;
    max-width: none;
    border-radius: 14px;
  }

  .results-section {
    max-height: 36dvh;
    border-radius: 0 0 14px 14px;
  }

  .route-sheet.collapsed .search-stack,
  .route-sheet.collapsed .results-section,
  .route-sheet.collapsed .error-banner {
    display: none !important;
  }

  .route-sheet.collapsed #btn-collapse-mobile svg {
    transform: rotate(180deg);
  }

  .map-controls-top {
    top: auto;
    bottom: 14px;
    left: 10px;
    right: 10px;
    justify-content: space-between;
  }

  .maplibregl-ctrl-bottom-right {
    bottom: 62px !important;
  }

  .maplibregl-ctrl-attrib {
    display: none !important;
  }

  .map-legend {
    display: none;
  }

  .search-hint {
    display: none;
  }
}

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