@import url('/static/css/fonts.css');

:root {
  --navy: #0b1933;
  --navy-2: #142a52;
  --gold: #c6a255;
  --gold-2: #e6cf96;
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #0b1933;
  --muted: #667085;
  --line: #e3e6eb;
  --ok: #0f7b55;
  --ok-bg: #e5f5ee;
  --warn: #9a6a12;
  --warn-bg: #fdf3dd;
  --bad: #b42318;
  --bad-bg: #fdeceb;
  --info: #1d4ed8;
  --info-bg: #e8effd;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 25, 51, .06), 0 6px 20px rgba(11, 25, 51, .06);
  --serif: 'Playfair Display', Georgia, serif;
  --sans: 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--sans); color: var(--ink); background: var(--bg); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--navy-2); }
button { font-family: inherit; }
[hidden] { display: none !important; }

/* ---------- topbar ---------- */
.topbar { position: sticky; top: 0; z-index: 30; background: var(--navy); color: #fff; height: 60px; display: flex; align-items: center; gap: 16px; padding: 0 22px; border-bottom: 3px solid var(--gold); }
.brand { display: flex; align-items: center; gap: 11px; color: #fff; text-decoration: none; min-width: 0; }
.brand-mark { width: 34px; height: 34px; border: 1.5px solid var(--gold); border-radius: 50%; display: grid; place-items: center; font-family: var(--serif); color: var(--gold); font-weight: 700; font-size: 15px; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand-text b { font-family: var(--serif); font-size: 17px; letter-spacing: .01em; white-space: nowrap; }
.brand-text small { color: var(--gold-2); font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase; }
.topbar .spacer { flex: 1; }
.topbar .who { color: #c9d1e0; font-size: 13px; }
.lang { display: inline-flex; border: 1px solid rgba(255, 255, 255, .25); border-radius: 999px; overflow: hidden; }
.lang button { background: none; border: 0; color: #c9d1e0; padding: 4px 10px; font-size: 12px; font-weight: 600; cursor: pointer; }
.lang button.on { background: var(--gold); color: var(--navy); }

/* ---------- layout ---------- */
.wrap { max-width: 1120px; margin: 0 auto; padding: 28px 22px 60px; }
h1, h2, h3 { font-family: var(--serif); margin: 0; font-weight: 700; letter-spacing: -.005em; }
h1 { font-size: 28px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrapflex { flex-wrap: wrap; }
.grow { flex: 1; }
.mt { margin-top: 16px; } .mt2 { margin-top: 28px; } .mb { margin-bottom: 16px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 18px; border-radius: 8px; border: 1px solid transparent; font-weight: 600; font-size: 13.5px; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, opacity .15s; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-gold { background: var(--gold); color: var(--navy); }
.btn-gold:hover:not(:disabled) { background: #d4b46c; }
.btn-navy { background: var(--navy); color: #fff; }
.btn-navy:hover:not(:disabled) { background: var(--navy-2); }
.btn-line { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-line:hover:not(:disabled) { border-color: #c4c9d2; }
.btn-ghost { background: none; color: var(--muted); }
.btn-ghost:hover { color: var(--ink); }
.btn-danger { background: #fff; color: var(--bad); border-color: #f2c6c2; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12.5px; }
.btn-lg { height: 48px; padding: 0 24px; font-size: 15px; }
.topbar .btn-line { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .3); }

label.lbl { display: block; font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 0 0 6px; }
.input, textarea.input, select.input { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; color: var(--ink); background: #fff; outline: none; }
textarea.input { height: auto; padding: 10px 12px; resize: vertical; min-height: 70px; }
.input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(198, 162, 85, .18); }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--navy); flex: none; }

/* ---------- chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.draft { background: #eef0f3; color: #475467; }
.chip.sent, .chip.viewed, .chip.pending { background: var(--warn-bg); color: var(--warn); }
.chip.completed, .chip.signed { background: var(--ok-bg); color: var(--ok); }
.chip.declined, .chip.voided { background: var(--bad-bg); color: var(--bad); }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat { padding: 16px 18px; cursor: pointer; transition: border-color .15s; }
.stat.on { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(198, 162, 85, .25); }
.stat b { display: block; font-family: var(--serif); font-size: 28px; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.doclist { width: 100%; border-collapse: collapse; }
.doclist th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.doclist td { padding: 14px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.doclist tr:last-child td { border-bottom: 0; }
.doclist tbody tr { cursor: pointer; }
.doclist tbody tr:hover { background: #fafbfc; }
.doc-title { font-weight: 600; }
.progress { height: 5px; background: #eceff3; border-radius: 9px; overflow: hidden; width: 90px; }
.progress i { display: block; height: 100%; background: var(--ok); }
.empty { padding: 56px 20px; text-align: center; color: var(--muted); }
.drop { border: 2px dashed #c9ced8; border-radius: var(--radius); padding: 34px; text-align: center; background: #fafbfc; transition: .15s; cursor: pointer; }
.drop.over { border-color: var(--gold); background: #fffaf0; }

/* ---------- modal & toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(11, 25, 51, .55); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal-head { padding: 18px 22px 0; display: flex; align-items: center; justify-content: space-between; }
.modal-body { padding: 18px 22px; }
.modal-foot { padding: 0 22px 20px; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.x { background: none; border: 0; font-size: 22px; color: var(--muted); cursor: pointer; line-height: 1; }
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 11px 18px; border-radius: 8px; z-index: 200; box-shadow: var(--shadow); font-weight: 500; max-width: calc(100vw - 32px); }
.toast.err { background: var(--bad); }

/* ---------- PDF pages ---------- */
.pages { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.page { position: relative; width: 100%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 8px 24px rgba(11, 25, 51, .08); }
.page canvas { display: block; width: 100%; height: 100%; }
.page .layer { position: absolute; inset: 0; }
.page-no { position: absolute; right: 8px; bottom: -20px; font-size: 11px; color: var(--muted); }

.field { position: absolute; border: 1.5px solid var(--c, #2563eb); background: color-mix(in srgb, var(--c, #2563eb) 13%, transparent); border-radius: 3px; display: flex; align-items: center; justify-content: center; overflow: hidden; font-size: calc(var(--ph, 800px) * var(--h) * .5); line-height: 1; color: var(--navy); user-select: none; -webkit-user-select: none; touch-action: none; }
.field .ftag { font-size: clamp(9px, calc(var(--ph, 800px) * var(--h) * .34), 13px); font-weight: 600; color: var(--c); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; pointer-events: none; }
.field img { max-width: 100%; max-height: 100%; pointer-events: none; }

/* editor */
.editor { display: grid; grid-template-columns: 300px 1fr; min-height: calc(100vh - 63px); }
.side { background: #fff; border-right: 1px solid var(--line); padding: 20px; overflow-y: auto; position: sticky; top: 63px; height: calc(100vh - 63px); }
.side h3 { font-family: var(--sans); font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 22px 0 10px; font-weight: 700; }
.side h3:first-child { margin-top: 0; }
.stage { padding: 26px 30px 80px; overflow: auto; }
.stage .pages { max-width: 860px; margin: 0 auto; }
.signer-item { border: 1px solid var(--line); border-radius: 9px; padding: 10px 10px 10px 12px; margin-bottom: 8px; border-left: 4px solid var(--c); cursor: pointer; background: #fff; }
.signer-item.on { box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 35%, transparent); }
.signer-item input { border: 0; padding: 2px 0; font: inherit; width: 100%; outline: none; background: transparent; }
.signer-item input.nm { font-weight: 600; }
.signer-item input.sub { font-size: 12.5px; color: var(--muted); }
.signer-item .row { gap: 6px; }
.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tool { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 10px; text-align: left; cursor: grab; font-weight: 600; font-size: 13px; display: flex; gap: 8px; align-items: center; }
.tool:hover { border-color: var(--gold); }
.tool.armed { border-color: var(--navy); background: var(--navy); color: #fff; }
.tool .ic { width: 22px; text-align: center; font-size: 15px; }
.hint { font-size: 12px; color: var(--muted); background: #f8f9fb; border-radius: 8px; padding: 10px 12px; margin-top: 10px; }
.editor .field { cursor: move; }
.editor .field.sel { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--c); z-index: 5; }
.field .del { position: absolute; top: -1px; right: -1px; width: 18px; height: 18px; border: 0; background: var(--c); color: #fff; font-size: 12px; line-height: 18px; padding: 0; cursor: pointer; display: none; border-radius: 0 2px 0 4px; }
.field .rs { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; background: var(--c); cursor: nwse-resize; display: none; border-radius: 3px 0 2px 0; }
.field.sel .del, .field.sel .rs { display: block; }
.pages.arming .layer { cursor: crosshair; }
.fprops { margin-top: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: #fbfbfc; }

/* detail */
.detail { display: grid; grid-template-columns: 1fr 360px; gap: 22px; align-items: start; }
.signer-card { padding: 14px 16px; border-bottom: 1px solid var(--line); border-left: 4px solid var(--c); }
.signer-card:last-child { border-bottom: 0; }
.linkbox { display: flex; gap: 6px; margin-top: 10px; }
.linkbox input { flex: 1; min-width: 0; height: 32px; font-size: 12px; border: 1px solid var(--line); border-radius: 6px; padding: 0 8px; color: var(--muted); background: #fafbfc; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 20px; font-size: 13px; }
.timeline li::before { content: ''; position: absolute; left: 4px; top: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--gold); }
.timeline li::after { content: ''; position: absolute; left: 7px; top: 15px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline small { display: block; color: var(--muted); font-size: 11.5px; }
.banner { padding: 14px 18px; border-radius: var(--radius); font-weight: 500; display: flex; gap: 12px; align-items: center; }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.info { background: var(--info-bg); color: var(--info); }
.hash { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; word-break: break-all; color: var(--muted); }

/* ---------- signer page ---------- */
.sign-body { background: #e9ecf1; }
.sign-head { background: #fff; border-bottom: 1px solid var(--line); }
.sign-head .inner { max-width: 860px; margin: 0 auto; padding: 18px 16px; }
.sign-main { max-width: 860px; margin: 0 auto; padding: 18px 12px 140px; }
.sign-main .field { cursor: pointer; }
.sign-main .field.req:not(.done) { animation: pulse 2s infinite; }
.sign-main .field.done { background: transparent; border-style: dashed; border-color: color-mix(in srgb, var(--c) 45%, transparent); }
.sign-main .field.active { box-shadow: 0 0 0 3px var(--gold); }
.field input.ftext { width: 100%; height: 100%; border: 0; background: transparent; font: inherit; font-size: inherit; color: var(--navy); padding: 0 4px; outline: none; }
.field .cbx { font-size: calc(var(--ph, 800px) * var(--h) * .8); color: var(--navy); font-weight: 700; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c) 40%, transparent); } 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--c) 0%, transparent); } }
.dock { position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -6px 24px rgba(11, 25, 51, .08); z-index: 40; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
.dock .inner { max-width: 860px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }
.dock .meter { flex: 1; min-width: 0; }
.dock .meter .progress { width: 100%; height: 6px; margin-top: 6px; }
.dock .meter .progress i { background: var(--gold); }
.sigpad-tabs { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.sigpad-tabs button { flex: 1; background: none; border: 0; padding: 10px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; }
.sigpad-tabs button.on { color: var(--navy); border-color: var(--gold); }
.sigpad { position: relative; border: 1px solid var(--line); border-radius: 10px; background: #fff; height: 200px; touch-action: none; }
.sigpad canvas { width: 100%; height: 100%; display: block; border-radius: 10px; cursor: crosshair; }
.sigpad .base { position: absolute; left: 20px; right: 20px; bottom: 42px; border-bottom: 1px dashed #c4c9d2; pointer-events: none; }
.sigpad .ph { position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); text-align: center; color: #b0b6c1; pointer-events: none; }
.typed-preview { height: 120px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 10px; font-family: 'Caveat', cursive; font-size: 46px; color: #0d1b4c; overflow: hidden; white-space: nowrap; margin-top: 10px; }
.state-card { max-width: 520px; margin: 40px auto; text-align: center; padding: 34px 26px; }
.state-card .big { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 16px; font-size: 30px; }
.big.ok { background: var(--ok-bg); color: var(--ok); }
.big.bad { background: var(--bad-bg); color: var(--bad); }
.big.wait { background: var(--warn-bg); color: var(--warn); }
.foot-note { text-align: center; font-size: 12px; color: var(--muted); padding: 16px; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 20% -10%, #1d3566 0%, var(--navy) 55%); padding: 20px; }
.auth .card { width: 100%; max-width: 400px; padding: 34px 30px; }
.auth .brand-mark { width: 52px; height: 52px; font-size: 22px; margin: 0 auto 14px; color: var(--navy); border-color: var(--gold); background: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .editor { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .stage { padding: 16px 10px 80px; }
  .detail { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .hide-sm { display: none; }
}
@media (max-width: 560px) {
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar .who { display: none; }
  .wrap { padding: 20px 14px 50px; }
  h1 { font-size: 23px; }
  .doclist th:nth-child(3), .doclist td:nth-child(3), .doclist th:nth-child(4), .doclist td:nth-child(4) { display: none; }
  .doclist td, .doclist th { padding: 12px; }
  .brand-text small { display: none; }
}
