:root {
  --ink: #0a0e1a; --muted: #1f2f4a; --subtle: #3d4f6e; --line: #e2e8f0; --line-strong: #cbd5e1;
  --bg: #ffffff; --bg-soft: #f6f9fb; --blue: #0e2e5a; --blue-mid: #2b6cb0; --sky: #e6f0f8;
  --green: #2d8c4f; --mint: #ecf7e6; --red: #c0392b; --red-soft: #fdecea; --amber-soft: #fff6e0;
  --radius: 12px; --shadow: 0 1px 2px rgba(14,46,90,.04), 0 4px 12px rgba(14,46,90,.06);
  --font: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif; --display: "Inter Tight", var(--font);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg-soft); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.5; }
h1, h2 { font-family: var(--display); letter-spacing: -0.01em; margin: 0 0 12px; }
h1 { font-size: 26px; } h2 { font-size: 18px; }
a { color: var(--blue-mid); }
button, input { font: inherit; }
label { display: block; font-size: 13px; color: var(--subtle); margin-bottom: 12px; }
label input, label textarea { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: var(--ink); font-size: 15px; }
input:focus { outline: 2px solid var(--blue-mid); outline-offset: 0; border-color: transparent; }
.muted { color: var(--subtle); } .small { font-size: 13px; }
.error { color: var(--red); font-size: 14px; }
.container { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.ok { border-color: var(--green); background: var(--mint); }
.card.warn { border-color: #e7c35a; background: var(--amber-soft); }
.card.error { border-color: var(--red); background: var(--red-soft); color: var(--ink); }
.narrow { max-width: 380px; margin: 48px auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .grid2 { grid-template-columns: 1fr; } }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 18px; border-radius: 8px; border: 1px solid transparent; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 42px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #12407c; }
.btn-success { background: var(--green); color: #fff; }
.btn-ghost { background: #fff; color: var(--blue); border-color: var(--line-strong); }
.btn-block { width: 100%; margin-top: 8px; }
.link { background: none; border: 0; color: var(--blue-mid); cursor: pointer; padding: 0; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg-soft); color: var(--muted); border: 1px solid var(--line); }
.s-sent, .s-viewed { background: var(--sky); color: var(--blue); border-color: #c7dcef; }
.s-completed { background: var(--mint); color: #0f6b3a; border-color: #cfe9c3; }
.s-cancelled { background: var(--red-soft); color: var(--red); border-color: #f3c9c3; }
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 12px; color: var(--subtle); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 50; }
.toast.err { background: var(--red); }
.pre { white-space: pre-wrap; background: var(--bg-soft); padding: 12px; border-radius: 8px; font-size: 13px; }
code { font-size: 12px; word-break: break-all; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.copy { display: flex; gap: 8px; margin-top: 4px; } .copy input { margin: 0; }

/* top bars */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 700; color: var(--ink); text-decoration: none; }
.topbar nav { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); text-decoration: none; font-weight: 500; }

/* pages + fields */
.pages { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 16px 0 120px; }
.page { position: relative; background: #fff; box-shadow: 0 2px 10px rgba(14,46,90,.12); }
.page canvas { display: block; }
.field { position: absolute; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 12px; overflow: hidden; }
.field.edit { border: 1.5px dashed; cursor: move; background: rgba(43,108,176,.10); color: var(--blue); user-select: none; touch-action: none; }
.field.edit.c-sender { background: rgba(45,140,79,.12); color: #0f6b3a; }
.field.edit.selected { border-style: solid; }
.field.edit .x { position: absolute; top: -1px; right: -1px; border: 0; background: var(--ink); color: #fff; width: 18px; height: 18px; border-radius: 0 4px 0 6px; cursor: pointer; line-height: 1; }
.field.todo { border: 2px solid var(--red); background: rgba(192,57,43,.08); color: var(--red); font-weight: 600; cursor: pointer; }
.field.done { border: 1.5px solid var(--green); background: rgba(45,140,79,.06); cursor: pointer; }
.field.locked { border: 1px dashed var(--line-strong); background: transparent; }
.field img { max-width: 100%; max-height: 100%; }
.field input { width: 100%; height: 100%; border: 0; background: transparent; padding: 0 4px; font-size: 12px; }
.field.text-value { justify-content: flex-start; padding-left: 3px; color: var(--ink); }
.field.pulse { animation: pulse 1.2s ease-out 2; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(192,57,43,.55); } 100% { box-shadow: 0 0 0 14px rgba(192,57,43,0); } }
.adding .page { cursor: crosshair; }
.chip { border: 1px solid var(--line-strong); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; margin: 0 6px 6px 0; }
.chip.c-client { border-color: #9fc9e8; color: var(--blue); }
.chip.c-sender { border-color: #a4d65e; color: #0f6b3a; }
.tools { margin: 8px 0 12px; }

/* admin editor */
.editor { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.editor-side { position: sticky; top: 16px; }
@media (max-width: 1000px) { .editor { grid-template-columns: 1fr; } .editor-side { position: static; } }
.sigpad { width: 100%; height: 180px; border: 1px dashed var(--line-strong); border-radius: 8px; background: #fff; touch-action: none; display: block; }
.sig-preview { display: block; max-height: 70px; margin: 8px 0 12px; }

/* signer */
.signbar { position: sticky; top: 0; z-index: 20; background: #fff; border-bottom: 1px solid var(--line); }
.signbar-inner { max-width: 900px; margin: 0 auto; display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.signbar-title { flex: 1; min-width: 0; }
.signbar-title #doc-title { font-family: var(--display); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.signbar-title #doc-sub { font-size: 13px; }
.progress { height: 3px; background: var(--line); } .progress div { height: 100%; width: 0; background: var(--green); transition: width .3s; }
.state-card { max-width: 520px; margin: 48px auto; text-align: center; }
.modal { position: fixed; inset: 0; background: rgba(10,14,26,.5); display: flex; align-items: flex-end; justify-content: center; z-index: 40; }
.modal[hidden] { display: none; }
.modal-box { background: #fff; width: 100%; max-width: 560px; border-radius: 16px 16px 0 0; padding: 20px; max-height: 92vh; overflow: auto; }
@media (min-width: 640px) { .modal { align-items: center; } .modal-box { border-radius: 16px; } }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button { flex: 1; padding: 10px; border: 1px solid var(--line-strong); background: #fff; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tabs button.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.typed-preview { height: 110px; display: flex; align-items: center; justify-content: center; border: 1px dashed var(--line-strong); border-radius: 8px; font-family: "Caveat", cursive; font-size: 48px; color: var(--ink); overflow: hidden; }
.code-input { font-size: 28px !important; letter-spacing: 8px; text-align: center; }
.check { display: flex; gap: 10px; align-items: flex-start; color: var(--ink); font-size: 14px; }
.check input { width: 20px; height: 20px; margin-top: 2px; flex: none; }
.field.edit.c-sender.signed { background: rgba(45,140,79,.04); border-style: solid; }
.field.edit.signed img { pointer-events: none; }
.field.edit.signed .value { color: var(--ink); font-size: 11px; }
.signbox { border: 1px solid #a4d65e; background: var(--mint); border-radius: 10px; padding: 12px; margin-top: 12px; display: flex; flex-direction: column; gap: 4px; }
.signbox.ok { color: #0f6b3a; }
.signbox .link { align-self: flex-start; margin-top: 2px; }
.field.edit.signed .x { opacity: 0; transition: opacity .15s; }
.field.edit.signed:hover .x, .field.edit.signed.selected .x { opacity: 1; }
