:root {
  color-scheme: light;
  --bg: #eef6ff;
  --ink: #14243a;
  --muted: #627894;
  --panel: #ffffff;
  --panel-strong: #e2f0ff;
  --line: #c8dcf2;
  --teal: #1b73d1;
  --teal-dark: #1257a4;
  --coral: #c4493d;
  --coral-dark: #96362e;
  --gold: #d18912;
  --shadow: 0 16px 36px rgba(22, 72, 128, 0.14);
  --button-shadow: 0 7px 0 #0b407f, 0 14px 24px rgba(24, 87, 164, 0.24);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.app-shell {
  min-height: 100vh;
}

.login-panel {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-box {
  width: min(100%, 390px);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.brand-lock {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--teal);
}

.login-box h1,
.topbar h1,
.side-panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.login-box h1 {
  margin-top: 18px;
  margin-bottom: 22px;
  font-size: 1.55rem;
}

.login-box label,
.field span,
.mode-control legend {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.password-row {
  display: flex;
  gap: 8px;
}

.login-box > input {
  margin-bottom: 14px;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(27, 115, 209, 0.18);
}

.primary-button,
.danger-button,
.ghost-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.primary-button {
  padding: 0 22px;
  background: linear-gradient(180deg, #3596ff 0%, var(--teal) 58%, var(--teal-dark) 100%);
  color: white;
  font-weight: 800;
  box-shadow: var(--button-shadow);
  transform: translateY(0);
}

.primary-button:hover {
  background: linear-gradient(180deg, #4aa2ff 0%, #207edc 58%, #145cae 100%);
}

.primary-button:active {
  box-shadow: 0 3px 0 #0b407f, 0 8px 18px rgba(24, 87, 164, 0.22);
  transform: translateY(4px);
}

.danger-button {
  padding: 0 20px;
  background: linear-gradient(180deg, #f06b60 0%, var(--coral) 58%, var(--coral-dark) 100%);
  color: white;
  font-weight: 800;
  box-shadow: 0 7px 0 #77251f, 0 14px 24px rgba(150, 54, 46, 0.22);
}

.danger-button:hover {
  background: linear-gradient(180deg, #ff776b 0%, #d04c41 58%, #9f372f 100%);
}

.danger-button:active {
  box-shadow: 0 3px 0 #77251f, 0 8px 18px rgba(150, 54, 46, 0.2);
  transform: translateY(4px);
}

.ghost-button,
.icon-button {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fff 0%, #edf6ff 100%);
  color: var(--ink);
  box-shadow: 0 5px 0 #bfd7f0, 0 10px 18px rgba(22, 72, 128, 0.1);
}

.ghost-button {
  padding: 0 14px;
}

.icon-button {
  width: 42px;
  padding: 0;
}

.error-text {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--coral-dark);
  font-size: 0.92rem;
}

.login-box .primary-button {
  width: 100%;
  margin-top: 18px;
}

.workspace {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #e8f4ff 100%);
}

.topbar h1 {
  font-size: clamp(1.4rem, 2vw, 2rem);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.control-band {
  padding: 16px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
  background: var(--panel-strong);
}

.nvr-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 0;
}

.view-sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #f9fcff 0%, #e8f4ff 100%);
}

.sidebar-title {
  display: grid;
  gap: 3px;
  padding: 8px 4px;
}

.sidebar-title span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.sidebar-title strong {
  font-size: 1.08rem;
}

.view-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.view-button {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 13px;
  border: 1px solid #b8d7f7;
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  box-shadow: none;
}

.view-button:hover {
  border-color: #7ab5ee;
  background: #f5fbff;
}

.view-button span {
  font-weight: 850;
}

.view-button small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.view-button.active {
  border-color: var(--teal);
  background: #d9ecff;
  color: var(--teal-dark);
  box-shadow: inset 0 0 0 1px var(--teal);
}

.camera-panel {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 12px;
  padding: 16px clamp(16px, 3vw, 28px);
}

.camera-grid {
  display: grid;
  flex: 1;
  min-height: 0;
  gap: 12px;
}

.camera-grid.single-view {
  grid-template-columns: 1fr;
}

.camera-grid.all-view {
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  align-content: stretch;
}

.camera-tile {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111a1d;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.camera-grid.single-view .camera-tile {
  min-height: min(72vh, 760px);
}

.camera-grid.all-view .camera-tile {
  aspect-ratio: 16 / 9;
  min-height: 210px;
}

.camera-tile video {
  position: absolute;
  inset: 0;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: #c8d7dc;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    #111a1d;
  background-size: 32px 32px;
  text-align: center;
}

.camera-overlay p {
  max-width: min(92%, 520px);
  margin: 0;
  font-weight: 850;
}

.camera-overlay svg {
  width: 36px;
  height: 36px;
}

.camera-caption {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  display: flex;
  min-height: 34px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-radius: 999px;
  padding: 0 10px;
  background: rgba(12, 40, 72, 0.78);
  color: #fff;
  font-size: 0.86rem;
}

.camera-caption span {
  color: #c8d7dc;
  font-weight: 800;
}

.action-group {
  display: flex;
  gap: 10px;
}

.fullscreen-button {
  width: 34px;
  min-height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: linear-gradient(180deg, rgba(75, 162, 255, 0.92), rgba(27, 115, 209, 0.92));
  color: #fff;
  box-shadow: 0 4px 0 rgba(8, 48, 96, 0.8), 0 8px 14px rgba(0, 0, 0, 0.22);
}

.fullscreen-button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(8, 48, 96, 0.8), 0 5px 10px rgba(0, 0, 0, 0.18);
}

.camera-tile:fullscreen {
  width: 100vw;
  height: 100vh;
  border-radius: 0;
}

.camera-tile:fullscreen video {
  object-fit: contain;
}

.stream-form {
  display: grid;
  grid-template-columns: minmax(260px, 1.7fr) minmax(170px, 0.65fr) minmax(190px, auto) auto;
  gap: 14px;
  align-items: end;
}

.camera-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.camera-summary {
  display: grid;
  gap: 4px;
}

.camera-summary span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

.camera-summary strong {
  font-size: 1.05rem;
}

.field {
  min-width: 0;
}

.mode-control {
  min-width: 190px;
  margin: 0;
  padding: 0;
  border: 0;
}

.mode-control div {
  display: flex;
}

.mode-control label {
  display: inline-flex;
  align-items: center;
  position: relative;
}

.mode-control input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.mode-control span {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  border: 1px solid var(--line);
  padding: 0 13px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

.mode-control label:first-of-type span {
  border-radius: 8px 0 0 8px;
}

.mode-control label:last-of-type span {
  border-left: 0;
  border-radius: 0 8px 8px 0;
}

.mode-control input:checked + span {
  background: #d8f0f1;
  border-color: var(--teal);
  color: var(--teal-dark);
}

.content-grid {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
  gap: 18px;
  align-items: start;
  padding: 18px clamp(16px, 3vw, 32px) 28px;
}

.player-surface,
.side-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.player-surface {
  overflow: hidden;
}

.video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 280px;
  background: #111a1d;
}

video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #111a1d;
  pointer-events: none;
  user-select: none;
}

video::-webkit-media-controls,
video::-webkit-media-controls-enclosure,
video::-webkit-media-controls-panel,
video::-webkit-media-controls-play-button,
video::-webkit-media-controls-timeline,
video::-webkit-media-controls-current-time-display,
video::-webkit-media-controls-time-remaining-display,
video::-webkit-media-controls-mute-button,
video::-webkit-media-controls-volume-slider,
video::-webkit-media-controls-fullscreen-button {
  display: none !important;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: #c8d7dc;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    #111a1d;
  background-size: 32px 32px;
}

.empty-state svg {
  width: 42px;
  height: 42px;
}

.loading-ring {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(200, 215, 220, 0.24);
  border-top-color: #c8d7dc;
  border-radius: 999px;
  animation: spin 0.9s linear infinite;
}

.empty-state p {
  margin: 0;
  font-weight: 800;
}

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

.player-actions {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(239, 247, 255, 0.96);
  box-shadow: 0 8px 18px rgba(22, 72, 128, 0.08);
  backdrop-filter: blur(8px);
}

.status-pill {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--muted);
}

.status-pill.running .status-dot {
  background: var(--teal);
}

.status-pill.error .status-dot {
  background: var(--coral);
}

.status-pill.starting .status-dot {
  background: var(--gold);
}

.side-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-header h2 {
  font-size: 1.1rem;
}

.stream-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 80px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.stream-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.stream-name {
  overflow: hidden;
  margin: 0 0 4px;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

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

.stream-log {
  flex: 1;
  min-height: 130px;
  max-height: 260px;
  overflow: auto;
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 8px;
  background: #142025;
  color: #d5e4e8;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 0.78rem;
  white-space: pre-wrap;
}

[hidden] {
  display: none !important;
}

@media (max-width: 980px) {
  .stream-form,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .nvr-layout {
    grid-template-columns: 1fr;
  }

  .view-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .view-list {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .view-button {
    min-width: 132px;
  }

  .camera-grid.all-view {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }

  .stream-form .primary-button {
    width: 100%;
  }
}

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

  .camera-control,
  .topbar,
  .player-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .action-group {
    flex-direction: column;
  }

  .action-group button,
  .camera-control .primary-button,
  .topbar .ghost-button,
  .player-actions .danger-button {
    width: 100%;
  }

  .video-frame {
    min-height: 220px;
  }
}
