:root {
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --group-card-bg: #efeee7;
}

/* Тёмная тема — по системной настройке (когда пользователь явно не выбрал
   свою, см. themeToggle в app.js: data-theme на <html>), ИЛИ принудительно
   через data-theme="dark", независимо от системной настройки. Обратное
   (data-theme="light" при тёмной системе) специально исключено из медиа-блока
   через :not(...), а не отдельным блоком light — светлые значения и так
   заданы в :root по умолчанию, переопределять их незачем. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-serious: #ec835a;
    --status-critical: #d03b3b;
    --group-card-bg: #232320;
  }
}

:root[data-theme="dark"] {
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --group-card-bg: #232320;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 600; font-size: 1.1rem; }

.topbar-right { display: flex; align-items: center; gap: 12px; }

.conn-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
}
.conn-dot.online { background: var(--status-good); }
.conn-dot.offline { background: var(--status-critical); }

.view { max-width: 900px; margin: 0 auto; padding: 24px 16px; }
.view[hidden] { display: none; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.login-card {
  max-width: 360px;
  margin: 10vh auto 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 { margin: 0 0 4px; font-size: 1.3rem; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.gate-mode-label {
  max-width: 360px;
  margin: 10px 0;
}

input:not([type="checkbox"]), select {
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--gridline);
  background: var(--page);
  color: var(--text-primary);
}

/* Чекбоксы не должны выглядеть как текстовые поля — иначе padding/border-radius
   раздувает их в большой скруглённый квадрат вместо обычной галочки. */
input[type="checkbox"] {
  width: auto;
  height: auto;
  margin: 0;
}

.btn {
  font: inherit;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-block;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--gridline); color: var(--text-primary); }
.btn-danger { background: var(--status-critical); color: #fff; }
.btn-good { background: var(--status-good); color: #fff; }

.error { color: var(--status-critical); font-size: 0.85rem; }
.hint { color: var(--text-muted); font-size: 0.82rem; margin-top: -6px; }
.save-msg { color: var(--status-good); font-size: 0.85rem; }
.managed-by-cell { color: var(--text-muted); font-size: 0.85rem; }

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--gridline);
}
.tab-btn {
  font: inherit;
  background: none;
  border: none;
  padding: 10px 16px;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab-btn.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.panel-header h2 { margin: 0; font-size: 1.1rem; }

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.zone-filter {
  flex: 1;
  max-width: 320px;
  margin: 0 12px;
}

.zones-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.home-picker-card {
  max-width: 560px;
  max-height: 88vh;
}
.home-picker-top {
  padding: 12px 16px 0;
}
.home-picker-top .zone-filter {
  width: 100%;
  box-sizing: border-box;
}
.home-picker-hint {
  margin: 8px 0 4px;
}
.home-picker-body {
  flex: 1;
  padding-bottom: 12px;
}
.home-picker-section { margin-top: 12px; }
.home-picker-section[hidden] { display: none; }
.home-picker-section h4 {
  margin: 0 0 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.home-picker-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.home-picker-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--page);
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, border-color 0.15s;
}
.home-picker-item[hidden] { display: none; }
.home-picker-item.pinned {
  border-color: var(--accent);
}
.home-picker-item.busy { opacity: 0.5; pointer-events: none; }
.home-picker-item-name { font-size: 0.92rem; }
.home-picker-toggle {
  flex-shrink: 0;
  padding: 5px 12px;
  font-size: 0.82rem;
  pointer-events: none;
}
.home-picker-toggle.pinned {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.home-picker-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--gridline);
}
.home-picker-footer .btn-primary { min-width: 120px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(20, 20, 20, 0.92);
  color: #fff;
  font-size: 0.9rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 1100;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[hidden] { display: none; }

.notify-pref-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 8px 2px;
  font-size: 0.9rem;
  cursor: pointer;
}
.notify-pref-row span {
  flex: none;
}

.zone-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}

/* Перетаскивание карточек на Главной (см. app.js: enableDragReorder) —
   общий стиль «приподнятой» карточки для всех четырёх типов (группы,
   разделы, ШС, ворота на Главной). touch-action: none выключает системный
   скролл/зум пальцем ТОЛЬКО пока карточка реально в состоянии драга (класс
   вешается/снимается в JS в момент старта/конца), а не постоянно — иначе
   обычный скролл списка на телефоне был бы сломан. */
