:root {
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --brand: #1f4e79;
  --line: #e3e3e3;
  --bg: #f6f7f8;
  --card: #ffffff;
  --ok: #1e7d3c;
  --warn: #9a6a00;
  --danger: #b3261e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; }
.tag { color: var(--muted); font-weight: 400; font-size: 14px; }
.topbar nav a { margin-left: 16px; font-size: 15px; }

main { max-width: 900px; margin: 24px auto; padding: 0 20px 60px; }

h1 { font-size: 24px; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 28px 0 10px; }
.muted { color: var(--muted); }

.flash { background: #eef6ff; border: 1px solid #cfe2f3; padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; }
.error { background: #fdecea; border: 1px solid #f5c6c0; color: var(--danger); padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }

table.list { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); }
table.list th, table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.list tr:last-child td { border-bottom: none; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.awaiting { background: #fff4e0; color: var(--warn); }
.badge.signed { background: #e4f5e9; color: var(--ok); }
.badge.void { background: #ececec; color: var(--muted); }
.badge.draft { background: #e8eef5; color: #4a5a6a; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .muted { margin: 0; }
.actions { white-space: nowrap; }
.mini-link { font-size: 14px; font-weight: 600; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin: 12px 0; }
.card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.card input[type="text"] { width: 100%; }
.card.signed { display: flex; flex-direction: column; gap: 12px; }

.row-actions { display: flex; gap: 10px; margin-top: 12px; }
.row-actions form { margin: 0; }

form.stack, form.narrow { display: flex; flex-direction: column; gap: 8px; max-width: 480px; }
form.narrow { max-width: 520px; }
label { font-weight: 600; font-size: 14px; }
input[type="text"], input[type="email"], input[type="password"], input[type="file"] {
  font-size: 16px; padding: 9px 11px; border: 1px solid #c9c9c9; border-radius: 6px; width: 100%;
}
input[type="text"][readonly] { background: #f3f3f3; }

button, .button {
  display: inline-block; font-size: 15px; font-weight: 600; cursor: pointer;
  padding: 10px 16px; border-radius: 6px; border: 1px solid var(--brand);
  background: var(--brand); color: #fff; text-decoration: none;
}
button:hover, .button:hover { background: #163d60; text-decoration: none; }
button.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
button.danger:hover { background: #fdecea; }

.auth-body, .sign-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 32px; width: 100%; max-width: 360px; }
.auth-card h1 { font-size: 22px; }

.sign-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 24px; width: 100%; max-width: 760px; }
.doc-head { margin-bottom: 18px; }
.doc-head h1 { font-size: 22px; }

.pages img { width: 100%; height: auto; display: block; border: 1px solid var(--line); margin-bottom: 10px; }

.sign-form { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; border-top: 1px solid var(--line); padding-top: 20px; }
.sign-form label.checkbox { display: flex; gap: 12px; align-items: flex-start; font-weight: 500; }
.sign-form label.checkbox input { width: 22px; height: 22px; flex: 0 0 22px; margin-top: 0; accent-color: var(--brand); cursor: pointer; }

@media (max-width: 600px) {
  .topbar { padding: 12px 16px; }
  .topbar nav a { margin-left: 12px; font-size: 14px; }
  main { padding: 0 14px 40px; }
}

/* --- field editor --- */
.palette { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 14px; margin-bottom: 16px; }
.palette label { font-size: 13px; color: var(--muted); margin: 0; }
.palette select, .palette input[type="text"] { font-size: 15px; padding: 8px 10px; border: 1px solid #c9c9c9; border-radius: 6px; }
.palette input[type="text"] { flex: 1 1 220px; }
.kinds { display: flex; gap: 8px; flex-wrap: wrap; }
.kind-btn { font-size: 14px; padding: 8px 14px; border: 1px solid #c9c9c9; border-radius: 999px; background: #fff; cursor: pointer; color: var(--ink); }
.kind-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.send-bar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.send-bar.sent { background: #eef8f0; border-color: #cde6d2; }
.page { margin-bottom: 18px; }
.page-canvas { position: relative; line-height: 0; }
.page-canvas img { width: 100%; height: auto; display: block; border: 1px solid var(--line); }

.field-box { position: absolute; border: 1.5px solid var(--brand); background: rgba(31, 78, 121, 0.10); border-radius: 3px; display: flex; align-items: flex-start; justify-content: space-between; overflow: hidden; font-size: 11px; color: var(--brand); padding: 1px 3px; }
.field-box .fb-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field-box .fb-del { background: var(--brand); color: #fff; border: none; border-radius: 50%; width: 16px; height: 16px; line-height: 14px; font-size: 12px; padding: 0; cursor: pointer; flex: 0 0 auto; }
.field-box .fb-grip { flex: 0 0 auto; cursor: move; color: var(--brand); opacity: 0.6; font-size: 12px; line-height: 1; padding: 0 2px; user-select: none; -webkit-user-select: none; touch-action: none; }
.field-box.kind-text { background: rgba(31, 78, 121, 0.06); align-items: center; }
.field-box .fb-text-input { flex: 1 1 auto; min-width: 0; border: none; background: transparent; font-size: 13px; color: #111; outline: none; padding: 0; }

/* --- signer field overlays --- */
.sf { position: absolute; display: flex; align-items: center; padding: 0 2px; overflow: hidden; font-size: 13px; }
.sf.sig { color: #1a3c5e; font-style: italic; border-bottom: 1.5px solid #1a3c5e; }
.sf.date { color: #333; }
.sf.init { color: #333; border-bottom: 1px dashed #999; }
.sf.text { color: #111; }

/* --- danger zone --- */
.danger-zone { border-color: #e5b8b4; background: #fdf6f5; }
.danger-zone h3 { margin: 0 0 4px; font-size: 15px; color: var(--danger); }

