:root {
  /* maleli brand — Rose palette (matches shipped icon assets) */
  --ink: #1E1016;
  --ink-2: #2C1A22;
  --ink-soft: #6B5560;
  --bg: #FFEDF2;
  --bg-2: #FBDCE6;
  --panel: #ffffff;
  --coral: #FF5C8A;
  --coral-deep: #ED3D71;
  --amber: #FF9E5C;
  --primary: #FF5C8A;
  --primary-dark: #ED3D71;
  --accent: #ED3D71;
  --accent-soft: #FFE1EB;
  --muted: #9A7E87;
  --line: #F2D6E0;
  --danger: #C62847;
  --radius: 16px;
  --warm: linear-gradient(135deg, #FF5C8A 0%, #FF9E5C 100%);
  --shadow: 0 1px 3px rgba(30, 16, 22, .08), 0 12px 32px -16px rgba(30, 16, 22, .22);
  font-family: "Heebo", "Hanken Grotesk", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.9rem 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .55rem;
  text-decoration: none; color: inherit; cursor: pointer; }
.brand-icon {
  width: 2.1rem; height: 2.1rem; flex: none;
  display: grid; place-items: center;
  background: var(--warm); border-radius: 30%;
  box-shadow: 0 1px 2px rgba(30,16,22,.18), 0 8px 18px -10px rgba(237,61,113,.6);
}
.brand-icon::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18); pointer-events: none;
}
.brand-icon { position: relative; }
.brand-icon svg { width: 100%; height: 100%; display: block; }
.brand-en {
  font-family: "Bricolage Grotesque", system-ui, sans-serif;
  font-weight: 800; color: var(--ink); font-size: 1.15rem; letter-spacing: -.035em;
}
.brand-en .dot { color: var(--coral); }
.tagline {
  margin: 0; color: var(--ink-soft); font-size: .9rem; flex: 1; min-width: 240px;
}
.tagline strong { color: var(--coral-deep); }

/* Language switcher */
.lang-switch {
  display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
}
.lang-btn {
  background: transparent; border: none; padding: .2rem .45rem;
  color: var(--ink-soft); font-weight: 600; font-size: .72rem; font-family: inherit;
}
.lang-btn + .lang-btn { border-inline-start: 1px solid var(--line); }
.lang-btn:hover:not(.active) { color: var(--primary); }
.lang-btn.active { background: var(--accent-soft); color: var(--accent); }

/* View switching — keep [hidden] authoritative over display rules below */
main[hidden] { display: none !important; }

/* View 1: clean landing with only a drop zone */
.view-landing {
  min-height: calc(100vh - 4.5rem);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1rem; padding: 2rem 1.5rem;
}
.dropzone {
  width: min(620px, 92vw);
  display: flex; flex-direction: column; align-items: center; gap: .6rem;
  padding: 3.5rem 2rem;
  background: var(--panel);
  border: 2px dashed var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  color: var(--ink-soft);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s, box-shadow .15s;
}
.dropzone:hover, .dropzone:focus-visible {
  border-color: var(--coral);
  outline: none;
}
.dropzone.dragover {
  border-color: var(--coral-deep);
  background: var(--accent-soft);
  transform: scale(1.01);
  box-shadow: 0 14px 40px -18px rgba(237, 61, 113, .5);
}
.dropzone-icon {
  width: 3.25rem; height: 3.25rem; color: var(--coral);
}
.dropzone-title {
  margin: .4rem 0 0; font-size: 1.5rem; color: var(--ink);
  font-family: "Bricolage Grotesque", system-ui, sans-serif; font-weight: 700;
}
.dropzone-sub { margin: 0; font-size: .95rem; }

/* "Photograph a form" — secondary entry on the landing screen (mobile/PWA). */
.camera-btn {
  display: inline-flex; align-items: center; gap: .5rem;
  font-size: .95rem; padding: .55rem 1.1rem;
}
.camera-icon { width: 1.15rem; height: 1.15rem; flex: none; }

