:root {
    --accent: #0F766E;
    --accent-strong: #115E59;
    --accent-soft: #CCFBF1;
    --ink: #0F172A;
    --muted: #475569;
    --line: #E2E8F0;
    --bg: #F1F5F9;
    --card: #FFFFFF;
    --danger: #B91C1C;
    --danger-soft: #FEE2E2;
    --ok: #166534;
    --ok-soft: #DCFCE7;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .08);
    --header-h: 64px;
    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 12px); }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
a:hover { color: var(--accent-strong); }

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }

.container { width: 100%; max-width: 1320px; margin: 0 auto; padding: 0 20px; }

.skip-link {
    position: absolute; left: 12px; top: -48px; z-index: 100;
    background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 8px;
}
.skip-link:focus { top: 12px; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Header */
.site-header {
    position: sticky; top: 0; z-index: 50;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; gap: 16px; min-height: var(--header-h); }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 1.1rem; }
.brand-mark {
    display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
    background: var(--accent); color: #fff;
}
.brand-tagline { color: var(--muted); font-size: .9rem; }
.site-nav { margin-left: auto; display: flex; align-items: center; gap: 18px; }
.site-nav a:not(.btn) { color: var(--muted); text-decoration: none; font-weight: 500; }
.site-nav a:not(.btn):hover { color: var(--ink); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 46px; padding: 0 18px; border-radius: 10px; border: 1px solid transparent;
    font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background-color .15s, border-color .15s, color .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); color: #fff; }
.btn-ghost { background: var(--card); color: var(--accent-strong); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--accent); background: var(--accent-soft); }
.btn-small { min-height: 38px; padding: 0 14px; font-size: .9rem; }
.btn[disabled] { opacity: .6; cursor: progress; }

/* Search */
.search { padding-top: 28px; padding-bottom: 20px; }
.search-intro h1 { font-size: clamp(1.7rem, 3vw, 2.3rem); letter-spacing: -.02em; }
.search-intro p { color: var(--muted); max-width: 720px; margin: 0 0 18px; }

.search-card {
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 20px; display: grid; gap: 18px;
}
.field { border: 0; margin: 0; padding: 0; min-width: 0; }
.field-label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 8px; padding: 0; }
.input-row { display: flex; gap: 10px; }
.input-row input { flex: 1; min-width: 0; }

input[type="search"], select {
    font: inherit; color: var(--ink); background: #fff;
    min-height: 46px; padding: 0 14px; border: 1px solid #CBD5E1; border-radius: 10px;
}
input[type="search"]:focus, select:focus { border-color: var(--accent); outline: 3px solid var(--accent-soft); outline-offset: 0; }

