:root {
  color-scheme: light;
  --bg: oklch(96% 0.008 82);
  --panel: oklch(99% 0.006 82);
  --ink: oklch(22% 0.035 78);
  --muted: oklch(46% 0.027 80);
  --line: oklch(86% 0.018 82);
  --accent: oklch(53% 0.15 35);
  --accent-strong: oklch(45% 0.16 32);
  --accent-soft: oklch(93% 0.04 42);
  --green: oklch(48% 0.12 152);
  --map-surface: oklch(98% 0.006 86);
  --map-surface-strong: oklch(94% 0.012 82);
  --map-ink: oklch(24% 0.032 76);
  --map-muted: oklch(49% 0.026 78);
  --map-line: oklch(84% 0.018 82);
  --shadow: 0 20px 60px oklch(20% 0.03 70 / 0.12);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body[data-map-theme="dark"] {
  color-scheme: dark;
  --bg: oklch(13% 0.03 264);
  --panel: oklch(18% 0.028 264);
  --ink: oklch(94% 0.012 88);
  --muted: oklch(72% 0.024 250);
  --line: oklch(31% 0.035 262);
  --accent: oklch(76% 0.16 74);
  --accent-strong: oklch(82% 0.14 78);
  --accent-soft: oklch(29% 0.08 66);
  --map-surface: oklch(18% 0.028 264);
  --map-surface-strong: oklch(13% 0.032 264);
  --map-ink: oklch(94% 0.012 88);
  --map-muted: oklch(73% 0.024 250);
  --map-line: oklch(33% 0.035 262);
  --shadow: 0 20px 60px oklch(6% 0.03 264 / 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(135deg, oklch(98% 0.009 86), oklch(94% 0.015 72)),
    var(--bg);
  color: var(--ink);
}

body[data-map-theme="dark"] {
  background:
    radial-gradient(circle at 15% 10%, oklch(24% 0.055 264), transparent 36%),
    var(--bg);
}

button,
input {
  font: inherit;
}

/* Critical Leaflet layout rules. Keeping these locally prevents a broken map if the CDN stylesheet is blocked. */
.leaflet-container {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 42%, color-mix(in oklch, var(--map-surface) 75%, var(--accent-soft)), transparent 34%),
    var(--map-surface-strong);
  outline-offset: 1px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  user-select: none;
  -webkit-user-drag: none;
}

.leaflet-tile {
  width: 256px;
  height: 256px;
  filter: saturate(0.9) contrast(1.04) brightness(0.98);
}

body[data-map-theme="dark"] .leaflet-tile {
  filter: saturate(1.02) contrast(1.12) brightness(1.04);
}

.leaflet-map-pane {
  z-index: 400;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-container img {
  max-width: none;
  max-height: none;
}

.leaflet-container.leaflet-touch-zoom {
  touch-action: pan-x pan-y;
}

.leaflet-control-container .leaflet-top,
.leaflet-control-container .leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-bottom .leaflet-control {
  margin-bottom: 18px;
}

.leaflet-top .leaflet-control {
  margin-top: 72px;
}

.leaflet-right .leaflet-control {
  margin-right: 18px;
}

.leaflet-control-zoom {
  border: 1px solid var(--map-line);
  border-radius: 12px;
  overflow: hidden;
  background: color-mix(in oklch, var(--map-surface) 92%, transparent);
  box-shadow: 0 18px 48px oklch(8% 0.03 264 / 0.42);
}

.leaflet-control-zoom a {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--map-ink);
  font-size: 1.1rem;
  font-weight: 900;
  line-height: 1;
  text-decoration: none;
}

.leaflet-control-zoom a + a {
  border-top: 1px solid var(--map-line);
}

.leaflet-control-attribution {
  padding: 5px 8px;
  background: color-mix(in oklch, var(--map-surface-strong) 88%, transparent);
  color: var(--map-muted);
  font-size: 0.7rem;
}

.leaflet-control-attribution a {
  color: oklch(80% 0.12 78);
}

.leaflet-popup {
  position: absolute;
  text-align: center;
}

.leaflet-popup-content-wrapper {
  padding: 1px;
  text-align: left;
  border: 1px solid var(--map-line);
  background: color-mix(in oklch, var(--map-surface) 96%, transparent);
  box-shadow: 0 22px 70px oklch(8% 0.03 264 / 0.5);
}

.leaflet-popup-content {
  min-width: 220px;
  margin: 14px 16px;
}

.leaflet-popup-tip-container {
  position: absolute;
  left: 50%;
  width: 40px;
  height: 20px;
  margin-left: -20px;
  overflow: hidden;
  pointer-events: none;
}

.leaflet-popup-tip {
  width: 16px;
  height: 16px;
  margin: -8px auto 0;
  border-right: 1px solid var(--map-line);
  border-bottom: 1px solid var(--map-line);
  background: var(--map-surface);
  transform: rotate(45deg);
  box-shadow: 0 16px 48px oklch(8% 0.03 264 / 0.35);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(340px, 430px) minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto auto auto auto minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-right: 1px solid var(--line);
  background: color-mix(in oklch, var(--panel) 92%, transparent);
  box-shadow: var(--shadow);
  z-index: 2;
}

.panel-close,
.sidebar-backdrop,
.mobile-search-toggle {
  display: none;
}

.map-theme-toggle {
  position: absolute;
  top: 18px;
  right: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--map-line);
  border-radius: 999px;
  padding: 0 15px;
  background: color-mix(in oklch, var(--map-surface) 92%, transparent);
  color: var(--map-ink);
  font-size: 0.84rem;
  font-weight: 900;
  box-shadow: 0 16px 42px oklch(8% 0.03 264 / 0.2);
  cursor: pointer;
  z-index: 700;
}

