:root {
  --bg: #07111f;
  --bg-soft: #0d1b2a;
  --panel: rgba(18, 31, 48, 0.92);
  --panel-alt: rgba(13, 27, 42, 0.96);
  --line: rgba(149, 174, 197, 0.14);
  --text: #ebf3ff;
  --muted: #8aa2bf;
  --primary: #5ac8fa;
  --primary-strong: #3eb8ff;
  --success: #38d39f;
  --warning: #f5b95f;
  --danger: #ff6b6b;
  --violet: #8f7cff;
  --shadow: 0 18px 36px rgba(5, 10, 18, 0.45);
}

html[data-theme="light"] {
  --bg: #eef2f8;
  --bg-soft: #e4eaf3;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-alt: rgba(255, 255, 255, 0.94);
  --line: rgba(20, 40, 70, 0.12);
  --text: #101826;
  --muted: #5c6a80;
  --shadow: 0 18px 36px rgba(30, 45, 70, 0.1);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: 'Inter', sans-serif;
  background:
    radial-gradient(circle at top left, rgba(90, 200, 250, 0.16), transparent 28%),
    linear-gradient(135deg, #050d18 0%, #0a1220 50%, #07111f 100%);
  color: var(--text);
}

body {
  min-height: 100vh;
}

html[data-theme="light"] body {
  background:
    radial-gradient(circle at top left, rgba(90, 200, 250, 0.14), transparent 28%),
    linear-gradient(135deg, #f4f7fc 0%, #e9eef7 50%, #eef2f8 100%);
}

button {
  font: inherit;
}

.app-shell {
  max-width: 1440px;
  margin: 0 auto;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  padding: 24px;
}

.app-shell[hidden] {
  display: none;
}

.sidebar,
.panel,
.hero {
  background: rgba(15, 25, 38, 0.86);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.sidebar {
  border-radius: 28px;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: sticky;
  top: 24px;
  height: calc(100vh - 48px);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 8px 20px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  color: #07111f;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.brand h1,
.topbar h2,
.hero-copy h3,
.panel-header h3 {
  margin: 0;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.nav-item {
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  border-radius: 12px;
  text-align: left;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  text-decoration: none;
  transition: 0.2s ease;
}

.nav-item[hidden] {
  display: none;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(90, 200, 250, 0.08);
  border-color: rgba(90, 200, 250, 0.2);
}

.sidebar-bottom {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-card {
  margin-top: 26px;
  background: rgba(9, 16, 25, 0.8);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px 14px;
}

.sidebar-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1.25rem;
}

.sidebar-card small,
.muted {
  color: var(--muted);
}

.status-bar {
  width: 100%;
  height: 8px;
  margin: 14px 0 8px;
  background: rgba(255,255,255,0.08);
  border-radius: 999px;
  overflow: hidden;
}

.status-fill {
  display: block;
  height: 100%;
  width: 88%;
  background: linear-gradient(90deg, var(--success), #96f0ca);
}

.content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 10px 4px 0;
}

.topbar-actions,
.hero-actions,
.filter-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.primary-btn,
.ghost-btn,
.filter-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 16px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.2s ease;
}

.primary-btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: #06131d;
  font-weight: 700;
}

.ghost-btn,
.filter-btn {
  background: rgba(255,255,255,0.02);
  color: var(--text);
  border-color: var(--line);
}

.primary-btn:hover,
.ghost-btn:hover,
.filter-btn:hover {
  transform: translateY(-1px);
}

.hero {
  display: grid;
  grid-template-columns: 1.3fr 0.7fr;
  border-radius: 28px;
  overflow: hidden;
}

.hero-copy {
  padding: 30px 30px 28px;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(90, 200, 250, 0.1);
  border: 1px solid rgba(90, 200, 250, 0.22);
  color: var(--primary);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero-copy h3 {
  margin-top: 18px;
  font-size: clamp(2rem, 2.4vw, 3rem);
  line-height: 1.08;
}

.hero-copy p {
  margin: 18px 0 22px;
  color: var(--muted);
  max-width: 52ch;
  line-height: 1.7;
}

.hero-panel {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(90,200,250,0.1), rgba(143,124,255,0.12));
}

.panel-circle {
  width: min(240px, 70%);
  aspect-ratio: 1;
  padding: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at center, rgba(90,200,250,0.2), rgba(8,16,23,0.7));
  border: 1px solid rgba(90,200,250,0.28);
  display: grid;
  place-items: center;
}

.inner-circle {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  text-align: center;
  background: linear-gradient(135deg, rgba(9,18,28,0.9), rgba(30,53,72,0.9));
  border: 1px solid rgba(255,255,255,0.08);
}

.inner-circle span {
  display: block;
  font-size: 2.2rem;
  font-weight: 800;
}

.inner-circle small {
  display: block;
  color: var(--muted);
  margin-top: 8px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 18px;
}

.stat-card {
  padding: 20px 18px;
  border-radius: 22px;
  background: rgba(15, 25, 38, 0.86);
  border: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-card .metric {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-card h4 {
  margin: 0;
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-card strong {
  font-size: clamp(1.5rem, 1.5vw, 2rem);
}

.stat-badge {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
}

.dashboard-grid,
.bottom-grid {
  display: grid;
  grid-template-columns: 1.8fr 1fr;
  gap: 24px;
}

.panel {
  border-radius: 24px;
  padding: 22px 20px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 10px;
}

.panel-header.compact {
  align-items: flex-end;
}

.filter-btn.active {
  background: rgba(90, 200, 250, 0.1);
  border-color: rgba(90, 200, 250, 0.24);
  color: var(--primary);
}

.camera-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 16px;
}

.camera-card {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(9,17,26,0.92), rgba(14,22,35,0.96));
  border-radius: 18px;
  overflow: hidden;
}

.camera-viewport {
  height: 160px;
  position: relative;
  background:
    linear-gradient(135deg, rgba(90,200,250,0.12), rgba(15,23,34,0.7)),
    linear-gradient(0deg, rgba(0,0,0,0.28), rgba(0,0,0,0.28)),
    #0b1830;
}

.camera-viewport::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg,
    transparent 0,
    transparent 38px,
    rgba(255,255,255,0.04) 38px,
    rgba(255,255,255,0.04) 39px
  );
}

.camera-camera {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 3rem;
  opacity: 0.6;
}

.live-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.82rem;
}

