:root {
  color-scheme: dark;
  --bg: #0f1219;
  --surface: #1a1f2e;
  --border: #2a3145;
  --text: #e8eaf0;
  --muted: #9aa3b5;
  --accent: #4f8cff;
  --success: #3ecf8e;
  --danger: #ff6b6b;
  --create: #ffb020;
  --control-height: 44px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell, sans-serif;
}

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

/* Full-viewport backdrop on html; horizontal scroll if any child exceeds viewport. */
html {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: auto;
  background: radial-gradient(1200px 600px at 10% -10%, #1c2438 0%, var(--bg) 55%);
}

body {
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: fit-content;
  max-width: 100%;
  min-width: 0;
  color: var(--text);
  line-height: 1.5;
}

/* Dashboard packs many full-width panels; fit-content shrink-wraps the shell (~500px) and breaks Live tile columns. */
body.page-dashboard {
  width: 100%;
}

.app-header {
  box-sizing: border-box;
  padding: 1.25rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(26, 31, 46, 0.95), rgba(15, 18, 25, 0.6));
}

.brand {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.brand-logo {
  display: block;
  height: 2.5rem;
  width: auto;
  max-width: min(220px, 55vw);
  object-fit: contain;
  object-position: left center;
  flex-shrink: 0;
}

.page-login .brand-logo {
  height: 3rem;
  max-width: min(260px, 85vw);
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.35rem 0 1rem;
  padding-left: 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.shell {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin: 0 auto;
  padding: 1rem 1rem calc(1.5rem + env(safe-area-inset-bottom));
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
}

.panel h2 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

.muted {
  color: var(--muted);
}

code {
  font-size: 0.85em;
  background: rgba(0, 0, 0, 0.35);
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
}

.health-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  font-size: 0.9rem;
  background: rgba(62, 207, 142, 0.12);
  border: 1px solid rgba(62, 207, 142, 0.35);
  color: var(--success);
}

.health-pill.error {
  background: rgba(255, 107, 107, 0.12);
  border-color: rgba(255, 107, 107, 0.35);
  color: var(--danger);
}

.auth-panel h2 {
  margin-top: 0;
}

.stack-form {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.85rem;
  margin-top: 0.75rem;
}

.stack-form.tight {
  margin-top: 0.75rem;
}

.field {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  font-size: 0.9rem;
  max-width: 100%;
}

.field input:where(:not([type='checkbox']):not([type='radio']):not([type='hidden'])),
.field select {
  box-sizing: border-box;
  height: var(--control-height);
  padding: 0 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #121722;
  color: var(--text);
  font: inherit;
  width: auto;
  max-width: 100%;
  min-width: min(100%, 14rem);
}

.field textarea {
  box-sizing: border-box;
  min-height: var(--control-height);
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #121722;
  color: var(--text);
  font: inherit;
  width: auto;
  max-width: 100%;
  min-width: min(100%, 22rem);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-height: var(--control-height);
  padding: 0 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #121722;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}

.btn.primary {
  background: linear-gradient(135deg, #3d5dff, #4f8cff);
  border-color: transparent;
  color: #fff;
}

.btn.success {
  background: rgba(62, 207, 142, 0.15);
  border-color: rgba(62, 207, 142, 0.55);
  color: #c9ffe7;
}

.btn.danger {
  background: rgba(255, 107, 107, 0.14);
  border-color: rgba(255, 107, 107, 0.6);
  color: #ffd0d0;
}

.btn.create {
  background: rgba(255, 176, 32, 0.14);
  border-color: rgba(255, 176, 32, 0.6);
  color: #ffe8bf;
}

.btn.secondary {
  background: #222838;
}

.btn.ghost {
  background: transparent;
  font-weight: 500;
}

.session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.session-label {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
}

.card {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #121722;
}

.h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.small {
  font-size: 0.85rem;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  font-size: 0.75rem;
}

.uri-box {
  white-space: pre-wrap;
  word-break: break-all;
  padding: 0.65rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  margin-top: 0.65rem;
}

.totp-qr-wrap {
  margin-top: 0.85rem;
  padding: 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
}

.totp-qr-host {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.65rem;
  border-radius: 10px;
  background: #121722;
}

.totp-qr-host img,
.totp-qr-host canvas {
  display: block;
  border-radius: 6px;
}

.uri-label {
  margin: 0.75rem 0 0.25rem;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 540px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

.checkbox-field {
  flex-direction: row !important;
  align-items: flex-start;
  gap: 0.5rem;
}

.checkbox-field input[type='checkbox'] {
  width: auto;
  margin-top: 0.2rem;
}

.nvr-add-card {
  margin-top: 1rem;
}

.nvr-add-title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.nvr-list-mount {
  margin-top: 0.75rem;
}

.nvr-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nvr-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(18, 23, 34, 0.65);
  margin-bottom: 0.5rem;
}

.nvr-row-main {
  min-width: 0;
}

.nvr-status {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: capitalize;
  white-space: nowrap;
}

.nvr-status--online {
  color: var(--success);
}

.nvr-status--degraded {
  color: #e6c84a;
}

.nvr-status--offline {
  color: var(--danger);
}

.nvr-status--unknown,
.nvr-status--disabled {
  color: var(--muted);
}

/* NVR devices screen (toolbar + grid + dialog) */
.nvr-screen {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.nvr-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.nvr-titlebar-heading {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: var(--control-height);
  height: var(--control-height);
  min-height: var(--control-height);
  min-width: var(--control-height);
  padding: 0;
  border-radius: 10px;
}

.icon-btn .icon-svg {
  width: 1.15rem;
  height: 1.15rem;
}

.icon-btn--primary {
  border-color: rgba(79, 140, 255, 0.55);
  background: rgba(79, 140, 255, 0.15);
  color: var(--accent);
}

.icon-btn--primary:hover:not(:disabled) {
  background: rgba(79, 140, 255, 0.28);
}

.icon-btn--create {
  border-color: rgba(255, 176, 32, 0.6);
  background: rgba(255, 176, 32, 0.16);
  color: var(--create);
}

.icon-btn--create:hover:not(:disabled) {
  background: rgba(255, 176, 32, 0.28);
}

.icon-btn--danger {
  border-color: rgba(255, 107, 107, 0.55);
  background: rgba(255, 107, 107, 0.12);
  color: var(--danger);
}

.icon-btn--danger:hover:not(:disabled) {
  background: rgba(255, 107, 107, 0.2);
}

.icon-btn--success {
  border-color: rgba(62, 207, 142, 0.6);
  background: rgba(62, 207, 142, 0.14);
  color: var(--success);
}

.icon-btn--success:hover:not(:disabled) {
  background: rgba(62, 207, 142, 0.24);
}

.nvr-toolbar {
  padding: 0.65rem 0.85rem;
}

.nvr-toolbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.85rem;
}

.nvr-found {
  color: var(--muted);
  font-size: 0.9rem;
}

.nvr-found strong {
  color: var(--text);
}

.nvr-search-group {
  display: flex;
  align-items: stretch;
  gap: 0.35rem;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
}

.nvr-search-input {
  box-sizing: border-box;
  width: 32ch;
  max-width: 100%;
  flex: 0 0 auto;
  min-width: 0;
  height: var(--control-height);
  padding: 0 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(12, 15, 22, 0.65);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.nvr-search-input::placeholder {
  color: var(--muted);
}

.nvr-search-input:focus {
  outline: none;
  border-color: rgba(79, 140, 255, 0.55);
  box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.2);
}

.nvr-grid-card {
  padding: 0;
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.nvr-data-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.nvr-data-grid th,
.nvr-data-grid td {
  padding: 0.55rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.nvr-data-grid thead th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.nvr-data-grid tbody tr:hover {
  background: rgba(79, 140, 255, 0.06);
}

.nvr-col-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right;
}

.nvr-col-actions .nvr-row-action + .nvr-row-action {
  margin-left: 0.25rem;
}

.nvr-row-action.danger-action {
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.35);
}

.nvr-row-action.danger-action:hover:not(:disabled) {
  background: rgba(255, 107, 107, 0.12);
}

.nvr-pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: capitalize;
  border: 1px solid var(--border);
  background: rgba(18, 23, 34, 0.65);
}

.nvr-pill--online {
  color: var(--success);
  border-color: rgba(62, 207, 142, 0.45);
  background: rgba(62, 207, 142, 0.1);
}

.nvr-pill--degraded {
  color: #e6c84a;
  border-color: rgba(230, 200, 74, 0.45);
  background: rgba(230, 200, 74, 0.1);
}

.nvr-pill--offline {
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.45);
  background: rgba(255, 107, 107, 0.1);
}

.nvr-pill--unknown,
.nvr-pill--disabled {
  color: var(--muted);
}

.nvr-readonly-hint {
  margin-top: 0.35rem;
}

.camera-stream-status {
  margin: 0 0 0.5rem;
}

.camera-stream-video-wrap {
  border-radius: 8px;
  overflow: hidden;
  background: #0a0c10;
  aspect-ratio: 16 / 9;
  width: 100%;
  max-width: min(960px, 100%);
  margin: 0 auto;
}

.camera-stream-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.playback-controls-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 0.65rem;
  max-width: min(960px, 100%);
  margin-left: auto;
  margin-right: auto;
}