.masthead {
  padding: 28px 28px 22px;
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  max-width: 10ch;
  margin: 0;
  font-size: clamp(2.1rem, 4vw, 3.55rem);
  line-height: 0.94;
  letter-spacing: 0;
}

.intro {
  max-width: 58ch;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.6;
}

.controls {
  display: grid;
  gap: 14px;
  padding: 0 28px 18px;
}

.search-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

#place-search {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 14px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

#place-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent) 20%, transparent);
}

.category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.category-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.category-button:hover {
  transform: translateY(-1px);
  border-color: color-mix(in oklch, var(--accent) 45%, var(--line));
  color: var(--ink);
}

.category-button.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 800;
}

.itinerary {
  border-top: 1px solid var(--line);
  padding: 16px 28px;
  background: color-mix(in oklch, var(--panel) 82%, var(--accent-soft));
}

.itinerary-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.section-kicker {
  margin: 0 0 3px;
  color: var(--accent-strong);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h2 {
  margin: 0;
  font-size: 1.12rem;
  line-height: 1.2;
}

.text-button {
  border: 0;
  padding: 4px 0;
  background: transparent;
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 850;
  cursor: pointer;
}

.text-button:disabled {
  color: color-mix(in oklch, var(--muted) 55%, transparent);
  cursor: not-allowed;
}

.itinerary-summary {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.itinerary-filter {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  margin-top: 12px;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 800;
  line-height: 1.35;
  cursor: pointer;
}

.itinerary-filter input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-strong);
}

.itinerary-filter:has(input:disabled) {
  color: color-mix(in oklch, var(--muted) 65%, transparent);
  cursor: not-allowed;
}

