:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #1c2330;
  --muted: #68738a;
  --accent: #2b5cff;
  --accent-ink: #ffffff;
  --line: #e3e7ee;
  --ok: #0a9d58;
  --warn: #c77700;
  font-size: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

header {
  display: flex; align-items: baseline; gap: 12px;
  padding: 14px 22px; background: var(--card); border-bottom: 1px solid var(--line);
}
.logo { font-weight: 800; font-size: 1.35rem; letter-spacing: 0.06em; color: var(--accent); }
.tagline { color: var(--muted); font-size: 0.9rem; flex: 1; }

.btn {
  display: inline-block; background: #eef1f6; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 18px;
  font-size: 1rem; cursor: pointer; user-select: none;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:hover { filter: brightness(0.96); }
.ghost {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 0.95rem; padding: 6px 10px; border-radius: 8px;
}
.ghost:hover { background: #eef1f6; color: var(--ink); }
.hint { color: var(--muted); font-size: 0.82rem; line-height: 1.45; }

/* dropzone */
#dropzone {
  max-width: 560px; margin: 9vh auto; padding: 48px 32px; text-align: center;
  background: var(--card); border: 2px dashed var(--line); border-radius: 18px;
}
#dropzone.over { border-color: var(--accent); background: #f0f4ff; }
.dropIcon { font-size: 3rem; }
.spinner {
  width: 34px; height: 34px; margin: 0 auto 12px;
  border: 4px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* work area */
#work { display: flex; gap: 18px; padding: 18px; align-items: flex-start; }
#pages { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 14px; align-items: center; }
.pageWrap { position: relative; box-shadow: 0 2px 10px rgba(20,30,60,0.12); }
.pageWrap canvas { display: block; max-width: 100%; }
.fieldBox {
  position: absolute; border: 1.5px solid var(--accent); border-radius: 2px;
  background: rgba(43, 92, 255, 0.08); cursor: pointer;
}
.fieldBox.filled { border-color: var(--ok); background: rgba(10, 157, 88, 0.10); }
.fieldBox.active { outline: 3px solid rgba(43, 92, 255, 0.45); }

#panel {
  width: 380px; flex-shrink: 0; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 16px; position: sticky; top: 14px;
  max-height: calc(100vh - 40px); display: flex; flex-direction: column;
}
.panelHead { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.panelHead h2 { font-size: 1rem; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#fieldList { overflow-y: auto; flex: 1; margin: 10px 0; }

.fieldRow { padding: 8px 6px; border-bottom: 1px solid var(--line); }
.fieldRow label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 3px; }
.fieldRow input[type="text"] {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 0.95rem; background: #fbfcfe;
}
.fieldRow input[type="text"]:focus { outline: 2px solid var(--accent); border-color: transparent; }
.fieldRow.checkbox { display: flex; align-items: center; gap: 10px; }
.fieldRow.checkbox label { margin: 0; flex: 1; }
.conf { font-size: 0.72rem; border-radius: 20px; padding: 1px 8px; margin-left: 6px; }
.conf.hi  { background: #e2f6ec; color: var(--ok); }
.conf.mid { background: #fdf1de; color: var(--warn); }
.sig { font-size: 0.78rem; color: var(--warn); }

/* perfil */
dialog {
  border: none; border-radius: 16px; padding: 22px 26px; width: min(520px, 92vw);
  max-height: 86vh; overflow-y: auto; box-shadow: 0 12px 50px rgba(10,20,50,0.25);
}
dialog::backdrop { background: rgba(15, 20, 35, 0.45); }
dialog h2 { margin: 0 0 4px; }
#profileForm { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin: 14px 0; }
#profileForm .full { grid-column: 1 / -1; }
#profileForm label { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 3px; }
#profileForm input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 0.95rem;
}
.dlgActions { display: flex; gap: 10px; justify-content: flex-end; }

@media (max-width: 860px) {
  #work { flex-direction: column; }
  #panel { width: 100%; position: static; max-height: none; }
}
