:root {
  --bg: #f3f4f8;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --ink: #161a2c;
  --ink-2: #4a5068;
  --ink-3: #7c8299;
  --line: #e2e5ee;
  --line-2: #cfd4e2;
  --brand: #3b3fd8;
  --brand-ink: #ffffff;
  --brand-soft: #eceefe;
  --accent: #ffd23f;
  --accent-soft: #fff6d1;
  --ok: #138a52;
  --ok-soft: #e3f6ec;
  --warn: #b35c00;
  --warn-soft: #fff0dc;
  --danger: #c62f3b;
  --danger-soft: #fde8ea;
  --shadow: 0 1px 2px rgba(20, 24, 50, .06), 0 6px 24px rgba(20, 24, 50, .07);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1120; --surface: #181b2e; --surface-2: #1f2338; --ink: #eceef8; --ink-2: #b4b9d0; --ink-3: #868ca8;
    --line: #2a2f48; --line-2: #3a4060; --brand: #7b80ff; --brand-ink: #0f1120; --brand-soft: #262a52;
    --accent: #ffd23f; --accent-soft: #3a3217; --ok: #4cd191; --ok-soft: #173427; --warn: #ffb35c; --warn-soft: #3a2a15;
    --danger: #ff7a85; --danger-soft: #3d1c22; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 28px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1120; --surface: #181b2e; --surface-2: #1f2338; --ink: #eceef8; --ink-2: #b4b9d0; --ink-3: #868ca8;
  --line: #2a2f48; --line-2: #3a4060; --brand: #7b80ff; --brand-ink: #0f1120; --brand-soft: #262a52;
  --accent: #ffd23f; --accent-soft: #3a3217; --ok: #4cd191; --ok-soft: #173427; --warn: #ffb35c; --warn-soft: #3a2a15;
  --danger: #ff7a85; --danger-soft: #3d1c22; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 28px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 "Heebo", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: var(--brand); color: var(--brand-ink); font-size: 17px;
}
.topbar .spacer { flex: 1; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 42px;
  padding: 0 16px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface);
  color: var(--ink); font-weight: 600; font-size: 15px; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand); filter: brightness(1.08); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #1b1a10; }
.btn-accent:hover { background: var(--accent); filter: brightness(1.04); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { color: var(--danger); }
.btn-sm { min-height: 34px; padding: 0 11px; font-size: 14px; border-radius: 8px; }
.btn-icon { min-height: 34px; width: 34px; padding: 0; border-radius: 8px; font-size: 15px; }
.btn-block { width: 100%; }

/* ---------- forms ---------- */
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--line-2); border-radius: 10px;
  background: var(--surface); color: var(--ink); outline: none; transition: border-color .15s, box-shadow .15s;
}
.textarea { resize: vertical; line-height: 1.6; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-size: 15px; }
.check input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--brand); flex: none; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.muted { color: var(--ink-3); }
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 99px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.pill-signed { background: var(--ok-soft); color: var(--ok); }
.pill-viewed { background: var(--brand-soft); color: var(--brand); }
.pill-pending { background: var(--warn-soft); color: var(--warn); }

