/* ============================================================================
   Sistema visual
   Concepto: la interfaz es el marco; el documento es papel.
   El fondo es un azul petróleo profundo y el documento es papel blanco real.
   El único color de acento es el azul de tinta estilográfica, presente solo
   donde hay firma: el trazo, el botón de firmar y el foco del teclado.
   ========================================================================= */

:root {
  --fondo:        #16232b;
  --fondo-alto:   #1e2f39;
  --fondo-borde:  #2b3f4b;
  --papel:        #ffffff;
  --tinta-texto:  #1a1d21;
  --tinta-suave:  #5b6670;
  --pauta:        #e4e2dd;
  --tinta:        #1e3fa8;
  --tinta-viva:   #17328b;
  --tinta-clara:  #5b7be0;
  --firmado:      #2e6b4f;
  --espera:       #8a6a16;
  --alerta:       #9d2b25;

  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  --sans:  system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono:  ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --pluma: "Segoe Script", "Bradley Hand", "Snell Roundhand", "Apple Chancery", "Lucida Handwriting", cursive;

  --hoja-ancho: 47rem;
  --radio: 3px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--fondo);
  color: #dbe3e8;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
}

a { color: var(--tinta-clara); }
a:hover { color: #93abee; }

:focus-visible {
  outline: 2px solid var(--tinta-clara);
  outline-offset: 2px;
  border-radius: 2px;
}

/* --- Marco de la aplicación ---------------------------------------------- */

.marco {
  max-width: calc(var(--hoja-ancho) + 4rem);
  margin: 0 auto;
  padding: 1.75rem 1.25rem 7rem;
}

.marco-ancho { max-width: 74rem; }

.encabezado-app {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.marca {
  font-family: var(--serif);
  font-size: 1.0625rem;
  letter-spacing: 0.01em;
  color: #eef3f6;
  text-decoration: none;
}
.marca span { color: #8aa0ac; }

.nota-app {
  font-size: 0.8125rem;
  color: #8aa0ac;
}
.nota-app a { color: #b9cad4; }

/* --- Hoja de papel ------------------------------------------------------- */

.hoja {
  background: var(--papel);
  color: var(--tinta-texto);
  border-radius: var(--radio);
  padding: clamp(1.75rem, 5vw, 4rem) clamp(1.5rem, 5vw, 4rem);
  box-shadow: 0 1px 0 rgba(255,255,255,.25),
              0 18px 45px -12px rgba(0,0,0,.55),
              0 2px 6px rgba(0,0,0,.35);
}

.hoja + .hoja { margin-top: 1.25rem; }

.titulo-doc {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(1.5rem, 4.2vw, 2.125rem);
  line-height: 1.2;
  margin: 0;
  color: var(--tinta-texto);
}

.filo {
  width: 42px;
  height: 3px;
  background: var(--tinta);
  margin: 1.1rem 0 1.5rem;
}

/* Bloque de metadatos: mismas filas de pauta que el PDF. */
.ficha { margin: 0 0 2rem; }
.ficha div {
  display: flex;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--pauta);
  font-size: 0.9375rem;
}
.ficha dt {
  flex: 0 0 9.5rem;
  margin: 0;
  color: var(--tinta-suave);
  font-size: 0.8125rem;
  padding-top: 0.15rem;
}
.ficha dd { margin: 0; font-family: var(--serif); }

/* --- Cuerpo del documento ------------------------------------------------ */

.cuerpo {
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.72;
  color: #24282d;
}
.cuerpo > *:first-child { margin-top: 0; }
.cuerpo p { margin: 0 0 1.1rem; }
.cuerpo h1 { font-size: 1.375rem; margin: 2.2rem 0 0.8rem; line-height: 1.3; }
.cuerpo h2 { font-size: 1.125rem; margin: 1.9rem 0 0.6rem; line-height: 1.35; }
.cuerpo h3 { font-size: 1rem; font-style: italic; margin: 1.4rem 0 0.4rem; }
.cuerpo ul, .cuerpo ol { margin: 0 0 1.1rem; padding-left: 1.4rem; }
.cuerpo li { margin-bottom: 0.45rem; }
.cuerpo strong { font-weight: 700; }
.cuerpo .corte {
  border: 0;
  border-top: 1px dashed var(--pauta);
  margin: 2rem 0;
}

/* --- Zona de firma ------------------------------------------------------- */

.zona-firma {
  margin-top: 2.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--pauta);
}

.zona-firma h2 {
  font-family: var(--sans);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--tinta-suave);
  margin: 0 0 1.25rem;
}

.campos {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  margin-bottom: 1.5rem;
}

label { display: block; font-size: 0.8125rem; color: var(--tinta-suave); margin-bottom: 0.35rem; }

input[type=text], input[type=email], input[type=password], input[type=date], textarea, select {
  width: 100%;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--tinta-texto);
  background: #fbfbfa;
  border: 1px solid #cfcdc8;
  border-radius: var(--radio);
  padding: 0.6rem 0.7rem;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--tinta);
  background: #fff;
  outline: 2px solid rgba(30,63,168,.18);
  outline-offset: 0;
}
textarea { min-height: 20rem; font-family: var(--mono); font-size: 0.8125rem; line-height: 1.6; }

