:root {
  --blue: #5B86E5; --green: #26854A; --green-dark: #1f6e3d;
  --slate: #303841; --slate2: #46515E; --gray: #B7BCC4; --light: #D3D6DB; --off: #EFF0F2; --white: #FFFFFF;
  --rose: #D35A6E;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(48,56,65,.08), 0 4px 16px rgba(48,56,65,.06);
  --head: "Noto Sans", "Open Sans", Arial, sans-serif;
  --body: "Open Sans", "Noto Sans", Arial, sans-serif;
  --mono: "JetBrains Mono", "Fira Code", Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--body); font-size: 15px; line-height: 1.6; color: var(--slate); background: var(--off); }
h1, h2, h3 { font-family: var(--head); font-weight: 800; line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.15rem; font-weight: 700; } h3 { font-size: 1rem; font-weight: 700; }
a { color: var(--blue); }
code, .mono { font-family: var(--mono); font-size: .85em; }
.muted { color: var(--slate2); }
.small { font-size: .85rem; }

.topbar { background: var(--slate); color: var(--white); display: flex; align-items: center; gap: 16px; padding: 10px 20px; position: sticky; top: 0; z-index: 20; }
.topbar img { height: 26px; display: block; }
.topbar .product { font-family: var(--head); font-weight: 700; color: var(--light); border-left: 1px solid var(--slate2); padding-left: 14px; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--gray); font-size: .85rem; }
.topbar a, .topbar button.link { color: var(--light); text-decoration: none; font-size: .9rem; background: none; border: 0; cursor: pointer; font-family: inherit; }
.topbar a:hover, .topbar button.link:hover { color: var(--white); }

