/* ═══════════════════════════════════════════════════════════════
   Шериф-Балки Monitor — stylesheet
   InTek-style: light theme, red accents, rounded cards
   ═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ═══════════════════════════════════════════════════════════════
   Тема «Ночная диспетчерская» — тёмный пульт по умолчанию.
   Токены сохраняют прежние имена, поэтому все компоненты
   перекрашиваются разом. Светлый режим — :root[data-theme="light"].
   Сигнатура интерфейса — янтарный маяк (--beacon).
   ═══════════════════════════════════════════════════════════════ */
:root {
  --sidebar-bg:     #0E1116;
  --sidebar-hover:  rgba(255,255,255,.06);
  --sidebar-active: #E30613;
  --sidebar-text:   #8B98A6;
  --sidebar-title:  #E6EDF3;

  --bg:             #0E1116;
  --bg-secondary:   #12161C;
  --card:           #161B22;
  --card-2:         #1B222C;
  --border:         #232B36;
  --border-light:   #1B222C;
  /* Алиасы — их использует легаси-код (ai.js/heatmap/perm), иначе светлые фоллбэки */
  --bg-card:        #161B22;
  --text-primary:   #E6EDF3;
  --surface:        #161B22;
  --hover:          #1B222C;
  --bg-hover:       #1B222C;
  --bg-active:      rgba(227,6,19,.16);

  --primary:        #FF4757;   /* INTEK-красный, осветлён для читаемости на тёмном */
  --primary-dark:   #E30613;   /* фирменный красный для заливок/бренда */
  --primary-light:  rgba(227,6,19,.16);
  --success:        #37D399;
  --success-bg:     rgba(55,211,153,.10);
  --warning:        #FFB020;   /* = янтарь маяка */
  --warning-bg:     rgba(255,176,32,.12);
  --danger:         #FF6470;
  --danger-bg:      rgba(227,6,19,.15);
  --info:           #3D82F6;
  --info-bg:        rgba(61,130,246,.12);
  --gray:           #6B7683;

  --text:           #E6EDF3;
  --text-secondary: #C3CCD6;
  --text-muted:     #8B98A6;
  --text-light:     #6B7683;

  /* Сигнатура — янтарный проблесковый маяк */
  --beacon:         #FFB020;
  --beacon-soft:    rgba(255,176,32,.14);
  --beacon-glow:    rgba(255,176,32,.50);

  --radius:         10px;
  --radius-sm:      6px;
  --radius-lg:      16px;
  --radius-xl:      24px;
  --shadow:         0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-card:    0 1px 2px rgba(0,0,0,.35), 0 0 0 1px rgba(255,255,255,.02);
  --shadow-hover:   0 14px 44px rgba(0,0,0,.55), 0 2px 6px rgba(0,0,0,.4);
  --font:           'Nunito', 'Avenir Next', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-display:   'Bahnschrift', 'DIN Condensed', 'Oswald', 'Nunito', var(--font);
  --font-mono:      'JetBrains Mono', ui-monospace, 'SF Mono', 'Cascadia Code', monospace;

  --transition:     all 0.2s cubic-bezier(.4,0,.2,1);
  --spring:         all 0.35s cubic-bezier(.34,1.56,.64,1);
}

/* Helpdesk integration */
.helpdesk-card {
  overflow: hidden;
}

.helpdesk-card-header,
.helpdesk-picker-row,
.helpdesk-ticket-main,
.helpdesk-ticket-meta,
.helpdesk-pagination {
  display: flex;
  align-items: center;
}

.helpdesk-card-header {
  justify-content: space-between;
  gap: 12px;
}

.helpdesk-summary {
  margin-left: 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 400;
}

.helpdesk-body {
  min-height: 76px;
}

.helpdesk-state {
  padding: 22px 18px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.helpdesk-ticket {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 18px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.helpdesk-ticket:first-child {
  border-top: 0;
}

.helpdesk-ticket-main {
  min-width: 0;
  gap: 8px;
}

.helpdesk-ticket-id {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-size: 12px;
}

.helpdesk-ticket-subject {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.helpdesk-ticket-meta {
  grid-column: 1;
  flex-wrap: wrap;
  gap: 6px 12px;
  color: var(--text-muted);
  font-size: 11px;
}

.helpdesk-badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  font-size: 11px;
}

.helpdesk-ticket-link {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  white-space: nowrap;
}

.helpdesk-pagination {
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}

.helpdesk-page-label {
  color: var(--text-muted);
  font-size: 12px;
}

.helpdesk-picker-row {
  gap: 8px;
}

.helpdesk-picker-row .input-field {
  min-width: 0;
}

.helpdesk-picker-selection {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 12px;
}

.helpdesk-picker-selection.is-linked {
  color: #159447;
  font-weight: 600;
}

.helpdesk-picker-results {
  max-height: 210px;
  margin-top: 6px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
}

.helpdesk-picker-option {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.helpdesk-picker-option:last-child {
  border-bottom: 0;
}

.helpdesk-picker-option:hover {
  background: var(--bg-secondary);
}

.helpdesk-picker-option small {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
}

.map-helpdesk {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}

.map-helpdesk-title {
  margin-bottom: 5px;
  font-weight: 700;
}

.map-helpdesk-ticket {
  display: flex;
  width: 100%;
  gap: 6px;
  margin-top: 4px;
  padding: 0;
  border: 0;
  color: var(--text-secondary);
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.map-helpdesk-ticket:hover { color: var(--primary); }

.map-helpdesk-ticket span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .helpdesk-ticket {
    grid-template-columns: minmax(0, 1fr);
  }

  .helpdesk-ticket-link {
    grid-column: 1;
    grid-row: auto;
    justify-self: start;
  }

  .helpdesk-picker-row {
    flex-wrap: wrap;
  }
}

/* ── Светлый режим (дневная работа) ── */
:root[data-theme="light"] {
  --sidebar-bg:     #1D1D1B;
  --sidebar-text:   #8a8a94;
  --sidebar-title:  #f0f0f2;

  --bg:             #f2f3f5;
  --bg-secondary:   #e9ebee;
  --card:           #ffffff;
  --card-2:         #f7f8fa;
  --border:         #e2e4e8;
  --border-light:   #eef0f2;
  --bg-card:        #ffffff;
  --text-primary:   #0f1114;
  --surface:        #ffffff;
  --hover:          #f1f5f9;
  --bg-hover:       #eef2f7;
  --bg-active:      #fef2f2;

  --primary:        #E30613;
  --primary-dark:   #C50511;
  --primary-light:  #fef2f2;
  --success:        #1a9f4a;
  --success-bg:     #ecfdf5;
  --warning:        #d97706;
  --warning-bg:     #fffbeb;
  --danger:         #dc2626;
  --danger-bg:      #fef2f2;
  --info:           #2563eb;
  --info-bg:        #eff6ff;
  --gray:           #868c98;

  --text:           #0f1114;
  --text-secondary: #2b2f36;
  --text-muted:     #5f6672;
  --text-light:     #8a8f9a;

  --beacon:         #d97706;
  --beacon-soft:    rgba(217,119,6,.12);
  --beacon-glow:    rgba(217,119,6,.35);

  --shadow:         0 1px 3px rgba(17,17,20,.06), 0 1px 2px rgba(17,17,20,.04);
  --shadow-card:    0 1px 3px rgba(17,17,20,.05), 0 0 0 1px rgba(17,17,20,.03);
  --shadow-hover:   0 12px 40px rgba(17,17,20,.1), 0 2px 6px rgba(17,17,20,.06);
}

html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums;
  scroll-behavior: smooth;
}

.hidden { display: none !important; }
.mb-16 { margin-bottom: 16px; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.24); }
:root[data-theme="light"] ::-webkit-scrollbar-thumb { background: rgba(0,0,0,.12); }
:root[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,.2); }

/* ════════════════════════════════════════════
   LOGIN
   ════════════════════════════════════════════ */
.login-screen {
  min-height: 100dvh;
  background: #0e0e11;
  background-image:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(200,25,31,.12) 0%, transparent 60%),
    radial-gradient(ellipse 50% 40% at 80% 100%, rgba(37,99,235,.06) 0%, transparent 50%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: rgba(255,255,255,.97);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 400px;
  box-shadow: 0 24px 80px rgba(0,0,0,.3), 0 0 0 1px rgba(255,255,255,.08);
  backdrop-filter: blur(20px);
}

.login-logo {
  text-align: center;
  margin-bottom: 36px;
}

.beacon-icon { font-size: 52px; display: block; margin-bottom: 14px; }
.login-logo h1 { font-size: 28px; font-weight: 700; color: var(--text); letter-spacing: -0.8px; line-height: 1.1; }
.login-logo p  { color: var(--text-muted); font-size: 13px; margin-top: 8px; font-weight: 400; letter-spacing: 0.01em; }

.login-error {
  background: var(--danger-bg);
  border: 1px solid #fecaca;
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* ════════════════════════════════════════════
   APP LAYOUT
   ════════════════════════════════════════════ */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
  border-right: 1px solid rgba(255,255,255,.04);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.beacon-icon-sm { font-size: 24px; flex-shrink: 0; }
.sidebar-title   { font-size: 15px; font-weight: 700; color: var(--sidebar-title); line-height: 1.2; letter-spacing: -0.4px; }
.sidebar-subtitle { font-size: 10.5px; color: var(--sidebar-text); font-weight: 400; letter-spacing: 0.02em; }

.sidebar-nav { flex: 1; padding: 12px 8px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
  border-radius: 8px;
  margin-bottom: 1px;
}

.nav-item svg { width: 17px; height: 17px; fill: currentColor; flex-shrink: 0; opacity: .8; }

.nav-item:hover  { background: var(--sidebar-hover); color: #d0d0d6; }
.nav-item:active { transform: scale(.98); }
.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
  box-shadow: 0 2px 12px rgba(200,25,31,.35), 0 0 0 1px rgba(200,25,31,.1);
}
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: 12px 12px;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.poller-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--sidebar-text);
  padding: 4px 6px;
}

/* ── Main Content ── */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  min-width: 0;
}

/* ── Views ── */
.view { display: none; }
.view.active { display: block; }

/* ════════════════════════════════════════════
   PAGE HEADER
   ════════════════════════════════════════════ */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
}

.page-title    { font-size: 24px; font-weight: 700; color: var(--text); line-height: 1.15; letter-spacing: -0.6px; }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 4px; font-weight: 400; letter-spacing: 0.01em; }
.page-actions  { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.last-update { font-size: 12px; color: var(--text-light); font-weight: 400; }

/* ════════════════════════════════════════════
   BUTTONS
   ════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.4;
  letter-spacing: -0.01em;
  font-family: var(--font);
}
.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 3px rgba(200,25,31,.25), inset 0 1px 0 rgba(255,255,255,.12); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 16px rgba(200,25,31,.3); transform: translateY(-1px); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn-danger-outline { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn-danger-outline:hover { background: var(--danger-bg); }

.btn-outline { border-color: var(--border); color: var(--text-secondary); background: var(--card); }
.btn-outline:hover { border-color: var(--text-light); background: var(--bg); }

.btn-outline-light { border-color: rgba(255,255,255,.15); color: #a0a0a8; background: transparent; padding: 6px 10px; }
.btn-outline-light:hover { background: rgba(255,255,255,.08); color: #e0e0e0; }

.btn-ghost { background: transparent; border: none; color: var(--text-secondary); padding: 6px 10px; }
.btn-ghost:hover { background: var(--bg); border-radius: var(--radius-sm); }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 14px; }

.btn-full { width: 100%; justify-content: center; }

.btn-beacon-on  { background: var(--success); color: #fff; box-shadow: 0 2px 4px rgba(34,197,94,.2); }
.btn-beacon-on:hover { background: #16a34a; }
.btn-beacon-off { background: var(--danger); color: #fff; }
.btn-beacon-off:hover { background: #dc2626; }

/* ════════════════════════════════════════════
   FORMS
   ════════════════════════════════════════════ */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-group label { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.input-field {
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text);
  background: var(--card);
  transition: var(--transition);
  width: 100%;
  font-family: var(--font);
}
.input-field:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(200,25,31,.07); }

.input-sm {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  background: var(--card);
  font-family: var(--font);
}
.input-sm:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(227,30,37,.08); }

.select-sm {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  background: var(--card);
  cursor: pointer;
  font-family: var(--font);
}

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

/* ════════════════════════════════════════════
   CARDS
   ════════════════════════════════════════════ */
.card {
  background: var(--card);
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  transition: var(--transition);
}

.card-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
}

/* ════════════════════════════════════════════
   KPI CARDS
   ════════════════════════════════════════════ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}

@media (max-width: 1200px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px)  { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }

.kpi-card {
  background: var(--card);
  border: none;
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-card);
  border-left: 3px solid var(--gray);
  transition: var(--spring);
}
.kpi-btn { cursor: pointer; user-select: none; position: relative; }
.kpi-btn:hover { box-shadow: var(--shadow-hover); transform: translateY(-3px); }
.kpi-btn:active { transform: translateY(0) scale(.98); }
.kpi-btn.active { outline: 2px solid var(--primary); outline-offset: -2px; }
.kpi-btn.active::after {
  content: '✕'; position: absolute; top: 6px; right: 8px;
  font-size: 10px; color: var(--text-muted); opacity: .6;
}
.kpi-card:hover { box-shadow: var(--shadow-hover); }
.kpi-success { border-left-color: var(--success); }
.kpi-danger  { border-left-color: var(--danger); }
.kpi-primary { border-left-color: var(--primary); }
.kpi-warning { border-left-color: var(--warning); }
.kpi-gray    { border-left-color: var(--gray); }

/* Показания пульта — цифра окрашена по смыслу */
.kpi-success .kpi-value { color: var(--success); }
.kpi-danger  .kpi-value { color: var(--danger); }
.kpi-warning .kpi-value { color: var(--warning); }

.kpi-value { font-family: var(--font-display); font-size: 36px; font-weight: 600; color: var(--text); line-height: 1; margin-bottom: 6px; letter-spacing: .01em; font-variant-numeric: tabular-nums; }
.kpi-label { font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .12em; font-weight: 600; }

/* ════════════════════════════════════════════
   SECTION HEADER
   ════════════════════════════════════════════ */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}
.section-header h3 { font-size: 16px; font-weight: 600; }
.section-header.collapsible:hover { opacity: 0.8; }
.collapse-arrow { display: inline-block; width: 16px; font-size: 12px; transition: transform 0.15s; }

/* ════════════════════════════════════════════
   DEVICE CARDS (DASHBOARD GRID)
   ════════════════════════════════════════════ */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}
/* Dashboard edit mode */
.device-grid.dash-edit-mode .device-card {
  cursor: move;
  outline: 2px dashed var(--primary);
  outline-offset: -2px;
}
.device-grid.dash-edit-mode .device-card:hover {
  outline-color: var(--primary-dark, #c4181e);
}
.device-grid:not(.dash-edit-mode) .device-card .resize-handle,
.device-grid:not(.dash-edit-mode) .device-card .resize-handle-v,
.device-grid:not(.dash-edit-mode) .device-card .resize-reset {
  display: none;
}

.device-card {
  background: var(--card);
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 16px 18px;
  cursor: pointer;
  transition: var(--spring);
  position: relative;
  display: flex;
  flex-direction: column;
}
.device-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-3px);
}
.device-card:active {
  transform: translateY(0) scale(.99);
}
.device-card.stolen { opacity: .55; }

/* Цветная полоска-статус сверху карточки (читается с одного взгляда) */
.device-card::before {
  content: "";
  position: absolute; left: 0; right: 0; top: 0; height: 3px;
  background: var(--gray);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.device-card.s-on::before     { background: var(--success); }
.device-card.s-off::before    { background: var(--danger); }
.device-card.s-stolen::before { background: var(--gray); }

/* Сигнатура — карточка с включённым маяком светится янтарём */
.device-card.beacon-live::before { background: var(--beacon); }
.device-card.beacon-live {
  background:
    radial-gradient(150px 110px at 92% -10%, var(--beacon-soft), transparent 70%),
    var(--card);
  box-shadow: var(--shadow-card), inset 0 0 0 1px color-mix(in srgb, var(--beacon) 28%, transparent);
}

.device-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}

.device-card-name {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text);
  line-height: 1.3;
}
.device-card-road {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.device-card-badges { display: flex; gap: 4px; flex-wrap: wrap; }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: -0.01em;
}
.badge-success { background: var(--success-bg); color: var(--success); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--success) 30%, transparent); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger);  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--danger) 30%, transparent); }
.badge-primary { background: var(--primary-light); color: var(--primary); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 30%, transparent); }
.badge-warning { background: var(--warning-bg); color: var(--warning); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--warning) 30%, transparent); }
.badge-gray    { background: var(--card-2); color: var(--text-muted); box-shadow: inset 0 0 0 1px var(--border); }

.device-card-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  margin-bottom: 12px;
  flex: 1;
}
.metric { display: flex; flex-direction: column; }
.metric-label { font-size: 10.5px; color: var(--text-light); text-transform: uppercase; letter-spacing: .3px; }
.metric-value { font-size: 13.5px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

.device-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid var(--border-light);
  padding-top: 10px;
  margin-top: 4px;
}

