:root {
  color-scheme: dark;
  --header-height: 4.8rem;
  --app-bg: #07101d;
  --panel-bg: #0c1727;
  --panel-raised: #111f33;
  --panel-border: rgba(148, 163, 184, 0.14);
  --muted: #8fa2bb;
  --accent: #38bdf8;
  --online: #2dd4bf;
  --offline: #fb7185;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 8% -10%, rgba(14, 165, 233, 0.12), transparent 30rem),
    var(--app-bg);
  color: #e8eef7;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

button,
input,
select {
  touch-action: manipulation;
}

.app-header {
  position: sticky;
  z-index: 100;
  top: 0;
  background: rgba(7, 16, 29, 0.88);
  border-color: var(--panel-border) !important;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.brand-mark {
  display: grid;
  width: 2.6rem;
  height: 2.6rem;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgba(56, 189, 248, 0.28);
  border-radius: 0.8rem;
  background: linear-gradient(145deg, rgba(56, 189, 248, 0.22), rgba(45, 212, 191, 0.08));
  color: #7dd3fc;
  font-size: 1.2rem;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.12rem;
  color: var(--muted);
  font-size: 0.76rem;
}

.separator {
  color: #455873;
}

.btn-header,
.btn-camera {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.045);
  color: #bfccdc;
}

.btn-header {
  min-height: 2.4rem;
  gap: 0.45rem;
}

.btn-header:hover,
.btn-header:focus-visible,
.btn-camera:hover,
.btn-camera:focus-visible {
  border-color: rgba(56, 189, 248, 0.4);
  background: rgba(56, 189, 248, 0.1);
  color: #e0f2fe;
}

.btn-header.active {
  border-color: rgba(45, 212, 191, 0.4);
  background: rgba(45, 212, 191, 0.12);
  color: #5eead4;
}

.camera-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  max-width: 1600px;
  margin-inline: auto;
}

@media (min-width: 768px) {
  main {
    height: calc(100dvh - var(--header-height));
  }

  .camera-grid {
    height: 100%;
    grid-template-rows: repeat(2, minmax(0, 1fr));
  }

  .camera-card {
    display: flex;
    min-height: 0;
    flex-direction: column;
  }

  .stream-stage {
    min-height: 0;
    flex: 1;
    aspect-ratio: auto;
  }
}

.camera-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--panel-border);
  border-radius: 1rem;
  background: var(--panel-bg);
  box-shadow: 0 1rem 2.5rem rgba(0, 0, 0, 0.16);
}

.camera-toolbar {
  display: flex;
  min-height: 4.15rem;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0.7rem 0.65rem 1rem;
}

.camera-name {
  color: #f1f5f9;
  font-size: 0.95rem;
  font-weight: 650;
}

.camera-state {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.18rem;
  color: var(--muted);
  font-size: 0.72rem;
}

.status-dot {
  width: 0.45rem;
  height: 0.45rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #64748b;
}

.camera-card[data-state="loading"] .status-dot {
  background: #fbbf24;
  box-shadow: 0 0 0 0.2rem rgba(251, 191, 36, 0.1);
}

.camera-card[data-state="online"] .status-dot {
  background: var(--online);
  box-shadow: 0 0 0 0.2rem rgba(45, 212, 191, 0.1);
}

.camera-card[data-state="offline"] .status-dot {
  background: var(--offline);
  box-shadow: 0 0 0 0.2rem rgba(251, 113, 133, 0.1);
}

.btn-camera {
  width: 2.55rem;
  height: 2.55rem;
  padding: 0;
  border-radius: 0.72rem;
}

.stream-stage {
  position: relative;
  display: grid;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  place-items: center;
  background:
    linear-gradient(rgba(15, 23, 42, 0.25), rgba(2, 6, 23, 0.65)),
    repeating-linear-gradient(45deg, #080e18 0, #080e18 10px, #0a1220 10px, #0a1220 20px);
}

.camera-video,
.camera-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #02060c;
}

.camera-placeholder {
  display: flex;
  max-width: 25rem;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
  color: #c6d2e1;
  text-align: center;
}

.camera-placeholder > i {
  margin-bottom: 0.6rem;
  color: #53657d;
  font-size: 1.8rem;
}

.camera-placeholder strong {
  font-size: 0.88rem;
}

.camera-placeholder span {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.72rem;
}

.camera-loading {
  position: absolute;
  inset: auto auto 0.75rem 0.75rem;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.55rem;
  background: rgba(2, 6, 12, 0.76);
  color: #dce7f5;
  font-size: 0.72rem;
  backdrop-filter: blur(8px);
}

.camera-loading:not(.d-none) {
  display: flex;
}

.camera-card:fullscreen,
.camera-card:-webkit-full-screen {
  display: flex;
  width: 100vw;
  height: 100vh;
  flex-direction: column;
  border: 0;
  border-radius: 0;
  background: #000;
}

.camera-card:fullscreen .stream-stage,
.camera-card:-webkit-full-screen .stream-stage {
  flex: 1;
  aspect-ratio: auto;
}

.camera-card:fullscreen .camera-toolbar,
.camera-card:-webkit-full-screen .camera-toolbar {
  background: #07101d;
}

.modal-content {
  border: 1px solid var(--panel-border);
  background: #0d192a;
  box-shadow: 0 1.5rem 5rem rgba(0, 0, 0, 0.4);
}

.camera-setting {
  padding: 1rem;
  border: 1px solid var(--panel-border);
  border-radius: 0.85rem;
  background: rgba(255, 255, 255, 0.025);
}

.camera-setting-title {
  margin-bottom: 0.75rem;
  color: #dce7f5;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.form-control,
.form-select {
  min-height: 2.8rem;
  border-color: rgba(148, 163, 184, 0.18);
  background-color: #081321;
}

.form-control:focus,
.form-select:focus {
  border-color: rgba(56, 189, 248, 0.65);
  box-shadow: 0 0 0 0.2rem rgba(56, 189, 248, 0.12);
}

.min-width-0 {
  min-width: 0;
}

@media (max-width: 767.98px) {
  .camera-grid {
    grid-template-columns: 1fr;
  }

  .app-header .container-fluid {
    padding-top: max(0.75rem, env(safe-area-inset-top)) !important;
  }
}

@media (orientation: landscape) and (max-height: 600px) {
  :root {
    --header-height: 3.65rem;
  }

  .app-header .container-fluid {
    padding-block: 0.55rem !important;
  }

  .camera-grid {
    gap: 0.7rem;
  }

  .camera-toolbar {
    min-height: 3.35rem;
  }

  .btn-camera {
    width: 2.25rem;
    height: 2.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
