:root {
  --navy: #222f40;
  --navy-2: #34435a;
  --blue: #3776e2;
  --blue-dark: #2a5fbf;
  --blue-soft: #e8f0fc;
  --green: #5cad90;
  --green-dark: #47997b;
  --green-soft: #e6f4ee;
  --ink: #1f2933;
  --muted: #6b7684;
  --line: #e1e6ec;
  --bg: #f5f7fa;
  --card: #ffffff;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --bad: #c0392b;
  --bad-soft: #fbe9e7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(34, 47, 64, 0.06), 0 4px 16px rgba(34, 47, 64, 0.06);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); }
h1, h2, h3 { margin: 0 0 6px; font-weight: 700; color: var(--navy); letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }

/* header */
header.top {
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px 24px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  position: sticky; top: 0; z-index: 20;
}
header.top .logo { height: 40px; display: block; }
header.top .tag { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-left: 12px; padding-left: 12px; border-left: 1px solid var(--line); }

.wrap { max-width: 1280px; margin: 0 auto; padding: 24px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }
.stack.tight > * + * { margin-top: 6px; }

/* buttons and inputs */
button, .btn {
  font: inherit; font-weight: 600; border: 1px solid var(--line); background: #fff; color: var(--navy);
  padding: 9px 16px; border-radius: 9px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}
button:hover, .btn:hover { border-color: #c5ced9; background: #fafbfc; }
button.primary, .btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
button.primary:hover, .btn.primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
button.success, .btn.success { background: var(--green); border-color: var(--green); color: #fff; }
button.success:hover, .btn.success:hover { background: var(--green-dark); border-color: var(--green-dark); }
button.ghost { border-color: transparent; background: transparent; color: var(--blue); }
button.ghost:hover { background: var(--blue-soft); }
button.danger { color: var(--bad); }
button.danger:hover { background: var(--bad-soft); border-color: #f0c8c3; }
button.sm, .btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 7px; }
button:disabled { opacity: 0.5; cursor: default; }
button svg, .btn svg { width: 15px; height: 15px; flex-shrink: 0; }
input[type=text], input[type=email], input[type=password], select {
  font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; width: 100%; background: #fff; color: var(--ink);
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(55, 118, 226, 0.18); }
input[type=file] { font: inherit; font-size: 14px; }
label.field { display: block; font-size: 13px; font-weight: 600; color: var(--navy-2); margin-bottom: 5px; }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

/* pills, notices, toast */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.sent { background: #eef1f5; color: var(--navy-2); }
.pill.viewed { background: var(--warn-soft); color: var(--warn); }
.pill.signed { background: var(--green-soft); color: var(--green-dark); }
.pill.void { background: var(--bad-soft); color: var(--bad); }
.notice { padding: 10px 14px; border-radius: 9px; font-size: 14px; }
.notice.err { background: var(--bad-soft); color: var(--bad); }
.notice.ok { background: var(--green-soft); color: var(--green-dark); }
.notice.info { background: var(--blue-soft); color: var(--blue-dark); }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--navy); color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 14px; font-weight: 600; opacity: 0; transition: opacity 0.2s, transform 0.2s; z-index: 100; pointer-events: none; box-shadow: 0 8px 24px rgba(34,47,64,0.25); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--bad); }

/* layout */
.layout { display: flex; gap: 20px; align-items: flex-start; }
.sidebar { width: 300px; flex-shrink: 0; position: sticky; top: 84px; }
.main { flex: 1; min-width: 0; }
@media (max-width: 900px) { .layout { flex-direction: column; } .sidebar { width: 100%; position: static; } }

.doc-item { padding: 10px 12px; border-radius: 9px; cursor: pointer; border: 1px solid transparent; display: flex; gap: 10px; align-items: center; }
.doc-item:hover { background: var(--bg); }
.doc-item.active { background: var(--blue-soft); border-color: #c9dbf7; }
.doc-item .icon { width: 34px; height: 34px; border-radius: 8px; background: var(--blue-soft); color: var(--blue); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.doc-item.active .icon { background: var(--blue); color: #fff; }
.doc-item .icon svg { width: 18px; height: 18px; }
.doc-item .name { font-weight: 600; color: var(--navy); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-item .sub { font-size: 12px; color: var(--muted); }

/* steps */
.steps { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin: 14px 0 18px; }
.steps button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 10px 14px; color: var(--muted); font-weight: 600; margin-bottom: -1px; }
.steps button:hover { background: none; color: var(--navy); }
.steps button.active { color: var(--blue); border-bottom-color: var(--blue); }
.steps button .n { display: inline-flex; width: 20px; height: 20px; border-radius: 50%; background: #eef1f5; color: var(--muted); font-size: 12px; align-items: center; justify-content: center; margin-right: 6px; }
.steps button.active .n { background: var(--blue); color: #fff; }
.steps button.done .n { background: var(--green); color: #fff; }

.toolbar { position: sticky; top: 61px; z-index: 5; background: var(--card); padding: 10px 0 12px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }

/* PDF viewer and boxes */
.pages { display: flex; flex-direction: column; gap: 16px; align-items: center; background: #eaeef3; padding: 18px; border-radius: 10px; }
.page { position: relative; box-shadow: 0 2px 10px rgba(34,47,64,0.18); background: #fff; max-width: 100%; }
.page canvas { display: block; max-width: 100%; height: auto; }
.page .overlay { position: absolute; inset: 0; }
.page .pn { position: absolute; top: -22px; left: 0; font-size: 11px; color: var(--muted); font-weight: 600; }
.box {
  position: absolute; border: 2px dashed var(--blue); background: rgba(55,118,226,0.14); border-radius: 4px;
  font-size: 12px; font-weight: 600; color: var(--blue-dark); display: flex; align-items: center; justify-content: center;
  user-select: none; touch-action: none;
}
.box.date { border-color: var(--warn); background: rgba(183,121,31,0.14); color: var(--warn); }
.box.name { border-color: var(--green); background: rgba(92,173,144,0.18); color: var(--green-dark); }
.box.editable { cursor: move; }
.box .del { position: absolute; top: -11px; right: -11px; width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 1px solid var(--line); color: var(--bad); font-size: 13px; line-height: 20px; text-align: center; cursor: pointer; box-shadow: var(--shadow); }
.box .who { position: absolute; left: -2px; top: -16px; font-size: 10px; line-height: 14px; padding: 0 6px; border-radius: 4px 4px 0 0; background: var(--blue); color: #fff; font-weight: 700; white-space: nowrap; cursor: pointer; letter-spacing: 0.02em; }
.role-chip { display: inline-flex; align-items: center; gap: 4px; border: 2px solid var(--c); border-radius: 999px; padding: 2px 6px 2px 10px; background: #fff; cursor: pointer; opacity: 0.75; }
.role-chip::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.role-chip.active { opacity: 1; box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 25%, transparent); }
.role-chip input { border: 0; padding: 2px 4px; width: 110px; font: inherit; font-size: 13px; font-weight: 600; color: var(--navy); background: transparent; }
.role-chip input:focus { outline: none; box-shadow: none; border: 0; background: var(--bg); border-radius: 4px; }
.role-chip b { color: var(--muted); font-weight: 400; padding: 0 4px; font-size: 15px; }
.role-chip b:hover { color: var(--bad); }
.box .resize { position: absolute; right: -6px; bottom: -6px; width: 14px; height: 14px; background: #fff; border: 2px solid currentColor; border-radius: 3px; cursor: nwse-resize; }

/* signer rows */
.signer-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: center; }
.signer-row.one { grid-template-columns: 1fr auto; max-width: 560px; }
@media (max-width: 600px) { .signer-row { grid-template-columns: 1fr; } }
.linkbox { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; word-break: break-all; background: var(--bg); padding: 8px 10px; border-radius: 7px; border: 1px solid var(--line); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(34,47,64,0.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; backdrop-filter: blur(2px); }
.modal { background: #fff; border-radius: 14px; padding: 22px; width: 100%; max-width: 560px; max-height: 95vh; overflow: auto; box-shadow: 0 20px 60px rgba(34,47,64,0.3); }
.sigpad { border: 2px dashed var(--line); border-radius: 10px; background: #fff; width: 100%; height: 210px; touch-action: none; }

/* empty state */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg { width: 48px; height: 48px; color: #c5ced9; margin-bottom: 10px; }
.empty h2 { color: var(--navy-2); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--bg); border-radius: 9px; padding: 10px 8px; text-align: center; min-width: 0; }
.stat .v { font-size: 22px; font-weight: 700; color: var(--navy); line-height: 1.1; }
.stat .l { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