.card-actions { display: flex; gap: 6px; }

.beacon-mini {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.beacon-mini.on  { background: var(--beacon); animation: beacon-flash 1.4s ease-in-out infinite; box-shadow: 0 0 10px 2px var(--beacon-glow); }
.beacon-mini.off { background: var(--gray); opacity: .5; }
@keyframes beacon-flash { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
@media (prefers-reduced-motion: reduce) { .beacon-mini.on { animation: none; } }

/* ════════════════════════════════════════════
   BATTERY BAR
   ════════════════════════════════════════════ */
.battery-bar {
  height: 5px;
  background: var(--card-2);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
  box-shadow: inset 0 0 0 1px var(--border);
}
.battery-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width .5s, background .3s;
}

/* ════════════════════════════════════════════
   DOTS / STATUS INDICATORS
   ════════════════════════════════════════════ */
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.dot-green  { background: var(--success); box-shadow: 0 0 4px var(--success); }
.dot-red    { background: var(--danger); }
.dot-gray   { background: var(--gray); }
.dot-pulse  { animation: pulse-dot 2s infinite; }

/* ════════════════════════════════════════════
   TABLE
   ════════════════════════════════════════════ */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: none;
  background: var(--card);
  box-shadow: var(--shadow-card);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table thead th {
  background: var(--card-2);
  color: var(--text-light);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border-light);
  transition: var(--transition);
}
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: var(--card-2); }
.data-table tbody tr.stolen { opacity: .55; }

.data-table td {
  padding: 11px 16px;
  color: var(--text);
  vertical-align: middle;
}

.tbl-device-name { font-weight: 600; cursor: pointer; color: var(--primary); }
.tbl-device-name:hover { text-decoration: underline; }

/* ════════════════════════════════════════════
   MAP
   ════════════════════════════════════════════ */
.map-container {
  height: calc(100vh - 160px);
  min-height: 400px;
  border-radius: var(--radius-lg);
  border: none;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.map-legend {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--card);
  border: none;
  border-radius: 999px;
  padding: 7px 16px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-card);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

