* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #0b1120;
  color: #e5e7eb;
}

.pv-splash-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #0f172a, #020617 65%);
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

.pv-splash-inner {
  text-align: center;
}

.pv-splash-logo {
  max-width: 260px;
  width: 60vw;
  height: auto;
  filter: drop-shadow(0 18px 45px rgba(15, 23, 42, 0.9));
}

.pv-splash-hide {
  opacity: 0;
  visibility: hidden;
}

.pv-login-box {
  margin: 1.75rem auto 0;
  width: 480px;
  max-width: 92vw;
  height: 240px;
  max-height: 260px;
  position: relative;
  background: radial-gradient(circle at top, #111827, #020617 65%);
  border-radius: 0.75rem;
  border: 1px solid rgba(250, 204, 21, 0.95);
  box-shadow:
    0 22px 50px rgba(0, 0, 0, 0.9),
    0 0 0 1px rgba(250, 250, 250, 0.06),
    0 0 32px rgba(250, 204, 21, 0.28);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  overflow: hidden;
  transition: opacity 0.35s ease, transform 0.35s ease, box-shadow 0.35s ease;
}

.pv-login-box::before {
  content: "";
  position: absolute;
  inset: 2px 2px auto 2px;
  height: 42%;
  border-radius: inherit;
  background: linear-gradient(
    to bottom,
    rgba(249, 250, 251, 0.16),
    rgba(15, 23, 42, 0.0)
  );
  opacity: 0.8;
  pointer-events: none;
}

.pv-login-box-hidden {
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
}

.pv-login-title {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: #facc15;
}

.pv-login-form {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.pv-login-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.pv-login-button-secondary {
  background: transparent;
  border: 1px solid #facc15;
  color: #facc15;
}

.pv-login-box .pv-field-group label {
  color: #f9fafb;
}

.pv-login-box .pv-field-group input {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: 0.375rem;
  border: 1px solid #facc15;
  background: #f9fafb;
  color: #111827;
}

.pv-login-box .pv-field-group input:focus {
  outline: 2px solid #facc15;
  outline-offset: 1px;
}

.pv-login-button {
  margin-top: 0.4rem;
  align-self: flex-end;
  padding: 0.5rem 1.4rem;
  border-radius: 999px;
  border: none;
  background: linear-gradient(to right, #facc15, #eab308);
  color: #000;
  font-weight: 600;
  cursor: pointer;
}

.pv-login-button:hover {
  filter: brightness(1.05);
}

.pv-skip-link {
  position: absolute;
  left: 0.5rem;
  top: -40px;
  padding: 0.4rem 0.8rem;
  background: #111827;
  color: #f9fafb;
  border-radius: 999px;
  text-decoration: none;
  z-index: 50;
}

.pv-skip-link:focus {
  top: 0.75rem;
}

.pv-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid #1f2937;
  backdrop-filter: blur(12px);
}

.pv-header-inner {
  max-width: 100%;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pv-brand {
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.9rem;
  color: #38bdf8;
}

.pv-nav a {
  color: #e5e7eb;
  text-decoration: none;
  margin-left: 1rem;
  font-size: 0.9rem;
}

.pv-nav a:hover {
  color: #38bdf8;
}

.pv-subnav {
  margin-top: 0.25rem;
  margin-bottom: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  font-size: 0.85rem;
}

.pv-subnav a {
  color: #cbd5f5;
  text-decoration: none;
}

.pv-subnav a:hover {
  color: #e5e7eb;
  text-decoration: underline;
}

.pv-main {
  max-width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
}

.pv-section {
  background: radial-gradient(circle at top left, #1d4ed8, #020617 55%);
  border-radius: 0.75rem;
  padding: 1.5rem;
  box-shadow: 0 20px 35px rgba(15, 23, 42, 0.8);
}

.pv-section h1 {
  margin-top: 0;
  margin-bottom: 0.75rem;
}

.pv-section.pv-admin {
  background: linear-gradient(135deg, #111827, #020617);
  padding: 1.75rem 1.75rem 1.5rem;
}

.pv-section.pv-dashboard {
  display: flex;
  flex-direction: column;
}

.pv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.pv-admin-grid {
  margin-top: 1.5rem;
}

.pv-dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 2fr);
  gap: 1.25rem;
  margin-top: 1.25rem;
}

.pv-card {
  background: rgba(15, 23, 42, 0.9);
  border-radius: 0.75rem;
  padding: 1rem 1.1rem;
  border: 1px solid #111827;
  display: block;
  text-decoration: none;
  color: #e5e7eb;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.pv-card:hover {
  border-color: #1d4ed8;
  background: rgba(15, 23, 42, 0.98);
  transform: translateY(-1px);
}

.pv-card-title {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}

.pv-card-wide {
  grid-column: span 1;
}

.pv-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
}

.pv-card-subtitle {
  font-size: 0.9rem;
  color: #9ca3af;
  margin: 0.2rem 0 0;
}

.pv-status-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
}

.pv-status-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0;
  font-size: 0.9rem;
}

