:root {
  --bg: #f4f5f7; --card: #fff; --fg: #17191c; --muted: #5d6470; --line: #dde1e6;
  --brand: #1a3d8f; --brand-fg: #fff; --field: rgba(26, 61, 143, .10); --field-line: #1a3d8f;
  --done: rgba(29, 122, 70, .12); --done-line: #1d7a46; --error: #b3261e;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111317; --card: #1b1e24; --fg: #eceef1; --muted: #9aa2ad; --line: #2c3038;
    --brand: #7ea2ff; --brand-fg: #0c1020; --field: rgba(126, 162, 255, .16); --field-line: #7ea2ff;
    --done: rgba(95, 208, 143, .16); --done-line: #5fd08f; --error: #ff8a80; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.55 "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif; }
.bar { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; letter-spacing: .02em; } .by { font-weight: 400; color: var(--muted); font-size: .8em; }
main { max-width: 860px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 16px; }
.sticky { position: sticky; top: 0; z-index: 5; }
h1 { font-size: 1.35rem; margin: 0 0 8px; } h2 { font-size: 1.15rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
blockquote { margin: 12px 0; padding: 8px 12px; border-inline-start: 3px solid var(--brand); background: var(--bg); border-radius: 4px; white-space: pre-wrap; }
.btn { display: inline-block; background: var(--brand); color: var(--brand-fg); border: 0; border-radius: 8px; padding: 12px 20px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--fg); border: 1px solid var(--line); }
.link { background: none; border: 0; color: var(--brand); font: inherit; cursor: pointer; padding: 8px 0; min-height: 44px; }
.error { color: var(--error); min-height: 1.2em; margin: 8px 0 0; }
#f-code { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
#code { font-size: 1.6rem; letter-spacing: .4em; width: 9.5em; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--fg); text-align: center; }
.page { position: relative; margin: 0 auto 16px; box-shadow: 0 1px 4px rgba(0,0,0,.15); background: #fff; max-width: 100%; }
/* direction: a canvas inherits the page direction, and RTL makes pdf.js misplace every glyph */
.page canvas { display: block; width: 100%; height: auto; direction: ltr; }
.field { position: absolute; border: 2px dashed var(--field-line); background: var(--field); border-radius: 4px; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--field-line); font-weight: 600; padding: 0; overflow: hidden; }
.field.done { border-style: solid; border-color: var(--done-line); background: var(--done); }
.field img { max-width: 100%; max-height: 100%; }
.field.date { cursor: default; }
.consent { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 16px; font-size: .92rem; }
.consent input { margin-top: 4px; width: 20px; height: 20px; flex: none; }
details { margin-top: 16px; } summary { cursor: pointer; color: var(--muted); min-height: 32px; }
textarea, #typed { width: 100%; font: inherit; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--fg); margin: 8px 0; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.modal[hidden] { display: none; }
.sheet { background: var(--card); width: 100%; max-width: 640px; border-radius: 14px 14px 0 0; padding: 20px 16px; }
@media (min-width: 700px) { .modal { align-items: center; } .sheet { border-radius: 14px; } }
.tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tab { flex: 1; padding: 10px; border: 1px solid var(--line); background: transparent; color: var(--fg); border-radius: 8px; font: inherit; cursor: pointer; min-height: 44px; }
.tab.on { background: var(--brand); color: var(--brand-fg); border-color: var(--brand); }
#pad, #typed-preview { width: 100%; height: auto; aspect-ratio: 3 / 1; background: #fff; border: 1px solid var(--line); border-radius: 8px; touch-action: none; }
.row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.demo-bar { display: flex; gap: 6px 18px; flex-wrap: wrap; justify-content: center; padding: 7px 14px; font-size: .85rem; font-weight: 600; text-align: center; background: #b45309; color: #fff; }
.sender-line { margin: -6px 0 10px; font-size: .86rem; color: var(--muted); } .sender-line.ok { color: #1d7a46; font-weight: 600; }
.qr-box { display: flex; gap: 16px; align-items: center; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); } .qr-box img { flex: none; border-radius: 8px; border: 1px solid var(--line); background: #fff; } .qr-box p { margin: 4px 0 0; font-size: .88rem; }
