:root {
  color-scheme: dark;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.22), transparent 28%),
    radial-gradient(circle at top right, rgba(14, 165, 233, 0.14), transparent 24%),
    linear-gradient(180deg, #061120 0%, #0b1220 40%, #0f172a 100%);
  color: #e5edf8;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.22), transparent 28%),
    radial-gradient(circle at top right, rgba(14, 165, 233, 0.14), transparent 24%),
    linear-gradient(180deg, #061120 0%, #0b1220 40%, #0f172a 100%);
  color: #e5edf8;
}

button, input, select, textarea { font: inherit; }

.app-shell {
  max-width: 1680px;
  margin: 0 auto;
  padding: 32px 24px 48px;
}

.card {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.96), rgba(10, 17, 31, 0.96));
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 22px 55px rgba(2, 6, 23, 0.34);
  backdrop-filter: blur(12px);
}

.card-subtle {
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: rgba(15, 23, 42, 0.64);
  border-radius: 18px;
  padding: 16px;
}

.narrow {
  max-width: 500px;
  margin: 8vh auto 0;
}

.login-shell {
  text-align: left;
  padding: 30px;
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  margin-bottom: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #eff6ff;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  box-shadow: 0 16px 30px rgba(37, 99, 235, 0.26);
}

.eyebrow,
.section-label,
.stat-label {
  margin: 0;
  font-size: 12px;
  line-height: 1.2;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #7dd3fc;
  font-weight: 700;
}

h1, h2, h3, p { margin-top: 0; }
h1 {
  margin-bottom: 10px;
  font-size: clamp(2rem, 3vw, 2.6rem);
  line-height: 1.05;
}
h2 {
  margin: 6px 0 8px;
  font-size: clamp(1.5rem, 2.4vw, 2rem);
}
h3 {
  margin: 6px 0 0;
  font-size: 1.08rem;
}

.login-copy { margin-bottom: 18px; }

.login-highlights {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 20px;
}

.login-highlights span,
.user-list li {
  border: 1px solid rgba(125, 211, 252, 0.15);
  background: rgba(14, 165, 233, 0.08);
  color: #dbeafe;
  border-radius: 999px;
  padding: 8px 12px;
}

.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; }
.space-between { justify-content: space-between; }
.gap { gap: 12px; }
.wrap { flex-wrap: wrap; }
.grid { display: grid; gap: 18px; }
.three-col { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.toolbar-copy { min-width: 0; }
.toolbar-actions { justify-content: flex-end; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.stat-card {
  padding: 18px 20px;
}

.stat-value {
  display: block;
  margin-top: 8px;
  font-size: 1.65rem;
  line-height: 1;
  color: #f8fbff;
}

.scanner-layout {
  grid-template-columns: minmax(780px, 1.55fr) minmax(360px, 0.95fr);
  align-items: start;
}

.workspace-card,
.sidebar-card,
.admin-card {
  min-width: 0;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.section-head.compact {
  align-items: center;
}

.section-hint {
  max-width: 320px;
  margin-bottom: 0;
  text-align: right;
}

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: #cbd5e1;
  font-weight: 600;
}

input, select, button {
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  padding: 12px 14px;
  font-size: 14px;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease, background .18s ease;
}

input, select {
  background: rgba(8, 15, 29, 0.95);
  color: #f8fafc;
}

input::placeholder { color: #64748b; }

input:focus,
select:focus,
button:focus {
  outline: none;
  border-color: rgba(96, 165, 250, 0.75);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.18);
}

input[type="range"] {
  padding: 0;
  accent-color: #38bdf8;
}

button {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.22);
}

button.secondary {
  background: rgba(15, 23, 42, 0.92);
  color: #dbeafe;
  box-shadow: none;
}

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

.preview-stage {
  position: relative;
  width: 100%;
  min-height: 520px;
  aspect-ratio: 16 / 9;
  background: linear-gradient(180deg, rgba(2, 6, 23, 0.98), rgba(15, 23, 42, 0.92));
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  overflow: hidden;
}

video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transition: transform .15s ease;
}

#preview-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.action-cluster,
.action-toolbar {
  align-items: stretch;
}

.export-panel {
  display: grid;
  gap: 14px;
}

.export-grid {
  grid-template-columns: 1.2fr 1fr;
}

.status-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(8, 15, 29, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.12);
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 0 6px rgba(34, 197, 94, 0.14);
  flex: 0 0 auto;
}

#status { margin: 0; }

.pages {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 12px;
  max-height: 72vh;
  overflow: auto;
  padding: 4px;
}

.page-card {
  position: relative;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 16px;
  overflow: hidden;
  background: rgba(8, 15, 29, 0.9);
  padding: 0;
  text-align: left;
  min-height: 160px;
}

.page-card.selected {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

.page-card.export-selected {
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.28);
}

.page-card canvas {
  width: 100%;
  display: block;
}

.page-meta {
  padding: 8px 10px 10px;
  font-size: 11px;
  line-height: 1.3;
  color: #cbd5e1;
}

.page-select {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(2, 6, 23, 0.88);
  padding: 5px 7px;
  border-radius: 999px;
  font-size: 11px;
  backdrop-filter: blur(8px);
}

.page-select input {
  width: auto;
  margin: 0;
  padding: 0;
}

.enhance-panel {
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: rgba(8, 15, 29, 0.72);
  border-radius: 16px;
  padding: 14px;
}

.preview-panel { width: min(1180px, 96vw); }

#page-preview-image {
  display: block;
  max-width: 100%;
  max-height: 78vh;
  object-fit: contain;
  margin: 0 auto;
  background: #020617;
  border-radius: 16px;
}

.hidden { display: none; }
.muted { color: #93a4bb; }
.error { color: #fda4af; min-height: 20px; margin: 0; }
.helper-copy { margin-bottom: 0; }

.user-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.user-list li {
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(8, 15, 29, 0.72);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 20;
  backdrop-filter: blur(10px);
}

.modal.hidden { display: none; }

.modal-panel {
  width: min(1000px, 95vw);
  max-height: 92vh;
  overflow: auto;
}

.editor-stage-wrap {
  background: rgba(2, 6, 23, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 16px;
  padding: 12px;
  overflow: auto;
}

#editor-canvas {
  display: block;
  max-width: 100%;
  margin: 0 auto;
  touch-action: none;
  background: #000;
}

@media (max-width: 1280px) {
  .scanner-layout,
  .stats-row,
  .export-grid {
    grid-template-columns: 1fr;
  }

  .section-head,
  .toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .section-hint {
    text-align: left;
    max-width: none;
  }
}

@media (max-width: 1100px) {
  .three-col,
  .scanner-layout,
  .stats-row,
  .export-grid {
    grid-template-columns: 1fr;
  }

  .preview-stage { min-height: 360px; }
}

@media (max-width: 720px) {
  .app-shell { padding: 20px 14px 32px; }
  .card { padding: 18px; border-radius: 18px; }
  .narrow { margin-top: 4vh; }
  .pages { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
}
