:root {
  --ink: #0b1820;
  --muted: #60717c;
  --surface: rgba(255, 255, 255, 0.96);
  --surface-solid: #fff;
  --line: #dce5e8;
  --accent: #087f6a;
  --accent-strong: #056252;
  --accent-soft: #e3f7f1;
  --dark: #071a20;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(5, 33, 40, 0.16);
  --radius: 20px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #dce8e7;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }

body { background: #dce8e7; }

button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 3px solid rgba(8, 127, 106, 0.3);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: -80px;
  z-index: 10000;
  padding: 10px 14px;
  border-radius: 10px;
  color: #fff;
  background: var(--dark);
  transition: top 160ms ease;
}
.skip-link:focus { top: 12px; }

.app-header {
  position: fixed;
  z-index: 1200;
  top: 16px;
  left: 16px;
  right: 16px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 8px 14px 8px 8px;
  color: #eafffb;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 16px;
  background: rgba(7, 26, 32, 0.93);
  box-shadow: 0 8px 30px rgba(5, 33, 40, 0.22);
  backdrop-filter: blur(14px);
  pointer-events: auto;
}
.brand img { border-radius: 12px; }
.brand span { display: flex; flex-direction: column; line-height: 1.1; }
.brand strong { font-size: 1rem; letter-spacing: -0.02em; }
.brand small { margin-top: 4px; color: #a8ccc6; font-size: 0.7rem; }

.header-actions { display: flex; gap: 8px; pointer-events: auto; }
.filter-toggle {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #fff;
  background: rgba(7, 26, 32, 0.93);
  box-shadow: 0 8px 30px rgba(5, 33, 40, 0.18);
  backdrop-filter: blur(14px);
}
.filter-toggle { display: none; gap: 8px; align-items: center; border-radius: 14px; padding: 0 15px; font-weight: 750; }

.app-shell, #map { position: relative; width: 100%; height: 100%; }
#map { z-index: 0; background: #dce8e7; }
.leaflet-container { font: inherit; }
.leaflet-control-attribution {
  padding: 3px 7px !important;
  color: #41545c;
  background: rgba(255, 255, 255, 0.88) !important;
  backdrop-filter: blur(6px);
}

.control-panel {
  position: fixed;
  z-index: 1100;
  top: 92px;
  right: 16px;
  width: min(390px, calc(100vw - 32px));
  max-height: calc(100dvh - 108px);
  padding: 20px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  scrollbar-width: thin;
}
.panel-handle { display: none; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 17px; }
.panel-heading h1 { margin: 2px 0 0; font-size: 1.35rem; line-height: 1.15; letter-spacing: -0.035em; }
.eyebrow { margin: 0; color: var(--accent); font-size: 0.69rem; font-weight: 800; letter-spacing: 0.11em; text-transform: uppercase; }
.panel-close { display: none; width: 40px; height: 40px; border: 0; border-radius: 50%; color: var(--ink); background: #edf3f3; font-size: 1.5rem; }

label { display: block; margin: 12px 0 6px; font-size: 0.76rem; font-weight: 760; color: #344851; }
input, select {
  width: 100%;
  min-height: 44px;
  border: 1px solid #cad7db;
  border-radius: 12px;
  color: var(--ink);
  background: #fff;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
input { min-width: 0; padding: 0 12px; }
select { padding: 0 36px 0 12px; }
input:hover, select:hover { border-color: #9db2b8; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(8, 127, 106, 0.1); outline: none; }

.input-action { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; }
.input-action button, .location-actions button, .direction-actions button, .direction-actions a {
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  font-weight: 720;
}
.input-action button { padding: 0 13px; color: #fff; background: var(--dark); }

.location-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0 17px; }
.location-actions button { padding: 8px 10px; border: 1px solid #cad7db; color: #2c4149; background: #f8fbfb; font-size: 0.78rem; }
.location-actions .primary-action { border-color: var(--accent); color: #fff; background: var(--accent); }
.location-actions button.is-active { border-color: var(--accent); color: var(--accent-strong); background: var(--accent-soft); }

.filter-section { padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: rgba(247, 250, 250, 0.82); }
.section-heading { display: flex; align-items: center; justify-content: space-between; }
.section-heading h2 { margin: 0; font-size: 0.91rem; letter-spacing: -0.015em; }
.text-button { border: 0; padding: 4px; color: var(--accent); background: transparent; font-size: 0.73rem; font-weight: 750; }

.band-filter { margin-top: 11px; border-top: 1px solid var(--line); }
.band-filter summary { padding-top: 11px; color: #344851; font-size: 0.77rem; font-weight: 760; }
.band-filter summary span { float: right; color: var(--accent); font-size: 0.69rem; }
.band-options { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.band-option { position: relative; }
.band-option input { position: absolute; opacity: 0; pointer-events: none; }
.band-option label { margin: 0; padding: 8px 9px; border: 1px solid #d5e0e3; border-radius: 9px; color: #4c6068; background: #fff; font-size: 0.7rem; text-align: center; }
.band-option input:checked + label { border-color: var(--accent); color: var(--accent-strong); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.band-option input:focus-visible + label { outline: 3px solid rgba(8, 127, 106, 0.25); }
.band-option[hidden] { display: none; }

.nearest-action {
  width: 100%;
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 13px;
  margin-top: 13px;
  padding: 10px 13px;
  border: 0;
  border-radius: 16px;
  color: #eafffb;
  background: linear-gradient(135deg, #082b31, #075b52);
  box-shadow: 0 9px 24px rgba(7, 91, 82, 0.18);
  text-align: left;
}
.nearest-action:hover { filter: brightness(1.05); }
.nearest-icon { display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 auto; border-radius: 50%; color: var(--dark); background: #5eead4; transform: rotate(-45deg); }
.nearest-action span:last-child { display: flex; flex-direction: column; }
.nearest-action strong { font-size: 0.84rem; }
.nearest-action small { margin-top: 3px; color: #a9d8d0; font-size: 0.7rem; }

.direction-card { display: grid; grid-template-columns: 84px 1fr; gap: 13px; margin-top: 12px; padding: 13px; border: 1px solid #b7e3da; border-radius: 16px; background: #f0fbf8; }
.direction-visual { display: grid; place-items: center; }
.compass-ring { position: relative; display: grid; place-items: center; width: 74px; height: 74px; border: 1px solid #a9ccc6; border-radius: 50%; background: radial-gradient(circle, #fff 0 48%, #dff5f0 49% 51%, #fff 52%); }
.compass-ring::before, .compass-ring::after { content: ""; position: absolute; background: #bdd6d2; }
.compass-ring::before { width: 1px; height: 100%; }
.compass-ring::after { width: 100%; height: 1px; }
.compass-ring span { position: absolute; z-index: 2; top: 2px; font-size: 0.58rem; font-weight: 900; color: var(--danger); }
.compass-ring i { z-index: 3; display: grid; place-items: center; width: 28px; height: 56px; color: var(--accent); font-style: normal; transform-origin: 50% 50%; transition: transform 300ms ease; filter: drop-shadow(0 2px 2px rgba(5, 98, 82, 0.2)); }
.compass-ring i svg { width: 24px; height: 48px; fill: currentColor; }
.direction-details h2 { margin: 2px 0; font-size: 1rem; }
.direction-details > p:not(.eyebrow) { margin: 0; color: #3e545c; font-size: 0.76rem; line-height: 1.42; }
.direction-bands { margin-top: 4px !important; color: var(--accent-strong) !important; font-weight: 720; }
.direction-actions { display: flex; gap: 6px; margin-top: 9px; }
.direction-actions button, .direction-actions a { display: inline-flex; align-items: center; justify-content: center; min-height: 34px; padding: 0 9px; border: 1px solid #b7d8d2; color: var(--accent-strong); background: #fff; font-size: 0.68rem; text-decoration: none; }

.map-status { display: flex; align-items: center; gap: 8px; margin-top: 14px; color: #526770; font-size: 0.73rem; }
.status-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: #8da2a8; }
.map-status.is-loading .status-dot { background: #e5a000; animation: pulse 900ms ease-in-out infinite alternate; }
.map-status.is-success .status-dot { background: #14a36f; }
.map-status.is-error .status-dot { background: var(--danger); }
@keyframes pulse { to { transform: scale(1.55); opacity: 0.5; } }

.source-note { margin: 10px 0 0; color: #718088; font-size: 0.64rem; line-height: 1.45; }

.map-toolbar {
  position: fixed;
  z-index: 1000;
  left: 16px;
  bottom: 24px;
  display: flex;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 24px rgba(5, 33, 40, 0.16);
}
.map-toolbar button { width: 44px; height: 44px; border: 0; border-right: 1px solid var(--line); color: #284049; background: transparent; font-size: 1.25rem; font-weight: 600; }
.map-toolbar button:last-child { border-right: 0; }
.map-toolbar button:hover { background: #edf7f5; }

.station-marker { background: transparent; border: 0; }
.station-pin {
  position: relative;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 3px solid #fff;
  border-radius: 50% 50% 50% 14%;
  box-shadow: 0 4px 10px rgba(7, 26, 32, 0.3);
  transform: rotate(-45deg);
}
.station-pin::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #fff; transform: rotate(45deg); }
.station-pin.is-target { animation: targetPulse 900ms ease-in-out infinite alternate; }
@keyframes targetPulse { to { box-shadow: 0 0 0 8px rgba(8, 127, 106, 0.18), 0 4px 10px rgba(7, 26, 32, 0.3); } }

.user-location-marker { background: transparent; border: 0; }
.analysis-point { position: relative; display: grid; place-items: center; width: 54px; height: 54px; }
.user-location-dot { position: relative; z-index: 3; width: 20px; height: 20px; border: 4px solid #fff; border-radius: 50%; background: #1687ff; box-shadow: 0 0 0 3px rgba(22, 135, 255, 0.28), 0 4px 10px rgba(7, 26, 32, 0.25); }
.antenna-bearing { position: absolute; z-index: 2; top: -5px; left: 17px; display: grid; place-items: center; width: 20px; height: 64px; transform: rotate(var(--bearing)); transition: transform 300ms ease; filter: drop-shadow(0 2px 2px rgba(7, 26, 32, 0.28)); }
.antenna-bearing svg { width: 20px; height: 64px; overflow: visible; fill: #075b52; }
.analysis-point.has-bearing::before { content: ""; position: absolute; inset: 2px; border: 1px solid rgba(7, 91, 82, 0.24); border-radius: 50%; background: rgba(255, 255, 255, 0.68); box-shadow: 0 3px 12px rgba(7, 26, 32, 0.14); }

.direction-line-marker { background: transparent; border: 0; }
.direction-line-marker > span { display: grid; place-items: center; width: 28px; height: 28px; border: 2px solid #fff; border-radius: 50%; background: var(--direction-color, var(--accent)); box-shadow: 0 3px 9px rgba(7, 26, 32, 0.28); transform: rotate(var(--bearing)); }
.direction-line-marker i { width: 8px; height: 8px; border-top: 3px solid #fff; border-right: 3px solid #fff; transform: translateY(2px) rotate(-45deg); }

.marker-cluster { display: grid; place-items: center; border-radius: 50%; color: #fff; background: rgba(7, 26, 32, 0.88); box-shadow: 0 3px 12px rgba(7, 26, 32, 0.28); }
.marker-cluster div { display: grid; place-items: center; width: calc(100% - 8px); height: calc(100% - 8px); border: 2px solid rgba(255, 255, 255, 0.72); border-radius: 50%; background: var(--accent); }
.marker-cluster span { font-size: 0.72rem; font-weight: 850; }
.leaflet-cluster-anim .leaflet-marker-icon, .leaflet-cluster-anim .leaflet-marker-shadow { transition: transform 0.3s ease-out, opacity 0.3s ease-in; }

.station-popup { min-width: 230px; }
.station-popup h3 { margin: 0 0 3px; font-size: 0.92rem; }
.station-popup .popup-place { margin: 0 0 9px; color: var(--muted); font-size: 0.72rem; }
.station-popup .popup-count { margin: 0 0 8px; padding: 5px 7px; border-radius: 7px; color: #34515a; background: #edf5f4; font-size: 0.67rem; }
.frequency-groups { display: grid; gap: 6px; margin: 0; }
.frequency-row { display: grid; grid-template-columns: 64px 1fr; gap: 7px; padding-top: 6px; border-top: 1px solid #e6eeee; font-size: 0.7rem; }
.frequency-row dt { font-weight: 800; }
.frequency-row dd { margin: 0; color: #4c6169; }
.popup-direction { width: 100%; min-height: 36px; margin-top: 10px; border: 0; border-radius: 9px; color: #fff; background: var(--accent); font-size: 0.72rem; font-weight: 750; }

.pick-crosshair, body.is-picking #map { cursor: crosshair !important; }

.toast {
  position: fixed;
  z-index: 3000;
  left: 50%;
  bottom: 28px;
  max-width: min(460px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: 12px;
  color: #fff;
  background: rgba(7, 26, 32, 0.94);
  box-shadow: var(--shadow);
  font-size: 0.78rem;
  text-align: center;
  transform: translateX(-50%);
}

.noscript-message { position: fixed; z-index: 9000; inset: 20px; padding: 30px; border-radius: 20px; background: #fff; }

@media (max-width: 760px) {
  .app-header { top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px; height: 52px; }
  .brand { min-height: 48px; padding: 6px 11px 6px 6px; border-radius: 14px; }
  .brand img { width: 36px; height: 36px; }
  .brand small { display: none; }
  .filter-toggle { display: flex; min-height: 48px; }

  .control-panel {
    top: auto;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 8px;
    width: auto;
    max-height: min(82dvh, 720px);
    padding: 9px 16px 16px;
    border-radius: 22px;
    transform: translateY(calc(100% + 18px));
    visibility: hidden;
    transition: transform 220ms cubic-bezier(.2,.8,.2,1), visibility 220ms;
  }
  .control-panel.is-open { transform: translateY(0); visibility: visible; }
  .panel-handle { display: block; width: 42px; height: 4px; margin: 0 auto 10px; border-radius: 2px; background: #cbd7d9; }
  .panel-close { display: block; }
  .panel-heading { margin-bottom: 12px; }
  .panel-heading h1 { font-size: 1.15rem; }
  .location-actions { margin-bottom: 12px; }
  .nearest-action { min-height: 58px; }
  .source-note { padding-bottom: env(safe-area-inset-bottom); }

  .map-toolbar { left: 8px; bottom: max(18px, env(safe-area-inset-bottom)); }
  .leaflet-control-attribution { max-width: calc(100vw - 164px); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .toast { bottom: max(76px, calc(env(safe-area-inset-bottom) + 76px)); }
  body.panel-open .map-toolbar { opacity: 0; pointer-events: none; }
}

@media (max-width: 380px) {
  .location-actions { grid-template-columns: 1fr; }
  .direction-card { grid-template-columns: 72px 1fr; }
  .compass-ring { width: 64px; height: 64px; }
}

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

@media (prefers-contrast: more) {
  :root { --line: #83969d; --muted: #344851; }
  .control-panel, input, select, .filter-section { border-width: 2px; }
}
