:root {
  --green: #31AF36;
  --green-dark: #1E7D27;
  --orange: #F79E1A;
  --orange-light: #F7C57C;
  --ink: #1d2320;
  --muted: #5b6660;
  --line: #dfe5e1;
  --bg: #f5f7f6;
  --card: #ffffff;
  --radius: 12px;
}

* { box-sizing: border-box; }

html { overflow-y: scroll; } /* stable width: no layout jump when the PDF makes the page scroll */

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--card); border-bottom: 3px solid var(--green);
}
.logo { height: 36px; width: auto; display: block; }
@media (max-width: 400px) {
  .topbar { padding: 10px 12px; gap: 8px; }
  .logo { height: 28px; }
  .langs { gap: 2px; }
  .langs a { min-width: 30px; padding: 6px 3px; font-size: .8rem; }
}
.test-banner {
  background: var(--orange); color: #3a2400; text-align: center; font-weight: 700;
  padding: 6px 12px; letter-spacing: .02em;
}

.page { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 20px 16px 32px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 16px; box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.card h1 { margin: 0 0 8px; font-size: 1.4rem; color: var(--green-dark); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 20px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn-primary { background: var(--green-dark); color: #fff; }
.btn-primary:hover { background: #17661f; }
.btn-block { width: 100%; }

.footer {
  padding: 16px; text-align: center; font-size: .75rem; color: var(--muted);
  border-top: 1px solid var(--line); background: var(--card);
}

/* ------------------------------------------------------------ utilities */
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; word-break: break-all; }
.center { text-align: center; }
.page-wide { max-width: 960px; }
.page-admin { max-width: 1200px; }
.card + .card, h1 + .card { margin-top: 16px; }
h1 { font-size: 1.35rem; line-height: 1.3; }
h2 { font-size: 1.05rem; margin: 16px 0 8px; }
.card h2:first-child { margin-top: 0; }

/* ------------------------------------------------------------ language switcher */
.langs { display: flex; gap: 4px; }
.langs a {
  min-width: 36px; padding: 6px; text-align: center; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-size: .85rem; font-weight: 600;
}
.langs a.active { background: var(--green-dark); color: #fff; }

/* ------------------------------------------------------------ forms & buttons */
.form { display: grid; gap: 12px; margin-top: 12px; }
.form label { display: grid; gap: 6px; font-weight: 600; font-size: .95rem; }
.form-grid { grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.input {
  width: 100%; min-height: 48px; padding: 10px 12px; font: inherit; font-weight: 400;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
.input:focus { outline: 2px solid var(--green); outline-offset: 1px; border-color: var(--green); }
.input-dob { font-size: 1.4rem; letter-spacing: .08em; text-align: center; }
textarea.input { min-height: 96px; resize: vertical; }
.btn-secondary { background: #fff; color: var(--green-dark); border-color: var(--green-dark); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-danger { background: #fff; color: #b3261e; border-color: #b3261e; }
.btn-wa { background: #25D366; color: #fff; }
.btn-small { min-height: 36px; padding: 0 12px; font-size: .9rem; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-tool { background: #fff; border-color: var(--line); color: var(--ink); min-height: 40px; }
.btn-tool.active { background: var(--orange-light); border-color: var(--orange); }
.alert {
  background: #fdecea; color: #8a1c13; border: 1px solid #f5c2bd; border-radius: 10px;
  padding: 10px 12px; margin: 12px 0;
}
.doc-name { font-size: 1.1rem; font-weight: 600; }

/* ------------------------------------------------------------ PDF viewer */
.doc-head { margin-bottom: 12px; }
.doc-head h1 { margin-bottom: 4px; }
.viewer { display: grid; gap: 12px; justify-items: center; padding-bottom: 8px; }
.loading { color: var(--muted); padding: 40px 0; }
.pdf-page { position: relative; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.pdf-page canvas { display: block; }
.pdf-overlay { position: absolute; inset: 0; }

.field {
  position: absolute; display: flex; align-items: center; justify-content: center;
  padding: 0 4px; overflow: hidden; white-space: nowrap; font: 600 14px/1 system-ui, sans-serif;
  color: #6b4500; background: rgba(247, 158, 26, .18); border: 2px dashed var(--orange);
  border-radius: 6px; cursor: pointer; text-align: center;
}
.field-text { display: inline-flex; align-items: center; gap: .3em; white-space: nowrap; }
.field-icon { font-size: 1.15em; line-height: 1; }
.field-word[hidden] { display: none; }
.field:not(.filled):not(.readonly):not(.field-edit) { animation: field-breathe 1.8s ease-in-out infinite; }
@keyframes field-breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(247,158,26,.55); background-color: rgba(247,158,26,.14); }
  50% { box-shadow: 0 0 0 6px rgba(247,158,26,0); background-color: rgba(247,158,26,.30); }
}
@media (prefers-reduced-motion: reduce) { .field:not(.filled):not(.readonly):not(.field-edit) { animation: none; } }
.field.filled { background: rgba(49, 175, 54, .10); border: 2px solid var(--green); color: var(--ink); font-weight: 500; }
.field.readonly { cursor: default; }
.field img { max-width: 100%; max-height: 100%; object-fit: contain; }
.field-check {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center; background: var(--green); color: #fff;
  font: 700 12px/1 system-ui, sans-serif;
}
.field-hint {
  position: absolute; z-index: 2; padding: 1px 5px; border-radius: 5px;
  background: var(--orange); color: #3a2400; font: 600 10px/1.25 system-ui, sans-serif;
  white-space: nowrap; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.field-hint[hidden] { display: none; }
.field.pulse { animation: pulse 1.2s ease-out; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(247,158,26,.7); } 100% { box-shadow: 0 0 0 14px rgba(247,158,26,0); } }

/* editor */
.viewer-editor .pdf-overlay { cursor: crosshair; }
.field-edit { cursor: move; touch-action: none; user-select: none; }
.field-edit.field-signature { background: rgba(30,125,39,.15); border-color: var(--green-dark); color: var(--green-dark); }
.field-edit.field-full_name { background: rgba(49,120,200,.15); border-color: #3178c8; color: #1f4f86; }
.field-edit.field-date { background: rgba(247,158,26,.2); border-color: var(--orange); color: #6b4500; }
.field-label { pointer-events: none; }
.field-del {
  position: absolute; top: -1px; right: -1px; width: 22px; height: 22px; border: 0; border-radius: 0 4px 0 6px;
  background: #b3261e; color: #fff; font-weight: 700; line-height: 1; cursor: pointer;
}
.field-resize {
  position: absolute; right: 0; bottom: 0; width: 14px; height: 14px; cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, currentColor 50%); touch-action: none;
}
.editor-head { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: flex-end; }
.editor-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ------------------------------------------------------------ sign bar */
.signbar {
  position: sticky; bottom: 0; z-index: 5; display: grid; gap: 10px;
  margin: 12px -16px -32px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -4px 12px rgba(0,0,0,.06);
}
.consent { display: flex; gap: 10px; align-items: flex-start; font-size: .85rem; line-height: 1.35; cursor: pointer; }
.signbar-buttons { display: grid; grid-template-columns: 1fr 1.3fr; gap: 8px; }
.signbar-buttons .btn { padding: 0 10px; }
.consent input { width: 22px; height: 22px; flex: none; margin-top: 1px; accent-color: var(--green-dark); }
.signbar .alert { margin: 0; }

/* ------------------------------------------------------------ modals */
body.modal-open { overflow: hidden; }
.modal {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0,0,0,.45);
}
.modal-box {
  width: 100%; max-width: 720px; background: #fff; border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 720px) { .modal { align-items: center; } .modal-box { border-radius: 16px; } }
.modal-box h2 { margin: 0 0 4px; }
.modal-sign { max-width: 900px; }
.sig-pad-wrap {
  margin: 8px 0 12px; border: 2px dashed var(--green); border-radius: 12px; background: #fff;
  height: min(46vh, 320px);
}
@media (orientation: landscape) and (max-height: 500px) { .sig-pad-wrap { height: 58vh; } }
#sig-canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 12px; }

/* ------------------------------------------------------------ status pages */
.spinner {
  width: 44px; height: 44px; margin: 8px auto 12px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--green); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.check {
  width: 56px; height: 56px; margin: 8px auto 12px; border-radius: 50%; display: grid; place-items: center;
  background: var(--green); color: #fff; font-size: 2rem; font-weight: 700;
}

/* ------------------------------------------------------------ admin */
.admin-nav { display: flex; gap: 12px; align-items: center; }
.admin-nav a { color: var(--green-dark); font-weight: 600; text-decoration: none; }
.admin-nav a.btn { color: #fff; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: #fff; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { font-size: .85rem; color: var(--muted); font-weight: 600; }
.table-compact td { padding: 6px 8px; font-size: .9rem; }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600;
  background: #eef1ef; color: var(--ink); white-space: nowrap;
}
.badge-sealed, .badge-delivered { background: #dcf3dd; color: #17661f; }
.badge-signed { background: #fff1d6; color: #7a4b00; }
.badge-blocked, .badge-failed, .badge-revoked, .badge-expired { background: #fdecea; color: #8a1c13; }
.detail-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.copy-row { display: flex; gap: 8px; }
.copy-row .input { flex: 1; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.actions form { margin: 0; }
.message { font-size: .95rem; }

/* ------------------------------------------------------------ verification */
.facts { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 8px 12px; margin: 12px 0 0; }
.facts dt { color: var(--muted); font-size: .9rem; }
.facts dd { margin: 0; font-weight: 600; min-width: 0; }
@media (max-width: 420px) { .facts { grid-template-columns: 1fr; gap: 2px; } .facts dd { margin-bottom: 8px; } }
.status-ok { color: var(--green-dark); }
.status-wait { color: #7a4b00; }
.result { border-width: 2px; }
.result-ok { border-color: var(--green); background: #effaef; }
.result-bad { border-color: #b3261e; background: #fdecea; }
.result-main { font-weight: 700; font-size: 1.05rem; margin: 0 0 6px; }
