/* ---------------------------------------------------------------------------
   FirmaMap — hoja de estilos
   Desarrollado por Marco Antonio Posligua San Martín

   Un solo sistema para toda la aplicación: los valores viven en variables y
   las pantallas solo los usan. Está pensado para trabajo de oficina —lotes
   largos, mucha tabla— así que prima la legibilidad sobre el adorno.
--------------------------------------------------------------------------- */

:root {
  /* Marca */
  --rojo: #b3121f;
  --rojo-claro: #d92433;
  --rojo-tenue: #fdf2f3;
  --rojo-borde: #f3c9cd;

  /* Texto */
  --tinta: #16181d;
  --tinta-media: #4a4f58;
  --gris: #6b7280;
  --gris-claro: #9aa1ac;

  /* Superficies */
  --fondo: #f1f3f6;
  --papel: #ffffff;
  --papel-suave: #fafbfc;
  --borde: #e2e5ea;
  --borde-fuerte: #cdd2da;

  /* Estados */
  --verde: #0f7a3d;
  --verde-tenue: #f0faf3;
  --ambar: #9a6200;
  --ambar-tenue: #fff9ec;

  /* Forma */
  --radio: 10px;
  --radio-chico: 7px;
  --sombra: 0 1px 2px rgba(16, 20, 28, .05), 0 2px 8px rgba(16, 20, 28, .05);
  --sombra-alta: 0 6px 24px rgba(16, 20, 28, .12);
  --foco: 0 0 0 3px rgba(179, 18, 31, .18);

  /* Ritmo vertical */
  --esp-1: 4px;
  --esp-2: 8px;
  --esp-3: 12px;
  --esp-4: 16px;
  --esp-5: 24px;
  --esp-6: 32px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  background: var(--fondo);
  color: var(--tinta);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.centrado .contenido {
  min-height: 78vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Cabecera ------------------------------------------------------------ */
.cabecera {
  display: flex; justify-content: space-between; align-items: center;
  gap: var(--esp-4);
  background: var(--papel);
  border-bottom: 1px solid var(--borde);
  box-shadow: 0 1px 0 rgba(16, 20, 28, .03);
  padding: var(--esp-3) var(--esp-5);
  position: sticky; top: 0; z-index: 20;
}
.marca { display: flex; align-items: center; gap: var(--esp-3); min-width: 0; }
.marca .logo {
  display: grid; place-items: center;
  width: 38px; height: 38px; flex: none;
  border-radius: var(--radio-chico);
  background: linear-gradient(160deg, var(--rojo-claro), var(--rojo));
  color: #fff;
  box-shadow: 0 2px 6px rgba(179, 18, 31, .25);
}
.marca strong {
  display: block; font-size: 16px; font-weight: 650;
  letter-spacing: -.2px; line-height: 1.25;
}
.marca small { color: var(--gris); font-size: 12.5px; }

.nav { display: flex; align-items: center; gap: var(--esp-4); flex: none; }
.nav .usuario {
  color: var(--tinta-media); font-size: 13.5px;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nav .salir {
  color: var(--rojo); text-decoration: none; font-weight: 600; font-size: 13.5px;
  padding: 6px 12px; border-radius: var(--radio-chico);
  border: 1px solid var(--rojo-borde); background: var(--rojo-tenue);
  transition: background .15s, border-color .15s;
}
.nav .salir:hover { background: #fbe6e8; border-color: var(--rojo-claro); }

/* --- Estructura ---------------------------------------------------------- */
.contenido { max-width: 1080px; margin: var(--esp-5) auto var(--esp-6); padding: 0 var(--esp-5); }

.tarjeta {
  background: var(--papel);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: var(--esp-5);
  margin-bottom: var(--esp-4);
}
.tarjeta.angosta { width: min(440px, 92vw); }

h1 { font-size: 21px; font-weight: 650; letter-spacing: -.3px; margin: 0 0 var(--esp-4); }
h2 {
  font-size: 15px; font-weight: 650; letter-spacing: -.1px;
  margin: 0 0 var(--esp-4); padding-bottom: var(--esp-3);
  border-bottom: 1px solid var(--borde);
  color: var(--tinta);
  display: flex; align-items: center; gap: var(--esp-2);
}
/* El número del paso, cuando el título empieza por "1." y demás. */
h2::first-letter { color: var(--rojo); font-weight: 700; }
h3 { font-size: 14px; font-weight: 640; margin: var(--esp-4) 0 var(--esp-2); }

/* --- Formularios --------------------------------------------------------- */
label {
  display: block; margin-bottom: var(--esp-4);
  font-size: 12.5px; font-weight: 600; color: var(--tinta-media);
  letter-spacing: .1px;
}
label small {
  display: block; font-weight: 400; margin-top: var(--esp-1);
  color: var(--gris); font-size: 12px; line-height: 1.45;
}

input, select, textarea {
  display: block; width: 100%; margin-top: 5px;
  padding: 9px 11px;
  border: 1px solid var(--borde-fuerte); border-radius: var(--radio-chico);
  font: inherit; font-size: 14px; font-weight: 400;
  color: var(--tinta); background: var(--papel);
  transition: border-color .15s, box-shadow .15s;
}
input:hover, select:hover { border-color: var(--gris-claro); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--rojo); box-shadow: var(--foco);
}
input[type="file"] { padding: 7px; }
input[type="number"] { max-width: 100%; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%236b7280' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
  padding-right: 30px;
}

/* --- Botones ------------------------------------------------------------- */
button, .boton {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 17px; border: 1px solid transparent; border-radius: var(--radio-chico);
  background: var(--rojo); color: #fff;
  font: inherit; font-size: 14px; font-weight: 600; letter-spacing: .1px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, box-shadow .15s, border-color .15s, transform .06s;
}
button:hover, .boton:hover { background: var(--rojo-claro); }
button:active, .boton:active { transform: translateY(1px); }
button:focus-visible, .boton:focus-visible { outline: none; box-shadow: var(--foco); }
button:disabled { opacity: .5; cursor: default; transform: none; }

button.secundario, .boton.secundario {
  background: var(--papel); color: var(--tinta); border-color: var(--borde-fuerte);
}
button.secundario:hover, .boton.secundario:hover {
  background: var(--papel-suave); border-color: var(--gris-claro);
}
button.chico { padding: 6px 12px; font-size: 13px; }

button.enlace {
  background: none; border: 0; padding: 0; color: var(--rojo);
  font: inherit; font-size: 12px; font-weight: 600;
  text-decoration: underline; cursor: pointer;
}
button.enlace:hover { background: none; color: var(--rojo-claro); }

.botonera { display: flex; gap: var(--esp-2); align-items: center; flex-wrap: wrap; margin: var(--esp-2) 0 var(--esp-4); }
.acciones { display: flex; align-items: flex-end; gap: var(--esp-2); flex-wrap: wrap; }

/* --- Rejilla de campos --------------------------------------------------- */
.rejilla {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0 var(--esp-4);
}
.rejilla .ancho2 { grid-column: span 2; }

/* --- Tabla de documentos ------------------------------------------------- */
.tabla {
  width: 100%; border-collapse: collapse; margin-top: var(--esp-2);
  font-size: 13.5px;
}
.tabla th, .tabla td {
  text-align: left; padding: 9px 10px;
  border-bottom: 1px solid var(--borde); vertical-align: top;
}
.tabla th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--gris); font-weight: 650;
  background: var(--papel-suave);
  border-bottom: 1px solid var(--borde-fuerte);
  position: sticky; top: 0;
}
.tabla tbody tr:hover { background: var(--papel-suave); }
.tabla td:first-child { font-weight: 550; word-break: break-word; }
.fila-ok td:nth-child(2) { color: var(--verde); }
.fila-error td:nth-child(2) { color: var(--rojo); }
.tabla-envoltura { overflow-x: auto; margin: 0 calc(var(--esp-1) * -1); }

/* --- Mensajes ------------------------------------------------------------ */
.mensaje { margin: var(--esp-2) 0 0; font-size: 13.5px; color: var(--gris); min-height: 20px; }
.mensaje.ok { color: var(--verde); font-weight: 550; }
.mensaje.error, .error { color: var(--rojo); font-weight: 550; }
.ok-linea {
  color: var(--verde); background: var(--verde-tenue);
  border: 1px solid #cfe9d8; border-radius: var(--radio-chico);
  padding: 9px 12px; margin: 0 0 var(--esp-3); font-size: 14px;
}
.nota { color: var(--gris); font-size: 12.5px; line-height: 1.5; }

.registro {
  background: var(--papel-suave); border: 1px solid var(--borde);
  border-radius: var(--radio-chico); padding: var(--esp-3);
  font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px;
  line-height: 1.6; white-space: pre-wrap; max-height: 300px; overflow: auto;
  color: var(--tinta-media);
}

/* --- Zona para arrastrar documentos -------------------------------------- */
.soltar {
  border: 2px dashed var(--borde-fuerte); border-radius: var(--radio);
  padding: var(--esp-6) var(--esp-4); text-align: center;
  background: var(--papel-suave);
  transition: border-color .15s, background .15s;
}
.soltar.encima { border-color: var(--rojo); background: var(--rojo-tenue); }
.soltar .soltar-titulo {
  margin: 0 0 var(--esp-1); font-weight: 640; font-size: 15px; color: var(--tinta);
}
.soltar .nota { margin: 0; }
.soltar p { pointer-events: none; }        /* el arrastre no lo capturan los hijos */
.soltar button.enlace { pointer-events: auto; }

/* --- Cómo se decide el sitio de la firma --------------------------------- */
.modos { display: flex; gap: var(--esp-2); flex-wrap: wrap; margin: 0 0 var(--esp-4); }
.modo {
  flex: 1 1 250px; display: flex; align-items: flex-start; gap: var(--esp-2);
  margin: 0; padding: var(--esp-3) var(--esp-4); cursor: pointer;
  border: 1px solid var(--borde-fuerte); border-radius: var(--radio-chico);
  background: var(--papel); transition: border-color .15s, background .15s;
}
.modo:hover { border-color: var(--gris-claro); }
.modo input { width: auto; margin: 3px 0 0; flex: none; accent-color: var(--rojo); }
.modo span { display: block; }
.modo strong { display: block; color: var(--tinta); font-size: 13.5px; font-weight: 640; }
.modo small { display: block; color: var(--gris); margin-top: 2px; font-size: 12px; }
.modo:has(input:checked) {
  border-color: var(--rojo); background: var(--rojo-tenue);
  box-shadow: inset 0 0 0 1px var(--rojo);
}
.modo:has(input:checked) strong { color: var(--rojo); }

/* --- Rótulos y lugares sugeridos ----------------------------------------- */
.sugerencias { display: flex; flex-wrap: wrap; gap: var(--esp-2); margin: var(--esp-1) 0 var(--esp-2); }
.sugerencia {
  background: var(--papel); color: var(--tinta);
  border: 1px solid var(--borde-fuerte); border-radius: var(--radio-chico);
  padding: 7px 13px; text-align: left; font-weight: 400;
  transition: border-color .15s, background .15s;
}
.sugerencia strong { display: block; font-size: 13px; font-weight: 600; }
.sugerencia small { color: var(--gris); font-size: 11.5px; }
.sugerencia:hover { background: var(--papel-suave); border-color: var(--gris-claro); }
.sugerencia.elegida {
  border-color: var(--rojo); background: var(--rojo-tenue);
  box-shadow: inset 0 0 0 1px var(--rojo);
}
.sugerencia.elegida strong { color: var(--rojo); }
.combinacion { margin: var(--esp-1) 0 var(--esp-2); }
.combinacion .nota { margin: var(--esp-2) 0 0; }

/* --- Colocar la firma sobre la imagen de la hoja -------------------------- */
.lienzo {
  position: relative; display: inline-block; max-width: 100%;
  border: 1px solid var(--borde-fuerte); border-radius: var(--radio-chico);
  overflow: hidden; background: var(--papel);
  box-shadow: var(--sombra); cursor: crosshair; line-height: 0;
}
.lienzo img { display: block; max-width: 100%; height: auto; }
.sello-arrastrable {
  position: absolute; box-sizing: border-box;
  border: 2px solid var(--rojo); background: rgba(179, 18, 31, .14);
  border-radius: 3px; cursor: grab; touch-action: none;
  display: flex; align-items: center; justify-content: center;
  color: var(--rojo); font-size: 10.5px; font-weight: 700; line-height: 1;
  text-transform: uppercase; letter-spacing: .5px; user-select: none;
  box-shadow: 0 1px 6px rgba(179, 18, 31, .25);
}
.sello-arrastrable:active { cursor: grabbing; background: rgba(179, 18, 31, .24); }
#zona-fallback { margin-top: var(--esp-3); }
#zona-previa img, #previa {
  max-width: 100%; border: 1px solid var(--borde-fuerte);
  border-radius: var(--radio-chico); box-shadow: var(--sombra);
}