.pv-badge {
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.pv-badge-ok {
  background: rgba(22, 163, 74, 0.15);
  color: #4ade80;
}

.pv-badge-error {
  background: rgba(248, 113, 113, 0.18);
  color: #fecaca;
}

.pv-badge-not_configured {
  background: rgba(148, 163, 184, 0.15);
  color: #cbd5f5;
}

.pv-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font-size: 0.75rem;
  background: rgba(56, 189, 248, 0.16);
  color: #e0f2fe;
}

.pv-chip-small {
  padding: 0.1rem 0.5rem;
}

.pv-chip-ok {
  background: rgba(22, 163, 74, 0.18);
  color: #bbf7d0;
}

.pv-chip-warn {
  background: rgba(234, 179, 8, 0.18);
  color: #fef9c3;
}

.pv-link-muted {
  font-size: 0.85rem;
  color: #9ca3af;
  text-decoration: none;
}

.pv-link-muted:hover {
  color: #e5e7eb;
}

.pv-camera-grid {
  margin-top: 0.75rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
}

.pv-camera-grid.pv-layout-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.pv-camera-grid.pv-layout-8 {
  grid-template-columns: repeat(8, minmax(0, 1fr));
}

.pv-camera-grid.pv-layout-16 {
  grid-template-columns: repeat(16, minmax(0, 1fr));
}

.pv-camera-tile {
  border-radius: 0.75rem;
  padding: 0.7rem 0.8rem;
  background: radial-gradient(circle at top left, #1d4ed8, #020617 80%);
  border: 1px solid rgba(30, 64, 175, 0.9);
}

.pv-camera-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
}

.pv-camera-title {
  font-weight: 500;
  font-size: 0.95rem;
}

.pv-camera-meta {
  font-size: 0.8rem;
  color: #e5e7eb;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  margin-bottom: 0.4rem;
}

.pv-camera-model {
  color: #cbd5f5;
}

.pv-camera-preview {
  margin: 0.4rem 0;
  border-radius: 0.6rem;
  overflow: hidden;
  background: radial-gradient(circle at top, #0f172a, #020617 70%);
}

.pv-camera-live {
  display: block;
  width: 100%;
  max-height: 160px;
  object-fit: cover;
}

.pv-camera-preview-large .pv-camera-live,
.pv-camera-live-large {
  max-height: none;
  height: auto;
}

/* Session view explicit display sizes (approximate the requested resolutions). */
.pv-session-size-320x240 {
  width: 320px;
  max-width: 100%;
  aspect-ratio: 4 / 3;
}

.pv-session-size-720x240 {
  width: 720px;
  max-width: 100%;
  aspect-ratio: 3 / 1;
}

.pv-session-size-720x480 {
  width: 720px;
  max-width: 100%;
  aspect-ratio: 3 / 2;
}

.pv-session-size-800x600 {
  width: 800px;
  max-width: 100%;
  aspect-ratio: 4 / 3;
}

.pv-session-size-1024x768 {
  width: 1024px;
  max-width: 100%;
  aspect-ratio: 4 / 3;
}

.pv-session-size-1280x720 {
  width: 1280px;
  max-width: 100%;
  aspect-ratio: 16 / 9;
}

.pv-session-size-1920x1080 {
  width: 1920px;
  max-width: 100%;
  aspect-ratio: 16 / 9;
}

/* Dashboard preview aspect ratios; grid width controls actual pixel size. */
.pv-dashboard-size-320x240 .pv-camera-live {
  aspect-ratio: 4 / 3;
}

.pv-dashboard-size-720x480 .pv-camera-live {
  aspect-ratio: 3 / 2;
}

/* Live session layout: scrollable left pane and narrow right faces bar */
.pv-session-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 100px;
  gap: 1rem;
  margin-top: 1rem;
  align-items: stretch;
}

