:root {
  --bg: #f5f6fa; --panel: #fff; --text: #1f2330; --muted: #6b7180; --line: #e3e5ec;
  --accent: #4f46e5; --accent-soft: #eef0ff; --danger: #dc2626; --ok: #059669; --warn: #d97706;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
code { background: #0000000d; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }

/* buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff;
  color: var(--text); padding: 7px 14px; border-radius: 8px; font: inherit; font-weight: 550; cursor: pointer;
  white-space: nowrap; }
.btn:hover { background: #f7f7fb; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.wide { width: 100%; justify-content: center; padding: 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input, textarea, select { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  width: 100%; background: #fff; color: var(--text); }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: auto; }
label { display: block; font-weight: 550; margin: 12px 0 0; }
label > input, label > textarea, label > select { margin-top: 5px; font-weight: 400; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }

/* 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); }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: var(--muted); padding: 6px 12px; border-radius: 8px; font-weight: 550; }
.topbar nav a.active, .topbar nav a:hover { background: var(--accent-soft); color: var(--accent); }
.topbar form { margin: 0; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; color: var(--text); }
.brand .logo { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 15px; }
.brand.big { font-size: 20px; margin-bottom: 20px; }
.banner { background: #fff8e6; border-bottom: 1px solid #f3e1b0; color: #7a5a00; padding: 8px 20px; font-size: 13px; }
main#view { max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 18px 20px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }

/* tables */
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase;
  letter-spacing: .03em; padding: 10px 16px; border-bottom: 1px solid var(--line); }
table.list td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover td { background: #fafaff; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 12px; cursor: pointer; font: inherit; }
.tabs button.on { background: var(--text); color: #fff; border-color: var(--text); }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: #eef0f4; color: #4b5060; }
.badge.in_progress, .badge.pending, .badge.viewed { background: #e0ecff; color: #1d4ed8; }
.badge.completed, .badge.signed { background: #dcfce7; color: #166534; }
.badge.declined, .badge.canceled, .badge.expired { background: #fee2e2; color: #991b1b; }
.badge.waiting { background: #f3f4f6; color: #6b7280; }
.bar { height: 6px; background: #eceef4; border-radius: 99px; overflow: hidden; width: 90px; }
.bar > i { display: block; height: 100%; background: var(--ok); }

.signer-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.signer-row:last-child { border-bottom: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.linkbox { display: flex; gap: 6px; width: 100%; }
.linkbox input { font-size: 12px; color: var(--muted); padding: 5px 8px; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }

/* pdf pages */
.pages { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 24px 12px 80px; }
.pdf-page { position: relative; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.12); width: 100%; max-width: 860px; }
.pdf-page canvas { display: block; width: 100%; height: auto; }
.pdf-page .overlay { position: absolute; inset: 0; }
.page-num { position: absolute; right: -2px; top: -20px; font-size: 11px; color: var(--muted); }

/* editor */
.editor { display: grid; grid-template-columns: 270px 1fr; height: calc(100vh - 57px); }
.editor aside { background: #fff; border-right: 1px solid var(--line); overflow: auto; padding: 16px; }
.editor .canvas-area { overflow: auto; }
main#view.full { max-width: none; padding: 0; }
.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.palette button { text-align: left; border: 1px dashed #c9cce0; background: #fafaff; border-radius: 8px; padding: 8px; cursor: grab; font: inherit; }
.palette button:hover { border-color: var(--accent); }
.section { margin-bottom: 22px; }
.section h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px; }
.role-item { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.role-item.on { background: var(--accent-soft); border-color: #d6d9ff; }
.role-item input { padding: 3px 6px; border-color: transparent; background: transparent; }
.role-item input:focus { background: #fff; }
.field { position: absolute; border: 1.5px solid; border-radius: 4px; font-size: 12px; display: flex; align-items: center;
  justify-content: center; overflow: hidden; user-select: none; touch-action: none; cursor: move; line-height: 1.1; text-align: center; }
.field.selected { box-shadow: 0 0 0 3px rgba(79,70,229,.35); }
.field .handle { position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, currentColor 50%); opacity: .7; }
.drop-ghost { outline: 2px dashed var(--accent); outline-offset: -2px; }
.props label { margin-top: 10px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* signing */
.sign-top .doc-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.progress { color: var(--muted); font-size: 13px; }
#notice:not(:empty) { max-width: 860px; margin: 18px auto 0; padding: 0 12px; }
.notice { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; box-shadow: var(--shadow); }
.notice.ok { border-color: #a7f3d0; background: #ecfdf5; }
.notice.bad { border-color: #fecaca; background: #fef2f2; }
.sfield { position: absolute; border-radius: 3px; display: flex; align-items: center; justify-content: center;
  font-size: 12px; overflow: hidden; }
.sfield.mine { border: 1.5px dashed var(--accent); background: rgba(79,70,229,.08); cursor: pointer; color: var(--accent); font-weight: 600; }
.sfield.mine.required::after { content: "*"; position: absolute; top: 0; right: 3px; color: var(--danger); }
.sfield.mine.filled { border-style: solid; border-color: rgba(5,150,105,.6); background: rgba(5,150,105,.05); color: var(--text); font-weight: 400; }
.sfield.mine.flash { animation: flash 1s ease 2; }
@keyframes flash { 50% { box-shadow: 0 0 0 5px rgba(79,70,229,.35); } }
.sfield.other { border: 1px dashed #c4c7d4; background: rgba(0,0,0,.02); color: #a0a3b1; font-size: 11px; }
.sfield.other.filled { border-color: transparent; background: transparent; color: var(--text); }
.sfield img { max-width: 100%; max-height: 100%; pointer-events: none; }
.sfield input[type=text] { border: 0; background: transparent; height: 100%; padding: 0 4px; border-radius: 0; font-size: inherit; color: var(--text); }
.sfield input[type=text]:focus { outline: none; background: #fff; }
.sfield .tick { font-size: 1.1em; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(15,18,30,.45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.3); max-height: 92vh; overflow: auto; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 650; font-size: 16px; }
.modal .body { padding: 18px 20px; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.sigtabs { display: flex; gap: 4px; margin-bottom: 12px; }
.sigtabs button { flex: 1; border: 1px solid var(--line); background: #fff; padding: 7px; border-radius: 8px; cursor: pointer; font: inherit; }
.sigtabs button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.sigpad { border: 1px solid var(--line); border-radius: 10px; background: #fcfcff; width: 100%; height: 180px; touch-action: none; display: block; }
.font-choices { display: flex; gap: 6px; margin-top: 8px; }
.font-choices button { flex: 1; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px; cursor: pointer; font-size: 20px; }
.font-choices button.on { border-color: var(--accent); background: var(--accent-soft); }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; }
#toast div { background: #1f2330; color: #fff; padding: 10px 16px; border-radius: 10px; margin-top: 8px; box-shadow: var(--shadow); }
#toast div.err { background: var(--danger); }

/* auth */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { background: #fff; padding: 32px; border-radius: 16px; width: 100%; max-width: 400px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.auth-card .btn { margin-top: 20px; }
.error { color: var(--danger); margin-top: 12px; }

@media (max-width: 700px) {
  .topbar { padding: 8px 12px; gap: 8px; flex-wrap: wrap; }
  .sign-top .doc-title, .progress { display: none; }
  .editor { grid-template-columns: 1fr; height: auto; }
  .editor aside { border-right: 0; border-bottom: 1px solid var(--line); }
  table.list .hide-sm { display: none; }
}
