:root {
  --bg: #0b1120;
  --bg-card: #111a2e;
  --bg-elev: #17233b;
  --border: #24324d;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; margin: 2px 0 0; }

/* Buttons & Inputs */
button, input, select {
  font: inherit;
  color: inherit;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="date"],
input[type="time"],
select {
  background: #0d1526;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus {
  border-color: var(--accent);
}

.input-sm {
  padding: 6px 10px !important;
  font-size: 13px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  text-decoration: none;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent-strong); color: #fff; }
.btn-primary:hover { background: #0369a1; }
.btn-ghost { background: var(--bg-elev); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--accent); }
.btn-danger { background: rgba(239, 68, 68, 0.18); border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.3); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-xs { padding: 3px 8px; font-size: 12px; }
.btn-block { width: 100%; }

/* Alerts & Banners */
.alert {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 8px;
}
.alert-error { background: rgba(239, 68, 68, 0.14); border: 1px solid rgba(239, 68, 68, 0.4); color: #fecaca; }
.alert-ok { background: rgba(34, 197, 94, 0.14); border: 1px solid rgba(34, 197, 94, 0.4); color: #bbf7d0; }
.alert-warn { background: rgba(245, 158, 11, 0.14); border: 1px solid rgba(245, 158, 11, 0.4); color: #fde68a; }

.banner {
  background: rgba(245, 158, 11, 0.12);
  border-bottom: 1px solid rgba(245, 158, 11, 0.35);
  color: #fde68a;
  padding: 9px 16px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* Login Screen */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at top, #13213e 0%, #0b1120 65%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.brand-logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-header h1 { margin: 0; font-size: 19px; }
.subtitle { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }

.form-stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12.5px; color: var(--muted); }

.login-hint {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}
.login-hint code {
  background: #0d1526;
  padding: 2px 5px;
  border-radius: 4px;
  color: var(--accent);
}

/* Topbar */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-mini {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  display: grid;
  place-items: center;
  color: #fff;
}

.app-title { font-weight: 650; font-size: 15px; line-height: 1.2; }
.app-domain { font-size: 11.5px; color: var(--accent); }

.nav-tabs {
  display: flex;
  gap: 6px;
  background: #0d1526;
  padding: 4px;
  border-radius: 9px;
  border: 1px solid var(--border);
}

.nav-tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
}

.nav-tab.active {
  background: var(--bg-elev);
  color: #fff;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: #0d1526;
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.status-ok .dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status-warn .dot { background: var(--amber); }

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

/* Live View Toolbar & Grid */
.tab-panel {
  flex: 1;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  background: #0d1526;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
}

.segmented button {
  background: transparent;
  border: none;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--muted);
}

.segmented button.active {
  background: var(--accent-strong);
  color: #fff;
}

.pager {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.pager-text { font-size: 12.5px; color: var(--muted); min-width: 76px; text-align: center; }

.group-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.group-pill {
  background: #0d1526;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}
.group-pill:hover { border-color: var(--accent); color: var(--text); }
.group-pill.active { background: var(--accent-strong); border-color: var(--accent); color: #fff; font-weight: 600; }

.camera-grid {
  display: grid;
  gap: 10px;
  flex: 1;
}

.camera-grid.grid-1 { grid-template-columns: 1fr; }
.camera-grid.grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.camera-grid.grid-9 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.camera-grid.grid-16 { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.camera-grid.grid-16 .tile-top { padding: 4px 6px; }
.camera-grid.grid-16 .tile-name { font-size: 11.5px; }
.camera-grid.grid-16 .badge { font-size: 9.5px; padding: 1px 4px; }

.camera-grid.grid-36 { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
.camera-grid.grid-36 .tile-top { padding: 3px 5px; }
.camera-grid.grid-36 .tile-name { font-size: 10.5px; }
.camera-grid.grid-36 .tile-badges { display: none; }
.camera-grid.grid-36 .tile-overlay { font-size: 10.5px; padding: 6px; }

.camera-grid.grid-64 { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 3px; }
.camera-grid.grid-64 .cam-tile { border-radius: 5px; }
.camera-grid.grid-64 .tile-top { padding: 2px 4px; }
.camera-grid.grid-64 .tile-name { font-size: 9.5px; }
.camera-grid.grid-64 .tile-badges { display: none; }
.camera-grid.grid-64 .tile-overlay { font-size: 9.5px; padding: 4px; }
.camera-grid.grid-64 .tile-actions { bottom: 3px; right: 3px; }
.camera-grid.grid-64 .tile-actions .btn-xs { padding: 2px 5px; font-size: 10px; }

@media (max-width: 1280px) {
  .camera-grid.grid-64 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .camera-grid.grid-36 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
  .camera-grid.grid-9, .camera-grid.grid-16, .camera-grid.grid-36, .camera-grid.grid-64 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .camera-grid.grid-4, .camera-grid.grid-9, .camera-grid.grid-16, .camera-grid.grid-36, .camera-grid.grid-64 { grid-template-columns: 1fr; }
}

.cam-tile {
  position: relative;
  background: #050914;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  display: flex;
  flex-direction: column;
}

.cam-tile:hover { border-color: var(--accent); }

.cam-tile video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}

.tile-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 7px 10px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.78) 0%, transparent 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  z-index: 2;
  pointer-events: none;
}

.tile-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px #000;
}

.tile-badges { display: flex; gap: 4px; flex-shrink: 0; }

.badge {
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.25);
  color: #cbd5e1;
}
.badge-info { border-color: rgba(56, 189, 248, 0.5); color: #7dd3fc; }
.badge-rec { background: rgba(239, 68, 68, 0.85); border-color: #ef4444; color: #fff; font-weight: 600; }

.tile-actions {
  position: absolute;
  bottom: 8px; right: 8px;
  display: flex;
  gap: 5px;
  z-index: 3;
  opacity: 0;
  transition: opacity 0.15s;
}
.cam-tile:hover .tile-actions { opacity: 1; }

.tile-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px;
  text-align: center;
  background: rgba(5, 9, 20, 0.8);
  color: var(--muted);
  font-size: 12.5px;
  z-index: 1;
}

/* Panels & Settings */
.panel-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.panel-header h2 { margin: 0; font-size: 16px; }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.span-all { grid-column: 1 / -1; }
@media (max-width: 1024px) {
  .settings-grid { grid-template-columns: 1fr; }
}

.nvr-box {
  background: #0d1526;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

.nvr-form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
@media (max-width: 640px) { .nvr-form-grid { grid-template-columns: 1fr; } }

.nvr-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.storage-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.flex-2 { flex: 2; min-width: 240px; }

.preset-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.chip {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

.extra-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}
.extra-form .span-2 { grid-column: span 2; }
@media (max-width: 720px) {
  .extra-form { grid-template-columns: 1fr; }
  .extra-form .span-2 { grid-column: span 1; }
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

.table-wrap { overflow-x: auto; }
.max-h-table { max-height: 360px; overflow-y: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
th {
  color: var(--muted);
  font-weight: 500;
  background: #0d1526;
  position: sticky;
  top: 0;
}
td input[type="text"] { width: 100%; padding: 5px 8px; }

/* Playback */
.playback-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.field-btn { justify-content: flex-end; }

.playback-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px;
}
@media (max-width: 900px) { .playback-layout { grid-template-columns: 1fr; } }

.playback-player-wrap {
  background: #000;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.playback-player-wrap video {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
}
.playback-player-bar {
  padding: 10px 12px;
  background: #0d1526;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.playback-list-wrap {
  background: #0d1526;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  max-height: 440px;
}
.list-title {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
}
.segment-list {
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.seg-item {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
}
.seg-item:hover, .seg-item.active { border-color: var(--accent); background: #1e2d4d; }
.empty-state { padding: 18px; text-align: center; color: var(--muted); font-size: 13px; }

/* Fullscreen Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.88);
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-box {
  width: min(1280px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.modal-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.modal-video-wrap {
  position: relative;
  background: #000;
  aspect-ratio: 16 / 9;
  max-height: 78vh;
}
.modal-video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
