@font-face { font-family: "Caveat"; src: url("/static/fonts/Caveat.ttf") format("truetype"); font-weight: 400 700; font-display: swap; }
:root {
  --bg: #F2F4F7; --surface: #FFFFFF; --ink: #14171C; --muted: #5A6472; --line: #DADFE6;
  --accent: #3347D6; --accent-ink: #FFFFFF; --accent-soft: #E6EAFC;
  --ok: #17794A; --ok-soft: #DDF3E7; --warn: #8A5A00; --warn-soft: #FBEBC8; --bad: #B3261E; --bad-soft: #FBE3E1;
  --paper-ink: #1B1F27;
  --fld-bg: #FFF1B8; --fld-line: #D9A400; --fld-ink: #4A3A00;
  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-script: "Caveat", "Segoe Script", "Brush Script MT", cursive;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1116; --surface: #161B22; --ink: #E8ECF2; --muted: #9AA4B2; --line: #29313C;
    --accent: #8FA0FF; --accent-ink: #0C1240; --accent-soft: #1F2650;
    --ok: #5FD08F; --ok-soft: #163A28; --warn: #E3A94B; --warn-soft: #3A2C0B; --bad: #FF8A80; --bad-soft: #3D1614;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.5; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
a { color: var(--accent); }

.app { max-width: 1000px; margin: 0 auto; padding: 20px 16px 72px; }
.top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand { font-family: var(--font-display); font-weight: 700; font-size: 1.4rem; letter-spacing: -0.02em; }
.brand small { font-family: var(--font-body); font-weight: 500; font-size: 12px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; margin-left: 8px; }
.topRight { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.tabs button { border: 0; background: transparent; border-radius: 6px; padding: 7px 14px; font-weight: 600; font-size: 14px; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
.badge { display: inline-block; min-width: 20px; text-align: center; margin-left: 6px; padding: 0 6px; border-radius: 999px; font-size: 12px; background: var(--warn-soft); color: var(--warn); }
.banner { margin: 0 0 14px; padding: 8px 12px; border: 1px dashed var(--warn); background: var(--warn-soft); color: var(--warn); border-radius: 6px; font-size: 13px; }

h1, h2 { margin: 0; font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; letter-spacing: -0.01em; }
h3 { margin: 0; font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; }
.note { margin: 0; font-size: 13.5px; color: var(--muted); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 20px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; align-items: center; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 8px 14px; font-weight: 600; font-size: 14px; text-decoration: none; color: var(--ink); display: inline-block; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }

.stepper { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.stepper button { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 14px 5px 6px; font-size: 14px; font-weight: 500; color: var(--muted); }
.stepper .n { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--bg); font-size: 12px; font-weight: 600; }
.stepper button[aria-current="step"] { color: var(--ink); border-color: var(--accent); }
.stepper button[aria-current="step"] .n { background: var(--accent); color: var(--accent-ink); }
.stepper button:disabled { opacity: 0.5; cursor: default; }

.drop { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 30px 16px; border: 2px dashed var(--line); border-radius: 8px; text-align: center; cursor: pointer; }
.drop:hover, .drop.over, .drop:focus-within { border-color: var(--accent); background: var(--accent-soft); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.filecard { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 12px 14px; border: 1px solid var(--ok); background: var(--ok-soft); border-radius: 8px; }
.filecard b { overflow-wrap: anywhere; }
.opt { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); cursor: pointer; }
.opt input { margin-top: 4px; accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.opt strong { display: block; }

.palette { display: flex; flex-wrap: wrap; gap: 8px; }
.palette .btn[aria-pressed="true"] { background: var(--fld-bg); border-color: var(--fld-line); color: var(--fld-ink); }
.docs { display: flex; flex-direction: column; gap: 28px; }
.docBlock { display: flex; flex-direction: column; gap: 10px; }
.pages { display: flex; flex-direction: column; gap: 14px; }
.pageWrap { width: 100%; max-width: 640px; margin: 0 auto; }
.docBlock.small .pageWrap { max-width: 420px; }
.page { position: relative; width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 3px; box-shadow: 0 2px 14px rgba(0,0,0,0.14); overflow: hidden; container-type: inline-size; }
.page canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.page.tooling { cursor: crosshair; }
.pageNum { text-align: center; font-size: 12px; color: var(--muted); margin-top: 4px; }

.fld { position: absolute; display: flex; align-items: center; gap: 4px; padding: 0 6px; background: var(--fld-bg); border: 1px solid var(--fld-line); border-radius: 3px; color: var(--fld-ink); font-size: clamp(10px, 2cqw, 13px); font-weight: 500; touch-action: none; user-select: none; white-space: nowrap; overflow: hidden; }
.page.editing .fld { cursor: grab; }
.fld.drag { cursor: grabbing; box-shadow: 0 4px 12px rgba(0,0,0,0.25); z-index: 2; }
.fld .lab { overflow: hidden; text-overflow: ellipsis; }
.fld .x { margin-left: auto; border: 0; background: transparent; color: var(--fld-ink); font-size: 15px; line-height: 1; padding: 0 2px; }
.fld .grip { position: absolute; right: 0; bottom: 0; width: 10px; height: 10px; cursor: nwse-resize; background: linear-gradient(135deg, transparent 50%, var(--fld-line) 50%); }
.fld.locked { background: rgba(255,241,184,0.55); }

/* signer-side fields */
.sfld { position: absolute; display: flex; align-items: stretch; min-height: 24px; background: var(--fld-bg); border: 1px solid var(--fld-line); border-radius: 3px; color: var(--fld-ink); font-size: clamp(11px, 2.1cqw, 14px); }
.sfld.done { background: transparent; border-color: transparent; border-radius: 0; }
.sfld.done:hover, .sfld.done:focus-within { background: rgba(51,71,214,0.07); }
.sfld.flash { outline: 3px solid var(--accent); outline-offset: 2px; }
.sfld input[type="text"], .sfld input[type="email"], .sfld input[type="tel"] { width: 100%; border: 0; background: transparent; padding: 0 6px; color: var(--paper-ink); font-size: inherit; min-width: 0; }
.sfld input::placeholder { color: var(--fld-ink); opacity: 0.85; }
.sfld .sigbtn { width: 100%; min-width: 0; border: 0; background: transparent; color: var(--fld-ink); font-weight: 600; text-align: left; padding: 0 6px; font-size: inherit; display: flex; align-items: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sfld .sigbtn.val { color: var(--paper-ink); font-weight: 400; align-items: flex-end; padding-bottom: 1px; font-size: clamp(8px, 1.8cqw, 13px); }
.sfld.sig { min-height: 34px; }
.sfld .sigbtn img { height: 100%; max-width: 100%; display: block; object-fit: contain; object-position: left bottom; }
.sfld .dateval { display: flex; align-items: flex-end; padding: 0 6px 1px; color: var(--paper-ink); white-space: nowrap; font-size: clamp(8px, 1.8cqw, 13px); }
.sfld label { display: flex; align-items: center; justify-content: center; width: 100%; }
.sfld label input { accent-color: var(--accent); width: 16px; height: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .lbl { font-weight: 600; font-size: 14px; }
textarea, input.tx, select.tx { width: 100%; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); padding: 9px 11px; font-size: 14.5px; }
textarea { resize: vertical; min-height: 110px; }
textarea.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 13.5px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13px; padding: 2px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); overflow-wrap: anywhere; }
.chip.bad { border-color: var(--bad); color: var(--bad); }
.info { margin: 0; padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 6px 6px 0; font-size: 14px; }
.err { margin: 0; padding: 10px 12px; border-left: 3px solid var(--bad); background: var(--bad-soft); color: var(--bad); border-radius: 0 6px 6px 0; font-size: 14px; }

.sum { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.pill { display: inline-block; font-size: 12.5px; font-weight: 600; padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.pill.Signed { background: var(--ok-soft); color: var(--ok); }
.pill.Opened { background: var(--accent-soft); color: var(--accent); }
.pill.Sent { background: var(--warn-soft); color: var(--warn); }
.pill.Bounced { background: var(--bad-soft); color: var(--bad); }
.pill.All { background: var(--surface); border: 1px solid var(--line); color: var(--ink); }
.batch { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px; display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; min-width: 0; }
.batchSide { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.tog { display: flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.tog input { accent-color: var(--accent); width: 16px; height: 16px; }
.bar { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.em { overflow-wrap: anywhere; min-width: 180px; }
td.when { color: var(--muted); white-space: nowrap; }
.acts { display: flex; gap: 6px; flex-wrap: nowrap; align-items: center; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

.modalBack { position: fixed; inset: 0; z-index: 60; background: rgba(8,10,14,0.55); display: grid; place-items: center; padding: 16px; }
.modal { width: 100%; max-width: 460px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 55; width: min(420px, 100%); background: var(--surface); border-left: 1px solid var(--line); box-shadow: -8px 0 30px rgba(0,0,0,0.25); padding: 20px; display: flex; flex-direction: column; gap: 14px; overflow: auto; }
.events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; border-left: 2px solid var(--line); margin-left: 6px; }
.events li { padding-left: 14px; position: relative; overflow-wrap: anywhere; }
.events li::before { content: ""; position: absolute; left: -6px; top: 7px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.events time { display: block; font-size: 12.5px; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 80; max-width: calc(100% - 32px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; font-weight: 500; }

/* signature adoption */
.segs { display: flex; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 3px; align-self: flex-start; }
.segs button { border: 0; background: transparent; border-radius: 6px; padding: 5px 14px; font-weight: 600; font-size: 13.5px; color: var(--muted); }
.segs button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }
.sigprev { min-height: 74px; display: grid; place-items: center; border-bottom: 1px solid var(--ink); font-family: var(--font-script); font-size: 2.3rem; font-weight: 600; color: #11235E; overflow: hidden; padding: 0 8px; background: #fff; border-radius: 6px 6px 0 0; }
.drawpad { width: 100%; height: 150px; background: #fff; border: 1px solid var(--line); border-radius: 6px; touch-action: none; display: block; cursor: crosshair; }

/* signing page */
.sbar { position: sticky; top: 0; z-index: 20; display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.sbody { width: 100%; max-width: 720px; margin: 0 auto; padding: 18px 16px 110px; display: flex; flex-direction: column; gap: 20px; }
.sfoot { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); background: var(--surface); border-top: 1px solid var(--line); }
.donePanel { text-align: center; padding: 36px 16px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.donePanel .tick { width: 56px; height: 56px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: grid; place-items: center; font-size: 28px; font-weight: 700; }
.login { max-width: 380px; margin: 10vh auto 0; padding: 0 16px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* full-size document viewer */
.viewer { position: fixed; inset: 0; z-index: 70; background: rgba(8,10,14,0.82); display: flex; flex-direction: column; }
.viewerBar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.viewerBody { flex: 1; overflow: auto; padding: 20px 16px 40px; }
.viewer .pageWrap { max-width: none; }

/* Sent tab on phones: each signer becomes a stacked card */
@media (max-width: 620px) {
  .batch .tablewrap { overflow: visible; }
  .batch table, .batch tbody, .batch tr, .batch td { display: block; }
  .batch thead { display: none; }
  .batch tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .batch tr:last-child { border-bottom: 0; }
  .batch td { padding: 0; border: 0; }
  .batch td.em { min-width: 0; }
  .batch td:last-child { grid-column: 1 / -1; }
  .batch .acts { flex-wrap: wrap; }
  .batchSide { width: 100%; justify-content: space-between; }
}