/* --- Acceso y respaldos --------------------------------------------------- */
.qr { text-align: center; }
.qr img {
  width: 190px; height: 190px;
  border: 1px solid var(--borde); border-radius: var(--radio-chico); padding: var(--esp-2);
  background: #fff;
}
.respaldos { columns: 2; list-style: none; padding: 0; margin: var(--esp-3) 0 var(--esp-4); }
.respaldos li {
  margin-bottom: 6px; font-family: Consolas, monospace; font-size: 14px;
  letter-spacing: .5px;
}
code {
  background: var(--papel-suave); border: 1px solid var(--borde);
  padding: 2px 6px; border-radius: 5px; font-size: 13px;
}

details { margin-top: var(--esp-3); }
summary {
  cursor: pointer; color: var(--tinta-media); font-size: 13.5px; font-weight: 550;
  padding: 6px 0; list-style-position: inside;
}
summary:hover { color: var(--rojo); }

.pie {
  text-align: center; color: var(--gris-claro); font-size: 12px;
  padding: var(--esp-5); border-top: 1px solid var(--borde); margin-top: var(--esp-4);
}

/* --- Pantallas estrechas -------------------------------------------------- */
@media (max-width: 720px) {
  body { font-size: 15px; }
  .cabecera { padding: var(--esp-3) var(--esp-4); }
  .marca small { display: none; }              /* el subtítulo estorba en móvil */
  .nav .usuario { display: none; }
  .contenido { padding: 0 var(--esp-3); margin-top: var(--esp-3); }
  .tarjeta { padding: var(--esp-4); border-radius: var(--radio-chico); }
  .rejilla { grid-template-columns: 1fr; }
  .rejilla .ancho2 { grid-column: span 1; }
  .botonera { gap: var(--esp-2); }
  .botonera button, .botonera .boton { flex: 1 1 auto; }
  .modo { flex: 1 1 100%; }
  .respaldos { columns: 1; }
  .soltar { padding: var(--esp-5) var(--esp-3); }

  /* La tabla se lee fatal en columnas estrechas: pasa a fichas. */
  .tabla thead { display: none; }
  .tabla, .tabla tbody, .tabla tr, .tabla td { display: block; width: 100%; }
  .tabla tr {
    border: 1px solid var(--borde); border-radius: var(--radio-chico);
    margin-bottom: var(--esp-2); padding: var(--esp-2); background: var(--papel);
  }
  .tabla td { border: 0; padding: 3px 4px; }
  .tabla td:first-child { font-weight: 640; font-size: 14px; }
  .tabla td:empty { display: none; }
}