.home-group-block.dragging,
.zone-row.dragging,
.gate-card.dragging {
  opacity: 0.6;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  touch-action: none;
  cursor: grabbing;
}

.zone-row .zone-name {
  flex: 1;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.92rem;
}

.zone-row .zone-id {
  color: var(--text-muted);
  font-size: 0.8rem;
  min-width: 2.5em;
}

.gate-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.gate-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.gate-card-name {
  font-size: 0.95rem;
  font-weight: 600;
}

.gate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.gate-thumb {
  flex: none;
  width: 60px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--page);
}

/* Иконка ворот теперь рендерится в отдельную обёртку (см. buildGateRow —
   нужно точечно обновлять только её innerHTML, не трогая соседний <img> с
   живым потоком камеры) — display:contents убирает саму обёртку из
   раскладки, чтобы SVG внутри участвовал в flex .gate-card как раньше. */
.gate-icon-wrap {
  display: contents;
}

.gate-icon {
  flex: none;
  width: 60px;
  height: 36px;
  overflow: visible;
}

.gate-icon .gate-ground { fill: var(--gridline); }
.gate-icon .gate-post { fill: var(--text-muted); }

.gate-icon .gate-leaf rect {
  fill: rgba(208, 59, 59, 0.15);
  stroke: var(--status-critical);
  stroke-width: 2.5;
  transition: fill 0.4s ease, stroke 0.4s ease;
}
.gate-icon .gate-leaf line {
  stroke: var(--status-critical);
  stroke-width: 1.5;
  opacity: 0.45;
  transition: stroke 0.4s ease;
}
.gate-icon.gate-icon-open .gate-leaf rect {
  fill: rgba(12, 163, 12, 0.15);
  stroke: var(--status-good);
}
.gate-icon.gate-icon-open .gate-leaf line {
  stroke: var(--status-good);
}

.gate-icon .gate-leaf-left {
  transform-box: fill-box;
  transform-origin: 0% 50%;
  transition: transform 0.6s cubic-bezier(0.34, 1.4, 0.64, 1);
}
.gate-icon .gate-leaf-right {
  transform-box: fill-box;
  transform-origin: 100% 50%;
  transition: transform 0.6s cubic-bezier(0.34, 1.4, 0.64, 1);
}
.gate-icon.gate-icon-open .gate-leaf-left { transform: rotate(-42deg); }
.gate-icon.gate-icon-open .gate-leaf-right { transform: rotate(42deg); }

.gate-icon.gate-icon-pending .gate-leaf-left { animation: gate-pending-swing-left 1s ease-in-out infinite; }
.gate-icon.gate-icon-pending .gate-leaf-right { animation: gate-pending-swing-right 1s ease-in-out infinite; }

@keyframes gate-pending-swing-left {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-18deg); }
}
@keyframes gate-pending-swing-right {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(18deg); }
}

.gate-icon .gate-roller-box { fill: var(--text-muted); }

.gate-icon .gate-roller-curtain rect {
  fill: rgba(208, 59, 59, 0.15);
  stroke: var(--status-critical);
  stroke-width: 2.5;
  transition: fill 0.4s ease, stroke 0.4s ease;
}
.gate-icon .gate-roller-slat {
  stroke: var(--status-critical);
  stroke-width: 1.2;
  opacity: 0.4;
  transition: stroke 0.4s ease, opacity 0.4s ease;
}
.gate-icon.gate-icon-open .gate-roller-curtain rect {
  fill: rgba(12, 163, 12, 0.15);
  stroke: var(--status-good);
}
.gate-icon.gate-icon-open .gate-roller-slat {
  stroke: var(--status-good);
  opacity: 0.15;
}

.gate-icon .gate-roller-curtain {
  transform-box: fill-box;
  transform-origin: 50% 0%;
  transition: transform 0.6s ease;
}
.gate-icon.gate-icon-open .gate-roller-curtain { transform: scaleY(0.12); }

.gate-icon.gate-icon-pending .gate-roller-curtain {
  animation: gate-pending-roller 0.9s ease-in-out infinite;
}
@keyframes gate-pending-roller {
  0%, 100% { transform: scaleY(0.9); }
  50% { transform: scaleY(0.45); }
}

