:root {
  --bg: #07111f;
  --bg-alt: #0d1728;
  --card: rgba(14, 24, 42, 0.7);
  --card-strong: rgba(10, 18, 34, 0.88);
  --stroke: rgba(148, 163, 184, 0.18);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --success: #16c784;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #38bdf8;
  --shadow: 0 20px 60px rgba(2, 6, 23, 0.45);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --transition: 180ms ease;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Manrope", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.12), transparent 22%),
    radial-gradient(circle at top right, rgba(34, 197, 94, 0.14), transparent 20%),
    linear-gradient(140deg, #020617 0%, #081120 52%, #0f172a 100%);
  color: var(--text);
}

body {
  overflow-x: hidden;
}

body.theme-light {
  --bg: #e5eefb;
  --bg-alt: #f8fafc;
  --card: rgba(255, 255, 255, 0.75);
  --card-strong: rgba(255, 255, 255, 0.95);
  --stroke: rgba(15, 23, 42, 0.08);
  --text: #0f172a;
  --muted: #475569;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  min-height: 100vh;
  padding: 20px;
}

.glass-card {
  background: var(--card);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}

.sidebar {
  border-radius: var(--radius-xl);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 20px;
  height: calc(100vh - 40px);
}

.brand-block,
.panel-header,
.topbar,
.status-row,
.operator-badge,
.dialog-actions,
.topbar-actions,
.camera-hud,
.scanner-controls,
.camera-toggles,
.box-progress__header,
.box-progress__meta,
.report-actions,
.inline-field,
.nav-chip {
  display: flex;
  align-items: center;
}

.brand-block {
  gap: 18px;
}

.brand-mark {
  width: 68px;
  height: 68px;
  border-radius: 22px;
  background: linear-gradient(145deg, rgba(56, 189, 248, 0.18), rgba(22, 199, 132, 0.14));
  border: 1px solid rgba(56, 189, 248, 0.24);
  display: grid;
  place-items: center;
}

.brand-mark__core {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--info), var(--success));
  box-shadow: 0 0 30px rgba(56, 189, 248, 0.32);
}

.eyebrow,
.section-caption {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 11px;
  color: var(--muted);
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1 {
  font-size: 1.5rem;
}

h2 {
  font-size: 1.7rem;
}

h3 {
  font-size: 1.12rem;
}

.muted {
  color: var(--muted);
}

.side-nav {
  display: grid;
  gap: 10px;
}

.nav-chip {
  width: 100%;
  justify-content: center;
  padding: 14px 16px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition), background var(--transition);
}

.nav-chip:hover,
.nav-chip.is-active {
  transform: translateY(-1px);
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.16), rgba(22, 199, 132, 0.12));
  border-color: rgba(56, 189, 248, 0.32);
}

.session-panel,
.status-list,
.dashboard-panel,
.bottom-grid,
.report-grid,
.settings-stack {
  display: grid;
  gap: 14px;
}

.operator-badge {
  gap: 12px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.24);
}

.status-row {
  justify-content: space-between;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
}

.status-row:last-child {
  border-bottom: 0;
}

.main-layout {
  display: grid;
  gap: 20px;
}

.topbar {
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  border-radius: var(--radius-xl);
}

.topbar-actions,
.panel-header__actions,
.camera-toggles,
.report-actions {
  gap: 12px;
  flex-wrap: wrap;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.stat-card {
  padding: 20px;
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: "";
  position: absolute;
  inset: auto -30px -30px auto;
  width: 120px;
  height: 120px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.14), transparent 60%);
}

.stat-card strong {
  display: block;
  margin: 12px 0 8px;
  font-size: clamp(1.6rem, 3vw, 2.3rem);
}

.stat-card__label {
  color: var(--muted);
  font-size: 0.92rem;
}

.stat-card--success {
  border-color: rgba(22, 199, 132, 0.3);
}

.stat-card--danger {
  border-color: rgba(239, 68, 68, 0.3);
}

.stat-card--warning {
  border-color: rgba(245, 158, 11, 0.3);
}

.stat-card--info {
  border-color: rgba(56, 189, 248, 0.3);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.9fr);
  gap: 20px;
}

.scanner-panel,
.history-card,
.report-card,
.list-card {
  border-radius: var(--radius-xl);
  padding: 20px;
}

.panel-header {
  justify-content: space-between;
  gap: 12px;
}

.scanner-controls {
  gap: 14px;
  margin: 18px 0;
  flex-wrap: wrap;
}

.field,
.range-field {
  display: grid;
  gap: 8px;
  flex: 1 1 180px;
}

.field span,
.range-field span {
  color: var(--muted);
  font-size: 0.88rem;
}

.field input,
.field select,
.range-field input {
  width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(15, 23, 42, 0.36);
  color: var(--text);
  padding: 14px 16px;
  border-radius: 14px;
  outline: none;
  transition: border-color var(--transition), background var(--transition);
}

