:root {
  --bg: #f5f5f4; --card: #fff; --ink: #1c1917; --muted: #78716c; --line: #e7e5e4;
  --accent: #1c1917; --accent-ink: #fff; --danger: #b91c1c; --ok: #15803d; --warn: #b45309;
  --s0: #2563eb; --s1: #db2777; --s2: #059669; --s3: #d97706; --s4: #7c3aed;
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
a { color: inherit; }
button, .btn {
  font: inherit; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  padding: 8px 14px; border-radius: 6px; cursor: pointer; text-decoration: none; display: inline-block;
}
button.ghost, .btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
button.danger { background: transparent; color: var(--danger); border-color: var(--line); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; width: 100%; background: #fff; color: var(--ink); }
input[type=checkbox] { width: auto; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--ink); }
label.check { display: flex; gap: 8px; align-items: flex-start; color: var(--ink); font-size: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 24px; }
.narrow { max-width: 420px; width: 100%; }
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.error { color: var(--danger); }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.hidden { display: none !important; }

header.top { display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--line); }
header.top strong { flex: 1; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 24px 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; }
td, th { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fafaf9; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--line); white-space: nowrap; }
.badge.out { background: #fef3c7; color: var(--warn); }
.badge.completed { background: #dcfce7; color: var(--ok); }
.badge.declined, .badge.cancelled { background: #fee2e2; color: var(--danger); }
.timeline { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.timeline li { padding: 6px 0; border-bottom: 1px dashed var(--line); }

/* PDF pages and field boxes */
.pages { display: flex; flex-direction: column; gap: 16px; }
.page { position: relative; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15); width: 100%; user-select: none; }
.page canvas { width: 100%; height: 100%; display: block; }
.field { position: absolute; border: 2px solid var(--c, var(--s0)); background: color-mix(in srgb, var(--c, var(--s0)) 12%, transparent);
  border-radius: 3px; font-size: 11px; color: var(--c, var(--s0)); display: flex; align-items: center; justify-content: center;
  overflow: hidden; cursor: move; touch-action: none; }
.field.selected { outline: 2px solid var(--ink); outline-offset: 1px; }
.field .grip { position: absolute; right: -2px; bottom: -2px; width: 10px; height: 10px; background: var(--c, var(--s0)); cursor: nwse-resize; }
.placing .page { cursor: crosshair; }

.editor { display: grid; grid-template-columns: 260px 1fr; gap: 16px; align-items: start; }
.editor aside { position: sticky; top: 16px; }
.palette button { width: 100%; margin-bottom: 6px; text-align: left; }
.palette button.on { outline: 3px solid var(--s0); }
@media (max-width: 800px) { .editor { grid-template-columns: 1fr; } .editor aside { position: static; } }

/* Signing */
.sign-field { position: absolute; border: 2px dashed var(--s0); background: rgba(37,99,235,.08); border-radius: 3px; display: flex;
  align-items: center; justify-content: center; font-size: 12px; color: var(--s0); cursor: pointer; overflow: hidden; }
.sign-field.done { border-style: solid; background: transparent; }
.sign-field.req::after { content: "*"; position: absolute; top: -2px; right: 2px; color: var(--danger); }
.sign-field input[type=text] { border: 0; background: transparent; padding: 0 2px; height: 100%; border-radius: 0; }
.sign-field img, .filled img { max-width: 100%; max-height: 100%; }
.filled { position: absolute; display: flex; align-items: center; overflow: hidden; color: #111; }
.bar { position: sticky; bottom: 0; background: var(--card); border-top: 1px solid var(--line); padding: 12px 16px; z-index: 5; }
.bar .inner { max-width: 900px; margin: 0 auto; }
.signdoc { max-width: 900px; margin: 0 auto; padding: 16px; }
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 20px; width: min(640px, 95vw); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs button { background: transparent; color: var(--ink); border-color: var(--line); }
.tabs button.on { background: var(--accent); color: var(--accent-ink); }
.pad { width: 100%; height: 200px; border: 1px solid var(--line); border-radius: 6px; touch-action: none; background: #fff; display: block; }
.typed-preview { font: italic 48px cursive; min-height: 80px; padding: 8px 0; overflow: hidden; white-space: nowrap; }
#docs { margin-top: 16px; }
