:root {
  --paper: #F6F7F9;
  --surface: #FFFFFF;
  --ink: #1A2233;
  --ink-2: #4A5468;
  --ink-3: #7A8396;
  --rule: #DCE0E7;
  --rule-2: #EDF0F4;
  --pen: #1F45C4;
  --pen-soft: #E8EDFB;
  --seal: #1D7650;
  --seal-soft: #E3F2EA;
  --wax: #B23A2F;
  --wax-soft: #F8E7E5;
  --amber: #8A5A00;
  --amber-soft: #FBF1DC;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 6px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--pen); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 24px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 18px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0 0 .8em; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }

/* ---------- Buttons and inputs ---------- */
button, .btn {
  font: inherit; font-size: 14px; font-weight: 550; border-radius: var(--radius); border: 1px solid var(--rule);
  background: var(--surface); color: var(--ink); padding: 7px 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; line-height: 1.3;
}
button:hover, .btn:hover { border-color: #BCC3CF; }
button:disabled { opacity: .55; cursor: default; }
.primary { background: var(--pen); border-color: var(--pen); color: #fff; }
.primary:hover { filter: brightness(1.08); border-color: var(--pen); }
.danger { color: var(--wax); }
.danger.solid { background: var(--wax); border-color: var(--wax); color: #fff; }
.link { border: 0; background: none; padding: 0; color: var(--pen); font-weight: 500; }
.ms { background: #fff; border-color: #8C93A0; }
.ms svg { width: 16px; height: 16px; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 0 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--rule); border-radius: var(--radius); background: #fff; color: var(--ink);
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--pen); box-shadow: 0 0 0 3px var(--pen-soft); }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 140px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); font-size: 14px; }
.check input { width: 16px; height: 16px; accent-color: var(--pen); }
.error { background: var(--wax-soft); color: var(--wax); padding: 10px 12px; border-radius: var(--radius); white-space: pre-wrap; font-size: 14px; margin-bottom: 14px; }
.note { background: var(--amber-soft); color: var(--amber); padding: 10px 12px; border-radius: var(--radius); font-size: 14px; margin-bottom: 14px; }

/* ---------- Sign-in screens ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-side { background: var(--ink); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side .mark { font-weight: 700; font-size: 18px; }
.auth-side blockquote { margin: 0; font-family: var(--serif); font-size: 30px; line-height: 1.3; max-width: 16em; }
.auth-side .sig { font-family: var(--serif); font-style: italic; font-size: 34px; color: #9DB3FF; border-bottom: 1px solid #56607A; display: inline-block; padding: 0 30px 2px 4px; margin-top: 28px; }
.auth-side .muted { color: #A3ACBE; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-box { width: 100%; max-width: 380px; }
.auth-box h1 { margin-bottom: 6px; }
.auth-box .sub { color: var(--ink-3); margin-bottom: 24px; }
.or { display: flex; align-items: center; gap: 12px; color: var(--ink-3); font-size: 13px; margin: 18px 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--rule); }
.wide { width: 100%; justify-content: center; padding: 10px 14px; }
@media (max-width: 820px) { .auth { grid-template-columns: 1fr; } .auth-side { display: none; } }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--rule); padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .org { padding: 4px 10px 16px; }
.side .org strong { display: block; font-size: 15px; }
.side .org span { font-size: 12px; color: var(--ink-3); }
.side .new { margin: 0 4px 14px; justify-content: center; }
.nav { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-radius: var(--radius); color: var(--ink-2); text-decoration: none; font-size: 14px; font-weight: 500; }
.nav:hover { background: var(--rule-2); }
.nav.on { background: var(--pen-soft); color: var(--pen); font-weight: 600; }
.nav .n { font-size: 12px; color: var(--ink-3); }
.nav.on .n { color: var(--pen); }
.side .group { font-size: 12px; color: var(--ink-3); padding: 16px 10px 4px; }
.side .me { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--rule-2); font-size: 13px; }
.side .me div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { padding: 28px 32px 60px; min-width: 0; }
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.topbar { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; position: fixed; inset: 0 25% 0 0; z-index: 30; height: auto; box-shadow: 0 0 0 100vmax rgba(26, 34, 51, .35); }
  .side.open { display: flex; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 20; }
  .main { padding: 20px 16px 60px; }
}

/* ---------- Tables and lists ---------- */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 10px 14px; border-bottom: 1px solid var(--rule); background: #FBFBFC; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--rule-2); vertical-align: middle; font-size: 14px; }
  .table select { width: auto; min-width: 120px; padding: 6px 8px; }
.table tr:last-child td { border-bottom: 0; }
.table tr.click { cursor: pointer; }
.table tr.click:hover td { background: #FAFBFD; }
.table .t { font-weight: 600; }
.scroll { overflow-x: auto; }
.empty { background: var(--surface); border: 1px dashed var(--rule); border-radius: var(--radius); padding: 40px 24px; text-align: center; color: var(--ink-2); }
.empty h2 { color: var(--ink); }
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.searchbar { max-width: 320px; }

.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--rule-2); color: var(--ink-2); white-space: nowrap; }
.pill.draft { background: var(--rule-2); color: var(--ink-2); }
.pill.sent, .pill.viewed, .pill.invited { background: var(--amber-soft); color: var(--amber); }
.pill.completed, .pill.signed, .pill.active { background: var(--seal-soft); color: var(--seal); }
.pill.declined, .pill.voided, .pill.expired, .pill.disabled, .pill.suspended { background: var(--wax-soft); color: var(--wax); }
.pill.waiting { background: var(--rule-2); color: var(--ink-3); }
.progress { display: inline-flex; gap: 3px; vertical-align: middle; margin-right: 6px; }
.progress i { width: 14px; height: 4px; border-radius: 2px; background: var(--rule); }
.progress i.done { background: var(--seal); }