body.theme-light .field input,
body.theme-light .field select,
body.theme-light .range-field input {
  background: rgba(255, 255, 255, 0.9);
}

.field input:focus,
.field select:focus,
.range-field input:focus {
  border-color: rgba(56, 189, 248, 0.34);
}

.camera-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
}

.camera-frame {
  position: relative;
  min-height: 540px;
  background: linear-gradient(160deg, rgba(2, 6, 23, 0.8), rgba(15, 23, 42, 0.92));
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.14);
}

#cameraVideo,
#overlayCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#cameraVideo {
  object-fit: cover;
  background: #020617;
}

#overlayCanvas {
  pointer-events: none;
}

.camera-hud {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.hud-pill,
.badge {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.18);
  font-size: 0.88rem;
}

.hud-pill strong {
  margin-left: 8px;
}

.camera-sidepanel {
  display: grid;
  gap: 16px;
  align-content: start;
}

.button {
  border: 0;
  border-radius: 16px;
  padding: 14px 18px;
  min-height: 52px;
  cursor: pointer;
  color: white;
  transition: transform var(--transition), opacity var(--transition), filter var(--transition);
}

.button:hover {
  transform: translateY(-1px);
  filter: brightness(1.02);
}

.button:active {
  transform: translateY(0);
}

.button--primary {
  background: linear-gradient(135deg, #0ea5e9, #14b8a6);
}

.button--secondary {
  background: linear-gradient(135deg, #1d4ed8, #2563eb);
}

.button--danger {
  background: linear-gradient(135deg, #dc2626, #ef4444);
}

.button--ghost {
  color: var(--text);
  background: rgba(148, 163, 184, 0.1);
  border: 1px solid rgba(148, 163, 184, 0.14);
}

.button--block {
  width: 100%;
}

.box-progress,
.summary-block {
  padding: 18px;
  border-radius: 20px;
  background: rgba(15, 23, 42, 0.32);
  border: 1px solid rgba(148, 163, 184, 0.1);
}

.progress-bar {
  height: 12px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  overflow: hidden;
  margin-top: 14px;
}

.progress-bar__value {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--info), var(--success));
  transition: width var(--transition);
}

.alert-stack,
.result-list,
.history-list {
  display: grid;
  gap: 10px;
}

.alert-chip,
.result-item,
.history-item {
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(15, 23, 42, 0.28);
}

.result-item,
.history-item {
  display: grid;
  gap: 6px;
}

.result-item__meta,
.history-item__meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.84rem;
}

.result-item--success {
  border-color: rgba(22, 199, 132, 0.32);
}

.result-item--danger {
  border-color: rgba(239, 68, 68, 0.32);
}

.result-item--warning {
  border-color: rgba(245, 158, 11, 0.32);
}

.result-list {
  max-height: 340px;
  overflow: auto;
}

.result-list--compact {
  max-height: 220px;
}

.bottom-grid {
  grid-template-columns: minmax(0, 1fr) minmax(340px, 0.92fr);
}

.report-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mini-list h4 {
  margin-bottom: 12px;
}

.badge--success {
  color: #bbf7d0;
}

.badge--danger {
  color: #fecaca;
}

.badge--warning {
  color: #fde68a;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
  background: var(--warning);
  box-shadow: 0 0 16px currentColor;
}

.status-dot--info {
  background: var(--info);
}

.text-info {
  color: #7dd3fc;
}

.text-success {
  color: #86efac;
}

.text-warning {
  color: #fde68a;
}

.text-danger {
  color: #fca5a5;
}

.auth-dialog {
  width: min(480px, calc(100vw - 24px));
  border: 0;
  border-radius: 28px;
  padding: 0;
  color: var(--text);
}

.auth-dialog::backdrop {
  background: rgba(2, 6, 23, 0.6);
  backdrop-filter: blur(10px);
}

.auth-dialog form {
  padding: 22px;
  display: grid;
  gap: 16px;
}

.dialog-actions {
  justify-content: flex-end;
  gap: 10px;
}

.empty-state {
  padding: 18px;
  border: 1px dashed rgba(148, 163, 184, 0.2);
  border-radius: 16px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 1420px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .content-grid,
  .bottom-grid,
  .camera-workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 12px;
    gap: 12px;
  }

  .topbar,
  .scanner-panel,
  .history-card,
  .report-card,
  .list-card,
  .sidebar {
    padding: 16px;
    border-radius: 22px;
  }

  .stats-grid,
  .report-grid {
    grid-template-columns: 1fr;
  }

  .camera-frame {
    min-height: 380px;
  }

  .button {
    width: 100%;
  }

  .topbar-actions,
  .panel-header,
  .scanner-controls,
  .camera-toggles,
  .report-actions,
  .inline-field,
  .camera-hud {
    align-items: stretch;
    flex-direction: column;
  }
}