.section-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-card .name { font-weight: 600; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.status-badge-home {
  display: flex;
  width: 100%;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: space-between;
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.status-dot.good { background: var(--status-good); }
.status-dot.warning { background: var(--status-warning); }
.status-dot.critical { background: var(--status-critical); }
.status-dot.neutral { background: var(--text-muted); }

.section-card .actions { margin-top: 4px; display: flex; justify-content: flex-end; }

.arm-controls { display: flex; gap: 6px; flex-wrap: wrap; flex-shrink: 0; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
}
.table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
}
.table input {
  width: 100%;
}
/* <select> по умолчанию сам растягивается под самый длинный <option>
   («Суперадминистратор») и один этим ужимает остальные колонки — как и
   input выше, привязываем ширину к самой ячейке. */
.table select {
  width: 100%;
}
/* Специфичность выше, чем у ".table input" (class+type+attr против
   class+type) — иначе при равной специфичности порядок правил в файле решал
   бы не в пользу этого, и чекбокс в таблице всё равно растягивался бы. */
.table input[type="checkbox"] {
  width: auto;
  height: auto;
  margin: 0;
}
.table input.zone-id,
.table input.section-id,
.table input.group-id,
.table input.user-id {
  width: 4em;
  min-width: 44px;
}
.table input.user-username { min-width: 90px; }
.table select.user-role { min-width: 70px; }

.perm-password-label {
  max-width: 280px;
  margin-bottom: 14px;
}

/* overflow-x: auto — таблицы настроек (особенно Расписание и Пользователи
   с редактором прав) на узких экранах шире доступного места; вместо
   разъезжания страницы в стороны скроллится только сама таблица, остальной
   блок (заголовок, кнопки) остаётся на месте. */
.settings-block {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--gridline);
  overflow-x: auto;
}
.settings-block:last-child { border-bottom: none; }
.settings-block h2 { font-size: 1.05rem; margin-bottom: 4px; }

@media (max-width: 640px) {
  .view {
    padding: 16px 10px;
  }
  .table th,
  .table td {
    padding: 6px 6px;
    font-size: 0.82rem;
  }
  .subnav-btn {
    padding: 7px 10px;
    font-size: 0.85rem;
  }
  .tab-btn {
    padding: 8px 10px;
  }
  .perm-editor {
    gap: 12px;
  }
  .perm-col {
    min-width: 160px;
  }
  /* «Закреплён за» — справочная колонка только для superadmin, на узком
     экране жертвуем ей первой, чтобы основная строка пользователя (ID/
     Логин/Роль/кнопки) помещалась без горизонтальной прокрутки таблицы. */
  #usersManagedByHeader,
  .managed-by-cell {
    display: none !important;
  }
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin: 12px 0;
}

/* ID — короткое поле, не должно ужиматься кнопками действий рядом с ним;
   Название — единственное, что осталось растягиваться в компактной
   строке (IP/Device ID/Local Key и остальное — в разворачивающейся
   панели «Настройки», см. gateSettingsRow), поэтому явно даём ему больше
   места. */
#gatesSettingsTable .gate-id { width: 3.5em; min-width: 3em; flex: none; }
#gatesSettingsTable .gate-name { min-width: 120px; }

.token-cell {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.conn-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.conn-badge.connected { background: rgba(12, 163, 12, 0.15); color: var(--status-good); }
.conn-badge.disconnected { background: rgba(137, 135, 129, 0.18); color: var(--text-muted); }
.conn-badge.fault { background: rgba(208, 59, 59, 0.15); color: var(--status-critical); }

.conn-badge.armed { background: rgba(208, 59, 59, 0.15); color: var(--status-critical); }
.conn-badge.disarmed { background: rgba(12, 163, 12, 0.15); color: var(--status-good); }
.conn-badge.gate-open { background: rgba(12, 163, 12, 0.15); color: var(--status-good); }
.conn-badge.gate-closed { background: rgba(208, 59, 59, 0.15); color: var(--status-critical); }
.conn-badge.partial { background: rgba(250, 178, 25, 0.2); color: #8a5a00; }
.conn-badge.alarm {
  background: rgba(208, 59, 59, 0.15);
  color: var(--status-critical);
  animation: alarm-text-blink 0.7s ease-in-out infinite;
}

.subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--gridline);
}
.subnav-btn {
  font: inherit;
  background: none;
  border: none;
  padding: 8px 14px;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-size: 0.9rem;
}
.subnav-btn.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.settings-subpanel { display: none; }
.settings-subpanel.active { display: block; }

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-end;
}

