:root {
  --green: #56eb09;
  --green-d: #3fb800;
  --purple: #813aa4;
  --purple-d: #452264;
  --ink: #241336;
  --muted: #6b5a80;
  --line: #e6dff0;
  --bg: #f5f2f9;
  --card: #ffffff;
  --danger: #c62845;
  --ok-bg: #eafbe0;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(36, 19, 54, .06), 0 8px 24px rgba(36, 19, 54, .07);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg); line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: var(--purple); }
.top { background: var(--purple-d); color: #fff; }
.top .in { max-width: 1100px; margin: 0 auto; padding: 14px 16px; display: flex; align-items: center; gap: 12px; }
.top img { width: 34px; height: 46px; object-fit: contain; background: #fff; border-radius: 8px; padding: 3px; }
.brand { font-weight: 800; font-size: 18px; letter-spacing: .3px; }
.brand small { display: block; font-weight: 500; font-size: 12.5px; color: #d9ffc4; letter-spacing: 0; }
.top .sp { flex: 1; }
.wrap { max-width: 560px; margin: 0 auto; padding: 20px 16px 48px; }
.wrap.wide { max-width: 1100px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; margin-bottom: 16px; }
h1 { font-size: 24px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -.3px; }
h2 { font-size: 18px; margin: 0 0 12px; }
p.lead { color: var(--muted); margin: 0 0 18px; }
label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
.hint { font-size: 12.5px; color: var(--muted); font-weight: 400; }
input[type=text], input[type=email], input[type=tel], input[type=password], input:not([type]) {
  width: 100%; font: inherit; font-size: 16px; padding: 12px 14px; border: 1.5px solid var(--line);
  border-radius: 12px; background: #fff; color: var(--ink); outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(129, 58, 164, .15); }
.code-input { letter-spacing: 10px; text-align: center; font-size: 26px !important; font-weight: 700; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 700; font-size: 16px;
  border: 0; border-radius: 999px; padding: 13px 22px; cursor: pointer; text-decoration: none;
  background: var(--green); color: #14240a; transition: transform .05s, background .15s, opacity .15s;
}
.btn:hover { background: #4fdc06; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.block { width: 100%; margin-top: 18px; }
.btn.purple { background: var(--purple-d); color: #fff; }
.btn.purple:hover { background: #5a2d82; }
.btn.ghost { background: transparent; color: var(--purple); border: 1.5px solid var(--line); }
.btn.ghost:hover { background: #faf7fd; }
.btn.small { font-size: 13.5px; padding: 7px 13px; }
.btn.wa { background: #25d366; color: #062b14; }
.btn.danger { background: transparent; color: var(--danger); border: 1.5px solid #f2c9d1; }
.linkbtn { background: none; border: 0; color: var(--purple); font: inherit; font-weight: 600; cursor: pointer; padding: 0; text-decoration: underline; }
.err { background: #fdecef; color: var(--danger); border-radius: 12px; padding: 10px 14px; font-size: 14px; margin-top: 14px; display: none; }
.err.show { display: block; }
.note { background: #f3eefa; border-radius: 12px; padding: 12px 14px; font-size: 14px; color: var(--purple-d); }
.ok { background: var(--ok-bg); color: #1e5a00; border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.steps { display: flex; gap: 6px; margin: 2px 0 18px; }
.steps i { flex: 1; height: 5px; border-radius: 5px; background: var(--line); }
.steps i.on { background: var(--green); }
.hidden { display: none !important; }

/* visor */
.doc-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 99px; background: #f0eaf7; color: var(--purple-d); white-space: nowrap; }
.pill.firmado { background: var(--ok-bg); color: #1e5a00; }
.pill.pendiente { background: #fff4d6; color: #7a5200; }
.pill.anulado, .pill.caducado { background: #fdecef; color: var(--danger); }
.pages { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.pages canvas { width: 100%; height: auto; border-radius: 8px; box-shadow: 0 0 0 1px var(--line); background: #fff; }
.viewer { max-height: 62vh; overflow-y: auto; padding: 2px; border-radius: 12px; background: #ece6f3; padding: 10px; -webkit-overflow-scrolling: touch; }
.loading { text-align: center; color: var(--muted); padding: 30px 0; font-size: 14px; }

/* firma */
.sigbox { position: relative; border: 2px dashed #cdbfe0; border-radius: 14px; background: #fff; margin-top: 10px; touch-action: none; }
.sigbox canvas { display: block; width: 100%; height: 210px; touch-action: none; cursor: crosshair; }
.sigbox .ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #b5a6c9; pointer-events: none; font-size: 15px; }
.sigbox .baseline { position: absolute; left: 22px; right: 22px; bottom: 46px; border-bottom: 1.5px solid #e4dbef; pointer-events: none; }
.sigtools { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 13px; color: var(--muted); }
.check { display: flex; gap: 10px; align-items: flex-start; margin-top: 16px; font-size: 15px; font-weight: 500; }
.check input { width: 22px; height: 22px; margin-top: 1px; accent-color: var(--purple); flex: none; }
.big-ok { font-size: 46px; line-height: 1; margin-bottom: 8px; }
.foot { text-align: center; color: var(--muted); font-size: 12.5px; margin-top: 24px; }

/* panel */
.drop { border: 2px dashed #cdbfe0; border-radius: var(--radius); padding: 28px 18px; text-align: center; background: #fff; cursor: pointer; transition: background .15s, border-color .15s; }
.drop.over { background: #f6fff0; border-color: var(--green-d); }
.drop b { display: block; font-size: 17px; margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 14px; }
.grid-new { display: grid; grid-template-columns: 320px 1fr; gap: 18px; align-items: start; }
.preview canvas { width: 100%; border-radius: 8px; box-shadow: 0 0 0 1px var(--line); }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1.5px solid var(--line); }
table.list td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:hover td { background: #fbf9fd; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-weight: 600; }
.acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { max-width: 280px; padding: 9px 12px; font-size: 14px; }
.toolbar .sp { flex: 1; }
.seg { display: inline-flex; background: #ece6f3; border-radius: 99px; padding: 3px; }
.seg button { border: 0; background: none; font: inherit; font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 99px; cursor: pointer; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
dialog { border: 0; border-radius: var(--radius); padding: 0; max-width: 560px; width: calc(100% - 24px); box-shadow: 0 20px 60px rgba(36,19,54,.3); color: var(--ink); }
dialog::backdrop { background: rgba(36, 19, 54, .45); }
dialog .dh { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px 0; }
dialog .db { padding: 12px 22px 22px; }
dialog .x { background: none; border: 0; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); }
.linkbox { display: flex; gap: 8px; align-items: center; background: #f5f2f9; border-radius: 12px; padding: 10px 12px; font-size: 14px; word-break: break-all; }
.timeline { font-size: 13px; margin: 8px 0 0; padding: 0; list-style: none; max-height: 220px; overflow: auto; }
.timeline li { padding: 5px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; }
.timeline li span:first-child { color: var(--muted); white-space: nowrap; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 10px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 99px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 99; }
.toast.show { opacity: 1; }

@media (max-width: 820px) {
  .grid3 { grid-template-columns: 1fr 1fr; }
  .grid-new { grid-template-columns: 1fr; }
  .preview { max-width: 340px; margin: 0 auto; }
  table.list thead { display: none; }
  table.list tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.list td { display: flex; justify-content: space-between; gap: 10px; border: 0; padding: 4px 6px; }
  table.list td::before { content: attr(data-l); color: var(--muted); font-size: 12.5px; }
  .acts { justify-content: flex-start; }
}
@media (max-width: 480px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .card { padding: 18px; }
  h1 { font-size: 22px; }
}

select { width: 100%; font: inherit; font-size: 16px; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); }
.sepa-head { display: flex; flex-wrap: wrap; gap: 4px 18px; align-items: flex-end; justify-content: space-between; }
.switch { display: flex; gap: 8px; align-items: center; font-weight: 600; font-size: 14px; margin: 0; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--purple); }
.check-sepa { margin-top: 10px; }

.idgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.idslot { position: relative; display: flex; align-items: center; justify-content: center; aspect-ratio: 1.58; border: 2px dashed #cdbfe0; border-radius: 12px; background: #faf8fc; cursor: pointer; overflow: hidden; margin: 0; font-weight: 400; }
.idslot.done { border-style: solid; border-color: var(--green-d); }
.idslot.off { opacity: .35; pointer-events: none; }
.idslot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.idph { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; color: var(--muted); font-size: 13px; padding: 6px; }
.idph b { color: var(--ink); font-size: 14px; }
.idph::before { content: "📷"; font-size: 24px; }