.wrap { max-width: 1120px; margin: 0 auto; padding: 24px 20px 64px; }
.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: 600 .92rem var(--body); border-radius: 8px; padding: 9px 16px; border: 1px solid var(--light); background: var(--white); color: var(--slate); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--gray); }
.btn.primary { background: var(--green); border-color: var(--green); color: var(--white); }
.btn.primary:hover { background: var(--green-dark); }
.btn.danger { color: var(--rose); border-color: #efc3cb; }
.btn.small { padding: 5px 10px; font-size: .82rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

input[type=text], input[type=email], input[type=password], input[type=number], textarea, select {
  font: inherit; color: var(--slate); border: 1px solid var(--light); border-radius: 8px; padding: 8px 10px; background: var(--white); width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(91,134,229,.35); border-color: var(--blue); }
label { font-weight: 600; font-size: .85rem; color: var(--slate2); display: block; margin-bottom: 4px; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }
.row > .shrink { flex: 0 0 auto; min-width: 0; }

.error { color: #a3283c; background: #fbe9ec; border-radius: 8px; padding: 8px 12px; margin: 10px 0; display: none; }
.error.show { display: block; }
.notice { background: #eaf0fc; border-left: 3px solid var(--blue); padding: 10px 14px; border-radius: 6px; margin: 10px 0; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font: 700 .78rem var(--head); text-transform: uppercase; letter-spacing: .04em; color: var(--slate2); padding: 8px 10px; border-bottom: 1px solid var(--light); }
td { padding: 10px; border-bottom: 1px solid var(--off); vertical-align: top; }
tr.click { cursor: pointer; } tr.click:hover td { background: #f7f8fa; }

.pill { display: inline-block; font: 700 .72rem var(--head); text-transform: uppercase; letter-spacing: .04em; padding: 2px 9px; border-radius: 999px; background: var(--off); color: var(--slate2); white-space: nowrap; }
.pill.draft { background: var(--off); color: var(--slate2); }
.pill.sent, .pill.viewed, .pill.pending { background: #e7eefc; color: #3a62b8; }
.pill.partially_signed { background: #fdf1e0; color: #8a5b16; }
.pill.completed, .pill.signed { background: #e3f2e8; color: var(--green); }
.pill.declined, .pill.voided { background: #fbe9ec; color: #a3283c; }

/* PDF pages */
.pages { display: flex; flex-direction: column; gap: 18px; align-items: center; }
.page { position: relative; width: 100%; max-width: 850px; background: var(--white); box-shadow: var(--shadow); user-select: none; touch-action: pan-y; }
.page canvas { display: block; width: 100%; height: auto; }
.page .overlay { position: absolute; inset: 0; }
.page .pageno { position: absolute; right: 8px; bottom: -20px; font-size: .75rem; color: var(--slate2); }

/* Fields */
.field { position: absolute; border: 1.5px solid var(--c, var(--blue)); background: color-mix(in srgb, var(--c, var(--blue)) 14%, transparent); border-radius: 4px; display: flex; align-items: center; justify-content: center; font: 600 11px var(--body); color: var(--slate); overflow: hidden; }
.editor .field { cursor: move; touch-action: none; }
.editor .field.selected { box-shadow: 0 0 0 2px var(--white), 0 0 0 4px var(--c, var(--blue)); z-index: 2; }
.field .lbl { pointer-events: none; padding: 0 4px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.field .del { position: absolute; top: -1px; right: -1px; width: 18px; height: 18px; border: 0; background: var(--c, var(--blue)); color: var(--white); font-size: 12px; line-height: 18px; padding: 0; cursor: pointer; border-radius: 0 3px 0 4px; display: none; }
.field .rs { position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; cursor: nwse-resize; background: linear-gradient(135deg, transparent 50%, var(--c, var(--blue)) 50%); touch-action: none; display: none; }
.editor .field.selected .del, .editor .field.selected .rs { display: block; }

/* Editor layout */
.editor-grid { display: grid; grid-template-columns: 340px 1fr; gap: 20px; align-items: start; }
.sidebar { position: sticky; top: 66px; max-height: calc(100vh - 80px); overflow: auto; }
.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.palette .chip { border: 1.5px dashed var(--c, var(--blue)); background: color-mix(in srgb, var(--c, var(--blue)) 10%, white); border-radius: 8px; padding: 8px; font-weight: 600; font-size: .85rem; cursor: grab; text-align: center; touch-action: none; user-select: none; }
.ghost { position: fixed; pointer-events: none; z-index: 100; opacity: .85; }
.signer-row { display: grid; grid-template-columns: 14px 1fr 1fr 56px 28px; gap: 6px; align-items: center; margin-bottom: 6px; }
.signer-row input { padding: 6px 8px; font-size: .85rem; }
.swatch { width: 12px; height: 12px; border-radius: 50%; background: var(--c); }
.signer-pick { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 10px; }
.signer-pick button { border: 1.5px solid var(--c); background: var(--white); color: var(--slate); border-radius: 999px; padding: 3px 10px; font: 600 .8rem var(--body); cursor: pointer; }
.signer-pick button.on { background: var(--c); color: var(--white); }

.links .link-row { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.links input { font-family: var(--mono); font-size: .78rem; }

.audit { font-size: .82rem; }
.audit td { padding: 6px 10px; }

/* Signer view */
.sign-bar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--white); border-top: 1px solid var(--light); padding: 12px 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; z-index: 20; box-shadow: 0 -4px 16px rgba(48,56,65,.06); }
.sign-bar .consent { flex: 1 1 320px; display: flex; gap: 8px; align-items: flex-start; font-size: .88rem; font-weight: 400; color: var(--slate); margin: 0; }
.sign-bar .consent input { margin-top: 4px; width: 18px; height: 18px; flex: 0 0 auto; }
.sfield { cursor: pointer; }
.sfield .lbl { font-size: clamp(7px, 1.5vw, 11px); padding: 0 2px; }
body.signing .wrap { padding-bottom: 170px !important; }
.sfield.done { background: transparent; border-style: dashed; border-color: var(--gray); }
.sfield img { max-width: 100%; max-height: 100%; }
.sfield input[type=text] { border: 0; background: transparent; padding: 0 3px; height: 100%; font-size: inherit; width: 100%; border-radius: 0; }
.sfield input[type=checkbox] { width: 70%; height: 70%; margin: 0; cursor: pointer; }
.sfield.req::after { content: "*"; position: absolute; top: -2px; right: 2px; color: var(--rose); font-weight: 700; }

.modal-bg { position: fixed; inset: 0; background: rgba(48,56,65,.55); display: none; align-items: center; justify-content: center; z-index: 50; padding: 12px; }
.modal-bg.show { display: flex; }
.modal { background: var(--white); border-radius: 12px; width: 100%; max-width: 560px; padding: 18px; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tabs button { flex: 1; border: 1px solid var(--light); background: var(--off); padding: 7px; border-radius: 8px; font: 600 .88rem var(--body); cursor: pointer; color: var(--slate); }
.tabs button.on { background: var(--white); border-color: var(--blue); color: var(--blue); }
.pad { width: 100%; height: 180px; border: 1px dashed var(--gray); border-radius: 8px; touch-action: none; background: var(--white); display: block; }
.typed-preview { font-family: "Dancing Script", cursive; font-size: 44px; min-height: 80px; display: flex; align-items: center; padding: 0 12px; border: 1px dashed var(--gray); border-radius: 8px; margin-top: 8px; }

.center-card { max-width: 420px; margin: 10vh auto; }
.done-state { text-align: center; padding: 40px 20px; }

@media (max-width: 860px) {
  .editor-grid { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
  .wrap { padding: 16px 12px 64px; }
  .hide-sm { display: none; }
  .topbar { padding: 10px 12px; }
  h1 { font-size: 1.3rem; }
  .sign-bar { padding: 10px 12px; }
  .sign-bar .consent { font-size: .8rem; }
}