video-stream {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

video-stream video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.fullscreen-btn {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 5;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.camera-viewport:hover .fullscreen-btn,
.fullscreen-btn:focus-visible {
  opacity: 1;
}

.fullscreen-btn:hover {
  transform: scale(1.08);
}

.camera-viewport:fullscreen {
  background: #000;
}

.camera-viewport:fullscreen video-stream video {
  object-fit: contain;
}

.camera-viewport:fullscreen .fullscreen-btn {
  opacity: 1;
}

.camera-meta {
  padding: 14px 14px 16px;
}

.camera-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.camera-name {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.camera-name strong {
  font-size: 1rem;
}

.camera-name small {
  color: var(--muted);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  background: var(--success);
  box-shadow: 0 0 12px rgba(56, 211, 159, 0.8);
}

.status-dot.alert {
  background: var(--warning);
  box-shadow: 0 0 12px rgba(245, 185, 95, 0.8);
}

.status-dot.offline {
  background: var(--danger);
  box-shadow: 0 0 12px rgba(255, 107, 107, 0.8);
}

.camera-stats {
  display: flex;
  justify-content: space-between;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.82rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge.neutral {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
  color: var(--text);
}

.badge.success {
  background: rgba(56, 211, 159, 0.12);
  color: var(--success);
}

.badge.warning {
  background: rgba(245, 185, 95, 0.12);
  color: var(--warning);
}

.badge.danger {
  background: rgba(255, 107, 107, 0.12);
  color: var(--danger);
}

.badge.violet {
  background: rgba(143, 124, 255, 0.14);
  color: var(--violet);
}

.event-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.event-item {
  display: block;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.02);
  border-radius: 16px;
  overflow: hidden;
  transition: border-color 0.2s ease;
}

.event-item[open] {
  border-color: rgba(90, 200, 250, 0.24);
}

.event-summary {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  list-style: none;
  color: var(--text);
  cursor: pointer;
  padding: 12px 14px;
}

.event-summary::-webkit-details-marker {
  display: none;
}

.event-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.event-title strong {
  font-size: 0.95rem;
}

.event-title span {
  color: var(--muted);
  font-size: 0.76rem;
}

.event-details {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 14px 16px;
}

.event-details-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
}

.event-detail-label {
  color: var(--muted);
}

.event-description {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.6;
}

.event-action {
  align-self: flex-start;
  padding: 8px 14px;
  font-size: 0.82rem;
}

.filter-group.compact {
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.filter-group.compact .filter-btn {
  padding: 7px 12px;
  font-size: 0.78rem;
}

.chart-wrap {
  height: 220px;
  padding-top: 14px;
}

.chart-bars {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  height: 100%;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: end;
  align-items: center;
  gap: 8px;
  height: 100%;
}

.bar {
  width: 100%;
  max-width: 44px;
  border-radius: 12px 12px 0 0;
  background: linear-gradient(180deg, var(--primary), var(--violet));
  box-shadow: inset 0 0 14px rgba(255,255,255,0.08);
}

.bar-col span {
  color: var(--muted);
  font-size: 0.8rem;
}

.task-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.02);
}

.task-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(90,200,250,0.08);
  color: var(--primary);
}

