:root {
  --bg: #0d1117;
  --panel: #151b23;
  --panel-2: #1c2430;
  --line: #2a3441;
  --text: #e6edf3;
  --muted: #8b98a8;
  --accent: #3fa7ff;
  --accent-2: #1f6feb;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --target: #f0b429;
  --radius: 10px;
  --mono: "Cascadia Mono", "Consolas", ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 "Segoe UI", system-ui, sans-serif; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

/* ---------- Шапка */
header {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 10;
}
header h1 { font-size: 16px; margin: 0; font-weight: 600; letter-spacing: .3px; }
nav { display: flex; gap: 4px; }
nav button {
  background: none; border: 1px solid transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted);
}
nav button.active { background: var(--panel-2); border-color: var(--line); color: var(--text); }
.pills { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 12px; white-space: nowrap;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); box-shadow: 0 0 6px var(--bad); }
.user { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }

/* ---------- Раскладка */
main { padding: 16px; max-width: 1600px; margin: 0 auto; }
.grid { display: grid; gap: 16px; grid-template-columns: minmax(340px, 1.1fr) minmax(300px, .9fr) minmax(340px, 1fr); }
@media (max-width: 1250px) { .grid { grid-template-columns: 1fr 1fr; } .grid .amp-col { grid-column: 1 / -1; } }
@media (max-width: 800px) { .grid { grid-template-columns: 1fr; } main { padding: 10px; } }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.card + .card { margin-top: 16px; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 0 0 12px; font-weight: 600;
  display: flex; align-items: center; gap: 8px; }
.card h2 .right { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 400; }

