:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #1d4ed8;
  --brand-ink: #ffffff;
  --danger: #b91c1c;
  --ok: #047857;
  --warn: #b45309;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; font-weight: 500; text-decoration: none; color: var(--text);
  white-space: nowrap;
}
.btn:hover { background: #f3f4f6; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff;
}
input:focus, textarea:focus, select:focus { outline: 2px solid #93c5fd; outline-offset: -1px; }
label.field-label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }

.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 700; font-size: 18px; text-decoration: none; color: var(--text); }
.topbar .spacer { flex: 1; }

.badge {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: #eef2ff; color: #3730a3; text-transform: capitalize;
}
.badge.draft { background: #f3f4f6; color: #374151; }
.badge.sent, .badge.viewed, .badge.waiting { background: #fef3c7; color: var(--warn); }
.badge.completed, .badge.signed { background: #d1fae5; color: var(--ok); }
.badge.declined, .badge.voided { background: #fee2e2; color: var(--danger); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff;
  padding: 10px 16px; border-radius: 8px; z-index: 100; max-width: calc(100% - 32px); font-size: 14px;
}

/* PDF pages */
.pages { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 24px 16px 80px; }
.page {
  position: relative; width: 100%; max-width: 860px; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 4px 16px rgba(0,0,0,.06);
}
.page canvas { display: block; width: 100%; height: auto; }
.page .layer { position: absolute; inset: 0; }
.page-num { font-size: 12px; color: var(--muted); margin-top: -12px; }

/* Placed fields */
.fld {
  position: absolute; container-type: size; border-radius: 3px;
  display: flex; align-items: center; justify-content: center; user-select: none;
}

.modal-back {
  position: fixed; inset: 0; background: rgba(17,24,39,.45); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--panel); border-radius: 14px; width: 100%; max-width: 560px; padding: 20px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25); max-height: calc(100vh - 32px); overflow: auto;
}
.modal h3 { margin: 0 0 12px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

.empty { text-align: center; color: var(--muted); padding: 60px 16px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
