/* Relay Control — дизайн-система панели. Светлая/тёмная тема, адаптив от 320 px. */
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --line: #e4e7ee;
  --line-strong: #d3d8e2;
  --text: #121826;
  --text-2: #4a5468;
  --muted: #7a8396;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --on-accent: #ffffff;
  --ok: #16a34a;     --ok-soft: #e6f6ec;
  --warn: #d97706;   --warn-soft: #fdf2e1;
  --bad: #dc2626;    --bad-soft: #fde8e8;
  --idle: #94a3b8;   --idle-soft: #eef1f5;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --surface: #121a2b; --surface-2: #172036; --line: #222d44; --line-strong: #2d3a55;
    --text: #e7ecf5; --text-2: #b4bed0; --muted: #8290a8;
    --accent: #5b8cff; --accent-soft: #1a2747; --on-accent: #fff;
    --ok: #34c56b; --ok-soft: #12301f; --warn: #f0a531; --warn-soft: #34260f;
    --bad: #f26060; --bad-soft: #3a1717; --idle: #66748c; --idle-soft: #1b2438;
    --shadow: 0 1px 2px rgba(0,0,0,.3); --shadow-lg: 0 16px 40px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --surface: #121a2b; --surface-2: #172036; --line: #222d44; --line-strong: #2d3a55;
  --text: #e7ecf5; --text-2: #b4bed0; --muted: #8290a8;
  --accent: #5b8cff; --accent-soft: #1a2747; --on-accent: #fff;
  --ok: #34c56b; --ok-soft: #12301f; --warn: #f0a531; --warn-soft: #34260f;
  --bad: #f26060; --bad-soft: #3a1717; --idle: #66748c; --idle-soft: #1b2438;
  --shadow: 0 1px 2px rgba(0,0,0,.3); --shadow-lg: 0 16px 40px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 600; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- Шапка и навигация ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 24px;
  height: 56px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; }
.brand-mark svg { width: 18px; height: 18px; stroke-width: 2.4; }
.nav { display: flex; gap: 4px; height: 100%; }
.nav a { display: flex; align-items: center; gap: 8px; padding: 0 12px; color: var(--text-2); font-weight: 500; border-bottom: 2px solid transparent; }
.nav a:hover { color: var(--text); text-decoration: none; }
.nav a.active { color: var(--accent); border-bottom-color: var(--accent); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.live { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.live.err i { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.menu-pop { position: absolute; right: 0; top: 42px; min-width: 210px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); }
.menu-pop a, .menu-pop button { display: block; width: 100%; padding: 8px 10px; border: 0; background: none; color: var(--text); text-align: left; font: inherit; border-radius: 6px; cursor: pointer; }
.menu-pop a:hover, .menu-pop button:hover { background: var(--surface-2); text-decoration: none; }
.menu-user { padding: 8px 10px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }

.page { max-width: 1440px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }

/* ---------- Карточки, плитки ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head h2 { flex: 1; }
.card-body { padding: 16px; }
.tiles { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile { padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); cursor: pointer; text-align: left; font: inherit; color: inherit; }
.tile:hover { border-color: var(--line-strong); }
.tile.sel { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tile-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; }
.tile-value { font-size: 26px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 12px; color: var(--muted); }

/* ---------- Статусы ---------- */
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--idle); flex: none; }
.dot.online { background: var(--ok); } .dot.offline { background: var(--bad); }
.dot.error, .dot.alarm { background: var(--warn); } .dot.never { background: var(--idle); }
.dot.pulse { box-shadow: 0 0 0 0 currentColor; animation: pulse 2s infinite; color: var(--ok-soft); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 var(--ok-soft); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 550; background: var(--idle-soft); color: var(--text-2); white-space: nowrap; }
.badge.online, .badge.success { background: var(--ok-soft); color: var(--ok); }
.badge.offline, .badge.error, .badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.alarm, .badge.warning, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info, .badge.accent { background: var(--accent-soft); color: var(--accent); }
.tag { display: inline-block; padding: 0 6px; border: 1px solid var(--line); border-radius: 5px; font-size: 11px; color: var(--muted); }