/* Leaflet popup custom */
.leaflet-popup-content-wrapper { border-radius: var(--radius-lg); box-shadow: var(--shadow-hover); }
.leaflet-popup-content-wrapper { background: var(--card); }
.leaflet-popup-content a.btn { color: #fff !important; text-decoration: none !important; }
.map-popup-title { font-weight: 600; font-size: 14px; color: var(--text); margin-bottom: 6px; }
.map-popup-row   { font-size: 12px; color: var(--text-secondary); margin: 2px 0; }
.map-popup-buttons { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.map-popup-buttons .btn { font-size: 12px; padding: 5px 12px; font-weight: 600; }
.map-popup-buttons .btn-primary { background: var(--primary); color: #fff !important; }
.map-popup-buttons .btn-success { background: #16a34a; color: #fff !important; }
.map-popup-buttons .btn-danger  { background: #ef4444; color: #fff !important; }
.btn-success { background: #16a34a; color: #fff; border: none; border-radius: 6px; cursor: pointer; }
.btn-success:hover { background: #15803d; }
.btn-danger  { background: #ef4444; color: #fff; border: none; border-radius: 6px; cursor: pointer; }
.btn-danger:hover  { background: #dc2626; }

/* Custom marker */
.map-marker {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
  transition: background .3s;
}
.map-marker-flash {
  animation: police-flash-marker 1s infinite !important;
}
@keyframes police-flash-marker {
  0%, 10%   { background: #2563eb !important; box-shadow: 0 0 8px rgba(37,99,235,.7), 0 1px 4px rgba(0,0,0,.3); }
  50%, 60%  { background: #ef4444 !important; box-shadow: 0 0 8px rgba(239,68,68,.7), 0 1px 4px rgba(0,0,0,.3); }
  100%      { background: #2563eb !important; box-shadow: 0 0 8px rgba(37,99,235,.7), 0 1px 4px rgba(0,0,0,.3); }
}
.map-marker-vehicle {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 2px solid white;
  box-shadow: 0 1px 5px rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  justify-content: center;
}
.map-marker-camera {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 2px solid white;
  background: #f59e0b;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: white;
  line-height: 1;
}

.map-layer-toggle {
  display: flex;
  gap: 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin-right: 12px;
}
.map-toggle-btn {
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  background: var(--card);
  color: var(--text-secondary);
  border-right: 1px solid var(--border);
  transition: all 0.15s;
  user-select: none;
}
.map-toggle-btn:last-child { border-right: none; }
.map-toggle-btn input { display: none; }
.map-toggle-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 4px rgba(227,30,37,.2);
}

/* Camera grid — 2 objects per row (4 images) */
.cameras-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}
.cameras-grid-all {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 4px;
}
.cameras-grid-all .cam-object { border-radius: 4px; }
.cameras-grid-all .cam-object-images { grid-template-columns: 1fr; gap: 1px; }
.cameras-grid-all .cam-object-footer { padding: 2px 6px; }
.cameras-grid-all .cam-object-name { font-size: 10px; }
.cameras-grid-all .cam-cell-label { font-size: 9px; padding: 1px 4px; }
.cam-object {
  background: var(--card);
  border: none;
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: var(--transition);
  box-shadow: var(--shadow-card);
}
.cam-object:hover { box-shadow: var(--shadow-hover); }
.cam-object-images {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2px;
}
.cam-cell {
  position: relative;
  background: var(--bg);
}
.cam-cell-img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  display: block;
  cursor: pointer;
  transition: opacity .2s;
}
.cam-cell-img:hover { opacity: .85; }
.cam-cell-noimg {
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--bg);
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-muted);
}
.cam-cell-label {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 10px;
  color: #fff;
  background: rgba(0,0,0,.45);
  padding: 1px 6px;
  border-radius: 3px;
  pointer-events: none;
}
.cam-object-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--border-light);
}
.cam-object-name {
  font-weight: 600;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.cam-object-footer .cam-refresh-btn {
  font-size: 16px;
  padding: 2px 6px;
  flex-shrink: 0;
}

.cam-weather-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px 12px;
  padding: 6px 12px;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border-light);
  background: var(--bg-secondary);
  border-radius: 0 0 10px 10px;
  min-height: 29px;
}
.cam-weather-bar:empty { display: none; }
.cam-weather-condition {
  color: var(--text);
  font-weight: 600;
}
.cam-weather-surface { color: var(--text-secondary); }
.cam-weather-meta {
  margin-left: auto;
  color: var(--text-muted);
  white-space: nowrap;
}
.cam-weather-stale {
  color: var(--warning);
  font-weight: 600;
}
.cam-weather-time {
  margin-left: auto;
  color: var(--text-muted);
}
.cam-weather-bar.is-stale { background: color-mix(in srgb, var(--warning) 7%, var(--bg-secondary)); }

@media (max-width: 680px) {
  .cam-weather-meta {
    width: 100%;
    margin-left: 0;
  }
}

.camera-player-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(5, 8, 12, .94);
}
.camera-player {
  width: min(1800px, 100%);
  height: calc(100vh - 24px);
  min-height: 520px;
  display: grid;
  grid-template-rows: 52px minmax(0, 1fr) auto;
  overflow: hidden;
  background: #111820;
  border: 1px solid #283441;
  border-radius: 6px;
  box-shadow: 0 20px 70px rgba(0, 0, 0, .55);
}
.camera-player-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  border-bottom: 1px solid #26313d;
  color: #eef3f8;
}
.camera-player-title {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.camera-player-title strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.camera-player-title span {
  flex: 0 0 auto;
  font-size: 11px;
  color: #8998a8;
}
.camera-player-modes {
  display: flex;
  height: 32px;
  overflow: hidden;
  border: 1px solid #344250;
  border-radius: 5px;
}
.camera-player-mode {
  min-width: 84px;
  padding: 0 14px;
  border: 0;
  border-right: 1px solid #344250;
  background: #17202a;
  color: #aab7c5;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.camera-player-mode:last-child { border-right: 0; }
.camera-player-mode.active {
  background: #e31e25;
  color: #fff;
}
.camera-player-close {
  display: inline-grid;
  justify-self: end;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #aab7c5;
  place-items: center;
  border-radius: 6px;
  cursor: pointer;
}
.camera-player-close:hover { color: #fff; background: rgba(255,255,255,.08); }
.camera-player-stage {
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #070b10;
}
.camera-player-video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #070b10;
}
.camera-player-loading {
  position: absolute;
  left: 50%;
  bottom: 18px;
  max-width: calc(100% - 32px);
  transform: translateX(-50%);
  padding: 6px 10px;
  border-radius: 4px;
  background: rgba(13, 19, 26, .88);
  color: #d6dee7;
  font-size: 12px;
  pointer-events: none;
}
.camera-player-loading.is-error { color: #ff8d92; }
.camera-archive-panel {
  padding: 10px 14px 12px;
  border-top: 1px solid #26313d;
  background: #141c25;
  color: #d8e0e8;
}
.camera-archive-panel[hidden] { display: none; }
.camera-archive-toolbar {
  min-height: 48px;
  display: flex;
  align-items: end;
  gap: 10px;
}
.camera-archive-field,
.camera-archive-speed {
  display: grid;
  gap: 3px;
}
.camera-archive-field > span,
.camera-archive-speed > span {
  color: #8291a0;
  font-size: 10px;
}
.camera-archive-day-button {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  padding: 0;
  border: 1px solid #344250;
  border-radius: 5px;
  background: #101821;
  color: #dbe4ed;
  font: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.camera-archive-day-button:hover:not(:disabled) {
  border-color: #607286;
  background: #1d2935;
}
.camera-archive-day-button:disabled {
  opacity: .35;
  cursor: default;
}
.camera-archive-field .form-control {
  width: 148px;
  height: 32px;
  border-color: #344250;
  background: #0f161e;
  color: #edf2f7;
  font-size: 12px;
}
.camera-archive-time-field .form-control { width: 116px; }
.camera-archive-open {
  height: 32px;
  padding: 0 16px;
  border-radius: 5px;
}
.camera-archive-days,
.camera-archive-current {
  align-self: center;
  color: #8291a0;
  font-size: 11px;
  white-space: nowrap;
}
.camera-archive-current {
  margin-left: auto;
  color: #e4eaf0;
  font-variant-numeric: tabular-nums;
}
.camera-archive-controls {
  display: flex;
  align-items: end;
  gap: 6px;
  margin-top: 8px;
}
.camera-player-icon {
  width: 38px;
  height: 34px;
  padding: 0;
  border: 1px solid #344250;
  border-radius: 5px;
  background: #101821;
  color: #dbe4ed;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.camera-player-icon:hover {
  border-color: #607286;
  background: #1d2935;
}
.camera-player-jump {
  width: 46px;
  font-size: 11px;
}
.camera-player-play {
  border-color: #e31e25;
  background: #e31e25;
  color: #fff;
}
.camera-player-play:hover {
  border-color: #f0444a;
  background: #f0444a;
}
.camera-archive-speed {
  width: 88px;
  margin-left: 8px;
}
.camera-archive-speed .form-control {
  height: 34px;
  border-color: #344250;
  background: #0f161e;
  color: #edf2f7;
  font-size: 12px;
}
.camera-archive-timeline-wrap {
  position: relative;
  margin-top: 8px;
}
.camera-archive-timeline {
  width: 100%;
  height: 36px;
  display: block;
  cursor: zoom-in;
  touch-action: none;
}
.camera-archive-timeline.is-panning { cursor: grabbing; }
.camera-archive-tooltip {
  position: absolute;
  z-index: 2;
  top: -25px;
  transform: translateX(-50%);
  padding: 3px 6px;
  border: 1px solid #455465;
  border-radius: 4px;
  background: #0a1017;
  color: #f2f5f8;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.camera-archive-hours {
  display: flex;
  justify-content: space-between;
  margin-top: -4px;
  color: #718091;
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.camera-archive-legend {
  display: flex;
  gap: 14px;
  margin-top: 3px;
  color: #8291a0;
  font-size: 10px;
}
.camera-archive-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.camera-archive-legend i {
  width: 12px;
  height: 4px;
  display: inline-block;
}
.camera-archive-record-mark { background: #3b82f6; }
.camera-archive-motion-mark { background: #f59e0b; }

@media (max-width: 760px) {
  .camera-player-overlay { padding: 0; }
  .camera-player {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    border: 0;
    border-radius: 0;
  }
  .camera-player-header {
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
    padding: 0 8px;
  }
  .camera-player-title span { display: none; }
  .camera-player-mode {
    min-width: 62px;
    padding: 0 8px;
  }
  .camera-player-modes { height: 40px; }
  .camera-player-close { width: 40px; height: 40px; }
  .camera-archive-panel {
    max-height: 230px;
    overflow-y: auto;
    padding: 8px;
  }
  .camera-archive-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
  }
  .camera-archive-field { flex: 1 1 120px; }
  .camera-archive-field .form-control,
  .camera-archive-time-field .form-control {
    width: 100%;
    height: 40px;
  }
  .camera-archive-day-button,
  .camera-archive-open,
  .camera-player-icon,
  .camera-archive-speed .form-control { height: 40px; }
  .camera-archive-day-button { width: 40px; flex-basis: 40px; }
  .camera-player-icon { width: 40px; }
  .camera-archive-days { display: none; }
  .camera-archive-current {
    width: 100%;
    margin-left: 0;
  }
}

.ai-weather-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 176px;
  padding: 14px 16px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.ai-weather-card.is-stale { border-color: color-mix(in srgb, var(--warning) 45%, var(--border)); }
.ai-weather-card-name {
  min-height: 30px;
  overflow: hidden;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.ai-weather-card-condition {
  overflow: hidden;
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.ai-weather-card-details {
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.5;
}
.ai-weather-card-evidence {
  overflow: hidden;
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.ai-weather-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  color: var(--text-muted);
  font-size: 10px;
}
.ai-weather-confidence { font-size: 11px; }
.ai-weather-confidence.is-high { color: var(--success); }
.ai-weather-confidence.is-medium { color: var(--warning); }
.ai-weather-confidence.is-low { color: var(--danger); }

.ai-weather-history {
  margin-bottom: 16px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.ai-weather-history-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.ai-weather-history-header h4 {
  margin: 0;
  color: var(--text);
  font-size: 15px;
}
.ai-weather-history-header p {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 11px;
}
.ai-weather-history-controls {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 10px;
}
.ai-weather-history-filter {
  display: grid;
  gap: 4px;
  min-width: min(300px, 32vw);
}
.ai-weather-history-filter > span {
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}
.ai-weather-history-filter select {
  width: 100%;
  height: 34px;
  padding: 0 30px 0 10px;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.ai-weather-history-filter select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.ai-weather-periods {
  display: grid;
  grid-template-columns: repeat(3, max-content);
  height: 34px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.ai-weather-periods button {
  min-width: 68px;
  padding: 0 10px;
  color: var(--text-muted);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  background: var(--card-2);
  border: 0;
  border-right: 1px solid var(--border);
  cursor: pointer;
}
.ai-weather-periods button:last-child { border-right: 0; }
.ai-weather-periods button:hover { color: var(--text); background: var(--hover); }
.ai-weather-periods button.active {
  color: #fff;
  background: var(--primary-dark);
}
.ai-weather-history-refresh {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
  color: var(--text-secondary);
  font: inherit;
  font-size: 20px;
  line-height: 1;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.ai-weather-history-refresh:hover {
  color: var(--text);
  background: var(--hover);
  border-color: var(--text-muted);
}
.ai-weather-history-refresh:focus-visible,
.ai-weather-periods button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}
.ai-weather-history[aria-busy="true"] .ai-weather-history-refresh {
  color: var(--text-muted);
  cursor: wait;
}
.ai-weather-history-state {
  display: grid;
  min-height: 220px;
  place-items: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}
.ai-weather-history-state.is-error { color: var(--danger); }
.ai-weather-history-state[hidden],
.ai-weather-history-content[hidden],
.ai-weather-object-summary[hidden] { display: none; }
.ai-weather-history-content { min-width: 0; }
.ai-weather-object-summary {
  padding: 16px 18px 18px;
  border-top: 1px solid var(--border);
}
.ai-weather-summary-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.ai-weather-summary-heading h5,
.ai-weather-chart-heading h5 {
  margin: 0;
  color: var(--text);
  font-size: 13px;
}
.ai-weather-summary-heading span,
.ai-weather-chart-heading span {
  color: var(--text-muted);
  font-size: 10px;
}
.ai-weather-summary-table-wrap {
  width: 100%;
  max-height: 320px;
  overflow-x: auto;
  overflow-y: auto;
}
.ai-weather-summary-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 11px;
}
.ai-weather-summary-table th {
  position: sticky;
  z-index: 1;
  top: 0;
  padding: 7px 10px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  text-align: left;
  text-transform: uppercase;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.ai-weather-summary-table td {
  padding: 9px 10px;
  color: var(--text-secondary);
  vertical-align: top;
  border-bottom: 1px solid var(--border-light);
}
.ai-weather-summary-table tbody tr:last-child td { border-bottom: 0; }
.ai-weather-summary-table td:first-child {
  max-width: 280px;
  color: var(--text);
  font-weight: 700;
}
.ai-lane-empty {
  padding: 12px 0;
  color: var(--text-muted);
  font-size: 13px;
}
.ai-lane-table-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 11px;
}
.ai-lane-table-meta span:first-child {
  color: var(--text);
  font-weight: 700;
}
.ai-lane-table-wrap {
  width: 100%;
  max-height: min(68vh, 760px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.ai-lane-table {
  width: 100%;
  min-width: 1120px;
  border-spacing: 0;
  border-collapse: separate;
  color: var(--text);
  font-size: 12px;
}
.ai-lane-table th,
.ai-lane-table td {
  height: 42px;
  padding: 8px 12px;
  border-right: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.ai-lane-table th:last-child,
.ai-lane-table td:last-child {
  border-right: 0;
}
.ai-lane-table thead th {
  position: sticky;
  z-index: 3;
  top: 0;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0;
  white-space: nowrap;
  background: var(--card-2);
}
.ai-lane-table thead th:first-child {
  z-index: 5;
  left: 0;
  min-width: 260px;
}
.ai-lane-table tbody + tbody tr:first-child > * {
  border-top: 1px solid var(--border);
}
.ai-lane-table tbody tr:hover td,
.ai-lane-table tbody tr:hover .ai-lane-zone {
  background: var(--card-2);
}
.ai-lane-object {
  position: sticky;
  z-index: 2;
  left: 0;
  width: 260px;
  min-width: 260px;
  max-width: 320px;
  color: var(--text);
  text-align: left;
  vertical-align: top !important;
  background: var(--card);
  box-shadow: 1px 0 0 var(--border);
}
.ai-lane-object-name,
.ai-lane-object-total {
  display: block;
}
.ai-lane-object-name {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.ai-lane-object-total {
  margin-top: 5px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  white-space: nowrap;
}
.ai-lane-zone {
  min-width: 170px;
  color: var(--text-secondary);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  background: var(--card);
}
.ai-lane-zone-marker {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  background: var(--lane-color);
  border-radius: 2px;
}
.ai-lane-number {
  min-width: 88px;
  font-variant-numeric: tabular-nums;
  text-align: right !important;
  white-space: nowrap;
}
.ai-lane-total {
  color: var(--lane-color, var(--text));
  font-size: 13px;
  font-weight: 800;
}
.ai-lane-share-cell {
  min-width: 112px;
  white-space: nowrap;
}
.ai-lane-share-value {
  display: inline-block;
  width: 34px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.ai-lane-share-track {
  display: inline-block;
  width: 54px;
  height: 5px;
  margin-left: 7px;
  overflow: hidden;
  vertical-align: middle;
  background: var(--card-2);
  border-radius: 2px;
}
.ai-lane-share-track > span {
  display: block;
  height: 100%;
  background: var(--lane-color);
}
.ai-lane-table tfoot th,
.ai-lane-table tfoot td {
  position: sticky;
  z-index: 3;
  bottom: 0;
  font-weight: 800;
  background: var(--card-2);
  border-bottom: 0;
}
.ai-lane-table tfoot th {
  z-index: 4;
  left: 0;
  text-align: left;
}
.ai-lane-share-total {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.ai-gost-table {
  min-width: 860px;
}
.ai-gost-table tbody tr:hover td,
.ai-gost-table tbody tr:hover .ai-gost-object {
  background: var(--card-2);
}
.ai-gost-object {
  vertical-align: middle !important;
}
.ai-gost-total {
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}
.ai-gost-heading {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}
.ai-gost-heading > span {
  width: 8px;
  min-width: 8px;
  height: 8px;
  background: var(--gost-color);
  border-radius: 2px;
}
.ai-gost-category-cell {
  min-width: 126px;
  padding: 0 !important;
}
.ai-gost-filter-cell {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  width: 100%;
  min-height: 41px;
  padding: 8px 12px;
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: right;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.ai-gost-filter-cell:hover {
  background: var(--card-2);
}
.ai-gost-filter-cell:focus-visible {
  outline: 2px solid var(--gost-color);
  outline-offset: -2px;
}
.ai-gost-filter-cell.is-active {
  background: var(--card-2);
  box-shadow: inset 3px 0 0 var(--gost-color);
}
.ai-gost-filter-cell:disabled {
  color: var(--text-muted);
  cursor: default;
  opacity: 0.55;
}
.ai-gost-cell-count {
  min-width: 42px;
  color: var(--gost-color);
  font-size: 13px;
  font-weight: 800;
}
.ai-gost-filter-cell:disabled .ai-gost-cell-count {
  color: var(--text-muted);
}
.ai-gost-cell-share {
  min-width: 34px;
  color: var(--text-muted);
  font-size: 10px;
}
.ai-gost-footer-cell {
  color: var(--gost-color);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.ai-gost-footer-cell strong {
  margin-right: 8px;
  font-size: 13px;
}
.ai-gost-footer-cell span {
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
}
.ai-gost-standard-header,
.ai-gost-hourly-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}
.ai-gost-standard-header > div,
.ai-gost-hourly-header > div:first-child {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.ai-gost-standard-header strong,
.ai-gost-hourly-header strong {
  color: var(--text);
  font-size: 13px;
}
.ai-gost-standard-header span,
.ai-gost-hourly-header span {
  color: var(--text-muted);
  font-size: 11px;
}
.ai-gost-standard-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.ai-gost-standard-metric {
  display: flex;
  min-width: 0;
  min-height: 86px;
  padding: 11px 12px;
  flex-direction: column;
  justify-content: center;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.ai-gost-standard-metric > span,
.ai-gost-standard-metric > small {
  overflow: hidden;
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.35;
  text-overflow: ellipsis;
}
.ai-gost-standard-metric > strong {
  margin: 4px 0 2px;
  color: var(--text);
  font-size: 17px;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.ai-gost-verification {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 16px;
  padding: 8px 10px;
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.45;
  background: color-mix(in srgb, #f59e0b 8%, transparent);
  border: 1px solid color-mix(in srgb, #f59e0b 36%, var(--border));
  border-radius: 5px;
}
.ai-gost-verification-mark {
  display: inline-grid;
  width: 20px;
  min-width: 20px;
  height: 20px;
  place-items: center;
  color: #f59e0b;
  font-size: 12px;
  font-weight: 800;
  border: 1px solid #f59e0b;
  border-radius: 50%;
}
.ai-gost-hourly-header {
  align-items: center;
  padding-top: 2px;
}
.ai-gost-hourly-controls {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.ai-gost-hourly-controls label {
  display: flex;
  color: var(--text-muted);
  font-size: 10px;
  flex-direction: column;
  gap: 3px;
}
.ai-gost-hourly-controls select {
  width: min(290px, 42vw);
  height: 32px;
  padding: 0 28px 0 9px;
  color: var(--text);
  font: inherit;
  font-size: 11px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 5px;
}
.ai-gost-hourly-controls label:last-child select {
  width: 132px;
}
.ai-gost-hourly-wrap {
  max-height: 420px;
  margin-bottom: 18px;
}
.ai-gost-hourly-table {
  min-width: 900px;
}
.ai-gost-hourly-table td:first-child {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
@media (max-width: 760px) {
  .ai-lane-table-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }
  .ai-lane-table-wrap {
    max-height: 62vh;
  }
  .ai-lane-table {
    min-width: 980px;
    font-size: 11px;
  }
  .ai-lane-table thead th:first-child,
  .ai-lane-object {
    width: 220px;
    min-width: 220px;
    max-width: 220px;
  }
  .ai-lane-table th,
  .ai-lane-table td {
    padding: 7px 9px;
  }
  .ai-lane-number {
    min-width: 76px;
  }
  .ai-gost-table {
    min-width: 760px;
  }
  .ai-gost-category-cell {
    min-width: 112px;
  }
  .ai-gost-standard-header,
  .ai-gost-hourly-header {
    align-items: flex-start;
    flex-direction: column;
  }
  .ai-gost-hourly-controls {
    width: 100%;
  }
  .ai-gost-hourly-controls label:first-child {
    min-width: 0;
    flex: 1;
  }
  .ai-gost-hourly-controls select {
    width: 100%;
  }
}
.ai-weather-state-label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 118px;
  line-height: 1.55;
  white-space: nowrap;
}
.ai-weather-state-label > span {
  width: 7px;
  min-width: 7px;
  height: 7px;
  background: var(--weather-state-color);
  border-radius: 50%;
}
.ai-weather-history-charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.ai-weather-chart-panel {
  min-width: 0;
  padding: 16px 18px 18px;
}
.ai-weather-chart-panel + .ai-weather-chart-panel {
  border-left: 1px solid var(--border);
}
.ai-weather-chart-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-height: 22px;
  margin-bottom: 10px;
}
.ai-weather-chart-heading span { text-align: right; }
.ai-weather-chart-canvas {
  position: relative;
  width: 100%;
  height: 300px;
}
.ai-weather-chart-canvas canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

@media (max-width: 1100px) {
  .ai-weather-history-header { align-items: stretch; flex-direction: column; }
  .ai-weather-history-controls { justify-content: flex-start; }
  .ai-weather-history-filter { flex: 1; min-width: 220px; }
  .ai-weather-history-charts { grid-template-columns: 1fr; }
  .ai-weather-chart-panel + .ai-weather-chart-panel {
    border-top: 1px solid var(--border);
    border-left: 0;
  }
}

@media (max-width: 680px) {
  .ai-weather-history-header,
  .ai-weather-object-summary,
  .ai-weather-chart-panel { padding-right: 12px; padding-left: 12px; }
  .ai-weather-history-controls {
    display: grid;
    grid-template-columns: 1fr 34px;
    align-items: end;
  }
  .ai-weather-history-filter { grid-column: 1 / -1; min-width: 0; }
  .ai-weather-periods { grid-template-columns: repeat(3, 1fr); }
  .ai-weather-periods button { min-width: 0; padding: 0 7px; }
  .ai-weather-summary-heading,
  .ai-weather-chart-heading { align-items: flex-start; flex-direction: column; gap: 2px; }
  .ai-weather-chart-heading span { text-align: left; }
  .ai-weather-chart-canvas { height: 260px; }
}

/* Device detail admin settings */
.detail-settings-panel {
  margin-bottom: 16px;
  border: 2px solid var(--primary);
  border-radius: var(--radius-lg);
}
.detail-settings-body { padding: 16px; }
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.settings-grid .form-group label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 3px;
  display: block;
}
.settings-grid .form-group input,
.settings-grid .form-group select {
  width: 100%;
}

/* ════════════════════════════════════════════
   DEVICE DETAIL — NEW LAYOUT (sidebar + hero + unified period)
   ════════════════════════════════════════════ */
.view-dd { padding: 0 !important; }

.dd-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 0;
  min-height: calc(100vh - var(--topbar-h, 56px));
  align-items: stretch;
}
.dd-layout.dd-sidebar-collapsed { grid-template-columns: 44px 1fr; }

/* ── Sidebar ── */
.dd-sidebar {
  background: var(--bg-secondary, #f8fafc);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: sticky;
  top: 0;
  align-self: start;
  height: calc(100vh - var(--topbar-h, 56px));
}
.dd-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.dd-sidebar-title { font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.dd-layout.dd-sidebar-collapsed .dd-sidebar-title,
.dd-layout.dd-sidebar-collapsed .dd-sidebar-filters,
.dd-layout.dd-sidebar-collapsed .dd-sidebar-list,
.dd-layout.dd-sidebar-collapsed .dd-sidebar-footer { display: none; }
.dd-layout.dd-sidebar-collapsed #dd-sidebar-toggle { transform: rotate(180deg); margin: 0 auto; }

.dd-sidebar-filters {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.dd-sidebar-filters input,
.dd-sidebar-filters select { width: 100%; font-size: 12px; }

.dd-sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}
.dd-sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  border-left: 3px solid transparent;
  font-size: 13px;
  color: var(--text, #111827);
  transition: background 120ms;
}
.dd-sidebar-item:hover { background: var(--card-2); }
.dd-sidebar-item.active {
  background: var(--primary-light);
  border-left-color: var(--primary);
  font-weight: 600;
}
.dd-sidebar-item .dd-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
  background: var(--gray);
}
.dd-sidebar-item .dd-dot.online  { background: #16a34a; box-shadow: 0 0 0 2px #16a34a22; }
.dd-sidebar-item .dd-dot.offline { background: #dc2626; }
.dd-sidebar-item .dd-dot.beacon  { background: #2563eb; box-shadow: 0 0 0 2px #2563eb33; }
.dd-sidebar-item .dd-dot.stolen  { background: #6b7280; }
.dd-sidebar-item .dd-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-sidebar-item .dd-sub { font-size: 10px; color: var(--text-muted); }

.dd-sidebar-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

/* ── Main column ── */
.dd-main {
  padding: 16px 20px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.dd-main .page-header { margin-bottom: 0; }

/* ── Compact title strip ── */
.dd-titlebar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px 4px;
}
.dd-titlebar-text { flex: 1; min-width: 0; }
.dd-titlebar-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.dd-titlebar-sub {
  font-size: 11px;
  margin: 0;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dd-titlebar-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Hero bar (sticky status) ── */
.dd-hero {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: center;
  padding: 8px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  position: sticky;
  top: 0;
  z-index: 10;
}
.dd-hero-beacon {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--bg-secondary, #f1f5f9);
  border: 1px solid var(--border);
  min-width: 0;
}
.dd-hero-beacon.beacon-on {
  background: var(--success-bg);
  border-color: var(--success);
}
.dd-hero-beacon.beacon-off {
  background: var(--warning-bg);
  border-color: var(--warning);
}
.dd-hero-beacon .beacon-light {
  width: 28px; height: 28px; flex-shrink: 0;
  /* Tame the police-flash-large animation inside the compact chip:
     shrink the spread and clip any overflow. */
  animation-name: police-flash-hero !important;
}
.dd-hero-beacon { overflow: hidden; }
@keyframes police-flash-hero {
  0%, 10%   { background: #2563eb; box-shadow: 0 0 6px rgba(37,99,235,.5); }
  25%       { background: #1e40af; box-shadow: 0 0 3px rgba(37,99,235,.2); }
  50%, 60%  { background: #ef4444; box-shadow: 0 0 6px rgba(239,68,68,.5); }
  75%       { background: #dc2626; box-shadow: 0 0 3px rgba(239,68,68,.2); }
  100%      { background: #2563eb; box-shadow: 0 0 6px rgba(37,99,235,.5); }
}
.dd-hero-beacon-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text);
  white-space: nowrap;
}

.dd-hero-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 4px 14px;
  min-width: 0;
}
.dd-metric { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.dd-metric-key {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
}
.dd-metric-val {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dd-metric-bar {
  height: 3px;
  background: var(--bg-secondary, #f1f5f9);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 2px;
}
.dd-metric-bar .battery-bar-fill { height: 100%; transition: width .4s; }

/* ── Toolbar: controls + period ── */
.dd-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 6px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 8px;
}
.dd-toolbar-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.dd-toolbar-controls .input-sm { width: 44px; padding: 3px 6px; }
.dd-toolbar-sep { width: 1px; height: 18px; background: var(--border); flex-shrink: 0; }
.dd-toolbar-label { font-size: 11px; color: var(--text-muted); white-space: nowrap; font-weight: 600; }
.dd-toolbar-period {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
}
.dd-toolbar-period .input-sm { padding: 3px 6px; font-size: 11px; }
.dd-cmd-status { padding: 4px 10px; border-radius: 6px; font-size: 11px; width: 100%; }
.dd-chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
  background: color-mix(in srgb, var(--card) 60%, transparent);
  pointer-events: none;
}
.dd-period-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.dd-period-btns { display: flex; gap: 4px; }
.dd-period-btn.active { background: var(--primary, #2563eb); color: #fff; border-color: var(--primary, #2563eb); }
.dd-period-custom { display: flex; align-items: center; gap: 6px; margin-left: auto; font-size: 11px; color: var(--text-muted); }
.dd-period-custom input { font-size: 12px; }
.dd-zoom-label { font-size: 11px; color: var(--text-muted); }

/* ── Chart card + timeline ── */
.dd-card-chart .dd-chart-wrap {
  position: relative;
  height: 300px;
  padding: 8px 12px 0;
}
.dd-card-timeline .timeline-container { padding: 0 0 6px; }

/* ── Logs row (events + commands side by side) ── */
.dd-logs-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.dd-card-log .dd-log-body {
  max-height: 420px;
  min-height: 260px;
  overflow-y: auto;
}
.dd-card-log .data-table th {
  position: sticky; top: 0; background: var(--card); z-index: 1;
}

/* ── Collapsible info accordion ── */
.dd-info-accordion { padding: 0; }
.dd-info-accordion > summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dd-info-accordion > summary::-webkit-details-marker { display: none; }
.dd-info-accordion > summary::before {
  content: '▸';
  color: var(--text-muted);
  transition: transform .2s;
}
.dd-info-accordion[open] > summary::before { transform: rotate(90deg); }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .dd-hero { grid-template-columns: 1fr; }
  .dd-toolbar { flex-direction: column; align-items: stretch; }
  .dd-toolbar-period { margin-left: 0; }
  .dd-logs-row { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .dd-layout { grid-template-columns: 1fr; }
  .dd-sidebar { position: static; height: auto; max-height: 240px; }
}

/* ════════════════════════════════════════════
   DEVICE DETAIL — LEGACY (kept for back-compat)
   ════════════════════════════════════════════ */
.detail-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
  align-content: flex-start;
}

.detail-grid > .card {
  flex: 1 1 280px;
  min-width: 200px;
  max-width: 100%;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

/* Cards with manual width from resize or span buttons */
.detail-grid > .card[style*="width"] {
  flex: 0 0 auto;
}

/* Stacked column for events + commands */
.detail-stack {
  flex: 1 1 280px;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detail-stack > .card {
  flex: 1;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

.card-compact .card-header { padding: 8px 12px; font-size: 13px; }
.card-compact .table-wrapper { font-size: 12px; }
.card-compact .data-table th,
.card-compact .data-table td { padding: 4px 8px; }

/* Chart cards default to full width */
.detail-chart-card {
  flex: 1 1 100% !important;
  min-width: 100%;
}
/* But allow chart cards to be resized narrower */
.detail-chart-card[style*="width"] {
  flex: 0 0 auto !important;
  min-width: 200px;
}

/* Width presets via data attribute */
.detail-grid > .card[data-col-span="1"] { flex: 0 0 calc(33.333% - 11px); }
.detail-grid > .card[data-col-span="2"] { flex: 0 0 calc(50% - 8px); }
.detail-grid > .card[data-col-span="3"] { flex: 0 0 calc(100%); }
.detail-grid > .card[data-col-span][style*="width"] { flex: 0 0 auto; }

@media (max-width: 768px) {
  .detail-grid > .card,
  .detail-grid > .card[data-col-span],
  .detail-stack,
  .detail-chart-card {
    flex: 1 1 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
  }
}

/* Detail edit mode (drag & drop / resize) */
.detail-edit-mode .card {
  outline: 2px dashed var(--primary);
  outline-offset: -2px;
  cursor: move;
  transition: box-shadow .15s, transform .1s;
}
.detail-edit-mode .card.dragging {
  opacity: 0.4;
  transform: scale(0.98);
}
.detail-edit-mode .card:hover {
  box-shadow: 0 4px 16px rgba(227, 30, 37, 0.2);
}
.drag-handle {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  font-size: 16px;
  line-height: 24px;
  text-align: center;
  color: var(--primary);
  cursor: grab;
  z-index: 10;
  user-select: none;
  border-radius: 4px;
  background: rgba(255,255,255,0.8);
}
.drag-handle:active { cursor: grabbing; }

/* Column span controls in edit mode */
.span-controls {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  gap: 2px;
  z-index: 10;
}
.span-controls button {
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: rgba(255,255,255,0.9);
  font-size: 10px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  color: var(--text);
  padding: 0;
}
.span-controls button:hover { background: var(--primary); color: #fff; }
.span-controls button.active { background: var(--primary); color: #fff; }

/* (responsive detail-grid breakpoints are defined above) */

.detail-status-body { padding: 16px; }

.beacon-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  margin-bottom: 16px;
}

.beacon-light {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #d1d5db;
  transition: background .3s, box-shadow .3s;
  margin-bottom: 10px;
}
.beacon-light.active {
  animation: police-flash-large 1s infinite;
}

.beacon-label { font-weight: 700; font-size: 15px; color: var(--text); }

/* Widget management */
.btn-widget-close {
  display: none;                  /* hidden by default, shown in edit mode */
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  margin-left: 8px;
  line-height: 1;
  border-radius: 4px;
  transition: color .2s, background .2s, border-color .2s;
  flex-shrink: 0;
}
.btn-widget-close:hover { color: var(--danger); background: var(--danger-bg); border-color: var(--danger); }

/* Show close buttons only in edit mode */
.detail-edit-mode .btn-widget-close { display: inline-flex; }

.widget-add-bar {
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.widget-picker {
  display: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  box-shadow: var(--shadow-card);
  gap: 6px;
  flex-wrap: wrap;
}
.widget-picker.show { display: flex; }

.widget-pick-btn { font-size: 12px !important; white-space: nowrap; }
.widget-pick-btn.disabled { opacity: .4; pointer-events: none; }

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
}
.status-row:last-child { border-bottom: none; }
.status-key { color: var(--text-muted); }
.status-val { font-weight: 500; }

.detail-battery-bar {
  height: 6px;
  background: var(--card-2);
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
}

.control-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.divider { border: none; border-top: 1px solid var(--border-light); margin: 4px 0; }

.info-body { padding: 16px; }
.info-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
  gap: 12px;
}
.info-row:last-child { border-bottom: none; }
.info-key { color: var(--text-muted); flex-shrink: 0; }
.info-val { font-weight: 500; text-align: right; }

/* ════════════════════════════════════════════
   EVENTS
   ════════════════════════════════════════════ */
.event-type-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}
.evt-offline       { background: var(--danger-bg); color: var(--danger); }
.evt-online        { background: var(--success-bg); color: var(--success); }
.evt-battery_low   { background: var(--warning-bg); color: var(--warning); }
.evt-command       { background: var(--primary-light); color: var(--primary); }
.evt-ccu           { background: var(--card-2); color: var(--text-muted); }
.evt-default       { background: var(--card-2); color: var(--text-muted); }

.cmd-success { color: var(--success); font-weight: 600; }
.cmd-fail    { color: var(--danger);  font-weight: 600; }

/* ════════════════════════════════════════════
   MODAL
   ════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,10,14,.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  animation: modal-bg-in .2s ease;
}
@keyframes modal-bg-in { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: var(--card);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 80px rgba(0,0,0,.25), 0 0 0 1px rgba(0,0,0,.04);
  animation: modal-card-in .3s cubic-bezier(.34,1.56,.64,1);
}

.ui-icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

.ui-icon {
  display: block;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.modal-close {
  display: inline-grid;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  padding: 0;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
  transition: color .15s ease, background-color .15s ease, border-color .15s ease;
}

.modal-close:hover {
  border-color: var(--border);
  color: var(--text);
  background: var(--bg);
}

.modal-close:active { transform: scale(.96); }
.modal-close:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn-icon {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  padding: 0;
  justify-content: center;
}
@keyframes modal-card-in {
  from { opacity: 0; transform: scale(.95) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-body   { padding: 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* ════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ════════════════════════════════════════════ */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 340px;
}

.toast {
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  color: #fff;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  animation: toast-in .3s cubic-bezier(.34,1.56,.64,1);
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.toast-success { background: rgba(26,159,74,.92); }
.toast-error   { background: rgba(220,38,38,.92); }
.toast-info    { background: rgba(200,25,31,.92); }
.toast-warning { background: rgba(217,119,6,.92); }

/* ════════════════════════════════════════════
   ANIMATIONS
   ════════════════════════════════════════════ */
@keyframes pulse-beacon {
  0%, 100% { opacity: 1; }
  50%       { opacity: .4; }
}

@keyframes police-flash {
  0%, 10%   { background: #2563eb; box-shadow: 0 0 8px rgba(37,99,235,.6); }
  25%       { background: #1e40af; box-shadow: 0 0 4px rgba(37,99,235,.3); }
  50%, 60%  { background: #ef4444; box-shadow: 0 0 8px rgba(239,68,68,.6); }
  75%       { background: #dc2626; box-shadow: 0 0 4px rgba(239,68,68,.3); }
  100%      { background: #2563eb; box-shadow: 0 0 8px rgba(37,99,235,.6); }
}

@keyframes police-flash-large {
  0%, 10%   { background: #2563eb; box-shadow: 0 0 0 12px rgba(37,99,235,.15), 0 0 30px rgba(37,99,235,.4); }
  25%       { background: #1e40af; box-shadow: 0 0 0 8px rgba(37,99,235,.1), 0 0 15px rgba(37,99,235,.2); }
  50%, 60%  { background: #ef4444; box-shadow: 0 0 0 12px rgba(239,68,68,.15), 0 0 30px rgba(239,68,68,.4); }
  75%       { background: #dc2626; box-shadow: 0 0 0 8px rgba(239,68,68,.1), 0 0 15px rgba(239,68,68,.2); }
  100%      { background: #2563eb; box-shadow: 0 0 0 12px rgba(37,99,235,.15), 0 0 30px rgba(37,99,235,.4); }
}

@keyframes pulse-beacon-large {
  0%, 100% { box-shadow: 0 0 0 12px rgba(227,30,37,.15), 0 0 30px rgba(227,30,37,.35); }
  50%       { box-shadow: 0 0 0 20px rgba(227,30,37,.08), 0 0 50px rgba(227,30,37,.5); }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: .3; }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px) scale(.9); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

/* ════════════════════════════════════════════
   LOADING STATE
   ════════════════════════════════════════════ */
.skeleton {
  background: linear-gradient(90deg, var(--card-2) 25%, var(--border) 50%, var(--card-2) 75%);
  background-size: 200% 100%;
  animation: skeleton-wave 1.8s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-wave {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ════════════════════════════════════════════
   USER BADGE (sidebar)
   ════════════════════════════════════════════ */
.user-badge {
  font-size: 12px;
  color: rgba(255,255,255,.7);
  padding: 8px 12px;
  border-radius: var(--radius);
  background: rgba(255,255,255,.06);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  font-weight: 500;
}
.user-badge:empty {
  display: none;
}

/* ════════════════════════════════════════════
   SECTION HEADERS (settings page)
   ════════════════════════════════════════════ */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.section-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

/* ════════════════════════════════════════════
   USERS TABLE BADGES
   ════════════════════════════════════════════ */
.btn-danger-outline {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}
.btn-danger-outline:hover {
  background: var(--danger);
  color: #fff;
}

/* Command result badges */
.cmd-success { color: var(--success); font-weight: 600; }
.cmd-fail    { color: var(--danger);  font-weight: 600; }

/* Event type badges */
.event-type-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}
.evt-offline    { background: var(--danger-bg); color: var(--danger); }
.evt-online     { background: var(--success-bg); color: var(--success); }
.evt-battery_low { background: var(--warning-bg); color: var(--warning); }
.evt-command    { background: var(--primary-light); color: var(--primary); }
.evt-ccu        { background: var(--card-2); color: #7c3aed; }
.evt-default    { background: var(--card-2); color: var(--text-muted); }

/* ════════════════════════════════════════════
   BULK SCHEDULE DEVICE LIST
   ════════════════════════════════════════════ */
.bulk-schedule-device-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 4px;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  background: var(--card-2);
}
.bulk-schedule-device-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  cursor: pointer;
  transition: background .1s;
}
.bulk-schedule-device-item:hover { background: var(--bg); }
.bulk-schedule-device-item input[type="checkbox"] { flex-shrink: 0; }
.bulk-schedule-device-item.stolen { opacity: .45; text-decoration: line-through; }

/* ════════════════════════════════════════════
   TIMELINE CHART
   ════════════════════════════════════════════ */
.timeline-period-btns { display: flex; gap: 4px; }
.timeline-period-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.timeline-container {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  min-height: 200px;
  cursor: grab;
}
.timeline-container:active { cursor: grabbing; }
#timeline-canvas { min-width: 100%; }
.timeline-legend {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-muted);
  align-items: center;
  flex-wrap: wrap;
}
.timeline-legend-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 4px;
}
.timeline-tooltip {
  position: fixed;
  z-index: 9999;
  background: rgba(17,24,39,.9);
  color: #fff;
  font-size: 12px;
  line-height: 1.5;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  pointer-events: none;
  display: none;
  max-width: 260px;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
}

/* ════════════════════════════════════════════
   REPORTS
   ════════════════════════════════════════════ */
.report-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  flex-wrap: wrap;
  border-bottom: 2px solid var(--border);
}
.report-tab {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.report-tab:hover { color: var(--text); }
.report-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 700; }

.report-period-presets { display: flex; gap: 4px; flex-wrap: wrap; }
.report-preset.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.report-filters { background: var(--card); }

/* Multi-select dropdown */
.multi-select { position: relative; display: inline-block; min-width: 160px; }
.multi-select-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; background: var(--card); cursor: pointer; user-select: none;
  white-space: nowrap; max-width: 220px;
}
.multi-select-toggle:hover { border-color: var(--primary); }
.multi-select-arrow { font-size: 10px; color: var(--text-muted); transition: transform .15s; }
.multi-select.open .multi-select-arrow { transform: rotate(180deg); }
.multi-select-label { overflow: hidden; text-overflow: ellipsis; color: var(--text); }

.multi-select-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 100;
  min-width: 240px; max-height: 320px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.multi-select-dropdown.hidden { display: none; }

.multi-select-actions {
  display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--border-light);
}
.multi-select-actions .btn { flex: 1; font-size: 11px; padding: 4px 8px; }

.multi-select-search { padding: 6px 8px; border-bottom: 1px solid var(--border-light); }
.multi-select-search .input-sm { width: 100%; font-size: 12px; }

.multi-select-list {
  overflow-y: auto; max-height: 220px; padding: 4px 0;
}
.multi-select-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px; font-size: 12.5px; cursor: pointer;
  transition: background .1s;
}
.multi-select-item:hover { background: var(--bg); }
.multi-select-item input[type="checkbox"] { accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.multi-select-item label { cursor: pointer; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.multi-select-item.ms-hidden { display: none; }

/* Uptime bar */
.uptime-bar { width: 80px; height: 8px; background: var(--card-2); border-radius: 4px; overflow: hidden; flex-shrink: 0; }
.uptime-bar-fill { height: 100%; border-radius: 4px; transition: width .3s; }
.uptime-bar-fill.good { background: var(--success); }
.uptime-bar-fill.warn { background: var(--warning); }
.uptime-bar-fill.bad  { background: var(--danger); }

/* Problem row highlights */
.report-row-warning { background: var(--warning-bg) !important; }
.report-row-danger  { background: var(--danger-bg) !important; }

/* Traffic light badges */
.traffic-light { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.traffic-green  { background: var(--success-bg); color: var(--success); }
.traffic-yellow { background: var(--warning-bg); color: var(--warning); }
.traffic-red    { background: var(--danger-bg); color: var(--danger); }

/* Report chart container */
.report-chart-wrap { position: relative; height: 260px; margin: 16px; }

/* Report section header */
.report-section-title { font-size: 14px; font-weight: 600; color: var(--text); margin: 20px 0 10px; padding-left: 4px; }

/* Needs maintenance badge */
.badge-maintenance { background: var(--warning-bg); color: var(--warning); font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 500; }

@media (max-width: 900px) {
  .report-tabs { gap: 0; }
  .report-tab { padding: 8px 12px; font-size: 12px; }
  .report-period-presets { width: 100%; }
  .uptime-bar { width: 60px; }
}

/* ════════════════════════════════════════════
   CAMERA SNAPSHOTS
   ════════════════════════════════════════════ */
.cam-snaps {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.cam-snap-wrap {
  flex: 1;
  min-width: 140px;
  max-width: 320px;
}
.cam-snap-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cam-snap-img {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: opacity .2s;
  display: block;
}
.cam-snap-img:hover { opacity: .85; }
.cam-snap-noimg {
  width: 100%;
  height: 80px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-muted);
}

/* Camera card expand (legacy — popups) */
.cam-expand { padding-top: 8px; border-top: 1px solid var(--border-light); margin-top: 8px; }

/* Lightbox slider overlay */
.cam-lightbox {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0,0,0,.92);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: camLbFadeIn .2s;
}
@keyframes camLbFadeIn { from { opacity: 0; } to { opacity: 1; } }
.cam-lb-close {
  position: absolute;
  top: 16px;
  right: 20px;
  display: inline-grid;
  width: 38px;
  height: 38px;
  padding: 0;
  place-items: center;
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  z-index: 10;
  opacity: .7;
  transition: opacity .2s, background-color .2s;
}
.cam-lb-close:hover { opacity: 1; background: rgba(0,0,0,.55); }
.cam-lb-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,.1);
  border: none;
  color: #fff;
  font-size: 48px;
  width: 56px;
  height: 80px;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background .2s;
  user-select: none;
}
.cam-lb-arrow:hover { background: rgba(255,255,255,.25); }
.cam-lb-prev { left: 16px; }
.cam-lb-next { right: 16px; }
.cam-lb-content {
  position: relative;
  max-width: 85vw;
  max-height: 85vh;
}
.cam-lb-img {
  max-width: 85vw;
  max-height: 85vh;
  object-fit: contain;
  display: block;
  border-radius: 4px;
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
}
.cam-lb-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 30px 16px 12px;
  background: linear-gradient(transparent, rgba(0,0,0,.75));
  border-radius: 0 0 4px 4px;
  pointer-events: none;
}
.cam-lb-name {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,.6);
}
.cam-lb-label {
  font-size: 12px;
  color: rgba(255,255,255,.7);
  margin-top: 2px;
}
.cam-lb-counter {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,.6);
  font-size: 13px;
  font-weight: 500;
}


/* Leaflet popup snapshots */
.leaflet-popup-content .cam-snaps { max-width: 460px; }
.leaflet-popup-content .cam-snap-wrap { max-width: 220px; }
.leaflet-popup-content .cam-snap-img { max-height: 160px; object-fit: cover; }
.leaflet-popup-content .map-live-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 6px;
}
.leaflet-popup-content .map-live-link {
  min-width: 104px;
}
.leaflet-popup-content .map-camera-previews {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: min(720px, calc(100vw - 64px));
  margin-top: 8px;
}
.leaflet-popup-content .map-camera-count-1 {
  grid-template-columns: minmax(0, 460px);
  width: min(460px, calc(100vw - 64px));
}
.leaflet-popup-content .map-camera-preview { min-width: 0; }
.leaflet-popup-content .map-preview-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #090d12;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.leaflet-popup-content .map-preview-image-button {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  color: #fff;
  background: transparent;
  cursor: pointer;
}
.leaflet-popup-content .map-preview-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #090d12;
  transition: opacity .15s ease;
}
.leaflet-popup-content .map-preview-play {
  position: absolute;
  left: 50%;
  top: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding-left: 3px;
  border-radius: 50%;
  color: #fff;
  background: rgba(9, 13, 18, .72);
  font-size: 16px;
  opacity: 0;
  transform: translate(-50%, -50%);
  transition: opacity .15s ease;
}
.leaflet-popup-content .map-preview-image-button:hover .map-preview-image { opacity: .82; }
.leaflet-popup-content .map-preview-image-button:hover .map-preview-play,
.leaflet-popup-content .map-preview-image-button:focus-visible .map-preview-play { opacity: 1; }
.leaflet-popup-content .map-preview-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 32px;
  padding: 5px 8px;
  border: 0;
  color: var(--text);
  background: var(--bg);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
}
.leaflet-popup-content .map-preview-caption:hover,
.leaflet-popup-content .map-preview-caption:focus-visible {
  color: #fff;
  background: var(--hover);
}
.leaflet-popup-content .map-preview-caption-action { color: var(--primary); }
.leaflet-popup-content .map-ai-stats { margin-top: 8px; }
.leaflet-popup-content .map-analytics-panel {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}
.leaflet-popup-content .map-analytics-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 9px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
}
.leaflet-popup-content .map-analytics-camera {
  min-width: 0;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.leaflet-popup-content .map-analytics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
.leaflet-popup-content .map-analytics-metric {
  min-width: 0;
  padding: 8px 6px;
  border-right: 1px solid var(--border);
  text-align: center;
}
.leaflet-popup-content .map-analytics-metric:last-child { border-right: 0; }
.leaflet-popup-content .map-analytics-metric span,
.leaflet-popup-content .map-analytics-metric small {
  display: block;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 9px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.leaflet-popup-content .map-analytics-metric strong {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.leaflet-popup-content .map-analytics-weather strong { font-size: 12px; }
.leaflet-popup-content .map-analytics-loading,
.leaflet-popup-content .map-analytics-empty {
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 11px;
  text-align: center;
}

@media (max-width: 480px) {
  .leaflet-popup-content-wrapper {
    max-width: calc(100vw - 24px);
  }
  .leaflet-popup-content {
    width: auto !important;
    max-width: calc(100vw - 52px);
  }
  .leaflet-popup-content .map-camera-previews {
    grid-template-columns: 1fr;
  }
  .leaflet-popup-content .map-player-open {
    width: 100%;
  }
  .leaflet-popup-content .map-analytics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .leaflet-popup-content .map-analytics-metric {
    border-bottom: 1px solid var(--border);
  }
  .leaflet-popup-content .map-analytics-metric:nth-child(2) { border-right: 0; }
  .leaflet-popup-content .map-analytics-metric:nth-child(even) { border-right: 0; }
  .leaflet-popup-content .map-analytics-metric:last-child { border-bottom: 0; }
}

@media (max-width: 768px) {
  .cameras-grid { grid-template-columns: 1fr; }
  .cam-snap-wrap { min-width: 100%; max-width: 100%; }
  .leaflet-popup-content .cam-snap-wrap { max-width: 100%; }
  .cam-lb-arrow { width: 40px; height: 60px; font-size: 32px; }
  .cam-lb-prev { left: 4px; }
  .cam-lb-next { right: 4px; }
  .cam-lb-content { max-width: 95vw; max-height: 80vh; }
  .cam-lb-img { max-width: 95vw; max-height: 80vh; }
}

/* ════════════════════════════════════════════
   PERMISSIONS TABLE (user modal)
   ════════════════════════════════════════════ */
.perm-table-wrapper {
  max-height: 400px;
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.perm-table { font-size: 12px; }
.perm-table thead th { position: sticky; top: 0; z-index: 2; }
.perm-th { text-align: center !important; width: 44px; font-size: 14px !important; padding: 4px 2px !important; }
.perm-table td { padding: 4px 8px !important; }
.perm-table td:not(:first-child) { text-align: center; }
.perm-table input[type="checkbox"] { cursor: pointer; accent-color: var(--primary); }
.perm-device-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; display: block; }
.perm-device-type { font-size: 10px; color: var(--text-muted); }
.perm-row-header {
  background: var(--card-2);
  font-weight: 600;
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .3px;
}
.perm-row-header td { padding: 6px 8px !important; }
.perm-row-district {
  background: var(--bg-secondary);
  font-size: 12px;
  font-weight: 500;
}
.perm-row-district td { padding: 4px 8px !important; }
.district-arrow { font-size: 10px; transition: transform .2s; }
.perm-global-label {
  display: flex; align-items: center; gap: 4px; font-size: 13px;
  cursor: pointer; padding: 4px 8px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface);
}
.perm-global-label:hover { background: var(--hover); }
.perm-global-label input { accent-color: var(--primary); }

.perm-col-toggle { cursor: pointer; user-select: none; }
.perm-col-toggle:hover { background: var(--hover); }

.perm-tpl-btn { font-size: 12px !important; }
.perm-tpl-btn:hover { background: var(--primary) !important; color: #fff !important; }

.impersonation-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
  background: linear-gradient(90deg, #e65100, #ff6d00);
  color: #fff; text-align: center; padding: 8px 16px;
  font-size: 13px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.impersonation-banner.hidden { display: none; }
body.impersonating { padding-top: 40px; }

@media (max-width: 768px) {
  .perm-th { width: 36px; font-size: 9.5px !important; }
  .perm-device-name { max-width: 100px; }
}

/* ════════════════════════════════════════════
   OVERVIEW (24h all devices)
   ════════════════════════════════════════════ */
.overview-timelines {
  max-height: calc(100vh - 260px);
  overflow-y: auto;
}

.overview-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border-light);
  padding: 0;
  transition: background .1s;
  cursor: pointer;
}
.overview-row:last-child { border-bottom: none; }
.overview-row:hover { background: var(--card-2); }

.overview-row-label {
  width: 220px;
  min-width: 220px;
  padding: 8px 12px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.overview-row-label .ov-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.overview-row-label .ov-district { font-size: 10.5px; color: var(--text-muted); font-weight: 400; }
.overview-row-label .ov-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  margin-top: 1px;
}

.overview-row-canvas {
  flex: 1;
  min-width: 0;
  height: 32px;
}

.overview-period-btns { display: flex; gap: 4px; }
.overview-period-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

@media (max-width: 768px) {
  .overview-row-label { width: 120px; min-width: 120px; padding: 6px 8px; font-size: 11px; }
  .overview-kpi { grid-template-columns: repeat(2, 1fr) !important; }
  .overview-timelines { max-height: calc(100vh - 300px); }
  .overview-legend { display: none !important; }
}

/* ── Освещение на карте (glowing polyline) ── */
.lighting-line { transition: stroke .3s, stroke-width .3s; }
.lighting-on {
  filter: drop-shadow(0 0 4px #ffca28) drop-shadow(0 0 8px rgba(255,179,0,.75));
  animation: lightingPulse 2.4s ease-in-out infinite;
}
@keyframes lightingPulse {
  0%, 100% { stroke-opacity: 0.95; filter: drop-shadow(0 0 4px #ffca28) drop-shadow(0 0 8px rgba(255,179,0,.6)); }
  50%      { stroke-opacity: 1;    filter: drop-shadow(0 0 7px #ffde59) drop-shadow(0 0 14px rgba(255,193,7,.9)); }
}

/* Более широкая модалка устройства (для карты освещения) */
#edit-modal .modal-card { max-width: 860px; }

/* Мини-редактор ломаной освещения */
#edit-light-map { width: 100%; height: 380px; border-radius: 8px; border: 1px solid var(--border); }

/* Карта положения устройства */
#edit-pos-map { width: 100%; height: 320px; border-radius: 8px; border: 1px solid var(--border); }

/* Рабочее пространство AI-видеоаналитики */
.ai-page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}
.ai-page-header .page-title {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}
.ai-page-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}
.ai-toolbar-field {
  display: grid;
  gap: 3px;
  min-width: 150px;
  color: var(--text-muted);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
}
#ai-camera-filter-wrap { width: min(360px, 30vw); }
.ai-toolbar-field select {
  width: 100%;
  height: 32px;
  padding: 0 28px 0 9px;
  overflow: hidden;
  color: var(--text);
  font: inherit;
  font-size: 11px;
  font-weight: 500;
  text-overflow: ellipsis;
  text-transform: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 5px;
}
.ai-runtime-status {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 32px;
}
#ai-status-badge,
#ai-detect-badge {
  padding: 3px 7px;
  color: var(--text-muted);
  font-size: 10px;
  white-space: nowrap;
  background: var(--bg-secondary);
  border-radius: 9px;
}
#ai-hailo-badge {
  color: var(--text-muted);
  font-size: 10px;
  white-space: nowrap;
}
.ai-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
}
.ai-tab {
  min-width: 84px;
  padding: 9px 14px;
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.ai-tab:hover { color: var(--text); background: var(--bg-secondary); }
.ai-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.ai-workspace {
  display: grid;
  gap: 12px;
  min-width: 0;
}
.ai-panel {
  min-width: 0;
  margin-bottom: 12px;
  padding: 13px 14px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  margin-bottom: 10px;
}
.ai-panel-header h4 {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  letter-spacing: 0;
}
.ai-panel-actions,
.ai-event-filters {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}
.ai-period-toggle { margin: 0; }
.ai-gost-toolbar .ai-panel-actions { flex-wrap: wrap; }
.ai-gost-custom-range {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}
.ai-gost-custom-range[hidden] { display: none; }
.ai-gost-custom-range label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--text-muted);
  font-size: 9px;
}
.ai-gost-custom-range input {
  width: 176px;
  min-height: 30px;
  padding: 4px 7px;
  color: var(--text);
  font: inherit;
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.ai-inline-state {
  padding: 18px 4px;
  color: var(--text-muted);
  font-size: 12px;
}
.ai-traffic-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(240px, 1fr);
  gap: 12px;
  min-width: 0;
}
.ai-chart-panel { min-height: 338px; }
.ai-compact-table-wrap {
  min-width: 0;
  overflow: auto;
}
.ai-compact-table {
  width: 100%;
  font-size: 11px;
}
.ai-compact-table th,
.ai-compact-table td { padding: 7px 9px; }
.ai-compact-table td:last-child {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  text-align: right;
}
.ai-disclosure {
  min-width: 0;
  margin-bottom: 12px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.ai-disclosure > summary {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 0 13px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  list-style: none;
}
.ai-disclosure > summary::-webkit-details-marker { display: none; }
.ai-disclosure > summary::after {
  margin-left: auto;
  color: var(--text-muted);
  content: '+';
  font-size: 16px;
  font-weight: 400;
}
.ai-disclosure[open] > summary::after { content: '−'; }
.ai-disclosure[open] > summary { border-bottom: 1px solid var(--border); }
.ai-disclosure-body { padding: 12px 13px; }
.ai-node-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}
.ai-monitor-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 12px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.ai-monitor-metrics > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 10px 12px;
  border-right: 1px solid var(--border);
}
.ai-monitor-metrics > div:last-child { border-right: 0; }
.ai-monitor-metrics span {
  overflow: hidden;
  color: var(--text-muted);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-monitor-metrics strong {
  color: var(--text);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.ai-camera-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.ai-speed-filter-header { align-items: flex-start; }
.ai-speed-custom-range,
.ai-speed-own-range,
.ai-speed-filters {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  min-width: 0;
  margin-top: 9px;
  flex-wrap: wrap;
}
.ai-speed-custom-range[hidden],
.ai-speed-own-range[hidden] { display: none; }
.ai-speed-custom-range label,
.ai-speed-own-range label,
.ai-speed-filters label:not(.ai-speed-checkbox) {
  display: flex;
  flex: 1 1 150px;
  flex-direction: column;
  gap: 4px;
  min-width: 130px;
  color: var(--text-muted);
  font-size: 10px;
}
.ai-speed-filters select,
.ai-speed-filters input[type="number"],
.ai-speed-custom-range input,
.ai-speed-own-range input {
  width: 100%;
  min-height: 34px;
  padding: 5px 8px;
  color: var(--text);
  font: inherit;
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
}
.ai-speed-filters .ai-speed-number { flex-grow: 0; flex-basis: 105px; }
.ai-speed-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  color: var(--text-secondary);
  font-size: 11px;
  white-space: nowrap;
}
.ai-speed-checkbox input { width: 15px; height: 15px; accent-color: var(--primary); }
.ai-speed-kpis {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-bottom: 12px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.ai-speed-kpis > div {
  min-width: 0;
  padding: 11px 12px;
  border-right: 1px solid var(--border);
}
.ai-speed-kpis > div:last-child { border-right: 0; }
.ai-speed-kpis span,
#ai-speed-range-label,
#ai-speed-events-count {
  display: block;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-speed-kpis strong {
  display: block;
  margin-top: 3px;
  color: var(--text);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ai-speed-chart { position: relative; width: 100%; height: 250px; }
.ai-speed-table { width: 100%; min-width: 820px; font-size: 11px; }
.ai-speed-table th,
.ai-speed-table td { padding: 8px 9px; }
.ai-speed-table th:not(:first-child),
.ai-speed-table td:not(:first-child) { text-align: right; }
.ai-speed-table td { font-variant-numeric: tabular-nums; }
.ai-speed-events {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 9px;
}
.ai-speed-event {
  min-width: 0;
  padding: 0;
  overflow: hidden;
  color: var(--text);
  font: inherit;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
}
.ai-speed-event:hover { border-color: var(--text-muted); }
.ai-speed-event-media {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: var(--bg-secondary);
}
.ai-speed-event-media img { width: 100%; height: 100%; object-fit: cover; }
.ai-speed-event-value,
.ai-speed-event-gost {
  position: absolute;
  top: 6px;
  padding: 2px 6px;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.4;
  border-radius: 3px;
  box-shadow: 0 1px 3px rgb(0 0 0 / 35%);
}
.ai-speed-event-value { right: 6px; background: #0284c7; }
.ai-speed-event-gost { left: 6px; }
.ai-speed-event-meta { display: grid; gap: 2px; padding: 7px 8px; }
.ai-speed-event-meta strong,
.ai-speed-event-meta span,
.ai-speed-event-meta time {
  overflow: hidden;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-speed-event-meta strong { font-size: 11px; }
.ai-speed-event-meta span,
.ai-speed-event-meta time { color: var(--text-muted); }
.ai-speed-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 34px;
  margin-top: 11px;
  color: var(--text-muted);
  font-size: 11px;
}
.ai-event-filters button {
  min-height: 30px;
  padding: 0 10px;
  color: var(--text-muted);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}
.ai-event-filters button:hover { color: var(--text); border-color: var(--text-muted); }
.ai-training-disclosure { margin-bottom: 12px; }
.ai-axle-panel {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.ai-weather-current-table { min-width: 780px; }
.ai-weather-current-table td { vertical-align: middle; }
.ai-weather-current-name {
  max-width: 340px;
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-weather-current-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  white-space: nowrap;
}
.ai-weather-current-dot {
  width: 7px;
  min-width: 7px;
  height: 7px;
  background: var(--ai-state-color);
  border-radius: 50%;
}
.ai-weather-current-meta {
  color: var(--text-muted);
  font-size: 10px;
  white-space: nowrap;
}
.ai-weather-current-table tr.is-stale td { opacity: .7; }
.ai-weather-current-table tr.is-stale .ai-weather-current-meta { color: var(--warning); }
/* Скрытие панелей неактивной вкладки — !important перебивает инлайновый display */
.ai-hidden { display: none !important; }

@media (max-width: 900px) {
  .ai-page-header { align-items: flex-start; flex-direction: column; }
  .ai-page-toolbar { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  #ai-camera-filter-wrap { width: min(420px, 48vw); }
  .ai-traffic-grid { grid-template-columns: 1fr; }
  .ai-chart-panel { min-height: 0; }
  .ai-speed-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ai-speed-kpis > div:nth-child(3) { border-right: 0; }
  .ai-speed-kpis > div:nth-child(-n+3) { border-bottom: 1px solid var(--border); }
}

@media (max-width: 620px) {
  .ai-page-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .ai-toolbar-field,
  #ai-camera-filter-wrap { width: auto; min-width: 0; }
  #ai-camera-filter-wrap { grid-column: 1 / -1; }
  .ai-runtime-status { grid-column: 1 / -1; overflow-x: auto; }
  .ai-tabs { margin-right: -8px; margin-left: -8px; padding-left: 8px; }
  .ai-tab { min-width: 76px; padding-right: 11px; padding-left: 11px; }
  .ai-panel { padding: 10px; }
  .ai-panel-header { align-items: flex-start; flex-direction: column; }
  .ai-panel-actions { width: 100%; align-items: flex-start; flex-direction: column; }
  .ai-period-toggle { width: 100%; overflow-x: auto; }
  .ai-gost-custom-range { width: 100%; flex-wrap: wrap; }
  .ai-gost-custom-range label { flex: 1 1 180px; }
  .ai-gost-custom-range input { width: 100%; }
  .ai-monitor-metrics { grid-template-columns: 1fr 1fr; }
  .ai-monitor-metrics > div { border-bottom: 1px solid var(--border); }
  .ai-monitor-metrics > div:nth-child(2) { border-right: 0; }
  .ai-camera-preview-grid { grid-template-columns: 1fr; }
  .ai-speed-filter-header { align-items: flex-start; }
  .ai-speed-filters label:not(.ai-speed-checkbox) { flex-basis: calc(50% - 5px); }
  .ai-speed-filters .ai-speed-number { flex-basis: calc(50% - 5px); }
  .ai-speed-filters .btn { flex: 1 1 100%; }
  .ai-speed-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ai-speed-kpis > div:nth-child(3) { border-right: 1px solid var(--border); }
  .ai-speed-kpis > div:nth-child(2n) { border-right: 0; }
  .ai-speed-kpis > div:nth-child(-n+4) { border-bottom: 1px solid var(--border); }
  .ai-speed-events { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ai-event-filters { width: 100%; justify-content: flex-start; }
}

.ai-event-photo {
  text-align: center;
}

.ai-event-photo-stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
}

.ai-event-photo-stage > img {
  display: block;
  max-width: 100%;
  max-height: 48vh;
  border-radius: 8px;
}

.ai-event-trajectory {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.ai-event-trajectory polyline {
  fill: none;
  stroke: #22d3ee;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.ai-event-trajectory circle {
  fill: #22d3ee;
  stroke: rgba(0, 0, 0, .72);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.ai-event-detection {
  --detection-color: #ef4444;
  position: absolute;
  box-sizing: border-box;
  border: 1px solid var(--detection-color);
  border-radius: 2px;
  pointer-events: none;
}

.ai-event-detection.is-high {
  --detection-color: #22c55e;
}

.ai-event-detection.is-medium {
  --detection-color: #f59e0b;
}

.ai-event-detection-label {
  position: absolute;
  top: -2px;
  left: 0;
  max-width: min(190px, 55vw);
  padding: 2px 4px;
  transform: translateY(-100%);
  overflow: hidden;
  color: #fff;
  background: color-mix(in srgb, var(--detection-color) 88%, transparent);
  border-radius: 2px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 1px rgba(0, 0, 0, .5);
}

.ai-event-detection.is-label-below .ai-event-detection-label {
  top: 2px;
  transform: none;
}

.ai-event-detection.is-label-right .ai-event-detection-label {
  right: 0;
  left: auto;
}

/* Каплевидные пины на карте (маяки/камеры) */
.map-pin-wrap { background: none; border: none; }
.map-pin {
  width: 30px; height: 30px;
  border-radius: 50% 50% 50% 0;
  background: var(--pc);
  transform: rotate(-45deg);
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
  box-shadow: 0 3px 8px rgba(0,0,0,.4);
}
.map-pin svg { transform: rotate(45deg); }
.map-pin.pulse { animation: pinGlow 1.3s ease-in-out infinite; }
@keyframes pinGlow {
  0%, 100% { box-shadow: 0 3px 8px rgba(0,0,0,.4), 0 0 6px 1px var(--pc); }
  50%      { box-shadow: 0 3px 8px rgba(0,0,0,.4), 0 0 16px 5px var(--pc); }
}
/* Круглый бейдж */
.map-badge {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--pc); border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
}
.map-badge.pulse { animation: pinGlow 1.3s ease-in-out infinite; }
/* Эмодзи-маркер */
.map-emoji { font-size: 20px; line-height: 1; text-align: center; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }
.map-emoji.pulse { animation: emojiPulse 1s ease-in-out infinite; }
@keyframes emojiPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.2); } }

/* Квадрат */
.map-sq { width: 28px; height: 28px; border-radius: 8px; background: var(--pc); border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; }
.map-sq.pulse { animation: pinGlow 1.3s ease-in-out infinite; }
/* Ромб */
.map-diamond { width: 26px; height: 26px; border-radius: 6px; background: var(--pc); border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.4); transform: rotate(45deg); display: flex; align-items: center; justify-content: center; }
.map-diamond-in { transform: rotate(-45deg); display: flex; }
.map-diamond.pulse { animation: pinGlow 1.3s ease-in-out infinite; }
/* Кольцо */
.map-ring { width: 28px; height: 28px; border-radius: 50%; background: #fff; border: 3px solid var(--pc); box-shadow: 0 2px 6px rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; }
.map-ring.pulse { animation: ringGlow 1.3s ease-in-out infinite; }
@keyframes ringGlow { 0%,100% { box-shadow: 0 2px 6px rgba(0,0,0,.35), 0 0 5px 1px var(--pc); } 50% { box-shadow: 0 2px 6px rgba(0,0,0,.35), 0 0 14px 4px var(--pc); } }
/* Радар (пульсирующий пинг) */
.map-radar { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; position: relative; }
.map-radar-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--pc); border: 2px solid #fff; z-index: 1; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.map-radar::before, .map-radar::after { content: ''; position: absolute; width: 12px; height: 12px; border-radius: 50%; background: var(--pc); opacity: .55; animation: radarPing 1.8s ease-out infinite; }
.map-radar::after { animation-delay: .9s; }
@keyframes radarPing { 0% { transform: scale(1); opacity: .55; } 100% { transform: scale(3.2); opacity: 0; } }
/* Звезда шерифа */
.map-star { width: 30px; height: 30px; border-radius: 50%; background: var(--pc); border: 2px solid #fff; box-shadow: 0 2px 7px rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; }
.map-star.pulse { animation: pinGlow 1.3s ease-in-out infinite; }

/* Освещение — бегущая линия (marching ants) */
.lighting-run { animation: lightRun 1s linear infinite; }
@keyframes lightRun { to { stroke-dashoffset: -24; } }

/* Селектор дорог/камер (master) */
.ai-road-group { border-top: 1px solid var(--border-light); }
.ai-road-ghead {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 8px; cursor: pointer; font-size: 13px; font-weight: 600;
  user-select: none; border-radius: 6px;
}
.ai-road-ghead:hover { background: var(--bg-secondary); }
.ai-road-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 8px 6px 22px; cursor: pointer; font-size: 13px;
  border-radius: 6px; transition: background .12s;
}
.ai-road-item:hover { background: var(--bg-secondary); }
.ai-road-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.ai-road-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-road-count { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--text-muted); margin-left: 10px; flex-shrink: 0; }
.ai-road-item.active .ai-road-count { color: var(--primary); }

/* Кликабельные KPI-карточки обзора (фильтр) */
.kpi-card.kpi-clickable { cursor: pointer; transition: transform .12s, box-shadow .12s; }
.kpi-card.kpi-clickable:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.kpi-card.kpi-clickable.active { outline: 2px solid var(--primary); outline-offset: 1px; }

/* Таймлапс на карте */
#map-timelapse-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tl-bar {
  display: flex; align-items: center; gap: 10px;
  margin-top: 10px; padding: 8px 14px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow-card);
}
.tl-bar input[type="range"] { accent-color: var(--primary); height: 4px; }
.tl-time { font-family: var(--font-mono); font-size: 13px; font-weight: 600; min-width: 118px; text-align: center; color: var(--text); }
.tl-speed { padding: 3px 6px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; background: var(--bg); }

/* ════════════════════════════════════════════
   RESIZABLE WIDGETS
   ════════════════════════════════════════════ */
.resizable {
  position: relative;
  overflow: hidden;
  min-height: 60px;
}
.resizable.resizing { user-select: none; }

/* Drag handle (bottom-right corner) */
.resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 20px;
  height: 20px;
  cursor: nwse-resize;
  z-index: 10;
  opacity: 0;
  transition: opacity .2s;
}
.resizable:hover .resize-handle { opacity: 1; }

.resize-handle::before,
.resize-handle::after {
  content: '';
  position: absolute;
  background: var(--gray);
  border-radius: 1px;
}
.resize-handle::before {
  width: 10px; height: 2px;
  bottom: 5px; right: 3px;
  transform: rotate(-45deg);
}
.resize-handle::after {
  width: 6px; height: 2px;
  bottom: 4px; right: 2px;
  transform: rotate(-45deg) translate(-2px, -4px);
}

/* Vertical-only resize handle */
.resize-handle-v {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 8px;
  cursor: ns-resize;
  z-index: 10;
  opacity: 0;
  transition: opacity .2s;
}
.resizable:hover .resize-handle-v { opacity: 1; }

.resize-handle-v::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 2px;
  transform: translateX(-50%);
  width: 32px;
  height: 3px;
  background: var(--gray);
  border-radius: 2px;
}

/* Reset button (top-right) */
.resize-reset {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border: none;
  background: var(--bg);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-muted);
  z-index: 10;
  line-height: 1;
  padding: 0;
}
.resize-reset:hover { background: var(--border); color: var(--text); }
.resizable.resized .resize-reset { display: flex; }
.resizable.resized:hover .resize-reset { display: flex; }

/* Chart cards need overflow visible for handle but clip content */
.detail-chart-card.resizable { overflow: hidden; }
.detail-chart-card.resizable > .card-header { position: relative; z-index: 2; }

/* Map container resizable */
.map-container.resizable { overflow: hidden; }

/* ════════════════════════════════════════════
   MOBILE RESPONSIVE
   ════════════════════════════════════════════ */

/* ── Hamburger button ── */
.hamburger {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1100;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--sidebar-bg);
  border: none;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: #fff;
  border-radius: 1px;
  transition: transform .2s, opacity .2s;
}
.hamburger.active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.active span:nth-child(2) { opacity: 0; }
.hamburger.active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Sidebar overlay ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 999;
}
.sidebar-overlay.active { display: block; }

@media (max-width: 768px) {
  .hamburger { display: flex; }

  /* Sidebar → slide-in drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform .25s ease;
    width: 260px;
    min-width: 260px;
  }
  .sidebar.open { transform: translateX(0); }

  /* Main content fills full width */
  .app { flex-direction: column; }
  .main-content {
    padding: 60px 12px 16px 12px;
    width: 100%;
  }

  /* Page header stack */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .page-title { font-size: 18px; }
  .page-actions { width: 100%; flex-wrap: wrap; }

  /* KPI grid → 2 columns */
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 16px; }
  .kpi-card { padding: 12px 14px; }
  .kpi-value { font-size: 24px; }
  .kpi-label { font-size: 11px; }

  /* Device cards → single column */
  .device-grid { grid-template-columns: 1fr; gap: 10px; }


  /* Filter rows wrap */
  .filter-row { flex-direction: column; align-items: stretch; gap: 6px; }
  .filter-row .select-sm,
  .filter-row .input-sm { width: 100%; }
  .filter-row > span[style*="flex:1"] { display: none; }

  /* Tables */
  .data-table { font-size: 12px; }
  .data-table thead th { padding: 8px 10px; font-size: 10.5px; }
  .data-table td { padding: 8px 10px; }

  /* Detail grid → single column on mobile */
  .detail-grid > .card {
    flex: 1 1 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
  }

  /* Map */
  .map-container { height: calc(100vh - 200px); min-height: 300px; }

  /* Map page header actions */
  .map-layer-toggle { margin-right: 0; }
  .map-legend { font-size: 11px; gap: 8px; padding: 5px 10px; }

  /* Reports */
  .report-tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .report-tab { padding: 8px 12px; font-size: 12px; flex-shrink: 0; }
  .report-period-presets { width: 100%; }
  .report-chart-wrap { height: 200px; margin: 12px 8px; }

  /* Multi-select */
  .multi-select { min-width: 100%; }
  .multi-select-dropdown { min-width: 100%; }

  /* Bulk schedule */
  #bulk-schedule-body > div[style*="display:flex"] { flex-direction: column; }

  /* Modals */
  .modal-overlay { padding: 8px; align-items: flex-end; }
  .modal-card { max-width: 100%; max-height: 85vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .form-row { grid-template-columns: 1fr; gap: 0; }

  /* Toast → full width */
  #toast-container { left: 12px; right: 12px; max-width: none; }

  /* Timeline */
  .timeline-legend { font-size: 11px; gap: 8px; }
  .timeline-legend span[style*="margin-left:auto"] { display: none; }

  /* Section headers */
  .section-header { flex-direction: column; align-items: flex-start; }

  /* Disable resize on mobile */
  .resize-handle,
  .resize-handle-v,
  .resize-reset { display: none !important; }
  .resizable { overflow: visible; }

  /* Login card */
  .login-card { width: 100%; padding: 32px 24px; margin: 16px; }

  /* Detail page back + title */
  #view-device-detail .page-header > div[style] { flex-wrap: wrap; }

  /* Buttons in page actions */
  .page-actions .btn { font-size: 12px; padding: 6px 10px; }
}

/* Small phones */
@media (max-width: 400px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .kpi-value { font-size: 20px; }
  .main-content { padding: 56px 8px 12px 8px; }
  .device-card { padding: 12px; }
  .page-title { font-size: 16px; }
}

/* Print styles */
@media print {
  .sidebar, .page-actions, .report-tabs, .report-filters,
  #btn-report-csv, #btn-report-print, .sidebar-footer,
  .report-period-presets, #btn-report-generate,
  #report-district-filter { display: none !important; }
  .app { display: block !important; }
  .main-content { margin-left: 0 !important; padding: 10px !important; overflow: visible !important; }
  .view { display: none !important; }
  #view-reports { display: block !important; }
  #view-reports .page-header .page-title { display: block !important; font-size: 18pt; }
  #view-reports .page-header .page-subtitle { display: block !important; }
  #view-reports .page-header { display: block !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd !important; break-inside: avoid; margin-bottom: 12px !important; }
  .data-table { font-size: 9pt; }
  .kpi-grid { grid-template-columns: repeat(3, 1fr) !important; }
  .kpi-value { font-size: 18pt; }
  #report-content { display: block !important; }
}

/* ═══════════════════════════════════════════════════════════════
   ДАШБОРД-ДИСПЕТЧЕРСКАЯ — шапка, приборы, лампа-маяк
   (элементы шаблона «Ночная диспетчерская»)
   ═══════════════════════════════════════════════════════════════ */
.dispatch-header { align-items: flex-end; }
.page-header .eyebrow, .eyebrow {
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: .22em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 2px;
}
.page-title.display {
  font-family: var(--font-display);
  font-weight: 600; text-transform: uppercase; letter-spacing: .01em;
  font-size: 26px; line-height: 1.12; margin-top: 3px;
  text-wrap: balance;
}
.dispatch-clock {
  display: flex; flex-direction: column; align-items: flex-end; gap: 2px;
  font-family: var(--font-mono); font-size: 11px; color: var(--text-muted);
}
.dispatch-clock .clock-geo { letter-spacing: .08em; }
.dispatch-clock b {
  font-family: var(--font-display); font-size: 22px; font-weight: 600;
  color: var(--text); letter-spacing: .04em; line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* KPI — приборные подписи снизу */
.kpi-foot {
  font-family: var(--font-mono); font-size: 11px; color: var(--text-muted);
  margin-top: 6px; font-variant-numeric: tabular-nums;
}

/* Заголовок секции устройств — дисплейный, с линией-разделителем */
.section-header h3 {
  font-family: var(--font-display); text-transform: uppercase;
  letter-spacing: .06em; font-size: 15px; color: var(--text-muted); font-weight: 600;
}

/* Карточка: полоса-статус слева (как в шаблоне), а не сверху */
.device-card::before {
  top: 0; bottom: 0; right: auto; width: 4px; height: auto;
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
}

/* Строка ID · округ под названием */
.device-card-id {
  font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); margin-top: 2px;
}
.device-card-name { font-family: var(--font-display); font-size: 17px; letter-spacing: .01em; }

/* Лампа-маяк — сигнатурный индикатор состояния балки */
.lamp {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--card-2); border: 1px solid var(--border);
}
.lamp i { width: 11px; height: 11px; border-radius: 50%; background: var(--gray); opacity: .45; transition: .2s; }
.device-card.s-on:not(.beacon-live) .lamp i {
  background: var(--success); opacity: 1;
  box-shadow: 0 0 8px 1px color-mix(in srgb, var(--success) 60%, transparent);
}
.device-card.beacon-live .lamp {
  border-color: color-mix(in srgb, var(--beacon) 55%, transparent);
  box-shadow: 0 0 0 3px var(--beacon-soft), 0 0 20px 3px var(--beacon-glow);
}
.device-card.beacon-live .lamp i {
  background: var(--beacon); opacity: 1;
  box-shadow: 0 0 10px 2px var(--beacon);
  animation: beacon-flash 1.6s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) { .device-card.beacon-live .lamp i { animation: none; } }

/* Метрики в строку (метка слева — значение справа) с пунктирным разделителем */
.device-card-metrics .metric {
  flex-direction: row; justify-content: space-between; align-items: baseline;
  gap: 10px; border-bottom: 1px dashed var(--border); padding-bottom: 5px;
}
.metric-value.warn { color: var(--beacon); }
.metric-value.crit { color: var(--danger); }

/* «Всего» — синий приборный акцент */
.kpi-card[data-kpi-filter="all"] { border-left-color: var(--info); }

/* Батарея — чуть толще и с воздухом сверху (как в шаблоне) */
.battery-bar { height: 6px; margin-top: 11px; }

/* Счётчик у заголовка секции */
.section-header .sect-count {
  font-family: var(--font-mono); font-size: 12px; color: var(--text-muted);
  font-weight: 400; margin-left: 10px;
}

/* Нативные контролы (селекты, скроллбары, дата-пикеры) — в тон теме */
:root { color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }

/* Leaflet: «хвостик» и кнопка закрытия попапа — под тёмную карточку */
.leaflet-popup-tip { background: var(--card); }
.leaflet-popup-close-button { color: var(--text-muted) !important; }
.gpu-manager-modal {
  width: min(1240px, calc(100vw - 32px));
  max-width: 1240px;
  max-height: calc(100vh - 32px);
  overflow: hidden;
}

.gpu-camera-form-modal {
  width: min(680px, calc(100vw - 32px));
  max-width: 680px;
}

.gpu-live-modal {
  width: min(1180px, calc(100vw - 32px));
  max-width: 1180px;
  max-height: calc(100vh - 32px);
  overflow: hidden;
}

.gpu-zones-modal {
  display: flex;
  flex-direction: column;
  width: calc(100vw - 20px);
  max-width: none;
  height: calc(100vh - 20px);
  max-height: none;
  overflow: hidden;
  border-radius: 8px;
}

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

.gpu-modal-header h3 {
  margin: 0;
  font-size: 17px;
  line-height: 1.3;
}

.gpu-header-actions,
.gpu-camera-actions,
.gpu-zone-tools,
.gpu-form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.gpu-muted {
  display: block;
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 12px;
}

.gpu-manager-body {
  max-height: calc(100vh - 112px);
  padding: 16px 18px 20px;
  overflow: auto;
}

.gpu-manager-toolbar {
  position: sticky;
  top: -16px;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
  padding: 10px 0 12px;
  background: var(--bg-card, var(--bg-secondary));
}

.gpu-manager-toolbar .input-field {
  flex: 1 1 145px;
  width: auto;
  min-width: 130px;
  height: 36px;
}

#gpu-filter-search {
  flex-basis: 230px;
}

#gpu-sort {
  flex-basis: 190px;
}

.gpu-filter-reset {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

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

.gpu-camera-item {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card, var(--bg-secondary));
}

.gpu-camera-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #111820;
}

.gpu-camera-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.gpu-camera-state {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 3px 7px;
  border-radius: 4px;
  color: #fff;
  background: rgba(24, 32, 40, .84);
  font-size: 11px;
  font-weight: 600;
}

.gpu-camera-state.is-online {
  background: rgba(13, 135, 80, .9);
}

.gpu-camera-state.is-offline {
  background: rgba(190, 48, 48, .92);
}

.gpu-camera-info {
  min-width: 0;
  padding: 12px 14px;
}

.gpu-camera-name-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.gpu-camera-name {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.35;
}

.gpu-camera-id {
  margin-top: 2px;
  overflow-wrap: anywhere;
  color: var(--text-muted);
  font-family: monospace;
  font-size: 11px;
}

.gpu-camera-district {
  margin-top: 4px;
  overflow-wrap: anywhere;
  color: var(--text-muted);
  font-size: 11px;
}

.gpu-camera-badges {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}

.gpu-roi-badge {
  color: #0d8750;
  border-color: rgba(13, 135, 80, .35);
  background: rgba(13, 135, 80, .1);
}

.gpu-speed-badge {
  color: #c83edc;
  border-color: rgba(200, 62, 220, .38);
  background: rgba(200, 62, 220, .1);
}

.gpu-camera-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.gpu-camera-metric {
  min-width: 0;
  padding: 7px 8px;
  border-left: 2px solid #3b82f6;
  background: var(--bg-secondary);
}

.gpu-camera-metric:nth-child(2) {
  border-color: #19a565;
}

.gpu-camera-metric:nth-child(3) {
  border-color: #e5a800;
}

.gpu-camera-metric:nth-child(4) {
  border-color: #a879ff;
}

.gpu-camera-metric:nth-child(5) {
  border-color: #ef5da8;
}

.gpu-camera-metric:nth-child(6) {
  border-color: #06a5bd;
}

.gpu-camera-metric span {
  display: block;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gpu-camera-metric strong {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gpu-camera-actions {
  flex-wrap: wrap;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border);
}

.gpu-camera-actions .btn {
  flex: 1 1 auto;
}

.gpu-camera-actions .gpu-delete-button {
  flex: 0 0 40px;
  width: 40px;
  padding: 0;
  justify-content: center;
}

.gpu-empty {
  grid-column: 1 / -1;
  padding: 42px 20px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  text-align: center;
}

.gpu-camera-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.gpu-camera-form .form-group {
  min-width: 0;
  margin: 0;
}

.gpu-form-wide {
  grid-column: 1 / -1;
}

.gpu-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.gpu-form-error {
  min-height: 18px;
  color: var(--danger, #c62828);
  font-size: 12px;
}

.gpu-form-actions {
  justify-content: flex-end;
}

.gpu-live-stage {
  display: grid;
  place-items: center;
  min-height: 320px;
  max-height: calc(100vh - 104px);
  overflow: auto;
  background: #111820;
}

.gpu-live-stage img {
  display: block;
  width: 100%;
  max-height: calc(100vh - 104px);
  object-fit: contain;
}

.gpu-live-header-actions,
.gpu-live-modes {
  display: flex;
  align-items: center;
  gap: 8px;
}

.gpu-live-modes {
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.gpu-live-modes button {
  min-height: 32px;
  padding: 5px 12px;
  border: 0;
  border-right: 1px solid var(--border);
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}

.gpu-live-modes button:last-child {
  border-right: 0;
}

.gpu-live-modes button.active {
  color: #fff;
  background: var(--primary);
}

.gpu-zones-layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 0;
  max-height: none;
}

.gpu-zone-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 14px;
  overflow: auto;
  border-right: 1px solid var(--border);
}

.gpu-editor-modes,
.gpu-speed-line-select {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.gpu-editor-modes button,
.gpu-speed-line-select button {
  min-height: 34px;
  padding: 6px 9px;
  border: 0;
  border-right: 1px solid var(--border);
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}

.gpu-editor-modes button:last-child,
.gpu-speed-line-select button:last-child {
  border-right: 0;
}

.gpu-editor-modes button.active {
  color: #fff;
  background: var(--primary);
}

#gpu-zone-controls,
.gpu-speed-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gpu-speed-controls[hidden] {
  display: none;
}

.gpu-speed-line-select button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.gpu-speed-line-select button.active {
  color: var(--text);
  background: var(--bg-secondary);
  box-shadow: inset 0 -2px var(--speed-color);
}

.gpu-speed-line-select button[data-gpu-speed-line="line_a"] {
  --speed-color: #28bde9;
}

.gpu-speed-line-select button[data-gpu-speed-line="line_b"] {
  --speed-color: #df56f4;
}

.gpu-speed-swatch {
  width: 12px;
  height: 3px;
  background: var(--speed-color);
}

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

.gpu-zone-list button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 34px;
  padding: 6px 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: var(--bg-secondary);
  cursor: pointer;
  text-align: left;
}

.gpu-zone-list button.active {
  border-color: #3b82f6;
  box-shadow: inset 3px 0 #3b82f6;
}

.gpu-zone-swatch {
  flex: 0 0 12px;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.gpu-zone-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gpu-zone-count {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 11px;
}

.gpu-danger-action {
  color: var(--danger, #c62828);
}

.gpu-zone-tools {
  flex-wrap: wrap;
}

.gpu-zone-tools .btn {
  min-height: 34px;
}

.gpu-zone-tools .btn:disabled,
.gpu-zone-sidebar > .btn:disabled {
  opacity: .42;
  cursor: not-allowed;
}

.gpu-zone-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background: #111820;
}

.gpu-zone-stage img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.gpu-zone-stage canvas {
  position: absolute;
  cursor: default;
  touch-action: none;
  outline: none;
}

.gpu-zone-stage canvas.is-drawing {
  cursor: crosshair;
}

.gpu-zone-stage canvas.is-speed {
  cursor: crosshair;
}

.gpu-zone-stage canvas.is-over-vertex {
  cursor: grab;
}

.gpu-zone-stage canvas.is-over-edge {
  cursor: copy;
}

.gpu-zone-stage canvas.is-dragging {
  cursor: grabbing;
}

.gpu-zone-stage canvas:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(53, 167, 255, .9);
}

.gpu-zone-loading {
  position: absolute;
  padding: 7px 10px;
  border-radius: 4px;
  color: #fff;
  background: rgba(17, 24, 32, .86);
  font-size: 12px;
}

@media (max-width: 760px) {
  #modal-gpu-zones {
    align-items: stretch;
    padding: 0;
  }

  .gpu-manager-modal,
  .gpu-camera-form-modal,
  .gpu-live-modal,
  .gpu-zones-modal {
    width: 100vw;
    max-width: none;
    max-height: 100vh;
    border-radius: 0;
  }

  .gpu-zones-modal {
    height: 100vh;
    max-height: none;
  }

  .gpu-camera-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .gpu-manager-toolbar {
    top: -16px;
  }

  .gpu-manager-toolbar .input-field,
  #gpu-filter-search,
  #gpu-sort {
    flex-basis: calc(50% - 4px);
    min-width: 0;
  }

  #gpu-filter-search {
    flex-basis: 100%;
  }

  .gpu-camera-form {
    grid-template-columns: minmax(0, 1fr);
  }

  .gpu-camera-form .form-group,
  .gpu-form-wide {
    grid-column: 1;
  }

  .gpu-zones-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(190px, auto) minmax(0, 1fr);
    min-height: 0;
    max-height: none;
  }

  .gpu-zone-sidebar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    max-height: 300px;
    padding: 10px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .gpu-zone-list,
  .gpu-editor-modes,
  #gpu-zone-controls,
  .gpu-speed-controls,
  .gpu-zone-sidebar .form-group,
  .gpu-zone-sidebar > .btn:last-child {
    grid-column: 1 / -1;
  }

  .gpu-zone-list {
    flex-direction: row;
    overflow-x: auto;
  }

  .gpu-zone-list button {
    flex: 0 0 150px;
  }

  .gpu-zone-stage {
    min-height: 0;
  }
}

/* Native Helpdesk */
.helpdesk-native-header {
  margin-bottom: 14px;
}

.helpdesk-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
}

.helpdesk-metric {
  display: flex;
  min-width: 0;
  min-height: 68px;
  padding: 12px 16px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  border: 0;
  border-right: 1px solid var(--border);
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
}

.helpdesk-metric:last-child { border-right: 0; }
.helpdesk-metric:hover { background: var(--bg-hover); }
.helpdesk-metric.active { box-shadow: inset 3px 0 0 var(--primary); background: var(--primary-light); }
.helpdesk-metric span { font-size: 11px; font-weight: 600; }
.helpdesk-metric strong { color: var(--text); font-size: 22px; line-height: 1.1; }
.helpdesk-metric[data-helpdesk-state="overdue"] strong { color: var(--warning); }
.helpdesk-metric[data-helpdesk-state="open"] strong { color: var(--info); }
.helpdesk-metric[data-helpdesk-state="closed"] strong { color: var(--success); }

.helpdesk-native-panel {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
}

.helpdesk-native-filters {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(190px, 1fr) minmax(140px, .7fr) minmax(160px, .75fr);
  gap: 8px;
  align-items: end;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.helpdesk-native-filters .input-sm,
.helpdesk-native-filters .select-sm {
  width: 100%;
  min-width: 0;
  height: 34px;
}

.helpdesk-date-field {
  display: grid;
  grid-template-columns: auto minmax(130px, 1fr);
  gap: 6px;
  align-items: center;
  color: var(--text-muted);
  font-size: 11px;
}

.helpdesk-period-filters {
  display: flex;
  grid-column: 1 / -1;
  align-items: end;
  justify-content: flex-end;
  gap: 8px;
}

.helpdesk-month-field { grid-template-columns: auto minmax(150px, 1fr); }
.helpdesk-period-filters .btn-icon { flex: 0 0 34px; height: 34px; }

.helpdesk-table-wrap { overflow-x: auto; }
.helpdesk-native-table { min-width: 980px; }
.helpdesk-native-table th { white-space: nowrap; }
.helpdesk-native-table td { vertical-align: middle; }
.helpdesk-native-table td:nth-child(2) { width: 32%; }
.helpdesk-native-table td:nth-child(3) { width: 24%; }
.helpdesk-native-table td span { display: block; color: var(--text-muted); font-size: 11px; }

.helpdesk-ticket-row { cursor: pointer; transition: background-color .15s ease; }
.helpdesk-ticket-row:hover,
.helpdesk-ticket-row:focus-visible { background: var(--bg-hover); outline: none; }
.helpdesk-ticket-row:focus-visible { box-shadow: inset 3px 0 0 var(--primary); }
.helpdesk-ticket-number { color: var(--text-muted); font-family: var(--font-mono); font-size: 12px; white-space: nowrap; }
.helpdesk-ticket-subject-native { display: block; color: var(--text); font-size: 13px; line-height: 1.3; }
.helpdesk-ticket-created { margin-top: 3px; }
.helpdesk-ticket-updated { color: var(--text-secondary); font-size: 12px; white-space: nowrap; }

.helpdesk-status-badge {
  display: inline-flex !important;
  width: fit-content;
  min-height: 24px;
  padding: 3px 8px;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-secondary) !important;
  background: var(--bg-secondary);
  font-size: 11px !important;
  font-weight: 600;
  white-space: nowrap;
}

.helpdesk-status-badge i {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.helpdesk-native-state {
  height: 120px;
  padding: 28px !important;
  color: var(--text-muted);
  text-align: center;
}

.helpdesk-native-error { color: var(--danger); }

.helpdesk-native-pagination {
  display: flex;
  min-height: 52px;
  padding: 9px 12px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
}

.helpdesk-native-pagination > div { display: flex; align-items: center; gap: 8px; }
.helpdesk-page-current { min-width: 72px; text-align: center; }

.helpdesk-ticket-modal-card {
  width: min(1080px, 100%);
  max-width: 1080px;
  max-height: 92vh;
  border-radius: 8px;
}

.helpdesk-ticket-modal-card .modal-header { align-items: flex-start; }
.helpdesk-ticket-modal-card .modal-header h3 { max-width: 760px; margin-top: 2px; font-size: 18px; line-height: 1.3; }
.helpdesk-ticket-modal-body { padding: 0; }
.helpdesk-detail-topline { display: flex; padding: 12px 18px; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--border); }
.helpdesk-detail-status,
.helpdesk-detail-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.helpdesk-detail-actions { justify-content: flex-end; }
.helpdesk-detail-actions .btn { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.helpdesk-detail-actions .ui-icon { width: 15px; height: 15px; }
.helpdesk-priority { color: var(--text-muted); font-size: 12px; }

.helpdesk-detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-bottom: 1px solid var(--border);
}

.helpdesk-detail-meta {
  min-width: 0;
  padding: 12px 18px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.helpdesk-detail-meta:nth-child(3n) { border-right: 0; }
.helpdesk-detail-meta:nth-last-child(-n+3) { border-bottom: 0; }
.helpdesk-detail-meta span { display: block; margin-bottom: 3px; color: var(--text-muted); font-size: 10px; text-transform: uppercase; }
.helpdesk-detail-meta strong { display: block; overflow: hidden; color: var(--text); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.helpdesk-detail-meta strong.text-danger { color: var(--danger); }

.helpdesk-detail-section { padding: 16px 18px; border-bottom: 1px solid var(--border); }
.helpdesk-detail-section:last-child { border-bottom: 0; }
.helpdesk-detail-section h4 { margin-bottom: 10px; color: var(--text); font-size: 13px; }
.helpdesk-detail-section h4 span { margin-left: 5px; color: var(--text-muted); font-weight: 500; }
.helpdesk-description { color: var(--text-secondary); font-size: 13px; line-height: 1.55; white-space: pre-wrap; }
.helpdesk-comments { display: grid; gap: 8px; }
.helpdesk-comment { padding: 10px 12px; border-left: 2px solid var(--border); background: var(--bg-secondary); }
.helpdesk-comment > div { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.helpdesk-comment strong { font-size: 12px; }
.helpdesk-comment span,
.helpdesk-comment em { color: var(--text-muted); font-size: 10px; font-style: normal; }
.helpdesk-comment em { color: var(--warning); }
.helpdesk-comment p { margin-top: 5px; color: var(--text-secondary); font-size: 12px; line-height: 1.45; white-space: pre-wrap; }
.helpdesk-detail-empty { padding: 10px 0; color: var(--text-muted); font-size: 12px; }

.helpdesk-attachments { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.helpdesk-attachment {
  display: flex;
  min-width: 0;
  min-height: 48px;
  padding: 8px 10px;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: var(--bg-secondary);
  text-align: left;
  cursor: pointer;
}
.helpdesk-attachment:hover { border-color: var(--primary); background: var(--bg-hover); }
.helpdesk-attachment:disabled { opacity: .55; cursor: wait; }
.helpdesk-attachment-icon { display: grid; flex: 0 0 28px; width: 28px; height: 28px; place-items: center; border-radius: 5px; color: var(--primary); background: var(--primary-light); font-weight: 700; }
.helpdesk-attachment-icon .ui-icon { width: 15px; height: 15px; }
.helpdesk-attachment > span:last-child { min-width: 0; }
.helpdesk-attachment strong { display: block; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.helpdesk-attachment small { display: block; margin-top: 2px; color: var(--text-muted); font-size: 10px; }

.helpdesk-media-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.helpdesk-media-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-secondary);
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}

.helpdesk-media-card.is-loading { display: grid; min-height: 210px; grid-template-rows: 1fr auto; }
.helpdesk-media-loading,
.helpdesk-media-error { display: grid; min-height: 170px; place-items: center; color: var(--text-muted); font-size: 12px; }
.helpdesk-media-card video { display: block; width: 100%; aspect-ratio: 16 / 10; max-height: 420px; background: var(--bg-secondary); object-fit: contain; }
.helpdesk-media-open { position: relative; display: block; width: 100%; padding: 0; overflow: hidden; border: 0; background: var(--bg-secondary); cursor: zoom-in; }
.helpdesk-media-open img { display: block; width: 100%; aspect-ratio: 16 / 10; max-height: 420px; object-fit: cover; transition: transform .2s ease; }
.helpdesk-media-open:hover img { transform: scale(1.015); }
.helpdesk-media-open > .ui-icon { position: absolute; right: 9px; bottom: 9px; width: 28px; height: 28px; padding: 6px; border-radius: 5px; color: #fff; background: rgba(0,0,0,.65); }
.helpdesk-media-caption { display: flex; min-width: 0; padding: 8px 10px; align-items: center; justify-content: space-between; gap: 10px; border-top: 1px solid var(--border); color: var(--text); background: var(--card); }
.helpdesk-media-caption strong { overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.helpdesk-media-caption span { flex: 0 0 auto; color: var(--text-muted); font-size: 10px; }

.helpdesk-media-viewer { z-index: 1150; padding: 24px; background: rgba(15,23,42,.42); backdrop-filter: blur(5px); }
.helpdesk-media-viewer-frame {
  display: grid;
  width: min(980px, 100%);
  max-height: 88vh;
  overflow: hidden;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 24px 80px rgba(0,0,0,.4);
}
.helpdesk-media-viewer-head { display: flex; min-height: 52px; padding: 8px 14px; align-items: center; justify-content: space-between; gap: 12px; color: var(--text); border-bottom: 1px solid var(--border); }
.helpdesk-media-viewer-head > div { display: flex; min-width: 0; align-items: baseline; gap: 10px; }
.helpdesk-media-viewer-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.helpdesk-media-viewer-head span { flex: 0 0 auto; color: var(--text-muted); font-size: 12px; }
.helpdesk-media-viewer-head .modal-close { color: var(--text); }
.helpdesk-media-viewer-body { position: relative; display: grid; min-height: 240px; max-height: calc(88vh - 53px); padding: 12px; place-items: center; background: var(--bg-secondary); }
.helpdesk-media-viewer-stage { display: grid; width: 100%; min-height: 240px; place-items: center; }
.helpdesk-media-viewer-loading { color: var(--text-muted); font-size: 13px; }
.helpdesk-media-viewer-stage img { display: block; max-width: 100%; max-height: calc(88vh - 77px); object-fit: contain; }
.helpdesk-media-nav {
  position: absolute;
  top: 50%;
  z-index: 2;
  display: grid;
  width: 42px;
  height: 42px;
  padding: 0;
  place-items: center;
  transform: translateY(-50%);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  background: var(--card);
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
  cursor: pointer;
}
.helpdesk-media-nav:hover { color: var(--primary); border-color: var(--primary); }
.helpdesk-media-nav .ui-icon { width: 24px; height: 24px; }
.helpdesk-media-nav-prev { left: 24px; }
.helpdesk-media-nav-next { right: 24px; }

@media (max-width: 1180px) {
  .helpdesk-native-filters { grid-template-columns: 1fr 1fr; }
  .helpdesk-date-field { grid-template-columns: auto 1fr; }
}

@media (max-width: 700px) {
  .helpdesk-metrics { grid-template-columns: repeat(2, 1fr); }
  .helpdesk-metric:nth-child(2) { border-right: 0; }
  .helpdesk-metric:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
  .helpdesk-native-filters { grid-template-columns: 1fr 1fr; }
  #helpdesk-filter-search,
  #helpdesk-filter-device { grid-column: 1 / -1; }
  .helpdesk-period-filters { display: grid; grid-template-columns: 1fr 1fr; }
  .helpdesk-month-field { grid-column: 1 / -1; }
  .helpdesk-period-filters .btn-icon { justify-self: end; }
  .helpdesk-native-pagination { align-items: flex-start; flex-direction: column; }
  .helpdesk-detail-grid { grid-template-columns: 1fr; }
  .helpdesk-detail-meta,
  .helpdesk-detail-meta:nth-child(3n),
  .helpdesk-detail-meta:nth-last-child(-n+3) { border-right: 0; border-bottom: 1px solid var(--border); }
  .helpdesk-detail-meta:last-child { border-bottom: 0; }
  .helpdesk-detail-topline { align-items: stretch; flex-direction: column; }
  .helpdesk-detail-actions { justify-content: flex-start; }
  .helpdesk-media-grid { grid-template-columns: 1fr; }
  .helpdesk-attachments { grid-template-columns: 1fr; }
  .helpdesk-media-viewer { padding: 8px; }
  .helpdesk-media-viewer-frame { max-height: 94vh; }
  .helpdesk-media-viewer-body { max-height: calc(94vh - 53px); }
  .helpdesk-media-viewer-stage img { max-height: calc(94vh - 77px); }
  .helpdesk-media-nav { width: 38px; height: 38px; }
  .helpdesk-media-nav-prev { left: 8px; }
  .helpdesk-media-nav-next { right: 8px; }
}

/* Mobile usability pass */
@media (max-width: 760px) {
  html { overflow: hidden; }
  body.mobile-menu-open .main-content { overflow: hidden; }

  .hamburger {
    top: max(10px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    width: 42px;
    height: 42px;
  }

  .sidebar {
    width: min(280px, calc(100vw - 48px));
    min-width: 0;
    max-width: calc(100vw - 48px);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    overflow-y: auto;
    transition: none;
  }
  .sidebar.open { transform: translateX(0) !important; }
  .sidebar:not(.open) { transform: translateX(-100%) !important; }
  .nav-item { min-height: 44px; }

  .sidebar-overlay { backdrop-filter: blur(2px); }
  .main-content {
    overflow-x: hidden;
    padding-top: calc(62px + env(safe-area-inset-top));
    padding-right: max(10px, env(safe-area-inset-right));
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    padding-left: max(10px, env(safe-area-inset-left));
  }

  .btn,
  .input-sm,
  .select-sm,
  .input-field,
  select {
    min-height: 40px;
  }

  .btn-icon,
  .modal-close { min-width: 40px; width: 40px; height: 40px; }

  .page-header { margin-bottom: 14px; }
  .page-subtitle { line-height: 1.35; }
  .page-actions { gap: 8px; }
  #view-map .map-layer-toggle {
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  #view-map .map-layer-toggle::-webkit-scrollbar { display: none; }

  .modal-overlay {
    align-items: flex-end;
    padding: max(4px, env(safe-area-inset-top)) 4px 0;
  }
  .modal-card {
    width: 100%;
    min-width: 0 !important;
    max-height: calc(100dvh - max(4px, env(safe-area-inset-top)));
    border-radius: 10px 10px 0 0;
    resize: none !important;
  }
  .modal-header {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 12px 14px;
    background: var(--card);
  }
  .modal-header h3 { line-height: 1.25; }
  .modal-body { padding: 14px; }
  .modal-footer {
    position: sticky;
    bottom: 0;
    z-index: 5;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    flex-wrap: wrap;
    background: var(--card);
  }
  .modal-footer .btn { flex: 1 1 120px; }

  /* Operational lists become scan-friendly cards instead of clipped rows. */
  .mobile-card-table,
  .mobile-card-table tbody,
  .mobile-card-table tr,
  .mobile-card-table td { display: block; width: 100%; }
  .mobile-card-table { min-width: 0 !important; background: transparent; }
  .mobile-card-table thead { display: none; }
  .mobile-card-table tbody { display: grid; gap: 9px; }
  .mobile-card-table tbody tr {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--card);
    box-shadow: var(--shadow-card);
  }
  .mobile-card-table tbody tr:hover { background: var(--card); }
  .mobile-card-table tbody td {
    display: grid;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    min-height: 38px;
    padding: 8px 10px !important;
    grid-template-columns: minmax(88px, .75fr) minmax(0, 1.25fr);
    gap: 10px;
    align-items: center;
    border: 0;
    border-bottom: 1px solid var(--border-light);
    text-align: right;
    overflow-wrap: anywhere;
  }
  .mobile-card-table tbody td:last-child { border-bottom: 0; }
  .mobile-card-table tbody td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    line-height: 1.2;
    text-align: left;
    text-transform: uppercase;
  }
  .mobile-card-table tbody td > * { min-width: 0; }
  .mobile-card-table tbody td strong,
  .mobile-card-table tbody td span { overflow-wrap: anywhere; }
  .mobile-card-table tbody td[colspan] {
    display: block;
    padding: 24px 12px !important;
    text-align: center;
  }
  .mobile-card-table tbody td[colspan]::before { display: none; }
  .mobile-card-table .card-actions { justify-content: flex-end; }
  .mobile-card-table .tbl-device-name {
    display: inline-block;
    padding: 3px 0;
    font-weight: 700;
  }
  #devices-table tbody tr,
  .helpdesk-native-table tbody tr { cursor: pointer; }
  #devices-table + *,
  .helpdesk-table-wrap { overflow: visible; }

  /* Device detail */
  .view-dd { margin: 0 -10px; }
  .dd-layout { width: 100%; overflow: hidden; }
  .dd-sidebar {
    width: 100%;
    max-height: min(56vh, 360px);
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .dd-layout.dd-sidebar-collapsed .dd-sidebar { max-height: 45px; }
  .dd-main { width: 100%; padding: 10px; gap: 10px; }
  .dd-titlebar { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; padding: 4px 0; }
  .dd-titlebar-actions { gap: 4px; }
  .dd-titlebar-actions .btn { min-height: 38px; padding: 6px 9px; }
  .dd-toolbar { width: 100%; padding: 10px; align-items: stretch; }
  .dd-toolbar-controls { width: 100%; flex-wrap: wrap; flex-shrink: 1; }
  .dd-toolbar-controls .btn { flex: 1 1 54px; }
  .dd-toolbar-controls .input-sm { min-height: 40px; }
  .dd-toolbar-period { width: 100%; margin-left: 0; align-items: stretch; }
  .dd-toolbar-period > .dd-toolbar-label { width: 100%; }
  .dd-period-btns { display: grid; width: 100%; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .dd-period-btns .btn { min-width: 0; padding-right: 5px; padding-left: 5px; }
  .dd-period-custom { display: grid; width: 100%; margin-left: 0; grid-template-columns: minmax(0, 1fr) 12px minmax(0, 1fr); }
  .dd-period-custom input { width: 100%; min-width: 0; }
  .dd-period-custom .btn { grid-column: 1 / -1; width: 100%; }
  .dd-card-chart .dd-chart-wrap { height: 260px; padding-right: 6px; padding-left: 6px; }

  /* Cameras */
  #view-cameras .page-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  #camera-district-filter { width: 100%; }
  #view-cameras [data-cam-view] { min-height: 40px; }
  #view-cameras [data-cam-view="grid4"] { font-size: 0; }
  #view-cameras [data-cam-view="grid4"]::after { content: 'Карточки'; font-size: 12px; }
  .cam-object-footer { align-items: flex-start; }
  .cam-object-name {
    display: -webkit-box;
    min-height: 34px;
    line-height: 1.35;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
  .cam-object-footer .btn,
  .cam-object-footer .cam-refresh-btn { min-width: 38px; min-height: 38px; padding: 4px; }

  /* Reports and device analytics */
  .report-filters { padding: 12px !important; overflow: hidden; }
  .report-filters .filter-row { display: grid !important; width: 100%; grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .report-period-presets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .report-period-presets .report-preset { width: 100%; }
  .report-period-presets .report-preset:last-child { grid-column: 1 / -1; }
  .report-date-range { display: grid !important; width: 100%; grid-template-columns: 24px minmax(0, 1fr); gap: 6px 8px !important; }
  .report-date-range input { width: 100%; min-width: 0; }
  #btn-report-generate { width: 100%; }
  #view-analytics .analytics-actions { display: grid !important; width: 100%; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  #view-analytics .analytics-actions #analytics-date { grid-column: 1 / -1; width: 100% !important; }
  #view-analytics .analytics-actions .btn { min-width: 0; padding-right: 8px; padding-left: 8px; white-space: normal; }
  #analytics-search { width: 100% !important; margin-left: 0 !important; }

  /* Local weather station */
  #weather-charts { grid-template-columns: minmax(0, 1fr) !important; }
  #weather-charts > div { width: 100%; min-width: 0; }
  #weather-charts canvas { width: 100% !important; max-width: 100% !important; }

  /* Helpdesk */
  .helpdesk-native-panel { overflow: visible; background: transparent; border: 0; }
  .helpdesk-native-filters { border: 1px solid var(--border); border-radius: 7px; background: var(--card); }
  .helpdesk-table-wrap { margin-top: 10px; }
  .helpdesk-ticket-modal-card { max-height: calc(100dvh - 4px); }
  .helpdesk-detail-actions .btn { flex: 1 1 145px; justify-content: center; }

  /* AI keeps comparison matrices scrollable, but makes touch targets clear. */
  .ai-tabs,
  .ai-period-toggle { scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .ai-tabs::-webkit-scrollbar,
  .ai-period-toggle::-webkit-scrollbar { display: none; }
  .ai-tab,
  .map-toggle-btn { min-height: 40px; }
  .ai-lane-table-wrap,
  .ai-compact-table-wrap { -webkit-overflow-scrolling: touch; }
  .ai-speed-pagination { flex-wrap: wrap; }
  #modal-ai-event button { min-height: 40px; }
  #ai-snapshots .ai-event-card {
    width: calc(50% - 4px) !important;
    margin: 2px !important;
  }
  #ai-snapshots .ai-event-thumb {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 16 / 10;
  }

  /* Settings */
  .settings-tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .settings-tab { flex: 0 0 auto; min-height: 42px; }
  .section-header .btn { width: 100%; }
}

@media (max-width: 480px) {
  .main-content { padding-right: 8px; padding-left: 8px; }
  .view-dd { margin-right: -8px; margin-left: -8px; }
  .kpi-card { min-width: 0; }
  .kpi-value { overflow-wrap: anywhere; }
  .ai-speed-events { grid-template-columns: minmax(0, 1fr); }
  .helpdesk-native-table td:nth-child(5),
  .helpdesk-native-table td:nth-child(6) { display: none; }
  #devices-table td:nth-child(3),
  #devices-table td:nth-child(4),
  #devices-table td:nth-child(8),
  #users-tbody td:first-child { display: none; }
  .mobile-card-table tbody td { grid-template-columns: minmax(78px, .7fr) minmax(0, 1.3fr); }
  .camera-player-header { grid-template-columns: minmax(0, 1fr) 124px 40px; gap: 4px; }
  .camera-player-mode { min-width: 62px; padding: 0 5px; }
  .camera-player { grid-template-rows: auto minmax(0, 1fr) auto; }
}
