:root {
  --ink: #1c2a4a;
  --ink-soft: #46536f;
  --paper: #f5f5f1;
  --card: #ffffff;
  --text: #2c3242;
  --muted: #6d7383;
  --rule: #e0ded4;
  --pen: #2b49c8;        /* client / signing actions — blue ink */
  --pen-soft: #eef1fc;
  --green: #0e6b58;      /* sender fields */
  --green-soft: #e9f3f0;
  --danger: #a03030;
  --radius: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: "Public Sans", -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3 { font-family: "Fraunces", Georgia, serif; color: var(--ink); font-weight: 600; }

.mono { font-family: "IBM Plex Mono", monospace; font-size: 12px; }

/* ---- top bar ---- */
.topbar {
  background: var(--ink);
  color: #f2f3f7;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.topbar .brand {
  font-family: "Fraunces", Georgia, serif;
  font-size: 18px;
  letter-spacing: 0.02em;
  color: #fff;
  text-decoration: none;
}
.topbar .brand span { color: #9fb0e8; }
.topbar .spacer { flex: 1; }
.topbar button { background: transparent; border: 1px solid #46536f; color: #c8cede; }
.topbar button:hover { border-color: #8b97b5; }

.wrap { max-width: 980px; margin: 0 auto; padding: 32px 24px 80px; }

/* ---- buttons & inputs ---- */
button, .btn {
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--ink);
  color: #fff;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
button:hover, .btn:hover { background: #2a3a61; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.secondary, .btn.secondary {
  background: var(--card);
  color: var(--ink);
  border-color: var(--rule);
}
button.secondary:hover, .btn.secondary:hover { border-color: var(--ink-soft); background: var(--card); }
button.pen { background: var(--pen); }
button.pen:hover { background: #2038a3; }
button.danger-link { background: none; border: none; color: var(--danger); padding: 4px; font-weight: 500; }

input[type="text"], input[type="email"], input[type="password"], input[type="date"] {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  width: 100%;
}
input:focus, button:focus-visible { outline: 2px solid var(--pen); outline-offset: 1px; }

label { font-size: 13px; font-weight: 600; color: var(--ink-soft); display: block; margin: 12px 0 4px; }

/* ---- cards / login ---- */
.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 20px;
}
.login-card { max-width: 360px; margin: 12vh auto; padding: 32px; }
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-card p { color: var(--muted); margin: 0 0 12px; font-size: 14px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ---- document list ---- */
.doc-table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.doc-table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--rule); font-weight: 600; }
.doc-table td { padding: 14px 16px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.doc-table tr:last-child td { border-bottom: none; }
.doc-title { font-weight: 600; color: var(--ink); }

.chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 99px; }
.chip.draft { background: #ececec; color: #555; }
.chip.sent { background: var(--pen-soft); color: var(--pen); }
.chip.completed { background: var(--green-soft); color: var(--green); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn, .actions button { padding: 5px 12px; font-size: 13px; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; border: 1px dashed var(--rule); border-radius: var(--radius); background: var(--card); }

/* ---- editor ---- */
.editor-layout { display: flex; gap: 24px; align-items: flex-start; max-width: 1200px; margin: 0 auto; padding: 24px; }
.palette {
  position: sticky; top: 24px;
  width: 230px; flex-shrink: 0;
  background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 16px;
}
.palette h3 { margin: 0 0 4px; font-size: 15px; }
.palette .hint { font-size: 12.5px; color: var(--muted); margin: 0 0 14px; }
.assignee-toggle { display: flex; border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.assignee-toggle button { flex: 1; border-radius: 0; background: var(--card); color: var(--muted); border: none; padding: 7px 4px; font-size: 13px; }
.assignee-toggle button.active-client { background: var(--pen); color: #fff; }
.assignee-toggle button.active-sender { background: var(--green); color: #fff; }
.field-btns { display: flex; flex-direction: column; gap: 8px; }
.field-btns button { background: var(--card); color: var(--ink); border: 1px solid var(--rule); justify-content: flex-start; }
.field-btns button.armed { border-color: var(--pen); background: var(--pen-soft); color: var(--pen); }
.palette .divider { border-top: 1px solid var(--rule); margin: 16px 0; }
.palette .actions-col { display: flex; flex-direction: column; gap: 8px; }
.palette .actions-col button { width: 100%; justify-content: center; }

.pages { flex: 1; min-width: 0; }
.page-holder { position: relative; margin: 0 auto 24px; background: #fff; box-shadow: 0 1px 6px rgba(28, 42, 74, 0.14); width: fit-content; }
.page-holder canvas { display: block; }
.page-overlay { position: absolute; inset: 0; }
.page-overlay.placing { cursor: crosshair; }
.page-num { text-align: center; color: var(--muted); font-size: 12px; margin: -16px 0 20px; }

/* placed fields (editor) */
.fbox {
  position: absolute;
  border: 1.5px dashed var(--pen);
  background: rgba(43, 73, 200, 0.07);
  border-radius: 3px;
  cursor: move;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: var(--pen);
  user-select: none;
  touch-action: none;
}
.fbox.sender { border-color: var(--green); background: rgba(14, 107, 88, 0.07); color: var(--green); }
.fbox .del {
  position: absolute; top: -9px; right: -9px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--ink); color: #fff; border: none; padding: 0;
  font-size: 11px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.fbox .grip {
  position: absolute; right: -5px; bottom: -5px;
  width: 12px; height: 12px; border-radius: 2px;
  background: currentColor; cursor: nwse-resize;
}

/* ---- signing page ---- */
.sign-header {
  background: var(--card); border-bottom: 1px solid var(--rule);
  padding: 18px 24px;
}
.sign-header .inner { max-width: 900px; margin: 0 auto; display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.sign-header h1 { margin: 0; font-size: 21px; }
.sign-header .who { color: var(--muted); font-size: 14px; }
.sign-progress { max-width: 900px; margin: 16px auto 0; padding: 0 24px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sign-progress .count { font-size: 14px; color: var(--ink-soft); font-weight: 600; }

/* fields on signing page */
.sfield {
  position: absolute;
  border: 1.5px solid var(--pen);
  background: rgba(43, 73, 200, 0.06);
  border-radius: 3px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: var(--pen);
  overflow: hidden;
}
.sfield:hover { background: rgba(43, 73, 200, 0.14); }
.sfield.done { border-style: solid; border-color: var(--green); background: transparent; color: var(--green); }
.sfield img { max-width: 100%; max-height: 100%; }
.sfield .val { font-family: "Public Sans", sans-serif; font-size: 13px; color: var(--text); font-weight: 500; }

/* ---- modal ---- */
.modal-back {
  position: fixed; inset: 0; background: rgba(28, 42, 74, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.modal { background: var(--card); border-radius: 8px; padding: 24px; width: 100%; max-width: 560px; box-shadow: 0 8px 40px rgba(0,0,0,0.25); }
.modal h2 { margin: 0 0 14px; font-size: 19px; }
.modal .row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.sig-tabs { display: flex; gap: 0; border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; width: fit-content; }
.sig-tabs button { border-radius: 0; background: var(--card); color: var(--muted); border: none; font-size: 13px; }
.sig-tabs button.on { background: var(--ink); color: #fff; }

.sig-pad-wrap { position: relative; }
canvas.sig-pad {
  width: 100%; height: 180px;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: #fdfdfb;
  cursor: crosshair;
  display: block;
  touch-action: none;
}
.sig-line {
  position: absolute; left: 8%; right: 8%; bottom: 38px;
  border-bottom: 1px solid #b9b6aa; pointer-events: none;
}
.sig-x { position: absolute; left: 8%; bottom: 42px; color: #b9b6aa; font-size: 15px; pointer-events: none; font-family: Georgia, serif; }
.sig-typed-preview {
  height: 110px; border: 1px solid var(--rule); border-radius: var(--radius);
  background: #fdfdfb; display: flex; align-items: center; justify-content: center;
  font-family: "Caveat", cursive; font-size: 44px; color: var(--pen);
  margin-top: 10px; overflow: hidden; white-space: nowrap; padding: 0 12px;
}

/* ---- link share modal / done panel ---- */
.link-row { display: flex; gap: 8px; margin-top: 6px; }
.link-row input { font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--ink-soft); }
.done-panel { max-width: 620px; margin: 10vh auto; text-align: center; padding: 40px 32px; }
.done-panel .seal {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--green-soft); color: var(--green);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; margin: 0 auto 16px;
}
.done-panel h1 { font-size: 26px; margin: 0 0 8px; }
.done-panel p { color: var(--muted); }
.done-panel .row { display: flex; gap: 10px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }

.note { font-size: 13px; color: var(--muted); }
.banner { background: var(--pen-soft); color: var(--ink); border: 1px solid #ccd6f5; border-radius: var(--radius); padding: 10px 14px; font-size: 14px; margin-bottom: 16px; }

@media (max-width: 760px) {
  .editor-layout { flex-direction: column; }
  .palette { position: static; width: 100%; }
  .wrap { padding: 20px 14px 60px; }
  .doc-table th:nth-child(3), .doc-table td:nth-child(3) { display: none; }
}