.playback-controls-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
}

.playback-btn-icon {
  width: 2.5rem;
  height: 2.5rem;
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: 0;
  flex-shrink: 0;
}

.playback-btn-icon .icon-svg,
.playback-ptz-btn .icon-svg {
  width: 1.25rem;
  height: 1.25rem;
  display: block;
}

.playback-btn-audio[disabled],
.playback-ptz-btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.playback-btn-audio--on {
  color: var(--accent, #4da3ff);
}

.playback-ptz {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.playback-ptz-label {
  flex-shrink: 0;
  min-width: 2.25rem;
  text-align: center;
}

.playback-ptz-grid {
  display: grid;
  grid-template-columns: repeat(3, 2.5rem);
  grid-template-rows: repeat(3, 2.5rem);
  grid-template-areas:
    '. up .'
    'left stop right'
    'zoom_in down zoom_out';
  gap: 0.25rem;
}

.playback-ptz-btn {
  width: 2.5rem;
  height: 2.5rem;
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: 0;
}

.playback-ptz-btn[data-ptz='up'] {
  grid-area: up;
}

.playback-ptz-btn[data-ptz='left'] {
  grid-area: left;
}

.playback-ptz-btn[data-ptz='stop'] {
  grid-area: stop;
}

.playback-ptz-btn[data-ptz='right'] {
  grid-area: right;
}

.playback-ptz-btn[data-ptz='down'] {
  grid-area: down;
}

.playback-ptz-btn[data-ptz='zoom_in'] {
  grid-area: zoom_in;
}

.playback-ptz-btn[data-ptz='zoom_out'] {
  grid-area: zoom_out;
}

.profile-wall-cell:fullscreen .playback-controls-bar {
  position: absolute;
  left: 0.75rem;
  right: 0.75rem;
  bottom: 0.75rem;
  z-index: 3;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  background: rgba(8, 10, 14, 0.82);
  margin: 0;
  max-width: none;
}

.profile-wall-cell:fullscreen {
  position: relative;
}

.profile-wall-cell:fullscreen .wall-video {
  width: 100%;
  height: 100%;
}

.nvr-dialog {
  max-width: min(520px, calc(100vw - 2rem));
  width: fit-content;
  padding: 0;
  border: none;
  background: transparent;
}

.nvr-dialog.profile-dialog-wide {
  max-width: min(920px, calc(100vw - 2rem));
}

#nvr-dialog {
  max-width: min(880px, calc(100vw - 2rem));
  width: min(880px, calc(100vw - 2rem));
}

#nvr-dialog .nvr-dialog-inner,
#nvr-dialog .stack-form,
#nvr-dialog .field-row,
#nvr-dialog .field,
#nvr-dialog .site-hierarchy-fieldset,
#nvr-dialog .nvr-validation-panel,
#nvr-dialog .nvr-cameras-panel {
  width: 100%;
}

