/* ═══════════════════════════════════════════════════════════════
   Тема повторяет lib/theme.dart приложения RadioCalc.
   ═══════════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #0f1419;
  --bg-2: #1a1f29;
  --panel: #1e242f;
  --panel-2: #252b38;
  --border: #2e3543;
  --border-2: #3a4252;
  --text: #e4e7eb;
  --muted: #8a92a3;
  --accent: #ff8c42;
  --accent-2: #ffb074;
  --tx: #ff4757;
  --rx: #3498ff;
  --anchor: #4ade80;
  --sol: #c084fc;
  --good: #4ade80;
  --warn: #fbbf24;
  --bad: #ef4444;
  --info: #60a5fa;
  --shadow: #673ab7;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bot: env(safe-area-inset-bottom, 0);
  --mono: ui-monospace, 'JetBrains Mono', 'Cascadia Mono', Consolas, monospace;
}

html, body {
  height: 100%; width: 100%;
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px; line-height: 1.45;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--mono); }
[hidden] { display: none !important; }

button, .btn {
  font-family: inherit; font-size: 13px; font-weight: 600;
  padding: 10px 16px; border: none; border-radius: 10px;
  background: var(--panel-2); color: var(--text);
  cursor: pointer; transition: transform .1s, background .15s, opacity .15s;
  user-select: none; min-height: 40px;
}
button:active { transform: scale(.96); }
button:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #1a0f08; }
.btn-primary:hover:not(:disabled) { background: var(--accent-2); }
.btn-ghost { background: transparent; border: 1px solid var(--border-2); }
.btn-danger { background: transparent; border: 1px solid var(--border-2); color: var(--bad); }
.btn.wide { width: 100%; margin-bottom: 12px; }

input, select {
  font-family: inherit; font-size: 14px;
  width: 100%; padding: 10px 12px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  outline: none; transition: border-color .15s;
  min-height: 42px;
}
input:focus, select:focus { border-color: var(--accent); }
input[type="checkbox"] { width: auto; min-height: 0; accent-color: var(--accent); }
input[type="range"] { padding: 0; min-height: 0; border: none; background: transparent; accent-color: var(--accent); }
input.bad-value { border-color: var(--bad); }

label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px;
        letter-spacing: .03em; text-transform: uppercase; font-weight: 500; }
label.check, label.sw {
  display: flex; align-items: center; gap: 8px;
  text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text);
  margin-bottom: 0; cursor: pointer;
}
.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.note { font-size: 11px; color: var(--muted); line-height: 1.5; margin-top: 8px; }
.note code { font-family: var(--mono); color: var(--text); font-size: 11px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--panel-2); font-size: 11px; font-weight: 600;
}
.chip-good { background: rgba(74,222,128,.15); color: var(--good); }
.chip-warn { background: rgba(251,191,36,.15); color: var(--warn); }
.chip-bad  { background: rgba(239,68,68,.15);  color: var(--bad); }
.chip-info { background: rgba(96,165,250,.15); color: var(--info); }

#app {
  display: flex; flex-direction: column;
  height: 100dvh; width: 100vw;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bot);
}

/* ── Шапка с переключателем разделов ────────────────────────── */
#header {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px; background: var(--panel);
  border-bottom: 1px solid var(--border); z-index: 100;
}
#header .logo { font-size: 18px; }
#header .title { font-weight: 700; font-size: 14px; flex: 1; min-width: 0; }
#header .subtitle { font-size: 10px; color: var(--muted); font-weight: 400;
                    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#sections {
  display: flex; gap: 2px; padding: 3px;
  background: var(--bg-2); border-radius: 10px; flex-shrink: 0;
}
.section-btn {
  padding: 7px 12px; min-height: 0; border-radius: 8px;
  background: transparent; color: var(--muted); font-size: 12px;
}
.section-btn.active { background: var(--accent); color: #1a0f08; }

#tabs { display: flex; background: var(--panel);
        border-bottom: 1px solid var(--border); padding: 0 4px; }
