/* FormPilot design system — iOS, Hebrew RTL first.
   Tokens taken directly from the approved canvas, not re-invented here. */

:root {
  --blue: #007AFF;
  --blue-pressed: #0062CC;
  --green: #34C759;
  --green-ink: #1F7A38;
  --orange: #FF9500;
  --orange-ink: #B26200;
  --red: #FF3B30;

  --bg: #F2F2F7;          /* systemGroupedBackground */
  --bg-canvas: #E9E9ED;
  --surface: #FFFFFF;
  --surface-bar: rgba(249, 249, 249, 0.94);

  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.6);
  --label-3: rgba(60, 60, 67, 0.3);
  --separator: #C6C6C8;   /* hairline, always 0.5px */

  --radius-cell: 10px;
  --radius-button: 12px;
  --radius-card: 16px;
  --radius-sheet: 20px;

  /* iOS type scale. Body is 17px — this is what makes it read as iOS. */
  --t-large-title: 34px/41px;
  --t-title2: 22px/28px;
  --t-headline: 17px/22px;
  --t-body: 17px/22px;
  --t-subhead: 15px/20px;
  --t-footnote: 13px/18px;
  --t-caption: 12px/16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-canvas: #000000;
    --surface: #1C1C1E;
    --surface-bar: rgba(28, 28, 30, 0.94);
    --label: #FFFFFF;
    --label-2: rgba(235, 235, 245, 0.6);
    --label-3: rgba(235, 235, 245, 0.3);
    --separator: #38383A;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  overflow-x: hidden;
  font-family: Heebo, -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  font-size: 17px;
  line-height: 22px;
  background: var(--bg);
  color: var(--label);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

[dir="rtl"] { text-align: right; }

/* Latin-script values stay LTR inside an RTL form — emails, IBANs, IDs. */
.ltr { direction: ltr; text-align: right; unicode-bidi: isolate; }

/* ---------- layout ---------- */

.screen { max-width: 640px; margin: 0 auto; padding-bottom: 120px; }

.bar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface-bar);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}
.bar-row {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; min-height: 52px;
}
.bar-title {
  flex: 1; min-width: 0; text-align: center;
  font: 600 var(--t-headline);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar-slot { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; }

.large-title { font: 700 var(--t-large-title); letter-spacing: -0.01em; }
.sub { margin-top: 8px; font: 400 var(--t-subhead); color: var(--label-2); text-wrap: pretty; }
.pad { padding: 16px; }
.section-title {
  font: 400 var(--t-footnote); color: var(--label-2);
  padding: 22px 16px 8px;
}
.section-title.sub { padding-top: 12px; font-weight: 500; }

/* ---------- inset grouped list: the core iOS form pattern ---------- */

.group {
  background: var(--surface);
  border-radius: var(--radius-cell);
  overflow: hidden;
  margin: 0 16px;
}
.cell {
  min-height: 56px;
  padding: 10px 16px;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  position: relative;
}
.cell + .cell::before {
  content: ""; position: absolute; top: 0; inset-inline: 16px 0;
  height: 0.5px; background: var(--separator);
}
.cell-label { font: 400 var(--t-footnote); color: var(--label-2); }
.cell.focused { box-shadow: inset 0 0 0 1.5px var(--blue); border-radius: var(--radius-cell); }
.cell.focused .cell-label { color: var(--blue); }
.cell.invalid { box-shadow: inset 0 0 0 1.5px var(--red); border-radius: var(--radius-cell); }

.cell input, .cell textarea, .cell select {
  border: 0; background: transparent; color: var(--label);
  font: 400 var(--t-body); font-family: inherit;
  width: 100%; padding: 0; outline: none;
}
.cell input::placeholder, .cell textarea::placeholder { color: var(--label-3); }
.cell textarea { resize: none; min-height: 66px; line-height: 22px; }

.field-error {
  display: flex; align-items: flex-start; gap: 6px; margin-top: 8px;
  font: 400 var(--t-footnote); color: var(--red); text-wrap: pretty;
}
.field-error svg { flex: none; margin-top: 2px; }

/* ---------- segmented character cells ---------- */

.segments { display: flex; gap: 5px; margin-top: 8px; direction: ltr; }
.segments input {
  flex: 1; min-width: 0; height: 40px;
  border: 0.5px solid var(--separator); border-radius: 7px;
  background: var(--bg);
  text-align: center; font: 500 var(--t-body);
  color: var(--label);
}
.segments input:focus { border-color: var(--blue); box-shadow: 0 0 0 1.5px var(--blue); }

/* ---------- choice rows ---------- */

.choice { display: flex; align-items: center; gap: 12px; min-height: 44px; cursor: pointer; }
.tick {
  width: 22px; height: 22px; flex: none;
  border: 1.5px solid var(--separator); border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); transition: all .15s;
}
.tick.round { border-radius: 50%; }
.tick svg { opacity: 0; }
.choice[aria-checked="true"] .tick { background: var(--blue); border-color: var(--blue); }
.choice[aria-checked="true"] .tick svg { opacity: 1; }
.choice-label { font: 400 var(--t-body); }

