:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-raised: #f8f9fb;
  --border: #e2e5ea;
  --border-accent: #d0d4db;
  --text: #1e2330;
  --text-dim: #6b7280;
  --text-bright: #0f1119;
  --amber: #D4922A;
  --amber-dim: rgba(212,146,42,0.12);
  --amber-glow: rgba(212,146,42,0.08);
  --green: #16a34a;
  --green-dim: rgba(22,163,74,0.1);
  --green-bright: #15803d;
  --red: #dc2626;
  --red-dim: rgba(220,38,38,0.08);
  --red-bright: #b91c1c;
  --blue: #2563eb;
  --blue-bright: #4a90d9;
  --font-display: 'IBM Plex Sans', sans-serif;
  --font-sans: 'IBM Plex Sans', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
  --radius: 10px;
}

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

body {
  font-family: var(--font-display);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ---- HEADER ---- */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  height: 64px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--amber), #b87a1e);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  color: #fff;
  letter-spacing: -0.5px;
}
.logo h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-bright);
  letter-spacing: 0.3px;
}
.logo h1 span { color: var(--text-dim); font-weight: 400; }
.status-bar {
  display: flex;
  gap: 20px;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 16px;
  color: var(--text-dim);
}
.status-indicator {
  display: flex;
  align-items: center;
  gap: 7px;
}
.pulse {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  position: relative;
}
.pulse.ok { background: var(--green); box-shadow: 0 0 6px rgba(22,163,74,0.4); }
.pulse.err { background: var(--red); box-shadow: 0 0 6px rgba(220,38,38,0.4); }
.pulse.ok::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1px solid var(--green);
  opacity: 0;
  animation: ping 2s cubic-bezier(0,0,0.2,1) infinite;
}
@keyframes ping {
  0% { transform: scale(1); opacity: 0.5; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* ---- GRID ---- */
.grid {
  display: grid;
  gap: 20px;
  padding: 24px 32px;
}
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-5 { grid-template-columns: repeat(5, 1fr); }

/* ---- CARD ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  opacity: 0;
  transform: translateY(12px);
  animation: cardIn 0.4s ease forwards;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
}
.card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  height: 4px;
  background: var(--green);
  transition: background 0.3s;
}
.card.offline { opacity: 1; }
.card.offline::before { background: var(--red); }
.card.offline .card-body { opacity: 0.4; pointer-events: none; }

@keyframes cardIn {
  to { opacity: 1; transform: translateY(0); }
}
.no-anim .card {
  animation: none;
  opacity: 1;
  transform: none;
}

.card-top {
  padding: 14px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--surface-raised);
}
.card-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.card-links-row {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
}
.card-links-row .habpanel-link {
  flex: 1;
  width: auto;
  height: 30px;
  border-radius: 6px;
}
.card-links-row .habpanel-link svg {
  width: 16px;
  height: 16px;
}
.card-name-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  justify-content: flex-end;
}
.card-name {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-bright);
  letter-spacing: 0.2px;
  margin-right: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.habpanel-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.15s;
  flex-shrink: 0;
  cursor: pointer;
}
.habpanel-link:hover {
  background: var(--border);
  color: var(--text-bright);
}
.card-badge {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 5px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-weight: 600;
}
.card-badge.online { background: var(--green-dim); color: var(--green-bright); }
.card-badge.offline { background: var(--red-dim); color: var(--red-bright); }

.status-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex-shrink: 0; margin-left: 8px; }
.status-dot.online { background: var(--green-bright); box-shadow: 0 0 6px var(--green-bright); }
.status-dot.offline { background: var(--red-bright); box-shadow: 0 0 6px var(--red-bright); }

/* NVR-health badges (Fix 3 + Fix 4) — small pill next to location name. */
.nvr-health-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  border-radius: 4px;
  vertical-align: middle;
  cursor: help;
}
.nvr-health-badge.offline { background: var(--red-bright); color: white; }
.nvr-health-badge.warn { background: #d97706; color: white; }

/* Intercom offline (Fix 7) — dim button + red tint to make it visible the
   intercom isn't reachable, but keep it clickable (user might still want
   to open the panel to confirm or read the last status). */
.intercom-offline { opacity: 0.45; color: var(--red-bright) !important; cursor: help; }
.intercom-offline:hover { opacity: 0.65; }

.card-body { padding: 20px; flex: 1; display: flex; flex-direction: column; }
.card-body .controls { flex: 1; }
.card-body .actions { margin-top: auto; }

/* ---- GAUGE ---- */
.gauge {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.gauge-ring {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 3px solid var(--border-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
}
.gauge-ring.active { border-color: var(--amber); box-shadow: 0 0 16px var(--amber-glow), inset 0 0 12px var(--amber-glow); }
.gauge-value {
  font-family: var(--font-mono);
  font-size: 42px;
  font-weight: 600;
  color: var(--text-bright);
  line-height: 1;
}
.gauge-meta { display: flex; flex-direction: column; gap: 3px; }
.gauge-label {
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-family: var(--font-mono);
}
.gauge-sub {
  font-size: 15px;
  color: var(--text);
  font-weight: 500;
}
.gauge-time {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-dim);
}
.card-note {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
  padding: 4px 0 2px;
  line-height: 1.3;
}

/* ---- CONTROLS ---- */
.controls { display: flex; flex-direction: column; gap: 4px; }
.ctrl-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--surface-raised);
  transition: background 0.15s;
}
.ctrl-row:hover { background: #eef0f4; }
.ctrl-label {
  font-size: 17px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ctrl-icon {
  width: 20px;
  height: 20px;
  opacity: 0.5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

/* Toggle switch — standard size (cards, forms) */
.sw-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border-accent);
  background: var(--surface-raised);
  color: var(--green);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.sw-btn svg { fill: var(--red); stroke: none; }
.sw-btn:hover { border-color: var(--green); background: var(--green); }
.sw-btn:hover svg { fill: #fff; }
.sw-btn:disabled { opacity: 0.3; cursor: default; }
.sw {
  width: 48px;
  height: 26px;
  border-radius: 13px;
  background: #e5e7eb;
  cursor: pointer;
  position: relative;
  border: 2px solid transparent;
  outline: none;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}
.sw::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--red);
  top: 1px;
  left: 1px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.sw.on {
  background: var(--green-dim);
  border-color: var(--green);
}
.sw.on::after {
  transform: translateX(22px);
  background: var(--green);
  box-shadow: 0 1px 4px rgba(22,163,74,0.3);
}
/* Toggle switch — compact size (tables, config) */
.sw-sm { width: 40px; height: 22px; border-radius: 11px; }
.sw-sm::after { width: 16px; height: 16px; }
.sw-sm.on::after { transform: translateX(18px); }
}
.sw:disabled { opacity: 0.3; cursor: not-allowed; }
.sw:not(:disabled):hover { border-color: var(--border-accent); }

/* ---- ACTIONS ---- */
.actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.act-btn {
  flex: 1;
  padding: 9px 0;
  border-radius: 8px;
  border: 1px solid var(--border-accent);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.act-btn:hover { background: var(--surface-raised); border-color: #b0b6c0; }
.act-btn:active { transform: scale(0.97); }
.act-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.act-btn.danger { border-color: rgba(220,38,38,0.25); color: var(--red); }
.act-btn.danger:hover { background: var(--red-dim); border-color: rgba(220,38,38,0.4); }
.act-btn.intercom-action { border-color: rgba(22,163,74,0.3); color: var(--green); }
.act-btn.intercom-action:hover { background: rgba(22,163,74,0.1); border-color: rgba(22,163,74,0.5); }

/* ---- TEST SIMULATION ---- */
.test-toggle {
  padding: 8px 0 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
.test-toggle::before {
  content: '\25B8';
  font-size: 10px;
  color: var(--text-dim);
  transition: transform 0.2s;
}
.test-toggle.open::before {
  transform: rotate(90deg);
}
.test-toggle-label {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}
.test-panel {
  overflow: hidden;
  transition: max-height 0.2s ease, opacity 0.2s ease;
  max-height: 500px;
  opacity: 1;
}
.test-panel.hidden {
  max-height: 0;
  opacity: 0;
}
.test-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 6px 0;
}
.test-btn {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px dashed var(--border-accent);
  background: var(--surface-raised);
  color: var(--text-dim);
  cursor: not-allowed;
  font-family: var(--font-mono);
  font-size: 11px;
  text-align: center;
  transition: all 0.15s;
  white-space: nowrap;
}
.test-btn:not(:disabled) {
  cursor: pointer;
  border-style: solid;
  color: var(--text);
}
.test-btn.in:not(:disabled):hover { background: var(--amber-dim); border-color: var(--amber); }
.test-btn.out:not(:disabled):hover { background: var(--green-dim); border-color: var(--green); }

/* Camera channel rows with trigger icons */
.cam-rows { display: flex; flex-direction: column; gap: 4px; padding: 6px 0; }
.cam-row { display: flex; align-items: center; gap: 6px; }
.cam-row .test-btn { flex: 1; text-align: left; }
.cam-triggers { display: flex; gap: 3px; flex-shrink: 0; }
.cam-trig {
  width: 22px; height: 22px; border-radius: 4px; border: 1px solid var(--border);
  background: var(--surface-raised); color: var(--text-dim); cursor: pointer;
  font-family: var(--font-mono); font-size: 10px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s; padding: 0; line-height: 1;
}
.cam-trig:hover { border-color: var(--border-accent); }
.cam-trig.on { background: var(--green-dim); color: var(--green); border-color: var(--green); }

/* ---- SCAN / STATUS SECTION ---- */
.scan-section {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.scan-header {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.scan-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.scan-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.scan-dot.green { background: var(--green); }
.scan-dot.red { background: var(--red); }
.scan-dot.amber { background: var(--amber); }
.scan-dot.gray { background: var(--border-accent); }
.scan-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  min-width: 80px;
}
.scan-time {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}

/* Scan badge — colored icon + type + time */
.scan-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.scan-badge.green {
  background: var(--green-dim);
  color: var(--green-bright);
}
.scan-badge.red {
  background: var(--red-dim);
  color: var(--red-bright);
}
.scan-badge-icon {
  font-size: 14px;
  line-height: 1;
}
.scan-badge-type {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.scan-badge-time {
  font-weight: 400;
  opacity: 0.8;
}

/* ---- HEADER RIGHT ---- */
.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}
#header-slot, #header-extra {
  display: contents;
}
.header-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border-accent);
  background: var(--surface);
  text-decoration: none;
  font-size: 16px;
  transition: all 0.15s;
}
.header-link:hover { background: var(--surface-raised); border-color: #b0b6c0; }
.col-select {
  padding: 4px 6px;
  border: 1px solid var(--border-accent);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  cursor: pointer;
  height: 36px;
}
.col-select:hover { background: var(--surface-raised); border-color: #b0b6c0; }
.device-search {
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border-accent);
  background: var(--surface);
  color: var(--text-bright);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  width: 140px;
  transition: all 0.15s;
}
.device-search:focus { border-color: var(--green); width: 180px; }
.device-search::placeholder { color: var(--text-dim); }
@media (max-width: 768px) {
  .device-search { display: none; }
}
.view-toggle {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border-accent);
  background: var(--surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.view-toggle:hover { background: var(--surface-raised); border-color: #b0b6c0; }
.view-icon { font-size: 18px; line-height: 1; }

/* ---- TABLE VIEW ---- */
.table-wrap {
  padding: 24px 32px;
  overflow-x: auto;
}
.dev-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  overflow: hidden;
}
.dev-table th {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  background: var(--surface-raised);
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.dev-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.dev-table.rows-small th { padding: 6px 16px; }
.dev-table.rows-small td { padding: 4px 16px; }
.dev-table.rows-big th { padding: 18px 16px; }
.dev-table.rows-big td { padding: 20px 16px; }
.dev-table tbody tr:last-child td { border-bottom: none; }
.dev-table tbody tr:nth-child(even) { background: var(--surface-raised); }
.dev-table tbody tr:hover { background: var(--surface-raised); }
.td-people.has-people { background: var(--amber-glow); }
.row-offline td { opacity: 0.4; }
.row-offline .td-name,
.row-offline td:nth-child(2) { opacity: 1; }

.td-name {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-bright);
  white-space: nowrap;
}
.td-name .habpanel-link { margin-left: 4px; }
.td-people {
  text-align: center;
}
.people-num {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--text-dim);
}
.people-num.active {
  color: var(--amber);
}
.td-toggle {
  text-align: center;
}
.td-na {
  text-align: center;
  color: var(--border-accent);
  font-size: 16px;
}
.td-scan {
  white-space: nowrap;
}
.td-scan .scan-dot {
  display: inline-block;
  vertical-align: middle;
  margin-right: 5px;
}
.td-scan .scan-time {
  vertical-align: middle;
}
.td-actions {
  white-space: nowrap;
  display: flex;
  gap: 6px;
}
.tbl-btn {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-accent);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}
.tbl-btn:hover { background: var(--surface-raised); border-color: #b0b6c0; }
.tbl-btn:active { transform: scale(0.97); }
.tbl-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.tbl-btn.danger { border-color: rgba(220,38,38,0.25); color: var(--red); }
.tbl-btn.danger:hover { background: var(--red-dim); }
.btn-icon { display: none; }
body.sidebar-open .btn-label { display: none; }
body.sidebar-open .btn-icon { display: inline; }

/* ---- NOTIFICATION SIDEBAR ---- */
.main-layout {
  display: flex;
  min-height: calc(100vh - 64px);
}
.main-layout #app {
  flex: 1;
  min-width: 0;
  transition: none;
}
.notif-panel {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  position: relative;
  border-left: 1px solid var(--border);
  transition: width 0.3s ease, opacity 0.3s ease;
  overflow: hidden;
}
.notif-panel.collapsed {
  width: 0;
  opacity: 0;
}
#app {
  transition: none;
}
body.sidebar-open #app {
  margin-right: 0;
}
body.carousel-open {
  padding-bottom: 280px;
}
body.sidebar-open .table-wrap {
  overflow-x: auto;
}
.notif-tab {
  position: absolute;
  left: -40px;
  top: 24px;
  width: 40px;
  height: 48px;
  border: 1px solid var(--border-accent);
  border-right: none;
  border-radius: 8px 0 0 8px;
  background: var(--surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: -2px 1px 6px rgba(0,0,0,0.08);
  transition: background 0.15s;
}
.notif-tab:hover { background: var(--surface-raised); }
.notif-tab-icon { font-size: 18px; line-height: 1; }
.notif-count {
  position: absolute;
  top: -5px;
  left: -5px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}
.notif-inner {
  flex: 1;
  min-width: 320px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.notif-title {
  padding: 16px 18px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-bright);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: var(--font-mono);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.notif-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.notif-chip {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border-accent);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.notif-chip.active {
  background: var(--text-bright);
  color: #fff;
  border-color: var(--text-bright);
}
.notif-chip:hover { border-color: var(--text); }
.notif-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.notif-empty {
  padding: 24px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
}
.notif-item {
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--surface-raised);
  border-left: 4px solid transparent;
  transition: all 0.2s ease;
  animation: notifIn 0.3s ease;
  overflow: hidden;
  min-width: 0;
  flex-shrink: 0;
}
.notif-item.in { border-left-color: var(--amber); background: var(--amber-glow); }
.notif-item.out { border-left-color: var(--green); background: var(--green-dim); }
.notif-item.reset { border-left-color: var(--red); background: var(--red-dim); }
.notif-item.reset .notif-arrow { color: var(--red); }
@keyframes notifIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
.notif-header {
  display: flex;
  align-items: center;
  gap: 6px;
}
.notif-arrow { display: inline-flex; align-items: center; }
.notif-item.in .notif-arrow { color: var(--amber); }
.notif-item.out .notif-arrow { color: var(--green); }
.notif-device {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-bright);
  flex: 1;
}
.notif-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}
.notif-change {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-top: 2px;
  word-break: break-all;
}
.notif-media {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.notif-thumb {
  display: block;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.notif-snap {
  display: block;
  width: 80px;
  height: auto;
  border-radius: 3px;
}
.notif-clip-link {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--green-bright);
  text-decoration: none;
  padding: 3px 8px;
  border: 1px solid var(--green-dim);
  border-radius: 4px;
  transition: all 0.15s;
}
.notif-clip-link:hover {
  background: var(--green-dim);
}
.notif-footer {
  flex-shrink: 0;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.notif-setting {
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  gap: 4px;
}
.notif-limit-select {
  padding: 3px 6px;
  border: 1px solid var(--border-accent);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.notif-clear-btn {
  padding: 4px 10px;
  border: 1px solid var(--border-accent);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}
.notif-clear-btn:hover { background: var(--red-dim); color: var(--red); border-color: rgba(220,38,38,0.25); }

/* ---- LOADING ---- */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60vh;
  font-family: var(--font-mono);
  font-size: 16px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

/* ---- TOAST NOTIFICATIONS ---- */
#toast-container {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border-accent);
  border-radius: 10px;
  padding: 12px 20px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 500;
  color: var(--text-bright);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 0.3s ease-out, toastOut 0.3s ease-in 4.7s forwards;
  pointer-events: auto;
}
.toast.in { border-left: 4px solid #D4922A; }
.toast.out { border-left: 4px solid var(--green-bright); }
.toast-icon { font-size: 18px; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ---- CONFIRM DIALOG ---- */
.confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0, 0, 0, 0.4);
  align-items: center;
  justify-content: center;
}
.confirm-overlay.active { display: flex; }
.confirm-box {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px 28px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  min-width: 280px;
  text-align: center;
}
.confirm-msg {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-bright);
  margin-bottom: 20px;
}
.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.confirm-btn {
  padding: 8px 24px;
  border-radius: 8px;
  border: 1px solid var(--border-accent);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.confirm-btn.cancel {
  background: var(--surface);
  color: var(--text);
}
.confirm-btn.cancel:hover { background: var(--surface-raised); }
.confirm-btn.ok {
  background: var(--green-bright);
  color: #fff;
  border-color: var(--green-bright);
}
.confirm-btn.ok:hover { opacity: 0.9; }

/* ---- MEDIA MODAL ---- */
.media-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.75);
  align-items: center;
  justify-content: center;
}
.media-modal.active {
  display: flex;
}
.media-modal-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  background: var(--surface);
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
.media-modal-close {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}
.media-modal-close:hover {
  background: var(--border-accent);
}
.media-modal-img {
  display: block;
  max-width: 85vw;
  max-height: 85vh;
  border-radius: 4px;
}
.media-modal-video {
  display: block;
  max-width: 85vw;
  max-height: 85vh;
  border-radius: 4px;
}