.field-inline { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.field-inline .field-label { margin: 0; }
.field-hint { color: var(--muted); font-size: .85rem; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip > span {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
    background: #fff; font-size: .92rem; font-weight: 500; color: var(--ink);
    transition: background-color .15s, border-color .15s;
}
.chip:hover > span { border-color: var(--accent); }
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.chip-icon { font-size: 1rem; line-height: 1; }

.search-card.is-busy #submit-btn { opacity: .7; }

/* Workspace */
.workspace {
    display: grid; grid-template-columns: minmax(320px, 410px) 1fr; gap: 16px;
    height: clamp(520px, calc(100vh - var(--header-h) - 40px), 920px);
    padding-bottom: 32px;
}

.results {
    display: flex; flex-direction: column; min-height: 0;
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.results-header { padding: 16px 18px 12px; border-bottom: 1px solid var(--line); }
.results-header h2 { font-size: 1.05rem; margin: 0 0 6px; }
.results-scroll { position: relative; flex: 1; overflow-y: auto; min-height: 0; }
.results-placeholder { padding: 18px; color: var(--muted); font-size: .95rem; }
.results-placeholder p { margin: 0 0 8px; }
.results-placeholder strong { color: var(--ink); }

.status { margin: 0; font-size: .9rem; color: var(--muted); min-height: 1.35em; }
.status:empty { display: none; }
.status-error { color: var(--danger); background: var(--danger-soft); padding: 8px 10px; border-radius: 8px; }
.status-ok { color: var(--ok); }
.status-loading { display: flex; align-items: center; gap: 8px; color: var(--accent-strong); }
.status-loading::before {
    content: ""; width: 14px; height: 14px; border-radius: 50%; flex: none;
    border: 2px solid var(--accent-soft); border-top-color: var(--accent);
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.results-list { list-style: none; margin: 0; padding: 0; }
.result { border-bottom: 1px solid var(--line); }
.result.is-active { background: var(--accent-soft); }
.result-head {
    display: flex; align-items: flex-start; gap: 12px; width: 100%;
    padding: 14px 18px 8px; background: none; border: 0; text-align: left;
    font: inherit; color: inherit; cursor: pointer;
}
.result-num {
    flex: none; display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
    background: var(--accent); color: #fff; font-size: .8rem; font-weight: 700;
}
.result-title { flex: 1; min-width: 0; }
.result-title strong { display: block; font-size: .98rem; overflow-wrap: anywhere; }
.result-title small { display: block; color: var(--muted); font-size: .85rem; }
.result-dist { flex: none; text-align: right; font-weight: 700; font-size: .95rem; color: var(--accent-strong); }
.result-dist small { display: block; font-weight: 500; color: var(--muted); font-size: .78rem; }
.result-details { list-style: none; margin: 0; padding: 0 18px 0 56px; font-size: .86rem; color: var(--muted); }
.result-details li { margin-bottom: 2px; overflow-wrap: anywhere; }
.result-details b { color: var(--ink); font-weight: 600; }
.result-links { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 6px 18px 14px 56px; font-size: .86rem; font-weight: 600; }
.result-links a { text-decoration: none; }
.result-links a:hover { text-decoration: underline; }

.results-empty { padding: 18px; color: var(--muted); }
.results-empty p { margin: 0 0 12px; }

/* Map */
.map-wrap { min-height: 0; }
.map {
    position: relative; width: 100%; height: 100%; overflow: hidden;
    background: #E8E6E1; border-radius: var(--radius); box-shadow: var(--shadow);
    touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab;
    scroll-margin-top: calc(var(--header-h) + 8px);
}
.map.is-dragging { cursor: grabbing; }
.map:focus-visible { outline-offset: -3px; }
.map-pane { position: absolute; left: 0; top: 0; width: 0; height: 0; }
.map-tiles { z-index: 1; }
.map-overlays { z-index: 2; pointer-events: none; }
.map-markers { z-index: 3; }
.map-tile {
    position: absolute; left: 0; top: 0; width: 256px; height: 256px; max-width: none;
    opacity: 0; transition: opacity .2s; pointer-events: none;
}
.map-tile.is-loaded { opacity: 1; }

.map-circle {
    position: absolute; left: 0; top: 0; border-radius: 50%;
    border: 2px solid var(--accent); background: rgba(15, 118, 110, .07);
}

.map-marker {
    position: absolute; left: 0; top: 0; padding: 0; border: 0; background: none; cursor: pointer;
}
.marker-pin {
    position: absolute; left: -14px; top: -38px; width: 28px; height: 28px; border-radius: 50%;
    display: grid; place-items: center; background: var(--accent); color: #fff;
    font: 700 .75rem/1 var(--font); border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
    transition: transform .15s;
}
.marker-pin::after {
    content: ""; position: absolute; left: 50%; bottom: -9px; transform: translateX(-50%);
    border: 6px solid transparent; border-top: 6px solid #fff;
}
.map-marker:hover .marker-pin, .map-marker.is-active .marker-pin { transform: scale(1.18); background: #0B4F4A; }
.map-marker.is-active { z-index: 2; }
.map-marker:focus-visible { outline: none; }
.map-marker:focus-visible .marker-pin { outline: 3px solid var(--ink); }

.map-origin { pointer-events: none; z-index: 1; }
.origin-dot {
    position: absolute; left: -9px; top: -9px; width: 18px; height: 18px; border-radius: 50%;
    background: #DC2626; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
.origin-dot::after {
    content: ""; position: absolute; inset: -9px; border-radius: 50%;
    border: 2px solid rgba(220, 38, 38, .5); animation: pulse 2s ease-out infinite;
}
@keyframes pulse { from { transform: scale(.5); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }

.map-popup {
    position: absolute; left: 0; top: 0; z-index: 4; width: max-content; max-width: 250px;
    background: #fff; border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .22);
    padding: 12px 34px 12px 14px; font-size: .88rem; cursor: default;
}
.map-popup::after {
    content: ""; position: absolute; left: 50%; bottom: -8px; transform: translateX(-50%);
    border: 8px solid transparent; border-bottom: 0; border-top-color: #fff;
}
.map-popup strong { display: block; font-size: .95rem; margin-bottom: 2px; }
.map-popup span { display: block; color: var(--muted); margin-bottom: 6px; }
.map-popup a { font-weight: 600; text-decoration: none; }
.popup-close {
    position: absolute; right: 4px; top: 4px; width: 28px; height: 28px; border: 0; background: none;
    font-size: 1.2rem; line-height: 1; color: var(--muted); cursor: pointer; border-radius: 6px;
}
.popup-close:hover { background: var(--bg); color: var(--ink); }

.map-controls { position: absolute; right: 12px; top: 12px; z-index: 5; display: flex; flex-direction: column; box-shadow: var(--shadow); border-radius: 10px; overflow: hidden; }
.map-controls button {
    width: 40px; height: 40px; border: 0; background: #fff; color: var(--ink);
    font: 600 1.3rem/1 var(--font); cursor: pointer;
}
.map-controls button + button { border-top: 1px solid var(--line); }
.map-controls button:hover { background: var(--accent-soft); }

.map-attrib {
    position: absolute; right: 0; bottom: 0; z-index: 5;
    background: rgba(255, 255, 255, .85); padding: 2px 8px; font-size: .72rem; border-top-left-radius: 8px;
}
.map-attrib a { color: var(--ink); }

/* How it works */
.how { padding-top: 24px; padding-bottom: 48px; }
.how h2 { font-size: 1.5rem; }
.how-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 16px; }
.how-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.how-card h3 { font-size: 1.05rem; margin-top: 12px; }
.how-card p { margin: 0; color: var(--muted); font-size: .95rem; }
.how-num {
    display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
    background: var(--accent-soft); color: var(--accent-strong); font-weight: 700;
}
.how-note { margin: 20px 0 0; color: var(--muted); font-size: .9rem; max-width: 900px; }

/* Footer */
.site-footer { background: var(--ink); color: #CBD5E1; padding: 28px 0; font-size: .88rem; }
.site-footer a { color: #fff; }
.footer-inner p { margin: 0 0 6px; }
.footer-links { display: flex; gap: 18px; margin-top: 10px; }

/* Responsive */
@media (max-width: 980px) {
    .brand-tagline { display: none; }
}

@media (max-width: 899px) {
    .workspace { grid-template-columns: 1fr; height: auto; }
    .map-wrap { order: -1; height: 58vh; min-height: 320px; }
    .results-scroll { overflow: visible; }
    .how-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .container { padding: 0 14px; }
    .site-nav a:not(.btn) { display: none; }
    .search-card { padding: 16px; }
    .input-row { flex-wrap: wrap; }
    .input-row input { flex-basis: 100%; }
    .input-row .btn { flex: 1; }
    .chip > span { padding: 7px 12px; font-size: .88rem; }
    .result-details, .result-links { padding-left: 18px; }
}

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