.itinerary-list {
  display: grid;
  gap: 7px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.itinerary-stop {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 10px;
  background: var(--panel);
}

.itinerary-stop button {
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.stop-index {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 900;
}

.stop-name {
  display: block;
  overflow: hidden;
  font-size: 0.84rem;
  font-weight: 850;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stop-hours {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.76rem;
}

.stop-actions {
  display: flex;
  align-items: center;
  gap: 3px;
}

.move-stop,
.remove-stop {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1;
  text-align: center;
}

.move-stop:hover,
.remove-stop:hover {
  background: color-mix(in oklch, var(--accent-soft) 64%, transparent);
  color: var(--accent-strong);
}

.move-stop:disabled {
  color: color-mix(in oklch, var(--muted) 45%, transparent);
  cursor: not-allowed;
}

.move-stop:disabled:hover {
  background: transparent;
}

.summary-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 0 28px;
  color: var(--muted);
  font-size: 0.9rem;
}

.summary-bar span:first-child {
  color: var(--ink);
  font-size: 1.08rem;
  font-weight: 900;
}

.places-list {
  min-height: 0;
  margin: 0;
  padding: 8px;
  list-style: none;
}

.place-item {
  margin: 0;
}

.place-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  border-radius: var(--radius);
}

.place-row:hover,
.place-row:focus-within {
  background: color-mix(in oklch, var(--accent-soft) 64%, transparent);
}

.place-button {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  border: 0;
  border-radius: var(--radius);
  padding: 13px 14px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.place-button:hover,
.place-button:focus-visible {
  outline: none;
}

.save-button {
  align-self: center;
  min-width: 64px;
  min-height: 34px;
  margin-right: 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 850;
  cursor: pointer;
}

.save-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.save-button.is-saved {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
  color: oklch(98% 0.006 82);
}

.place-number {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--ink);
  color: oklch(98% 0.006 82);
  font-size: 0.76rem;
  font-weight: 900;
}

.place-name {
  display: block;
  margin-bottom: 5px;
  font-weight: 850;
  line-height: 1.25;
}

.place-meta {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.place-hours {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 7px;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 850;
}

.place-category {
  display: inline-block;
  margin-top: 6px;
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.map-panel {
  position: relative;
  min-width: 0;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.map {
  width: 100%;
  height: 100%;
  min-height: 0;
  background: var(--map-surface-strong);
}

.map-fallback {
  display: grid;
  place-items: center;
  min-height: inherit;
  padding: 24px;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.map-note {
  position: absolute;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100% - 36px));
  border: 1px solid var(--map-line);
  border-radius: 12px;
  padding: 11px 13px;
  background: color-mix(in oklch, var(--map-surface) 92%, transparent);
  color: var(--map-muted);
  font-size: 0.82rem;
  line-height: 1.45;
  box-shadow: 0 18px 48px oklch(8% 0.03 264 / 0.4);
  z-index: 600;
}

.map-note span {
  display: block;
  margin-top: 5px;
}

.map-note a {
  color: var(--accent-strong);
  font-weight: 850;
  text-decoration: none;
}

.map-note a:hover {
  text-decoration: underline;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius);
}

.popup-title {
  margin: 0 0 8px;
  color: var(--map-ink);
  font-weight: 900;
  line-height: 1.25;
}

.popup-address,
.popup-category,
.popup-hours {
  margin: 0 0 8px;
  color: var(--map-muted);
  line-height: 1.4;
}

.popup-hours {
  color: oklch(86% 0.15 78);
  font-weight: 850;
}

.popup-link {
  color: oklch(82% 0.14 78);
  font-weight: 800;
  text-decoration: none;
}

.empty-state {
  padding: 22px 20px;
  color: var(--muted);
  line-height: 1.5;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(430px, 92vw);
    height: 100dvh;
    min-height: 0;
    overflow-y: auto;
    transform: translateX(-104%);
    transition: transform 220ms ease;
    border-right: 0;
    border-bottom: 0;
    box-shadow: 24px 0 60px oklch(20% 0.03 70 / 0.2);
    z-index: 1100;
  }

  body.panel-open {
    touch-action: none;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    display: block;
    border: 0;
    background: oklch(16% 0.02 70 / 0.42);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
    z-index: 1000;
  }

  .sidebar-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  .panel-close {
    position: sticky;
    top: 0;
    display: block;
    width: 100%;
    min-height: 44px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: color-mix(in oklch, var(--panel) 96%, transparent);
    color: var(--accent-strong);
    font-weight: 900;
    text-align: center;
    z-index: 5;
  }

  .places-list {
    max-height: none;
  }

  .map-panel,
  .map {
    height: 100dvh;
    min-height: 100dvh;
  }

  .mobile-search-toggle {
    position: absolute;
    top: 14px;
    left: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0 16px;
    background: var(--panel);
    color: var(--accent-strong);
    font-weight: 900;
    box-shadow: 0 12px 32px oklch(20% 0.03 70 / 0.16);
    z-index: 700;
  }

  .leaflet-top .leaflet-control {
    margin-top: 68px;
  }

  .map-note {
    display: none;
  }
}

@media (max-width: 620px) {
  .masthead,
  .controls,
  .itinerary,
  .summary-bar {
    padding-left: 18px;
    padding-right: 18px;
  }

  .masthead {
    padding-top: 22px;
  }

  h1 {
    max-width: 11ch;
    font-size: 2.55rem;
  }

  .category-tabs {
    flex-wrap: nowrap;
    margin-inline: -18px;
    padding: 0 18px 14px;
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .category-button {
    flex: 0 0 auto;
  }

  .place-row {
    grid-template-columns: 1fr;
  }

  .save-button {
    justify-self: start;
    margin: 0 0 12px 56px;
  }

  .map-note {
    right: 10px;
    bottom: 10px;
    max-width: calc(100% - 20px);
    font-size: 0.76rem;
  }
}