/* ---- RESPONSIVE ---- */
/* Mute button */
.mute-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  padding: 4px 6px;
  border-radius: 6px;
  opacity: 0.85;
  transition: opacity 0.15s;
}
.mute-btn:hover { opacity: 1; }
.mute-btn.muted { opacity: 0.45; }

/* ---- Camera carousel ---- */
.camera-carousel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 900;
  background: rgba(20, 20, 20, 0.92);
  border-top: 2px solid var(--green);
  padding: 8px 12px;
  backdrop-filter: blur(8px);
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.carousel-close-all {
  flex-shrink: 0;
  background: none;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  color: #fff;
  font-size: 20px;
  width: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
  transition: opacity 0.15s, background 0.15s;
}
.carousel-close-all:hover {
  opacity: 1;
  background: rgba(220,38,38,0.3);
}
.carousel-track {
  flex: 1;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.carousel-track::-webkit-scrollbar { height: 4px; }
.carousel-track::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.3); border-radius: 2px; }

.carousel-tile {
  flex: 0 0 280px;
  height: 20vh;
  border-radius: 8px;
  overflow: hidden;
  background: #111;
  border: 2px solid transparent;
  transition: border-color 0.3s;
  display: flex;
  flex-direction: column;
  position: relative;
}
.carousel-tile.motion-active { border-color: var(--green); }
.carousel-tile.pinned { border-color: #f0c040; }

.carousel-tile-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3px;
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 2;
}
.carousel-tile-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.carousel-tile-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ff4444;
  animation: live-blink 1s infinite;
  flex-shrink: 0;
}
@keyframes live-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.carousel-tile-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px 4px;
  background: rgba(0,0,0,0.7);
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 2;
}
.carousel-tile-toolbar button {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 6px 6px;
  line-height: 1;
  opacity: 0.6;
  flex-shrink: 0;
  min-width: 28px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.15s;
}
.carousel-tile-toolbar button:hover { opacity: 1; background: rgba(255,255,255,0.1); }
.carousel-tile-toolbar button:active { background: rgba(255,255,255,0.2); }
.carousel-tile-audio.muted { opacity: 0.3; }
.carousel-tile-audio.muted:hover { opacity: 0.7; }
.carousel-tile-audio.muted .audio-waves { display: none; }
.carousel-tile-audio:not(.muted) { opacity: 1; color: #4a9eff; }
.carousel-tile-audio:not(.muted):hover { opacity: 1; color: #6cb5ff; }
.carousel-tile-trigger { margin-left: auto; font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; line-height: 1.4; display: none; }
.carousel-tile-trigger[data-trigger="M"] { display: inline; background: var(--green); color: #000; }
.carousel-tile-trigger[data-trigger="P"] { display: inline; background: #4a9eff; color: #fff; }
.carousel-tile-trigger[data-trigger="O"] { display: inline; background: #ff6a4a; color: #fff; }
.carousel-tile-event { font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; line-height: 1.4; background: #6d28d9; color: #fff; margin-left: 4px; letter-spacing: 0.5px; }
.carousel-tile-pin { opacity: 0.3; }
.carousel-tile-pin:hover { opacity: 0.7; }
.carousel-tile.pinned .carousel-tile-pin { opacity: 1; color: #f0c040; filter: drop-shadow(0 0 3px #f0c040); }
.carousel-tile-close { font-size: 18px; opacity: 0.9; }

.carousel-tile-block {
  font-size: 9px !important;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: #d32f2f !important;
  color: #fff;
  border-radius: 4px;
  padding: 4px 8px !important;
  min-width: auto !important;
  min-height: auto !important;
  opacity: 1 !important;
}
.carousel-tile-block:hover { background: #b71c1c !important; }
.carousel-tile-block.blocked { background: #f57c00 !important; }
.carousel-tile-block.blocked:hover { background: #e65100 !important; }

.carousel-tile-video {
  position: absolute;
  inset: 0;
  background: #000;
  overflow: hidden;
  cursor: pointer;
}
.carousel-tile-video bop-stream,
.carousel-tile-video bop-stream-fisheye {
  width: 100%;
  height: 100%;
  display: block;
}
.carousel-tile-video bop-stream video {
  object-fit: contain !important;
}
.carousel-tile-video bop-stream-fisheye canvas {
  /* The dewarped frame fills the tile — no letterbox. */
  background: #000;
}

.carousel-tile-expanded {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.carousel-tile-expanded img,
.carousel-tile-expanded video,
.carousel-tile-expanded bop-stream,
.carousel-tile-expanded bop-stream video,
.carousel-tile-expanded bop-stream-fisheye {
  max-width: 95vw;
  max-height: 80vh;
  object-fit: contain;
}
.carousel-tile-expanded bop-stream-fisheye {
  /* The expanded fisheye element wants a concrete pixel size to size its
     canvas — clamp it to a 16:9 region inside the max bounds. */
  width: 95vw;
  height: 80vh;
}
.expanded-header {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  padding: 12px 20px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent);
  color: #fff;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  z-index: 1;
}
.expanded-header span { flex: 1; }
.expanded-toolbar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 20px;
  background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
  z-index: 1;
}
.expanded-toolbar button {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  cursor: pointer;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-family: var(--font-display);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  transition: all 0.15s;
}
.expanded-toolbar button:hover { background: rgba(255,255,255,0.25); }
.expanded-toolbar button:active { background: rgba(255,255,255,0.35); }
.expanded-toolbar button.active { background: rgba(74,158,255,0.3); border-color: #4a9eff; color: #4a9eff; }
.carousel-tile-expanded .carousel-tile-close-overlay {
  position: absolute;
  top: 12px; right: 16px;
  background: none;
  border: none;
  color: #fff;
  font-size: 32px;
  z-index: 2;
  cursor: pointer;
}

/* ---- TABLET (iPad) ---- */
@media (max-width: 1024px) {
  .grid { grid-template-columns: repeat(2, 1fr) !important; gap: 16px; padding: 20px 24px; }
  .notif-panel { width: 280px; }
  .notif-inner { min-width: 280px; }
  .header-right { gap: 12px; }
  .status-bar { gap: 12px; }
  #last-update { display: none; }
}

/* ---- SMALL TABLET / LARGE PHONE ---- */
/* ---- Hamburger menu (hidden on desktop) ---- */
.hamburger-btn { display: none; }
.mobile-drawer { display: none; }
.mobile-backdrop { display: none; }

@media (max-width: 768px) {
  header { padding: 0 16px; height: 56px; }
  .logo-mark { width: 32px; height: 32px; font-size: 11px; }
  .logo h1 { font-size: 16px; }
  .logo h1 span { display: none; }
  .logo { gap: 8px; }

  /* Hide nav links, status bar, user menu, page-specific extras — move to drawer */
  .header-right .header-link,
  .header-right .status-bar,
  .header-right .user-menu,
  #header-slot,
  #header-extra { display: none !important; }
  .header-right { gap: 8px; }

  /* Show hamburger */
  .hamburger-btn {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border: 1px solid var(--border-accent);
    border-radius: 8px; background: var(--surface); cursor: pointer;
    flex-shrink: 0;
  }
  .hamburger-btn svg { width: 20px; height: 20px; stroke: var(--text); }

  /* Drawer */
  .mobile-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    z-index: 199; opacity: 0; transition: opacity 0.2s;
  }
  .mobile-backdrop.open { display: block; opacity: 1; }

  .mobile-drawer {
    display: flex; flex-direction: column;
    position: fixed; top: 0; right: -280px; width: 280px; height: 100%;
    background: var(--surface); border-left: 1px solid var(--border);
    z-index: 200; transition: right 0.25s ease;
    box-shadow: -4px 0 20px rgba(0,0,0,0.1);
    overflow-y: auto;
  }
  .mobile-drawer.open { right: 0; }

  .drawer-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
  }
  .drawer-close {
    width: 32px; height: 32px; border: none; background: none;
    font-size: 20px; color: var(--text-dim); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px;
  }
  .drawer-close:hover { background: var(--surface-raised); }

  .drawer-nav { display: flex; flex-direction: column; padding: 8px 0; }
  .drawer-nav a {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 20px; text-decoration: none; color: var(--text);
    font-size: 15px; font-weight: 500; transition: background 0.1s;
  }
  .drawer-nav a:hover { background: var(--surface-raised); }
  .drawer-nav a svg { width: 20px; height: 20px; color: var(--text-dim); flex-shrink: 0; }

  .drawer-status {
    padding: 16px 20px; border-top: 1px solid var(--border);
    font-family: var(--font-mono); font-size: 13px; color: var(--text-dim);
  }
  .drawer-user {
    padding: 12px 20px; border-top: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 8px;
  }
  .drawer-user-info {
    font-size: 14px; font-weight: 500; color: var(--text-bright);
    display: flex; align-items: center; gap: 8px;
  }
  .drawer-user button {
    padding: 10px 16px; border: 1px solid var(--border-accent);
    border-radius: 6px; background: var(--surface); color: var(--text);
    font-size: 13px; cursor: pointer; text-align: left;
  }
  .drawer-user button:hover { background: var(--surface-raised); }

  .grid { grid-template-columns: 1fr !important; padding: 16px; gap: 12px; }
  .table-wrap { padding: 12px 16px; }
  .main-layout { flex-direction: column; }
  .notif-panel { width: 100% !important; border-left: none; border-top: 1px solid var(--border); max-height: 40vh; flex-shrink: 1; }
  .notif-panel.collapsed { max-height: 0; opacity: 0; overflow: hidden; }
  .notif-inner { min-width: 0; }
  .notif-tab { left: unset; right: 16px; top: -36px; border-radius: 8px 8px 0 0; border: 1px solid var(--border-accent); border-bottom: none; width: 44px; height: 36px; }
  .carousel-tile { flex: 0 0 240px; height: 18vh; }
  .camera-carousel { padding: 8px 12px; }
  body.carousel-open { padding-bottom: 280px; }
  .card-top { flex-wrap: wrap; gap: 6px; }
  .card-body { padding: 16px; }
  .intercom-panel { width: 95vw; max-width: none; }
  .intercom-toolbar { gap: 8px; padding: 10px 8px; }
  .intercom-btn { width: 42px; height: 42px; }
  .intercom-volume-slider { width: 60px; }
  .intercom-volume { padding-top: 2px; }

  /* Users page */
  .users-header { flex-direction: column; align-items: stretch; gap: 12px; padding: 16px; }
  .users-header h2 { font-size: 20px; }
  .users-content { padding: 0 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .users-section { margin: 24px 0; padding: 0 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .users-table { min-width: 560px; }
  .roles-table { min-width: 480px; }
  .user-dialog { max-width: 95vw; max-height: 90vh; }
  .ud-device { gap: 6px 8px; }
  .ud-device strong { min-width: 100%; margin-bottom: 4px; }
  .ud-device label { min-width: 56px !important; font-size: 11px; }
}

/* ---- PHONE ---- */
@media (max-width: 480px) {
  header { padding: 0 12px; height: 48px; }
  .logo-mark { width: 28px; height: 28px; font-size: 10px; }
  .logo h1 { font-size: 14px; }
  .hamburger-btn { width: 32px; height: 32px; }
  .hamburger-btn svg { width: 18px; height: 18px; }
  .grid { padding: 12px; gap: 10px; }
  .table-wrap { padding: 8px 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .carousel-tile { flex: 0 0 200px; height: 16vh; }
  .camera-carousel { padding: 6px 8px; }
  body.carousel-open { padding-bottom: 260px; }
  .notif-panel { max-height: 35vh; }
  .card { border-radius: 8px; }
  .gauge-ring { width: 52px; height: 52px; }
  .gauge-value { font-size: 20px; }
  .controls .row { flex-wrap: wrap; }
  .scan-badge { font-size: 11px; padding: 2px 6px; }
}

/* ---- Login page ---- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg);
}
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 48px 40px; width: 100%; max-width: 380px;
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo .logo-mark { display: inline-block; margin-bottom: 8px; }
.login-logo h1 { font-size: 20px; color: var(--text); }
.login-logo h1 span { color: var(--text-dim); }
.login-field { margin-bottom: 16px; }
.login-field label { display: block; font-family: var(--font-mono); font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.login-field input { width: 100%; padding: 10px 12px; border: 1px solid var(--border-accent); border-radius: 6px; font-size: 15px; font-family: var(--font-sans); background: var(--bg); color: var(--text-bright); box-sizing: border-box; }
.login-field input:focus { outline: none; border-color: var(--blue); }
.login-error { color: var(--red); font-size: 13px; min-height: 20px; margin-bottom: 8px; }
.login-btn { width: 100%; padding: 12px; border: none; border-radius: 8px; background: var(--blue); color: #fff; font-size: 15px; font-weight: 600; font-family: var(--font-sans); cursor: pointer; transition: background 0.15s; }
.login-btn:hover { background: var(--blue-bright, #4a90d9); }
.login-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---- User menu ---- */
.user-menu { position: relative; margin-left: 12px; }
.user-menu-btn { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border: 1px solid var(--border-accent); border-radius: 6px; background: var(--surface); color: var(--text-bright); font-family: var(--font-sans); font-size: 13px; font-weight: 500; cursor: pointer; transition: all 0.15s; }
.user-menu-btn:hover { background: var(--surface-raised); }
.role-badge { font-family: var(--font-mono); font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.role-admin { background: var(--red); color: #fff; }
.role-operator { background: var(--blue); color: #fff; }
.role-viewer { background: var(--border-accent); color: var(--text-dim); }
.role-tenant { background: var(--green); color: #fff; }
.user-dropdown { position: absolute; top: 100%; right: 0; margin-top: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); flex-direction: column; min-width: 160px; z-index: 200; }
.user-dropdown a, .user-dropdown button { display: block; width: 100%; padding: 10px 16px; color: var(--text); font-size: 14px; text-decoration: none; transition: background 0.1s; background: none; border: none; text-align: left; cursor: pointer; font-family: var(--font-sans); }
.user-dropdown a:hover, .user-dropdown button:hover { background: var(--surface-raised); }
.user-dropdown a:first-child, .user-dropdown button:first-child { border-radius: 6px 6px 0 0; }
.user-dropdown a:last-child, .user-dropdown button:last-child { border-radius: 0 0 6px 6px; }

/* ---- Password dialog ---- */
.pw-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 500; }
.pw-dialog { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; width: 100%; max-width: 420px; }
.pw-dialog h3 { margin: 0 0 20px; font-size: 18px; color: var(--text-bright); }
.pw-field { margin-bottom: 16px; }
.pw-dialog label { display: block; margin-bottom: 4px; font-size: 13px; font-weight: 500; color: var(--text-dim); }
.pw-dialog input, .pw-dialog select { width: 100%; padding: 10px 12px; border: 1px solid var(--border-accent); border-radius: 6px; font-size: 14px; background: var(--bg); color: var(--text-bright); box-sizing: border-box; transition: border-color 0.15s; }
.pw-dialog input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px rgba(74,158,255,0.15); }
.pw-error { color: var(--red); font-size: 13px; min-height: 18px; margin: 4px 0 8px; }
.pw-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 20px; }
.pw-cancel, .pw-save { padding: 10px 24px; border: none; border-radius: 6px; font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.15s; font-family: var(--font-sans); }
.pw-cancel { background: var(--border-accent); color: var(--text); }
.pw-cancel:hover { background: var(--border); }
.pw-save { background: var(--blue); color: #fff; }
.pw-save:hover { filter: brightness(1.1); }

/* ---- iPhone pairing dialog ---- */
.pair-status { font-size: 13px; font-weight: 500; color: var(--text-dim); margin: 0 0 12px; }
.pair-status-error { color: var(--red); }
.pair-qr-box { padding: 16px; background: #fff; border-radius: 8px; margin: 0 auto 16px; width: fit-content; }
.pair-url { white-space: pre-wrap; word-break: break-all; font-family: var(--font-mono); font-size: 13px; padding: 10px 12px; background: var(--bg); color: var(--text-bright); border: 1px solid var(--border-accent); border-radius: 6px; margin: 0 0 12px; box-sizing: border-box; }
.pair-expires { font-size: 12px; color: var(--text-dim); margin: 0 0 4px; }

/* ---- Users page ---- */
.users-header { display: flex; align-items: center; justify-content: space-between; padding: 24px 32px; }
.users-header h2 { font-size: 24px; font-weight: 600; color: var(--text-bright); }
.users-add-btn { font-family: var(--font-mono); font-size: 13px; font-weight: 600; padding: 8px 20px; border: none; border-radius: 6px; background: var(--blue); color: #fff; cursor: pointer; }
.users-content { padding: 0 32px; }
.users-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.users-table th { font-family: var(--font-mono); font-size: 12px; font-weight: 600; color: var(--text-dim); padding: 12px 16px; text-align: left; background: var(--surface-raised); border-bottom: 1px solid var(--border); text-transform: uppercase; letter-spacing: 0.5px; }
.users-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 14px; color: var(--text); }
.users-table tr:last-child td { border-bottom: none; }
.users-actions { display: flex; gap: 8px; }
.users-action-btn { padding: 4px 12px; border: 1px solid var(--border-accent); border-radius: 4px; background: var(--surface); color: var(--text); font-size: 12px; cursor: pointer; }
.users-action-btn.danger { border-color: var(--red); color: var(--red); }
.users-action-btn:hover { background: var(--surface-raised); }
.users-section { margin: 32px 0; padding: 0 32px; }
.users-section h3 { font-size: 18px; font-weight: 600; color: var(--text-bright); margin-bottom: 16px; }
.roles-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.roles-table th { font-family: var(--font-mono); font-size: 12px; padding: 10px 12px; background: var(--surface-raised); border-bottom: 1px solid var(--border); text-transform: uppercase; }
.roles-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); font-family: var(--font-mono); font-size: 13px; }
.roles-table tr:last-child td { border-bottom: none; }
.user-dialog { max-width: 560px; max-height: 80vh; overflow-y: auto; }
.user-dialog h4 { font-size: 14px; color: var(--text-bright); margin: 16px 0 8px; }
.ud-device { padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.ud-device strong { min-width: 140px; font-size: 13px; }
.ud-device label { font-size: 12px; display: inline-flex; align-items: center; gap: 4px; }
#ud-preset-row { margin-bottom: 12px; }

/* ---- Shared page layout helpers ---- */
.page-header { display: flex; align-items: center; gap: 16px; padding: 24px 32px; }
.page-header h2 { font-size: 24px; font-weight: 600; color: var(--text-bright); }
.page-back { font-family: var(--font-mono); font-size: 13px; color: var(--text-dim); text-decoration: none; padding: 6px 12px; border: 1px solid var(--border-accent); border-radius: 6px; transition: all 0.15s; }
.page-back:hover { background: var(--surface-raised); }
.page-empty { text-align: center; padding: 60px 20px; color: var(--text-dim); font-size: 15px; }
.filter-chip { display: inline-block; font-family: var(--font-mono); font-size: 12px; font-weight: 500; padding: 4px 10px; border-radius: 12px; cursor: pointer; background: var(--surface-raised); color: var(--text-dim); border: 1px solid var(--border); margin: 0 4px 4px 0; transition: all 0.15s; }
.filter-chip:hover { border-color: var(--text-dim); }
.filter-chip.active { background: var(--text-bright); color: #fff; border-color: var(--text-bright); }

/* ---- INTERCOM ---- */
.intercom-link { color: var(--green) !important; }
.carousel-tile-intercom { color: var(--green) !important; opacity: 0.8 !important; min-width: 24px !important; padding: 4px !important; }
.carousel-tile-intercom:hover { opacity: 1 !important; color: #22c55e !important; }
.intercom-link:hover { color: var(--green-bright) !important; }
.intercom-panel-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.85);
  z-index: 2000; display: flex; align-items: center; justify-content: center;
}
.intercom-panel {
  background: #111; border-radius: 12px; width: 90vw; max-width: 640px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.intercom-panel-header {
  display: flex; align-items: center; gap: 12px; padding: 14px 18px;
  background: rgba(255,255,255,0.05); border-bottom: 1px solid rgba(255,255,255,0.1);
  color: #fff; font-size: 14px; font-weight: 600;
}
.intercom-status { margin-left: auto; font-size: 12px; font-weight: 400; color: var(--text-dim); }
.intercom-panel-close {
  background: none; border: none; color: #999; font-size: 22px; cursor: pointer;
  padding: 0 4px; line-height: 1; margin-left: 8px;
}
.intercom-panel-close:hover { color: #fff; }
.intercom-video { aspect-ratio: 16/9; background: #000; position: relative; }
.intercom-toolbar {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 12px 16px; background: rgba(255,255,255,0.05);
  flex-wrap: wrap;
}
.intercom-btn {
  width: 48px; height: 48px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08); color: #999; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all 0.15s;
  flex-shrink: 0;
}
.intercom-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }
.intercom-btn.active { border-color: var(--green); color: var(--green); background: rgba(22,163,74,0.15); }
.intercom-btn.hangup { border-color: var(--red); color: var(--red); background: rgba(220,38,38,0.15); }
.intercom-btn.hangup:hover { background: rgba(220,38,38,0.3); color: #ff6b6b; }
.intercom-btn.hangup svg { transform: rotate(135deg); }

/* Intercom volume slider */
.intercom-volume {
  display: flex; align-items: center; gap: 6px; color: #999;
  width: 100%; justify-content: center; padding-top: 4px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.intercom-volume-slider {
  width: 80px; height: 4px; -webkit-appearance: none; appearance: none;
  background: rgba(255,255,255,0.2); border-radius: 2px; outline: none;
}
.intercom-volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--green); cursor: pointer; border: none;
}
.intercom-volume-slider::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--green); cursor: pointer; border: none;
}
.intercom-volume-label { font-size: 12px; min-width: 18px; text-align: center; color: var(--text-dim); }

/* Intercom ring notification */
.intercom-ring {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 2100; display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 12px;
  background: var(--surface); border: 2px solid var(--green);
  box-shadow: 0 4px 24px rgba(0,0,0,0.15), 0 0 0 0 rgba(22,163,74,0.4);
  animation: intercom-ring-pulse 2s ease-in-out infinite;
  min-width: 300px; max-width: 480px;
}
@keyframes intercom-ring-pulse {
  0%, 100% { box-shadow: 0 4px 24px rgba(0,0,0,0.15), 0 0 0 0 rgba(22,163,74,0.4); }
  50% { box-shadow: 0 4px 24px rgba(0,0,0,0.15), 0 0 0 8px rgba(22,163,74,0); }
}
.intercom-ring-icon {
  color: var(--green); flex-shrink: 0;
  animation: intercom-ring-shake 0.5s ease-in-out infinite;
}
@keyframes intercom-ring-shake {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-12deg); }
  75% { transform: rotate(12deg); }
}
.intercom-ring-answer {
  padding: 6px 16px; border-radius: 8px; border: none;
  background: var(--green); color: #fff; font-weight: 600;
  font-size: 13px; cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.intercom-ring-answer:hover { background: var(--green-bright); }
.intercom-ring-reject {
  padding: 6px 16px; border-radius: 8px; border: none;
  background: var(--red); color: #fff; font-weight: 600;
  font-size: 13px; cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.intercom-ring-reject:hover { background: #e53935; }
.intercom-ring-dismiss {
  background: none; border: none; color: var(--text-dim); font-size: 20px;
  cursor: pointer; padding: 0 4px; line-height: 1; flex-shrink: 0;
}
.intercom-ring-dismiss:hover { color: var(--text); }