#nvr-dialog .stack-form {
  align-items: stretch;
}

#nvr-dialog .field input:where(:not([type='checkbox']):not([type='radio']):not([type='hidden'])),
#nvr-dialog .field select,
#nvr-dialog .field textarea {
  width: 100%;
  min-width: 0;
}

.nvr-dialog::backdrop {
  background: rgba(6, 8, 14, 0.72);
  backdrop-filter: blur(4px);
}

.nvr-dialog-inner {
  margin: 0;
  max-height: calc(100vh - 2rem);
  overflow: auto;
}

.nvr-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

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

.nvr-validation-panel {
  margin: 0.5rem 0;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(12, 15, 22, 0.55);
}

.nvr-validation-pre {
  margin: 0;
  max-height: 220px;
  overflow: auto;
  font-size: 0.78rem;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
}

.nvr-mgmt-open-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.nvr-mgmt-open-link:hover {
  color: var(--text);
}

.nvr-dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.btn.primary.nvr-save-blocked {
  opacity: 0.55;
  cursor: help;
}

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

/* Live profile wall — only when visible; a bare #view-live { display:flex } overrides [hidden] in some browsers. */
#view-live:not([hidden]) {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 9rem);
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

#profile-wall-card {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
  min-width: 0;
}

.live-wall-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  margin: 0.75rem 0 0.35rem;
}