/* ---------- buttons ---------- */

.cta-bar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface-bar);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
}
.cta-inner { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }

.btn {
  height: 50px; border-radius: var(--radius-button); border: 0;
  background: var(--blue); color: #fff;
  font: 600 var(--t-headline); font-family: inherit;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer; width: 100%;
  transition: background .15s, opacity .15s;
}
.btn:active { background: var(--blue-pressed); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.secondary { background: transparent; color: var(--blue); height: 44px; }
.btn.destructive { background: var(--red); }
.btn.small { height: 36px; width: auto; padding: 0 16px; font: 600 var(--t-subhead); border-radius: 10px; }
.btn.grey { background: var(--bg); color: var(--label); }

/* ---------- progress ---------- */

.progress-row { display: flex; align-items: center; gap: 10px; padding: 0 16px 10px; }
.track { flex: 1; height: 4px; border-radius: 2px; background: rgba(60,60,67,0.18); overflow: hidden; }
.track > div { height: 100%; border-radius: 2px; background: var(--blue); transition: width .3s ease; }
.progress-text { font: 400 var(--t-footnote); color: var(--label-2); white-space: nowrap; }
.saved { display: flex; align-items: center; gap: 4px; font: 400 var(--t-caption); color: var(--green); white-space: nowrap; }

/* ---------- status pills ---------- */

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 100px;
  font: 500 var(--t-caption);
}
.pill.ok { background: rgba(52,199,89,.14); color: var(--green-ink); }
.pill.warn { background: rgba(255,149,0,.15); color: var(--orange-ink); }
.pill.info { background: rgba(0,122,255,.12); color: var(--blue); }
.pill.err { background: rgba(255,59,48,.12); color: var(--red); }
.pill.muted { background: rgba(60,60,67,.1); color: var(--label-2); }

/* ---------- dropzone ---------- */

.dropzone {
  margin: 28px 16px 0; height: 300px;
  background: var(--surface);
  border: 1.5px dashed rgba(0,122,255,.4); border-radius: var(--radius-card);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  cursor: pointer; transition: background .15s, border-color .15s;
  text-align: center; padding: 20px;
}
.dropzone.over { background: rgba(0,122,255,.05); border-color: var(--blue); }
.dropzone-title { font: 500 var(--t-body); }
.dropzone-hint { font: 400 var(--t-footnote); color: var(--label-3); }

/* ---------- steps ---------- */