/* Уровень сигнала GSM (CSQ 0–31) */
.signal { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.signal i { width: 3px; border-radius: 1px; background: var(--line-strong); }
.signal i:nth-child(1) { height: 25%; } .signal i:nth-child(2) { height: 50%; } .signal i:nth-child(3) { height: 75%; } .signal i:nth-child(4) { height: 100%; }
.signal.s1 i:nth-child(-n+1), .signal.s2 i:nth-child(-n+2), .signal.s3 i:nth-child(-n+3), .signal.s4 i:nth-child(-n+4) { background: var(--text-2); }
.signal.s1 i:nth-child(1) { background: var(--bad); }

/* ---------- Кнопки и поля ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: 500 14px var(--font); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger-text { color: var(--bad); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-2); min-width: 0; }
.field.grow { flex: 1; }
.input, select.input, textarea.input {
  height: 36px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: 14px var(--font); min-width: 0; width: 100%;
}
textarea.input { height: auto; min-height: 76px; padding: 8px 10px; font-family: var(--mono); font-size: 13px; resize: vertical; }
.input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; gap: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 6px; font: 500 13px var(--font); color: var(--text-2); cursor: pointer; white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.search { position: relative; flex: 1; min-width: 180px; max-width: 360px; }
.search svg { position: absolute; left: 10px; top: 9px; color: var(--muted); }
.search .input { padding-left: 34px; }

/* ---------- Сетка устройств ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.devgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.dev { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.dev.state-offline { border-top: 3px solid var(--bad); }
.dev.state-online { border-top: 3px solid var(--ok); }
.dev.state-alarm, .dev.state-error { border-top: 3px solid var(--warn); }
.dev.state-never { border-top: 3px solid var(--idle); }
.dev-head { display: flex; gap: 10px; padding: 14px 16px 10px; }
.dev-title { flex: 1; min-width: 0; }
.dev-title a { color: var(--text); font-weight: 600; font-size: 15px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev-addr { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 0 16px 12px; font-size: 12.5px; color: var(--text-2); }
.dev-meta .item { display: inline-flex; align-items: center; gap: 5px; }
.dev-meta svg { width: 14px; height: 14px; color: var(--muted); }
.relays { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--line); }
.relay { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px 12px; border-right: 1px solid var(--line); min-width: 0; }
.relay:last-child { border-right: 0; }
.relay-name { font-size: 11.5px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 4px; }
.switch { position: relative; width: 44px; height: 24px; border-radius: 999px; border: 0; background: var(--line-strong); cursor: pointer; transition: background .15s; padding: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
.switch.on { background: var(--ok); }
.switch.on::after { transform: translateX(20px); }
.switch.err { background: var(--warn); }
.switch.busy { opacity: .6; cursor: progress; }
.switch:disabled { cursor: not-allowed; opacity: .45; }
.relay-state { font-size: 11.5px; font-weight: 550; color: var(--text-2); }
.dev-foot { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--surface-2); margin-top: auto; }
.dev-foot .spacer { flex: 1; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.empty svg { width: 40px; height: 40px; color: var(--line-strong); margin-bottom: 8px; }
.empty code { background: var(--surface-2); padding: 2px 6px; border-radius: 5px; font-family: var(--mono); color: var(--text); }

/* ---------- Страница устройства ---------- */
.layout-2 { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.relay-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.relay-card { padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.relay-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.relay-card-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.relay-card .btn-row .btn { flex: 1; }
.lastdata { display: flex; gap: 14px; align-items: center; }
.lastdata-ago { font-size: 28px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 0 8px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 12px 12px 10px; font: 500 14px var(--font); color: var(--text-2); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line); }

/* ---------- Таблицы и журналы ---------- */
.table-wrap { overflow: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { position: sticky; top: 0; z-index: 1; background: var(--surface); text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.flash { animation: flash 1.4s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }
.hex { display: none; margin-top: 3px; font-family: var(--mono); font-size: 11px; color: var(--muted); word-break: break-all; }
.show-hex .hex { display: block; }
.dir { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.dir.in { color: var(--accent); } .dir.out { color: var(--ok); }
.dir svg { width: 13px; height: 13px; }
.more { display: flex; justify-content: center; padding: 12px; }
.timeline { list-style: none; margin: 0; padding: 4px 0; }
.timeline li { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 10px; padding: 9px 16px; border-bottom: 1px solid var(--line); align-items: start; }
.timeline li:last-child { border-bottom: 0; }
.timeline .ico { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--idle-soft); color: var(--text-2); }
.timeline .ico svg { width: 13px; height: 13px; }
.timeline .ico.success { background: var(--ok-soft); color: var(--ok); }
.timeline .ico.warning { background: var(--warn-soft); color: var(--warn); }
.timeline .ico.error { background: var(--bad-soft); color: var(--bad); }
.timeline .ico.info { background: var(--accent-soft); color: var(--accent); }
.timeline .when { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.timeline .who { color: var(--muted); font-size: 12px; }

/* ---------- Монитор ---------- */
.monitor { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.side-list { max-height: calc(100vh - 230px); overflow: auto; }
.side-item { display: block; width: 100%; text-align: left; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; font: inherit; color: inherit; cursor: pointer; }
.side-item:hover { background: var(--surface-2); }
.side-item.sel { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.side-item-top { display: flex; align-items: center; gap: 8px; }
.side-item-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.mini-relays { display: flex; gap: 3px; margin-top: 6px; }
.mini-relays span { font-size: 10.5px; padding: 0 6px; border-radius: 4px; background: var(--idle-soft); color: var(--muted); font-weight: 600; }
.mini-relays span.on { background: var(--ok-soft); color: var(--ok); }
.mini-relays span.er { background: var(--warn-soft); color: var(--warn); }
.broker-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.broker-bar .input { width: auto; min-width: 220px; max-width: 100%; }
.broker-info { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.broker-err { color: var(--bad); overflow-wrap: anywhere; }
.send-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.result { margin-top: 10px; font-size: 13px; min-height: 1.2em; }
.result.ok { color: var(--ok); } .result.err { color: var(--bad); } .result.wait { color: var(--muted); }
.log-wrap { max-height: calc(100vh - 430px); min-height: 280px; overflow: auto; }
details.box { border-top: 1px solid var(--line); }
details.box > summary { padding: 12px 16px; cursor: pointer; color: var(--text-2); font-weight: 500; }
details.box > div { padding: 0 16px 16px; display: grid; gap: 10px; }

/* ---------- Модальное окно ---------- */
dialog.modal { width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
dialog.modal::backdrop { background: rgba(10, 15, 30, .45); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-head h2 { flex: 1; }
.modal-body { padding: 16px; overflow: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--surface-2); }
.broker-row { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.broker-row:last-child { border-bottom: 0; }

/* ---------- Уведомления ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 11px 14px; border-radius: var(--radius-sm); background: var(--text); color: var(--surface); box-shadow: var(--shadow-lg); font-size: 13.5px; animation: toast-in .2s ease-out; }
.toast.ok { background: var(--ok); color: #fff; } .toast.err { background: var(--bad); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Вход ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(380px, 100%); padding: 28px; }
.auth-card .brand { justify-content: center; margin-bottom: 6px; font-size: 18px; }
.auth-card .sub { text-align: center; color: var(--muted); margin: 0 0 22px; }
.auth-card form { display: grid; gap: 14px; }
.auth-card .btn { height: 40px; }
.alert { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--bad-soft); color: var(--bad); font-size: 13.5px; }

/* ---------- Адаптив ---------- */
@media (max-width: 1100px) {
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .layout-2 { grid-template-columns: 1fr; }
  .layout-2 > .stack { display: contents; }
  .o-last { order: 1; } .o-relays { order: 2; } .o-lock { order: 3; } .o-bat { order: 4; } .o-comments { order: 5; } .o-logs { order: 6; } .o-info { order: 7; }
  .monitor { grid-template-columns: 1fr; }
  .side-list { max-height: 260px; }
  .log-wrap { max-height: none; }
}
@media (max-width: 760px) {
  .topbar { padding: 0 16px; gap: 12px; }
  .brand-name { display: none; }
  .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; height: calc(58px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
         background: var(--surface); border-top: 1px solid var(--line); justify-content: space-around; gap: 0; }
  .nav a { flex: 1 1 0; min-width: 0; padding: 0 2px; flex-direction: column; justify-content: center; gap: 2px; font-size: 11.5px; border-bottom: 0; border-top: 2px solid transparent;
           white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .nav a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .nav a.active { border-top-color: var(--accent); }
  .nav svg { width: 20px; height: 20px; }
  .page { padding: 16px 16px calc(80px + env(safe-area-inset-bottom)); }
  h1 { font-size: 19px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 12px; }
  .tile-value { font-size: 22px; }
  .devgrid { grid-template-columns: 1fr; }
  .relay-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .search { max-width: none; flex-basis: 100%; }
  .toasts { left: 16px; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom)); max-width: none; }
  .broker-bar .input { min-width: 0; flex: 1; }
  .live span { display: none; }
  /* журнал сообщений — карточками */
  .tbl.cards thead { display: none; }
  .tbl.cards, .tbl.cards tbody { display: block; }
  .tbl.cards tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
  .tbl.cards td { padding: 0; border: 0; }
  .tbl.cards td[data-c="time"] { grid-column: 1; }
  .tbl.cards td[data-c="dir"] { grid-column: 2; grid-row: 1; text-align: right; }
  .tbl.cards td[data-c="topic"] { grid-column: 1 / -1; }
  .tbl.cards td[data-c="data"] { grid-column: 1 / -1; }
  .tbl.cards td[data-c="act"] { grid-column: 1 / -1; }
  .tbl.cards td:empty { display: none; }
  .timeline li { grid-template-columns: 22px minmax(0, 1fr); }
  .timeline .when { grid-column: 2; }
}
@media (max-width: 420px) {
  .relay-cards { grid-template-columns: 1fr; }
  .seg button { padding: 5px 9px; }
}

/* ---------- АКБ ---------- */
.bat { display: inline-flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; }
.bat.ok { color: var(--ok); } .bat.warn { color: var(--warn); } .bat.bad { color: var(--bad); } .bat.raw { color: var(--muted); }
.bat svg { width: 15px; height: 15px; }
.bat-big { font-size: 30px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.1; }
.bat-scale { position: relative; height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--bad) 0%, var(--bad) 56%, var(--warn) 64%, var(--warn) 66%, var(--ok) 72%); /* 6–15 В: красный до 11,5 В, жёлтый до 12,2 В */ margin: 10px 0 4px; }
.bat-scale i { position: absolute; top: -4px; width: 4px; height: 16px; margin-left: -2px; border-radius: 2px; background: var(--text); box-shadow: 0 0 0 2px var(--surface); }
.bat-scale-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.chart { width: 100%; height: 120px; display: block; margin-top: 12px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart .area { fill: var(--accent-soft); opacity: .7; }
.chart text { font-size: 10px; fill: var(--muted); font-family: var(--font); }
.cal-row { display: flex; gap: 8px; align-items: flex-end; }
.cal-row .field { flex: 1; }
.fieldset { grid-column: 1 / -1; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; display: grid; gap: 10px; }
.fieldset legend { padding: 0 6px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.fieldset .hint { font-size: 12px; color: var(--muted); margin: 0; }
.pending-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.pending-row:last-child { border-bottom: 0; }
.card.attention { border-color: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); margin-bottom: 16px; }

/* ---------- Наклейки ---------- */
.labels-layout { grid-template-columns: minmax(0, 1fr) 420px; }
.label-canvas { width: 100%; height: auto; display: block; border: 1px dashed var(--line-strong); border-radius: 6px; background: #fff; }
.label-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.label-grid figure { margin: 0; }
.label-grid img { width: 100%; display: block; border: 1px solid var(--line); border-radius: 4px; background: #fff; }
.label-grid figcaption { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; margin-top: 4px; }
.label-grid .dup { color: var(--bad); }
.print-area { display: none; }
@media (max-width: 1100px) { .labels-layout { grid-template-columns: 1fr; } }
/* ---------- Пользователи ---------- */
.menu-user small { display: block; margin-top: 2px; color: var(--muted); font-size: 11.5px; }
.users-tbl { width: 100%; border-collapse: collapse; }
.users-tbl td { vertical-align: middle; }
.users-tbl .users-act { text-align: right; width: 1%; white-space: nowrap; }
.users-tbl tr.disabled-row td { opacity: .6; }
.roles-help { margin-top: 16px; }
.pass-row { display: flex; gap: 8px; }
.pass-row .input { flex: 1; min-width: 0; }
/* Пользователь (не администратор): добавление устройств и незарегистрированные устройства скрыты */
.role-user #b-add, .role-user #pending { display: none !important; }
.ro-note { font-size: 12px; white-space: nowrap; }
.ro-box { display: flex; align-items: center; min-height: 30px; }
.relay-card.is-lock { border-color: var(--accent); }
.relay-card .lock-btns .btn { flex: 1 1 auto; }
.pips i.lock { border-radius: 50%; }
.bat-type { font-size: 13px; font-weight: 500; margin-left: 6px; }
.nowrap { white-space: nowrap; }
/* права на реле в карточке пользователя */
.perm-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.perm-list { border: 1px solid var(--line); border-radius: var(--radius-sm); max-height: 46vh; overflow: auto; }
.perm-dev { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.perm-dev:last-child { border-bottom: 0; }
.perm-dev-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.perm-dev-head b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.perm-relays { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 12px; }
.perm-relay { display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 0; }
.perm-relay span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.perm-relay select.input { width: auto; height: 30px; padding: 0 6px; font-size: 12.5px; }
.perm-summary { font-size: 12.5px; color: var(--muted); }
.modal.wide { width: min(860px, calc(100vw - 32px)); max-width: none; }
/* длинная форма в окне: прокручивается тело, заголовок и кнопки остаются на месте */
dialog.modal[open] > form { display: flex; flex-direction: column; max-height: calc(100vh - 50px); }
dialog.modal > form > .modal-body { flex: 1 1 auto; min-height: 0; }
.check.full { grid-column: 1 / -1; white-space: normal; flex-wrap: wrap; row-gap: 2px; }
.check.full .hint { flex-basis: 100%; padding-left: 22px; font-size: 12px; color: var(--muted); }
.ov-sw .btn-row { flex-wrap: nowrap; justify-content: flex-end; gap: 6px; }
@media (max-width: 760px) { .ov-sw .btn-row { flex-direction: column; align-items: stretch; gap: 4px; } }

/* ---------- Главная: список устройств слева, реле справа ---------- */
.split { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; align-items: start; }
.split-side { position: sticky; top: 76px; overflow: hidden; }
.split-side .side-list { max-height: calc(100vh - 160px); }
.side-all { border-bottom: 1px solid var(--line-strong); }
.side-empty { padding: 16px 14px; font-size: 13px; }
.side-dev-meta { display: flex; align-items: center; gap: 8px; }
.side-dev-meta .spacer { flex: 1; }
.pips { display: inline-flex; gap: 3px; }
.pips i { width: 10px; height: 10px; border-radius: 3px; background: var(--line-strong); }
.pips i.on { background: var(--ok); } .pips i.err { background: var(--warn); }
.pips i.na { background: transparent; box-shadow: inset 0 0 0 1px var(--line-strong); }
.split-main { min-width: 0; }
.tbl.ov { width: 100%; border-collapse: collapse; }
.tbl.ov td { vertical-align: middle; }
.tbl.ov tr.ov-grp td { background: var(--surface-2); padding: 9px 12px; }
.ov-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ov-dev { display: inline-flex; align-items: center; gap: 8px; border: 0; background: none; padding: 0; font: inherit; color: var(--text); cursor: pointer; min-width: 0; }
.ov-dev b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ov-dev:hover b { color: var(--accent); text-decoration: underline; }
.dev-meta.ov-meta { padding: 0; margin-left: auto; gap: 10px; }
.tbl.ov tr.ov-relay td:first-child { padding-left: 30px; }
.ov-rname { font-weight: 550; }
.ov-rnum { font-size: 12px; }
.ov-ts { white-space: nowrap; font-size: 12.5px; }
.ov-sw { width: 1%; text-align: center; white-space: nowrap; }
.dev-panel.state-online { border-top: 3px solid var(--ok); }
.dev-panel.state-offline { border-top: 3px solid var(--bad); }
.dev-panel.state-alarm, .dev-panel.state-error { border-top: 3px solid var(--warn); }
.dev-panel.state-never { border-top: 3px solid var(--idle); }
.dev-panel-title { flex: 1; min-width: 0; }
.dev-panel-title h2 a { color: var(--text); }
.dev-panel-title .muted { font-size: 13px; margin-top: 2px; }
.dev-meta.dev-panel-meta { padding: 0 0 14px; }
.lock-row { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; margin-top: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 13.5px; }
.lock-row .spacer { flex: 1; }
.only-narrow { display: none; }
@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
  .split-side { display: none; }
  .only-narrow { display: inline-flex; }
}
@media (max-width: 760px) {
  .ov-ts { display: none; }
  .tbl.ov tr.ov-relay td:first-child { padding-left: 14px; }
  .dev-meta.ov-meta { margin-left: 0; flex-basis: 100%; }
  .hide-narrow { display: none; }
}

@media print {
  @page { margin: 8mm; }
  body { background: #fff !important; }
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: flex !important; flex-wrap: wrap; gap: 3mm; }
  .print-area img { display: block; break-inside: avoid; }
}

/* ---------- Карта устройств ---------- */
:root { --pin-green: #16a34a; --pin-red: #dc2626; --pin-yellow: #eab308; --pin-blue: #2563eb; --pin-purple: #9333ea; --purple-soft: #f3e8ff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --purple-soft: #2e1a47; } }
:root[data-theme="dark"] { --purple-soft: #2e1a47; }
.map-card { margin-bottom: 16px; overflow: hidden; }
.map-card .card-head { gap: 8px 14px; }
.map-card .card-head h2 { flex: 0 0 auto; }
.map-legend { flex: 1; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--text-2); }
.map-legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.map { height: 380px; background: var(--surface-2); z-index: 0; }
.map-card.collapsed .map-wrap { display: none; }
.map-note { padding: 8px 16px; font-size: 13px; color: var(--muted); }
.map-note:empty { display: none; }
.pin { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25), 0 1px 3px rgba(0,0,0,.35); flex: none; }
.map-pin-wrap { background: none; border: 0; }
.map-pin-wrap .pin { width: 20px; height: 20px; border-width: 3px; }
.map-pin-wrap .pin.sel { width: 26px; height: 26px; margin: -3px; box-shadow: 0 0 0 3px var(--accent), 0 2px 6px rgba(0,0,0,.4); }
.pin.c-green { background: var(--pin-green); } .pin.c-red { background: var(--pin-red); } .pin.c-yellow { background: var(--pin-yellow); }
.pin.c-blue { background: var(--pin-blue); } .pin.c-purple { background: var(--pin-purple); }
.map-pin-wrap .pin.c-purple { animation: pin-alarm 1.2s ease-in-out infinite; }
@keyframes pin-alarm { 0%, 100% { box-shadow: 0 0 0 0 rgba(147, 51, 234, .7); } 50% { box-shadow: 0 0 0 10px rgba(147, 51, 234, 0); } }
.map-pop { font: 13px var(--font); line-height: 1.45; min-width: 180px; }
.map-pop .muted { color: #6b7280; }
.map-alarm { margin: 4px 0; padding: 3px 8px; border-radius: 6px; background: var(--pin-purple); color: #fff; font-weight: 700; font-size: 12px; }
.map-open { display: inline-block; margin-top: 6px; font-weight: 600; }
.leaflet-container a.map-open { color: var(--pin-blue); }
/* тревога «взлом двери» */
.badge.breakin { background: var(--pin-purple); color: #fff; font-weight: 700; }
.dot.breakin { background: var(--pin-purple); }
.breakin-banner { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; margin-bottom: 14px; padding: 10px 14px;
  border: 1px solid var(--pin-purple); border-radius: var(--radius-sm); background: var(--purple-soft); color: var(--text); font-size: 13.5px; }
.breakin-banner b { color: var(--pin-purple); letter-spacing: .02em; }
.breakin-banner .spacer { flex: 1; }
#breakin .breakin-banner { margin-bottom: 16px; }
/* отключение реле в форме */
.relay-field .relay-off { font-size: 12px; color: var(--muted); white-space: normal; }
@media (max-width: 760px) { .map { height: 300px; } .map-legend { flex-basis: 100%; order: 3; } }

/* ---------- Монитор: симуляция устройств ---------- */
.sim-head { display: flex; align-items: center; gap: 8px; margin: 12px 0 6px; font-size: 13.5px; }
.sim-head .spacer { flex: 1; }
.sim-tbl { width: 100%; border-collapse: collapse; }
.sim-tbl td { vertical-align: middle; }
.sim-relays { display: flex; flex-wrap: wrap; gap: 4px; }
.sim-relay { min-width: 30px; height: 28px; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface-2);
  color: var(--text-2); font: 600 12.5px var(--font); cursor: pointer; }
.sim-relay.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.sim-relay.door.open { background: var(--warn); border-color: var(--warn); color: #fff; }
.sim-relay:disabled { opacity: .6; cursor: progress; }
@media (max-width: 760px) { #sim-form .field.grow { flex-basis: 100%; } #sim-form .field select.input { min-width: 0 !important; } }
.log-limit select.input { width: auto; height: 30px; padding: 0 6px; font-size: 12.5px; margin-left: 6px; }
/* карта справа вместо сводки реле (устройство не выбрано) */
.split-main .map-card { margin-bottom: 0; }
.split-main .map { height: max(420px, calc(100vh - 250px)); }
@media (max-width: 1100px) {
  .split:not(.has-sel) .split-side { display: block; order: 2; }  /* на узком экране — список под картой */
  .split .split-main { order: 1; }
  .split-side { position: static; }
  .split-main .map { height: 60vh; min-height: 320px; }
}
/* массовое изменение названий реле */
.role-user #b-bulk { display: none !important; }
.bulk-preview { font-size: 13px; color: var(--text-2); min-height: 18px; }
.bad-text { color: var(--bad); }
.link-btn { border: 0; background: none; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }

/* доступ пользователя к устройствам: номера вручную + одна строка на устройство */
.perm-ids { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.perm-ids .field.grow { flex: 1 1 220px; }
.perm-ids select.input { width: auto; }
.perm-dev-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 13.5px; cursor: default; }
.perm-dev-row:last-child { border-bottom: 0; }
.perm-dev-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.perm-dev-row select.input { width: auto; height: 32px; padding: 0 8px; font-size: 13px; }

/* версия устройства и контроль АКБ в формах */
.check.bat-monitor { white-space: normal; flex-wrap: wrap; row-gap: 2px; align-self: end; min-height: 36px; }
.check.bat-monitor .hint { flex-basis: 100%; padding-left: 22px; font-size: 12px; color: var(--muted); }

/* плата ver_5_1: отдельный замок */
.lock-row .lock-title { font-size: 13.5px; }
.pips i.lock-pip { width: 10px; height: 10px; border-radius: 50%; margin-left: 4px; background: var(--line-strong); }
.pips i.lock-pip.closed { background: var(--ok); } .pips i.lock-pip.open { background: var(--pin-blue); }
.pips i.lock-pip.na { background: transparent; box-shadow: inset 0 0 0 1px var(--line-strong); }

/* ---------- Резервные копии ---------- */
.backup-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 16px; align-items: start; }
.radio-list { display: grid; gap: 10px; }
.radio-list .check { white-space: normal; flex-wrap: wrap; align-items: baseline; }
.radio-list .hint { flex-basis: 100%; padding-left: 22px; font-size: 12px; color: var(--muted); }
pre.code { margin: 6px 0 12px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  font: 12.5px var(--mono); white-space: pre-wrap; word-break: break-all; }
.imp-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 12px 0 8px; font-size: 13.5px; }
.imp-tools .spacer { flex: 1; }
.imp-list { max-height: 50vh; border: 1px solid var(--line); border-radius: var(--radius-sm); }
@media (max-width: 1100px) { .backup-grid { grid-template-columns: 1fr; } }

/* ---------- Комментарии к устройству ---------- */
.comment-form { display: grid; gap: 8px; }
.comment-form textarea.input { font-family: var(--font); font-size: 13.5px; min-height: 58px; }
.comment-form .btn-row { justify-content: flex-end; }
.comments { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 10px; max-height: 420px; overflow: auto; }
.comments li { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.comment-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.comment-head b { color: var(--text-2); }
.comment-head .spacer { flex: 1; }
.comment-text { font-size: 13.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-del { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 12px; padding: 0; }
.comment-del:hover { color: var(--bad); }
.dev-comment { display: flex; gap: 6px; align-items: baseline; margin-top: 12px; font-size: 13px; color: var(--text-2); }
.dev-comment a { color: var(--accent); white-space: nowrap; }
.dev-comment .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* «Не принимать сообщения» (устройство версии 1) */
.block-banner { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; margin-bottom: 14px; padding: 10px 14px;
  border: 1px solid var(--warn); border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--text); font-size: 13.5px; }
.block-banner b { color: var(--warn); }
.block-banner .spacer { flex: 1; }
#mqtt-block .block-banner { margin-bottom: 16px; }

/* страница устройства: переход к соседним */
.crumbs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.dev-nav { display: inline-flex; align-items: center; gap: 8px; margin-left: 12px; }
.dev-nav .btn { height: 26px; font-size: 12.5px; }

/* тревога «АКБ ниже 6 В» и «отключено по питанию» */
:root { --power-off: #7c2d12; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --power-off: #c2410c; } }
:root[data-theme="dark"] { --power-off: #c2410c; }
.dot.bat_low { background: var(--bad); }
.dot.power_off { background: var(--power-off); }
.badge.power_off { background: color-mix(in srgb, var(--power-off) 14%, transparent); color: var(--power-off); }
.tile.lit[data-f="batlow"] { border-color: var(--bad); background: var(--bad-soft); box-shadow: 0 0 0 3px var(--bad-soft); }
.tile.lit[data-f="batlow"] .tile-value { color: var(--bad); }
.tile.lit[data-f="poweroff"] { border-color: var(--power-off); box-shadow: 0 0 0 3px color-mix(in srgb, var(--power-off) 18%, transparent); }
.tile.lit[data-f="poweroff"] .tile-value { color: var(--power-off); }
.tile.lit[data-f="batlow"] .tile-label .dot { animation: pin-alarm-red 1.2s ease-in-out infinite; }
@keyframes pin-alarm-red { 0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .6); } 50% { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); } }
.dev-panel.state-power_off { border-top: 3px solid var(--power-off); }

/* карта: кластер устройств без координат */
.map-pin-wrap .cluster { display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid #fff; color: #fff; font: 700 13px var(--font); box-shadow: 0 0 0 1px rgba(0,0,0,.25), 0 2px 6px rgba(0,0,0,.35); }
.cluster.c-green { background: var(--pin-green); } .cluster.c-red { background: var(--pin-red); } .cluster.c-yellow { background: var(--pin-yellow); }
.cluster.c-blue { background: var(--pin-blue); } .cluster.c-purple { background: var(--pin-purple); }
.cluster-list { max-height: 220px; overflow: auto; display: grid; gap: 2px; }
.cluster-row { display: flex; align-items: center; gap: 6px; padding: 3px 4px; border-radius: 6px; color: inherit !important; text-decoration: none; }
.cluster-row:hover { background: rgba(37, 99, 235, .08); }
.cluster-row span:first-of-type { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cluster-row .pin { width: 10px; height: 10px; border-width: 2px; }

/* главная: фильтр по пользователю (администратор) */
.user-filter { position: relative; display: inline-flex; align-items: center; }
.user-filter svg { position: absolute; left: 10px; width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.user-filter select.input { padding-left: 32px; width: auto; max-width: 320px; }
.user-filter select.input.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); color: var(--accent); font-weight: 600; }
@media (max-width: 760px) { .user-filter { flex-basis: 100%; } .user-filter select.input { max-width: none; width: 100%; } }

/* плитка «все реле выключены» (на связи) */
.dot.all_off { background: var(--pin-yellow); }

/* монтаж: не смонтировано / демонтировано (в ремонт) */
:root { --mount: #8b8fa3; }
.dot.not_mounted, .dot.repair { background: var(--mount); }
.badge.not_mounted, .badge.repair { background: color-mix(in srgb, var(--mount) 18%, transparent); color: var(--text-2); }
.dev-panel.state-not_mounted, .dev-panel.state-repair { border-top: 3px solid var(--mount); }
.pin.c-gray, .cluster.c-gray { background: var(--mount); }
.mount-field > span:first-child { font-size: 13px; font-weight: 550; }
.mount-checks { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.tile-sub b { font-weight: 650; color: var(--text); }
body:not(.role-admin) .admin-only { display: none !important; }

/* внешний API: пример запроса и страница описания */
.code-sample { margin: 8px 0 14px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--idle-soft); color: var(--text);
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-all; }
.api-doc { max-width: 980px; line-height: 1.55; }
.api-doc h1 { font-size: 22px; margin: 0 0 10px; } .api-doc h2 { font-size: 18px; margin: 26px 0 8px; } .api-doc h3 { font-size: 15.5px; margin: 20px 0 6px; }
.api-doc code { font: 12.5px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; padding: 1px 5px; border-radius: 4px; background: var(--idle-soft); }
.api-doc .doc-tbl { margin: 6px 0 12px; } .api-doc .doc-tbl td, .api-doc .doc-tbl th { vertical-align: top; }
.api-doc ul { padding-left: 22px; }

.api-https-warn { margin: 0 16px 14px; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--text); font-size: 13px; }

/* вкладка «Сервер» */
:root { --series-1: #2a78d6; --series-2: #eb6834; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --series-1: #3987e5; --series-2: #d95926; } }
:root[data-theme="dark"] { --series-1: #3987e5; --series-2: #d95926; }
.srv-tiles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.srv-tile { cursor: default; }
.srv-tile .tile-sub { margin-top: 6px; }
.meter { height: 6px; margin-top: 6px; border-radius: 3px; background: var(--idle-soft); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 3px; background: var(--ok); }
.meter i.warn { background: var(--warn); } .meter i.bad { background: var(--bad); }
.srv-charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.srv-charts .card, .srv-grid .card { margin: 0; }
.srv-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin: 16px 0; }
.chart { position: relative; padding: 6px 12px 10px; min-height: 180px; }
.chart svg { display: block; width: 100%; height: auto; overflow: hidden; stroke: none; stroke-width: 0; fill: none; }
.chart svg text { stroke: none; font-weight: 400; }
.chart .hit { stroke: none; }
.chart .dot { opacity: 0; } .chart.hover .dot { opacity: 1; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .ln.s1, .chart .dot.s1 { stroke: var(--series-1); } .chart .ln.s2, .chart .dot.s2 { stroke: var(--series-2); }
.chart .dot { fill: var(--surface); stroke-width: 2; }
.chart .xh { stroke: var(--line-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart-legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-2); padding: 0 0 4px 40px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.sw.s1 { background: var(--series-1); } .sw.s2 { background: var(--series-2); }
.chart-tip { position: absolute; top: 28px; z-index: 5; pointer-events: none; padding: 7px 10px; border-radius: var(--radius-sm); font-size: 12.5px;
  background: var(--surface); color: var(--text); border: 1px solid var(--line-strong); box-shadow: var(--shadow-lg); white-space: nowrap; }
.chart-empty { padding: 50px 16px; text-align: center; color: var(--muted); font-size: 13px; }
.chart-now { font-size: 12.5px; }
.srv-warns { display: grid; gap: 8px; margin-bottom: 16px; }
.srv-warn { padding: 9px 14px; border-radius: var(--radius-sm); font-size: 13.5px; border: 1px solid var(--line); background: var(--surface); }
.srv-warn.bad { border-color: var(--bad); background: var(--bad-soft); }
.srv-warn.warn { border-color: var(--warn); background: var(--warn-soft); }
.srv-warn.info { border-color: var(--accent); background: var(--accent-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 1200px) { .srv-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } .srv-grid { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .srv-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } .srv-charts { grid-template-columns: 1fr; } }
@media (max-width: 420px) { .nav a { font-size: 10px; letter-spacing: -.1px; } }