.pv-session-left {
  max-height: calc(100vh - 260px);
  overflow-y: auto;
}

.pv-session-faces-bar {
  width: 100px;
  max-width: 100px;
  display: flex;
  flex-direction: column;
  font-size: 0.75rem;
}

.pv-session-faces-list {
  margin-top: 0.25rem;
  overflow-y: auto;
  max-height: calc(100vh - 260px);
}

.pv-session-face-tile {
  margin-bottom: 0.4rem;
  text-align: center;
}

.pv-session-face-img {
  width: 80px;
  height: 80px;
  border-radius: 0.5rem;
  object-fit: cover;
  display: block;
  margin: 0 auto 0.15rem;
}

.pv-session-face-assign {
  display: inline-block;
  font-size: 0.7rem;
  margin-top: 0.05rem;
}

.pv-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.8);
}

.pv-modal.is-visible {
  display: flex;
}

.pv-modal-dialog {
  background: rgba(15, 23, 42, 0.98);
  border-radius: 0.75rem;
  border: 1px solid #1f2937;
  padding: 1rem 1.25rem;
  max-width: 360px;
  width: 90%;
}

.pv-camera-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
}

.pv-status-chip {
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  font-size: 0.75rem;
}

.pv-status-unknown {
  background: rgba(148, 163, 184, 0.16);
  color: #e5e7eb;
}

.pv-status-online {
  background: rgba(22, 163, 74, 0.24);
  color: #bbf7d0;
}

.pv-status-offline {
  background: rgba(248, 113, 113, 0.22);
  color: #fecaca;
}

.pv-camera-status-block {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.pv-camera-lastseen {
  font-size: 0.7rem;
  color: #9ca3af;
}

.pv-dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.pv-layout-switcher {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
}

.pv-layout-button {
  border-radius: 999px;
  border: 1px solid #1f2937;
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
  padding: 0.25rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
}

.pv-layout-button.is-active {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.18);
}

.pv-dashboard-shell {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  /* Constrain overall height so camera wall can scroll above a compact status bar */
  max-height: calc(100vh - 220px);
}

.pv-camera-wall {
  flex: 1 1 auto;
  overflow: auto;
  padding-right: 0.25rem;
}

.pv-status-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.25rem 0.75rem;
  border-radius: 0.75rem;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid #111827;
  height: 50px;
  max-height: 50px;
  font-size: 0.8rem;
}

.pv-status-section {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pv-status-section + .pv-status-section {
  border-left: 1px solid #111827;
  padding-left: 0.75rem;
}

.pv-status-label {
  font-weight: 500;
  color: #e5e7eb;
  margin-right: 0.25rem;
}

.pv-status-kv {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
}

.pv-status-manage-link {
  margin-left: 0.5rem;
}

.pv-form {
  margin-top: 1.5rem;
  display: grid;
  gap: 1rem;
}

/* Admin forms: use more horizontal space with a responsive two-column layout. */
.pv-form-admin-user {
  max-width: 1100px;
  margin-top: 1.75rem;
  margin-left: auto;
  margin-right: auto;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 1.75rem;
  row-gap: 1.1rem;
  align-items: flex-start;
}

.pv-form-admin-user .pv-field-group {
  min-width: 0;
}

/* Fields that should span full width, like multi-selects and role groups. */
.pv-form-full-row {
  grid-column: 1 / -1;
}

.pv-field-group label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
}

