:root {
  --brand: #c84f41;
  --brand-dark: #9f372d;
  --ink: #20242b;
  --muted: #69717d;
  --line: #e4e7eb;
  --panel: #ffffff;
  --soft: #f5f6f7;
  --spectator: #558b2f;
  --track: #f57c00;
  --marshal: #9c27b0;
  --shadow: 0 8px 28px rgba(25, 32, 43, 0.18);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --visual-top-offset: 0px;
  --ios-browser-inset: 0px;
}

html.is-ios-browser { --ios-browser-inset: 48px; }

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: #dce2e5;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input { font: inherit; }

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

button { color: inherit; }

.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;
}

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

@supports (height: 100dvh) {
  html,
  body,
  .app-shell { height: 100dvh; }
}

.sidebar {
  position: relative;
  z-index: 500;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  background: var(--panel);
  box-shadow: 3px 0 18px rgba(20, 26, 34, 0.18);
}

.brand-bar {
  display: flex;
  align-items: center;
  min-height: 92px;
  padding: 18px 22px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), #d65b49);
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  margin-right: 13px;
  border: 2px solid rgba(255, 255, 255, 0.38);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  font-size: 1.15rem;
  font-weight: 800;
}

.brand-copy { min-width: 0; }

.brand-copy h1 {
  margin: 0;
  overflow: hidden;
  font-size: 1.15rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-copy p {
  margin: 5px 0 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.875rem;
}

.search-zone {
  position: relative;
  z-index: 10;
  padding: 20px 20px 12px;
}

.search-box {
  display: flex;
  align-items: center;
  height: 52px;
  border: 1px solid #cfd5dc;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 3px 12px rgba(28, 38, 48, 0.08);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.search-box:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(200, 79, 65, 0.14);
}

.search-box > svg {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  margin-left: 15px;
  fill: none;
  stroke: #5c6570;
  stroke-linecap: round;
  stroke-width: 2;
}

.search-box input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 10px;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-size: 1rem;
}

.search-box input::placeholder { color: #828a94; }
.search-box input::-webkit-search-cancel-button { display: none; }

.clear-search,
.close-selection {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.clear-search { margin-right: 5px; }
.clear-search:hover,
.close-selection:hover { background: var(--soft); }

.clear-search svg,
.close-selection svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: #59616b;
  stroke-linecap: round;
  stroke-width: 2;
}

.search-results {
  position: absolute;
  top: 78px;
  left: 20px;
  right: 20px;
  max-height: min(430px, calc(100vh - 190px));
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow);
}

