/* ===================== Тёмная ham-radio тема ===================== */
:root {
  --bg: #0d1117;
  --bg-panel: #131a24;
  --bg-card: #161d29;
  --bg-input: #0d141f;
  --border: #263244;
  --text: #d7e2ec;
  --text-dim: #7f92a8;
  --accent: #ff8c1a;
  --accent-dim: #b8620f;
  --local: #4da3ff;
  --remote: #ff5470;
  --good: #35d07f;
  --warn: #f2c14e;
  --bad: #ff5470;
  --font: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Consolas", "SF Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 20% -10%, #131c2b 0%, var(--bg) 55%);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}

h1, h2, h3 { margin: 0; }

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: linear-gradient(180deg, #141b27 0%, #10161f 100%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: wrap;
  gap: 10px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { font-size: 30px; filter: drop-shadow(0 0 6px rgba(255,140,26,.5)); }
.brand h1 { font-size: 18px; letter-spacing: .5px; color: #fff; }
.brand-sub { font-size: 12px; color: var(--text-dim); }

.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  border: 1px solid var(--border);
}
.badge-muted { color: var(--text-dim); background: var(--bg-input); }
.badge-good { color: #06331e; background: var(--good); border-color: var(--good); font-weight: 600; }
.badge-warn { color: #3a2c00; background: var(--warn); border-color: var(--warn); font-weight: 600; }
.badge-bad { color: #390010; background: var(--bad); border-color: var(--bad); font-weight: 600; }

.units-toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); cursor: pointer; user-select: none; }
.units-toggle input { display: none; }
.units-toggle .slider {
  width: 30px; height: 16px; border-radius: 10px; background: var(--bg-input);
  border: 1px solid var(--border); position: relative; transition: .2s;
}
.units-toggle .slider::after {
  content: ""; position: absolute; width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); top: 1px; left: 1px; transition: .2s;
}
.units-toggle input:checked + .slider::after { left: 15px; }

/* ---------- Buttons ---------- */
.btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  transition: .15s;
}
.btn:hover { border-color: var(--accent); color: #fff; }
.btn-ghost { background: transparent; }
.btn-mini { padding: 4px 8px; font-size: 12px; }

.btn-place { border-color: var(--border); }
.btn-place.place-local.active { background: var(--local); color: #04101f; border-color: var(--local); font-weight: 600; }
.btn-place.place-remote.active { background: var(--remote); color: #260006; border-color: var(--remote); font-weight: 600; }
.btn-ghost.active { background: var(--accent); color: #2a1400; border-color: var(--accent); font-weight: 600; }

.btn-calculate {
  display: block;
  width: 100%;
  padding: 16px;
  margin: 4px 0 18px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #1a0d00;
  background: linear-gradient(180deg, #ffb14d, var(--accent));
  border: none;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(255, 140, 26, .35);
  transition: transform .1s, box-shadow .2s;
}
.btn-calculate:hover { box-shadow: 0 8px 26px rgba(255, 140, 26, .5); transform: translateY(-1px); }
.btn-calculate:active { transform: translateY(0); }
.btn-calculate:disabled { opacity: .6; cursor: wait; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 300px 1fr 300px;
  gap: 16px;
  padding: 16px 20px 40px;
  align-items: start;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---------- Panels (Local/Remote) ---------- */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  position: sticky;
  top: 74px;
}
@media (max-width: 1100px) { .panel { position: static; } }

.panel-title { font-size: 15px; padding-bottom: 10px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.local-title { color: var(--local); }
.remote-title { color: var(--remote); }

.field-row { margin-bottom: 10px; }
.field-row label { display: block; font-size: 11.5px; color: var(--text-dim); margin-bottom: 4px; }
.field-hint { font-size: 10px; color: var(--text-dim); margin-top: 3px; line-height: 1.4; opacity: .8; }

input[type="number"], input[type="text"], select {
  width: 100%;
  padding: 7px 9px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--mono);
}
select { font-family: var(--font); }
input:focus, select:focus { outline: none; border-color: var(--accent); }

.input-with-btn { display: flex; gap: 6px; }
.input-with-btn input { flex: 1; }

.city-search-wrap { position: relative; }
.city-search-results {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 240px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.city-search-results.open { display: block; }
.city-result-item {
  padding: 7px 10px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.city-result-item:hover, .city-result-item.active { background: var(--bg-input); }
.city-result-item .place-kind { color: var(--text-dim); font-size: 11px; }
.city-search-empty { padding: 7px 10px; font-size: 12px; color: var(--text-dim); }

.cable-loss-row { display: flex; align-items: center; justify-content: space-between; }
.cable-loss-row label { margin: 0; }
.computed-value { font-family: var(--mono); color: var(--accent); font-weight: 600; font-size: 13px; }

/* ---------- Center column ---------- */
.center-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.map-card, .results-card, .chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}

.map-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.map-hint { font-size: 11.5px; color: var(--text-dim); }

.freq-shared-row {
  display: flex; align-items: flex-end; gap: 18px; flex-wrap: wrap;
  margin-bottom: 10px; padding: 10px 12px;
  background: var(--bg-input); border: 1px solid var(--accent); border-radius: 10px;
}
.freq-field { display: flex; flex-direction: column; gap: 4px; }
.freq-field label { font-size: 12.5px; color: var(--text); font-weight: 600; white-space: nowrap; }
.freq-field input { width: 130px; }
.freq-field.mode-field { flex: 1; min-width: 220px; }
.freq-field.mode-field select { width: 100%; }

#map {
  height: 420px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0a0f16;
}

/* Атрибуция OSM обязательна по их Tile Usage Policy - убрать нельзя,
   но можно сделать её мельче и незаметнее. */
#map .maplibregl-ctrl-attrib {
  font-size: 9px;
  padding: 0 4px;
  background: rgba(13, 17, 23, 0.55);
  color: rgba(255, 255, 255, 0.5);
}
#map .maplibregl-ctrl-attrib a {
  color: rgba(255, 255, 255, 0.6);
}
#map .maplibregl-ctrl-attrib.maplibregl-compact::after { display: none; }

.geo-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.geo-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
.geo-label { display: block; font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .3px; }
.geo-value { font-family: var(--mono); font-size: 15px; color: #fff; }

.mode-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.mode-row label { font-size: 12.5px; color: var(--text-dim); white-space: nowrap; }
.mode-row select { max-width: 320px; }
.mode-row.mode-custom input { max-width: 110px; }
.mode-row.hidden { display: none; }
.mode-info { font-family: var(--mono); font-size: 12px; color: var(--accent); background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; }

.terrain-warning {
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.5;
}
.terrain-warning.hidden { display: none; }
.terrain-warning.level-caution { background: rgba(242,193,78,0.12); border: 1px solid var(--warn); color: #ffe9a8; }
.terrain-warning.level-severe { background: rgba(255,84,112,0.14); border: 1px solid var(--bad); color: #ffc2cc; }

/* ---------- Results ---------- */
.results-card.hidden, .badges-row.hidden { display: none; }

.verdict-block { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; margin-bottom: 14px; }

.probability-gauge { position: relative; width: 160px; }
.gauge-svg { width: 100%; }
.gauge-bg { fill: none; stroke: var(--bg-input); stroke-width: 10; }
.gauge-fg { fill: none; stroke: var(--good); stroke-width: 10; stroke-linecap: round; transition: stroke-dasharray .6s ease, stroke .6s ease; }
.gauge-value { position: absolute; bottom: 0; left: 0; right: 0; text-align: center; font-size: 24px; font-weight: 700; color: #fff; }

.verdict-text { flex: 1; min-width: 220px; }
.verdict-line { font-size: 19px; font-weight: 700; margin-bottom: 6px; }
.margin-line { font-size: 13px; color: var(--text-dim); font-family: var(--mono); }

.badges-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

.chart-card h3, .direction-card h3 { font-size: 13px; color: var(--text-dim); margin-bottom: 10px; font-weight: 600; }
.diffraction-model-note { margin-top: 8px; font-size: 11px; color: var(--text-dim); opacity: .85; }
.chart-card { padding: 12px; margin-bottom: 16px; }

.directions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .directions-grid { grid-template-columns: 1fr; } }

.direction-card { background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }

.budget-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.budget-table td { padding: 5px 4px; border-bottom: 1px dashed var(--border); }
.budget-table td:first-child { color: var(--text-dim); }
.budget-table td:last-child { text-align: right; font-family: var(--mono); color: #fff; }
.budget-table tr.highlight td { color: var(--accent); font-weight: 700; font-size: 13.5px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1c2634;
  border: 1px solid var(--accent);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 999;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  transition: opacity .3s, transform .3s;
}
.toast.hidden { opacity: 0; transform: translate(-50%, 10px); pointer-events: none; }

/* ---------- Модалка ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(4, 8, 14, .65);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; width: 420px; max-width: calc(100vw - 32px); max-height: calc(100vh - 40px);
  overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.modal-box h3 { margin: 0 0 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

/* ---------- Точки на карте (WebSDR/маяки/репитеры) ---------- */
.poi-popup h4 { margin: 0 0 6px; font-size: 14px; }
.poi-popup p { margin: 0 0 6px; font-size: 12.5px; color: var(--text-dim); }
.poi-popup a { color: var(--accent); }

/* ---------- Виджет статистики тайлового кэша высот ---------- */
.tile-stats-widget {
  position: fixed; right: 12px; bottom: 12px; z-index: 500;
  background: rgba(20, 27, 38, 0.85); backdrop-filter: blur(4px);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 10px; font-size: 11px; color: var(--text-dim);
  font-family: var(--mono); pointer-events: none; user-select: none;
}
.tile-stats-widget #tileStatsDownloading { color: var(--accent); }
#tileStatsDownloadingWrap.hidden { display: none; }

/* ---------- Ретрансляторы / цепочка (multi-hop) ---------- */
.relays-section { margin-bottom: 10px; }
.relays-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.relays-header h3 { font-size: 13px; color: var(--text-dim); font-weight: 600; }
#relaysContainer { display: flex; flex-direction: column; gap: 10px; }
.relay-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; position: relative;
}
.relay-card-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.relay-card-header input[type="text"].relay-name { font-weight: 600; border: none; background: transparent; padding: 0; font-size: 13.5px; color: #d9b3ff; }
.relay-card-header input[type="text"].relay-name:focus { outline: none; border-bottom: 1px solid var(--accent); }
.relay-card-actions { display: flex; gap: 6px; }
.relay-fields-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 12px; }
.relay-fields-grid .field-row { margin-bottom: 0; }

.hop-label { font-size: 12px; color: var(--text-dim); font-weight: 600; margin: 10px 0 4px; padding-top: 6px; border-top: 1px dashed var(--border); }
.hop-label:first-child { border-top: none; padding-top: 0; }
.extra-hop-row { margin: 8px 0; padding: 10px; background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px; }
.extra-hop-row .freq-shared-row { margin: 0 0 8px; }
.extra-hop-row .mode-row.mode-info { font-size: 11px; }

.chain-overall-banner {
  border-radius: 12px; padding: 12px 16px; margin: 10px 0;
  border: 1px solid var(--border); background: var(--bg-card);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.chain-overall-banner .banner-verdict { font-weight: 700; font-size: 14px; }
.chain-overall-banner .banner-sub { font-size: 12px; color: var(--text-dim); }

.hop-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.hop-tab {
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text-dim); font-size: 12.5px; cursor: pointer;
}
.hop-tab.active { border-color: var(--accent); color: var(--text); background: var(--bg-input); }
.hop-tab .hop-tab-pct { font-weight: 700; margin-left: 6px; }
