/* =============================================================================
   FirmaSegura — sistema de diseño
   Identidad: confianza legal. Tinta azul-marino para estructura, verde sello
   para validez/firmado, IBM Plex Mono para evidencia criptográfica.
   ============================================================================= */

:root {
  --ink: #16233a;
  --ink-soft: #3a4a63;
  --paper: #fbfbf8;
  --surface: #ffffff;
  --surface-2: #f5f6f2;
  --line: #e4e4dd;
  --line-strong: #cfd0c8;
  --muted: #6b7280;
  --accent: #1e7a5a;        /* verde sello: validez / firmado */
  --accent-soft: #e7f1ec;
  --accent-ink: #15563f;
  --danger: #b23a3a;
  --danger-soft: #f7ebeb;
  --warning: #9a6a12;
  --warning-soft: #f6efdd;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(22, 35, 58, 0.06), 0 8px 24px rgba(22, 35, 58, 0.06);
  --sans: 'IBM Plex Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-ink); }

/* ---------- Marca ---------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.brand .seal {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
}
.brand-lg { font-size: 20px; }
.brand-lg .seal { width: 34px; height: 34px; font-size: 16px; }

/* ---------- Layout de pantallas públicas centradas ---------- */
.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.stack { display: flex; flex-direction: column; gap: 16px; }

/* ---------- Tarjeta ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 28px;
  width: 100%;
  max-width: 400px;
}
.card-wide { max-width: 460px; }
.card h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -0.01em; }
.card .sub { color: var(--muted); font-size: 14px; margin: 0 0 20px; }

/* ---------- Campos ---------- */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 6px;
  font-weight: 500;
}
input[type="text"], input[type="email"], input[type="password"], input[type="tel"] {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(22, 35, 58, 0.1);
}
.input-otp {
  letter-spacing: 0.5em;
  text-align: center;
  font-family: var(--mono);
  font-size: 22px;
}

/* ---------- Botones ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s, border-color 0.15s;
}
.btn:active { transform: scale(0.99); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #0f1a2c; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover:not(:disabled) { background: var(--accent-ink); }
.btn-block { width: 100%; }

/* ---------- Mensajes ---------- */
.alert {
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--accent-soft); color: var(--accent-ink); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.hidden { display: none !important; }

/* ---------- Nota de seguridad al pie de tarjeta ---------- */
.secure-note {
  margin-top: 16px;
  padding: 10px 12px;
  background: var(--accent-soft);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--accent-ink);
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ---------- Pasos del firmante ---------- */
.steps { display: flex; gap: 6px; margin-bottom: 6px; }
.steps .bar {
  flex: 1;
  height: 4px;
  border-radius: 4px;
  background: var(--line-strong);
}
.steps .bar.done { background: var(--accent); }
.steps .bar.active { background: var(--ink); }
.step-label { font-size: 12px; color: var(--muted); margin-bottom: 18px; }

/* ---------- Documento (chip) ---------- */
.doc-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 16px;
}
.doc-chip .ico {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  display: grid; place-items: center;
  font-weight: 700; font-size: 11px;
}
.doc-chip .name { font-weight: 500; font-size: 14px; }
.doc-chip .meta { font-size: 12px; color: var(--muted); }

/* ---------- Firma (canvas) ---------- */
.sign-pad {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  touch-action: none;
  width: 100%;
  height: 140px;
  display: block;
}
.sign-actions { display: flex; gap: 8px; margin: 8px 0 16px; }
.sign-actions .btn { flex: 1; height: 36px; font-size: 13px; }

/* ---------- Consentimiento ---------- */
.consent {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--ink-soft);
}
.consent input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------- Estado final ---------- */
.result { text-align: center; padding: 8px 0; }
.result .mark {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid; place-items: center;
  margin: 0 auto 14px;
  font-size: 30px;
}
.result h2 { margin: 0 0 6px; font-size: 18px; }
.result p { color: var(--muted); font-size: 14px; margin: 0; }

/* ---------- Verificación (código mono) ---------- */
.verify-code {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 10px;
  word-break: break-all;
  color: var(--ink-soft);
}
.signer-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.signer-row .who { font-weight: 500; }
.signer-row .when { color: var(--muted); font-size: 12px; }

/* ---------- App shell mínimo ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.container { max-width: 960px; margin: 0 auto; padding: 32px 24px; }
.role-pill {
  font-size: 12px; font-family: var(--mono);
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 999px; color: var(--ink-soft);
}

/* ---------- Navegación (shell) ---------- */
.nav {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.nav a {
  padding: 12px 14px;
  font-size: 14px;
  color: var(--ink-soft);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.nav a:hover { color: var(--ink); }
.nav a.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 500; }

/* ---------- Encabezado de sección ---------- */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.page-head h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }

/* ---------- Tablas ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
table.data td { padding: 14px 16px; border-bottom: 1px solid var(--line); }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: var(--surface-2); }
.t-strong { font-weight: 500; }
.t-mono { font-family: var(--mono); font-size: 13px; }
.t-muted { color: var(--muted); font-size: 12px; }

/* ---------- Badges de estado ---------- */
.badge {
  display: inline-block;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 500;
}
.badge-ok { background: var(--accent-soft); color: var(--accent-ink); }
.badge-warn { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: var(--surface-2); color: var(--ink-soft); }
.badge-info { background: #e7eef7; color: #1f4f7a; }

/* ---------- Métricas ---------- */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.metric { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.metric .label { font-size: 13px; color: var(--muted); }
.metric .value { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; margin-top: 2px; }

/* ---------- Barra de consumo ---------- */
.usage-bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin: 6px 0; }
.usage-bar > span { display: block; height: 100%; background: var(--accent); }
.usage-bar.warn > span { background: var(--warning); }

/* ---------- Formularios en rejilla ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
select {
  width: 100%; height: 42px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  font-family: var(--sans); font-size: 15px; color: var(--ink); background: var(--surface);
}
select:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(22,35,58,0.1); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(22, 35, 58, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  width: 100%; max-width: 520px; padding: 24px; max-height: 90vh; overflow-y: auto;
}
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: var(--radius);
  font-size: 14px; box-shadow: var(--shadow); z-index: 100; opacity: 0; transition: opacity 0.2s;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--danger); }

/* ---------- Firmantes (constructor) ---------- */
.signer-item {
  display: grid; grid-template-columns: auto 1fr 1fr auto; gap: 10px; align-items: center;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 8px;
}
.signer-item .num {
  width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
}
.mode-toggle { display: flex; gap: 10px; }
.mode-opt {
  flex: 1; border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 12px; cursor: pointer;
}
.mode-opt.sel { border-color: var(--ink); border-width: 2px; background: var(--surface-2); }
.mode-opt .t { font-weight: 500; font-size: 14px; }
.mode-opt .d { font-size: 12px; color: var(--muted); margin-top: 2px; }

.empty { text-align: center; color: var(--muted); padding: 40px; font-size: 14px; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .signer-item { grid-template-columns: auto 1fr; }
}
@media (max-width: 480px) {
  .card { padding: 22px; }
}