.steps { margin: 32px 16px 0; display: flex; flex-direction: column; gap: 2px; }
.step { display: flex; align-items: center; gap: 12px; padding: 12px 4px; font: 400 var(--t-body); color: var(--label-3); }
.step.done { color: var(--label); }
.step.active { color: var(--label); font-weight: 500; }
.step-mark { width: 22px; height: 22px; flex: none; display: flex; align-items: center; justify-content: center; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(0,122,255,.25); border-top-color: var(--blue);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- signature ---------- */

.sign-card {
  margin: 24px 16px 0; background: var(--surface);
  border-radius: var(--radius-card); padding: 16px;
  position: relative;
}
.sign-canvas { width: 100%; height: 220px; touch-action: none; display: block; border-radius: 10px; cursor: crosshair; }
.sign-baseline { position: absolute; inset-inline: 32px; bottom: 42px; height: 0.5px; background: var(--separator); }
.sign-x { position: absolute; inset-inline-start: 32px; bottom: 46px; color: var(--label-3); font-size: 15px; }

/* ---------- success ---------- */

.hero-check {
  width: 96px; height: 96px; margin: 48px auto 0; border-radius: 50%;
  background: rgba(52,199,89,.12);
  display: flex; align-items: center; justify-content: center;
}

/* ---------- dashboard (desktop) ---------- */

.shell { display: flex; min-height: 100dvh; }
.sidebar {
  width: 244px; flex: none; padding: 20px 12px;
  border-inline-start: 0.5px solid var(--separator);
  background: var(--surface);
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 8px 12px 20px; font: 700 20px/26px Heebo, system-ui; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px; min-height: 44px;
  font: 500 var(--t-subhead); color: var(--label); cursor: pointer;
}
.nav-item.active { background: rgba(0,122,255,.1); color: var(--blue); }
.main { flex: 1; min-width: 0; padding: 28px 32px 80px; background: var(--bg); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat { background: var(--surface); border-radius: var(--radius-card); padding: 18px; }
.stat-label { font: 400 var(--t-footnote); color: var(--label-2); }
.stat-value { font: 700 30px/36px Heebo, system-ui; margin-top: 6px; }
.stat.attention .stat-value { color: var(--orange-ink); }

/* Wide content scrolls inside its own container; the page body never does. */
.table-scroll { overflow-x: auto; border-radius: var(--radius-card); background: var(--surface); -webkit-overflow-scrolling: touch; }
table.list { width: 100%; min-width: 560px; border-collapse: collapse; background: var(--surface); }
table.list th {
  text-align: right; font: 500 var(--t-footnote); color: var(--label-2);
  padding: 12px 16px; border-bottom: 0.5px solid var(--separator); white-space: nowrap;
}
table.list td { padding: 14px 16px; border-bottom: 0.5px solid var(--separator); font: 400 var(--t-subhead); }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover { background: rgba(0,122,255,.04); }

/* ---------- review split view ---------- */

.split { display: grid; grid-template-columns: 1fr 380px; gap: 20px; align-items: start; }
.viewer { background: var(--surface); border-radius: var(--radius-card); padding: 12px; position: relative; }
/* Field boxes are positioned from the left in a normalized space, so the page
   wrapper is forced LTR. Letting it inherit RTL would mirror every box. */
.page-wrap { position: relative; margin-bottom: 12px; direction: ltr; }
.page-wrap img, .page-wrap canvas { width: 100%; display: block; border-radius: 8px;
  user-select: none; -webkit-user-drag: none; }
.page-wrap.drawing { cursor: crosshair; }
.page-wrap.drawing img { pointer-events: none; }

.overlay-box {
  position: absolute; border: 1.5px solid var(--blue);
  background: rgba(0,122,255,.1); border-radius: 3px; cursor: move;
  touch-action: none;
}
.overlay-box.warn { border-color: var(--orange); background: rgba(255,149,0,.14); }
.overlay-box.selected { border-width: 2.5px; box-shadow: 0 0 0 3px rgba(0,122,255,.25); }
.overlay-box.dragging { opacity: .8; }

/* Resize grip, big enough to hit without magnifying the page. */
.grip {
  position: absolute; right: -6px; bottom: -6px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--blue); border: 2px solid #fff;
  cursor: nwse-resize; touch-action: none;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.overlay-box:not(.selected) .grip { display: none; }

.draw-preview {
  position: absolute; border: 1.5px dashed var(--blue);
  background: rgba(0,122,255,.12); border-radius: 3px; pointer-events: none;
}
.draw-hint {
  position: sticky; top: 8px; z-index: 5; margin: 0 0 10px;
  background: rgba(0,122,255,.12); color: var(--blue);
  padding: 10px 14px; border-radius: var(--radius-cell);
  font: 500 var(--t-subhead); text-align: center;
}
/* The row stacks: a header line, then the editor beneath it when selected.
   Laying all three out in one flex row put the editor beside the caption and
   the two overlapped. */
.field-row {
  background: var(--surface); border-radius: var(--radius-cell);
  padding: 12px 14px; margin-bottom: 8px; cursor: pointer;
  display: flex; flex-direction: column;
}
.field-row-head { display: flex; align-items: flex-start; gap: 10px; }
.field-row-head > div { flex: 1; min-width: 0; }
.field-row.selected { box-shadow: inset 0 0 0 1.5px var(--blue); }

/* ---------- misc ---------- */

.toast {
  position: fixed; inset-inline: 16px; bottom: 96px; z-index: 60;
  max-width: 480px; margin: 0 auto;
  background: rgba(28,28,30,.95); color: #fff;
  padding: 12px 16px; border-radius: 12px;
  font: 400 var(--t-subhead);
  opacity: 0; transform: translateY(8px); transition: all .25s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: rgba(255,59,48,.96); }

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.sheet-backdrop.show { opacity: 1; pointer-events: auto; }
.sheet {
  background: var(--bg); width: 100%; max-width: 640px;
  max-height: 92dvh; border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  display: flex; flex-direction: column;
  transform: translateY(20px); transition: transform .25s;
}
.sheet-backdrop.show .sheet { transform: none; }
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--label-3); margin: 8px auto; flex: none; }
.sheet-body { overflow: auto; padding: 8px 0 24px; }

