:root {
  --bg: #f1f5f9;
  --sidebar: #ffffff;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #465fff;
  --primary-hover: #3641f5;
  --purple: #7a5af8;
  --blue: #0ba5ec;
  --green: #12b76a;
  --danger: #f04438;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  --sidebar-width: 260px;
  --header-height: 64px;
}

:root[data-theme="dark"] {
  --bg: #071426;
  --sidebar: #0a1b30;
  --card: #102844;
  --text: #e7f2ff;
  --muted: #9bb6d1;
  --border: #284b6d;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --shadow: 0 6px 20px rgba(1, 10, 24, 0.28);
}

:root[data-theme="dark"] body,
:root[data-theme="dark"] .main { background: var(--bg); color: var(--text); }
:root[data-theme="dark"] input,
:root[data-theme="dark"] select { background: #0b2038 !important; color: var(--text); }
:root[data-theme="dark"] .topbar { background: rgba(10, 27, 48, 0.92); border-color: var(--border); }
:root[data-theme="dark"] .nav-item { color: #b8cee4; }
:root[data-theme="dark"] .nav-item:hover { background: #123253; color: #fff; }
:root[data-theme="dark"] .nav-item.active { background: #163d66; color: #dcebff; }
:root[data-theme="dark"] .data-table th { background: #0d223a; color: #a9c4df; }
:root[data-theme="dark"] .data-table tbody tr:hover { background: #153554; }
:root[data-theme="dark"] .btn-secondary { background: #163652; color: #e7f2ff; border-color: #31597d; }
:root[data-theme="dark"] .btn-secondary:hover,
:root[data-theme="dark"] .btn-ghost:hover { background: #1d466b; }
:root[data-theme="dark"] .btn-ghost { color: #bdd2e7; }
:root[data-theme="dark"] .readonly-grid input,
:root[data-theme="dark"] code { background: #0b2038; color: #cfe4f8; }
:root[data-theme="dark"] .progress-track { background: #234663; }
:root[data-theme="dark"] .stat-icon.purple { background: #283867; }
:root[data-theme="dark"] .stat-icon.blue { background: #123f62; }
:root[data-theme="dark"] .stat-icon.green { background: #124b47; }
:root[data-theme="dark"] .stat-icon.orange { background: #554021; }
:root[data-theme="dark"] .action-menu-button { background: #153554; }
:root[data-theme="dark"] .action-menu-popup { background: #12304f; }
:root[data-theme="dark"] .livewall-camera-item:hover { background: #173b5e; }
:root[data-theme="dark"] .status-badge.online { background: #123f3b; color: #68e0bb; }
:root[data-theme="dark"] .status-badge.offline { background: #243c55; color: #b7cae0; }
:root[data-theme="dark"] .status-badge.error { background: #532c31; color: #ffaaa5; }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

code {
  background: #f8fafc;
  border: 1px solid var(--border);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
}

/* ── Auth ── */
.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 50%, #eff6ff 100%);
}

.auth-wrap { width: min(420px, 92vw); }

.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1.75rem;
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.brand h1 { margin: 0; font-size: 1.25rem; }
.brand p { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.9rem; }

.auth-form h2 { margin: 0 0 0.35rem; font-size: 1.35rem; }
.auth-sub { margin: 0 0 1.25rem; color: var(--muted); font-size: 0.92rem; }

.auth-form label {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.88rem;
  font-weight: 500;
  color: #334155;
}

.auth-form input {
  display: block;
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  background: #fff;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(70, 95, 255, 0.15);
}

.auth-foot {
  margin: 1.25rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.form-error {
  margin: 0.75rem 0 0;
  color: var(--danger);
  font-size: 0.88rem;
}

.hidden { display: none !important; }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  transition: width 0.22s ease, transform 0.22s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  height: var(--header-height);
  min-height: var(--header-height);
  padding: 0 1.35rem;
  font-weight: 700;
  font-size: 1.05rem;
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
}

.sidebar-toggle {
  position: absolute;
  top: 18px;
  right: -14px;
  z-index: 45;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--card);
  color: var(--muted);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .22s ease, color .2s, background .2s;
}
.sidebar-toggle:hover { color: var(--primary); background: var(--bg); }
.sidebar-toggle svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-brand .brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.brand-logo {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex-shrink: 0;
}

.brand .brand-logo {
  width: 42px;
  height: 42px;
}

.sidebar-nav {
  padding: 1rem 0.85rem 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem;
  border: none;
  background: transparent;
  color: #475569;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.92rem;
  text-align: left;
  margin-bottom: 0.25rem;
}

.nav-item svg:first-child { width: 18px; height: 18px; stroke-width: 2; flex-shrink: 0; fill: none; }

.nav-item:hover { background: #f8fafc; color: var(--text); }

.nav-item.active {
  background: #eef2ff;
  color: var(--primary);
  font-weight: 600;
}

.nav-item .chevron {
  width: 16px;
  height: 16px;
  margin-left: auto;
  stroke-width: 2;
  transition: transform 0.2s;
}

.nav-parent.open .chevron { transform: rotate(180deg); }

.nav-item.sub {
  padding-left: 2.5rem;
  font-size: 0.88rem;
}

.nav-item.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.nav-sub {
  display: none;
  margin-top: 0.15rem;
}

.nav-sub.open { display: block; }

.form-grid label.checkbox {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 400;
  color: var(--muted);
}

.form-grid label.checkbox input[type="checkbox"] {
  width: auto;
  margin: 0;
  padding: 0;
  accent-color: var(--primary);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 400;
  color: var(--muted);
  font-size: 0.88rem;
}

.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  transition: margin-left .22s ease;
}

:root.sidebar-collapsed .sidebar { width: 76px; }
:root.sidebar-collapsed .main { margin-left: 76px; }
:root.sidebar-collapsed .sidebar-brand {
  justify-content: center;
  padding: 0;
}
:root.sidebar-collapsed .sidebar-brand > span { display: none; }
:root.sidebar-collapsed .sidebar-nav { padding: 1rem 0.65rem; overflow-x: hidden; }
:root.sidebar-collapsed .nav-item {
  justify-content: center;
  gap: 0;
  padding: 0.72rem;
  font-size: 0;
}
:root.sidebar-collapsed .nav-item svg:first-child { width: 21px; height: 21px; }
:root.sidebar-collapsed .nav-item .chevron,
:root.sidebar-collapsed .nav-sub { display: none; }
:root.sidebar-collapsed .sidebar-toggle { transform: rotate(180deg); }
:root[data-theme="dark"] .sidebar-toggle { background: #153554; color: #bcd2e8; }

.topbar {
  height: var(--header-height);
  min-height: var(--header-height);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 30;
  box-sizing: border-box;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.theme-icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--card);
  color: #526b84;
  cursor: pointer;
  transition: background .2s, color .2s, transform .2s;
}
.theme-icon-button:hover {
  color: var(--primary);
  transform: translateY(-1px);
}
.theme-icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.theme-icon-button .theme-moon { fill: currentColor; stroke: none; }
.theme-sun { display: none; }
:root[data-theme="dark"] .theme-icon-button { background: #153554; color: #ffd166; }
:root[data-theme="dark"] .theme-moon { display: none; }
:root[data-theme="dark"] .theme-sun { display: block; }

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 0.85rem;
}

.content { padding: 1.5rem; }

.page { display: none; }
.page.active { display: block; }

.page-head { margin-bottom: 1.25rem; }
.page-head h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.page-head p { margin: 0; color: var(--muted); }
.page-head-actions { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }

/* ── Cards & stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem;
  display: flex;
  gap: 0.85rem;
  box-shadow: var(--shadow);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: grid;
  place-items: center;
}

.stat-icon svg { width: 22px; height: 22px; stroke-width: 2; fill: none; }

.stat-icon.purple { background: #f4f3ff; color: var(--purple); }
.stat-icon.blue { background: #eff8ff; color: var(--blue); }
.stat-icon.green { background: #ecfdf3; color: var(--green); }
.stat-icon.orange { background: #fff6ed; color: #f79009; }

.stat-label { margin: 0; font-size: 0.82rem; color: var(--muted); }
.stat-value { margin: 0.15rem 0 0; font-size: 1.05rem; font-weight: 600; }
.stat-meta { margin: 0.15rem 0 0; font-size: 0.8rem; color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow);
}

.card h3 { margin: 0 0 0.5rem; font-size: 1rem; }
.card-spaced { margin-bottom: 1rem; }

.resource-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-top: 0.75rem;
}

.resource-item {
  display: flex;
  flex-direction: column;
}

.resource-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.55rem;
}

.resource-label {
  font-size: 0.9rem;
  font-weight: 600;
}

.resource-value {
  font-size: 0.95rem;
  font-weight: 700;
}

.resource-meta {
  margin: 0.45rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.progress-track {
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--green);
  transition: width 0.35s ease, background-color 0.35s ease;
}

.progress-fill.warning { background: #f79009; }
.progress-fill.critical { background: var(--danger); }

.readonly-grid input[readonly] {
  background: #f8fafc;
  color: #475569;
  cursor: default;
}
.muted { color: var(--muted); font-size: 0.92rem; margin: 0; }

/* ── Forms ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem 1.25rem;
}

.form-grid label {
  display: block;
  font-size: 0.88rem;
  font-weight: 500;
  color: #334155;
}

.form-grid label.full { grid-column: 1 / -1; }
.form-grid > .full { grid-column: 1 / -1; }

.form-grid label .field-hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.82rem;
  font-weight: 400;
  line-height: 1.45;
  color: var(--muted);
}

.form-grid input:not([type="checkbox"]):not([type="radio"]),
.form-grid select {
  display: block;
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  background: #fff;
}

.form-grid input:focus, .form-grid select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(70, 95, 255, 0.12);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.25rem;
}

.form-actions.full { grid-column: 1 / -1; }

/* ── Buttons ── */
.btn {
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

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

.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: #f8fafc; }

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

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: #475569;
}
.btn-ghost:hover { background: #f8fafc; }
.btn-block { width: 100%; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  max-width: 420px;
  padding: 0.85rem 1.1rem;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 12px 32px rgba(16, 24, 40, 0.12);
  z-index: 100;
}
.toast.ok { border-left: 4px solid var(--green); }
.toast.err { border-left: 4px solid var(--danger); }

/* ── Data table ── */
.table-wrap { overflow-x: auto; margin-top: 0.75rem; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.data-table th,
.data-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table tbody tr:hover { background: #f8fafc; }

.filter-row {
  display: flex;
  align-items: end;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.filter-row label {
  display: grid;
  gap: 0.3rem;
  min-width: 130px;
  color: var(--muted);
  font-size: 0.8rem;
}

.filter-row input, .filter-row select,
.livewall-camera-workspace input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  background: #fff;
  color: var(--text);
}

.filter-grow { flex: 1; }
.camera-search { width: 240px; flex: 0 0 240px; }

.action-menu { position: relative; display: inline-block; }
.action-menu-button {
  min-width: 38px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  padding: 0.3rem 0.55rem;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
}
.action-menu-popup {
  position: absolute;
  top: calc(100% + 5px);
  right: 0;
  z-index: 30;
  min-width: 120px;
  padding: 0.3rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 10px 25px rgba(15,23,42,.18);
}
.action-menu-popup.hidden { display: none; }
.action-menu-popup button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 0.5rem 0.65rem;
  text-align: left;
  cursor: pointer;
}
.action-menu-popup button:hover { background: rgba(148,163,184,.15); }
.action-menu-popup button.danger { color: #dc2626; }

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  vertical-align: middle;
}
.toggle-switch input {
  width: 0;
  height: 0;
  opacity: 0;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #cbd5e1;
  cursor: pointer;
  transition: background .2s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .2s;
}
.toggle-switch input:checked + .toggle-slider { background: #22c55e; }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }
.toggle-switch input:disabled + .toggle-slider { opacity: .55; cursor: not-allowed; }

.record-status-button {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: .25rem .65rem;
  text-transform: capitalize;
  cursor: pointer;
}
.record-status-button.recording { color: #15803d; border-color: #86efac; background: #f0fdf4; }
.record-status-button.error { color: #b91c1c; border-color: #fca5a5; background: #fef2f2; }
.record-controls { display: flex; align-items: center; gap: .45rem; min-width: 190px; }
.playback-video { width: 100%; max-height: 58vh; background: #000; border-radius: 8px; margin-bottom: 1rem; }
.playback-files { display: grid; gap: .5rem; max-height: 240px; overflow: auto; }
.playback-file { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .65rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.playback-file-actions { display: flex; gap: .5rem; }

.pagination {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.85rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.68); }
.modal-panel {
  position: relative;
  width: min(620px, 100%);
  max-height: 90vh;
  overflow: auto;
  border-radius: 12px;
  background: var(--card);
  padding: 1.25rem;
  box-shadow: 0 24px 60px rgba(0,0,0,.28);
}
.modal-wide { width: min(1000px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.modal-head h2 { margin: 0; font-size: 1.2rem; }
.modal-close { border: 0; background: transparent; color: var(--muted); font-size: 1.8rem; cursor: pointer; }

.btn-compact {
  padding: 0.3rem 0.6rem;
  font-size: 0.78rem;
  margin-right: 0.35rem;
}

.livewall-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
}

.livewall-controls { display: flex; align-items: end; gap: 0.5rem; flex-wrap: wrap; }
.livewall-controls label { display: grid; gap: 0.25rem; color: var(--muted); font-size: 0.8rem; }
.livewall-controls select { border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem; }

.livewall-workspaces {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 0.75rem;
  transition: grid-template-columns .22s ease;
}

.livewall-camera-workspace { padding: 0.8rem; min-width: 0; }
.camera-tree-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.65rem;
}
.camera-tree-head h3 { margin: 0; }
.camera-tree-head-actions { display: flex; align-items: center; gap: 0.4rem; }
.workspace-panel-toggle {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: transform .2s, color .2s, background .2s;
}
.workspace-panel-toggle:hover { color: var(--primary); background: rgba(59,130,246,.12); }
.workspace-panel-toggle svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.livewall-workspaces.workspace-panel-collapsed {
  grid-template-columns: 48px minmax(0, 1fr);
}
.workspace-panel-collapsed .livewall-camera-workspace { padding: 0.55rem; }
.workspace-panel-collapsed .camera-tree-head { justify-content: center; }
.workspace-panel-collapsed .camera-tree-head h3,
.workspace-panel-collapsed .tree-add-button,
.workspace-panel-collapsed .livewall-camera-workspace > input,
.workspace-panel-collapsed .camera-tree,
.workspace-panel-collapsed .camera-tree-selection,
.workspace-panel-collapsed #livewall-camera-list { display: none; }
.workspace-panel-collapsed .workspace-panel-toggle { transform: rotate(180deg); }
.tree-add-button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
}
.camera-tree {
  margin-top: 0.75rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}
.camera-tree-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 34px;
  padding-right: 0.35rem;
  border-radius: 7px;
  color: var(--text);
  cursor: pointer;
}
.camera-tree-row:hover,
.camera-tree-row.active { background: rgba(59, 130, 246, 0.15); }
.tree-expand {
  display: grid;
  place-items: center;
  width: 18px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
}
.tree-expand:disabled { cursor: default; }
.tree-folder-icon { color: #80bfff; font-size: 1rem; }
.tree-group-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.84rem;
}
.tree-group-count {
  min-width: 25px;
  padding: 0.05rem 0.3rem;
  border-radius: 5px;
  background: rgba(234, 179, 8, 0.12);
  color: #d7b84b;
  font-size: 0.72rem;
  text-align: center;
}
.tree-group-actions { display: none; align-items: center; }
.camera-tree-row:hover .tree-group-actions { display: flex; }
.tree-group-actions button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.1rem 0.2rem;
  cursor: pointer;
}
.tree-group-actions button:hover { color: var(--primary); }
.camera-tree-selection {
  margin-top: 0.7rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}
#livewall-camera-list { display: grid; gap: 0.45rem; margin-top: 0.65rem; max-height: 70vh; overflow: auto; }
.livewall-camera-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: grab;
}
.livewall-camera-details {
  display: grid;
  gap: 0.2rem;
  flex: 1;
  min-width: 0;
}
.livewall-camera-item span { color: var(--muted); font-size: 0.75rem; }
.workspace-camera-delete {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  opacity: 0;
  cursor: pointer;
  transition: opacity .15s, color .15s, background .15s;
}
.livewall-camera-item:hover .workspace-camera-delete { opacity: 1; }
.workspace-camera-delete:hover {
  border-color: rgba(239,68,68,.3);
  background: rgba(239,68,68,.12);
  color: #ef4444;
}
.livewall-camera-item.temporarily-hidden {
  border-style: dashed;
  opacity: .82;
}
.workspace-camera-restore {
  flex: 0 0 auto;
  padding: 0.3rem 0.45rem;
  border: 1px solid rgba(59,130,246,.45);
  border-radius: 6px;
  background: rgba(59,130,246,.12);
  color: #7db5ff;
  font-size: 0.7rem;
  cursor: pointer;
}
.workspace-camera-restore:hover {
  background: rgba(59,130,246,.25);
  color: #fff;
}

.livewall-layout-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.livewall-layout-control select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  background: #fff;
}

.livewall-grid {
  display: grid;
  gap: 0.75rem;
  min-height: 420px;
}

.livewall-grid-area {
  position: relative;
  min-width: 0;
}

.livewall-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.livewall-pagination span {
  min-width: 78px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
  text-align: center;
}

.livewall-page-arrow {
  position: absolute;
  top: calc(50% - 24px);
  z-index: 20;
  display: grid;
  place-items: center;
  width: 42px;
  height: 54px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 9px;
  background: rgba(5, 20, 38, .72);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  opacity: 0;
  cursor: pointer;
  transition: opacity .18s, background .18s;
}
.livewall-page-arrow.previous { left: 10px; }
.livewall-page-arrow.next { right: 10px; }
.livewall-grid-area:hover .livewall-page-arrow { opacity: 1; }
.livewall-page-arrow:hover { background: rgba(22, 61, 102, .95); }

.livewall-grid.cols-1 { grid-template-columns: 1fr; }
.livewall-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.livewall-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.livewall-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.livewall-grid.cols-8 { grid-template-columns: repeat(8, minmax(0, 1fr)); }

.livewall-tile {
  min-width: 0;
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid #263241;
  background: #111827;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
}

.livewall-player {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
  background: #020617;
  pointer-events: none;
}

.livewall-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.55rem 0.7rem;
  color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.82));
  opacity: 0;
  transition: opacity .15s;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  pointer-events: auto;
}
.livewall-tile { position: relative; }
.livewall-tile:hover .livewall-overlay { opacity: 1; }
.livewall-tile.dragging { opacity: .5; transform: scale(.985); }
.livewall-tile.drop-target {
  border-color: #60a5fa;
  box-shadow: inset 0 0 0 2px #60a5fa, 0 0 18px rgba(59,130,246,.35);
}
.livewall-cell-menu { position: relative; }
.livewall-cell-menu-button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 7px;
  background: rgba(5,20,38,.7);
  color: #fff;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}
.livewall-cell-menu-popup {
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  z-index: 35;
  min-width: 180px;
  padding: 0.3rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 12px 28px rgba(0,0,0,.32);
}
.livewall-cell-menu-popup.hidden { display: none; }
.livewall-cell-menu-popup button {
  display: block;
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.livewall-cell-menu-popup button:hover { background: rgba(148,163,184,.16); }
.livewall-cell-menu-popup button.danger { color: #ef4444; }
.livewall-grid:fullscreen,
.livewall-grid.fullscreen-fallback {
  padding: 0.75rem;
  background: #020617;
}
.livewall-grid.fullscreen-fallback { position: fixed; inset: 0; z-index: 999; overflow: auto; }

.livewall-tile-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.7rem;
  color: #f8fafc;
  font-size: 0.85rem;
}

.livewall-empty {
  display: grid;
  place-items: center;
  min-height: 180px;
  color: #94a3b8;
}

.status-badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: capitalize;
}

.status-badge.online {
  background: #ecfdf3;
  color: #027a48;
}

.status-badge.offline {
  background: #fef3f2;
  color: #b42318;
}

.status-badge.error {
  background: #fff6ed;
  color: #c4320a;
}

/* ── Logs ── */
.log-viewer {
  background: #0f172a;
  color: #e2e8f0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  padding: 1rem;
  border-radius: 8px;
  height: 400px;
  overflow-y: auto;
  white-space: pre-wrap;
  border: 1px solid #334155;
  margin-top: 1rem;
}

/* Responsive */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    position: relative;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .main { margin-left: 0; }
  .sidebar-toggle { right: 1rem; }
  :root.sidebar-collapsed .sidebar { width: 100%; }
  :root.sidebar-collapsed .main { margin-left: 0; }
  :root.sidebar-collapsed .sidebar-brand {
    justify-content: flex-start;
    padding: 0 1.35rem;
  }
  :root.sidebar-collapsed .sidebar-brand > span { display: inline; }
  :root.sidebar-collapsed .sidebar-nav { display: none; }
  :root.sidebar-collapsed .sidebar-toggle { transform: rotate(-90deg); }
  .form-grid { grid-template-columns: 1fr; }
  .livewall-grid.cols-2,
  .livewall-grid.cols-3,
  .livewall-grid.cols-4,
  .livewall-grid.cols-8 { grid-template-columns: 1fr; }
  .livewall-workspaces { grid-template-columns: 1fr; }
  .livewall-workspaces.workspace-panel-collapsed { grid-template-columns: 1fr; }
  .workspace-panel-collapsed .livewall-camera-workspace { min-height: 48px; }
}
