:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6b7280;
  --faint: #9ca3af;
  --line: #e5e7eb;
  --line-2: #f0f1f4;
  --brand: #4f46e5;
  --brand-2: color-mix(in srgb, var(--brand) 82%, #000);
  --brand-soft: color-mix(in srgb, var(--brand) 9%, #fff);
  --brand-ring: color-mix(in srgb, var(--brand) 18%, transparent);
  --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --bad: #dc2626;
  --bad-soft: #fef2f2;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14), 0 2px 6px rgba(16, 24, 40, .06);
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); min-height: 100%; }
body { font-size: 14px; line-height: 1.5; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.boot { display: grid; place-items: center; min-height: 100vh; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; }
.spinner.sm { width: 16px; height: 16px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, box-shadow .15s, transform .05s; color: var(--ink-2); text-decoration: none !important; }
.btn:hover { background: #f9fafb; border-color: #d1d5db; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 1px 2px color-mix(in srgb, var(--brand) 30%, transparent); }
.btn.primary:hover { background: var(--brand-2); }
.btn.success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); border-color: #fecaca; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #eef0f4; }
.btn.lg { height: 46px; padding: 0 22px; font-size: 15px; border-radius: 12px; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn.icon { width: 36px; padding: 0; }
.btn svg { width: 16px; height: 16px; flex: none; }

.input, select.input, textarea.input { width: 100%; height: 40px; padding: 0 12px; border: 1px solid #d1d5db; border-radius: 10px; background: #fff; outline: none; transition: border-color .15s, box-shadow .15s; }
textarea.input { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.input.invalid { border-color: var(--bad); }
label.lbl { display: block; font-weight: 600; font-size: 13px; color: var(--ink-2); margin: 0 0 6px; }
.hint { color: var(--muted); font-size: 12.5px; }
.field { margin-bottom: 16px; }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; user-select: none; }
.check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--brand); flex: none; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #111827; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 500; max-width: 90vw; animation: toastIn .2s ease-out; }
.toast.error { background: var(--bad); }
.toast.success { background: var(--ok); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--brand) 16%, #fff) 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #fce7f3 0%, transparent 55%), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 20px; padding: 36px; box-shadow: var(--shadow-lg); }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--ink); text-decoration: none !important; }
.logo .mark { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 16px; font-weight: 700; box-shadow: 0 4px 10px color-mix(in srgb, var(--brand) 35%, transparent); flex: none; }
.logo svg { flex: none; }
.logo .brand-img { height: 34px; max-width: 190px; object-fit: contain; display: block; }
.logo .brand-sub { color: var(--faint); font-weight: 500; font-size: 13px; padding-left: 10px; margin-left: 2px; border-left: 1px solid var(--line); }
.powered { color: var(--faint); font-size: 12px; text-decoration: none !important; }
.powered b { color: var(--muted); }
.login-card h1 { font-size: 22px; margin: 28px 0 6px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }

/* ---------- Shell ---------- */
.topbar { position: sticky; top: 0; z-index: 50; height: 64px; display: flex; align-items: center; gap: 16px; padding: 0 28px; background: rgba(255, 255, 255, .9); backdrop-filter: saturate(180%) blur(10px); border-bottom: 1px solid var(--line); }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 13px; }
.container { max-width: 1180px; margin: 0 auto; padding: 28px; }
.page-head { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; flex: 1; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; cursor: pointer; transition: border-color .15s, box-shadow .15s; text-align: left; }
.stat:hover { border-color: color-mix(in srgb, var(--brand) 35%, #fff); box-shadow: var(--shadow); }
.stat.active { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.stat .n { font-size: 26px; font-weight: 700; }
.stat .t { color: var(--muted); font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; background: #eceef3; padding: 4px; border-radius: 10px; }
.tab { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font-weight: 600; font-size: 13px; color: var(--muted); cursor: pointer; }
.tab.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.search { position: relative; flex: 1; min-width: 200px; max-width: 340px; margin-left: auto; }
.search input { padding-left: 36px; }
.search svg { position: absolute; left: 12px; top: 12px; width: 16px; height: 16px; color: var(--faint); }

.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.doc-list { overflow: hidden; }
.doc-row { display: grid; grid-template-columns: 40px minmax(0, 2.2fr) minmax(0, 1.6fr) 130px 110px 40px; align-items: center; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); cursor: pointer; transition: background .12s; }
.doc-row:last-child { border-bottom: 0; }
.doc-row:hover { background: color-mix(in srgb, var(--brand) 3%, #fff); }
.doc-row .ficon { width: 40px; height: 40px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; }
.doc-row .ficon svg { width: 20px; height: 20px; }
.doc-row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-row .sub { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-row .date { color: var(--muted); font-size: 13px; }
.avatars { display: flex; align-items: center; }
.avatar { width: 30px; height: 30px; border-radius: 50%; color: #fff; font-weight: 700; font-size: 11.5px; display: grid; place-items: center; border: 2px solid #fff; margin-left: -8px; position: relative; flex: none; }
.avatars .avatar:first-child { margin-left: 0; }
.avatar .badge { position: absolute; right: -3px; bottom: -3px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; display: grid; place-items: center; font-size: 8px; }
.avatar .badge.ok { background: var(--ok); }
.avatar .badge.no { background: var(--bad); }
.progress { height: 6px; background: var(--line-2); border-radius: 6px; overflow: hidden; margin-top: 6px; width: 120px; }
.progress > span { display: block; height: 100%; background: var(--ok); border-radius: 6px; transition: width .3s; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.draft { background: #f3f4f6; color: #4b5563; }
.pill.sent { background: var(--warn-soft); color: #b45309; }
.pill.completed { background: var(--ok-soft); color: #047857; }
.pill.declined, .pill.expired { background: var(--bad-soft); color: #b91c1c; }
.pill.cancelled { background: #f3f4f6; color: #6b7280; text-decoration: line-through; }
.pill.viewed { background: #eff6ff; color: #1d4ed8; }
.pill.signed { background: var(--ok-soft); color: #047857; }
.pill.pending { background: #f3f4f6; color: #6b7280; }

.empty { text-align: center; padding: 64px 24px; color: var(--muted); }
.empty .ill { width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 20px; background: var(--brand-soft); display: grid; place-items: center; color: var(--brand); }
.empty .ill svg { width: 34px; height: 34px; }
.empty h3 { color: var(--ink); font-size: 17px; margin-bottom: 6px; }
.empty p { margin: 0 0 20px; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(17, 24, 39, .45); z-index: 200; display: grid; place-items: center; padding: 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: #fff; border-radius: 18px; box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; animation: pop .18s ease-out; }
.modal.wide { max-width: 640px; }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }
.modal-head { padding: 22px 24px 0; display: flex; align-items: flex-start; gap: 12px; }
.modal-head h2 { font-size: 19px; flex: 1; }
.modal-head p { color: var(--muted); margin: 4px 0 0; }
.modal-body { padding: 20px 24px; }
.modal-foot { padding: 14px 24px 20px; display: flex; gap: 10px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; }

.dropzone { border: 2px dashed color-mix(in srgb, var(--brand) 35%, #fff); border-radius: 16px; background: color-mix(in srgb, var(--brand) 4%, #fff); padding: 44px 20px; text-align: center; cursor: pointer; transition: background .15s, border-color .15s; }
.dropzone:hover, .dropzone.over { background: var(--brand-soft); border-color: var(--brand); }
.dropzone .ill { width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 16px; background: #fff; color: var(--brand); display: grid; place-items: center; box-shadow: var(--shadow); }
.dropzone .ill svg { width: 26px; height: 26px; }
.dropzone b { display: block; font-size: 16px; margin-bottom: 4px; }

/* ---------- Editor ---------- */
.editor { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - 64px); }
.side { background: #fff; border-right: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; }
.side-sec { padding: 18px 20px; border-bottom: 1px solid var(--line-2); }
.side-sec h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.side-sec h3 .num { width: 20px; height: 20px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 11px; letter-spacing: 0; }
.title-input { font-size: 16px; font-weight: 600; border: 1px solid transparent; padding: 6px 8px; margin: -6px -8px; width: calc(100% + 16px); border-radius: 8px; background: transparent; outline: none; }
.title-input:hover { background: #f5f6fa; }
.title-input:focus { border-color: var(--brand); background: #fff; }

.signer { border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 10px 10px 12px; margin-bottom: 10px; cursor: pointer; transition: border-color .15s, box-shadow .15s; position: relative; background: #fff; }
.signer.active { border-color: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 16%, transparent); }
.signer .row { display: flex; align-items: center; gap: 8px; }
.signer .row + .row { margin-top: 6px; }
.signer .sw { width: 12px; height: 12px; border-radius: 4px; background: var(--c); flex: none; }
.signer input { border: 1px solid transparent; background: transparent; padding: 4px 6px; border-radius: 6px; width: 100%; outline: none; min-width: 0; }
.signer input:hover { background: #f5f6fa; }
.signer input:focus { border-color: var(--brand); background: #fff; }
.signer input.name { font-weight: 600; }
.signer input.email { font-size: 13px; color: var(--ink-2); }
.signer .order { width: 22px; height: 22px; border-radius: 6px; background: #f3f4f6; font-size: 11px; font-weight: 700; color: var(--muted); display: grid; place-items: center; flex: none; }
.signer .tools { display: flex; gap: 2px; }
.signer .tools button { width: 26px; height: 26px; border: 0; background: transparent; border-radius: 6px; color: var(--faint); cursor: pointer; display: grid; place-items: center; }
.signer .tools button:hover { background: #f3f4f6; color: var(--ink); }
.signer .tools svg { width: 14px; height: 14px; }
.signer .count { font-size: 11.5px; color: var(--muted); padding-left: 26px; }

.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pal { display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: grab; font-weight: 600; font-size: 13px; color: var(--ink-2); user-select: none; transition: border-color .15s, background .15s, transform .1s; touch-action: none; }
.pal:hover { border-color: var(--c, var(--brand)); background: color-mix(in srgb, var(--c, var(--brand)) 6%, #fff); }
.pal:active { cursor: grabbing; transform: scale(.98); }
.pal .ic { width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; background: color-mix(in srgb, var(--c, var(--brand)) 14%, #fff); color: var(--c, var(--brand)); flex: none; }
.pal .ic svg { width: 15px; height: 15px; }
.pal.wide { grid-column: span 2; }

.side-foot { margin-top: auto; padding: 16px 20px; border-top: 1px solid var(--line); background: #fff; position: sticky; bottom: 0; }

.viewer-wrap { overflow: auto; position: relative; background: #e9ebf1; }
.viewer { padding: 28px 24px 80px; display: flex; flex-direction: column; align-items: center; gap: 22px; }
.pdf-page { position: relative; background: #fff; box-shadow: 0 2px 10px rgba(16, 24, 40, .12); width: 100%; max-width: 860px; user-select: none; }
.pdf-page canvas { display: block; width: 100%; height: 100%; }
.pdf-page .pnum { position: absolute; left: -2px; top: -20px; font-size: 11.5px; color: var(--muted); font-weight: 600; }
.pdf-page .layer { position: absolute; inset: 0; }

.fbox { position: absolute; border: 1.5px solid var(--c); background: color-mix(in srgb, var(--c) 13%, transparent); border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 11.5px; font-weight: 600; color: var(--c); cursor: move; touch-action: none; container-type: size; overflow: visible; }
.fbox .lab { display: flex; align-items: center; gap: 4px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding: 0 4px; font-size: clamp(8px, 45cqh, 13px); pointer-events: none; }
.fbox .lab svg { width: 1.1em; height: 1.1em; flex: none; }
.fbox.sel { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--c); z-index: 5; }
.fbox .rs { position: absolute; right: -6px; bottom: -6px; width: 12px; height: 12px; background: #fff; border: 2px solid var(--c); border-radius: 50%; cursor: nwse-resize; display: none; }
.fbox.sel .rs { display: block; }
.fbox .del { position: absolute; top: -12px; right: -12px; width: 22px; height: 22px; border-radius: 50%; background: #111827; color: #fff; border: 2px solid #fff; display: none; place-items: center; cursor: pointer; padding: 0; }
.fbox .del svg { width: 11px; height: 11px; }
.fbox.sel .del { display: grid; }
.fbox .req { position: absolute; top: -2px; left: 3px; color: var(--bad); font-size: 13px; line-height: 1; }

.fprops { position: absolute; z-index: 30; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 12px; width: 240px; }
.fprops .field { margin-bottom: 10px; }
.fprops .input { height: 34px; font-size: 13px; }

.drag-ghost { position: fixed; pointer-events: none; z-index: 500; border: 1.5px dashed var(--c); background: color-mix(in srgb, var(--c) 15%, #fff); border-radius: 4px; color: var(--c); font-weight: 600; font-size: 12px; display: grid; place-items: center; opacity: .9; }

/* ---------- Detail ---------- */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 22px; align-items: start; }
.detail .preview { height: calc(100vh - 220px); min-height: 500px; overflow: auto; background: #e9ebf1; }
.detail .preview .viewer { padding: 28px 18px; }
.panel { padding: 18px 20px; }
.panel + .panel { border-top: 1px solid var(--line-2); }
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 14px; }
.srow { display: flex; gap: 12px; align-items: center; padding: 10px 0; }
.srow + .srow { border-top: 1px dashed var(--line); }
.srow .who { flex: 1; min-width: 0; }
.srow .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srow .who span { color: var(--muted); font-size: 12.5px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srow .avatar { margin: 0; }
.timeline { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow: auto; }
.timeline li { position: relative; padding: 0 0 14px 22px; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--c, color-mix(in srgb, var(--brand) 40%, #fff)); }
.timeline li::after { content: ""; position: absolute; left: 7.5px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline .when { color: var(--faint); font-size: 12px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; min-width: 200px; z-index: 60; }
.menu-list button { display: flex; width: 100%; align-items: center; gap: 10px; border: 0; background: transparent; padding: 9px 10px; border-radius: 8px; cursor: pointer; font-weight: 500; text-align: left; }
.menu-list button:hover { background: #f5f6fa; }
.menu-list button.danger { color: var(--bad); }
.menu-list svg { width: 16px; height: 16px; color: var(--muted); }
.banner { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-radius: 12px; margin-bottom: 18px; font-weight: 500; }
.banner.ok { background: var(--ok-soft); color: #065f46; }
.banner.warn { background: var(--warn-soft); color: #92400e; }
.banner.bad { background: var(--bad-soft); color: #991b1b; }
.banner .grow { flex: 1; }

/* ---------- Signer ---------- */
.s-top { position: sticky; top: 0; z-index: 50; background: #fff; border-bottom: 1px solid var(--line); }
.s-top-in { max-width: 1000px; margin: 0 auto; height: 64px; display: flex; align-items: center; gap: 14px; padding: 0 20px; }
.s-top .doc-t { flex: 1; min-width: 0; }
.s-top .doc-t b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-top .doc-t span { color: var(--muted); font-size: 12.5px; }
.s-progress { height: 3px; background: var(--line-2); }
.s-progress > span { display: block; height: 100%; background: var(--ok); transition: width .3s; }
.s-viewer { padding: 24px 12px 140px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.s-viewer .pdf-page { max-width: 900px; }
.s-bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); background: linear-gradient(to top, rgba(245, 246, 250, 1) 55%, rgba(245, 246, 250, 0)); display: flex; justify-content: center; pointer-events: none; }
.s-bottom .btn { pointer-events: auto; box-shadow: var(--shadow-lg); min-width: 240px; }

.sfield { position: absolute; border: 2px dashed var(--c, var(--brand)); background: color-mix(in srgb, var(--c, var(--brand)) 10%, rgba(255, 255, 255, .6)); border-radius: 5px; display: flex; align-items: center; justify-content: center; cursor: pointer; container-type: size; transition: background .15s, box-shadow .15s; }
.sfield:hover { background: color-mix(in srgb, var(--c, var(--brand)) 20%, rgba(255, 255, 255, .6)); }
.sfield.current { box-shadow: 0 0 0 3px color-mix(in srgb, var(--c, var(--brand)) 35%, transparent); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--c, var(--brand)) 12%, transparent); } }
.sfield.done { border-style: solid; border-color: transparent; background: transparent; }
.sfield.done:hover { border-color: color-mix(in srgb, var(--c, var(--brand)) 40%, transparent); }
.sfield.readonly { border: 0; background: transparent; cursor: default; }
.sfield .ph { color: var(--c, var(--brand)); font-weight: 700; font-size: clamp(8px, 42cqh, 14px); display: flex; gap: 5px; align-items: center; white-space: nowrap; padding: 0 4px; }
.sfield .ph svg { width: 1.1em; height: 1.1em; }
.sfield img { max-width: 100%; max-height: 100%; object-fit: contain; }
.sfield input[type=text] { width: 100%; height: 100%; border: 0; background: transparent; outline: none; padding: 0 4px; font-size: clamp(8px, 60cqh, 15px); color: #13205a; }
.sfield .txt { width: 100%; padding: 0 4px; font-size: clamp(8px, 60cqh, 15px); color: #13205a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sfield .cb { width: 80%; height: 80%; max-width: 100%; display: grid; place-items: center; color: #13205a; }
.sfield .cb svg { width: 100%; height: 100%; }
.sfield .tag { position: absolute; left: -2px; top: -18px; font-size: 10px; font-weight: 700; background: var(--c, var(--brand)); color: #fff; padding: 1px 6px; border-radius: 4px 4px 4px 0; white-space: nowrap; pointer-events: none; }
.sfield.done .tag { display: none; }

.sigpad-tabs { display: flex; gap: 4px; background: #eceef3; padding: 4px; border-radius: 10px; margin-bottom: 14px; }
.sigpad-tabs .tab { flex: 1; }
.sigpad { position: relative; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; height: 190px; overflow: hidden; }
.sigpad canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.sigpad .base { position: absolute; left: 24px; right: 24px; bottom: 44px; border-bottom: 1.5px solid #d1d5db; pointer-events: none; }
.sigpad .x { position: absolute; left: 24px; bottom: 50px; color: var(--faint); font-size: 18px; pointer-events: none; }
.sigpad .clear { position: absolute; right: 10px; top: 10px; }
.sigpad .hint-in { position: absolute; inset: 0; display: grid; place-items: center; color: var(--faint); pointer-events: none; font-size: 15px; }
.fonts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.font-opt { border: 1.5px solid var(--line); border-radius: 10px; height: 64px; display: grid; place-items: center; cursor: pointer; font-size: 26px; color: #13205a; overflow: hidden; white-space: nowrap; padding: 0 8px; background: #fff; }
.font-opt.active { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.colors { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.colors button { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1.5px var(--line); cursor: pointer; }
.colors button.active { box-shadow: 0 0 0 2px var(--brand); }

.center-card { max-width: 520px; margin: 9vh auto; background: #fff; border-radius: 20px; box-shadow: var(--shadow-lg); padding: 40px 36px; text-align: center; }
.center-card .big { width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 20px; }
.center-card .big svg { width: 38px; height: 38px; }
.center-card .big.ok { background: var(--ok-soft); color: var(--ok); }
.center-card .big.info { background: var(--brand-soft); color: var(--brand); }
.center-card .big.bad { background: var(--bad-soft); color: var(--bad); }
.center-card h1 { font-size: 23px; margin-bottom: 10px; }
.center-card p { color: var(--muted); margin: 0 0 8px; }
.msg-quote { text-align: left; white-space: pre-wrap; background: var(--brand-soft); border-left: 3px solid color-mix(in srgb, var(--brand) 40%, #fff); padding: 12px 14px; border-radius: 8px; margin: 16px 0; color: var(--ink-2); }
.foot-note { text-align: center; color: var(--faint); font-size: 12px; padding: 18px; }

.pop-check { animation: popc .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes popc { from { transform: scale(.4); opacity: 0; } }

@media (max-width: 960px) {
  .editor { grid-template-columns: 1fr; height: auto; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .viewer-wrap { height: 80vh; }
  .detail { grid-template-columns: 1fr; }
  .detail .preview { height: 70vh; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .doc-row { grid-template-columns: 40px minmax(0, 1fr) 100px; }
  .doc-row .c-signers, .doc-row .date, .doc-row .c-more { display: none; }
  .container { padding: 18px; }
  .topbar { padding: 0 16px; }
  .topbar .who { display: none; }
}
@media (max-width: 560px) {
  .s-top .hide-sm { display: none; }
  .center-card { margin: 4vh 12px; padding: 32px 22px; }
  .fonts { grid-template-columns: 1fr; }
}

.banner > svg { width: 20px; height: 20px; flex: none; }
.menu-list svg, .tab svg { width: 16px; height: 16px; }
.modal-head > div:first-child { flex: 1; min-width: 0; }

/* ---------- Multi-tenant additions ---------- */
.topnav { display: flex; gap: 4px; margin-left: 18px; }
.topnav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; text-decoration: none !important; }
.topnav a:hover { background: #f3f4f6; color: var(--ink); }
.topnav a.active { color: var(--brand); background: var(--brand-soft); }
.badge-admin { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: #4338ca; background: #eef2ff; padding: 3px 8px; border-radius: 6px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

.cust-row { grid-template-columns: 44px minmax(0, 2fr) minmax(0, 1.3fr) 130px 110px 40px; }
.cust-logo { width: 44px; height: 44px; border-radius: 12px; background: color-mix(in srgb, var(--c) 12%, #fff); color: var(--c); display: grid; place-items: center; font-weight: 700; overflow: hidden; border: 1px solid var(--line); flex: none; }
.cust-logo img { max-width: 86%; max-height: 70%; object-fit: contain; }
.cust-logo.lg { width: 56px; height: 56px; border-radius: 14px; font-size: 20px; }
.detail.wide-left { grid-template-columns: minmax(0, 1fr) 360px; }

.brand-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 28px; align-items: start; }
.logo-box { width: 150px; height: 72px; border: 1.5px dashed var(--line); border-radius: 12px; display: grid; place-items: center; cursor: pointer; background: #fafafa; flex: none; transition: border-color .15s; overflow: hidden; }
.logo-box:hover { border-color: var(--brand); }
.logo-box img { max-width: 86%; max-height: 70%; object-fit: contain; }
.logo-box .hint { display: flex; align-items: center; gap: 6px; }
.logo-box .hint svg { width: 16px; height: 16px; }
.logo-box.busy { opacity: .5; pointer-events: none; }
.color-pick { width: 44px; height: 40px; border: 1px solid #d1d5db; border-radius: 10px; padding: 3px; background: #fff; cursor: pointer; }
.swatches { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.swatches button { width: 22px; height: 22px; border-radius: 6px; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.file-chip { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 10px; border: 1px solid var(--line); border-radius: 10px; }
.file-chip > svg { width: 16px; height: 16px; color: var(--muted); flex: none; }
.file-chip a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-preview { position: sticky; top: 84px; background: #f4f5f9; border-radius: 14px; padding: 16px; --pc: #4f46e5; }
.pv-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); margin: 4px 0 8px; }
.pv-label + * { margin-bottom: 14px; }
.pv-logo { padding: 0 2px 10px; min-height: 30px; }
.pv-logo img { height: 28px; max-width: 180px; object-fit: contain; }
.pv-card { background: #fff; border-radius: 12px; padding: 16px; border-top: 3px solid var(--pc); box-shadow: var(--shadow); font-size: 13px; }
.pv-card p { color: var(--muted); margin: 6px 0 12px; }
.pv-btn { display: inline-block; background: var(--pc); color: #fff; font-weight: 600; font-size: 13px; padding: 8px 14px; border-radius: 8px; }
.pv-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pv-field { border: 2px dashed var(--pc); color: var(--pc); background: color-mix(in srgb, var(--pc) 10%, #fff); font-weight: 700; font-size: 12px; padding: 6px 10px; border-radius: 6px; }
.pv-pill { background: color-mix(in srgb, var(--pc) 12%, #fff); color: var(--pc); font-weight: 600; font-size: 12px; padding: 3px 10px; border-radius: 999px; }

.lead { padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.lead:last-child { border-bottom: 0; }
.lead-top { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }
.meter { height: 4px; border-radius: 4px; background: var(--line-2); margin: 8px 0 6px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; transition: width .2s, background .2s; }
.card-brand { display: flex; justify-content: center; margin-top: 6vh; }
.card-brand + .center-card { margin-top: 24px; }

@media (max-width: 960px) {
  .brand-grid, .detail.wide-left { grid-template-columns: 1fr; }
  .brand-preview { position: static; }
  .cust-row { grid-template-columns: 44px minmax(0, 1fr) 100px; }
  .cust-row > :nth-child(4) { display: none; }
  .topnav { margin-left: 4px; }
  .badge-admin { display: none; }
}
.c-more svg { width: 18px; height: 18px; }
.cust-row { grid-template-columns: 76px minmax(0, 2fr) minmax(0, 1.3fr) 130px 110px 40px; }
.cust-row .cust-logo { width: 76px; }
.cust-logo.lg { width: 96px; }
@media (max-width: 960px) { .cust-row { grid-template-columns: 76px minmax(0, 1fr) 100px; } }
.urow { flex-wrap: wrap; }
.urow .uacts { display: flex; align-items: center; gap: 6px; width: 100%; padding-left: 42px; }
.urow .uacts .pill { margin-right: auto; }
