:root {
  --bg: #0b1020; --panel: #121a2e; --panel-2: #172038; --line: #26314d; --text: #e7ecf6; --muted: #95a3c0;
  --accent: #6366f1; --accent-2: #4f46e5; --ok: #10b981; --warn: #f59e0b; --bad: #ef4444; --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: #a5b4fc; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  background: rgba(11,16,32,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 800; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); }
.brand .mark { width: 26px; height: 26px; border-radius: 7px; background: linear-gradient(135deg, var(--accent), #22d3ee); display: grid; place-items: center; font-size: 14px; }
.spacer { flex: 1; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 20px 64px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 16px; }
h1 { font-size: 24px; margin: 0 0 4px; } h2 { font-size: 18px; margin: 0 0 12px; } h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel-2);
  border-radius: 9px; padding: 9px 14px; cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text); }
.btn:hover { border-color: #3b4a72; }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.primary:hover { background: var(--accent); }
.btn.danger { background: transparent; border-color: #7f1d1d; color: #fca5a5; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 6px 10px; font-size: 12.5px; }
.input, select.input, textarea.input { width: 100%; background: #0e1528; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; outline: none; }
.input:focus { border-color: var(--accent); }
label.lbl { display: block; font-size: 12.5px; color: var(--muted); margin: 10px 0 4px; font-weight: 600; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; border: 1px solid var(--line); text-transform: capitalize; }
.chip.draft { color: #cbd5e1; } .chip.sent, .chip.viewed { color: #fcd34d; border-color: #78350f; }
.chip.completed, .chip.signed { color: #6ee7b7; border-color: #065f46; }
.chip.declined, .chip.voided { color: #fca5a5; border-color: #7f1d1d; } .chip.pending { color: var(--muted); }
.chip.high { color: #fca5a5; border-color: #7f1d1d; } .chip.medium { color: #fcd34d; border-color: #78350f; } .chip.low { color: #93c5fd; border-color: #1e3a8a; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1e293b; border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 10px; z-index: 100; max-width: min(560px, 92vw); box-shadow: 0 12px 30px rgba(0,0,0,.5); }
.toast.err { border-color: #7f1d1d; color: #fecaca; }
.modal-back { position: fixed; inset: 0; background: rgba(2,6,23,.72); display: grid; place-items: center; z-index: 80; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: min(560px, 100%); padding: 20px; max-height: 92vh; overflow: auto; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button { flex: 1; }
.tabs button.on { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.tabs a.btn { flex: 1; text-align: center; text-decoration: none; }
.tabs a.btn.on { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.navtabs { max-width: 380px; }
table.list { width: 100%; border-collapse: collapse; }
table.list td, table.list th { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
table.list tr.click { cursor: pointer; } table.list tr.click:hover td { background: #141d34; }
.table-scroll { overflow-x: auto; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.drop { border: 2px dashed #34406a; border-radius: 14px; padding: 36px 16px; text-align: center; cursor: pointer; }
.drop.over { border-color: var(--accent); background: #131c36; }
/* editor & signer document view */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; align-items: start; }
.side { position: sticky; top: 72px; max-height: calc(100vh - 90px); overflow: auto; }
.pages { display: flex; flex-direction: column; gap: 16px; align-items: center; }
.page { position: relative; background: #fff; box-shadow: 0 8px 28px rgba(0,0,0,.45); width: 100%; max-width: 900px; user-select: none; }
.page canvas { display: block; width: 100%; height: auto; }
.page .num { position: absolute; top: -20px; right: 0; font-size: 11px; color: var(--muted); }
.page.armed { cursor: crosshair; }
.fld { position: absolute; border: 2px solid var(--c, var(--accent)); background: color-mix(in srgb, var(--c, #6366f1) 14%, transparent);
  border-radius: 4px; font-size: 11px; font-weight: 700; color: #0f172a; display: flex; align-items: center; justify-content: center;
  overflow: hidden; touch-action: none; }
.fld .lab { pointer-events: none; padding: 0 4px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; color: #1e1b4b; }
.fld.sel { outline: 2px dashed #f59e0b; outline-offset: 2px; }
.fld .rz { position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; background: var(--c, var(--accent)); cursor: nwse-resize; }
.fld.editable { cursor: move; }
.fld.todo { cursor: pointer; animation: pulse 1.6s ease-in-out infinite; }
.fld.done { background: transparent; border-style: dashed; border-color: rgba(16,185,129,.7); }
.fld img.val { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.fld input.txt { width: 100%; height: 100%; border: 0; background: #fff; color: #0f172a; font-size: 13px; padding: 0 4px; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(99,102,241,.0); } 50% { box-shadow: 0 0 0 4px rgba(99,102,241,.35); } }
.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.palette .btn.on { background: var(--accent-2); color: #fff; border-color: var(--accent-2); }
.signer { border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 10px; padding: 10px; margin-bottom: 8px; background: var(--panel-2); }
.signer.active { box-shadow: 0 0 0 1px var(--c); }
.sigpad { width: 100%; height: 170px; background: #fff; border-radius: 10px; touch-action: none; cursor: crosshair; display: block; }
.events li { margin: 0 0 8px; } .events { padding-left: 18px; }
.flag { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: var(--panel-2); }
.flag q { display: block; color: var(--muted); font-size: 12.5px; margin-top: 6px; font-style: italic; }
.steps { display: flex; gap: 8px; color: var(--muted); font-size: 12.5px; flex-wrap: wrap; }
.steps b { color: var(--text); }
.bar { position: sticky; top: 56px; z-index: 20; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 16px; }
.center-card { max-width: 480px; margin: 40px auto; }
.code-input { font-size: 26px; letter-spacing: .4em; text-align: center; }
.saved-preview { background: #fff; border-radius: 10px; padding: 12px; display: grid; place-items: center; min-height: 120px; }
.saved-preview img { max-width: 100%; max-height: 160px; }
/* editor zoom (field placement on small screens) */
.pages-col { min-width: 0; }
.zoombar { margin-bottom: 10px; gap: 6px; }
.pages.zoomable { overflow: auto; touch-action: pan-x pan-y; }   /* one-finger scroll stays native; pinch is handled by the editor, not the browser */
.pages.zoomed { align-items: flex-start; max-height: calc(100vh - 150px); }
.pages.zoomed .page { width: calc(min(100%, 900px) * var(--zoom, 1)); max-width: none; flex: none; }
.show-coarse { display: none; }
/* end-to-end encrypted documents, developer page */
.zk-card { border-color: #065f46; }
pre.code { background: #0e1528; border: 1px solid var(--line); border-radius: 9px; padding: 12px; overflow-x: auto; font-size: 12.5px; white-space: pre; }
/* phone handoff */
.qr-box { display: grid; place-items: center; gap: 8px; margin: 10px 0; }
.qr-box img { width: 220px; height: 220px; background: #fff; border-radius: 10px; padding: 6px; image-rendering: pixelated; }
.sigpad-phone { height: 46vh; min-height: 220px; }
/* Local AI pill + Contract Assistant drawer */
.ai-pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 700;
  border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: default; white-space: nowrap; }
button.ai-pill { cursor: pointer; }
button.ai-pill:hover { border-color: #3b4a72; }
.ai-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #475569; }
.ai-pill.on { color: #6ee7b7; border-color: #065f46; }
.ai-pill.on::before { background: var(--ok); }
.ai-pill.rules { font-weight: 600; }
.ai-pill.rules::before { display: none; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); z-index: 60; background: var(--panel);
  border-left: 1px solid var(--line); padding: 16px 18px 28px; overflow-y: auto; box-shadow: -18px 0 40px rgba(2,6,23,.5); }
.drawer-head { margin-bottom: 4px; flex-wrap: nowrap; }
.drawer h3 { margin: 14px 0 6px; }
.ai-disclaimer { border: 1px solid #78350f; background: rgba(245,158,11,.08); color: #fde68a; border-radius: 10px;
  padding: 9px 11px; font-size: 12.5px; margin-bottom: 12px; }
.ai-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.ai-actions .btn.on { border-color: var(--accent); }
.ai-list { margin: 0; padding-left: 18px; } .ai-list li { margin-bottom: 6px; }
.ai-note { color: #fcd34d; }
.form-err { color: #fca5a5; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; max-height: none; }
  .grid2 { grid-template-columns: 1fr; }
}
/* phones: dialogs become bottom sheets, the signing bar sits at the bottom within thumb reach, bigger pad */
@media (max-width: 640px) {
  .topbar .tagline { display: none; }   /* keeps the sticky top bar one line high next to the Local AI pill */
  .modal-back { padding: 0; place-items: end stretch; }
  .modal { width: 100%; border-radius: 16px 16px 0 0; max-height: 94vh; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
  .sigpad { height: 210px; }
  .bar { position: fixed; top: auto; bottom: 0; left: 0; right: 0; margin: 0; border-radius: 14px 14px 0 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 24px rgba(2,6,23,.45); }
  .bar .spacer { display: none; }
  .bar > span:first-child { width: 100%; }
  .pages { padding-bottom: 130px; }
}
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .fld .rz { width: 20px; height: 20px; right: 0; bottom: 0; border-radius: 6px 0 2px 0; }
  .hide-coarse { display: none; }
  .show-coarse { display: inline; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .sigpad-phone { height: 58vh; }
}
