:root {
  --brand: #0b3954;
  --brand-2: #12507a;
  --accent: #087e8b;
  --accent-2: #066d78;
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-2: #f7f9fa;
  --border: #dce3e8;
  --border-2: #c7d1d8;
  --text: #1d2a33;
  --muted: #5b6770;
  --faint: #8a98a3;
  --ok: #2b8a3e;
  --ok-bg: #e6f4ea;
  --warn: #a8650b;
  --warn-bg: #fdf3e1;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --info: #1f63b5;
  --info-bg: #e7f0fb;
  --shadow: 0 1px 2px rgba(16, 38, 56, .06), 0 4px 14px rgba(16, 38, 56, .06);
  --radius: 8px;
  --field-me: #ffd84d;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); }
body { min-height: 100vh; line-height: 1.45; }
a { color: var(--accent); }
h1, h2, h3 { color: var(--brand); margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: .85rem; }
.mono { font-family: Consolas, "SFMono-Regular", Menlo, monospace; font-size: .82rem; word-break: break-all; }
.hidden { display: none !important; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.grow { flex: 1 1 auto; }
.right { margin-left: auto; }
.center { text-align: center; }

/* ------------------------------------------------------------ top bar */
.topbar {
  background: var(--brand); color: #fff; display: flex; align-items: center; gap: 1.5rem;
  padding: 0 1.25rem; height: 56px; position: sticky; top: 0; z-index: 50;
}
.topbar .brand { font-weight: 700; font-size: 1.1rem; letter-spacing: .2px; color: #fff; text-decoration: none; display: flex; align-items: center; gap: .5rem; }
.topbar .brand .logo { width: 26px; height: 26px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; font-size: .8rem; }
.topbar .brand small { font-weight: 400; opacity: .75; font-size: .8rem; }
.topbar nav { display: flex; gap: .25rem; }
.topbar nav a { color: rgba(255,255,255,.82); text-decoration: none; padding: .45rem .75rem; border-radius: 6px; font-size: .92rem; }
.topbar nav a:hover, .topbar nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.topbar .user { margin-left: auto; display: flex; align-items: center; gap: .75rem; font-size: .9rem; }
.topbar .user button { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.35); }

.page { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.page.wide { max-width: 1440px; }

/* ------------------------------------------------------------ cards, tables */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.card + .card { margin-top: 1rem; }
.card h2 { margin-bottom: .75rem; }
.card.flush { padding: 0; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 0 0 .75rem; }

table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; padding: .6rem .9rem; border-bottom: 1px solid var(--border); background: var(--surface-2); }
table.list td { padding: .7rem .9rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: #f6fafb; }
table.list tr:last-child td { border-bottom: none; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); cursor: pointer; }
.stat .n { font-size: 1.7rem; font-weight: 700; color: var(--brand); }
.stat .l { color: var(--muted); font-size: .88rem; }
.stat.active { outline: 2px solid var(--accent); }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs button { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: .6rem .9rem; color: var(--muted); font-weight: 600; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--accent); }

/* ------------------------------------------------------------ forms */
button, .btn {
  font: inherit; font-size: .92rem; font-weight: 600; cursor: pointer; border-radius: 6px; padding: .5rem 1rem;
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text); text-decoration: none; display: inline-flex; align-items: center; gap: .4rem; line-height: 1.2;
}
button:hover, .btn:hover { background: var(--surface-2); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover, .btn.primary:hover { background: var(--accent-2); }
button.danger { color: var(--danger); border-color: #e6b3ad; }
button.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; color: var(--accent); }
button.ghost:hover { background: rgba(8,126,139,.08); }
button.small, .btn.small { padding: .3rem .6rem; font-size: .82rem; }
button.big { padding: .75rem 1.6rem; font-size: 1rem; }
label { font-weight: 600; font-size: .86rem; color: var(--muted); display: block; margin-bottom: .25rem; }
label.inline { display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; color: var(--text); margin: 0; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=tel], input[type=date], input[type=search], select, textarea {
  font: inherit; font-size: .95rem; width: 100%; padding: .5rem .65rem; border: 1px solid var(--border-2); border-radius: 6px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid rgba(8,126,139,.45); outline-offset: 1px; border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
.field { margin-bottom: .9rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1rem; }
.help { font-size: .8rem; color: var(--faint); margin-top: .25rem; }

.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.badge.draft { background: #eef1f3; color: #55636d; }
.badge.sent, .badge.delivered { background: var(--info-bg); color: var(--info); }
.badge.completed { background: var(--ok-bg); color: var(--ok); }
.badge.declined { background: var(--danger-bg); color: var(--danger); }
.badge.voided { background: #e9ecef; color: #495057; }
.badge.expired { background: var(--warn-bg); color: var(--warn); }
.badge.completing { background: #efe7fb; color: #6a3fb5; }
.badge.created { background: #eef1f3; color: #6c7a84; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

.notice { border-radius: 6px; padding: .7rem .9rem; font-size: .9rem; margin-bottom: 1rem; border: 1px solid transparent; }
.notice.info { background: var(--info-bg); color: #164a86; border-color: #c8dbf3; }
.notice.warn { background: var(--warn-bg); color: #7a4a08; border-color: #f3dcb0; }
.notice.error { background: var(--danger-bg); color: #8d2a20; border-color: #f2c4be; }
.notice.ok { background: var(--ok-bg); color: #1f6a30; border-color: #bfe3c8; }
.notice ul { margin: .3rem 0 0 1.1rem; padding: 0; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty .big { font-size: 2.2rem; margin-bottom: .5rem; }

/* ------------------------------------------------------------ toasts, modal */
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 300; }
.toast { background: var(--brand); color: #fff; padding: .7rem 1rem; border-radius: 6px; box-shadow: var(--shadow); max-width: 380px; font-size: .9rem; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
.modal-back { position: fixed; inset: 0; background: rgba(13, 30, 43, .45); display: grid; place-items: center; z-index: 200; padding: 1rem; }
.modal { background: #fff; border-radius: 10px; width: min(560px, 100%); max-height: calc(100vh - 2rem); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(760px, 100%); }
.modal header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal header h2 { margin: 0; }
.modal .body { padding: 1.25rem; }
.modal footer { padding: .9rem 1.25rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .5rem; background: var(--surface-2); }

/* ------------------------------------------------------------ login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(135deg, #0b3954 0%, #087e8b 100%); }
.login-card { width: min(400px, 100%); background: #fff; border-radius: 12px; padding: 2rem; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-card .brandmark { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.25rem; }
.login-card .brandmark .logo { width: 38px; height: 38px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; }

/* ------------------------------------------------------------ editor */
.steps { display: flex; gap: .5rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.steps button { border-radius: 999px; padding: .45rem 1rem; background: var(--surface); }
.steps button .num { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--border); color: var(--muted); font-size: .78rem; }
.steps button.active { border-color: var(--accent); color: var(--brand); }
.steps button.active .num { background: var(--accent); color: #fff; }
.steps button.done .num { background: var(--ok); color: #fff; }

.dropzone { border: 2px dashed var(--border-2); border-radius: 10px; padding: 2.2rem 1rem; text-align: center; color: var(--muted); background: var(--surface-2); cursor: pointer; }
.dropzone.over { border-color: var(--accent); background: #eef8f9; }
.doc-list .doc { display: flex; align-items: center; gap: .75rem; padding: .65rem .8rem; border: 1px solid var(--border); border-radius: 6px; margin-top: .5rem; background: #fff; }
.doc-list .doc .ico { width: 32px; height: 40px; border-radius: 4px; background: #fbe9e7; color: #c0392b; display: grid; place-items: center; font-size: .65rem; font-weight: 700; }

.rcpt { display: grid; grid-template-columns: 56px minmax(0,1.2fr) minmax(0,1.4fr) 175px; gap: .6rem; align-items: end; padding: .9rem; border: 1px solid var(--border); border-left: 4px solid var(--c, var(--accent)); border-radius: 6px; background: #fff; margin-bottom: .6rem; }
.rcpt .order input { text-align: center; }
.rcpt .opts { grid-column: 2 / -1; display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }
.rcpt .opts input[type=text], .rcpt .opts input[type=tel] { width: 170px; }
.rcpt .remove { position: relative; }

.editor { display: grid; grid-template-columns: 250px minmax(0, 1fr) 260px; gap: 1rem; align-items: start; }
.editor .panel { position: sticky; top: 72px; max-height: calc(100vh - 90px); overflow: auto; }
.palette .ptype { display: flex; align-items: center; gap: .5rem; width: 100%; justify-content: flex-start; margin-bottom: .35rem; background: #fff; }
.palette .ptype.active { border-color: var(--accent); background: #eef8f9; }
.palette .ptype .sw { width: 16px; height: 16px; border-radius: 3px; border: 1px solid rgba(0,0,0,.15); }
.rsel { display: flex; align-items: center; gap: .5rem; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 6px; margin-bottom: .35rem; cursor: pointer; background: #fff; font-size: .9rem; }
.rsel.active { border-color: var(--c); box-shadow: inset 3px 0 0 var(--c); }
.pages { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.doc-title { align-self: stretch; font-weight: 700; color: var(--brand); margin-top: .5rem; }
.pagebox { position: relative; width: 100%; max-width: 880px; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.18); user-select: none; }
.pagebox img { display: block; width: 100%; height: auto; pointer-events: none; }
.pagebox .layer { position: absolute; inset: 0; }
.pagebox .pnum { position: absolute; right: 6px; bottom: 4px; font-size: .7rem; color: var(--faint); }
.pagebox.placing { cursor: crosshair; }
.fld { position: absolute; border: 1.5px solid var(--c); background: color-mix(in srgb, var(--c) 18%, transparent); border-radius: 3px; font-size: 11px; color: #1d2a33; display: flex; align-items: center; padding: 0 3px; overflow: hidden; white-space: nowrap; cursor: move; }
.fld.sel { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--c); z-index: 5; }
.fld .h { position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; background: var(--c); cursor: nwse-resize; }
.fld .req { color: var(--danger); margin-left: 2px; }
.props .field { margin-bottom: .6rem; }

.review-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 1rem; }

/* ------------------------------------------------------------ envelope detail */
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.r-item { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: .75rem; padding: .85rem 0; border-bottom: 1px solid var(--border); }
.r-item:last-child { border-bottom: 0; }
.r-item .ord { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; background: var(--c); font-size: .85rem; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: .75rem; padding: .55rem 0; border-bottom: 1px dashed var(--border); font-size: .88rem; }
.timeline li:last-child { border-bottom: 0; }
.thumbs { display: flex; gap: .6rem; flex-wrap: wrap; }
.thumbs img { width: 120px; border: 1px solid var(--border); border-radius: 4px; background: #fff; }
.chain-ok { color: var(--ok); font-weight: 700; }
.chain-bad { color: var(--danger); font-weight: 700; }

/* ------------------------------------------------------------ signing */
.sign-top { position: sticky; top: 0; z-index: 60; background: #fff; border-bottom: 1px solid var(--border); box-shadow: var(--shadow); }
.sign-top .inner { max-width: 980px; margin: 0 auto; padding: .7rem 1rem; display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.sign-hero { background: var(--brand); color: #fff; }
.sign-hero .inner { max-width: 980px; margin: 0 auto; padding: .9rem 1rem; display: flex; align-items: center; gap: .75rem; }
.sign-hero .brand { font-weight: 700; }
.sign-wrap { max-width: 980px; margin: 0 auto; padding: 1.25rem 1rem 6rem; }
.sign-card { max-width: 560px; margin: 2rem auto; }
.disclosure { max-height: 300px; overflow: auto; white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: .9rem; font-size: .85rem; }
.progress { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; min-width: 120px; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .25s; }
.layer .cover { position: absolute; background: #fff; }
.sfld { position: absolute; border-radius: 3px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.sfld.mine { background: #fff0b3; border: 1.5px solid #d4a800; cursor: pointer; }
.sfld.mine.req::after { content: "*"; position: absolute; top: -2px; right: 2px; color: var(--danger); font-weight: 700; font-size: 12px; }
.sfld.mine.done { background: #f1faf3; border-color: rgba(43,138,62,.55); }
.sfld.mine.focus { box-shadow: 0 0 0 3px rgba(8,126,139,.6); animation: pulse 1.2s ease-in-out 2; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(8,126,139,.25); } }
.sfld.other { border: 1px dashed rgba(0,0,0,.2); background: #f4f6f7; color: var(--faint); }
.sfld .lbl { font-size: .78em; font-weight: 700; color: #5a4700; text-transform: uppercase; letter-spacing: .3px; pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.sfld.other span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; padding: 0 2px; }
.sfld img { max-width: 100%; max-height: 100%; pointer-events: none; }
.sfld input[type=text], .sfld input[type=date] { width: 100%; height: 100%; border: none; background: transparent; padding: 0 3px; font-size: inherit; border-radius: 0; }
.sfld input[type=checkbox] { width: 80%; height: 80%; margin: 0; cursor: pointer; }
.sfld .auto { font-size: inherit; color: #1d2a33; padding: 0 3px; width: 100%; white-space: nowrap; overflow: hidden; }
.adopt-tabs { display: flex; gap: .25rem; margin-bottom: .75rem; }
.adopt-tabs button.active { border-color: var(--accent); color: var(--brand); background: #eef8f9; }
.styles { display: flex; flex-direction: column; gap: .4rem; }
.styles .opt { border: 1px solid var(--border); border-radius: 6px; padding: .3rem .6rem; cursor: pointer; background: #fff; display: flex; align-items: center; gap: .5rem; }
.styles .opt.active { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.styles canvas { height: 56px; width: 100%; }
.drawpad { border: 1px dashed var(--border-2); border-radius: 6px; background: #fff; touch-action: none; width: 100%; height: 170px; display: block; }
.done-card { text-align: center; }
.done-card .check { width: 64px; height: 64px; border-radius: 50%; background: var(--ok-bg); color: var(--ok); display: grid; place-items: center; font-size: 2rem; margin: 0 auto 1rem; }

/* ------------------------------------------------------------ verify */
.verdict { border-radius: 10px; padding: 1.25rem; margin-top: 1rem; border: 1px solid var(--border); }
.verdict.authentic { background: var(--ok-bg); border-color: #bfe3c8; }
.verdict.tampered, .verdict.forged { background: var(--danger-bg); border-color: #f2c4be; }
.verdict.unknown, .verdict.sealed_unknown { background: var(--warn-bg); border-color: #f3dcb0; }

pre.mail { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: .75rem; font-size: .82rem; max-height: 320px; overflow: auto; }

@media (max-width: 1100px) {
  .editor { grid-template-columns: 210px minmax(0, 1fr); }
  .editor .props-panel { grid-column: 1 / -1; position: static; max-height: none; }
}
@media (max-width: 760px) {
  .topbar { gap: .5rem; padding: 0 .75rem; }
  .topbar nav a { padding: .4rem .45rem; font-size: .82rem; }
  .topbar .brand small, .topbar .user .who { display: none; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .review-grid { grid-template-columns: 1fr; }
  .rcpt { grid-template-columns: 1fr; }
  .rcpt .opts { grid-column: auto; }
  .editor { grid-template-columns: 1fr; }
  .editor .panel { position: static; max-height: none; }
  .timeline li { grid-template-columns: 1fr; gap: .1rem; }
  table.list .hide-sm { display: none; }
  .page { padding: 1rem .75rem 3rem; }
  .sign-top .inner { padding: .5rem .75rem; gap: .4rem; }
  .sign-top .inner > .grow { flex-basis: 100%; }
  .sign-top select { flex: 1 1 auto; min-width: 0; font-size: .85rem; padding: .35rem .4rem; }
  .sign-top button { padding: .4rem .75rem; }
  .sign-wrap { padding: .75rem .5rem 5rem; }
  .sign-card { margin: 1rem auto; }
}
