/* A to Z Fire — Document Signing
   Palette and type follow the A to Z Fire Forms Portal (paper, ink, fire red, Barlow). */

/* ---------- Fonts (self-hosted) ---------- */
@font-face { font-family: 'Barlow'; font-weight: 400; font-style: normal; font-display: swap; src: url('/fonts/barlow-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow'; font-weight: 500; font-style: normal; font-display: swap; src: url('/fonts/barlow-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow'; font-weight: 600; font-style: normal; font-display: swap; src: url('/fonts/barlow-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow'; font-weight: 700; font-style: normal; font-display: swap; src: url('/fonts/barlow-latin-700-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 600; font-style: normal; font-display: swap; src: url('/fonts/barlow-condensed-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 700; font-style: normal; font-display: swap; src: url('/fonts/barlow-condensed-latin-700-normal.woff2') format('woff2'); }
/* Signature styles */
@font-face { font-family: 'AZ Sig 1'; font-display: block; src: url('/fonts/great-vibes-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'AZ Sig 2'; font-display: block; src: url('/fonts/dancing-script-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'AZ Sig 3'; font-display: block; src: url('/fonts/homemade-apple-latin-400-normal.woff2') format('woff2'); }

/* ---------- Tokens ---------- */
:root {
  --ink: #0a0a0a;
  --ink-2: #2a2a2a;
  --muted: #6b6b6b;
  --line: #e6e3dd;
  --line-2: #cdc8be;
  --paper: #faf8f3;
  --paper-2: #f3efe6;
  --card: #ffffff;
  --red: #b91c1c;
  --red-2: #991b1b;
  --red-soft: #fdecec;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --green: #15803d;
  --green-soft: #e7f5ec;
  --blue: #1d4ed8;
  --blue-soft: #e8eefc;
  --gray-soft: #eeebe5;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(10, 10, 10, .04), 0 2px 8px rgba(10, 10, 10, .06);
  --shadow-lg: 0 12px 40px rgba(10, 10, 10, .22);
  --font: 'Barlow', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-head: 'Barlow Condensed', 'Barlow', system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', monospace;
  /* box colors */
  --k-signer: #d97706;
  --k-office: #2563eb;
  --k-auto: #059669;
  --k-sig: #b91c1c;
  --k-ini: #7c3aed;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--paper); }
a { color: var(--red); }
a:hover { color: var(--red-2); }
h1, h2, h3 { font-family: var(--font-head); font-weight: 700; line-height: 1.15; margin: 0 0 .4em; letter-spacing: .01em; }
h1 { font-size: 30px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
p { margin: 0 0 .8em; }
code, .mono { font-family: var(--mono); font-size: .92em; }
code { background: var(--paper-2); padding: 1px 5px; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: #fff; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 700; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.warn-text { color: var(--amber); font-weight: 600; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.inline { display: inline; }
ol.tight { margin: 0; padding-left: 18px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 8px 14px; border: 1px solid var(--line-2); border-radius: 8px; background: #fff; color: var(--ink); font: inherit; font-weight: 600; font-size: 14px; line-height: 1.2; text-decoration: none; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, color .15s, box-shadow .15s; }
.btn:hover { border-color: var(--ink-2); color: var(--ink); }
.btn:focus-visible { outline: 3px solid rgba(185, 28, 28, .35); outline-offset: 1px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-2); border-color: var(--red-2); color: #fff; }
.btn-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-dark:hover { background: var(--ink-2); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--paper-2); border-color: transparent; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: var(--red-2); color: #fff; }
.btn-danger-outline { color: var(--red); border-color: rgba(185, 28, 28, .45); }
.btn-danger-outline:hover { background: var(--red-soft); color: var(--red-2); border-color: var(--red); }
.btn-sm { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.btn-block { display: flex; width: 100%; }
.btn.copied { border-color: var(--green); color: var(--green); }
.btn-primary.copied { background: var(--green); color: #fff; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.btn-row form { margin: 0; }
.linklike { background: none; border: 0; padding: 0; color: var(--red); font: inherit; cursor: pointer; text-decoration: underline; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin: 0; }
.field > span { font-weight: 600; font-size: 13px; color: var(--ink-2); }
.field small { color: var(--muted); font-size: 12px; line-height: 1.35; }
.input { width: 100%; min-height: 40px; padding: 8px 11px; border: 1px solid var(--line-2); border-radius: 8px; background: #fff; color: var(--ink); font: inherit; font-size: 15px; }
.input:focus { outline: none; border-color: var(--ink-2); box-shadow: 0 0 0 3px rgba(10, 10, 10, .08); }
textarea.input { min-height: 120px; resize: vertical; line-height: 1.45; }
select.input { padding-right: 28px; }
.input-xs { width: 64px; min-height: 32px; padding: 4px 8px; }
.check { display: flex; gap: 9px; align-items: flex-start; cursor: pointer; font-size: 14px; }
.check input { margin-top: 3px; width: 17px; height: 17px; flex: none; accent-color: var(--red); }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 18px; }
.form-card { padding: 0; }
.form-section { padding: 20px 22px; border-bottom: 1px solid var(--line); }
.form-section h2 { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.step { width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff; display: inline-grid; place-items: center; font-size: 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; background: var(--paper); border-radius: 0 0 var(--radius) var(--radius); }
.form-error { background: var(--red-soft); color: var(--red-2); border-radius: 8px; padding: 8px 12px; font-size: 14px; margin: 10px 0 0; }
.seg { display: flex; gap: 6px; }
.seg label { flex: 1; display: flex; gap: 6px; align-items: center; justify-content: center; border: 1px solid var(--line-2); border-radius: 8px; padding: 7px; cursor: pointer; font-weight: 600; font-size: 14px; }
.seg input { accent-color: var(--red); }

/* ---------- Staff layout ---------- */
.topbar { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 18px; padding: 8px 22px; background: rgba(255, 255, 255, .97); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); flex: none; }
.brand-logo { height: 36px; width: auto; display: block; }
.brand-sub { font-family: var(--font-head); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; font-size: 13px; color: var(--muted); border-left: 1px solid var(--line); padding-left: 12px; }
.nav { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 8px 12px; border-radius: 8px; color: var(--ink-2); text-decoration: none; font-weight: 600; white-space: nowrap; }
.nav a:hover { background: var(--paper-2); color: var(--ink); }
.nav a.active { background: var(--paper-2); color: var(--red); }
.nav-sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; flex: none; }
.badge { display: inline-block; min-width: 20px; padding: 1px 6px; margin-left: 4px; border-radius: 999px; background: var(--red); color: #fff; font-size: 12px; font-weight: 700; text-align: center; line-height: 18px; }
.usermenu { display: flex; align-items: center; gap: 14px; font-size: 14px; flex: none; }
.usermenu .who { font-weight: 600; }
.usermenu a, .usermenu .linklike { color: var(--muted); text-decoration: none; }
.usermenu a:hover, .usermenu .linklike:hover { color: var(--ink); }
.usermenu form { margin: 0; }

.container { max-width: 1180px; margin: 0 auto; padding: 26px 22px 60px; }
.container.wide { max-width: 1560px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 4px; }
.page-head p { margin: 0; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }
.eyebrow { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.eyebrow a { color: var(--muted); }
.layout-2 { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }

/* ---------- Cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 19px; }
.card-body { padding: 16px 18px; }
.card-foot { padding: 10px 18px 14px; margin: 0; }
.card-accent { border-top: 3px solid var(--red); }
.card-success { border-top: 3px solid var(--green); }
.card-muted { border-top: 3px solid var(--line-2); }
.card-danger .card-head h2 { color: var(--red); }
.narrow { max-width: 560px; }
.center-card { margin: 40px auto; padding: 26px; text-align: center; }
.empty { padding: 34px; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 14px; align-items: center; }
.table-card { overflow-x: auto; }
.callout { display: flex; gap: 12px; align-items: center; padding: 12px 16px; margin-bottom: 16px; border-radius: var(--radius); background: var(--green-soft); border: 1px solid rgba(21, 128, 61, .3); color: var(--ink); text-decoration: none; flex-wrap: wrap; }
.callout strong { color: var(--green); }
.callout:hover { border-color: var(--green); color: var(--ink); }

/* ---------- Alerts / pills ---------- */
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; font-size: 14px; }
.alert-success { background: var(--green-soft); border-color: rgba(21, 128, 61, .3); color: #14532d; }
.alert-error { background: var(--red-soft); border-color: rgba(185, 28, 28, .3); color: var(--red-2); }
.alert-info { background: var(--blue-soft); border-color: rgba(29, 78, 216, .25); color: #1e3a8a; }
.alert-warn { background: var(--amber-soft); border-color: rgba(180, 83, 9, .3); color: #78350f; }
.pw-row { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.pw { font-size: 17px; padding: 4px 10px; background: #fff; border: 1px solid var(--line-2); }
.pill { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; font-family: var(--font); letter-spacing: .01em; border: 1px solid transparent; white-space: nowrap; vertical-align: middle; }
.pill-gray { background: var(--gray-soft); color: #57534e; }
.pill-amber { background: var(--amber-soft); color: #92400e; }
.pill-blue { background: var(--blue-soft); color: #1e40af; }
.pill-green { background: var(--green-soft); color: #166534; }
.pill-red { background: var(--red-soft); color: var(--red-2); }
.pill-new { background: var(--red); color: #fff; }

/* ---------- Tables / tabs / filters ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--paper); }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tr.row-new td { background: #fffaf5; }
.table tr.row-new td:first-child { box-shadow: inset 3px 0 0 var(--red); }
.table tr.row-muted td { opacity: .65; }
.table td.right form { display: inline; }
.docs-cell { max-width: 280px; }
.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filters .input { width: auto; flex: 1; min-width: 180px; }
.filters select.input { flex: 0 1 200px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 9px 12px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--ink); border-bottom-color: var(--red); }
.tabs .count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--gray-soft); font-size: 12px; text-align: center; color: var(--ink-2); }
.tabs a.has-new .count { background: var(--red); color: #fff; }

/* ---------- Menus (details) ---------- */
details.menu { position: relative; display: inline-block; }
details.menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: 270px; padding: 14px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); text-align: left; display: flex; flex-direction: column; gap: 8px; white-space: normal; }
.menu-pop form { margin: 0; }

/* ---------- Folder page ---------- */
.link-box { display: flex; gap: 8px; }
.link-box .input { flex: 1; font-size: 13px; background: var(--paper); }
.status-line { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); font-size: 14px; }
.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.doc-list li:last-child { border-bottom: 0; }
.doc-icon { flex: none; width: 34px; height: 40px; border-radius: 4px; background: var(--red-soft); color: var(--red); font-size: 10px; font-weight: 800; display: grid; place-items: center; border: 1px solid rgba(185, 28, 28, .25); }
.doc-name { flex: 1; min-width: 0; font-weight: 600; }
.doc-actions { display: flex; gap: 6px; flex: none; }
.activity { list-style: none; margin: 0; padding: 6px 18px 10px; }
.activity > li { display: grid; grid-template-columns: 190px minmax(0, 1fr) 120px; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.activity > li:last-child { border-bottom: 0; }
.activity .when { color: var(--muted); font-size: 13px; }
.activity .ip { font-size: 12px; text-align: right; font-family: var(--mono); }
.changes { margin: 4px 0 0; padding-left: 18px; font-size: 13px; }
.changes .from { text-decoration: line-through; color: var(--muted); }
.changes .to { font-weight: 600; }
.facts { display: grid; grid-template-columns: 100px minmax(0, 1fr); gap: 8px 10px; margin: 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

/* ---------- New folder ---------- */
.bundle-picks { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.chip { border: 1px solid var(--line-2); background: #fff; border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.chip:hover { border-color: var(--ink-2); }
.chip-on { border-color: var(--red); background: var(--red-soft); }
.template-picks { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.pick-group { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px 12px; margin: 0; }
.pick-group legend { font-family: var(--font-head); font-weight: 700; font-size: 15px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 0 6px; }
.pick { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 2px 8px; padding: 8px; border-radius: 8px; cursor: pointer; }
.pick:hover { background: var(--paper); }
.pick input { grid-row: span 2; width: 18px; height: 18px; margin-top: 2px; accent-color: var(--red); }
.pick-name { font-weight: 600; }
.pick-meta { font-size: 12px; color: var(--muted); }
.picked { margin-top: 16px; }
.picked h3 { font-size: 15px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.picked-list { margin: 0; padding-left: 22px; }
.picked-list li { padding: 2px 0; }
.picked-list li > * { vertical-align: middle; }
.picked-list .grow { display: inline-block; min-width: 240px; font-weight: 600; }

/* ---------- Bundles admin ---------- */
.bundle-rows { display: flex; flex-direction: column; gap: 4px; max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.bundle-row { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.bundle-row:hover { background: var(--paper); }
.bundle-row input[type=checkbox] { accent-color: var(--red); width: 16px; height: 16px; }

/* ---------- Templates admin ---------- */
.upload-form { display: grid; grid-template-columns: 1.4fr 1fr 1fr auto; gap: 14px; align-items: end; }

/* ---------- Auth ---------- */
body.auth { background: linear-gradient(180deg, var(--paper) 0%, var(--paper-2) 100%); }
body.auth .container { min-height: 90vh; display: flex; align-items: center; justify-content: center; }
.auth-card { width: 100%; max-width: 400px; padding: 30px; text-align: left; border-top: 4px solid var(--red); }
.auth-logo { display: block; height: 64px; margin: 0 auto 10px; }
.auth-card h1 { text-align: center; margin-bottom: 0; }
.auth-card > .muted { text-align: center; margin-bottom: 18px; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200; max-width: calc(100vw - 32px); padding: 11px 18px; border-radius: 10px; background: var(--ink); color: #fff; font-weight: 600; font-size: 14px; box-shadow: var(--shadow-lg); }
.toast.error { background: var(--red); }
body.signing .toast { bottom: 96px; }

/* ---------- Document viewer (prefill / sign / edit) ---------- */
.loading { padding: 40px; text-align: center; color: var(--muted); }
.doc-stack { max-width: 920px; margin: 0 auto; }
.doc { margin: 0 0 30px; }
.doc-head { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; }
.doc-num { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.doc-head h2 { margin: 0; font-size: 21px; flex: 1; min-width: 0; }
.doc-meta { color: var(--muted); font-size: 13px; white-space: nowrap; }
.pdf-page { position: relative; width: 100%; margin: 0 auto 16px; background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow); }
.pdf-page:not(.drawn) { background: repeating-linear-gradient(135deg, #fff 0, #fff 12px, #f7f5f0 12px, #f7f5f0 24px); }
.pdf-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: block; }
.field-layer { position: absolute; top: 0; left: 0; right: 0; bottom: 0; pointer-events: none; }
.field-layer > * { pointer-events: auto; }

.fld { position: absolute; margin: 0; }
.fld-text { font-family: Helvetica, Arial, sans-serif; line-height: 1.15; padding: 0 .2em; border: 1px solid; border-radius: 2px; color: #111; outline: none; resize: none; overflow: hidden; -webkit-appearance: none; appearance: none; min-height: 0; }
textarea.fld-text { line-height: 1.2; padding-top: .1em; overflow: auto; }
.fld-text.owner-signer { border-color: rgba(217, 119, 6, .7); background: rgba(254, 243, 199, .6); }
.fld-text.owner-office { border-color: rgba(37, 99, 235, .6); background: rgba(232, 238, 252, .7); }
.fld-text:focus { background: #fff; box-shadow: 0 0 0 2px rgba(29, 78, 216, .45); }
.fld-text::placeholder { color: rgba(0, 0, 0, .35); }
.fld-show { font-family: Helvetica, Arial, sans-serif; line-height: 1.15; padding: 0 .2em; display: flex; align-items: center; white-space: nowrap; overflow: hidden; color: #111; }
.fld-show.multi { align-items: flex-start; white-space: pre-wrap; padding-top: .1em; }
.fld-show.auto { color: #047857; background: rgba(209, 250, 229, .5); border: 1px dashed rgba(5, 150, 105, .6); font-style: italic; }
.fld-show.locked { background: rgba(0, 0, 0, .03); border: 1px dashed rgba(0, 0, 0, .25); }
.fld-sigph { display: flex; align-items: center; justify-content: center; border: 1px dashed rgba(185, 28, 28, .6); background: rgba(253, 236, 236, .65); color: var(--red); font-size: 11px; font-weight: 700; overflow: hidden; white-space: nowrap; }
.fld-sigph.type-initials { border-color: rgba(124, 58, 237, .6); background: rgba(237, 233, 254, .65); color: #6d28d9; }
.fld-sigshow img { width: 100%; height: 100%; object-fit: contain; display: block; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin: 0 auto 16px; max-width: 920px; }
.key { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.key::before { content: ''; width: 16px; height: 11px; border-radius: 2px; border: 1.5px solid; }
.key-office::before { border-color: var(--k-office); background: rgba(37, 99, 235, .15); }
.key-signer::before { border-color: var(--k-signer); background: rgba(217, 119, 6, .18); }
.key-auto::before { border-color: var(--k-auto); border-style: dashed; background: rgba(5, 150, 105, .15); }
.key-sig::before { border-color: var(--k-sig); border-style: dashed; background: rgba(185, 28, 28, .12); }
.key-locked::before { border-color: rgba(0, 0, 0, .3); border-style: dashed; background: rgba(0, 0, 0, .04); }

.fill-head { position: sticky; top: 53px; z-index: 30; display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; margin: -26px -22px 18px; padding: 14px 22px; background: rgba(250, 248, 243, .97); border-bottom: 1px solid var(--line); }
.fill-head h1 { margin: 0; font-size: 26px; }
.save-status { font-size: 13px; color: var(--muted); }
.save-status.error { color: var(--red); font-weight: 600; }

/* ---------- Template editor ---------- */
.editor { display: grid; grid-template-columns: 200px minmax(0, 1fr) 290px; gap: 18px; align-items: start; }
.tools, .props { position: sticky; top: 140px; max-height: calc(100vh - 160px); overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.tools-title { font-family: var(--font-head); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; font-size: 13px; color: var(--muted); margin: 4px 0 8px; }
.tools-title:not(:first-child) { margin-top: 18px; }
.tool { display: flex; width: 100%; align-items: center; gap: 10px; padding: 8px 10px; margin-bottom: 6px; border: 1px solid var(--line-2); border-radius: 8px; background: #fff; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; text-align: left; }
.tool:hover { border-color: var(--ink-2); }
.tool.active { border-color: var(--red); background: var(--red-soft); box-shadow: 0 0 0 2px rgba(185, 28, 28, .2); }
.tool-sm { font-size: 13px; padding: 6px 10px; }
.tool-swatch { width: 30px; height: 22px; border-radius: 4px; display: grid; place-items: center; font-size: 12px; font-weight: 800; border: 1.5px solid; flex: none; }
.sw-text { border-color: var(--k-signer); color: var(--k-signer); background: rgba(217, 119, 6, .1); }
.sw-sig { border-color: var(--k-sig); color: var(--k-sig); background: rgba(185, 28, 28, .08); }
.sw-ini { border-color: var(--k-ini); color: var(--k-ini); background: rgba(124, 58, 237, .08); }
.tools-help { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.tools-keys { margin-top: 16px; display: flex; flex-direction: column; gap: 4px; }
.editor-pages { min-width: 0; padding-top: 6px; }
.editor .pdf-page { margin-top: 26px; max-width: 900px; }
.editor .field-layer { pointer-events: auto; }
.editor.placing .field-layer { cursor: crosshair; }
.page-tag { position: absolute; top: -22px; left: 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.efld { position: absolute; display: flex; align-items: center; padding: 0 4px; border: 1.5px solid; border-radius: 3px; font-size: 11px; font-weight: 700; line-height: 1.1; overflow: hidden; cursor: move; user-select: none; -webkit-user-select: none; touch-action: none; }
.efld.k-signer { border-color: var(--k-signer); background: rgba(217, 119, 6, .16); color: #92400e; }
.efld.k-office { border-color: var(--k-office); background: rgba(37, 99, 235, .14); color: #1e40af; }
.efld.k-auto { border-color: var(--k-auto); background: rgba(5, 150, 105, .14); color: #065f46; }
.efld.k-signature { border-color: var(--k-sig); background: rgba(185, 28, 28, .12); color: var(--red-2); }
.efld.k-initials { border-color: var(--k-ini); background: rgba(124, 58, 237, .12); color: #5b21b6; justify-content: center; }
.efld.optional { border-style: dashed; }
.efld.selected { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ink); z-index: 2; }
.efld-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.efld-handle { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; background: var(--ink); border-radius: 3px 0 2px 0; cursor: nwse-resize; opacity: 0; }
.efld:hover .efld-handle, .efld.selected .efld-handle { opacity: 1; }
.props h3 { margin-top: 2px; }
.stats { list-style: none; padding: 0; margin: 0 0 12px; }
.stats li { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.swatch { width: 14px; height: 10px; border-radius: 2px; border: 1.5px solid; flex: none; }
.swatch.k-signer { border-color: var(--k-signer); background: rgba(217, 119, 6, .18); }
.swatch.k-office { border-color: var(--k-office); background: rgba(37, 99, 235, .15); }
.swatch.k-auto { border-color: var(--k-auto); background: rgba(5, 150, 105, .15); }
.swatch.k-signature { border-color: var(--k-sig); background: rgba(185, 28, 28, .12); }
.swatch.k-initials { border-color: var(--k-ini); background: rgba(124, 58, 237, .12); }

/* ---------- Public pages ---------- */
body.public { background: var(--paper); }
.ptop { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 18px; background: #fff; border-bottom: 3px solid var(--red); }
.ptop-logo { height: 42px; width: auto; display: block; }
.ptop-sub { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 600; }
.pmain { max-width: 960px; margin: 0 auto; padding: 20px 12px 40px; }
.pfoot { text-align: center; padding: 18px 16px 30px; font-size: 13px; color: var(--ink-2); }
.pfoot p { margin: 0 0 4px; }
body.signing .pfoot { padding-bottom: 110px; }
.pcard { background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 26px 24px; max-width: 560px; margin: 24px auto; }
.message-card { border-top: 4px solid var(--blue); text-align: center; }
.message-card.is-error { border-top-color: var(--red); }
.done-card { border-top: 4px solid var(--green); }
.done-card h1 { text-align: center; }
.done-card > p:first-of-type { text-align: center; }
.done-card h2 { margin-top: 18px; }
.done-check { width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 50%; background: var(--green); color: #fff; font-size: 36px; font-weight: 700; display: grid; place-items: center; }

/* ---------- Signing page ---------- */
.sign-intro { max-width: 920px; margin: 0 auto 18px; padding: 18px 20px; background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--red); border-radius: var(--radius); }
.sign-intro h1 { font-size: 26px; margin-bottom: 6px; }
.sign-intro p { margin-bottom: 6px; }
.sign-doclist { margin: 0 0 6px; padding-left: 22px; font-weight: 600; }
.sign-docs .doc-head h2 { font-size: 19px; }

.fld-sig { display: flex; align-items: center; justify-content: center; gap: 4px; padding: 0; border: 2px solid #f59e0b; border-radius: 4px; background: #fef3c7; color: #92400e; font: inherit; cursor: pointer; overflow: visible; -webkit-tap-highlight-color: transparent; }
.fld-sig .tag { font-family: var(--font-head); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; line-height: 1; white-space: nowrap; }
.fld-sig.type-signature .tag::before { content: '✍ '; }
.fld-sig .opt { font-size: 10px; color: var(--muted); }
.fld-sig:not(.req):not(.applied) { border-style: dashed; background: rgba(254, 243, 199, .5); }
.fld-sig:hover:not(.applied) { background: #fde68a; }
.fld-sig.applied { border: 1px dashed transparent; background: transparent; }
.fld-sig.applied:hover, .fld-sig.applied.armed { border-color: rgba(0, 0, 0, .25); }
.fld-sig.applied img { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }
.fld-sig .unapply { position: absolute; top: -11px; right: -11px; width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 15px; line-height: 22px; text-align: center; font-weight: 700; display: none; }
.fld-sig.applied.armed .unapply { display: block; }
body.signing .fld-text.req { border: 2px solid #f59e0b; background: rgba(254, 243, 199, .85); }
body.signing .fld.done.fld-text { border: 1px solid rgba(21, 128, 61, .55); background: rgba(231, 245, 236, .55); }
body.signing .fld-show.office { background: transparent; }
.fld.pulse { animation: pulse 1.3s ease-out; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(185, 28, 28, .7); }
  100% { box-shadow: 0 0 0 18px rgba(185, 28, 28, 0); }
}

.sign-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: flex; align-items: center; gap: 10px; padding: 10px 16px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); background: rgba(255, 255, 255, .97); border-top: 1px solid var(--line); box-shadow: 0 -4px 22px rgba(0, 0, 0, .09); }
.sign-bar .btn { min-height: 46px; padding: 10px 20px; font-size: 16px; }
.sign-progress { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; }
.sign-progress .bar { height: 6px; margin-top: 6px; border-radius: 3px; background: var(--gray-soft); overflow: hidden; }
.sign-progress .bar i { display: block; width: 0; height: 100%; background: var(--green); transition: width .3s ease; }
@media (min-width: 960px) {
  .sign-bar { left: 50%; right: auto; bottom: 16px; width: 900px; transform: translateX(-50%); border: 1px solid var(--line); border-radius: 14px; padding-bottom: 10px; }
}

/* Dialogs */
.modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 14px; background: rgba(10, 10, 10, .55); }
.modal-card { width: 100%; max-width: 500px; max-height: calc(100vh - 28px); overflow: auto; padding: 22px; border-radius: 14px; background: #fff; box-shadow: var(--shadow-lg); -webkit-overflow-scrolling: touch; }
.modal-wide { max-width: 660px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
body.modal-open { overflow: hidden; }
.consent-check { padding: 12px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--paper); font-size: 14px; line-height: 1.45; }
.disclosure { margin-top: 12px; font-size: 14px; }
.disclosure summary { cursor: pointer; color: var(--red); font-weight: 600; }
.disclosure ul { margin: 8px 0 0; padding-left: 20px; color: var(--ink-2); }
.adopt-names { display: grid; grid-template-columns: minmax(0, 1fr) 120px; gap: 12px; margin-bottom: 14px; }
.seg-tabs { display: flex; gap: 4px; padding: 4px; margin-bottom: 14px; background: var(--paper-2); border-radius: 10px; }
.seg-tab { flex: 1; padding: 9px; border: 0; border-radius: 8px; background: transparent; font: inherit; font-weight: 700; font-size: 15px; cursor: pointer; color: var(--muted); }
.seg-tab.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.styles { display: flex; flex-direction: column; gap: 8px; }
.style-card { display: block; cursor: pointer; }
.style-card input { position: absolute; opacity: 0; pointer-events: none; }
.style-body { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 76px; padding: 8px 16px; border: 2px solid var(--line); border-radius: 10px; background: #fff; color: #1b2a6b; overflow: hidden; }
.style-card input:checked + .style-body { border-color: var(--red); background: #fffaf9; box-shadow: 0 0 0 3px rgba(185, 28, 28, .12); }
.style-card input:focus-visible + .style-body { outline: 3px solid rgba(185, 28, 28, .35); }
.style-sig { font-size: 38px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.style-ini { font-size: 30px; white-space: nowrap; flex: none; padding-left: 14px; border-left: 1px solid var(--line); }
.pad-wrap { margin-bottom: 12px; }
.pad-label { display: flex; justify-content: space-between; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.pad { display: block; width: 100%; height: 170px; border: 1px solid var(--line-2); border-radius: 10px; background: #fff linear-gradient(to top, transparent 34px, rgba(0, 0, 0, .12) 34px, rgba(0, 0, 0, .12) 35px, transparent 35px); touch-action: none; }
.pad-wrap-ini { max-width: 260px; }
.pad-ini { height: 120px; }
.adopt-legal { color: var(--ink-2); margin: 10px 0 0; }

/* Phone typing sheet (sits at the top so the keyboard never covers it) */
.field-sheet { position: fixed; top: 0; left: 0; right: 0; z-index: 60; padding: 12px 14px 12px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); background: #fff; border-bottom: 3px solid var(--red); border-radius: 0 0 14px 14px; box-shadow: 0 8px 28px rgba(0, 0, 0, .2); }
.fs-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.fs-head label { font-weight: 700; font-size: 15px; }
.fs-head span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fs-input { font-size: 16px; }
textarea.fs-input { min-height: 84px; }
.fs-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.fld-text.tap-edit { cursor: pointer; }
.fld-text.editing { box-shadow: 0 0 0 3px rgba(29, 78, 216, .55); background: #fff; }
body.sheet-open .ptop { visibility: hidden; }

/* ---------- Responsive ---------- */
@media (max-width: 1240px) {
  .brand-sub { display: none; }
  .nav a { padding: 8px 10px; }
}
@media (max-width: 1180px) {
  .editor { grid-template-columns: minmax(0, 1fr) 270px; }
  .tools { grid-column: 1 / -1; position: static; max-height: none; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 10px 12px; }
  .tools .tool { width: auto; margin: 0; }
  .tools-title { margin: 0 4px 0 6px; }
  .tools-title:not(:first-child) { margin-top: 0; margin-left: 14px; }
  .tools-help, .tools-keys { display: none; }
  .props { top: 140px; }
}
@media (max-width: 900px) {
  .layout-2 { grid-template-columns: minmax(0, 1fr); }
  .upload-form { grid-template-columns: 1fr; }
  .editor { grid-template-columns: minmax(0, 1fr); }
  .props { position: static; max-height: none; }
  .activity > li { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .activity .ip { text-align: left; }
}
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; padding: 8px 12px; position: static; }
  .brand-sub { display: none; }
  .nav { order: 3; width: 100%; flex: none; }
  .usermenu { margin-left: auto; gap: 10px; }
  .usermenu .who { display: none; }
  .container { padding: 18px 12px 50px; }
  .fill-head { top: 0; margin: -18px -12px 14px; padding: 10px 12px; }
  h1 { font-size: 26px; }
  .table th, .table td { padding: 10px; }
  .docs-cell { display: none; }
  .link-box { flex-direction: column; }
}
@media (max-width: 560px) {
  .ptop { padding: 8px 12px; }
  .ptop-logo { height: 34px; }
  .ptop-sub { font-size: 12px; }
  .pmain { padding: 12px 6px 30px; }
  .sign-intro { padding: 14px; border-radius: 8px; }
  .sign-intro h1 { font-size: 22px; }
  .pdf-page { margin-bottom: 10px; }
  .doc-head { padding: 0 4px; }
  .fld-sig .tag { font-size: 10px; letter-spacing: .02em; }
  .sign-bar { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .sign-bar .btn { padding: 10px 14px; font-size: 15px; }
  .sign-progress { font-size: 13px; }
  .modal { padding: 8px; align-items: flex-end; }
  .modal-card { padding: 18px 16px; border-radius: 14px 14px 10px 10px; max-height: calc(100vh - 16px); }
  .adopt-names { grid-template-columns: minmax(0, 1fr) 90px; }
  .style-sig { font-size: 30px; }
  .style-ini { font-size: 24px; }
  .pad { height: 150px; }
  .pcard { padding: 20px 16px; margin: 12px auto; }
}
