:root {
  color-scheme: light;
  --blue: #1a73e8;
  --blue-dark: #1558b0;
  --blue-soft: #e8f0fe;
  --orange: #f57c00;
  --purple: #7b61c9;
  --green: #188038;
  --red: #c5221f;
  --ink: #202124;
  --muted: #5f6368;
  --line: #dadce0;
  --surface: #ffffff;
  --surface-soft: #f8f9fa;
  --shadow: 0 2px 8px rgba(60, 64, 67, 0.22), 0 1px 3px rgba(60, 64, 67, 0.18);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #e5e9ec;
  color: var(--ink);
  font-family: Arial, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea { font: inherit; }

button,
a { -webkit-tap-highlight-color: transparent; }

button { border: 0; cursor: pointer; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.map-app,
.map-stage,
#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

@supports (height: 100dvh) {
  body,
  .map-app,
  .map-stage,
  #map { height: 100dvh; }
}

#map { z-index: 0; background: #e7ebee; }

.leaflet-container {
  font-family: Arial, "Helvetica Neue", sans-serif;
  color: var(--ink);
}

.leaflet-control-zoom {
  border: 0 !important;
  border-radius: 10px !important;
  overflow: hidden;
  box-shadow: var(--shadow) !important;
}

.leaflet-control-zoom a {
  width: 40px !important;
  height: 40px !important;
  line-height: 38px !important;
  color: #3c4043 !important;
  border: 0 !important;
  border-bottom: 1px solid #e8eaed !important;
}

.leaflet-control-attribution {
  padding: 2px 6px !important;
  background: rgba(255, 255, 255, 0.88) !important;
  font-size: 10px !important;
}

.map-search {
  position: absolute;
  z-index: 700;
  top: 16px;
  left: 18px;
  width: min(680px, calc(100vw - 36px));
  height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 10px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.round-button {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
}

.round-button:hover { background: var(--surface-soft); }

.menu-button { gap: 4px; align-content: center; }
.menu-button span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: #5f6368;
}

.line-badge {
  flex: 0 0 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--blue);
  color: white;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.search-field { flex: 1 1 auto; min-width: 0; }
.search-field input {
  width: 100%;
  height: 42px;
  padding: 0 4px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
}
.search-field input::placeholder { color: #80868b; }

.clear-button { font-size: 25px; font-weight: 300; }

.source-button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-left: 1px solid var(--line);
  color: var(--blue-dark);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}
.source-button:hover { text-decoration: underline; }

.places-panel {
  position: absolute;
  z-index: 650;
  top: 84px;
  bottom: 18px;
  left: 18px;
  width: 390px;
  overflow: hidden;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: transform 180ms ease, opacity 180ms ease;
}

.places-panel.desktop-hidden {
  pointer-events: none;
  opacity: 0;
  transform: translateX(calc(-100% - 28px));
}

.panel-handle { display: none; }

.panel-body {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 20px 14px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1,
h2,
p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-size: 25px;
  line-height: 1.12;
  letter-spacing: -0.5px;
}

.total-pill {
  flex: 0 0 auto;
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue-dark);
  font-size: 12px;
}

.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 20px 15px;
  border-bottom: 1px solid var(--line);
}

.filters label,
.dialog-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.filters select,
.dialog-field select,
.dialog-field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: 0;
  background: white;
  color: var(--ink);
}

.filters select,
.dialog-field select {
  min-height: 40px;
  padding: 0 34px 0 10px;
}

.filters select:focus,
.dialog-field select:focus,
.dialog-field textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.12);
}

.places-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.place-card {
  position: relative;
  width: 100%;
  min-height: 72px;
  display: grid;
  grid-template-columns: 38px 1fr 24px;
  align-items: center;
  gap: 11px;
  padding: 12px 16px;
  border-bottom: 1px solid #eef0f2;
  background: white;
  color: var(--ink);
  text-align: left;
}