/* Pestañas de modo de firma */
.modos { display: flex; gap: 0.25rem; margin-bottom: 0.75rem; }
.modos button {
  font: inherit;
  font-size: 0.875rem;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radio);
  padding: 0.35rem 0.75rem;
  color: var(--tinta-suave);
  cursor: pointer;
}
.modos button[aria-selected=true] {
  color: var(--tinta);
  border-color: rgba(30,63,168,.3);
  background: rgba(30,63,168,.06);
}

/* El renglón: la firma se traza sobre una línea de pauta real. */
.renglon { position: relative; }
.renglon canvas {
  display: block;
  width: 100%;
  height: 170px;
  background: #fdfdfc;
  border: 1px solid var(--pauta);
  border-radius: var(--radio);
  touch-action: none;
  cursor: crosshair;
}
.renglon::after {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 44px;
  border-bottom: 1px solid #b9b7b1;
  pointer-events: none;
}
.renglon.escrito::after { display: none; }

.escrito-previo {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 170px;
  border: 1px solid var(--pauta);
  border-radius: var(--radio);
  background: #fdfdfc;
  font-family: var(--pluma);
  font-size: 2.5rem;
  color: var(--tinta);
  padding-bottom: 2.5rem;
  overflow: hidden;
}

.pie-firma {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.6rem;
  font-size: 0.8125rem;
  color: var(--tinta-suave);
}
.enlace-sobrio {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--tinta);
  text-decoration: underline;
  cursor: pointer;
}

.consentimiento {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  margin: 1.5rem 0 0;
  padding: 1rem;
  background: #f7f7f5;
  border: 1px solid var(--pauta);
  border-radius: var(--radio);
  font-size: 0.875rem;
  color: #3c4249;
  line-height: 1.5;
}
.consentimiento input { margin-top: 0.2rem; flex: 0 0 auto; width: 1.05rem; height: 1.05rem; accent-color: var(--tinta); }
.consentimiento label { margin: 0; font-size: inherit; color: inherit; }

/* --- Botones ------------------------------------------------------------- */