tr.perm-row td {
  background: var(--page);
  padding: 12px 10px;
}

.perm-editor {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.perm-col {
  flex: 1;
  min-width: 220px;
}

.perm-col h4 {
  margin: 0 0 6px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.perm-filter {
  width: 100%;
  margin-bottom: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--gridline);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 0.85rem;
}

.perm-list {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid var(--gridline);
  border-radius: 8px;
  padding: 6px;
  background: var(--surface-1);
}

.perm-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
  padding: 3px 4px;
}

.perm-item .perm-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.perm-item select {
  font-size: 0.78rem;
  padding: 3px 4px;
  flex: 0 0 auto;
  width: 116px;
}

.home-group-block {
  margin-bottom: 12px;
  padding: 10px 16px;
  border-radius: 16px;
  background: var(--group-card-bg);
}

.home-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 6px 0;
}

.home-group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  /* min-width не 0 — иначе flex просто сжимает название (и h3 внутри
     обрезается многоточием чуть ли не до одной буквы) вместо переноса
     arm-controls (см. ниже) на новую строку, когда двум кнопкам «Взять
     всё»/«Снять всё» уже не хватает места рядом с названием. */
  min-width: 160px;
  cursor: pointer;
}

.home-group-title h3 {
  margin: 0;
  font-size: 1rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-caret {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.home-group-content {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.25s ease;
}

.home-group-content.open {
  grid-template-rows: 1fr;
}

.home-group-content-inner {
  overflow: hidden;
  min-height: 0;
}

.section-square-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 24px);
  gap: 4px;
  padding: 4px 0 10px;
}

.section-square {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.6rem;
  cursor: pointer;
  user-select: none;
}

.section-square.armed { background: var(--status-critical); color: #fff; }
.section-square.disarmed { background: var(--status-good); color: #fff; }
.section-square.fault { background: var(--status-warning); color: #241a00; }

.section-square.alarm {
  background: var(--status-critical);
  color: #fff;
  animation: square-alarm-blink 0.6s ease-in-out infinite;
}

.section-square.readonly {
  cursor: default;
  opacity: 0.85;
}

@keyframes square-alarm-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

@keyframes btn-blink {
  0%, 100% { opacity: 1; box-shadow: none; }
  50% { opacity: 0.25; box-shadow: 0 0 0 3px rgba(250, 178, 25, 0.6); }
}

.blinking {
  animation: btn-blink 0.5s ease-in-out infinite;
  pointer-events: none;
}

@keyframes alarm-text-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.alarm-text {
  color: var(--status-critical);
  font-weight: 700;
  animation: alarm-text-blink 0.7s ease-in-out infinite;
}

.armed-text { color: var(--status-critical); font-weight: 600; }
.disarmed-text { color: var(--status-good); font-weight: 600; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-card {
  background: var(--surface-1);
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--gridline);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-body {
  overflow-y: auto;
  padding: 8px 16px;
}

.camera-body {
  padding: 0;
  display: flex;
  justify-content: center;
  background: #000;
}

.gate-camera-img {
  display: block;
  width: 100%;
  height: auto;
}

.camera-action {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-top: 1px solid var(--gridline);
}
.camera-action .gate-camera-action-btn {
  min-width: 160px;
}

#gateCameraModal .modal-card {
  max-width: 720px;
}

#gateCropModal .modal-card {
  max-width: 720px;
}

.crop-hint {
  padding: 0 16px;
  margin: 8px 0;
}

.crop-wrap {
  position: relative;
  width: 100%;
  line-height: 0;
  cursor: crosshair;
  user-select: none;
  touch-action: none;
}

.crop-select-box {
  position: absolute;
  border: 2px solid #ffd400;
  background: rgba(255, 212, 0, 0.18);
  box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.camera-action .gate-crop-btn,
.gate-crop-btn {
  width: 100%;
}

.modal-event-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--gridline);
  font-size: 0.88rem;
}

.modal-event-row:last-child {
  border-bottom: none;
}

.modal-event-time {
  color: var(--text-muted);
  white-space: nowrap;
  font-size: 0.82rem;
}

.schedules-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 14px;
}