.result-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  width: 100%;
  min-height: 58px;
  padding: 8px 12px;
  border: 0;
  border-bottom: 1px solid #edf0f2;
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.result-item:last-child { border-bottom: 0; }
.result-item:hover,
.result-item:focus-visible,
.result-item.is-focused { outline: 0; background: #f7f8f9; }

.result-pin {
  position: relative;
  width: 20px;
  height: 20px;
  border-radius: 50% 50% 50% 0;
  background: var(--result-color, var(--brand));
  transform: rotate(-45deg);
}

.result-pin::after {
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: #fff;
  content: "";
}

.result-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.result-text strong {
  overflow: hidden;
  font-size: 0.94rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-text small {
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-distance {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.empty-results {
  margin: 0;
  padding: 18px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.filter-section { padding: 10px 20px 0; }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.section-heading h2 {
  margin: 0;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.text-button {
  padding: 8px 0;
  border: 0;
  color: var(--brand-dark);
  background: transparent;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.filter-list { border-top: 1px solid var(--line); }

.filter-button {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 58px;
  padding: 8px 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: #777f88;
  background: transparent;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
}

.filter-button.is-active { color: var(--ink); }
.filter-button strong { color: #8a929c; font-size: 0.78rem; }

.layer-swatch {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(20, 28, 36, 0.2);
}

.layer-swatch.spectator { background: var(--spectator); }
.layer-swatch.track { background: var(--track); }
.layer-swatch.marshal { background: var(--marshal); }
.filter-button:not(.is-active) .layer-swatch { background: #b9bec4; }

.selection-card {
  position: relative;
  margin: 18px 20px 0;
  padding: 17px;
  border: 1px solid #e2e5e9;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 5px 18px rgba(22, 31, 42, 0.1);
}

.close-selection { position: absolute; top: 6px; right: 6px; }

.selection-category {
  margin: 0 40px 4px 0;
  color: var(--brand-dark);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.selection-card h2 { margin: 0 40px 12px 0; font-size: 1.35rem; }

.selection-card dl {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 0 0 15px;
}

.selection-card dl div { display: flex; gap: 5px; }
.selection-card dt,
.selection-card dd { margin: 0; font-size: 0.82rem; }
.selection-card dt { color: var(--muted); }
.selection-card dd { font-weight: 700; }

.directions-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 16px;
  border-radius: 12px;
  color: #fff;
  background: var(--brand);
  font-size: 0.92rem;
  font-weight: 800;
  text-decoration: none;
}

.directions-button:hover { background: var(--brand-dark); }
.directions-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; }

.sidebar-footer {
  margin-top: auto;
  padding: 18px 20px 20px;
  color: var(--muted);
  font-size: 0.78rem;
}

.sidebar-footer p { margin: 0 0 7px; }
.sidebar-footer a { color: var(--brand-dark); font-weight: 700; }

.map-stage { position: relative; min-width: 0; height: 100%; overflow: hidden; }
#map { width: 100%; height: 100%; background: #d9dfe2; }
.leaflet-control-attribution { font-size: 10px; }

.leaflet-tooltip.point-label {
  padding: 4px 7px;
  border: 0;
  border-radius: 6px;
  color: #23272d;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.22);
  font-size: 0.76rem;
  font-weight: 800;
}

.map-pin-wrap { background: transparent; border: 0; }

.map-pin {
  position: relative;
  display: block;
  width: 27px;
  height: 27px;
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  background: var(--pin-color, var(--brand));
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  transform: rotate(-45deg);
  transform-origin: 50% 50%;
}

.map-pin::after {
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: #fff;
  content: "";
}

.map-pin.is-selected {
  z-index: 1;
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.85), 0 5px 14px rgba(0, 0, 0, 0.45);
  transform: rotate(-45deg) scale(1.18);
}

.map-tools {
  position: absolute;
  z-index: 450;
  right: 14px;
  bottom: calc(28px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.map-tool,
.zoom-tools button {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid rgba(25, 32, 40, 0.16);
  border-radius: 13px;
  color: #39424c;
  background: #fff;
  box-shadow: 0 3px 12px rgba(22, 31, 42, 0.2);
  cursor: pointer;
}

.map-tool:hover,
.zoom-tools button:hover { background: #f5f6f7; }
.map-tool-primary { color: #fff; border-color: var(--brand); background: var(--brand); }
.map-tool-primary:hover { background: var(--brand-dark); }
.map-tool.is-loading svg { animation: spin 900ms linear infinite; }

.map-tool svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.zoom-tools {
  position: absolute;
  z-index: 450;
  top: 16px;
  right: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 12px;
  box-shadow: 0 3px 12px rgba(22, 31, 42, 0.18);
}

.zoom-tools button {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  font-size: 1.55rem;
  line-height: 1;
}

.zoom-tools button + button { border-top: 1px solid var(--line); }
.mobile-filter-rail { display: none; }

.loading-card,
.toast {
  position: absolute;
  z-index: 700;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 12px;
  color: #fff;
  background: rgba(31, 37, 44, 0.9);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  font-weight: 700;
  transform: translateX(-50%);
}

.loading-card { top: 18px; }
.toast { bottom: calc(24px + var(--safe-bottom)); text-align: center; }

.loading-spinner {
  width: 17px;
  height: 17px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.user-location {
  display: block;
  width: 18px;
  height: 18px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #1976d2;
  box-shadow: 0 0 0 4px rgba(25, 118, 210, 0.22), 0 2px 7px rgba(0, 0, 0, 0.35);
}

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

@media (max-width: 760px) {
  .app-shell { display: block; }

  .sidebar {
    position: fixed;
    z-index: 1100;
    top: calc(10px + max(var(--safe-top), var(--visual-top-offset), var(--ios-browser-inset)));
    left: 10px;
    right: 10px;
    display: block;
    width: auto;
    height: auto;
    background: transparent;
    box-shadow: none;
    pointer-events: none;
  }

  .brand-bar,
  .filter-section,
  .sidebar-footer { display: none; }

  .search-zone {
    position: relative;
    z-index: 1;
    padding: 0;
    pointer-events: auto;
  }

  .search-box {
    height: 56px;
    border: 0;
    border-radius: 16px;
    box-shadow: 0 5px 22px rgba(24, 32, 43, 0.22);
  }

  .search-box input { font-size: 1rem; }

  .search-results {
    top: 64px;
    left: 0;
    right: 0;
    max-height: min(52vh, 430px);
  }

  .selection-card {
    position: fixed;
    z-index: 750;
    right: 10px;
    bottom: calc(10px + var(--safe-bottom));
    left: 10px;
    margin: 0;
    padding: 17px 18px;
    border: 0;
    border-radius: 18px;
    box-shadow: 0 8px 30px rgba(24, 31, 39, 0.28);
    pointer-events: auto;
  }

  .selection-card h2 { font-size: 1.25rem; }
  .map-stage { width: 100%; height: 100%; }

  @supports (height: 100dvh) {
    .map-stage { height: 100dvh; }
  }

  .mobile-filter-rail {
    position: fixed;
    z-index: 1000;
    top: calc(76px + max(var(--safe-top), var(--visual-top-offset), var(--ios-browser-inset)));
    left: 0;
    right: 0;
    display: flex;
    gap: 8px;
    padding: 0 10px 10px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .mobile-filter-rail::-webkit-scrollbar { display: none; }

  .mobile-chip {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 7px;
    min-height: 40px;
    padding: 7px 13px;
    border: 1px solid rgba(35, 43, 52, 0.15);
    border-radius: 999px;
    color: #6d747d;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 3px 12px rgba(24, 32, 43, 0.15);
    font-size: 0.86rem;
    font-weight: 750;
    cursor: pointer;
  }

  .mobile-chip.is-active { color: var(--ink); border-color: rgba(35, 43, 52, 0.28); }
  .mobile-chip:not(.is-active) .layer-swatch { background: #b8bec5; }
  .zoom-tools { top: calc(130px + max(var(--safe-top), var(--visual-top-offset), var(--ios-browser-inset))); right: 10px; }
  .map-tools { right: 10px; bottom: calc(30px + var(--safe-bottom)); }
  .loading-card { top: calc(130px + max(var(--safe-top), var(--visual-top-offset), var(--ios-browser-inset))); }
  .toast { bottom: calc(26px + var(--safe-bottom)); width: max-content; max-width: calc(100% - 130px); }
  body.has-selection .map-tools { bottom: calc(210px + var(--safe-bottom)); }
  body.has-selection .toast { bottom: calc(218px + var(--safe-bottom)); }
}

@media (max-width: 390px) {
  .mobile-chip { padding-inline: 11px; font-size: 0.8rem; }
  .map-tool { width: 44px; height: 44px; }
}

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