.boton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  padding: 0.7rem 1.4rem;
  border-radius: var(--radio);
  border: 1px solid var(--tinta);
  background: var(--tinta);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
}
.boton:hover { background: var(--tinta-viva); border-color: var(--tinta-viva); color: #fff; }
.boton[disabled] { opacity: .45; cursor: not-allowed; }
.boton-claro {
  background: transparent;
  color: #cddae2;
  border-color: var(--fondo-borde);
}
.boton-claro:hover { background: var(--fondo-alto); color: #fff; border-color: #3c5666; }
.boton-papel { background: transparent; color: var(--tinta); }
.boton-papel:hover { background: rgba(30,63,168,.07); color: var(--tinta-viva); }

/* --- Barra fija de firma ------------------------------------------------- */

.barra {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: rgba(22,35,43,.94);
  border-top: 1px solid var(--fondo-borde);
  backdrop-filter: blur(8px);
  z-index: 20;
}
.barra-progreso {
  height: 2px;
  background: var(--tinta);
  width: 0;
  transition: width .15s linear;
}
.barra-interior {
  max-width: calc(var(--hoja-ancho) + 4rem);
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.barra-texto { font-size: 0.8125rem; color: #9db2bf; }

/* --- Estados y avisos ---------------------------------------------------- */

.sello {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.sello.firmado { color: var(--firmado); }
.sello.pendiente { color: var(--espera); }
.sello.anulado { color: var(--alerta); }

.aviso {
  padding: 0.85rem 1rem;
  border-radius: var(--radio);
  border: 1px solid;
  margin-bottom: 1.25rem;
  font-size: 0.9375rem;
}
.aviso.error { border-color: rgba(157,43,37,.4); background: rgba(157,43,37,.12); color: #f0c3c0; }
.aviso.bien  { border-color: rgba(46,107,79,.45); background: rgba(46,107,79,.15); color: #bfe2d0; }
.hoja .aviso.error { border-color: rgba(157,43,37,.35); background: #fcf3f2; color: #8a2822; }
.hoja .aviso.bien  { border-color: rgba(46,107,79,.35); background: #f1f7f3; color: #245840; }

/* --- Resultado de verificación ------------------------------------------ */

.veredicto {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-bottom: 1.25rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--pauta);
}
.veredicto .marca-estado {
  flex: 0 0 auto;
  width: 2.75rem; height: 2.75rem;
  border-radius: 50%;
  border: 2px solid currentColor;
  display: grid; place-items: center;
  font-size: 1.25rem;
  font-family: var(--serif);
}
.veredicto h1 { font-family: var(--serif); font-size: 1.375rem; margin: 0; }
.veredicto p { margin: 0.15rem 0 0; font-size: 0.875rem; color: var(--tinta-suave); }
.veredicto.si .marca-estado { color: var(--firmado); }
.veredicto.no .marca-estado { color: var(--alerta); }

.codigo {
  font-family: var(--mono);
  font-size: 0.9375rem;
  letter-spacing: 0.06em;
}

/* --- Panel --------------------------------------------------------------- */

.tabla { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.tabla th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--tinta-suave);
  padding: 0 0.6rem 0.55rem;
  border-bottom: 1px solid #c9c7c2;
}
.tabla td {
  padding: 0.7rem 0.6rem;
  border-bottom: 1px solid var(--pauta);
  vertical-align: top;
}
.tabla tr:hover td { background: #faf9f7; }
.tabla a { color: var(--tinta); }
.tabla .secundario { color: var(--tinta-suave); font-size: 0.8125rem; }

.barra-acciones {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1.25rem;
}
.crece { flex: 1 1 auto; }

.copiable {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  background: #f7f7f5;
  border: 1px solid var(--pauta);
  border-radius: var(--radio);
  padding: 0.5rem 0.6rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
  word-break: break-all;
}
.copiable button { flex: 0 0 auto; }

.vacio {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--tinta-suave);
  font-family: var(--serif);
  font-size: 1.0625rem;
}

.registro { list-style: none; margin: 0; padding: 0; font-size: 0.875rem; }
.registro li {
  display: flex;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--pauta);
}
.registro time { flex: 0 0 9.5rem; color: var(--tinta-suave); font-size: 0.8125rem; }

/* --- Acceso -------------------------------------------------------------- */

.acceso { max-width: 23rem; margin: 12vh auto 0; }
.acceso .hoja { padding: 2.25rem; }
.acceso h1 { font-family: var(--serif); font-size: 1.375rem; margin: 0 0 1.5rem; }
.acceso .campo + .campo { margin-top: 1rem; }
.acceso .boton { width: 100%; margin-top: 1.5rem; }

@media (max-width: 40rem) {
  .ficha div { flex-direction: column; gap: 0.15rem; }
  .ficha dt { flex-basis: auto; }
  .registro li { flex-direction: column; gap: 0.15rem; }
  .registro time { flex-basis: auto; }
  .barra-interior { padding: 0.7rem 1rem; }
  .barra-texto { display: none; }
  .barra .boton { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media print {
  body { background: #fff; }
  .barra, .zona-firma, .encabezado-app { display: none; }
  .hoja { box-shadow: none; padding: 0; }
}
