:root {
  --red: #b91c1c;
  --red-dark: #7f1d1d;
  --red-light: #fee2e2;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --ok: #15803d;
  --warn: #b45309;
  --fail: #b91c1c;
  --shadow: 0 10px 30px -12px rgba(15, 23, 42, 0.15);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app-header {
  padding: 20px 24px 16px;
  background: linear-gradient(180deg, #fff 0%, #fff 65%, rgba(255,255,255,0) 100%);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 760px;
  margin: 0 auto 14px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--red);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.5px;
  box-shadow: var(--shadow);
}

.brand-name { font-weight: 700; font-size: 18px; line-height: 1; }
.brand-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.progress-bar {
  max-width: 760px;
  margin: 0 auto;
}

.progress-steps {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
}

.progress-step {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  transition: background 0.25s;
}

.progress-step.active,
.progress-step.done {
  background: var(--red);
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 8px 24px 80px;
}

.step {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  animation: fade-up 0.35s ease;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

h1, h2, h3 { margin: 0 0 12px; color: var(--ink); }
h1 { font-size: 28px; letter-spacing: -0.02em; }
h2 { font-size: 22px; letter-spacing: -0.01em; }
h3 { font-size: 16px; }

.lead { font-size: 16px; color: var(--ink-2); margin-bottom: 20px; }
.muted { color: var(--muted); font-size: 14px; margin: 0 0 20px; }

.choice-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 24px 0;
}

.choice-card {
  background: white;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, transform 0.1s;
  font: inherit;
  color: inherit;
}

.choice-card:hover { border-color: var(--red); transform: translateY(-1px); }
.choice-card h3 { margin: 10px 0 6px; }
.choice-card p { margin: 0; color: var(--muted); font-size: 14px; }

.choice-icon {
  width: 38px;
  height: 38px;
  background: var(--red-light);
  color: var(--red);
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
}

.features {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  display: grid;
  gap: 8px;
  color: var(--ink-2);
}

.features li {
  padding-left: 26px;
  position: relative;
  font-size: 14px;
}

.features li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 8px;
  width: 10px;
  height: 6px;
  border-left: 2px solid var(--red);
  border-bottom: 2px solid var(--red);
  transform: rotate(-45deg);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 14px;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-2);
  font-weight: 500;
}

.form-grid input,
.form-grid select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font: inherit;
  color: var(--ink);
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-grid input:focus,
.form-grid select:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.12);
}

.col-span-2 { grid-column: 1 / -1; }

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.btn {
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s, opacity 0.15s;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn.primary { background: var(--red); color: white; }
.btn.primary:hover:not(:disabled) { background: var(--red-dark); }

.btn.secondary {
  background: var(--red-light);
  color: var(--red);
}
.btn.secondary:hover:not(:disabled) { background: #fecaca; }

.btn.ghost {
  background: transparent;
  color: var(--ink-2);
  border-color: var(--border);
}
.btn.ghost:hover:not(:disabled) { background: var(--bg); }

/* Capture zone */
.capture-zone,
.selfie-zone {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
}

.capture-preview,
.selfie-preview {
  background: #f1f5f9;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  min-height: 220px;
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
}

.selfie-preview { min-height: 260px; }

.capture-preview img,
.selfie-preview img {
  max-width: 100%;
  max-height: 360px;
  display: block;
}

.placeholder {
  color: var(--muted);
  display: grid;
  place-items: center;
  gap: 8px;
}

.placeholder svg { width: 48px; height: 48px; }

.capture-actions,
.selfie-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.checklist {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 14px;
  display: grid;
  gap: 6px;
}

.checklist .check {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-2);
}

.checklist .check::before {
  content: "";
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}

.checklist .check.ok { color: var(--ok); }
.checklist .check.ok::before { background: var(--ok); }
.checklist .check.fail { color: var(--fail); }
.checklist .check.fail::before { background: var(--fail); }

/* Review */
.review-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 14px;
}

.review-section h4 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.review-section dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  font-size: 14px;
}

.review-section dt { color: var(--muted); }
.review-section dd { margin: 0; color: var(--ink); }

.review-section img {
  max-width: 160px;
  max-height: 220px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* Confirmation */
.step-done { text-align: center; padding: 48px 32px; }

.check-badge {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--red);
  color: white;
  font-size: 36px;
  display: grid;
  place-items: center;
  margin: 0 auto 18px;
}

.reference-box {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 24px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin: 24px 0;
}

.reference-box span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.reference-box strong { font-size: 22px; letter-spacing: 0.08em; color: var(--red); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
}

.modal[aria-hidden="false"] { display: block; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
}

.modal-panel {
  position: relative;
  max-width: 560px;
  margin: 4vh auto;
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  animation: fade-up 0.25s ease;
}

.modal-panel.narrow { max-width: 420px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-header h3 { margin: 0; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
}

.icon-btn:hover { background: var(--bg); }

.camera-stage {
  position: relative;
  aspect-ratio: 3 / 4;
  background: #000;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.camera-stage video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-stage.mirror video { transform: scaleX(-1); }

.camera-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.camera-overlay.selfie::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 46%;
  width: 60%;
  aspect-ratio: 3 / 4;
  transform: translate(-50%, -50%);
  border: 2px dashed rgba(255,255,255,0.8);
  border-radius: 46% / 55%;
}

.camera-overlay.document::before {
  content: "";
  position: absolute;
  inset: 12%;
  border: 2px dashed rgba(255,255,255,0.85);
  border-radius: 6px;
}

.flash-overlay {
  position: absolute;
  inset: 0;
  background: white;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.flash-overlay.on { opacity: 1; }

.camera-hint {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 10px 0 2px;
  min-height: 20px;
}

.camera-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 4px 4px;
}

.shutter {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 4px solid var(--ink);
  background: white;
  cursor: pointer;
  position: relative;
  box-shadow: 0 0 0 4px white, 0 0 0 6px var(--ink);
  transition: transform 0.1s;
}

.shutter:active { transform: scale(0.95); }

/* QR */
.qr-box {
  background: white;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  margin: 12px 0;
}

.qr-box canvas,
.qr-box img { max-width: 100%; }

.qr-url {
  font-size: 12px;
  color: var(--muted);
}

.qr-url label { display: block; margin-bottom: 4px; }

.qr-url code {
  display: block;
  background: var(--bg);
  padding: 10px;
  border-radius: 8px;
  word-break: break-all;
  color: var(--ink);
}

.qr-status {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--red-light);
  color: var(--red-dark);
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
}

.qr-status.ok {
  background: #dcfce7;
  color: var(--ok);
}

/* Device visibility helpers - JS toggles .is-mobile on body */
body:not(.is-mobile) .mobile-only { display: none !important; }
body.is-mobile .desktop-only { display: none !important; }

/* Responsive */
@media (max-width: 640px) {
  main { padding: 8px 16px 60px; }
  .step { padding: 20px; border-radius: 12px; }
  .choice-cards { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .col-span-2 { grid-column: 1; }
  .app-header { padding: 16px 16px 12px; }
  h1 { font-size: 24px; }
  .modal-panel { margin: 0; border-radius: 0; min-height: 100vh; }
}