.place-card:hover,
.place-card:focus-visible { background: #f8fafd; outline: 0; }
.place-card.active { background: var(--blue-soft); }

.card-pin {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50% 50% 50% 12%;
  transform: rotate(-45deg);
  background: var(--blue);
  color: white;
  box-shadow: 0 2px 5px rgba(26, 115, 232, 0.25);
}
.card-pin span { transform: rotate(45deg); font-size: 11px; font-weight: 800; }
.place-card[data-status="visited"] .card-pin { background: var(--green); }
.place-card[data-status="discarded"] .card-pin { background: var(--red); }

.place-copy { min-width: 0; display: grid; gap: 4px; }
.place-name {
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.place-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
}
.place-meta span + span::before { content: "·"; margin-right: 7px; color: #9aa0a6; }
.place-arrow { color: #9aa0a6; font-size: 25px; font-weight: 300; }

.empty-state {
  margin: 30px 20px;
  color: var(--muted);
  text-align: center;
}

.panel-footer {
  flex: 0 0 auto;
  padding: 10px 16px 12px;
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}
.panel-footer > p:first-child { margin: 0 0 7px; color: var(--muted); font-size: 10px; }
.panel-footer > div { display: flex; gap: 8px; }
.text-button {
  position: relative;
  padding: 0;
  background: transparent;
  color: var(--blue-dark);
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
}
.text-button:hover { text-decoration: underline; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.data-message { min-height: 13px; margin: 5px 0 0; color: var(--green); font-size: 10px; }

.map-actions {
  position: absolute;
  z-index: 620;
  right: 18px;
  bottom: 36px;
  display: grid;
  gap: 9px;
}

.floating-button {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 13px;
  border-radius: 10px;
  background: white;
  color: #3c4043;
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 700;
}
.floating-button:hover { background: var(--surface-soft); }
.floating-button > span:first-child { color: var(--blue); font-size: 20px; }

.route-card {
  position: absolute;
  z-index: 610;
  top: 84px;
  right: 18px;
  width: 220px;
  padding: 13px 14px 11px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}
.route-card-title { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; font-size: 13px; font-weight: 800; }
.route-number { display: grid; place-items: center; width: 27px; height: 27px; border-radius: 7px; background: var(--blue); color: white; }
.route-card label { min-height: 30px; display: flex; align-items: center; gap: 8px; color: #3c4043; font-size: 11px; cursor: pointer; }
.route-card input { accent-color: var(--blue); }
.route-swatch { width: 23px; height: 4px; border-radius: 4px; }
.route-swatch.outbound { background: var(--blue); }
.route-swatch.return { background: repeating-linear-gradient(90deg, var(--purple) 0 6px, transparent 6px 9px); }
.route-card p { margin: 7px 0 0; color: #80868b; font-size: 9px; line-height: 1.35; }

.toast {
  position: absolute;
  z-index: 800;
  left: 50%;
  bottom: 26px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 9px;
  transform: translateX(-50%);
  background: rgba(32, 33, 36, 0.94);
  color: white;
  box-shadow: var(--shadow);
  font-size: 12px;
}

.marker-pin {
  position: relative;
  width: 34px;
  height: 40px;
  filter: drop-shadow(0 2px 3px rgba(32, 33, 36, 0.32));
}
.marker-pin::before {
  content: "";
  position: absolute;
  inset: 0 0 6px;
  border: 3px solid white;
  border-radius: 50% 50% 50% 10px;
  transform: rotate(-45deg);
  background: var(--blue);
}
.marker-pin span {
  position: absolute;
  inset: 0 0 6px;
  display: grid;
  place-items: center;
  color: white;
  font-size: 11px;
  font-weight: 800;
}
.marker-pin.visited::before { background: var(--green); }
.marker-pin.discarded::before { background: var(--red); }
.marker-pin.active { transform: scale(1.18); transform-origin: center bottom; z-index: 3; }
.marker-pin.active::before { box-shadow: 0 0 0 4px rgba(26, 115, 232, 0.25); }
.user-marker { width: 22px; height: 22px; border: 4px solid white; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.28), 0 2px 8px rgba(0,0,0,0.28); }

.place-tooltip {
  border: 0 !important;
  border-radius: 7px !important;
  box-shadow: var(--shadow) !important;
  color: var(--ink) !important;
  font-size: 11px !important;
  font-weight: 700 !important;
}
.place-tooltip::before { display: none; }

.place-dialog {
  width: min(500px, calc(100% - 28px));
  max-height: min(84dvh, 700px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  color: var(--ink);
  box-shadow: 0 18px 60px rgba(32, 33, 36, 0.32);
}
.place-dialog::backdrop { background: rgba(32, 33, 36, 0.36); }
.place-dialog form { display: grid; gap: 15px; padding: 22px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dialog-heading h2 { margin: 0 0 5px; font-size: 23px; line-height: 1.2; }
.dialog-address { margin: 0; color: var(--muted); font-size: 12px; }
.dialog-close { width: 40px; height: 40px; flex: 0 0 40px; border-radius: 50%; background: var(--surface-soft); color: var(--muted); font-size: 25px; }
.dialog-field textarea { min-height: 120px; padding: 11px; resize: vertical; line-height: 1.45; }
.dialog-updated { min-height: 16px; margin: -4px 0 0; color: var(--muted); font-size: 10px; }
.dialog-links { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.secondary-action,
.primary-action { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; padding: 0 14px; border-radius: 9px; font-size: 13px; font-weight: 700; text-decoration: none; }
.secondary-action { border: 1px solid var(--line); color: var(--blue-dark); background: white; }
.primary-action { background: var(--blue); color: white; }
.primary-action:hover { background: var(--blue-dark); }

@media (max-width: 820px) {
  .map-search {
    top: max(10px, env(safe-area-inset-top));
    left: 10px;
    width: calc(100vw - 20px);
    height: 54px;
    border-radius: 14px;
  }
  .source-button { width: 40px; padding: 0; overflow: hidden; color: transparent; border-left: 1px solid var(--line); }
  .source-button::after { content: "↗"; display: grid; place-items: center; width: 40px; color: var(--blue-dark); font-size: 18px; }

  .places-panel {
    top: auto;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 8px;
    width: auto;
    height: min(52dvh, 520px);
    border-radius: 18px;
    transition: height 180ms ease;
  }
  .places-panel.desktop-hidden { pointer-events: auto; opacity: 1; transform: none; }
  .places-panel.mobile-collapsed { height: 64px; }
  .places-panel.mobile-collapsed .panel-body { display: none; }
  .places-panel.mobile-collapsed .handle-chevron { transform: rotate(180deg); }
  .panel-handle {
    width: 100%;
    height: 64px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 7px 18px 8px;
    background: white;
    color: var(--ink);
    font-size: 12px;
    font-weight: 700;
  }
  .handle-line { position: absolute; top: 7px; left: 50%; width: 38px; height: 4px; border-radius: 4px; transform: translateX(-50%); background: #dadce0; }
  .handle-chevron { justify-self: end; color: #80868b; font-size: 17px; transition: transform 180ms ease; }
  .panel-body { height: calc(100% - 64px); }
  .panel-heading { padding: 12px 16px 10px; }
  .panel-heading .eyebrow { display: none; }
  h1 { font-size: 20px; }
  .filters { padding: 0 16px 11px; }
  .place-card { min-height: 66px; padding: 10px 14px; }
  .panel-footer { display: none; }

  .route-card {
    top: 75px;
    right: 10px;
    width: 178px;
    padding: 10px 11px 8px;
  }
  .route-card-title { margin-bottom: 4px; }
  .route-card label { min-height: 27px; font-size: 10px; }
  .route-card p { display: none; }
  .route-number { width: 24px; height: 24px; }

  .map-actions { right: 10px; bottom: 82px; }
  .floating-button { width: 44px; min-height: 44px; justify-content: center; padding: 0; border-radius: 50%; }
  .floating-button > span:last-child { display: none; }

  .leaflet-bottom.leaflet-right { bottom: 72px; }
  .leaflet-control-attribution { max-width: 64vw; white-space: normal; line-height: 1.2; }
  .toast { bottom: 82px; }

  .place-dialog {
    width: 100%;
    max-width: none;
    max-height: 86dvh;
    margin: auto 0 0;
    border-radius: 20px 20px 0 0;
  }
  .place-dialog form { max-height: 86dvh; overflow-y: auto; padding: 20px 16px max(20px, env(safe-area-inset-bottom)); }
}

@media (max-width: 430px) {
  .line-badge { display: none; }
  .map-search { gap: 4px; padding-right: 4px; }
  .search-field input { font-size: 15px; }
  .route-card { width: 166px; }
  .filters { grid-template-columns: 1fr 1fr; gap: 7px; }
  .dialog-links { grid-template-columns: 1fr; }
}

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