.task-content {
  flex: 1;
}

.task-content strong {
  display: block;
  margin-bottom: 4px;
}

.task-content span {
  color: var(--muted);
  font-size: 0.8rem;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding-bottom: 18px;
  }

  .stats-grid,
  .dashboard-grid,
  .bottom-grid,
  .hero {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 14px;
  }

  .camera-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .topbar-actions,
  .hero-actions,
  .panel-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* View switching */
[data-view-panel] {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

[data-view-panel][hidden] {
  display: none;
}

/* Pulse highlight (used to draw attention after navigation) */
@keyframes pulse-highlight {
  0%, 100% { box-shadow: var(--shadow); border-color: var(--line); }
  40% { box-shadow: 0 0 0 3px rgba(90, 200, 250, 0.35), var(--shadow); border-color: rgba(90, 200, 250, 0.5); }
}

.pulse-highlight {
  animation: pulse-highlight 1.6s ease;
}

/* Toasts */
.toast-stack {
  position: fixed;
  right: 24px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
}

.toast {
  min-width: 240px;
  max-width: 340px;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 0.86rem;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-success { border-color: rgba(56, 211, 159, 0.4); }
.toast-primary { border-color: rgba(90, 200, 250, 0.4); }
.toast-neutral { border-color: var(--line); }

.toast.flash {
  animation: toast-fade-out 4s ease forwards;
}

@keyframes toast-fade-out {
  0%, 80% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(12px); }
}

/* Settings */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}

.settings-block h4 {
  margin: 0 0 4px;
}

.settings-block .muted {
  margin: 0 0 14px;
  font-size: 0.82rem;
}

.toggle-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toggle-switch {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.2s ease, background 0.2s ease;
}

.toggle-switch input:checked + .toggle-track {
  background: rgba(90, 200, 250, 0.25);
  border-color: rgba(90, 200, 250, 0.4);
}

.toggle-switch input:checked + .toggle-track .toggle-thumb {
  transform: translateX(18px);
  background: var(--primary);
}

.toggle-label {
  font-size: 0.88rem;
}

/* Camera management */
.camera-add-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) auto;
  gap: 14px;
  align-items: end;
}

.camera-add-form .auth-field {
  text-align: left;
}

.camera-add-form input {
  font: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  width: 100%;
}

@media (max-width: 900px) {
  .camera-add-form {
    grid-template-columns: 1fr;
  }
}

/* Archive */
.archive-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.archive-item {
  display: grid;
  grid-template-columns: 1fr auto auto auto auto;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 14px;
  padding: 12px 14px;
}

.archive-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.archive-meta span {
  color: var(--muted);
  font-size: 0.78rem;
}

.archive-size {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

@media (max-width: 640px) {
  .archive-item {
    grid-template-columns: 1fr;
    justify-items: start;
  }
}

/* Auth */
.auth-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 2000;
  padding: 20px;
}

.auth-overlay[hidden] {
  display: none;
}

.auth-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}

.auth-card .brand-mark.large {
  width: 56px;
  height: 56px;
  margin: 0 auto 4px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.2rem;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  color: #06131d;
}

.auth-card h2 {
  margin: 0;
}

.auth-card > .muted {
  margin: 0 0 6px;
  font-size: 0.84rem;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  font-size: 0.84rem;
  color: var(--muted);
}

.auth-field input,
.auth-field select {
  font: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
}

.auth-field select option {
  background: var(--bg-soft);
  color: var(--text);
}

.auth-error {
  color: var(--danger);
  font-size: 0.82rem;
  margin: 0;
}

.auth-submit {
  margin-top: 6px;
}

.auth-hint {
  font-size: 0.74rem;
  margin: 4px 0 0;
}

.auth-hint code {
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 5px;
  border-radius: 6px;
}

/* User card */
.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.02);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(90, 200, 250, 0.12);
  color: var(--primary);
  font-weight: 700;
  font-size: 0.82rem;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.user-info strong {
  font-size: 0.86rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-btn {
  padding: 6px 10px;
  font-size: 0.76rem;
  flex-shrink: 0;
}