.playback-wall-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.65rem;
  margin: 0.75rem 0 0.35rem;
}

.playback-wall-toolbar .live-wall-toolbar {
  margin: 0;
}

.playback-wall-toolbar .playback-time-field {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 10.5rem;
}

.playback-wall-toolbar .playback-nvr-field,
.playback-wall-toolbar .playback-camera-field,
.playback-wall-toolbar .playback-totp-field {
  min-width: min(100%, 14rem);
}

.playback-wall-toolbar .playback-nvr-field .live-camera-select,
.playback-wall-toolbar .playback-camera-field .live-camera-select {
  width: 100%;
  min-width: 12rem;
}

.playback-single-view {
  margin-top: 0.75rem;
  min-height: 0;
  flex: 1;
  min-width: 0;
  align-self: stretch;
}

.playback-single-cell {
  max-width: 100%;
  min-height: min(72vh, 52rem);
}

.playback-single-cell .playback-single-video {
  min-height: min(68vh, 48rem);
  max-height: min(68vh, 48rem);
}

.playback-datetime {
  font: inherit;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

#btn-playback-download.icon-btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

.live-wall-paginator {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.25rem;
  margin: 0;
  padding-left: 0.5rem;
  border-left: 1px solid var(--border);
}

.live-wall-page-numbers {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.live-wall-page-num {
  min-width: 2rem;
  height: var(--control-height);
  padding: 0 0.45rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(12, 15, 22, 0.65);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.live-wall-page-num:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.live-wall-page-num[aria-current='page'] {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent);
  cursor: default;
}

.live-wall-page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.live-camera-field {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
}

.live-camera-select {
  box-sizing: border-box;
  width: auto;
  max-width: 100%;
  min-width: min(100%, 12rem);
  height: var(--control-height);
  padding: 0 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(12, 15, 22, 0.65);
  color: var(--text);
  font: inherit;
}

.live-video {
  display: block;
  width: 100%;
  max-height: 70vh;
  background: #000;
}

/* Dashboard header + menu */
.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.header-top-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: var(--control-height);
  height: var(--control-height);
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(18, 23, 34, 0.85);
  color: var(--text);
  cursor: pointer;
}

.menu-toggle:hover {
  color: var(--accent);
  border-color: rgba(79, 140, 255, 0.45);
}

.menu-toggle-icon {
  width: 1.35rem;
  height: 1.35rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.main-menu {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.75rem 0 0;
  padding: 0;
}

@media (max-width: 719px) {
  .menu-toggle {
    display: inline-flex;
  }

  .main-menu {
    display: none;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 0.25rem;
    margin-top: 0.5rem;
    padding: 0.5rem 0.65rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(26, 31, 46, 0.98);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  }

  .main-menu.is-open {
    display: flex;
  }

  .nav-tab {
    width: 100%;
    text-align: left;
    justify-content: flex-start;
  }
}

@media (min-width: 720px) {
  .main-menu {
    display: flex !important;
  }
}

.nav-tab {
  font: inherit;
  font-size: 0.88rem;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control-height);
  padding: 0 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(18, 23, 34, 0.85);
  color: var(--muted);
  cursor: pointer;
}

.nav-tab:hover {
  color: var(--text);
}

.nav-tab.active {
  color: var(--accent);
  border-color: rgba(79, 140, 255, 0.45);
  font-weight: 600;
}

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

.view-panel {
  padding-top: 0.25rem;
}

/* Ensure programmatic `hidden` always hides panels (author display:* must not beat the attribute). */
.view-panel[hidden] {
  display: none !important;
}

.view-panel > h2 {
  margin-top: 0;
}

.page-login .login-shell {
  max-width: 420px;
  margin: 0 auto;
}

.page-login .login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.page-login .login-brand .brand-logo {
  object-position: center center;
}

.page-login .login-card .tagline {
  margin: 0 0 1rem;
  padding: 0;
  text-align: center;
  width: 100%;
}

.totp-status-block {
  margin-top: 0.75rem;
}

.btn.danger-outline {
  border-color: rgba(255, 107, 107, 0.55);
  color: var(--danger);
  background: rgba(255, 107, 107, 0.08);
}

.btn.danger-outline:hover {
  background: rgba(255, 107, 107, 0.15);
}

.toolbar-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.75rem;
}