.center-card {
  max-width: 380px; margin: 12vh auto 0; background: var(--surface);
  border-radius: var(--radius-card); padding: 28px 24px;
}

.empty { text-align: center; padding: 60px 24px; color: var(--label-2); font: 400 var(--t-subhead); }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mono { font-variant-numeric: tabular-nums; }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  .shell { flex-direction: column; }
  .sidebar { width: auto; display: flex; gap: 4px; overflow-x: auto; padding: 10px; border: 0; border-bottom: 0.5px solid var(--separator); }
  .sidebar-brand { display: none; }
  .main { padding: 16px; }
}

/* ---------- provider banner ---------- */

.banner {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border-radius: var(--radius-cell);
  background: rgba(255,149,0,.12); color: var(--orange-ink);
  font: 400 var(--t-subhead); margin-bottom: 18px;
}
.banner svg { flex: none; margin-top: 2px; }
.banner code {
  font-family: ui-monospace, monospace; font-size: 13px;
  background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px;
}

/* ---------- field editor ---------- */

.editor { width: 100%; margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
/* A <label> is inline by default, so a caption and a full-width control end up
   stacked on top of each other. Every control here is an explicit column. */
.editor label { display: flex; flex-direction: column; gap: 4px; }
.editor .cap { font: 400 var(--t-footnote); color: var(--label-2); }
.editor input[type="text"], .editor select {
  width: 100%; height: 36px; padding: 0 10px;
  font: 400 var(--t-subhead); font-family: inherit;
  color: var(--label); background: var(--bg);
  border: 0.5px solid var(--separator); border-radius: 8px;
  appearance: none; -webkit-appearance: none;
}
.editor select { padding-inline-end: 28px; }
.editor input:focus, .editor select:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px rgba(0,122,255,.2);
}
.editor .toggle {
  flex-direction: row; align-items: center; gap: 10px;
  min-height: 44px; font: 400 var(--t-body); cursor: pointer;
}
.editor .toggle input { width: 20px; height: 20px; accent-color: var(--blue); }
.editor .hint {
  font: 400 var(--t-caption); color: var(--label-3);
  text-wrap: pretty; line-height: 16px;
}
.editor .actions { display: flex; gap: 8px; }

/* Selection must not swallow a short field. A 9pt box at screen scale is a few
   pixels tall, and a 3px glow around it reads as a solid blue bar. */
.overlay-box.selected {
  border-width: 2px;
  outline: 1.5px solid rgba(0,122,255,.55);
  outline-offset: 2px;
  box-shadow: none;
}

/* ---------- review: attention first ---------- */