/* ---------- The paper ---------- */
.paper {
  background: #fff; border: 1px solid var(--rule); box-shadow: 0 1px 0 var(--rule), 0 8px 24px -16px rgba(26, 34, 51, .25);
  max-width: 760px; margin: 0 auto; padding: 64px 72px; font-family: var(--serif); font-size: 17px; line-height: 1.65; color: #1E2433; min-height: 600px;
}
.paper h1 { font-family: var(--serif); font-size: 30px; font-weight: 600; letter-spacing: -.01em; margin: 0 0 .6em; }
.paper h2 { font-family: var(--serif); font-size: 22px; font-weight: 600; margin: 1.2em 0 .4em; }
.paper h3 { font-family: var(--serif); font-size: 18px; font-weight: 600; margin: 1em 0 .3em; }
.paper p { margin: 0 0 .9em; }
.paper ul, .paper ol { padding-left: 1.4em; }
.paper[contenteditable] { outline: none; cursor: text; }
.paper[contenteditable]:focus { border-color: #C3CADA; }
@media (max-width: 860px) { .paper { padding: 32px 22px; font-size: 16px; min-height: 360px; } }

/* Fields on the paper: pen-blue ink tabs */
.slot { font-family: var(--sans); font-size: .82em; display: inline-block; padding: 1px 8px; border-radius: 4px; background: var(--pen-soft); color: var(--pen); border-bottom: 2px solid var(--pen); font-weight: 600; vertical-align: baseline; line-height: 1.5; }
.slot.filled { background: transparent; color: var(--ink); border-bottom: 1px solid #9AA3B5; font-family: var(--serif); font-size: 1em; font-weight: 500; padding: 0 2px; border-radius: 0; }
.slot.mine { background: #FFF6D6; color: #6B4E00; border-bottom-color: #E0A800; }
.slot.other { background: var(--rule-2); color: var(--ink-3); border-bottom-color: #B3BAC7; }
.slot.missing { background: var(--wax-soft); color: var(--wax); border-bottom-color: var(--wax); }
.sigbox { display: inline-flex; flex-direction: column; min-width: 220px; padding: 4px 4px 0; border-bottom: 1px solid #6E778A; vertical-align: bottom; margin: 6px 0; }
.sigbox img { height: 46px; max-width: 240px; object-fit: contain; object-position: left; }
.sigbox .typed { font-family: var(--serif); font-style: italic; font-size: 28px; color: #13308F; line-height: 1.2; }
.sigbox small { font-family: var(--sans); font-size: 11px; color: var(--ink-3); padding-top: 2px; }
.raw-ph { color: var(--pen); background: var(--pen-soft); border-radius: 3px; padding: 0 2px; font-family: var(--sans); font-size: .85em; }
.raw-if { color: var(--seal); background: var(--seal-soft); border-radius: 3px; padding: 0 2px; font-family: var(--sans); font-size: .85em; }

/* ---------- Editor ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 22px; align-items: start; }
.editor-left { min-width: 0; }
.titlebar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.titlebar input { font-size: 20px; font-weight: 650; border-color: transparent; background: transparent; padding: 4px 8px; flex: 1; min-width: 200px; }
.titlebar input:hover { border-color: var(--rule); }
.saved { font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.toolbar { display: flex; gap: 4px; flex-wrap: wrap; position: sticky; top: 0; z-index: 5; background: var(--paper); padding: 6px 0 10px; max-width: 760px; margin: 0 auto; }
.toolbar button { padding: 5px 10px; font-size: 13px; }
.toolbar .sep { width: 1px; background: var(--rule); margin: 2px 4px; }
.toolbar .on { background: var(--ink); color: #fff; border-color: var(--ink); }
.dock { position: sticky; top: 16px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.tabs { display: flex; border-bottom: 1px solid var(--rule); overflow-x: auto; flex-shrink: 0; }
.tabs button { border: 0; border-radius: 0; background: none; padding: 11px 9px; font-size: 13px; color: var(--ink-3); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--pen); }
.dock-body { padding: 16px; overflow-y: auto; }
.fcard { border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.fcard .top { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.fcard .top input { font-weight: 600; }
.fcard .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.fcard code, .code { font-family: var(--mono); font-size: 12px; background: var(--rule-2); padding: 1px 5px; border-radius: 3px; }
.who { flex-shrink: 0; display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.rcard { border: 1px solid var(--rule); border-radius: var(--radius); padding: 10px; margin-bottom: 8px; display: grid; grid-template-columns: 44px 1fr; gap: 8px; }
.rcard .step { font-size: 11px; color: var(--ink-3); text-align: center; }
.rcard .step input { text-align: center; padding: 6px 2px; }
.ai-out { white-space: pre-wrap; background: var(--rule-2); border-radius: var(--radius); padding: 12px; font-size: 14px; margin-top: 12px; }
@media (max-width: 1100px) { .editor { grid-template-columns: 1fr; } .dock { position: static; max-height: none; } }

/* ---------- Document detail ---------- */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 22px; align-items: start; }
@media (max-width: 1100px) { .detail { grid-template-columns: 1fr; } }
.steps { list-style: none; padding: 0; margin: 0; }
.steps li { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--rule-2); align-items: start; }
.steps li:last-child { border-bottom: 0; }
.steps .num { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; background: var(--rule-2); color: var(--ink-2); }
.steps .num.done { background: var(--seal); color: #fff; }
.trail { font-size: 13px; }
.trail div { overflow-wrap: anywhere; padding: 6px 0; border-bottom: 1px solid var(--rule-2); }
.trail time { color: var(--ink-3); font-size: 12px; display: block; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Toast and modal ---------- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: var(--radius); font-size: 14px; z-index: 100; max-width: 90vw; }
.modal-bg { position: fixed; inset: 0; background: rgba(26, 34, 51, .45); display: grid; place-items: center; z-index: 90; padding: 16px; }
.modal { background: #fff; border-radius: 8px; padding: 22px; width: 100%; max-width: 460px; max-height: 90vh; overflow: auto; }
.modal .actions { justify-content: flex-end; margin-top: 18px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- Signer page ---------- */
.sign-top { background: var(--surface); border-bottom: 1px solid var(--rule); padding: 12px 24px; display: flex; justify-content: space-between; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 10; }
.sign-top strong { font-size: 15px; }
.sign-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; padding: 24px; max-width: 1200px; margin: 0 auto; align-items: start; }
.sign-panel { position: sticky; top: 76px; }
@media (max-width: 960px) { .sign-wrap { grid-template-columns: 1fr; padding: 16px; } .sign-panel { position: static; order: -1; } }
.center-box { max-width: 440px; margin: 60px auto; padding: 0 16px; }
.pad { border: 1px solid var(--rule); border-radius: var(--radius); background: #fff; touch-action: none; width: 100%; height: 140px; display: block; cursor: crosshair; }
.typed-preview { font-family: var(--serif); font-style: italic; font-size: 30px; color: #13308F; border-bottom: 1px solid #6E778A; padding: 4px; min-height: 52px; }
.codebox { font-size: 26px; letter-spacing: .4em; text-align: center; font-family: var(--mono); }