.tab {
  flex: 1; padding: 12px 4px; background: transparent;
  border: none; color: var(--muted); font-size: 12px; font-weight: 600;
  border-bottom: 2px solid transparent; border-radius: 0; min-height: 0;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

#views { flex: 1; position: relative; overflow: hidden; }
.view { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden;
        -webkit-overflow-scrolling: touch; display: none; }
.view.active { display: block; }

#map { width: 100%; height: 100%; background: var(--bg-2); }
.leaflet-container { background: var(--bg-2) !important; font-family: inherit !important; }
/* Оверлей карты покрытия: без сглаживания читаются границы ячеек,
   со сглаживанием картинка ближе к приложению. Оставляем сглаживание. */
.leaflet-image-layer { image-rendering: auto; }

.map-overlay {
  position: absolute; bottom: 16px; left: 16px; right: 16px;
  background: rgba(30,36,47,.94); backdrop-filter: blur(12px);
  border: 1px solid var(--border-2); border-radius: 14px;
  padding: 12px 14px; z-index: 500;
  box-shadow: 0 10px 40px rgba(0,0,0,.4);
  max-height: calc(100% - 32px); overflow-y: auto;
}
.map-overlay .row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 12px; }
.map-overlay .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.map-overlay .dot-ico { width: 10px; text-align: center; flex-shrink: 0; }
.dot-tx { background: var(--tx); box-shadow: 0 0 8px var(--tx); }
.dot-rx { background: var(--rx); box-shadow: 0 0 8px var(--rx); }
.dot-anchor { background: var(--anchor); box-shadow: 0 0 8px var(--anchor); }
.dot-sol { background: var(--sol); box-shadow: 0 0 8px var(--sol); }
.map-overlay .lbl { color: var(--muted); width: 44px; flex-shrink: 0; }
.map-overlay .val { flex: 1; font-family: var(--mono); font-size: 11px; }
.map-overlay .actions { display: flex; gap: 8px; margin-top: 10px; }
.map-overlay .actions button { flex: 1; }
.hint-inline { font-size: 11px; color: var(--muted); line-height: 1.4; }

#layer-box { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 10px; }
.layers { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 10px; }
.layers .sw { font-size: 12px; }
.hslider label { text-transform: none; letter-spacing: 0; font-size: 11px; margin-bottom: 6px; }
.hslider b { color: var(--text); font-family: var(--mono); }
.legend { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 10px; color: var(--muted); }
.legend .bar { flex: 1; height: 8px; border-radius: 4px; }

.map-hint {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  background: rgba(255,140,66,.95); color: #1a0f08;
  padding: 8px 14px; border-radius: 999px;
  font-size: 12px; font-weight: 600; z-index: 500;
  box-shadow: 0 4px 20px rgba(255,140,66,.4);
  transition: opacity .3s, transform .3s; opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); text-align: center;
}
.map-hint.show { opacity: 1; }

.panel { padding: 16px; padding-bottom: 32px; }
.panel h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--muted); margin: 16px 0 10px; font-weight: 600;
}
.panel h2:first-child { margin-top: 0; }
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px; margin-bottom: 12px;
}

.result-card { background: var(--panel); border: 1px solid var(--border);
               border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.result-card .ttl {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted); margin-bottom: 10px; font-weight: 600;
}
.result-row { display: flex; justify-content: space-between; align-items: center;
              gap: 12px; padding: 6px 0; font-size: 13px; }
.result-row:not(:last-child) { border-bottom: 1px solid var(--border); }
.result-row .key { color: var(--muted); }
.result-row .val { font-family: var(--mono); font-weight: 600; text-align: right; }
.result-row .val.good { color: var(--good); }
.result-row .val.warn { color: var(--warn); }
.result-row .val.bad  { color: var(--bad); }
.result-row .val.info { color: var(--info); }

.big-stat { display: flex; flex-direction: column; align-items: center;
            padding: 16px 8px; text-align: center; }
