:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --line: #e2e5ec;
  --text: #1c2030;
  --muted: #6b7183;
  --accent: #3b5bdb;
  --accent-soft: #e8edff;
  --danger: #d6336c;
  --ok: #2b8a3e;
  --warn: #e8590c;
  --radius: 10px;
  --sig-font: "Snell Roundhand", "Segoe Script", "Apple Chancery", "Brush Script MT", cursive;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 1.25rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; word-break: break-all; }

header.top {
  display: flex; align-items: center; gap: 1rem;
  padding: .75rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 1.1rem; text-decoration: none; color: var(--text); display: flex; align-items: center; gap: .5rem; }
.brand .logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: .9rem; }
.spacer { flex: 1; }

button, .btn {
  font: inherit; font-size: .9rem; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: .5rem .9rem; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .4rem;
}
button:hover, .btn:hover { border-color: #c5cad6; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.ghost { border-color: transparent; background: transparent; }

input[type=text], input[type=email], input[type=password], textarea {
  font: inherit; font-size: .9rem; width: 100%; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
input:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.check { display: flex; gap: .5rem; align-items: flex-start; font-size: .9rem; cursor: pointer; }

main.wrap { max-width: 980px; margin: 2rem auto; padding: 0 1.25rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }

table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: .75rem; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: .5rem; border-bottom: 1px solid var(--line); }
table.list td { padding: .75rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover td { background: #fafbfd; }

.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; text-transform: capitalize; background: #eef0f4; color: var(--muted); }
.badge.sent, .badge.viewed { background: #fff4e6; color: var(--warn); }
.badge.completed, .badge.signed { background: #ebfbee; color: var(--ok); }
.badge.voided, .badge.declined { background: #fff0f6; color: var(--danger); }

.dropzone {
  border: 2px dashed #c5cad6; border-radius: var(--radius); padding: 2.5rem; text-align: center; background: #fafbfd; cursor: pointer;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- editor ---------- */
.editor { display: grid; grid-template-columns: 300px 1fr; height: calc(100vh - 57px); }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 1rem; overflow-y: auto; }
.viewer { overflow-y: auto; padding: 1.5rem; }
.signer-row { border: 1px solid var(--line); border-radius: 8px; padding: .5rem; margin-bottom: .5rem; display: grid; gap: .35rem; cursor: pointer; }
.signer-row.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.signer-row .head { display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.tools button { justify-content: flex-start; font-size: .85rem; }
.tools button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.pages { display: flex; flex-direction: column; align-items: center; gap: 1.25rem; }
.page { position: relative; background: #fff; box-shadow: 0 1px 4px rgba(20, 25, 40, .15); }
.page canvas { display: block; width: 100%; height: 100%; }
.page .overlay { position: absolute; inset: 0; }
.page .pageno { position: absolute; right: -2.25rem; top: 0; font-size: .75rem; color: var(--muted); }
.placing .overlay { cursor: crosshair; }

.field {
  position: absolute; border: 1.5px solid; border-radius: 4px; font-size: 11px; display: flex; align-items: center; padding: 0 4px;
  overflow: hidden; white-space: nowrap; user-select: none; touch-action: none;
}
.editor .field { cursor: move; }
.field .x { position: absolute; top: 0; right: 0; border: 0; padding: 0 4px; background: transparent; font-size: 12px; line-height: 1; cursor: pointer; display: none; }
.field:hover .x, .field.selected .x { display: block; }
.field .grip { position: absolute; right: 0; bottom: 0; width: 10px; height: 10px; cursor: nwse-resize; background: currentColor; opacity: .5; clip-path: polygon(100% 0, 100% 100%, 0 100%); }
.field.selected { box-shadow: 0 0 0 2px rgba(59, 91, 219, .35); }

/* ---------- signer ---------- */
.signbar { position: sticky; top: 57px; z-index: 15; background: #1c2030; color: #fff; padding: .7rem 1.25rem; display: flex; align-items: center; gap: 1rem; }
.signbar button { border-color: #3a4057; background: #2a2f44; color: #fff; }
.signbar button.primary { background: var(--accent); border-color: var(--accent); }
.signdoc .field { cursor: pointer; background: rgba(255, 212, 59, .25); border-color: #f59f00; color: #8a5a00; }
.signdoc .field.done { background: rgba(43, 138, 62, .06); border-color: rgba(43, 138, 62, .45); color: var(--text); }
.signdoc .field.focus { box-shadow: 0 0 0 3px rgba(245, 159, 0, .55); }
.signdoc .field img { max-width: 100%; max-height: 100%; }
.signdoc .field input[type=text] { border: 0; padding: 0 2px; height: 100%; background: transparent; font-size: inherit; outline: none; }
.signdoc .field input[type=checkbox] { margin: auto; width: 70%; height: 70%; }
.signdoc .field .req { position: absolute; top: -1px; left: 2px; color: var(--danger); font-size: 10px; }

.modal-back { position: fixed; inset: 0; background: rgba(20, 25, 40, .5); display: grid; place-items: center; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: min(640px, 94vw); padding: 1.25rem; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin: .75rem 0; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; }
.tabs button.on { border-bottom-color: var(--accent); color: var(--accent); }
.pad { border: 1px solid var(--line); border-radius: 8px; width: 100%; height: 180px; background: #fff; touch-action: none; cursor: crosshair; display: block; }
.typed { font-family: var(--sig-font); font-size: 46px; height: 180px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; color: #142060; overflow: hidden; }
.actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }
.toast { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); background: #1c2030; color: #fff; padding: .6rem 1rem; border-radius: 8px; z-index: 60; font-size: .9rem; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .5rem 0; border-bottom: 1px solid var(--line); font-size: .88rem; display: grid; grid-template-columns: 170px 1fr; gap: .75rem; }
.linkbox { display: flex; gap: .4rem; margin-top: .35rem; }
.linkbox input { font-family: ui-monospace, Menlo, monospace; font-size: .75rem; }

/* ---------- sign in & account menu ---------- */
.wrap.narrow { max-width: 420px; }
.auth { display: flex; flex-direction: column; gap: .75rem; }
.auth h1, .auth h2 { margin: 0; }
.auth p { margin: 0; }
.form-row { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; font-weight: 600; }
.form-error { color: var(--danger); font-size: .85rem; min-height: 1em; }
.form-error:empty { display: none; }
.auth button.primary { padding: .6rem; }
#userMenu { margin-left: .5rem; }
.menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: .45rem; }
.avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: .75rem; }
.menu-panel { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(20, 24, 40, .12); padding: .75rem; min-width: 220px; z-index: 50; display: flex; flex-direction: column; gap: .2rem; }
.menu-panel[hidden] { display: none; }
.menu-panel hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: .4rem 0; }
.menu-panel button { text-align: left; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 24, 40, .45); display: grid; place-items: center; z-index: 100; }
.modal-card { background: var(--panel); border-radius: var(--radius); padding: 1.25rem; width: min(400px, 92vw); }
.row-end { display: flex; justify-content: flex-end; gap: .5rem; }