.tight-field {
  margin: 0;
  min-width: 140px;
}

.small-btn {
  font-size: 0.78rem;
  min-height: var(--control-height);
  padding: 0 0.45rem;
}

.ops-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.ops-card h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.ops-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}

.ops-card > :where(button.btn, a.btn) {
  text-align: center;
}

.audit-pre {
  margin: 0.5rem 0 0;
  max-height: 220px;
  overflow: auto;
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
  background: rgba(12, 15, 22, 0.55);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
}

.maps-list {
  margin: 0;
  padding-left: 1.2rem;
}

.maps-list li {
  margin: 0.35rem 0;
}

.nvr-cameras-panel {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
}

.nvr-cameras-heading {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.nvr-cameras-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.5rem 0;
}

/* Hidden by default; JS toggles .is-busy (avoids display:flex beating the hidden attribute). */
.nvr-discover-progress {
  display: none;
  align-items: center;
  gap: 0.65rem;
  margin: 0.5rem 0 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  background: rgba(77, 163, 255, 0.08);
  border: 1px solid rgba(77, 163, 255, 0.25);
  color: var(--text, #e8ecf1);
  font-size: 0.875rem;
}

.nvr-discover-progress.is-busy {
  display: flex;
}

.nvr-discover-spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent, #4da3ff);
  border-radius: 50%;
  animation: nvr-discover-spin 0.75s linear infinite;
  flex-shrink: 0;
}

@keyframes nvr-discover-spin {
  to {
    transform: rotate(360deg);
  }
}

#nvr-db-cameras-table .small {
  font-size: 0.72rem;
}

.profile-wall-grid {
  margin-top: 0.75rem;
  min-height: 0;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: auto;
  align-self: stretch;
}

.profile-wall-cell {
  background: rgba(12, 15, 22, 0.45);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.profile-wall-cell--camera {
  display: flex;
  flex-direction: column;
}

.profile-wall-cell--camera:fullscreen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  padding: 0.75rem;
  border: 0;
  border-radius: 0;
  background: #000;
  cursor: default;
}

.wall-cell-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.wall-video {
  width: 100%;
  flex: 1;
  min-height: 8rem;
  max-height: none;
  background: #000;
  border-radius: 4px;
  object-fit: contain;
}

.profile-wall-cell--camera:fullscreen .wall-video {
  flex: 1;
  max-height: none;
  min-height: 0;
  object-fit: contain;
}

.wall-video:fullscreen,
.wall-video:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  object-fit: contain;
  background: #000;
}

.wall-empty {
  padding: 2rem 0.5rem;
  text-align: center;
}

.profile-dialog-wide .nvr-dialog-inner {
  max-width: min(920px, 96vw);
}

.profile-tiles-grid .profile-tile-num {
  width: 1%;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

#profile-nvr-fieldset {
  width: 100%;
}

#profile-nvr-fieldset > .muted {
  margin: 0 0 0.5rem;
}

.profile-nvr-checkboxes {
  margin-bottom: 0.25rem;
}

