:root {
  --bg: #eef2f7;
  --card: #ffffff;
  --ink: #182235;
  --muted: #657186;
  --line: #dbe2ec;
  --primary: #1f5eff;
  --primary-dark: #1547c7;
  --navy: #15243a;
  --success: #0c8f62;
  --danger: #b72835;
  --shadow: 0 12px 38px rgba(31, 48, 77, 0.09);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgba(31,94,255,.08), transparent 24rem),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  min-height: 74px;
  padding: 12px clamp(16px, 4vw, 48px);
  color: #fff;
  background: rgba(21, 36, 58, .97);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  box-shadow: 0 8px 28px rgba(9, 18, 32, .14);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  font-weight: 850; letter-spacing: -.04em;
  color: var(--navy); background: #fff;
}
.brand strong, .brand span { display: block; }
.brand strong { font-size: 16px; }
.brand span { margin-top: 2px; color: #bdc8d8; font-size: 12px; }
.top-actions { display: flex; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }

.page-shell { width: min(1460px, calc(100% - 32px)); margin: 22px auto 56px; }
.notice {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; margin-bottom: 18px;
  border: 1px solid #cbd9fb; border-radius: 14px;
  background: #f5f8ff; color: #38517e; font-size: 13px; line-height: 1.5;
}
.notice-icon { font-size: 18px; }
.workspace { display: grid; grid-template-columns: minmax(320px, .8fr) minmax(520px, 1.5fr); gap: 18px; align-items: start; }
.card { background: var(--card); border: 1px solid rgba(210,220,233,.9); border-radius: var(--radius); box-shadow: var(--shadow); }
.scanner-card, .form-card, .template-card { padding: clamp(18px, 2.4vw, 28px); }
.card-heading { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; margin-bottom: 20px; }
.card-heading h1, .card-heading h2 { margin: 2px 0 0; letter-spacing: -.025em; }
.card-heading h1 { font-size: 26px; }
.card-heading h2 { font-size: 22px; }
.eyebrow { margin: 0; color: var(--primary); font-weight: 800; font-size: 11px; letter-spacing: .11em; text-transform: uppercase; }
.prototype-badge, .quality-badge, .template-note {
  display: inline-flex; align-items: center; min-height: 28px;
  padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 800;
  color: #486179; background: #edf2f7; border: 1px solid #dce5ee;
}

.participant-label { display: block; margin: 0 0 7px; font-size: 12px; color: var(--muted); font-weight: 750; }
.select, input, select, textarea {
  width: 100%; border: 1px solid #ccd6e3; border-radius: 10px; color: var(--ink); background: #fff;
  outline: none; transition: border-color .15s, box-shadow .15s, background .15s;
}
.select, input, select { min-height: 42px; padding: 9px 11px; }
textarea { padding: 10px 11px; resize: vertical; }
.select:focus, input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31,94,255,.12); }