.review-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.review-title { font: 700 26px/32px Heebo, system-ui; }
.review-sub { margin-top: 6px; font: 400 var(--t-subhead); color: var(--label-2); }
.review-actions { display: flex; align-items: center; gap: 10px; }

.tabs { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 10px; margin: 18px 0 12px; }
.tab {
  flex: 1; min-height: 34px; border: 0; background: transparent;
  font: 500 var(--t-subhead); font-family: inherit; color: var(--label-2);
  border-radius: 8px; cursor: pointer; display: flex; align-items: center;
  justify-content: center; gap: 6px;
}
.tab.on { background: var(--surface); color: var(--label); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.tab .count {
  min-width: 20px; padding: 0 5px; border-radius: 100px;
  font: 600 var(--t-caption); background: rgba(60,60,67,.12); color: var(--label-2);
}
.tab.on .count.alert { background: var(--orange); color: #fff; }

.page-label {
  font: 500 var(--t-footnote); color: var(--label-2);
  padding: 14px 4px 6px; position: sticky; top: 0;
  background: var(--bg); z-index: 2;
}

/* A field's number ties the list row to the box on the page. */
.pin {
  min-width: 22px; height: 22px; flex: none; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font: 600 var(--t-caption); background: var(--orange); color: #fff;
}
.pin.ok { background: rgba(52,199,89,.16); color: var(--green-ink); }

.box-pin {
  position: absolute; top: -9px; inset-inline-start: -9px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--orange); color: #fff;
  font: 600 10px/18px Heebo, system-ui; text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.3); pointer-events: none;
}

/* Approved fields fade back so the page itself shows where to look. */
.overlay-box.calm { border-color: rgba(0,122,255,.35); background: rgba(0,122,255,.05); }
.overlay-box.calm:hover { border-color: var(--blue); background: rgba(0,122,255,.12); }
.overlay-box.flagged { border-color: var(--orange); background: rgba(255,149,0,.18); }

.reason {
  display: flex; align-items: flex-start; gap: 6px; margin-top: 6px;
  font: 400 var(--t-footnote); color: var(--orange-ink); text-wrap: pretty;
}

.all-clear { text-align: center; padding: 44px 24px; }
.all-clear .mark {
  width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 50%;
  background: rgba(52,199,89,.14); display: flex; align-items: center; justify-content: center;
}
.all-clear h3 { font: 600 var(--t-title2); }
.all-clear p { margin-top: 6px; font: 400 var(--t-subhead); color: var(--label-2); }

.kbd-hint {
  font: 400 var(--t-caption); color: var(--label-3); padding: 10px 4px 0;
  text-align: center;
}
.kbd-hint kbd {
  font-family: ui-monospace, monospace; font-size: 11px;
  background: var(--bg); border: 0.5px solid var(--separator);
  border-radius: 4px; padding: 1px 5px;
}

.cell-label .live-ok { display: inline-flex; margin-inline-start: 6px; vertical-align: -2px; }


/* ---- signer document viewer: page images + value overlay ---- */
.page-stack { display: flex; flex-direction: column; gap: 14px; padding: 12px; background: var(--surface); max-height: 72dvh; overflow: auto; }
.page { position: relative; flex: none; background: #fff; border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.12); overflow: hidden; }
.page img { display: block; width: 100%; height: auto; user-select: none; }
.page .ov { position: absolute; display: flex; align-items: center; justify-content: flex-end; direction: rtl;
  padding: 0 2px; box-sizing: border-box; font: 500 11px/1 -apple-system, system-ui, sans-serif; color: #1a3fd1;
  background: rgba(58,123,255,.10); border-radius: 2px; overflow: hidden; white-space: nowrap; pointer-events: none; }
.page .ov.ltr { direction: ltr; justify-content: flex-start; }
.page .ov.sig { justify-content: center; color: var(--green); background: rgba(52,199,89,.12); font-weight: 600; }
.page .page-num { position: absolute; right: 8px; bottom: 6px; font-size: 11px; color: var(--label-3); background: rgba(255,255,255,.85); padding: 2px 6px; border-radius: 6px; }
@media (max-width: 767px) { .page .ov { font-size: 9px; } }