/* Camera capture overlay (live scanner with edge highlighting) */
.cam-overlay {
  position: fixed; inset: 0; z-index: 60;
  display: flex; flex-direction: column;
  background: #0b0608; color: #fff;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.cam-overlay[hidden] { display: none; }
.cam-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .8rem 1.1rem; gap: 1rem;
}
.cam-title {
  font-family: "Bricolage Grotesque", system-ui, sans-serif;
  font-weight: 700; font-size: 1.05rem;
}
.cam-overlay .cam-close { color: #fff; border-color: rgba(255,255,255,.4); }
.cam-overlay .cam-close:hover { background: rgba(255,255,255,.12); color: #fff; }
.cam-stage {
  flex: 1; position: relative; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.cam-canvas {
  max-width: 100%; max-height: 100%;
  width: auto; height: auto; display: block;
  background: #000; border-radius: 8px;
}
.cam-status {
  margin: 0; text-align: center; padding: .5rem 1rem; min-height: 1.2em;
  font-size: .9rem; color: rgba(255,255,255,.85);
}
.cam-actions {
  display: flex; align-items: center; justify-content: center; gap: .75rem;
  padding: 1rem 1.1rem 1.4rem;
}
.cam-actions .ghost-btn { color: #fff; border-color: rgba(255,255,255,.4); }
.cam-actions .ghost-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.cam-shoot { min-width: 7rem; }

/* View 2: form preview + the single big MALELI button */
.view-preview {
  min-height: calc(100vh - 4.5rem);
  display: flex; flex-direction: column; align-items: center;
  gap: 1.25rem; padding: 1.5rem;
  padding-bottom: 6rem; /* clear the floating MALELI button */
}
.lp-toolbar {
  width: 100%; max-width: 900px;
  display: flex; align-items: center; gap: .5rem;
}
.lp-toolbar .zoom { margin-inline-start: auto; }
.lp-stage {
  flex: 1; width: 100%; max-width: 900px;
  overflow: auto;
  background: var(--panel, #fff);
  border: 1px solid var(--line, #f2d6e0);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 1rem;
}
.lp-stage.panning { cursor: grabbing; }
.lp-pages {
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
  margin: 0 auto;
}
.lp-pages img {
  display: block; width: 100%; height: auto;
  background: #fff; border-radius: 6px;
  box-shadow: 0 1px 6px rgba(30, 16, 22, .12);
}
.lp-hint { margin: 0; }
/* The MALELI call-to-action floats above the preview (FAB), staying reachable
   while the form pages scroll. Sits below the profile drawer (z 20) + spinner. */
.maleli-btn {
  position: fixed; bottom: calc(1.5rem + env(safe-area-inset-bottom));
  inset-inline-end: 1.5rem; z-index: 15;
  max-width: calc(100vw - 3rem);
  background: var(--warm); color: #fff; border: none;
  padding: .9rem 2.6rem; border-radius: 999px;
  font-family: "Bricolage Grotesque", system-ui, sans-serif;
  font-weight: 800; font-size: 1.45rem; letter-spacing: .04em;
  text-transform: uppercase;
  box-shadow: 0 14px 36px -12px rgba(237, 61, 113, .85);
  transition: filter .15s, box-shadow .15s, transform .05s;
}
.maleli-btn:hover { filter: brightness(1.05); box-shadow: 0 18px 44px -14px rgba(237, 61, 113, .9); }
.maleli-btn:active { transform: translateY(2px); }
@media (max-width: 560px) {
  .maleli-btn { inset-inline: 1rem; inset-inline-end: 1rem; width: auto;
    padding: .85rem 1.5rem; font-size: 1.25rem; }
}

/* Full-screen detection spinner */
.spinner-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1.1rem;
  background: rgba(255, 237, 242, .82);
  backdrop-filter: blur(3px);
}
.spinner-overlay[hidden] { display: none; }
.spinner {
  width: 3.5rem; height: 3.5rem;
  border: 4px solid var(--accent-soft);
  border-top-color: var(--coral);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-gif { width: 140px; height: auto; }
.spinner-text {
  margin: 0; color: var(--ink-2); font-weight: 600; font-size: 1rem;
}
/* Claude-style typed "thinking" word with a blinking cursor. */
.thinking-line {
  margin: 0; min-height: 1.4em;
  display: inline-flex; align-items: center;
  font-family: "Bricolage Grotesque", system-ui, sans-serif;
  font-weight: 700; font-size: 1.25rem; color: var(--coral-deep);
  letter-spacing: .01em;
}
.type-cursor {
  display: inline-block; width: .14em; height: 1.05em;
  margin-inline-start: .12em; background: var(--coral-deep);
  border-radius: 1px; animation: type-blink 1s steps(1, end) infinite;
}
@keyframes type-blink { 50% { opacity: 0; } }

/* View 3: form-fill workspace layout */
.layout {
  display: grid;
  grid-template-columns: minmax(340px, 420px) 1fr;
  gap: 1.25rem;
  padding: 1.25rem;
  align-items: start;
}
@media (max-width: 880px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Steps */
.steps { padding: .5rem; display: flex; flex-direction: column; }
.step {
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line);
  transition: opacity .2s;
}
.step:last-child { border-bottom: none; }
.step[data-state="locked"] { opacity: .45; pointer-events: none; }
.step[data-state="done"] h2 .num { background: var(--accent); }
.step h2 {
  display: flex; align-items: center; gap: .6rem;
  margin: 0 0 .35rem; font-size: 1.05rem;
}
.num {
  display: inline-grid; place-items: center;
  width: 1.6rem; height: 1.6rem; border-radius: 50%;
  background: var(--warm); color: #fff; font-size: .85rem; font-weight: 700;
}
.step[data-state="done"] h2 .num { background: var(--accent); }
.hint { margin: .15rem 0 .7rem; color: var(--ink-soft); font-size: .85rem; }
.status { margin: .55rem 0 0; font-size: .85rem; min-height: 1.1em; }
.status.error { color: var(--danger); }
.status.ok { color: var(--accent); }

/* Buttons */
button { font-family: inherit; cursor: pointer; }
.primary-btn {
  background: var(--warm); color: #fff; border: none;
  padding: .58rem 1.2rem; border-radius: 999px; font-weight: 700; font-size: .95rem;
  box-shadow: 0 8px 20px -12px rgba(237,61,113,.7);
  transition: filter .15s, box-shadow .15s, transform .05s;
}
.primary-btn:hover:not(:disabled) { filter: brightness(1.04); box-shadow: 0 10px 24px -12px rgba(237,61,113,.8); }
.primary-btn:active:not(:disabled) { transform: translateY(1px); }
.primary-btn:disabled { background: #EBD3DC; color: #B79AA6; box-shadow: none; cursor: not-allowed; }
.ghost-btn {
  background: transparent; border: 1px solid var(--line);
  padding: .45rem .9rem; border-radius: 999px; color: var(--ink-2); font-weight: 600;
  transition: border-color .15s, color .15s, background .15s;
}
.ghost-btn:hover { border-color: var(--coral); color: var(--coral-deep); background: var(--accent-soft); }
.ghost-btn.small { padding: .25rem .6rem; font-size: .85rem; }
.download-btn {
  display: inline-block; margin-inline-start: .5rem;
  background: var(--ink); color: var(--bg); text-decoration: none;
  padding: .58rem 1.2rem; border-radius: 999px; font-weight: 700;
}
.download-btn:hover { background: var(--ink-2); }
input[type="file"] { font-size: .9rem; }

/* Field list */
.field-list { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .75rem; max-height: 320px; overflow: auto; }
.field-row {
  display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: center;
  padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 10px;
  background: #FFF7FA;
}
.field-row.low-conf { border-color: var(--amber); background: #FFF1E6; }
.field-row.clickable { cursor: pointer; }
.field-row.clickable:hover { border-color: var(--primary); }
.field-row.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--accent-soft); }
.field-row.skipped { opacity: .6; }
.field-row.skipped select { text-decoration: line-through; }
.field-label { font-size: .85rem; color: var(--ink-soft); }
.field-label b { color: var(--ink); display: block; font-size: .92rem; }
.field-row select { padding: .35rem; border-radius: 6px; border: 1px solid var(--line); font-family: inherit; }
.badge { font-size: .7rem; color: #C56A12; }
.field-skip {
  grid-column: 1 / -1; display: flex; align-items: center; gap: .35rem;
  font-size: .78rem; color: var(--ink-soft); cursor: pointer;
}
.field-skip input { margin: 0; }

/* Preview */
.preview { position: relative; display: flex; flex-direction: column; min-height: 480px; }
.preview-tabs {
  display: flex; align-items: center; gap: .35rem;
  padding: .6rem .75rem; border-bottom: 1px solid var(--line);
}
.tab {
  background: transparent; border: none; padding: .4rem .8rem; border-radius: 7px;
  color: var(--ink-soft); font-weight: 600; font-size: .9rem;
}
.tab.active { background: var(--accent-soft); color: var(--accent); }
.tab:disabled { opacity: .4; cursor: not-allowed; }
.zoom { display: flex; align-items: center; gap: .25rem; margin-inline-start: auto; }
.zoom .ghost-btn.small { min-width: 2rem; text-align: center; }
#zoom-reset { min-width: 3.4rem; font-variant-numeric: tabular-nums; }
.pager { display: flex; align-items: center; gap: .4rem; font-size: .9rem; }
.preview-tabs .zoom + .pager { margin-inline-start: .75rem; }
.preview-stage {
  flex: 1; display: flex; align-items: flex-start; justify-content: center;
  padding: 1.25rem; overflow: auto;
  background: repeating-conic-gradient(#FBDCE6 0% 25%, #FFEDF2 0% 50%) 50%/22px 22px;
  border-radius: 0 0 var(--radius) var(--radius);
}
.preview-canvas {
  position: relative; margin: auto; flex: none; box-shadow: var(--shadow);
  cursor: grab; touch-action: none;
}
.preview-canvas.panning { cursor: grabbing; }
.preview-canvas[hidden] { display: none; }
#preview-img { display: block; width: 100%; height: auto; background: #fff; pointer-events: none; }

/* Client-rendered (local fill) views — the locally built PDF, shown in the browser's
   native viewer. Used for "Review" (real values) and "Filled" so neither the PII nor
   the finished document ever round-trips through a server. */
.preview-frame {
  width: 100%; height: min(78vh, 900px); min-height: 460px;
  border: none; background: #fff; border-radius: 8px; box-shadow: var(--shadow);
}
.preview-frame[hidden] { display: none; }

/* Field highlight overlay: a full-canvas layer holding one exact box per bbox. */
.field-highlight { position: absolute; inset: 0; pointer-events: none; }
.field-highlight[hidden] { display: none; }
.hl-rect {
  position: absolute;
  border: 2px solid var(--coral);
  background: rgba(255, 92, 138, .14);
}
.hl-rect.flash { animation: field-flash .9s ease-out 2; }
@keyframes field-flash {
  0%   { background: rgba(255, 158, 92, .45); border-color: var(--amber); }
  100% { background: rgba(255, 92, 138, .14); border-color: var(--coral); }
}
.zoom-hint {
  position: absolute; inset-block-end: .5rem; inset-inline-start: .5rem; margin: 0;
  padding: .2rem .5rem; font-size: .72rem; color: var(--ink-soft);
  background: rgba(255, 255, 255, .85); border: 1px solid var(--line); border-radius: 6px;
  pointer-events: none;
}
.zoom-hint[hidden] { display: none; }
.empty { color: var(--ink-soft); margin: auto; }

/* Step 2 instruction text */
.instructions {
  width: 100%; resize: vertical; margin: 0 0 .6rem;
  padding: .45rem .55rem; border: 1px solid var(--line); border-radius: 7px;
  font-family: inherit; font-size: .88rem; line-height: 1.4;
}

/* Drawer */
.drawer {
  position: fixed; inset-block: 0; inset-inline-end: 0; width: min(420px, 92vw);
  background: var(--panel); border-inline-start: 1px solid var(--line);
  box-shadow: -8px 0 32px rgba(26,31,54,.12);
  padding: 1.2rem; overflow: auto; z-index: 20;
}
.drawer[hidden] { display: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.profile-fields { display: flex; flex-direction: column; gap: .55rem; margin: .75rem 0 1rem; }
.profile-fields label { font-size: .8rem; color: var(--ink-soft); }
.profile-fields .pf-row { display: flex; flex-direction: column; gap: .2rem; }
.profile-fields input {
  padding: .45rem .55rem; border: 1px solid var(--line); border-radius: 7px;
  font-family: inherit; font-size: .92rem;
}

/* Hosted-mode account / unlock gate — a clean centered login page */
.acct-overlay {
  position: fixed; inset: 0; z-index: 70; overflow: auto;
  display: flex; align-items: flex-start; justify-content: center;
  padding: clamp(1.5rem, 8vh, 5rem) 1rem 2rem;
  background: var(--bg);
}
.acct-overlay[hidden] { display: none; }
.acct-col {
  width: min(440px, 100%);
  display: flex; flex-direction: column; align-items: center; gap: 1.5rem;
}
.acct-header { display: flex; align-items: center; gap: .6rem; }
.acct-logo {
  width: 2.6rem; height: 2.6rem; flex: none;
  display: grid; place-items: center; background: var(--warm); border-radius: 30%;
  box-shadow: 0 1px 2px rgba(30,16,22,.18), 0 8px 18px -10px rgba(237,61,113,.6);
}
.acct-logo svg { width: 100%; height: 100%; display: block; }
.acct-name {
  font-family: "Bricolage Grotesque", system-ui, sans-serif; font-weight: 800;
  font-size: 1.9rem; color: var(--ink); letter-spacing: -.035em;
}
.acct-name .dot { color: var(--coral); }
/* Center Clerk's own card; keep our forms (unlock/create) as their own card. */
.acct-signin { width: 100%; display: flex; justify-content: center; }
/* These rules must beat the display below when the section is inactive. */
.acct-signin[hidden], .acct-unlock[hidden], .acct-create[hidden] { display: none; }
.acct-card {
  width: 100%; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.5rem;
  display: flex; flex-direction: column; gap: .6rem;
}
.acct-card .acct-h { margin: 0; font-size: 1.15rem; }
.acct-hint { color: var(--ink-soft); font-size: .85rem; margin: 0 0 .2rem; }
.acct-warn {
  color: var(--danger); font-size: .82rem; margin: 0 0 .2rem;
  background: #FFF1E6; border: 1px solid var(--amber); border-radius: 8px; padding: .5rem .6rem;
}
.acct-card input[type="password"] {
  padding: .55rem .6rem; border: 1px solid var(--line); border-radius: 8px;
  font-family: inherit; font-size: 1rem;
}
.acct-err { color: var(--danger); font-size: .82rem; margin: 0; }
.acct-err[hidden] { display: none; }
.acct-card .acct-signout { align-self: center; margin-top: .2rem; }

/* Cloud export (native share) */
#share-btn { margin-inline-start: .5rem; }
.export-hint { margin-top: .45rem; }

/* Browser-autofill alternative */
.autofill-area {
  margin-top: .9rem; padding-top: .8rem; border-top: 1px dashed var(--line);
}
.autofill-area .hint { margin: 0 0 .5rem; }

/* Signature */
.sign-area { margin-bottom: .75rem; }
.sign-area label { display: block; font-size: .82rem; color: var(--ink-soft); margin-bottom: .3rem; }
#sig-pad { border: 1px dashed var(--line); border-radius: 8px; background: #fff; touch-action: none; display: block; }
#sig-clear { margin-top: .35rem; }