/* ---------- the contract "paper" ---------- */
.paper {
  background: #fff; color: #1b1e2e; border-radius: 6px; box-shadow: var(--shadow);
  padding: 28px 22px; max-width: 800px; margin: 0 auto; font-size: 15.5px; line-height: 1.75;
}
@media (min-width: 700px) { .paper { padding: 56px 64px; } }
.paper .c-title { font-size: 22px; line-height: 1.35; text-align: center; margin: 0 0 18px; font-weight: 800; }
.paper .c-heading { font-size: 16.5px; margin: 22px 0 6px; font-weight: 700; }
.paper .c-para { margin: 0 0 9px; }
.paper .c-clause { display: flex; gap: 8px; }
.paper .c-num { flex: none; min-width: 2.2em; font-weight: 600; color: #3a3f58; }
.paper .c-body { flex: 1; }
.paper strong { font-weight: 700; }
/* Isolated so numbers like 050-1234567 keep their order inside Hebrew text. */
.paper .var { font-weight: 600; unicode-bidi: isolate; }
.paper .var-ltr { white-space: nowrap; }
.paper .var-missing {
  background: #fff1c2; color: #8a5a00; border: 1px dashed #e0a800; border-radius: 4px;
  padding: 0 5px; font-size: .88em; font-family: ui-monospace, Consolas, monospace;
}
.paper .var-blank { color: #9aa0b5; letter-spacing: -1px; }
.paper .c-sigs { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 18px; }
.paper .c-sig { text-align: center; min-width: 0; }
.paper .sig-box { height: 92px; display: flex; align-items: flex-end; justify-content: center; }
.paper .sig-img { max-height: 88px; max-width: 100%; }
.paper .sig-empty { color: #9aa0b5; font-size: 13px; padding-bottom: 6px; }
.paper .sig-line { border-top: 1.5px solid #2a2f45; margin: 2px 8px 6px; }
.paper .sig-label { font-size: 13px; color: #5a607a; }
.paper .sig-name { font-weight: 600; font-size: 14.5px; }
.paper .sig-slot {
  width: 100%; height: 84px; border: 2px dashed #e0a800; background: #fff8dc; border-radius: 10px;
  color: #6f5200; font-weight: 700; font-size: 15px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px;
}
.paper .audit {
  margin-top: 26px; padding-top: 12px; border-top: 1px solid #e3e6ef; font-size: 11.5px; color: #6b7188; line-height: 1.6;
}
.paper .audit b { color: #3a3f58; }
.paper .audit code { font-family: ui-monospace, Consolas, monospace; font-size: 10.5px; word-break: break-all; direction: ltr; unicode-bidi: embed; }

/* The PDF copy: spacing in em, so shrinking the text to fit one page shrinks the gaps with it. */
.paper-fit .c-title { font-size: 1.5em; margin-bottom: .9em; }
.paper-fit .c-heading { font-size: 1.12em; margin: 1.2em 0 .35em; }
.paper-fit .c-para { margin-bottom: .55em; }
.paper-fit .c-sigs { margin-top: 1.2em; gap: 1.4em; }
.paper-fit .sig-box { height: 5.4em; }
.paper-fit .sig-img { max-height: 5.2em; }
.paper-fit .audit { margin-top: 1.5em; padding-top: .8em; font-size: .76em; }
.paper-fit .audit code { font-size: .95em; }

/* ---------- signature pad ---------- */
.sigpad-wrap { position: relative; }
.sigpad {
  display: block; width: 100%; height: 200px; background: #fff; border: 2px solid var(--line-2);
  border-radius: 12px; touch-action: none; cursor: crosshair;
}
.sigpad-wrap.has-ink .sigpad { border-color: var(--brand); }
.sigpad-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none;
  color: #a2a8bd; font-size: 17px; gap: 8px;
}
.sigpad-wrap.has-ink .sigpad-hint { display: none; }
.sigpad-baseline { position: absolute; left: 24px; right: 24px; bottom: 46px; border-top: 1.5px dashed #d0d4e2; pointer-events: none; }

/* ---------- toast / modal ---------- */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 100; max-width: calc(100% - 32px);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 10px; font-weight: 600; box-shadow: var(--shadow);
  animation: toast-in .2s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

.modal-back {
  position: fixed; inset: 0; z-index: 90; background: rgba(10, 12, 25, .5); display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 640px) { .modal-back { align-items: center; padding: 16px; } }
.modal {
  width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; background: var(--surface); color: var(--ink);
  border-radius: 18px 18px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  animation: sheet-in .22s ease-out;
}
@media (min-width: 640px) { .modal { border-radius: 18px; } }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
.modal h3 { margin: 0 0 12px; font-size: 19px; }

.spinner {
  width: 26px; height: 26px; border: 3px solid var(--line-2); border-top-color: var(--brand); border-radius: 50%;
  animation: spin .8s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