.schedule-card {
  background: var(--group-card-bg);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.schedule-card-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.schedule-card-top {
  justify-content: space-between;
}

.schedule-enabled-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.schedule-name {
  width: 100%;
}

.schedule-targets-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.schedule-targets-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.schedule-target-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.schedule-target-row select {
  flex: 1;
  min-width: 100px;
}

.schedule-card-fields {
  gap: 8px;
}

.schedule-card-fields select,
.schedule-card-fields input[type="time"] {
  flex: 1;
  min-width: 110px;
}

.schedule-days-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.day-toggle {
  font: inherit;
  font-size: 0.8rem;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
}

.day-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* Полоса «Нет связи с сервером» — при смене сети */
.net-banner {
  position: fixed; left: 12px; right: 12px; top: calc(env(safe-area-inset-top, 0px) + 8px);
  z-index: 3000; display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 12px;
  background: #b45309; color: #fff; font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.net-banner[hidden] { display: none; }
.net-banner-spin {
  width: 16px; height: 16px; flex: none; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  animation: net-spin .8s linear infinite;
}
@keyframes net-spin { to { transform: rotate(360deg); } }

/* Привязка сигнализации к воротам: подпись на карточке ворот и блоки выбора
   объектов в Настройках → Ворота (gateSettingsRow, GateAlarmAction в config.py). */
.gate-alarm-note {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}
.gate-alarm {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--gridline);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.gate-alarm-row {
  border: 1px solid var(--gridline);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.gate-alarm-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  justify-content: space-between;
}
.gate-alarm-switch { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.gate-alarm-delay { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; }
.gate-alarm-delay input { width: 90px; }
/* Список объектов: каждый — отдельной строкой на всю ширину, название слева,
   галочка у правого края на одном уровне со всеми остальными.
   Приём нарочито «дубовый»: название — обычный текст (flex: 1 1 auto, перенос
   разрешён), галочка — order: 2 + margin-left: auto. Поэтому порядок «текст
   слева, галочка справа» держится независимо от того, в каком порядке они идут
   в разметке (у старых версий app.js галочка стояла первой), и независимо от
   justify-content/выравнивания текста в ячейке таблицы. Раньше тут стояло
   flex: 1 + min-width: 0 + nowrap у названия — внутри ячейки таблицы его ширина
   схлопывалась в ноль, и на экране оставались только галочки. */
.gate-alarm-items {
  display: flex;
  flex-direction: column;
  max-height: 320px;
  overflow-y: auto;
}
.gate-alarm-pick .gate-alarm-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  box-sizing: border-box;
  width: 100%;
  min-height: 40px;
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid var(--gridline);
  cursor: pointer;
  user-select: none;
}
.gate-alarm-pick .gate-alarm-item:last-child { border-bottom: none; }
.gate-alarm-pick .gate-alarm-name { flex: 1 1 auto; min-width: 0; }
/* Специфичность выше, чем у ".table input[type=checkbox]" — иначе чекбокс
   снова становился бы стандартным мелким. */
.gate-alarm-pick .gate-alarm-item input[type="checkbox"] {
  order: 2;
  flex: 0 0 auto;
  margin-left: auto;
  width: 20px;
  height: 20px;
}
/* Строка переключателей над списком: надпись и галочка — на одной строке,
   задержка прижата вправо. */
.gate-alarm-row .gate-alarm-head {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  text-align: left;
}
.gate-alarm-row .gate-alarm-head .gate-alarm-switch {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

/* Раздел «Геолокация» в Настройках (только суперадмин): переключатель, срок
   хранения, таблица телефонов и заявок. */
.geo-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  margin: 12px 0 6px;
}
.geo-switch,
.geo-keep { display: inline-flex; align-items: center; gap: 8px; }
.geo-switch { font-weight: 600; }
.geo-keep select { min-width: 110px; }
.geo-coords { font-variant-numeric: tabular-nums; }
.geo-link { padding: 3px 8px; font-size: 0.78rem; margin-left: 4px; text-decoration: none; }
.geo-actions { white-space: nowrap; }
.geo-actions .btn { padding: 5px 9px; font-size: 0.8rem; }
.geo-ok { color: var(--good, #15803d); }
.geo-bad { color: var(--bad, #b91c1c); }
.geo-history { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--gridline); }