/* En pantallas táctiles el objetivo debe ser cómodo de tocar. */
@media (pointer: coarse) {
  button, .boton { padding: 11px 18px; }
  button.chico { padding: 8px 13px; }
  input, select { padding: 11px; font-size: 16px; }  /* 16px evita el zoom de iOS */
  .sello-arrastrable { border-width: 3px; }
}

@media print {
  .cabecera, .nav, .botonera, .soltar, .pie { display: none; }
  .tarjeta { box-shadow: none; border: 0; }
}

/* --- Lista de certificados guardados ------------------------------------- */
.lista-certificados { list-style: none; padding: 0; margin: 0 0 var(--esp-3); }
.certificado {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--esp-3); flex-wrap: wrap;
  padding: var(--esp-3) var(--esp-4); margin-bottom: var(--esp-2);
  border: 1px solid var(--borde); border-left: 3px solid var(--verde);
  border-radius: var(--radio-chico); background: var(--papel-suave);
}
.certificado-datos { min-width: 0; }
.certificado-datos strong { display: block; font-size: 14px; font-weight: 640; }
.certificado-datos small {
  display: block; color: var(--gris); font-size: 12px; margin-top: 2px;
  word-break: break-word;
}
.certificado-acciones { display: flex; gap: 6px; flex-wrap: wrap; flex: none; }

@media (max-width: 720px) {
  .certificado { flex-direction: column; align-items: stretch; }
  .certificado-acciones button { flex: 1 1 auto; }
}
