/* p_mon — оформление. Цвета — только токенами (светлая и тёмная темы) */
:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f0f2f5; --border: #d9dde3;
  --text: #1b1f24; --muted: #5f6b7a; --accent: #1f6feb; --accent-text: #ffffff;
  --ok: #1a7f37; --indoor: #8250df; --warn: #9a6700; --danger: #cf222e; --danger-bg: #ffebe9; --offline: #8c959f;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.12), 0 4px 16px rgb(0 0 0 / 0.06);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --surface: #171b21; --surface-2: #1f242b; --border: #2e353e;
    --text: #e6e9ed; --muted: #97a1ad; --accent: #4c8dff; --accent-text: #0b0e12;
    --ok: #3fb950; --indoor: #b083f0; --warn: #d29922; --danger: #ff6b6b; --danger-bg: #3a1d1f; --offline: #6e7681;
    --shadow: 0 1px 3px rgb(0 0 0 / 0.5), 0 4px 16px rgb(0 0 0 / 0.3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { display: grid; place-items: center; height: 100%; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

button, .btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 12px; cursor: pointer;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
button:disabled { opacity: 0.6; cursor: default; }
input, select, textarea { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }
label.check input { width: auto; }
.form { display: grid; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.error { color: var(--danger); min-height: 1.2em; }

/* Вход */
.login { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.login form { width: min(360px, 100%); background: var(--surface); padding: 24px; border-radius: var(--radius); box-shadow: var(--shadow); }
.login h1 { margin: 0 0 4px; font-size: 22px; }

/* Каркас */
.shell { display: grid; grid-template-rows: auto 1fr; height: 100%; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .brand { font-weight: 700; }
.topbar .spacer { flex: 1; }
.badge { display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 10px; background: var(--danger); color: #fff; font-size: 12px; text-align: center; }
.main { display: grid; grid-template-columns: 340px minmax(0, 1fr); min-height: 0; min-width: 0; }
.side { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--border); }
/* Скрытая левая колонка (переключатель в шапке) */
.main.side-hidden { grid-template-columns: minmax(0, 1fr); }
.main.side-hidden .side { display: none; }
/* Значки: кнопки-иконки (SVG-маска, цвет — токеном) */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 30px; padding: 0; }
.ico { display: inline-block; width: 18px; height: 18px; background: var(--muted); -webkit-mask: var(--ico) center / contain no-repeat; mask: var(--ico) center / contain no-repeat; }
.icon-btn:hover .ico { background: var(--accent); }
.ico-list { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18M3 12h18M3 18h18'/%3E%3C/svg%3E"); }
.ico-track { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='6' cy='19' r='2'/%3E%3Ccircle cx='18' cy='5' r='2'/%3E%3Cpath d='M8 19h8.5a3.5 3.5 0 0 0 0-7h-9a3.5 3.5 0 0 1 0-7H16'/%3E%3C/svg%3E"); }
.ico-cmd { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 17l6-5-6-5M12 19h8'/%3E%3C/svg%3E"); }
.ico-gear { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1.1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1.1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z'/%3E%3C/svg%3E"); }
.item-actions { display: flex; gap: 4px; margin-top: 4px; align-items: center; flex-wrap: wrap; }
.ico-clock { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E"); }
/* Значки-показатели в ряду под названием: счётчик «на связи» и заряд */
.badge-ico { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 6px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 12px; color: var(--muted); background: var(--surface); white-space: nowrap; font-variant-numeric: tabular-nums; }
.badge-ico .ico { width: 15px; height: 15px; }
.since.online { color: var(--ok); }
.ico-move { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 11l18-8-8 18-2-8z'/%3E%3C/svg%3E"); }
.ico-park { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='3'/%3E%3Cpath d='M9 17V7h4a3 3 0 0 1 0 6H9'/%3E%3C/svg%3E"); }
.ico-indoor { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 21h18M5 21V5l7-3 7 3v16M9 9h1M14 9h1M9 13h1M14 13h1M10 21v-4h4v4'/%3E%3C/svg%3E"); }
.ico-outdoor { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3l2 4 4-2-2 4 4 2-4 2 2 4-4-2-2 4-2-4-4 2 2-4-4-2 4-2-2-4 4 2z'/%3E%3C/svg%3E"); }
.ico-unknown { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M9.5 9a2.5 2.5 0 1 1 3.5 2.3c-.6.3-1 .9-1 1.6V14M12 17h.01'/%3E%3C/svg%3E"); }
.place.indoor { color: var(--indoor); }
.place.indoor .ico { background: var(--indoor); }
.place.outdoor { color: var(--ok); }
.place.outdoor .ico { background: var(--ok); }
.place.stale { color: var(--muted); }
.place.stale .ico { background: var(--muted); }
.motion.moving { color: var(--accent); }
.motion.moving .ico { background: var(--accent); }
.motion.stale { color: var(--muted); }
.motion.stale .ico { background: var(--muted); }
.since.online .ico { background: var(--ok); }
.since-text { min-width: 2.8em; }
/* Значки без текста — квадратные */
.badge-ico.motion, .badge-ico.place, .badge-ico.batt { width: 30px; justify-content: center; padding: 0; }
.badge-ico.batt { width: 34px; }
.batt-body { position: relative; width: 20px; height: 10px; border: 1.5px solid currentColor; border-radius: 2px; }
.batt-body::after { content: ''; position: absolute; right: -4px; top: 2px; width: 2px; height: 4px; background: currentColor; border-radius: 0 1px 1px 0; }
.batt-fill { position: absolute; left: 1px; top: 1px; bottom: 1px; max-width: calc(100% - 2px); background: currentColor; border-radius: 1px; }
.batt.high { color: var(--ok); }
.batt.mid { color: var(--warn); }
.batt.low { color: var(--danger); }
.item-actions .icon-btn { width: 28px; height: 26px; border-radius: 6px; }
/* Окно команд */
dialog.commands { width: min(640px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow: auto; display: grid; gap: 10px; }
dialog.commands:not([open]) { display: none; }
dialog.commands h2, dialog.commands h3 { margin: 0; }
.cmd-params { display: grid; gap: 8px; }
.status { font-weight: 600; }
.status.ok, .ok-text { color: var(--ok); }
.status.warn { color: var(--warn); }
.audit-row { cursor: pointer; }
.audit-row:hover td { background: var(--surface-2); }
.audit-detail { white-space: pre-wrap; margin: 6px 0 0; background: var(--surface-2); padding: 6px; border-radius: 6px; }
.check-list { display: grid; gap: 4px; max-height: 240px; overflow: auto; border: 1px solid var(--border); border-radius: 6px; padding: 8px; }
.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tabs button { flex: 1; border: 0; border-radius: 0; background: transparent; padding: 10px; border-bottom: 2px solid transparent; }
.tabs button.active { border-bottom-color: var(--accent); font-weight: 600; }
.list { overflow: auto; flex: 1; }
.item { overflow-wrap: anywhere; padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; display: grid; gap: 2px; }
.item:hover { background: var(--surface-2); }
.item.selected { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.item .title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--offline); flex: none; }
.dot.online { background: var(--ok); }
.dot.alarm { background: var(--danger); animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
/* Окно тревоги — компактное, правый верхний угол, стопкой */
.alarm-popups { position: fixed; z-index: 3000; top: 64px; right: 12px; display: grid; gap: 8px; width: min(360px, calc(100vw - 24px)); }
.alarm-popup { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--danger); border-radius: 8px;
  box-shadow: var(--shadow); padding: 10px 12px; display: grid; gap: 4px; }
.alarm-popup .ap-head { display: flex; align-items: center; gap: 8px; color: var(--danger); }
.alarm-popup .icon-btn { width: 26px; height: 24px; border: 0; background: transparent; color: var(--muted); }
.chip { font-size: 12px; padding: 1px 7px; border-radius: 10px; background: var(--danger-bg); color: var(--danger); font-weight: 600; }
.chip.ok { background: var(--surface-2); color: var(--muted); font-weight: 400; }
.mapwrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }
.detail { position: absolute; z-index: 500; top: 12px; right: 12px; width: min(340px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow: auto;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; display: grid; gap: 10px; }
.detail h2 { margin: 0; font-size: 17px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.detail { width: min(400px, calc(100% - 24px)); }
/* Раскрывающиеся таблицы параметров (карточка объекта) */
.sections { display: grid; gap: 6px; }
details.section > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 6px 0;
  font-weight: 700; font-size: 16px; user-select: none; }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::before { content: ''; width: 22px; height: 22px; flex: none; border-radius: 50%; background: var(--surface-2)
  url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231f6feb' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 6l6 6-6 6'/%3E%3C/svg%3E")
  center / 14px no-repeat; transition: transform .15s; }
details.section[open] > summary::before { transform: rotate(90deg); }
details.section > summary:hover { color: var(--accent); }
table.grants td, table.grants th { text-align: center; }
.sensor-rows { display: grid; gap: 8px; }
.sensor-row { display: grid; grid-template-columns: 1.4fr 1.2fr 0.6fr auto; gap: 8px; align-items: end; }
.sensor-row select { max-width: 100%; }
dialog:has(.sensor-rows) { width: min(720px, calc(100% - 32px)); }
@media (max-width: 600px) { .sensor-row { grid-template-columns: 1fr 1fr; } }
table.grants td:first-child, table.grants th:first-child { text-align: left; }
dialog:has(table.grants) { width: min(640px, calc(100% - 32px)); }
table.params { width: 100%; border-collapse: collapse; font-size: 14px; table-layout: fixed; }
table.params td { border: 1px solid var(--border); padding: 7px 10px; vertical-align: top; overflow-wrap: anywhere; }
table.params td:first-child { width: 50%; color: var(--text); }
table.params tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
table.params.raw td { padding: 5px 10px; font-size: 13px; }
table.params.compact { font-size: 13px; }
table.params.compact td { padding: 4px 8px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.95em; }
pre.hex { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; white-space: pre-wrap; word-break: break-all;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 8px; margin: 6px 0; }
/* Всплывающее окно при наведении на объект в списке (по образцу Wialon) */
.hovercard { position: fixed; z-index: 2000; width: 400px; max-width: calc(100vw - 16px); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px; display: grid; gap: 8px; pointer-events: none; font-size: 14px; }
.hc-head { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.hc-head .title { font-weight: 700; font-size: 16px; }
.hc-time { color: var(--text); }
.hc-strip { display: grid; grid-template-columns: 1fr 1fr 0.8fr 1.6fr; border: 1px solid var(--border); }
.hc-strip .cell { display: flex; align-items: center; justify-content: center; text-align: center; padding: 6px 4px; border-left: 1px solid var(--border); }
.hc-strip .cell:first-child { border-left: 0; }
.hc-box { border: 1px solid var(--border); }
.sat-icon { display: inline-block; width: 18px; height: 18px; vertical-align: -4px; background: var(--muted);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='6' height='6' transform='rotate(45 12 12)'/%3E%3Cpath d='M4 10l3-3 3 3-3 3zM14 20l3-3 3 3-3 3zM14 4l3-3M20 10l3-3M3 17a4 4 0 0 0 4 4'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='6' height='6' transform='rotate(45 12 12)'/%3E%3Cpath d='M4 10l3-3 3 3-3 3zM14 20l3-3 3 3-3 3zM14 4l3-3M20 10l3-3M3 17a4 4 0 0 0 4 4'/%3E%3C/svg%3E") center / contain no-repeat; }
.hc-caption { background: var(--surface-2); padding: 6px 10px; border-bottom: 1px solid var(--border); }
.prow { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--border); }
.prow:last-child { border-bottom: 0; }
.prow.one { grid-template-columns: 1fr; }
.pair { padding: 6px 10px; overflow-wrap: anywhere; }
.prow .pair + .pair { border-left: 1px solid var(--border); }
.alarm { overflow-wrap: anywhere; padding: 10px 12px; border-bottom: 1px solid var(--border); display: grid; gap: 4px; }
.alarm.open { background: var(--danger-bg); }
.alarm .title { font-weight: 600; }

/* Страницы (профиль, пользователи, админка) */
.page { overflow: auto; padding: 16px; }
.page section { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin: 0 auto 16px; max-width: 960px; }
.page h2 { margin: 0 0 12px; font-size: 18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 500; }
.table-scroll { overflow-x: auto; }

.toast-box { position: fixed; z-index: 2000; left: 50%; bottom: 16px; transform: translateX(-50%); display: grid; gap: 8px; width: min(420px, calc(100% - 32px)); }
.toast { background: var(--surface); border-left: 4px solid var(--accent); border-radius: 8px; box-shadow: var(--shadow); padding: 10px 14px; }
.toast.alarm-toast { border-left-color: var(--danger); }

dialog { border: 0; border-radius: var(--radius); box-shadow: var(--shadow); background: var(--surface); color: var(--text); width: min(440px, calc(100% - 32px)); padding: 20px; }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }

.marker { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; box-shadow: 0 0 0 1px rgb(0 0 0 / 0.3); }
.marker.offline { background: var(--offline); }
.marker.alarm { background: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgb(207 34 46 / 0.25); } }
.leaflet-container { background: var(--surface-2); font: inherit; }

@media (max-width: 760px) {
  .main { grid-template-columns: minmax(0, 1fr); grid-template-rows: 45vh minmax(0, 1fr); }
  .topbar { flex-wrap: wrap; gap: 6px; padding: 6px 8px; }
  .topbar .spacer { display: none; }
  .topbar button { padding: 5px 9px; font-size: 14px; }
  .topbar .brand { width: 100%; }
  .side { order: 2; border-right: 0; border-top: 1px solid var(--border); }
  .mapwrap { order: 1; }
  .detail { top: auto; bottom: 8px; right: 8px; left: 8px; width: auto; max-height: 60%; }
  .main.side-hidden { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .topbar .account { display: none; }
}
.grow { flex: 1; }
.admin-body { display: grid; grid-template-rows: auto 1fr; min-height: 0; }
.admin-body > .tabs { background: var(--surface); overflow-x: auto; }
.admin-body > .tabs button { flex: none; padding: 10px 16px; }