.big-stat.sm { padding: 8px; }
.big-stat .num { font-size: 32px; font-weight: 700; font-family: var(--mono); line-height: 1; }
.big-stat.sm .num { font-size: 22px; }
.big-stat .unit { font-size: 12px; color: var(--muted); margin-top: 4px; }
.big-stat .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .1em;
                 color: var(--muted); margin-bottom: 8px; }
.big-stat .chip { margin-top: 10px; }
.num.good { color: var(--good); } .num.warn { color: var(--warn); } .num.bad { color: var(--bad); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-grid .result-card { margin: 0; padding: 8px; }

#chart-wrap { background: var(--panel); border: 1px solid var(--border);
              border-radius: 14px; padding: 12px; margin: 12px 0; }
#chart-canvas { width: 100%; display: block; }

.empty-state { display: flex; flex-direction: column; align-items: center;
               justify-content: center; padding: 60px 20px; text-align: center; color: var(--muted); }
.empty-state .icon { font-size: 48px; margin-bottom: 16px; opacity: .5; }
.empty-state .text { font-size: 14px; max-width: 280px; line-height: 1.5; }

.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.2); border-top-color: currentColor;
  border-radius: 50%; animation: spin .7s linear infinite;
  vertical-align: middle; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

#toast {
  position: fixed; bottom: calc(80px + var(--safe-bot)); left: 50%;
  transform: translateX(-50%) translateY(140px);
  background: var(--panel); border: 1px solid var(--border-2);
  padding: 10px 18px; border-radius: 999px; font-size: 13px;
  z-index: 9999; transition: transform .3s; pointer-events: none;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); max-width: 90vw; text-align: center;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.err { border-color: var(--bad); color: var(--bad); }
#toast.ok  { border-color: var(--good); color: var(--good); }

/* ── Трилатерация: карточка опорной точки ───────────────────── */
.anchor {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 12px 14px; margin-bottom: 10px;
}
.anchor.suspect { border-color: var(--warn); }
.anchor.dropped { opacity: .55; border-style: dashed; }
.anchor-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.anchor-head .badge {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  background: var(--anchor); color: #06280f;
  font-size: 11px; font-weight: 700; display: flex;
  align-items: center; justify-content: center; font-family: var(--mono);
}
.anchor-head .name { flex: 1; }
.anchor-head .name input { min-height: 32px; padding: 5px 8px; font-size: 13px; }
.anchor-head .del { padding: 4px 8px; min-height: 28px; font-size: 16px; line-height: 1;
                    background: transparent; color: var(--muted); }
.anchor-head .del:hover { color: var(--bad); }
.anchor .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.anchor .grid2 + .grid2 { margin-top: 8px; }
.anchor input { min-height: 38px; padding: 8px 10px; }
.anchor .stats { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.anchor .stats .chip { font-size: 10px; font-family: var(--mono); }

.problems { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.35);
            border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.problems ul { margin: 0; padding-left: 18px; }
.problems li { font-size: 12px; line-height: 1.5; color: var(--bad); }
.msg-card { background: var(--panel); border: 1px solid var(--border);
            border-radius: 14px; padding: 12px 14px; margin-bottom: 12px;
            font-size: 12px; line-height: 1.55; color: var(--muted); }
.sol-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.sol-head .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--sol); }

@media (min-width: 900px) {
  #app { display: grid; grid-template-columns: 400px 1fr 400px; grid-template-rows: 52px 1fr; }
  #header { grid-column: 1 / -1; }
  #tabs { display: none; }
  #views { display: contents; }
  .view { position: static; display: block !important; height: 100%; }
  .view#view-map { grid-row: 2; grid-column: 2; }
  .view#view-params { grid-row: 2; grid-column: 1;
                      border-right: 1px solid var(--border); background: var(--panel);
                      overflow-y: auto; }
  .view#view-results { grid-row: 2; grid-column: 3;
                       border-left: 1px solid var(--border); background: var(--panel);
                       overflow-y: auto; }
  .map-overlay { left: 24px; right: auto; max-width: 380px; bottom: 24px; }
}
