:root {
  --bg: #0a1118; --panel: #0f1923; --raise: #14212d; --line: #1f3040;
  --text: #dce8f0; --muted: #82979f; --accent: #5eead4; --accent-ink: #052b26;
  --warn: #f2c46d; --bad: #f08a8a;
  --font: "Avenir Next", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.shell { display: grid; grid-template-columns: 76px 1fr; height: 100vh; }
.rail { background: #070d13; border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 0; }
.brand { width: 40px; height: 40px; display: grid; place-items: center; margin-bottom: 10px; border-radius: 12px; background: var(--raise); }
.brand svg { width: 22px; height: 22px; fill: var(--accent); stroke: none; }
.rail-link { width: 64px; padding: 8px 2px 6px; border-radius: 10px; color: var(--muted); text-decoration: none; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; text-align: center; line-height: 1.15; }
.rail-link svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.rail-link:hover { color: var(--text); background: var(--panel); }
.rail-link.active { color: var(--accent); background: var(--raise); box-shadow: inset 3px 0 0 var(--accent); }

.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 22px; border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar h1 { font-size: 17px; font-weight: 600; letter-spacing: .01em; }
.live { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--accent); box-shadow: 0 0 0 3px rgba(94, 234, 212, .15); }
.dot.pulse { animation: pulse 1.2s ease-out; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(94,234,212,.7); } 100% { box-shadow: 0 0 0 10px rgba(94,234,212,0); } }

button { cursor: pointer; }
.ghost, .solid { border-radius: 8px; padding: 6px 12px; border: 1px solid var(--line); background: transparent; font-size: 12.5px; }
.ghost:hover { border-color: var(--accent); color: var(--accent); }
.solid { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.solid:hover { filter: brightness(1.08); }
.eyebrow { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin-top: 6px; }
.empty { color: var(--muted); padding: 18px 4px; }

/* map page */
.mapview { flex: 1; min-height: 0; display: grid; grid-template-columns: 420px 1fr; }
.panel { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 12px; }
.where { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.where strong { display: block; font-size: 15px; }
.where small { color: var(--muted); font-size: 11.5px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tab { background: none; border: 0; padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 9px; padding: 0 6px; font-size: 11px; font-weight: 700; margin-left: 4px; }
.filters { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--muted); flex: 1 1 100%; }
select, input[type=text], input:not([type]) { background: var(--raise); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; color: var(--text); }
select option { background: var(--raise); }
.chip-check input { position: absolute; opacity: 0; }
.chip-check span { display: inline-block; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--raise); color: var(--muted); font-size: 12.5px; cursor: pointer; user-select: none; }
.chip-check input:checked + span { background: rgba(94,234,212,.12); border-color: var(--accent); color: var(--accent); }
.chip-check input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.areas-head, .result-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.areas-head > div { display: flex; gap: 6px; }
.hint .solid, .hint .ghost { margin-left: 6px; padding: 3px 9px; }
.area-list { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.area-list li { display: flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px; border-radius: 999px; background: rgba(125,183,255,.1); border: 1px solid rgba(125,183,255,.4); font-size: 12px; }
.area-list button { background: none; border: 0; color: var(--muted); padding: 0 6px; font-size: 14px; }
.area-list button:hover { color: var(--bad); }
.result-head { margin-top: 4px; }
.result-head small { color: var(--muted); }
.cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.card { background: var(--raise); border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
.card:hover, .card.hot { border-color: var(--accent); }
.card h3 { font-size: 14.5px; font-weight: 600; }
.card .dist { text-align: right; font-weight: 600; color: var(--accent); white-space: nowrap; }
.card .dist small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; }
.card .place, .card .meta { color: var(--muted); font-size: 12.5px; grid-column: 1 / -1; }
.card .tags { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.tag { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: rgba(94,234,212,.1); color: var(--accent); }
.tag.dog { background: rgba(125,183,255,.12); color: #8ec0ff; }
.rating { color: var(--warn); font-weight: 600; }
.saved, .matches { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.saved li, .matches li { background: var(--raise); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 4px; }
.saved .row, .matches .row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.saved .row div { display: flex; gap: 6px; }
.saved small, .matches small { color: var(--muted); font-size: 12px; }
.paused { color: var(--warn); }
.matches li { border-color: rgba(94,234,212,.5); }
.save-form { display: grid; gap: 8px; }

.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: #0b141c; }
#map.drawing { cursor: crosshair; }
.leaflet-container { background: #0b141c; font-family: var(--font); }
.leaflet-tile-pane { filter: saturate(.55) brightness(1.02); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); border: 1px solid var(--line); }
.leaflet-popup-content { margin: 10px 12px; }
.leaflet-control-attribution { background: rgba(7,13,19,.75) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-bar a { background: var(--panel); color: var(--text); border-color: var(--line); }
.me { width: 18px; height: 18px; border-radius: 50%; background: #8ec0ff; border: 3px solid #0a1118; box-shadow: 0 0 0 2px #8ec0ff, 0 0 14px #8ec0ff; }
.pin { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: 2px solid #0a1118; box-shadow: 0 0 10px rgba(94,234,212,.7); }
.pin.hot { transform: scale(1.5); background: #fff; }
.cell { display: grid; place-items: center; border-radius: 50%; background: rgba(94,234,212,.22); border: 1.5px solid var(--accent); color: #fff; font-weight: 700; box-shadow: 0 0 18px rgba(94,234,212,.35); }
.vertex { width: 10px; height: 10px; border-radius: 50%; background: #8ec0ff; border: 2px solid #0a1118; }
.map-note { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 500; background: rgba(10,17,24,.92); border: 1px solid var(--line); padding: 7px 14px; border-radius: 999px; font-size: 12.5px; }

/* statistic pages */
.stats { padding: 20px 22px 40px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.kpi .v { font-size: 26px; font-weight: 650; letter-spacing: -.01em; }
.kpi .v small { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 5px; }
.kpi .l { color: var(--muted); font-size: 12px; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; }
.chart { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px 12px; }
.chart h2, .list h2 { font-size: 13.5px; font-weight: 600; margin-bottom: 10px; }
.chart .box { position: relative; height: 250px; }
.chart .none, .loading { color: var(--muted); display: grid; place-items: center; height: 100%; }
.chart .note { color: var(--muted); font-size: 12px; margin-top: 6px; }
.lists { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 14px; }
.list { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 11.5px; padding: 4px 10px 6px 0; }
td { padding: 7px 10px 7px 0; border-top: 1px solid var(--line); }

.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 2000; max-width: 360px; }
.toast { background: var(--raise); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 10px; padding: 9px 13px; box-shadow: 0 8px 24px rgba(0,0,0,.45); animation: in .25s ease-out; }
.toast.match { border-left-color: var(--warn); }
.toast b { display: block; font-size: 12.5px; }
.toast small { color: var(--muted); display: block; font-size: 12px; }
@keyframes in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr 58px; }
  .rail { order: 2; flex-direction: row; justify-content: space-around; padding: 4px; border-right: 0; border-top: 1px solid var(--line); }
  .brand { display: none; }
  .rail-link { width: auto; flex: 1; }
  .rail-link.active { box-shadow: inset 0 3px 0 var(--accent); }
  .main { height: auto; min-height: 0; overflow: hidden; }
  .mapview { grid-template-columns: 1fr; grid-template-rows: 46vh 1fr; }
  .map-wrap { order: -1; }
  .panel { border-right: 0; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
