:root {
  --ink: #1b2233; --muted: #6b7286; --line: #e3e6ee; --bg: #f3f4f8; --card: #fff;
  --accent: #c1493c; --accent-2: #a83a2e; --primary: #1b1b1d; --primary-2: #3a3a3f; --ok: #13915f; --warn: #c27a00; --bad: #c8382b;
  --r: 10px; --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 4px 16px rgba(20, 30, 60, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
button, input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- Buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: #fff; padding: 9px 15px; border-radius: 8px; cursor: pointer; font-weight: 550; text-decoration: none; color: var(--ink); white-space: nowrap; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { background: #f6f7fb; border-color: #cfd4e2; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #eceef5; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn.lg { padding: 13px 22px; font-size: 16px; }
.input, textarea.input { width: 100%; border: 1px solid #d5d9e4; border-radius: 8px; padding: 9px 12px; background: #fff; outline: none; transition: border-color .15s, box-shadow .15s; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(193, 73, 60, .15); }
label.lbl { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 5px; }
.field-row { margin-bottom: 14px; }

/* ---------- Layout ---------- */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 14px; padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--line); min-height: 58px; }
.brand { font-weight: 750; color: var(--accent); font-size: 17px; text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand img { height: 42px; width: auto; display: block; }
.login .brand img { height: 46px; }
.topbar .spacer { flex: 1; }
.container { max-width: 1080px; margin: 0 auto; padding: 26px 20px 80px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Nav ---------- */
.nav { display: flex; gap: 2px; margin-left: 10px; }
.nav a { padding: 7px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; }
.nav a:hover { background: #f1f2f6; color: var(--ink); }
.nav a.active { color: var(--ink); background: #f1f2f6; }
.crumb { color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 550; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.crumb:hover { color: var(--ink); }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; margin: 0; }
select.input { appearance: auto; }

/* ---------- Badges / chips ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 650; background: #eceef5; color: var(--muted); }
.badge.draft { background: #eceef5; color: #59607a; }
.badge.sent { background: #fff3dc; color: var(--warn); }
.badge.completed { background: #dcf5ea; color: var(--ok); }
.badge.cancelled { background: #fde6e3; color: var(--bad); }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 2px 9px 2px 4px; border-radius: 99px; background: #f3f4f8; margin: 2px 4px 2px 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.chip .ico { width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; color: #fff; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; padding: 32px; }

/* ---------- Document list ---------- */
.dropzone { display: block; border: 2px dashed #c7cde0; border-radius: var(--r); padding: 34px 20px; text-align: center; background: #fff; cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: #fdf6f5; }
.dropzone strong { color: var(--accent); }
.doc-list { margin-top: 24px; display: grid; gap: 10px; }
.doc-item { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; align-items: center; padding: 15px 18px; text-decoration: none; color: inherit; transition: border-color .15s, transform .1s; }
.doc-item:hover { border-color: #c9cfe2; }
.doc-item .t { font-weight: 650; font-size: 15.5px; }
.doc-item .meta { font-size: 13px; color: var(--muted); }
.filters { display: flex; gap: 6px; margin-top: 26px; flex-wrap: wrap; }
.filters .btn.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }

/* ---------- Editor ---------- */
.editor { display: grid; grid-template-columns: 330px 1fr; min-height: calc(100vh - 58px); }
.sidebar { background: #fff; border-right: 1px solid var(--line); padding: 18px; overflow-y: auto; height: calc(100vh - 58px); position: sticky; top: 58px; }
.sidebar h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; }
.sidebar h3:first-child { margin-top: 0; }
.signer-card { border: 1px solid var(--line); border-radius: 9px; padding: 10px; margin-bottom: 8px; border-left-width: 4px; cursor: pointer; transition: box-shadow .15s; }
.signer-card.active { box-shadow: 0 0 0 2px var(--c, var(--accent)); }
.signer-card .row { display: flex; gap: 6px; align-items: center; }
.signer-card .input { padding: 6px 9px; font-size: 14px; }
.signer-card .row + .row { margin-top: 6px; }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tool { border: 1px solid var(--line); background: #fff; padding: 9px 8px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; gap: 7px; font-weight: 550; font-size: 14px; text-align: left; }
.tool:hover { background: #f6f7fb; }
.tool.active { border-color: var(--c, var(--accent)); box-shadow: 0 0 0 2px var(--c, var(--accent)) inset; }
.tool span.i { width: 22px; text-align: center; }
.hint { font-size: 13px; color: var(--muted); background: #f6f7fb; border-radius: 8px; padding: 10px 12px; margin-top: 10px; }
.viewer { padding: 24px; overflow: auto; }
.pages { max-width: 900px; width: 100%; margin: 0 auto; display: grid; gap: 20px; }
.pdf-page { position: relative; background: #fff; box-shadow: 0 2px 10px rgba(20, 30, 60, .12); border-radius: 3px; overflow: hidden; width: 100%; }
.pdf-page canvas { display: block; width: 100%; height: 100%; }
.pdf-page .layer { position: absolute; inset: 0; }
.pdf-page .page-num { position: absolute; right: 8px; bottom: 6px; font-size: 11px; color: #9aa0b0; pointer-events: none; }
.pdf-loading { text-align: center; padding: 60px; color: var(--muted); }
.placing .layer { cursor: crosshair; }

.fld { position: absolute; border: 2px solid var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 650; color: var(--c); user-select: none; touch-action: none; overflow: hidden; container-type: size; }
.fld .lab { pointer-events: none; text-align: center; line-height: 1.1; padding: 0 3px; font-size: clamp(9px, 40cqh, 14px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.editor .fld { cursor: move; }
.fld .del { position: absolute; top: 1px; right: 1px; width: 18px; height: 18px; border: 0; border-radius: 4px; background: var(--c); color: #fff; font-size: 12px; line-height: 18px; padding: 0; cursor: pointer; display: none; }
.fld .rs { position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; background: var(--c); cursor: nwse-resize; clip-path: polygon(100% 0, 100% 100%, 0 100%); display: none; }
.editor .fld:hover .del, .editor .fld:hover .rs, .editor .fld.sel .del, .editor .fld.sel .rs { display: block; }
.editor .fld.sel { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--c); }

/* ---------- Detail ---------- */
.detail-grid { display: grid; grid-template-columns: 360px 1fr; gap: 22px; align-items: start; }
.panel { padding: 18px; }
.panel + .panel { margin-top: 16px; }
.signer-status { padding: 12px 0; border-bottom: 1px solid var(--line); }
.signer-status:last-child { border-bottom: 0; }
.signer-status .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.signer-status .actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.timeline { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.timeline li { padding: 6px 0 6px 16px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ''; position: absolute; left: -5px; top: 12px; width: 8px; height: 8px; border-radius: 50%; background: #b9c0d4; }
.timeline .when { color: var(--muted); font-size: 12px; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 20, 40, .5); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .15s; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 620px; max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); animation: pop .18s; }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.modal header h2 { font-size: 18px; margin: 0; }
.modal .body { padding: 16px 20px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 18px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.97); opacity: 0; } }

.tabs { display: flex; gap: 4px; background: #f0f1f6; padding: 4px; border-radius: 10px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tabs button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.pad-wrap { position: relative; margin-top: 14px; border: 1px solid #d5d9e4; border-radius: 10px; background: #fff; height: 220px; overflow: hidden; }
.pad-wrap canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.pad-wrap .baseline { position: absolute; left: 8%; right: 8%; bottom: 28%; border-bottom: 1.5px dashed #c5cad8; pointer-events: none; }
.pad-wrap .ph { position: absolute; inset: 0; display: grid; place-items: center; color: #b3b9c9; pointer-events: none; font-size: 15px; }
.pad-tools { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 8px; }
.inks { display: flex; gap: 8px; }
.inks button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #ccd; cursor: pointer; }
.inks button.active { box-shadow: 0 0 0 2px var(--ink); }
.fonts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.fonts button { border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 10px; height: 76px; font-size: 30px; cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.fonts button.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary) inset; }
.upload-zone { margin-top: 14px; border: 2px dashed #c7cde0; border-radius: 10px; height: 220px; display: grid; place-items: center; text-align: center; cursor: pointer; color: var(--muted); padding: 10px; }
.upload-zone img { max-width: 100%; max-height: 190px; }

/* ---------- Signer page ---------- */
.sign-head { background: #fff; border-bottom: 1px solid var(--line); }
.sign-head .inner { max-width: 960px; margin: 0 auto; padding: 18px 20px; }
.sign-head h1 { font-size: 20px; margin: 12px 0 4px; }
.msg { background: #f6f7fb; border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 0 8px 8px 0; white-space: pre-line; margin-top: 10px; font-size: 14px; }
.sign-main { max-width: 960px; margin: 0 auto; padding: 20px 12px 120px; }
.sign .fld { cursor: pointer; animation: pulse 2s infinite; }
.sign .fld.done { animation: none; background: transparent; border-style: dashed; border-width: 1px; }
.sign .fld.done img { width: 100%; height: 100%; object-fit: contain; }
.sign .fld.auto { cursor: default; animation: none; background: transparent; border-style: dashed; border-width: 1px; color: #1a2550; font-weight: 500; justify-content: flex-start; }
.sign .fld.auto .lab { text-align: left; }
.sign .fld input { width: 100%; height: 100%; border: 0; background: transparent; padding: 0 4px; font-size: clamp(9px, 55cqh, 15px); color: #1a2550; outline: none; }
.sign .fld.text { cursor: text; animation: none; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--c) 25%, transparent); } }
.bottom-bar { position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); display: flex; align-items: center; justify-content: center; gap: 12px; z-index: 40; box-shadow: 0 -4px 20px rgba(20, 30, 60, .08); }
.bottom-bar .prog { font-size: 14px; color: var(--muted); }
.consent { display: flex; gap: 10px; align-items: flex-start; background: #f6f7fb; padding: 12px; border-radius: 9px; cursor: pointer; font-size: 14px; }
.consent input { margin-top: 3px; width: 18px; height: 18px; flex: none; accent-color: var(--accent); }
.state { max-width: 520px; margin: 60px auto; text-align: center; padding: 34px 26px; }
.state .big { font-size: 44px; line-height: 1; margin-bottom: 12px; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 200; font-size: 14px; box-shadow: var(--shadow); animation: fade .2s; max-width: calc(100vw - 32px); }
.toast.err { background: var(--bad); }

@media (max-width: 860px) {
  .editor { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .viewer { padding: 12px; }
  .detail-grid { grid-template-columns: 1fr; }
  .container { padding: 18px 14px 80px; }
  .topbar { padding: 10px 14px; flex-wrap: wrap; }
  .nav { order: 10; width: 100%; margin: 4px 0 0; }
  .detail-grid { grid-template-columns: 1fr !important; }
}
@media (max-width: 520px) {
  .fonts { grid-template-columns: 1fr; }
  .modal .body { padding: 14px; }
  .bottom-bar .prog { display: none; }
  .pad-wrap { height: 190px; }
}