.pv-field-group input {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border-radius: 0.375rem;
  border: 1px solid #1f2937;
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
}

.pv-field-group input:focus {
  outline: 2px solid #38bdf8;
  outline-offset: 1px;
}

/* Match select styling to inputs for a more cohesive look. */
.pv-field-group select,
.pv-field-group textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border-radius: 0.375rem;
  border: 1px solid #1f2937;
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
}

.pv-field-group select:focus,
.pv-field-group textarea:focus {
  outline: 2px solid #38bdf8;
  outline-offset: 1px;
}

/* Roles checkboxes in a neat vertical stack. */
.pv-form-admin-user fieldset {
  border: 1px solid #1f2937;
  border-radius: 0.5rem;
  padding: 0.75rem 0.9rem 0.85rem;
}

.pv-form-admin-user fieldset legend {
  padding: 0 0.25rem;
  font-size: 0.9rem;
  color: #e5e7eb;
}

.pv-checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  margin-top: 0.35rem;
}

.pv-checkbox-label input[type='checkbox'] {
  width: 1rem;
  height: 1rem;
}

.pv-form-actions {
  grid-column: 1 / -1;
  margin-top: 0.5rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  align-items: center;
}

/* Shared button styles used across the app. */
.pv-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  border: 1px solid #1f2937;
  background: rgba(15, 23, 42, 0.95);
  color: #e5e7eb;
  font-size: 0.9rem;
  text-decoration: none;
  cursor: pointer;
}

.pv-button:hover {
  border-color: #1d4ed8;
  background: rgba(30, 64, 175, 0.95);
}

.pv-button-small {
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
}

.pv-button-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  border: 1px solid #38bdf8;
  background: transparent;
  color: #e0f2fe;
  font-size: 0.9rem;
  text-decoration: none;
  cursor: pointer;
}

.pv-button-secondary:hover {
  background: rgba(56, 189, 248, 0.15);
}

.pv-button-primary {
  margin-top: 0.5rem;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  border: none;
  background: linear-gradient(to right, #22c55e, #16a34a);
  color: #022c22;
  font-weight: 600;
  cursor: pointer;
}

.pv-button-primary:hover {
  filter: brightness(1.05);
}

.pv-alert {
  padding: 0.75rem 0.9rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.pv-alert-success {
  background: rgba(22, 163, 74, 0.18);
  border: 1px solid rgba(22, 163, 74, 0.7);
}

.pv-alert-error {
  background: rgba(220, 38, 38, 0.18);
  border: 1px solid rgba(248, 113, 113, 0.7);
}

.pv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.pv-table th,
.pv-table td {
  border-bottom: 1px solid #1f2937;
  padding: 0.4rem 0.5rem;
  text-align: left;
}

.pv-table th {
  font-weight: 500;
  color: #9ca3af;
}

.pv-table tr:nth-child(even) {
  background-color: rgba(15, 23, 42, 0.6);
}

@media (max-width: 768px) {
  .pv-form-admin-user {
    grid-template-columns: minmax(0, 1fr);
  }

  .pv-main {
    padding: 1.25rem 0.75rem 2.5rem;
  }

  .pv-section {
    padding: 1.1rem;
  }

  .pv-header-inner {
    padding: 0.6rem 0.75rem;
  }

  .pv-dashboard-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .pv-card-wide {
    grid-column: auto;
  }

  .pv-camera-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }
}

@media (max-width: 640px) {
  .pv-header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .pv-nav a {
    margin-left: 0;
    margin-right: 0.75rem;
    font-size: 0.85rem;
  }

  .pv-camera-live {
    max-height: 140px;
  }

  .pv-camera-preview-large .pv-camera-live,
  .pv-camera-live-large {
    max-height: none;
  }

  .pv-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}