.upload-zone {
  margin-top: 14px; padding: 24px 18px; border: 1.5px dashed #9eb3cf; border-radius: 15px;
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 7px;
  background: #f8faff; transition: border-color .15s, background .15s, transform .15s;
}
.upload-zone.dragover { border-color: var(--primary); background: #eef4ff; transform: translateY(-1px); }
.upload-zone strong { font-size: 15px; }
.upload-zone span { max-width: 310px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.upload-icon { width: 52px; height: 52px; border-radius: 15px; display: grid; place-items: center; margin-bottom: 4px; color: var(--primary); background: #e9f0ff; font-size: 28px; }

.button {
  min-height: 40px; padding: 9px 14px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 800; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .12s, background .15s, border-color .15s, opacity .15s;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(0); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button.primary { color: #fff; background: var(--primary); }
.button.primary:hover:not(:disabled) { background: var(--primary-dark); }
.button.secondary { color: #2d4464; background: #fff; border-color: #cbd6e4; }
.button.ghost { color: #dce5f2; background: rgba(255,255,255,.07); border-color: rgba(255,255,255,.15); }
.scanner-card .button.ghost { color: #52657e; background: transparent; border-color: transparent; }
.button.success { color: #fff; background: var(--success); }
.button.scan-button { margin-top: 12px; color: #fff; background: var(--navy); font-size: 14px; }
.button.full { width: 100%; margin-top: 12px; }
.danger-text { color: var(--danger) !important; }

.preview-wrap { margin-top: 14px; }
.preview-wrap img { width: 100%; max-height: 280px; object-fit: contain; border: 1px solid var(--line); border-radius: 14px; background: #f0f3f7; }
.preview-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; }

.progress { margin-top: 14px; padding: 13px; border: 1px solid #d8e2f0; border-radius: 12px; background: #f7f9fc; }
.progress-row { display: flex; justify-content: space-between; gap: 12px; color: #52627a; font-size: 12px; }
.progress-track { height: 7px; overflow: hidden; margin-top: 9px; background: #dce4ef; border-radius: 999px; }
.progress-track > div { width: 0; height: 100%; background: var(--primary); border-radius: inherit; transition: width .18s; }

.ocr-result { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.result-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.result-title h2 { margin: 2px 0 0; font-size: 19px; }
.quality-badge.good { color: #0a704e; background: #e9f8f2; border-color: #bfe8d8; }
.quality-badge.warn { color: #8b5c08; background: #fff7de; border-color: #efd99f; }
.result-grid, .fields-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.result-grid label, .fields-grid label { color: #56657a; font-size: 11px; font-weight: 750; }
.result-grid label input, .fields-grid label input, .fields-grid label select, .fields-grid label textarea { margin-top: 6px; font-weight: 500; font-size: 13px; }
.wide { grid-column: 1 / -1; }
.raw-text-details { margin-top: 12px; color: var(--muted); font-size: 12px; }
.raw-text-details summary { cursor: pointer; font-weight: 750; }
.raw-text-details textarea { margin-top: 8px; min-height: 120px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; }
.scanner-help { margin-top: 16px; padding: 12px 13px; color: #6b5a30; background: #fff9e9; border: 1px solid #f0dfac; border-radius: 11px; font-size: 11px; line-height: 1.5; }

.form-heading { align-items: center; }
.save-state { color: #5d6b7e; font-size: 11px; }
.participant-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding-bottom: 19px; border-bottom: 1px solid var(--line); }
.tab {
  min-height: 43px; border: 1px solid #d4dde8; border-radius: 11px; background: #f8fafc; color: #53647b; font-weight: 800; font-size: 12px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.tab span { width: 23px; height: 23px; border-radius: 50%; display: grid; place-items: center; background: #e5ebf2; }
.tab.active { color: #fff; background: var(--navy); border-color: var(--navy); }
.tab.active span { color: var(--navy); background: #fff; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 20px 0 12px; }
.section-heading.second { margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--line); }
.section-heading h3 { margin: 0; font-size: 15px; }
.section-heading span { color: var(--muted); font-size: 10px; }

.template-card { margin-top: 18px; }
.paper-stage { overflow: auto; padding: 18px; border-radius: 14px; background: #dfe4eb; box-shadow: inset 0 0 0 1px rgba(33,48,72,.07); }
.paper { position: relative; width: min(754px, 100%); margin: 0 auto; background: #fff; box-shadow: 0 8px 24px rgba(19,33,52,.18); }
.paper > img { display: block; width: 100%; height: auto; }
#paperOverlay { position: absolute; inset: 0; pointer-events: none; }
.paper-text {
  position: absolute; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  color: #0b1f48; font-family: Arial, sans-serif; font-size: clamp(5px, 1.1vw, 9px); line-height: 1.1; font-weight: 700;
}
.paper-text.soft { color: #26334c; font-weight: 600; }

footer { padding: 24px 16px 44px; color: #748195; text-align: center; font-size: 11px; }
.hidden { display: none !important; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .scanner-card { order: 1; }
  .form-card { order: 2; }
}
@media (max-width: 680px) {
  .topbar { position: static; align-items: flex-start; flex-direction: column; }
  .top-actions { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); }
  .top-actions .button { padding-inline: 8px; font-size: 11px; }
  .page-shell { width: min(100% - 18px, 1460px); margin-top: 10px; }
  .scanner-card, .form-card, .template-card { padding: 16px; border-radius: 14px; }
  .result-grid, .fields-grid { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
  .section-heading { align-items: flex-start; flex-direction: column; gap: 3px; }
  .participant-tabs { gap: 5px; }
  .tab { padding: 6px; font-size: 10px; gap: 5px; }
  .paper-stage { padding: 8px; }
}

@media print {
  body { background: #fff; }
  .topbar, .notice, .workspace, footer, .template-card .card-heading { display: none !important; }
  .page-shell, .template-card { width: auto; margin: 0; padding: 0; box-shadow: none; border: 0; }
  .paper-stage { overflow: visible; padding: 0; background: #fff; }
  .paper { width: 100%; box-shadow: none; }
  @page { size: A4 portrait; margin: 8mm; }
}