.profile-camera-sources-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  margin-top: 0.5rem;
}

.profile-tiles-grid .profile-tile-q-cell,
.profile-tiles-grid .profile-tile-sv-cell {
  width: 1%;
  white-space: nowrap;
}

.profile-tile-quality-label {
  display: inline-block;
  color: var(--text);
  font-size: 0.92em;
}

.profile-tiles-grid .profile-tile-cam {
  width: 100%;
  max-width: 100%;
  min-width: 6rem;
}

.profile-tiles-grid .profile-tile-cam-cell {
  min-width: 12rem;
}

.site-hierarchy-fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  margin: 0.5rem 0;
}

.profiles-admin {
  margin-bottom: 1rem;
}

.roles-permissions-grid {
  min-width: 56rem;
}

.roles-permissions-grid .role-matrix-sticky {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface, #151922);
}

.roles-permissions-grid thead .role-matrix-sticky {
  z-index: 2;
}

.roles-permissions-grid .role-perm-cat-head {
  text-align: center;
  font-size: 0.72rem;
  border-bottom: none;
  padding-bottom: 0.25rem;
}

.roles-permissions-grid .role-perm-col {
  text-align: center;
  font-size: 0.68rem;
  line-height: 1.2;
  white-space: normal;
  min-width: 2.6rem;
  max-width: 4rem;
  vertical-align: bottom;
  padding: 0.35rem 0.25rem;
}

.roles-permissions-grid .role-perm-cell {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 0.45rem 0.25rem;
}

.roles-permissions-grid .role-perm-cell--on {
  color: var(--success);
  font-weight: 650;
}

.role-name-cell strong {
  display: block;
  margin-bottom: 0.2rem;
}

.role-id-code {
  font-size: 0.75rem;
  color: var(--muted, #888);
}

.role-permissions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.role-perms-all {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.role-perms-category-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted, #888);
  margin-bottom: 0.25rem;
}

.role-perms-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.85rem;
  line-height: 1.45;
}

.role-perms-list li + li {
  margin-top: 0.15rem;
}

.role-dialog .nvr-dialog-inner {
  max-width: 36rem;
  width: min(96vw, 36rem);
}

.role-permissions-editor-host {
  max-height: min(60vh, 28rem);
  overflow: auto;
  margin-top: 0.35rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2, rgba(0, 0, 0, 0.15));
}

.role-perms-fieldset {
  border: none;
  margin: 0 0 0.75rem;
  padding: 0;
}

.role-perms-fieldset:last-child {
  margin-bottom: 0;
}

.role-perms-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.role-perm-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.88rem;
  line-height: 1.35;
  cursor: pointer;
}

.role-perm-checkbox input {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.dashboard-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.kpi-card-title {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.kpi-card-value {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.3;
}

.kpi-card-sub {
  margin: 0.35rem 0 0;
  font-size: 0.72rem;
  line-height: 1.35;
  word-break: break-word;
}

.kpi-updated {
  margin-top: 0.75rem;
}

.app-toast {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 10000;
  max-width: min(92vw, 36rem);
  padding: 0.65rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(26, 31, 46, 0.96);
  color: var(--text);
  font-size: 0.9rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.app-toast--error {
  border-color: rgba(255, 107, 107, 0.45);
  color: #ffd4d4;
}

.app-toast--success {
  border-color: rgba(62, 207, 142, 0.45);
  color: #c8f5e0;
}

.app-confirm-dialog {
  max-width: min(92vw, 28rem);
}

.app-confirm-message {
  margin: 0 0 1rem;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn:focus-visible,
.nav-tab:focus-visible,
.icon-btn:focus-visible,
.menu-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

body.page-tv .nav-tab,
body.page-tv .btn {
  min-height: 48px;
  font-size: 1rem;
}

body.page-tv .profile-wall-grid {
  --wall-tile-fixed: 280px;
}

body.page-kiosk .header-actions,
body.page-tv .header-actions .btn#btn-logout {
  opacity: 0.85;
}

.playback-export-download-link {
  display: inline-block;
  margin-top: 0.35rem;
  font-weight: 600;
  text-decoration: underline;
}

.playback-export-download-link[hidden] {
  display: none !important;
}
