:root {
  --navy: #142638;
  --steel: #526f88;
  --silver: #b9c4ce;
  --paper: #f5f7f9;
  --white: #ffffff;
  --muted: #627383;
  --ink: #1b2c3e;
  --line: #dce3e9;
  --danger: #9d2f38;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.55 "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--steel); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--line);
  padding: 16px 22px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand { display: flex; align-items: baseline; gap: 8px; font-weight: 800; letter-spacing: 0.16em; color: var(--navy); }
.brand small { font-weight: 600; letter-spacing: 0.08em; color: var(--steel); }
.topbar .spacer { flex: 1; }
.pill { border: 1px solid var(--silver); border-radius: 999px; padding: 5px 11px; font-size: 12px; color: var(--muted); }

.shell { max-width: 1180px; margin: 0 auto; padding: 24px 18px 60px; }
.sign-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.pages { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.page {
  position: relative;
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(20, 38, 56, 0.06);
  width: min(100%, 860px);
}
.page canvas { display: block; width: 100%; height: auto; }
.overlay { position: absolute; inset: 0; }
.field {
  position: absolute;
  border: 1.5px dashed var(--steel);
  background: rgba(255, 255, 255, 0.82);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11px;
  color: var(--steel);
  overflow: hidden;
  text-align: center;
  padding: 2px;
  cursor: pointer;
}
.field:hover { border-color: var(--navy); }
.field.filled { border-style: solid; border-color: var(--navy); background: #fff; color: var(--ink); }
.field img { max-width: 100%; max-height: 100%; object-fit: contain; }
.field .check { font-size: 18px; color: var(--navy); font-weight: 800; }

.panel {
  position: sticky;
  top: 18px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.panel h1 { margin: 0 0 6px; font-size: 22px; line-height: 1.2; color: var(--navy); }
.panel .message { white-space: pre-wrap; color: var(--muted); font-size: 14px; margin: 8px 0 14px; }
.meta { font-size: 12px; color: var(--muted); }
.progress { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 16px 0 8px; }
.progress > span { display: block; height: 100%; width: 0; background: var(--navy); transition: width .2s; }
.steps { font-size: 12px; color: var(--muted); margin-bottom: 18px; }
label.checkline { display: flex; gap: 9px; align-items: flex-start; font-size: 12.5px; color: var(--muted); margin: 14px 0; }
label.checkline input { margin-top: 3px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; border: 1px solid transparent; border-radius: 8px;
  padding: 12px 14px; font-weight: 700; font-size: 14px;
}
.btn-primary { background: var(--navy); color: white; }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost { background: transparent; border-color: var(--silver); color: var(--ink); }
.btn-link { background: transparent; color: var(--danger); border: 0; padding: 8px; font-size: 12px; }
.error { color: var(--danger); font-size: 13px; margin: 10px 0; }
.notice { background: #eef2f6; border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-size: 13px; color: var(--muted); }
.center { min-height: 60vh; display: grid; place-items: center; text-align: center; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(92vw, 560px); box-shadow: 0 20px 60px rgba(20,38,56,.25); }
dialog::backdrop { background: rgba(20, 38, 56, .45); }
.dialog-body { padding: 20px; }
.dialog-body h2 { margin: 0 0 12px; font-size: 19px; color: var(--navy); }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.dialog-actions .btn { width: auto; min-width: 100px; }
.sigpad { width: 100%; height: 190px; background: #fff; border: 1px solid var(--silver); border-radius: 8px; touch-action: none; }
.field-input { width: 100%; border: 1px solid var(--silver); border-radius: 8px; padding: 10px 12px; background: #fff; color: var(--ink); }
.field-input:focus { outline: 2px solid var(--steel); outline-offset: 1px; }

/* requester builder */
.build-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; align-items: start; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.chip { border: 1px solid var(--silver); background: var(--white); border-radius: 999px; padding: 7px 11px; font-size: 12px; color: var(--ink); }
.chip.active { background: var(--navy); border-color: var(--navy); color: #fff; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; }
.row > * { min-width: 0; }
.row .field-input { flex: 1; }
.small { font-size: 12px; color: var(--muted); }
.recipient-row { display: flex; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: #fff; }
.recipient-row .who { flex: 1; min-width: 0; }
.recipient-row .who strong { display: block; font-size: 13px; }
.recipient-row .who span { display: block; font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.iconbtn { border: 0; background: transparent; color: var(--danger); padding: 4px 6px; }
.placefield { position: absolute; border: 1.5px dashed var(--steel); background: rgba(255,255,255,.8); border-radius: 4px; font-size: 10px; color: var(--steel); display:flex; align-items:center; justify-content:center; cursor: pointer; }
.placefield:hover { border-color: var(--danger); color: var(--danger); }
.summary { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; font-size: 12px; color: var(--muted); }
.success { background: #e9eff4; border: 1px solid var(--line); border-radius: 10px; padding: 16px; font-size: 13px; overflow-wrap: anywhere; }
.success a { font-weight: 700; }

@media (max-width: 900px) {
  .sign-grid, .build-grid { grid-template-columns: 1fr; }
  .panel { position: static; }
}
@media (max-width: 560px) {
  .topbar { padding: 12px 14px; }
  .shell { padding: 14px 10px 40px; }
  .brand { letter-spacing: .1em; }
  .pill { display: none; }
}
