:root {
  color-scheme: dark;
  --ink: #f8fafc;
  --muted: #94a3b8;
  --panel: rgba(11, 18, 32, 0.96);
  --panel-soft: #172033;
  --line: #334155;
  --accent: #4ade80;
  --accent-ink: #07140d;
  --cyan: #22d3ee;
  --danger: #fb7185;
  --drawer-height: 360px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html,
body,
.app-shell,
#map {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body { background: #0f172a; color: var(--ink); }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.48; }

:focus-visible {
  outline: 3px solid #f8fafc;
  outline-offset: 2px;
}

.app-shell { position: relative; }
.app-shell { height: 100dvh; }
#map { z-index: 0; background: #dce4e7; }

.map-header {
  position: absolute;
  z-index: 700;
  top: 16px;
  left: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 12px 8px 8px;
  border: 1px solid rgba(148, 163, 184, 0.32);
  border-radius: 12px;
  background: rgba(10, 16, 29, 0.92);
  box-shadow: 0 12px 34px rgba(2, 6, 23, 0.28);
  backdrop-filter: blur(12px);
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: -0.03em;
}

.map-header h1 { margin: 0; font-size: 14px; line-height: 1.1; }
.map-header p { margin: 3px 0 0; color: var(--muted); font: 10px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase; letter-spacing: 0.08em; }
.connection-dot { width: 8px; height: 8px; margin-left: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px rgba(74, 222, 128, 0.75); }

.lookup-panel {
  position: absolute;
  z-index: 700;
  top: 78px;
  left: 56px;
  width: min(390px, calc(100vw - 72px));
  padding: 10px;
  border: 1px solid rgba(148, 163, 184, 0.32);
  border-radius: 12px;
  background: rgba(10, 16, 29, 0.94);
  box-shadow: 0 12px 34px rgba(2, 6, 23, 0.28);
  backdrop-filter: blur(12px);
}
.lookup-form label { display: block; margin: 0 0 6px 2px; color: #e2e8f0; font-size: 11px; font-weight: 750; }
.osm-way-form, .edge-form { margin-top: 9px; padding-top: 9px; border-top: 1px solid rgba(100, 116, 139, 0.42); }
.location-entry { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.location-entry input { min-width: 0; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: #0f172a; color: var(--ink); font: 12px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }
.location-entry input::placeholder { color: #64748b; }
.location-entry input[aria-invalid="true"] { border-color: var(--danger); }
.location-help, .location-error { display: block; min-height: 14px; margin: 6px 2px 0; font-size: 10px; line-height: 1.35; }
.location-help { color: var(--muted); }
.location-error:empty { display: none; }
.location-error { color: #fda4af; }

.map-hint {
  position: absolute;
  z-index: 650;
  top: 18px;
  left: 50%;
  translate: -50% 0;
  padding: 9px 13px;
  border: 1px solid rgba(15, 23, 42, 0.2);
  border-radius: 999px;
  background: rgba(248, 250, 252, 0.92);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
  color: #0f172a;
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
}

.drawer {
  position: absolute;
  z-index: 800;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  max-width: 1180px;
  height: min(42vh, 410px);
  min-height: 128px;
  margin-inline: auto;
  overflow: hidden;
  border: 1px solid rgba(100, 116, 139, 0.48);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 22px 70px rgba(2, 6, 23, 0.44);
  backdrop-filter: blur(18px);
  transition: height 180ms ease;
}

.drawer[data-state="expanded"] { height: min(78vh, 760px); }
.drawer[data-state="collapsed"] { height: 82px; min-height: 82px; }
.drawer[data-state="collapsed"] .drawer-body { visibility: hidden; }
.drawer[data-state="collapsed"] #drawer-toggle svg { rotate: 180deg; }

.drawer-grab { width: 42px; height: 4px; margin: 7px auto 2px; border-radius: 999px; background: #64748b; }
.drawer-toolbar { display: flex; min-height: 62px; align-items: center; justify-content: space-between; gap: 16px; padding: 6px 16px 10px; border-bottom: 1px solid var(--line); }
.status-group, .toolbar-actions { display: flex; align-items: center; gap: 10px; }
.status-indicator { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: #64748b; }
.status-indicator[data-kind="loading"] { background: #fbbf24; box-shadow: 0 0 9px rgba(251, 191, 36, 0.8); }
.status-indicator[data-kind="success"] { background: var(--accent); box-shadow: 0 0 9px rgba(74, 222, 128, 0.7); }
.status-indicator[data-kind="error"] { background: var(--danger); box-shadow: 0 0 9px rgba(251, 113, 133, 0.7); }
.status { margin: 0; font-size: 13px; font-weight: 750; }
.coordinate { margin: 3px 0 0; color: var(--muted); font: 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }
.button, .icon-button { min-height: 44px; border: 1px solid var(--line); border-radius: 9px; }
.button { padding: 0 14px; font-size: 12px; font-weight: 800; }
.button-primary { border-color: #22c55e; background: var(--accent); color: var(--accent-ink); }
.button-primary:hover:not(:disabled) { background: #86efac; }
.icon-button { display: grid; width: 44px; place-items: center; background: #1e293b; color: var(--ink); }
.icon-button:hover { background: #334155; }
.icon-button svg { width: 19px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; transition: rotate 180ms ease; }

.drawer-body { height: calc(100% - 75px); overflow: auto; padding: 12px 16px 22px; scrollbar-color: #475569 transparent; }
.query-controls { display: grid; grid-template-columns: max-content 82px max-content 96px max-content 96px; gap: 8px 10px; align-items: center; }
.query-controls label { color: #cbd5e1; font-size: 11px; font-weight: 650; }
.query-controls label span { color: #64748b; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.query-controls input { width: 100%; min-height: 44px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: #0f172a; color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.query-controls input:invalid { border-color: var(--danger); }

.summary { display: grid; grid-template-columns: repeat(5, minmax(90px, 1fr)); gap: 8px; margin-top: 12px; }
.summary div { min-width: 0; padding: 9px 10px; border: 1px solid #263349; border-radius: 9px; background: var(--panel-soft); }
.summary span { display: block; color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.summary strong { display: block; overflow: hidden; margin-top: 3px; font: 700 15px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; margin: 14px 1px 7px; }
.section-heading h2 { margin: 0; font-size: 12px; }
.section-heading span { color: var(--muted); font-size: 10px; }

.candidate-rail { display: flex; gap: 8px; min-height: 72px; overflow-x: auto; padding: 1px 1px 8px; scrollbar-color: #475569 transparent; }
.candidate-card { position: relative; display: grid; flex: 0 0 210px; grid-template-columns: 5px 1fr; gap: 10px; min-height: 64px; padding: 9px 10px; border: 1px solid #334155; border-radius: 10px; background: #111b2c; color: var(--ink); text-align: left; }
.candidate-card:hover { border-color: #64748b; background: #18243a; }
.candidate-card[aria-pressed="true"] { border-color: var(--candidate-color); box-shadow: inset 0 0 0 1px var(--candidate-color); }
.candidate-swatch { width: 5px; height: 100%; border-radius: 999px; background: var(--candidate-color); }
.candidate-main { min-width: 0; }
.candidate-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.direction-badge { padding: 3px 6px; border-radius: 5px; background: #263349; color: #e2e8f0; font: 800 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.06em; }
.distance { color: var(--candidate-color); font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.candidate-osm { display: block; overflow: hidden; margin-top: 8px; font: 650 11px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }
.candidate-edge-id { display: block; margin-top: 4px; color: var(--muted); font: 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.empty-message { margin: auto 0; color: var(--muted); font-size: 12px; }

.tabs { display: flex; gap: 6px; margin-top: 8px; border-bottom: 1px solid var(--line); }
.tab { min-height: 44px; padding: 0 10px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-size: 11px; font-weight: 750; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--ink); }
.tabpanel { padding-top: 10px; }
.selected-edge { color: #cbd5e1; font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.datapoint-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; margin-top: 8px; }
.datapoint-item { display: flex; min-height: 54px; align-items: center; gap: 10px; padding: 7px 9px; border: 1px solid #2b384e; border-radius: 9px; background: #111b2c; color: var(--ink); text-align: left; }
.datapoint-item:hover { border-color: #64748b; }
.datapoint-item img { width: 34px; height: 34px; flex: 0 0 auto; object-fit: contain; }
.datapoint-item strong, .datapoint-item span { display: block; }
.datapoint-item strong { font-size: 11px; }
.datapoint-item span { margin-top: 3px; color: var(--muted); font: 9px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; }
#raw-json { min-height: 130px; margin: 0; overflow: auto; padding: 12px; border-radius: 9px; background: #070c16; color: #cbd5e1; font: 10px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-word; }

.leaflet-control-zoom { margin-top: 88px !important; }
.leaflet-bottom { bottom: var(--drawer-height); transition: bottom 180ms ease; }
.leaflet-control-attribution { background: rgba(255, 255, 255, 0.9) !important; color: #334155; }
.leaflet-control-attribution a { color: #075985; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: #0f172a; color: var(--ink); }
.leaflet-popup-content-wrapper { border: 1px solid #475569; border-radius: 10px; box-shadow: 0 12px 34px rgba(2, 6, 23, 0.35); }
.leaflet-popup-content { margin: 12px 14px; min-width: 180px; font-size: 12px; }
.leaflet-popup-close-button { width: 32px !important; height: 32px !important; color: #cbd5e1 !important; font-size: 22px !important; }
.leaflet-tooltip { border: 1px solid #475569; background: #0f172a; color: var(--ink); box-shadow: 0 6px 18px rgba(2, 6, 23, 0.25); font: 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }
.popup-title { margin: 0 24px 8px 0; font-size: 13px; }
.popup-row { display: grid; grid-template-columns: 76px 1fr; gap: 8px; margin-top: 5px; }
.popup-row span:first-child { color: var(--muted); }
.popup-row span:last-child { overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.query-dot { border: 3px solid #fff; border-radius: 50%; background: #f43f5e; box-shadow: 0 0 0 3px rgba(244, 63, 94, 0.32); }
.direction-arrow-layer { pointer-events: none; }

@media (max-width: 760px) {
  .map-header { top: 10px; left: 50px; }
  .map-header p, .connection-dot { display: none; }
  .map-hint { top: 68px; max-width: calc(100vw - 28px); white-space: nowrap; }
  .lookup-panel { top: 108px; left: 12px; width: calc(100vw - 24px); }
  .drawer { right: 0; bottom: 0; left: 0; width: 100%; height: 48vh; max-width: none; border-right: 0; border-bottom: 0; border-left: 0; border-radius: 15px 15px 0 0; }
  .drawer[data-state="expanded"] { height: 82vh; }
  .drawer-toolbar { padding-inline: 12px; }
  .drawer-body { padding-inline: 12px; }
  .query-controls { grid-template-columns: 1fr 84px; }
  .query-controls label { font-size: 10px; }
  .summary { grid-template-columns: repeat(3, 1fr); }
  .summary div:last-child { grid-column: span 2; }
  .candidate-card { flex-basis: 190px; }
}

@media (max-width: 420px) {
  .map-header h1 { font-size: 12px; }
  .brand-mark { width: 30px; height: 30px; }
  .button { padding-inline: 10px; }
  .coordinate { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .location-entry { grid-template-columns: minmax(0, 1fr) 52px; }
}

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