.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer;
  transition: background .1s, border-color .1s; user-select: none; touch-action: manipulation;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { background: #243044; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { background: #3a1417; border-color: #6e2227; color: #ffb4b0; }
.btn.danger:hover:not(:disabled) { border-color: var(--bad); }
.btn.ok { background: #12301a; border-color: #23633a; color: #a7f3b5; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.stop {
  background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 700; letter-spacing: 1px; font-size: 15px;
}

input[type=number], input[type=text], input[type=password], select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; min-width: 0;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row + .row { margin-top: 8px; }
.row > label { color: var(--muted); font-size: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { color: var(--muted); font-size: 12px; }

/* ---------- Поворотка */
.readouts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.readout { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.readout .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.readout .value { font-family: var(--mono); font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; }
.readout .sub { font-size: 12px; color: var(--muted); font-family: var(--mono); min-height: 16px; }
.readout .sub.target { color: var(--target); }

.dials { display: grid; grid-template-columns: 1.2fr .8fr; gap: 10px; align-items: center; }
.dials svg { width: 100%; height: auto; display: block; cursor: crosshair; user-select: none; }
.dial-caption { text-align: center; font-size: 11px; color: var(--muted); margin-top: 2px; }

.goto { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; margin-top: 12px; }
.goto input { width: 100%; }
.nudge { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.nudge .btn { padding: 5px 0; font-family: var(--mono); font-size: 12px; }

.joy-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; }
#joystick {
  position: relative; width: min(260px, 70vw); aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle, #1d2633 0%, #141a22 70%); border: 1px solid var(--line);
  touch-action: none; user-select: none; cursor: grab;
}
#joystick::before, #joystick::after { content: ""; position: absolute; background: var(--line); }
#joystick::before { left: 50%; top: 8%; bottom: 8%; width: 1px; }
#joystick::after { top: 50%; left: 8%; right: 8%; height: 1px; }
#joystick .ring { position: absolute; inset: 25%; border: 1px dashed var(--line); border-radius: 50%; }
#knob {
  position: absolute; width: 30%; height: 30%; left: 35%; top: 35%; border-radius: 50%; z-index: 2;
  background: radial-gradient(circle at 35% 35%, #5bb8ff, var(--accent-2)); box-shadow: 0 4px 14px #0008;
}
#joystick.active #knob { background: radial-gradient(circle at 35% 35%, #ffd36b, #d18b00); }
.dpad { display: grid; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(3, 44px); gap: 6px; }
.dpad .btn { padding: 0; font-size: 18px; }
.dpad .btn.stop { font-size: 12px; letter-spacing: 0; }
.speed { width: 100%; }
.speed input { width: 100%; accent-color: var(--accent); }
.kbd-hint { font-size: 11px; color: var(--muted); text-align: center; }
kbd { background: var(--panel-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; font-family: var(--mono); font-size: 11px; }

.list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow: auto; }
.list-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; }
.list-item .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.empty { color: var(--muted); font-size: 12px; padding: 6px 2px; }

/* ---------- Усилитель */
.amp-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.amp-state { font-size: 18px; font-weight: 700; letter-spacing: 1px; padding: 6px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); }
.amp-state.on { background: #12301a; border-color: var(--ok); color: #7ee79a; }
.amp-state.off { color: var(--muted); }
.amp-state.fault { background: #3a1417; border-color: var(--bad); color: #ffb4b0; }
.power-big { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.metric { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.metric .label { font-size: 11px; color: var(--muted); }
.metric .value { font-family: var(--mono); font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.metric .value small { font-size: 12px; color: var(--muted); font-weight: 400; }
.metric.warn { border-color: var(--warn); }
.metric.bad { border-color: var(--bad); }
.bar { height: 4px; background: var(--bg); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metrics .value { font-size: 15px; }
.flags { display: grid; grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); gap: 6px; margin: 12px 0; }
.flag { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 4px 8px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); }
.flag.bad { border-color: var(--bad); color: #ffb4b0; }
.flag.warn { border-color: var(--warn); color: #f5d68a; }
.enables { display: flex; gap: 4px; flex-wrap: wrap; font-family: var(--mono); font-size: 11px; }
.enables span { padding: 2px 6px; border-radius: 4px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.enables span.on { color: var(--ok); border-color: #23633a; }
.amp-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.amp-controls .field input { width: 100%; }
.inline { display: flex; gap: 6px; }
.inline input { flex: 1; }
.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- Журнал */
.log-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.log-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.log-table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.log-table td { padding: 5px 8px; border-bottom: 1px solid #1e2631; vertical-align: top; }
.log-table td.ts { font-family: var(--mono); color: var(--muted); white-space: nowrap; }
.log-table tr.warn td.msg { color: #f5d68a; }
.log-table tr.error td.msg { color: #ffb4b0; }
.log-scroll { max-height: calc(100vh - 220px); overflow: auto; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap; }
.mini-log { max-height: 180px; overflow: auto; font-size: 12px; }
.mini-log div { padding: 2px 0; border-bottom: 1px solid #1e2631; display: flex; gap: 8px; }
.mini-log .ts { font-family: var(--mono); color: var(--muted); }
.mini-log .warn { color: #f5d68a; }
.mini-log .error { color: #ffb4b0; }

/* ---------- Настройки */
.settings { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); align-items: start; }
@media (max-width: 800px) { .settings { grid-template-columns: 1fr; } }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid input, .form-grid select { width: 100%; }
.hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.raw-out { font-family: var(--mono); font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; min-height: 60px; white-space: pre-wrap; margin-top: 8px; max-height: 200px; overflow: auto; }

/* ---------- Уведомления */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: 10px 12px; box-shadow: 0 8px 24px #0008; font-size: 13px; }
.toast.error { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }
.banner { background: #3a2a0c; border: 1px solid var(--warn); color: #f5d68a; border-radius: 8px; padding: 8px 12px; margin-bottom: 16px; }
.offline { background: #3a1417; border-color: var(--bad); color: #ffb4b0; }

/* ---------- Вход */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); }
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.login-card input { width: 100%; padding: 9px 10px; }
.error-text { color: var(--bad); font-size: 13px; min-height: 18px; }

/* ================================================================ Карта и новая раскладка */
:root { --lime: #d4ef8a; --lime-dim: #d4ef8a33; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.main-col, .side-col { min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.layout .card + .card { margin-top: 0; }
@media (max-width: 1100px) { .layout { grid-template-columns: 1fr; } }

.chip { font-size: 12px; padding: 3px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); background: var(--panel-2); text-transform: none; letter-spacing: 0; font-weight: 400; }
.chip.sim { color: var(--lime); border-color: #6b7d3a; background: #1f2614; }
.eyebrow { font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); }
.map-card { padding: 16px; }
.map-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.map-title { margin: 4px 0 0; font-size: 22px; font-weight: 600; }
.map-wrap { position: relative; height: clamp(360px, 58vh, 640px); border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
#map { position: absolute; inset: 0; background: #0b0f14; }
.map-wrap.placing #map, .map-wrap.aiming #map { cursor: crosshair; }

.map-overlay { position: absolute; z-index: 500; display: flex; gap: 8px; pointer-events: none; }
.map-overlay > * { pointer-events: auto; }
.top-left { top: 12px; left: 12px; }
.top-center { top: 12px; right: 12px; flex-wrap: wrap; justify-content: flex-end; max-width: calc(100% - 260px); }
.right-center { right: 12px; top: 50%; transform: translateY(-50%); flex-direction: column; align-items: center; }
.bottom-left { left: 12px; bottom: 12px; flex-direction: column; align-items: flex-start; }
.bottom-center { left: 50%; bottom: 12px; transform: translateX(-50%); }
@media (max-width: 700px) {
  .top-center { top: 56px; left: 12px; right: 12px; max-width: none; justify-content: flex-start; }
  .bottom-left .map-stats { grid-template-columns: repeat(2, auto); }
  .bottom-center { display: none; }
}

.map-select, .map-btn {
  background: #11161dcc; backdrop-filter: blur(6px); border: 1px solid #ffffff22; color: var(--text);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; cursor: pointer; box-shadow: 0 4px 14px #0006;
}
.map-btn:hover { border-color: var(--lime); }
.map-btn.active { background: var(--lime); color: #11161d; border-color: var(--lime); font-weight: 600; }
.map-btn.square { width: 38px; height: 38px; padding: 0; font-size: 18px; display: grid; place-items: center; }
.north { background: #11161dcc; border: 1px solid #ffffff22; border-radius: 8px; width: 38px; padding: 4px 0 6px; text-align: center; font-size: 11px; font-weight: 700; color: var(--lime); }
.north svg { width: 14px; height: 20px; display: block; margin: 2px auto 0; }

.map-stats { display: grid; grid-template-columns: repeat(4, auto); gap: 4px 22px; background: #11161dd9; backdrop-filter: blur(6px); border: 1px solid #ffffff22; border-radius: 10px; padding: 10px 16px; }
.map-stats .label { font-size: 10px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.map-stats .value { font-family: var(--mono); font-size: 24px; font-weight: 600; }
.map-coords, .map-cursor { background: #11161dd9; border: 1px solid #ffffff22; border-radius: 8px; padding: 6px 10px; font-size: 12px; font-family: var(--mono); color: var(--muted); }
.map-cursor { color: var(--text); white-space: nowrap; }
.map-mode { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); z-index: 600; background: var(--lime); color: #11161d; font-weight: 600; padding: 6px 14px; border-radius: 99px; font-size: 13px; box-shadow: 0 4px 14px #0008; }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { background: #11161dcc !important; color: var(--muted) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--muted) !important; }

/* Сектор диаграммы и анимации */
.beam-fill { fill: var(--lime); fill-opacity: .16; stroke: var(--lime); stroke-width: 2; stroke-opacity: .9; }
.beam-sweep { fill: var(--lime); fill-opacity: .0; stroke: none; animation: sweep 2.4s ease-out infinite; transform-box: fill-box; }
@keyframes sweep { 0% { fill-opacity: .28; } 100% { fill-opacity: 0; } }
.beam-axis { stroke: var(--lime); stroke-width: 2; stroke-dasharray: 8 10; animation: dash 0.9s linear infinite; fill: none; }
@keyframes dash { to { stroke-dashoffset: -18; } }
.beam-target { fill: #f0b429; fill-opacity: .06; stroke: #f0b429; stroke-width: 1.5; stroke-dasharray: 6 6; }
.range-ring { fill: none; stroke: #ffffff30; stroke-width: 1; stroke-dasharray: 3 6; }
.aim-line { stroke: #f0b429; stroke-width: 2; stroke-dasharray: 4 6; fill: none; }
/* position задаёт Leaflet (absolute) — не переопределять, иначе маркеры съезжают друг за другом */
.station-icon { background: none; border: none; }
.station-icon .core { position: absolute; left: 50%; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%; background: #f85149; border: 3px solid #fff; box-shadow: 0 0 0 2px #f8514966, 0 2px 8px #000a; }
.station-icon .pulse { position: absolute; left: 50%; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%; border: 2px solid #f85149; animation: pulse 2s ease-out infinite; }
.station-icon .pulse.p2 { animation-delay: 1s; }
@keyframes pulse { 0% { transform: scale(1); opacity: .9; } 100% { transform: scale(4.5); opacity: 0; } }
.target-icon { width: 18px; height: 18px; border: 2px solid #f0b429; border-radius: 50%; background: #f0b42933; box-shadow: 0 0 0 4px #f0b42922; }

/* Панель поворотки справа */
.ptz-status { color: var(--ok); font-size: 13px; margin: -6px 0 10px; }
.ptz-status.warn { color: var(--warn); }
.ptz-status.bad { color: var(--bad); }
.readout .value { font-size: 34px; }
.btn.accent { background: var(--lime); border-color: var(--lime); color: #11161d; font-weight: 600; }
.btn.accent:hover:not(:disabled) { border-color: #fff; }
.btn.full, .goto .full { grid-column: 1 / -1; width: 100%; }
.goto { grid-template-columns: 1fr 1fr; }
.manual { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.manual-title { font-weight: 600; }
.manual-body { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.manual #joystick { width: 150px; flex: none; }
.manual .dpad { grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 40px); }
.btn.stop.full { background: #3a1417; border-color: #6e2227; color: #ffb4b0; padding: 10px; }
.btn.stop.full:hover { background: var(--bad); color: #fff; }
.tilt-mini { display: flex; align-items: center; gap: 12px; border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
.tilt-mini svg { width: 90px; flex: none; cursor: crosshair; }

/* Усилитель внизу */
.amp-card .amp-head { flex-wrap: wrap; }
.amp-body { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(240px, 1fr); gap: 16px; }
.amp-body .amp-controls { grid-template-columns: 1fr; margin-top: 0; align-content: start; }
@media (max-width: 800px) { .amp-body { grid-template-columns: 1fr; } }

/* ================================================================ Рельеф и прямая видимость */
.top-left { flex-direction: column; align-items: flex-start; max-width: min(420px, calc(100% - 24px)); }
.top-left-row { display: flex; gap: 8px; }
.los-panel { width: min(420px, calc(100vw - 60px)); background: #11161dee; backdrop-filter: blur(8px); border: 1px solid #ffffff22; border-radius: 12px; padding: 12px; box-shadow: 0 8px 24px #0009; max-height: calc(100% - 70px); overflow: auto; }
.los-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.icon-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 16px; }
.los-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.los-field { position: relative; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px 6px; background: #0d1117; min-width: 0; }
.los-field span { font-size: 11px; color: var(--muted); white-space: nowrap; }
.los-field input, .los-field select { border: none; background: none; padding: 0; font-size: 18px; font-family: var(--mono); width: 100%; }
.los-field select { font-size: 13px; font-family: inherit; padding: 4px 0; }
.los-field i { position: absolute; right: 8px; bottom: 7px; font-style: normal; color: var(--muted); font-size: 12px; }
.los-az { grid-column: span 2; background: #0d1117; border: 1px solid var(--line); border-radius: 8px; color: var(--lime); cursor: pointer; font-size: 13px; letter-spacing: .5px; }
.los-az.active { border-color: var(--lime); background: #1f2614; }
.los-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.los-actions .switch { margin-right: auto; font-size: 12px; color: var(--muted); }
.switch.small input { width: 14px; height: 14px; }
.los-status { font-size: 12px; color: var(--muted); margin-top: 8px; font-family: var(--mono); }
.los-status.error { color: #ffb4b0; }
.los-profile canvas { width: 100%; height: 170px; display: block; margin-top: 10px; background: #0b0f14; border: 1px solid var(--line); border-radius: 8px; }
.los-overlay { image-rendering: auto; }
#btn-los.active { background: var(--lime); color: #11161d; border-color: var(--lime); font-weight: 600; }
@media (max-width: 700px) { .los-grid { grid-template-columns: repeat(2, 1fr); } }
.map-overlay.top-left { z-index: 520; }
.los-panel { max-height: calc(clamp(360px, 58vh, 640px) - 70px); }

/* ================================================================ Адаптивная раскладка: карте — максимум места */
:root { --header-h: 50px; --side-w: 380px; }
main { max-width: none; padding: 12px; }
main:has(#tab-control:not(.hidden)) { padding-bottom: 0; }
#tab-log, #tab-settings { max-width: 1600px; margin: 0 auto; }
.map-head { margin-bottom: 8px; align-items: center; }
.map-title { margin: 0; font-size: 16px; }
.map-card { padding: 10px 12px 12px; display: flex; flex-direction: column; }
.amp-summary { color: var(--muted); font-size: 13px; min-width: 0; }
.amp-summary b { color: var(--text); font-weight: 600; }
.amp-card.collapsed .amp-body { display: none; }
.amp-card.collapsed .amp-head { margin-bottom: 0; }
.amp-card { padding: 10px 14px; }

@media (min-width: 1101px) {
  .layout { grid-template-columns: minmax(0, 1fr) var(--side-w); height: calc(100dvh - var(--header-h) - 24px); }
  .main-col { height: 100%; gap: 12px; }
  .map-card { flex: 1 1 auto; min-height: 320px; }
  .map-wrap { flex: 1 1 auto; height: auto; min-height: 0; }
  .amp-card { flex: none; max-height: 55%; overflow: auto; }
  .side-col { height: 100%; overflow-y: auto; gap: 12px; padding-right: 2px; scrollbar-width: thin; scrollbar-color: #2a3441 transparent; }
  .los-panel { max-height: calc(100dvh - var(--header-h) - 190px); }
}
@media (min-width: 1800px) { :root { --side-w: 420px; } }
@media (max-width: 1100px) {
  .map-wrap { height: 70vh; min-height: 380px; }
  .los-panel { max-height: calc(70vh - 70px); }
}
@media (max-width: 700px) {
  .map-wrap { height: 75vh; }
  .amp-summary { display: none; }
  header { gap: 8px; }
  .pills { order: 3; width: 100%; margin-left: 0; }
}

/* Полноэкранная карта */
.map-card.fullscreen { position: fixed; inset: 0; z-index: 1000; border-radius: 0; padding: 0; border: none; }
.map-card.fullscreen .map-head { display: none; }
.map-card.fullscreen .map-wrap { height: 100dvh !important; border-radius: 0; border: none; }
.map-card.fullscreen .los-panel { max-height: calc(100dvh - 80px); }
#btn-fullscreen.active { background: var(--lime); color: #11161d; }

/* ================================================================ Бренд */
.brand { display: flex; align-items: center; gap: 14px; color: var(--text); text-decoration: none; }
.brand-logo { height: 22px; width: auto; display: block; }
.brand-name { font-size: 19px; font-weight: 700; letter-spacing: .5px; padding-left: 14px; border-left: 1px solid var(--line); line-height: 1.2; }
#sim-chip { font-weight: 600; letter-spacing: 1px; font-size: 11px; }
.login-logo { height: 30px; width: auto; display: block; margin: 6px auto 22px; }
.login-card h1 { font-size: 22px; }
@media (max-width: 700px) { .brand-logo { height: 16px; } .brand-name { font-size: 16px; padding-left: 10px; } }

/* ================================================================ Парк устройств (многостанционный портал) */
:root { --fleet-w: 270px; }
@media (min-width: 1101px) {
  .layout { grid-template-columns: var(--fleet-w) minmax(0, 1fr) var(--side-w); }
  .fleet-col { height: 100%; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #2a3441 transparent; }
}
@media (min-width: 1800px) { :root { --fleet-w: 300px; } }
@media (max-width: 1100px) { .fleet-col { order: -1; } .fleet-list { max-height: 240px; } }
.fleet-col { min-width: 0; }
.fleet-card { min-height: 100%; }
.fleet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.fleet-head h2 { margin: 0; }
#fleet-search { width: 100%; margin-bottom: 8px; }
.fleet-list { display: flex; flex-direction: column; gap: 4px; }
.fleet-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 2px 8px; align-items: center; padding: 7px 9px;
  border: 1px solid transparent; border-radius: 8px; cursor: pointer; background: var(--panel-2); user-select: none; }
.fleet-item:hover { border-color: var(--line); }
.fleet-item.active { border-color: var(--lime); background: #1f2614; }
.fleet-item.in-sel { border-color: #6b7d3a; }
.fleet-item .fi-name { font-weight: 600; overflow-wrap: anywhere; }
.fleet-item .fi-meta { grid-column: 2 / 4; font-size: 11px; color: var(--muted); font-family: var(--mono);
  display: flex; flex-wrap: wrap; gap: 1px 10px; line-height: 1.5; }
.fleet-item .fi-meta .m-lock, .fleet-item .fi-meta .warn { color: #f5d68a; }
.fleet-item .fi-meta .bad { color: #ffb4b0; }
.fleet-item .fi-right { font-size: 11px; font-family: var(--mono); color: var(--muted); }
.fleet-item.offline .fi-name { color: var(--muted); }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.amp-dot { display: inline-block; font-size: 10px; padding: 0 5px; border-radius: 4px; border: 1px solid var(--line); }
.amp-dot.on { color: #7ee79a; border-color: #23633a; }
.amp-dot.fault { color: #ffb4b0; border-color: #6e2227; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--warn); color: #11161d; font-size: 11px; font-weight: 700; text-align: center; }

.sel-card { padding: 12px 14px; }
.sel-head { display: flex; align-items: center; gap: 10px; }
.sel-swatch { width: 12px; height: 34px; border-radius: 4px; background: var(--line); flex: none; }
.sel-titles { flex: 1; min-width: 0; }
.sel-kind { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.sel-name { font-size: 18px; font-weight: 700; overflow-wrap: anywhere; line-height: 1.25; }
.sel-card .ptz-status { margin: 8px 0 0; }

table.members { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 8px; }
table.members th { text-align: left; color: var(--muted); font-weight: 500; padding: 4px 6px; border-bottom: 1px solid var(--line); }
table.members td { padding: 5px 6px; border-bottom: 1px solid #1e2631; font-family: var(--mono); }
table.members td.nm { font-family: inherit; font-weight: 600; overflow-wrap: anywhere; }
table.members tr.offline td { color: var(--muted); }
.group-amp { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 10px; }
.group-amp .row .btn { flex: 1; }

/* Таблицы администратора */
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: 7px 8px; border-bottom: 1px solid #1e2631; vertical-align: middle; }
.data-table td.mono { font-size: 12px; }
.data-table .actions { display: flex; gap: 4px; justify-content: flex-end; flex-wrap: wrap; }
.status-tag { font-size: 11px; padding: 2px 7px; border-radius: 5px; border: 1px solid var(--line); white-space: nowrap; }
.status-tag.approved { color: #7ee79a; border-color: #23633a; }
.status-tag.pending { color: #f5d68a; border-color: #7a5d17; }
.status-tag.rejected { color: #ffb4b0; border-color: #6e2227; }
.pending-item { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 12px; border: 1px solid #7a5d17; background: #2a220d; border-radius: 8px; margin-bottom: 8px; }
.pending-item .pid { font-size: 18px; font-weight: 700; font-family: var(--mono); }
.pending-item .meta { color: var(--muted); font-size: 12px; font-family: var(--mono); flex: 1; min-width: 200px; }
.user-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid #1e2631; }
.user-row .un { font-weight: 600; min-width: 120px; }
.user-row .ud { flex: 1; min-width: 160px; font-size: 12px; color: var(--muted); }
.settings-target { margin-bottom: 16px; }
.settings-target select { min-width: 220px; }

/* Модальное окно */
.modal { position: fixed; inset: 0; z-index: 2000; background: #000a; display: grid; place-items: center; padding: 16px; }
.modal-box { width: min(520px, 100%); max-height: calc(100dvh - 32px); overflow: auto; }
.modal-actions { justify-content: flex-end; margin-top: 14px; }
.check-list { display: flex; flex-direction: column; gap: 4px; max-height: 50vh; overflow: auto; margin-top: 8px; }
.check-list label { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--panel-2); border-radius: 6px; cursor: pointer; }
.check-list label .muted { margin-left: auto; font-size: 11px; font-family: var(--mono); }
.color-row { display: flex; gap: 6px; margin-top: 8px; }
.color-row button { width: 26px; height: 26px; border-radius: 6px; border: 2px solid transparent; cursor: pointer; }
.color-row button.active { border-color: #fff; }

/* Станции на карте: выбранные яркие, остальные приглушены, без связи — серые */
.station-label { background: #11161dd9 !important; color: var(--text) !important; border: 1px solid #ffffff22 !important; border-radius: 6px !important;
  font-size: 11px !important; font-weight: 600; padding: 1px 6px !important; box-shadow: none !important; }
.station-label::before { display: none !important; }
.station-icon.dim .core { background: #8b98a8; box-shadow: 0 0 0 2px #0006; }
.station-icon.dim .pulse { display: none; }
.station-icon.offline .core { background: #4a5563; border-color: #8b98a8; }
.station-icon.offline .pulse { display: none; }
.station-icon.primary .core { width: 20px; height: 20px; margin: -10px 0 0 -10px; }
path.beam-fill.dim { fill-opacity: .06; stroke-opacity: .45; stroke-width: 1.2; }
path.beam-sweep.dim, path.beam-axis.dim { display: none; }
path.beam-fill.offline { stroke: #8b98a8; fill: #8b98a8; stroke-dasharray: 4 5; }
path.range-ring.dim { display: none; }

/* ================================================================ Усилители группы под картой */
.amp-grid-card { flex: none; padding: 10px 12px 12px; }
.amp-grid-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.amp-grid-head h2 { margin: 0; }
.amp-grid-head .muted { font-size: 12px; }
/* Колонки задаются из JS: до 7 в ряд, ряды делятся поровну */
.amp-grid { display: grid; gap: 8px; grid-template-columns: repeat(var(--cols, 7), minmax(0, 1fr)); }
@media (max-width: 900px) { .amp-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }
.amp-tile { background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.amp-tile.on { border-color: #23633a; }
.amp-tile.fault { border-color: var(--bad); background: #2a1416; }
.amp-tile.offline { opacity: .6; }
.amp-tile-head { display: flex; align-items: center; gap: 6px; min-width: 0; }
.amp-tile-name { font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; cursor: pointer; line-height: 1.25; }
.amp-tile-more { background: none; border: 1px solid transparent; color: var(--muted); border-radius: 6px; cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 6px; }
.amp-tile-more:hover { border-color: var(--line); color: var(--text); }
.amp-tile-state { font-size: 11px; font-weight: 700; letter-spacing: .5px; color: var(--muted); }
.amp-tile.on .amp-tile-state { color: #7ee79a; }
.amp-tile.fault .amp-tile-state { color: #ffb4b0; }
.amp-tile-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.amp-tile-metrics > div { min-width: 0; }
.amp-tile-metrics .l { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.amp-tile-metrics .v { font-family: var(--mono); font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }
.amp-tile-metrics .v small { font-size: 10px; color: var(--muted); font-weight: 400; }
.amp-tile-metrics .warn { color: #f5d68a; }
.amp-tile-metrics .bad { color: #ffb4b0; }
.amp-tile .bar { margin-top: 0; }

/* Полная информация об усилителе — полупрозрачное окно поверх портала */
.amp-overlay { position: fixed; inset: 0; z-index: 1500; background: #0d1117b3; backdrop-filter: blur(3px); display: grid; place-items: center; padding: 16px; }
.amp-ov-box { width: min(880px, 100%); max-height: calc(100dvh - 32px); overflow: auto; background: #151b23e6; border: 1px solid #ffffff26;
  border-radius: 14px; padding: 16px 18px; box-shadow: 0 20px 60px #000a; }
.amp-ov-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.amp-ov-titles { flex: 1; min-width: 0; }
.amp-ov-close { font-size: 20px; padding: 4px 8px; }
.amp-ov-sec { margin-bottom: 14px; }
.amp-ov-sec h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 0 0 6px; font-weight: 600; }
.amp-ov-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 700px) { .amp-ov-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.amp-ov-grid .metric { background: #1c2430cc; }
.amp-ov-controls { border-top: 1px solid var(--line); padding-top: 12px; }
.amp-ov-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.amp-ov-inputs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.amp-ov-inputs input { width: 100%; }
@media (max-width: 700px) { .amp-ov-inputs { grid-template-columns: 1fr; } }
.amp-ov-foot { font-size: 12px; color: var(--muted); font-family: var(--mono); }

/* ================================================================ Контроллер (Pi) */
.host-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.host-metrics .value { font-size: 18px; }
.host-metrics .value.v-text { font-size: 14px; font-family: inherit; white-space: normal; }
.host-metrics .value small { font-size: 11px; color: var(--muted); font-weight: 400; }
.host-metrics .warn, .kv .warn, td .warn { color: #f5d68a; }
.host-metrics .bad { color: #ffb4b0; }
.host-metrics .metric.warn { border-color: var(--warn); }
.host-metrics .metric.bad { border-color: var(--bad); }
.host-issues { margin-top: 8px; font-size: 12px; color: #f5d68a; min-height: 0; }
.host-issues:empty { display: none; }
table.kv { width: 100%; border-collapse: collapse; font-size: 13px; }
table.kv td, table.kv th { padding: 5px 8px; border-bottom: 1px solid #1e2631; text-align: left; vertical-align: top; }
table.kv td:first-child { color: var(--muted); width: 38%; }
table.kv th { color: var(--muted); font-weight: 500; font-size: 12px; }
table.kv.ifaces { margin-top: 8px; }
table.kv.ifaces td:first-child { width: auto; color: var(--text); font-family: var(--mono); }
td .bad { color: #ffb4b0; }

/* Подключение с другого оборудования */
.pending-item.hw-changed { border-color: var(--bad); background: #2a1416; }
.hw-alert { flex-basis: 100%; order: 3; color: #ffb4b0; font-size: 13px; padding: 8px 10px; border: 1px solid #6e2227; border-radius: 6px; background: #3a1417; }
.pending-item .btn { order: 4; }
.hw-alert.ok { color: #a7f3b5; border-color: #23633a; background: #12301a; }

/* ================================================================ Устройство не привязано к оборудованию */
.lock-banner { display: flex; align-items: center; gap: 10px; margin-top: 10px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid #7a5d17; background: #2a220d; color: #f5d68a; font-size: 13px; }
.lock-banner span { flex: 1; }
.fleet-item.locked:not(.active) { border-color: #5c4a1a; }
/* Всё, что двигает поворотку и включает усилитель, неактивно; «Остановить» и «Выключить» остаются */
body.ctl-locked #goto-form, body.ctl-locked .nudge, body.ctl-locked #tiltgauge,
body.ctl-locked #manual-card .manual-body, body.ctl-locked #manual-card .speed,
body.ctl-locked #group-goto-form, body.ctl-locked #grp-allow, body.ctl-locked #grp-amp-on,
body.ctl-locked #amp-on, body.ctl-locked #amp-allow, body.ctl-locked .amp-controls,
body.ctl-locked #presets .btn.primary, body.ctl-locked #preset-form, body.ctl-locked #btn-aim {
  opacity: .4; pointer-events: none; filter: grayscale(.6);
}

/* ================================================================ Таблица устройств: действия в одну строку,
   на узком экране — карточки с подписями и кнопками на всю ширину */
#tab-devices .card { container: devtable / inline-size; }
.data-table td.act { width: 1%; white-space: nowrap; }
.data-table .actions { flex-wrap: nowrap; justify-content: flex-end; }
@container devtable (max-width: 1500px) {
  .data-table thead { display: none; }
  .data-table, .data-table tbody { display: block; }
  .data-table tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 16px;
    padding: 12px 14px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
  .data-table td { border: none; padding: 0; min-width: 0; overflow-wrap: anywhere; }
  .data-table td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 2px; font: 500 10px/1.4 "Segoe UI", system-ui, sans-serif;
    letter-spacing: .6px; text-transform: uppercase; color: var(--muted); }
  .data-table td.act { grid-column: 1 / -1; width: auto; white-space: normal; border-top: 1px solid var(--line); padding-top: 10px; }
  .data-table td.act .actions { flex-wrap: wrap; justify-content: flex-start; gap: 6px; }
  .data-table td.act .btn { flex: 1 1 auto; }
}
.nowrap { white-space: nowrap; }
/* Телефон: вкладки меню переносятся на отдельную строку, страница не растягивается вбок */
@media (max-width: 700px) {
  nav { order: 2; width: 100%; flex-wrap: wrap; }
  nav button { padding: 6px 10px; }
  .user { margin-left: auto; }
}

/* Группы: карандаш в списке и кнопки редактирования вверху карточки */
.fi-edit { background: none; border: 1px solid transparent; color: var(--muted); cursor: pointer; border-radius: 6px;
  padding: 0 5px; font-size: 13px; line-height: 1.4; margin-left: 2px; }
.fi-edit:hover { border-color: var(--line); color: var(--text); background: var(--panel); }
.group-actions { display: flex; gap: 6px; flex-wrap: wrap; margin: -4px 0 10px; }

/* ================================================================ Координаты: поиск, точка на карте */
.map-head { flex-wrap: wrap; }
.coord-search { display: flex; gap: 6px; flex: 1 1 260px; max-width: 480px; margin: 0 auto 0 16px; }
.coord-search input { flex: 1; min-width: 0; font-family: var(--mono); font-size: 13px; padding: 5px 8px; }
@media (max-width: 700px) { .coord-search { margin: 0; order: 3; flex-basis: 100%; max-width: none; } }
.point-icon { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; box-shadow: 0 0 0 4px #3fa7ff44, 0 2px 8px #000a; }
.leaflet-popup.point-popup .leaflet-popup-content-wrapper { background: #151b23f2; color: var(--text); border: 1px solid #ffffff26; border-radius: 10px; box-shadow: 0 10px 30px #000a; }
.leaflet-popup.point-popup .leaflet-popup-tip { background: #151b23f2; }
.leaflet-popup.point-popup .leaflet-popup-content { margin: 12px 14px 10px; font-size: 13px; line-height: 1.4; }
.leaflet-popup.point-popup a.leaflet-popup-close-button { color: var(--muted); }
.pt-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 4px 0; border-bottom: 1px solid #1e2631; }
.pt-row span { color: var(--muted); font-size: 11px; white-space: nowrap; }
.pt-row b { font-size: 12px; text-align: right; font-weight: 600; }
.pt-row.cur b { color: var(--lime); }
.pt-rel { margin-top: 6px; font-size: 12px; color: var(--muted); }
.pt-rel b { color: var(--text); }
.pt-actions { display: flex; gap: 6px; margin-top: 10px; }
.pt-actions .btn { flex: 1; }
/* Группы пользователя в окне администратора */
.ug-list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow: auto; }
.ug-list .list-item { align-items: flex-start; }
.ug-list .swatch { margin-top: 5px; flex: none; }

/* Чужие действия на общем устройстве — без имени, курсивом */
.log-table td.log-other { font-style: italic; color: var(--muted); }

/* ================================================================ Программное обеспечение агента */
.ver-badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 5px; border: 1px solid var(--line); white-space: nowrap; margin-left: 4px; }
.ver-badge.ok { color: #7ee79a; border-color: #23633a; }
.ver-badge.new { color: #11161d; background: var(--lime); border-color: var(--lime); font-weight: 600; }
.ver-badge.old { color: #f5d68a; border-color: #7a5d17; }
.ver-badge.busy { color: #9ecbff; border-color: var(--accent-2); }
.sw-current { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.sw-notes { white-space: pre-wrap; font-size: 13px; margin-top: 6px; color: var(--text); }
.list-item .sw-notes { color: var(--muted); font-size: 12px; }
.sw-admin { margin-top: 14px; }
.sw-upload { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sw-upload input[type=text] { flex: 1 1 280px; }
.sw-upload input[type=file] { color: var(--muted); font-size: 13px; max-width: 100%; }
#software-card { margin-bottom: 16px; }
#pending-card { margin-bottom: 16px; }
code { font-family: var(--mono); font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
