:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --line: #e3e5ea;
  --accent: #2563eb;
  --ok: #16a34a;
  --warn: #d97706;
  --alert: #dc2626;
  --rec: #dc2626;
  --side: #111827;
  --side-text: #d1d5db;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b22;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --line: #2a2f3a;
    --side: #0a0c10;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h3 { font-size: 15px; margin-bottom: 10px; }

.layout { display: flex; min-height: 100vh; }
.sidebar { width: 200px; flex-shrink: 0; background: var(--side); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar .brand { color: #fff; font-size: 18px; font-weight: 700; padding: 4px 10px 16px; }
.sidebar a { color: var(--side-text); padding: 8px 10px; border-radius: 6px; display: flex; align-items: center; justify-content: space-between; }
.sidebar a.active, .sidebar a:hover { background: #1f2937; color: #fff; }
.sidebar .link { margin-top: auto; color: var(--side-text); text-align: left; padding: 8px 10px; }
main { flex: 1; min-width: 0; padding: 0 24px 24px; }
.topbar { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.bell { position: relative; font-size: 18px; background: none; border: 0; cursor: pointer; }
.bell .badge { position: absolute; top: -4px; right: -8px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.grid { display: grid; gap: 16px; }
.tiles { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.tile .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.tile .label, .muted { color: var(--muted); font-size: 13px; }
.cols { grid-template-columns: 2fr 1fr; align-items: start; }
@media (max-width: 1000px) { .cols { grid-template-columns: 1fr; } }

.devices { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.device-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.device-head .name { font-weight: 600; font-size: 15px; flex: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.dot.on { background: var(--ok); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--alert); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: var(--line); color: var(--text); }
.pill.rec { background: var(--rec); color: #fff; }
.pill.ok { background: var(--ok); color: #fff; }
.pill.warn { background: var(--warn); color: #fff; }
.pill.alert { background: var(--alert); color: #fff; }

.btn { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 6px; padding: 6px 12px; cursor: pointer; font: inherit; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--alert); }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
input, select { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--text); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
.day-row td { background: var(--bg); font-weight: 600; }
.thumb { width: 64px; height: 40px; object-fit: cover; border-radius: 4px; background: #000; display: block; }
.thumb.video { display: flex; align-items: center; justify-content: center; color: #fff; font-size: 16px; }

.events-list { list-style: none; margin: 0; padding: 0; }
.events-list li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.events-list li:last-child { border-bottom: 0; }
.events-list .time { color: var(--muted); font-size: 12px; white-space: nowrap; min-width: 92px; }
.events-list li.unread .msg { font-weight: 600; }
.sev { width: 4px; border-radius: 2px; background: var(--line); flex-shrink: 0; }
.sev.warn { background: var(--warn); }
.sev.alert { background: var(--alert); }

.live-grid { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }
.player { background: #000; border-radius: 10px; overflow: hidden; position: relative; aspect-ratio: 16 / 9; }
.player video { width: 100%; height: 100%; display: block; }
.live-tile .player { margin-bottom: 10px; }
.player .msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #9ca3af; }

/* isolation: z-index слоёв Leaflet (до 1000) не перекрывает рацию и уведомления */
.map-card { padding: 0; overflow: hidden; position: relative; isolation: isolate; }
#map { height: calc(100vh - 230px); min-height: 360px; }
.map-empty { position: absolute; left: 50%; top: 16px; transform: translateX(-50%); z-index: 1000;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; color: var(--muted); }

.chart { width: 100%; height: 180px; }
.chart rect.a { fill: var(--accent); }
.chart rect.b { fill: #93c5fd; }
.chart text { fill: var(--muted); font-size: 10px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.legend i.a { background: var(--accent); }
.legend i.b { background: #93c5fd; }
.bar { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; margin-top: 8px; }
.bar > div { height: 100%; background: var(--accent); }
.bar.warn > div { background: var(--warn); }

.ptt { position: sticky; bottom: 12px; margin-top: 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .12); }
.ptt-title { font-weight: 600; }
.ptt-talk { user-select: none; touch-action: none; min-width: 240px; }
.ptt.talking .ptt-talk { background: var(--rec); border-color: var(--rec); }
.ptt.receiving { border-color: var(--ok); box-shadow: 0 0 0 2px var(--ok); }
.ptt.receiving #ptt-status { color: var(--ok); font-weight: 600; }
.thumb.audio { display: flex; align-items: center; justify-content: center; color: #fff; font-size: 16px; background: #374151; }
#viewer-body audio { display: block; width: 420px; max-width: 90vw; margin: 8px 14px 16px; }

.form { display: grid; grid-template-columns: 260px 140px; gap: 10px 16px; align-items: center; }
.toasts { position: fixed; right: 16px; bottom: 90px; display: flex; flex-direction: column; gap: 8px; z-index: 10; }
.toast { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: 10px 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .15); max-width: 360px; }
.toast.warn { border-left-color: var(--warn); }
.toast.alert { border-left-color: var(--alert); }

dialog { border: 0; border-radius: 10px; padding: 0; max-width: 92vw; background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .7); }
.viewer-head { display: flex; justify-content: space-between; gap: 16px; padding: 10px 14px; }
#viewer-body video, #viewer-body img { display: block; max-width: 90vw; max-height: 80vh; }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 300px; display: flex; flex-direction: column; gap: 12px; }
.error { color: var(--alert); min-height: 1em; margin: 0; }
.empty { color: var(--muted); padding: 24px; text-align: center; }

@media (max-width: 700px) {
  .layout { flex-direction: column; }
  .sidebar { width: auto; flex-direction: row; flex-wrap: wrap; padding: 8px; }
  .sidebar .brand { display: none; }
  .sidebar .link { margin-top: 0; }
  main { padding: 0 12px 12px; }
  .live-grid { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }
}
