:root {
  --bg: #f6f7f9; --panel: #fff; --text: #14181f; --muted: #667085; --line: #e3e6eb;
  --brand: #2563eb; --brand-ink: #fff; --danger: #c62828; --ok: #1b8a3b; --warn: #b26a00;
  --field: rgba(37, 99, 235, .14); --field-line: #2563eb; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 14px rgba(16,24,40,.06);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1218; --panel: #171b23; --text: #e8ebf0; --muted: #98a2b3; --line: #2a303b;
    --brand: #5b8cff; --brand-ink: #0b1020; --field: rgba(91,140,255,.2); --field-line: #5b8cff; --shadow: none; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 4px; } h2 { font-size: 16px; margin: 0 0 10px; } h3 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.top { display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 54px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.logo { font-weight: 700; font-size: 17px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.logo i { width: 22px; height: 22px; background: var(--brand); border-radius: 6px; display: inline-block; }
.top nav { display: flex; gap: 14px; flex: 1; } .top nav a { color: var(--muted); } .top nav a.on { color: var(--text); font-weight: 600; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 24px 16px 60px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } .grow { flex: 1; } .gap { margin-top: 16px; }
.muted { color: var(--muted); } .err { color: var(--danger); }
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 7px 13px; border-radius: 7px; cursor: pointer; display: inline-block; }
button:hover:not(:disabled) { border-color: var(--brand); } button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.danger { color: var(--danger); } button.sm { padding: 3px 9px; font-size: 12px; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
input[type=checkbox], input[type=radio] { width: auto; }
label.f { display: block; margin: 9px 0; font-size: 13px; color: var(--muted); } label.f > input, label.f > select, label.f > textarea { margin-top: 3px; color: var(--text); }
table { width: 100%; border-collapse: collapse; } th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; } tr.click { cursor: pointer; } tr.click:hover td { background: var(--bg); }
.badge { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--bg); border: 1px solid var(--line); }
.badge.COMPLETED, .badge.SIGNED { color: var(--ok); } .badge.PENDING, .badge.SENT, .badge.OPENED { color: var(--warn); }
.badge.REJECTED, .badge.CANCELLED { color: var(--danger); } .badge.DRAFT, .badge.NOT_SIGNED { color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; } .tabs a.on { color: var(--text); border-color: var(--brand); font-weight: 600; }
.auth { max-width: 380px; margin: 9vh auto; }
.empty { text-align: center; padding: 40px; color: var(--muted); }
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; }
.toast { background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; box-shadow: var(--shadow); } .toast.bad { background: var(--danger); color: #fff; }
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); padding: 20px; max-width: 520px; width: calc(100% - 32px); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }

/* editor + signing layout */
.editor > * { min-width: 0; }
.editor { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
@media (max-width: 880px) { .editor { grid-template-columns: 1fr; } }
.side { position: sticky; top: 70px; max-height: calc(100vh - 86px); overflow: auto; }
.pages { display: grid; gap: 14px; justify-items: center; }
.page { position: relative; box-shadow: var(--shadow); background: #fff; max-width: 100%; touch-action: pan-y; }
.page canvas { display: block; width: 100%; height: auto; }
.page.place { cursor: crosshair; }
.fld { position: absolute; background: var(--field); border: 1.5px solid var(--field-line); border-radius: 3px; font-size: 11px; color: var(--text); display: flex; align-items: center; justify-content: center; overflow: hidden; user-select: none; cursor: move; }
.fld .tag { position: absolute; top: 0; left: 0; font-size: 9px; padding: 0 3px; background: var(--field-line); color: var(--brand-ink); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.fld .x { position: absolute; top: 0; right: 0; width: 16px; height: 16px; line-height: 14px; padding: 0; border: 0; background: var(--danger); color: #fff; border-radius: 0 0 0 4px; font-size: 12px; cursor: pointer; }
.fld .rs { position: absolute; right: 0; bottom: 0; width: 10px; height: 10px; background: var(--field-line); cursor: nwse-resize; }
.fld.todo { cursor: pointer; background: rgba(255, 193, 7, .25); border-color: #e0a800; animation: pulse 1.6s infinite; }
.fld.done { background: rgba(27,138,59,.12); border-color: var(--ok); cursor: pointer; }
.fld.other { background: rgba(120,120,120,.12); border-color: #999; cursor: default; }
.fld img { max-width: 100%; max-height: 100%; } .fld input, .fld select, .fld textarea { height: 100%; border-radius: 0; padding: 0 4px; font-size: 12px; background: #fff; color: #111; }
@keyframes pulse { 50% { background: rgba(255,193,7,.45); } }
.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; } .palette button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.rcp { border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-bottom: 8px; } .rcp.sel { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.rcp .row > * { min-width: 0; }
.bar { position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--line); padding: 10px 16px; display: flex; gap: 10px; align-items: center; justify-content: center; z-index: 15; }
.sigpad { border: 1px dashed var(--line); background: #fff; border-radius: 8px; width: 100%; height: 160px; touch-action: none; display: block; }
.typed { font: italic 34px "Segoe Script", "Brush Script MT", cursive; text-align: center; }

body.embed { background: transparent; }
body.embed .bar { position: static; }
