@font-face {
  font-family: 'YTC Signature';
  src: url('/vendor/signature-font.woff2') format('woff2');
  font-display: block;
}
:root {
  --navy: #0f1a3a;
  --blue: #1d4ed8;
  --blue-soft: #e8efff;
  --grey: #5b6478;
  --line: #e2e6f0;
  --bg: #f4f6fb;
  --ok: #047857;
  --warn: #b45309;
  --bad: #b91c1c;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif; color: var(--navy); background: var(--bg); }
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; letter-spacing: 0.2px; }
.brand small { font-weight: 400; color: var(--grey); margin-left: 6px; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 24px 20px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; padding: 9px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; color: var(--navy); font-weight: 600; font-size: 14px; }
.btn:hover { border-color: #c4cbdd; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #1e40af; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.small { padding: 5px 9px; font-size: 13px; }
.link { background: none; border: 0; color: var(--blue); cursor: pointer; padding: 0; text-decoration: underline; }

.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.muted { color: var(--grey); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 13px; color: var(--grey); margin-bottom: 4px; }
input[type='text'], input[type='email'], input[type='password'], input[type='number'], textarea, select { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
textarea { min-height: 70px; resize: vertical; }
.error { color: var(--bad); font-size: 14px; }
.notice { padding: 10px 14px; border-radius: 8px; background: var(--blue-soft); }

table.list { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.list th, table.list td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
table.list th { font-size: 12px; text-transform: uppercase; color: var(--grey); letter-spacing: 0.4px; background: #fafbfe; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: #f8faff; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef0f5; color: var(--grey); text-transform: capitalize; }
.badge.sent, .badge.viewed { background: #fff4e0; color: var(--warn); }
.badge.completed, .badge.signed { background: #e3f6ee; color: var(--ok); }
.badge.voided, .badge.declined, .badge.expired { background: #fde8e8; color: var(--bad); }
.badge.draft, .badge.pending { background: #eef0f5; color: var(--grey); }
.badge.completing { background: var(--blue-soft); color: var(--blue); }

/* Editor */
.editor { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 57px); }
.side { background: #fff; border-right: 1px solid var(--line); overflow-y: auto; padding: 16px; }
.side h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--grey); margin: 18px 0 8px; }
.side h3:first-child { margin-top: 0; }
.viewer { overflow: auto; padding: 24px; }
.signer-item { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: start; cursor: pointer; }
.signer-item.selected { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-soft); }
.signer-item input { padding: 5px 8px; margin-bottom: 4px; font-size: 13px; }
.dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 8px; }
.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.palette .btn { justify-content: flex-start; font-weight: 500; }
.palette .btn.armed { background: var(--blue-soft); border-color: var(--blue); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 7px 12px; cursor: pointer; font-size: 13px; }
.seg button.on { background: var(--blue); color: #fff; }

.page-wrap { position: relative; margin: 0 auto 22px; box-shadow: 0 2px 10px rgba(15, 26, 58, 0.12); background: #fff; }
.page-wrap canvas { display: block; width: 100%; height: auto; }
.page-wrap .overlay { position: absolute; inset: 0; }
.page-wrap.placing .overlay { cursor: crosshair; }
.page-label { text-align: center; font-size: 12px; color: var(--grey); margin: -14px 0 18px; }

.fbox { position: absolute; border: 2px solid; border-radius: 4px; font-size: 11px; font-weight: 600; display: flex; align-items: center; justify-content: center; user-select: none; overflow: hidden; white-space: nowrap; }
.editor .fbox { cursor: move; }
.fbox.sel { outline: 2px dashed var(--navy); outline-offset: 2px; }
.fbox .handle { position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; background: currentColor; cursor: nwse-resize; }
.fbox .opt { position: absolute; top: 1px; left: 3px; font-size: 9px; opacity: 0.8; }

/* Signer */
.sign-head { background: #fff; border-bottom: 1px solid var(--line); padding: 14px 20px; position: sticky; top: 0; z-index: 20; }
.sign-head h1 { font-size: 18px; margin: 0; }
.sign-body { max-width: 900px; margin: 0 auto; padding: 18px 12px 160px; }
.sign-foot { position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line); padding: 12px 16px; z-index: 20; box-shadow: 0 -4px 14px rgba(15, 26, 58, 0.06); }
.sign-foot .inner { max-width: 900px; margin: 0 auto; }
.consent { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; margin-bottom: 10px; }
.consent input { margin-top: 4px; width: 18px; height: 18px; flex: none; }
.sf { background: rgba(255, 214, 102, 0.35); border: 2px dashed #d99a00; color: #7a5600; cursor: pointer; }
.sf.done { background: rgba(4, 120, 87, 0.06); border: 1px solid rgba(4, 120, 87, 0.4); color: var(--navy); }
.sf img { max-width: 100%; max-height: 100%; }
.sf input[type='text'] { width: 100%; height: 100%; border: 0; background: transparent; padding: 0 4px; font-size: 12px; border-radius: 0; }
.sf input[type='checkbox'] { width: 80%; height: 80%; margin: 0; }
.sf.flash { animation: flash 1s ease 2; }
@keyframes flash { 50% { box-shadow: 0 0 0 5px rgba(217, 154, 0, 0.45); } }

.modal-bg { position: fixed; inset: 0; background: rgba(15, 26, 58, 0.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 14px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; padding: 20px; }
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.pad { border: 1px solid var(--line); border-radius: 8px; background: #fbfcff; touch-action: none; width: 100%; height: 190px; display: block; }
.typed-preview { font-family: 'YTC Signature', cursive; font-size: 46px; border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; min-height: 92px; background: #fbfcff; white-space: nowrap; overflow: hidden; }
.center-msg { max-width: 520px; margin: 60px auto; text-align: center; }

@media (max-width: 800px) {
  .editor { grid-template-columns: 1fr; height: auto; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .viewer { padding: 12px; }
  table.list .hide-sm { display: none; }
}
