:root {
  --azul: #0e3a5f;
  --azul-claro: #1b5e8f;
  --acento: #d4a24e;
  --fondo: #f4f6f8;
  --tarjeta: #ffffff;
  --texto: #1c2733;
  --texto-suave: #5b6b7b;
  --borde: #dde4ea;
  --exito: #1e7d4f;
  --alerta: #b3541e;
  --peligro: #a83232;
  --radio: 10px;
  --sombra: 0 1px 3px rgba(16, 34, 51, 0.08), 0 4px 14px rgba(16, 34, 51, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  min-height: 100vh;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 0.95rem; }

.oculto { display: none !important; }

/* ---------- Pantalla de acceso ---------- */
#pantalla-auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--azul) 0%, #0a2942 60%, #071e31 100%);
  padding: 1rem;
}

.caja-auth {
  background: var(--tarjeta);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  width: 100%;
  max-width: 430px;
  padding: 2.2rem;
}

.marca { text-align: center; margin-bottom: 1.4rem; }
.marca h1 { font-size: 1.6rem; color: var(--azul); letter-spacing: 0.5px; }
.marca h1 span { color: var(--acento); }
.marca p { color: var(--texto-suave); font-size: 0.85rem; margin-top: 0.3rem; }

.pestanas { display: flex; gap: 0.5rem; margin-bottom: 1.2rem; }
.pestanas button {
  flex: 1; padding: 0.6rem; border: 1px solid var(--borde); background: #f0f3f6;
  border-radius: 8px; font-weight: 600; color: var(--texto-suave);
}
.pestanas button.activa { background: var(--azul); color: #fff; border-color: var(--azul); }

/* ---------- Formularios ---------- */
.campo { margin-bottom: 0.9rem; }
.campo label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--texto-suave); margin-bottom: 0.3rem; }
.campo input, .campo select, .campo textarea {
  width: 100%; padding: 0.6rem 0.7rem; border: 1px solid var(--borde);
  border-radius: 8px; background: #fff;
}
.campo input:focus, .campo select:focus { outline: 2px solid var(--azul-claro); border-color: transparent; }
.ayuda { font-size: 0.76rem; color: var(--texto-suave); margin-top: 0.25rem; }

.boton {
  display: inline-block; padding: 0.65rem 1.2rem; border: none; border-radius: 8px;
  background: var(--azul); color: #fff; font-weight: 600; font-size: 0.95rem;
  transition: background 0.15s;
}
.boton:hover { background: var(--azul-claro); }
.boton:disabled { opacity: 0.6; cursor: wait; }
.boton.completo { width: 100%; }
.boton.secundario { background: #e8edf2; color: var(--azul); }
.boton.secundario:hover { background: #dbe3ea; }
.boton.peligro { background: var(--peligro); }

.mensaje-error { color: var(--peligro); font-size: 0.85rem; margin-top: 0.6rem; min-height: 1.2em; }

/* ---------- Estructura de la app ---------- */
#app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }

.lateral {
  background: var(--azul); color: #fff; padding: 1.2rem 0.9rem;
  display: flex; flex-direction: column; gap: 0.3rem;
}
.lateral .logo { font-size: 1.15rem; font-weight: 700; padding: 0.4rem 0.6rem 1rem; }
.lateral .logo span { color: var(--acento); }
.lateral nav { display: flex; flex-direction: column; gap: 0.2rem; flex: 1; }
.lateral nav button {
  text-align: left; padding: 0.65rem 0.8rem; background: transparent; border: none;
  color: #cfe0ee; border-radius: 8px; font-size: 0.93rem; font-weight: 500;
}
.lateral nav button:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.lateral nav button.activa { background: rgba(255, 255, 255, 0.16); color: #fff; font-weight: 600; }
.lateral .pie { font-size: 0.75rem; color: #9db8cc; padding: 0.6rem; }

.contenido { padding: 1.6rem 2rem; max-width: 1100px; width: 100%; }

.encabezado { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.4rem; flex-wrap: wrap; gap: 0.6rem; }
.encabezado h2 { color: var(--azul); font-size: 1.35rem; }
.encabezado .usuario { display: flex; align-items: center; gap: 0.7rem; color: var(--texto-suave); font-size: 0.9rem; }

.tarjeta {
  background: var(--tarjeta); border-radius: var(--radio); box-shadow: var(--sombra);
  padding: 1.3rem; margin-bottom: 1.2rem;
}
.tarjeta h3 { font-size: 1.02rem; color: var(--azul); margin-bottom: 0.9rem; }

/* ---------- Dashboard ---------- */
.fila-estadisticas { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.estadistica { background: var(--tarjeta); border-radius: var(--radio); box-shadow: var(--sombra); padding: 1.1rem 1.2rem; }
.estadistica .valor { font-size: 1.9rem; font-weight: 700; color: var(--azul); }
.estadistica .valor.ok { color: var(--exito); }
.estadistica .valor.mal { color: var(--alerta); }
.estadistica .etiqueta { font-size: 0.8rem; color: var(--texto-suave); margin-top: 0.2rem; }

.barra-grupo { margin-bottom: 1rem; }
.barra-cabecera { display: flex; justify-content: space-between; font-size: 0.88rem; margin-bottom: 0.3rem; }
.barra-cabecera .nombre { font-weight: 600; }
.barra-cabecera .datos { color: var(--texto-suave); }
.barra { height: 12px; background: #e5eaef; border-radius: 6px; overflow: hidden; }
.barra > div { height: 100%; background: linear-gradient(90deg, var(--azul-claro), var(--azul)); border-radius: 6px; transition: width 0.4s; }
.barra > div.completa { background: linear-gradient(90deg, #2c9d68, var(--exito)); }

.alerta-item {
  padding: 0.6rem 0.9rem; border-radius: 8px; font-size: 0.88rem; margin-bottom: 0.5rem;
  background: #fdf3e7; border-left: 4px solid var(--alerta); color: #6b4a1e;
}
.alerta-item.vencida { background: #fbeaea; border-left-color: var(--peligro); color: #6e2323; }
.alerta-item.info { background: #eaf2fb; border-left-color: var(--azul-claro); color: #1e3d5c; }

.nota-legal { font-size: 0.78rem; color: var(--texto-suave); background: #f0f3f6; padding: 0.8rem 1rem; border-radius: 8px; line-height: 1.5; }

/* ---------- Certificados ---------- */
.zona-subida {
  border: 2px dashed var(--borde); border-radius: var(--radio); padding: 2rem;
  text-align: center; color: var(--texto-suave); background: #fbfcfd; transition: border-color 0.2s, background 0.2s;
}
.zona-subida.arrastrando { border-color: var(--azul-claro); background: #eef5fb; }
.zona-subida strong { color: var(--azul); }

table.lista { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.lista th { text-align: left; padding: 0.55rem 0.6rem; color: var(--texto-suave); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.4px; border-bottom: 2px solid var(--borde); }
table.lista td { padding: 0.6rem; border-bottom: 1px solid var(--borde); vertical-align: middle; }
table.lista tr:hover td { background: #f7fafc; }

.chip { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 20px; font-size: 0.74rem; font-weight: 600; }
.chip.extraido { background: #e2f3ea; color: var(--exito); }
.chip.verificado { background: #e2f3ea; color: var(--exito); }
.chip.pendiente { background: #fdf3e7; color: var(--alerta); }
.chip.error { background: #fbeaea; color: var(--peligro); }
.chip.email { background: #eaf2fb; color: var(--azul-claro); }
.chip.manual { background: #eef0f3; color: var(--texto-suave); }

.acciones-mini { display: flex; gap: 0.3rem; }
.acciones-mini button {
  border: 1px solid var(--borde); background: #fff; border-radius: 6px;
  padding: 0.25rem 0.55rem; font-size: 0.78rem; color: var(--azul);
}
.acciones-mini button:hover { background: #eef3f8; }

/* ---------- Modal ---------- */
#modal-fondo {
  position: fixed; inset: 0; background: rgba(10, 25, 40, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem;
}
.modal {
  background: #fff; border-radius: 12px; padding: 1.6rem; width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
}
.modal h3 { color: var(--azul); margin-bottom: 1rem; }
.modal.modal-ancha { max-width: 1040px; }
.editor-dividido { display: grid; grid-template-columns: 1.15fr 1fr; gap: 1.2rem; align-items: start; }
.panel-preview {
  border: 1px solid var(--borde); border-radius: 8px; background: #f4f6f8;
  min-height: 420px; max-height: 68vh; overflow: auto; display: flex;
  align-items: center; justify-content: center;
}
.panel-preview iframe { width: 100%; height: 66vh; border: none; border-radius: 8px; background: #fff; }
.panel-preview img { max-width: 100%; height: auto; border-radius: 8px; }
@media (max-width: 900px) {
  .editor-dividido { grid-template-columns: 1fr; }
  .panel-preview { min-height: 260px; max-height: 40vh; }
  .panel-preview iframe { height: 40vh; }
}
.modal .pie-modal { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.2rem; }

/* ---------- Escaneo de email ---------- */
.progreso-escaneo { font-size: 0.9rem; }
.progreso-escaneo .detalle { color: var(--texto-suave); margin: 0.4rem 0; font-style: italic; }
.progreso-escaneo .contadores { display: flex; gap: 1.4rem; flex-wrap: wrap; margin-top: 0.6rem; }
.progreso-escaneo .contadores div strong { font-size: 1.3rem; color: var(--azul); display: block; }
.progreso-escaneo .contadores div span { font-size: 0.76rem; color: var(--texto-suave); }

.girando {
  display: inline-block; width: 16px; height: 16px; border: 2.5px solid var(--borde);
  border-top-color: var(--azul); border-radius: 50%; animation: girar 0.8s linear infinite;
  vertical-align: middle; margin-right: 0.5rem;
}
@keyframes girar { to { transform: rotate(360deg); } }

#preview-flotante {
  position: fixed; z-index: 70; width: 420px; height: 520px;
  background: #fff; border: 1px solid var(--borde); border-radius: 10px;
  box-shadow: 0 12px 40px rgba(10, 25, 40, 0.35); overflow: hidden;
  pointer-events: none; /* no roba el cursor: el clic sigue siendo del enlace */
}
#preview-flotante iframe { width: 100%; height: 100%; border: none; background: #fff; }
#preview-flotante img { width: 100%; height: 100%; object-fit: contain; background: #f4f6f8; }
#preview-flotante .cargando-preview {
  display: flex; align-items: center; justify-content: center; height: 100%;
  color: var(--texto-suave); font-size: 0.85rem;
}

.banner-alerta {
  padding: 0.8rem 1.1rem; border-radius: 8px; font-size: 0.92rem; font-weight: 600;
  margin-bottom: 1rem; cursor: pointer; display: flex; align-items: center; gap: 0.6rem;
  animation: pulso 2.2s ease-in-out infinite;
}
.banner-alerta.critico { background: #fbeaea; border: 1.5px solid var(--peligro); color: #6e2323; }
.banner-alerta.aviso { background: #fdf3e7; border: 1.5px solid var(--alerta); color: #6b4a1e; animation: none; }
@keyframes pulso {
  0%, 100% { box-shadow: 0 0 0 0 rgba(168, 50, 50, 0.35); }
  50% { box-shadow: 0 0 0 7px rgba(168, 50, 50, 0); }
}

.popup-alerta-item {
  padding: 0.7rem 0.9rem; border-radius: 8px; font-size: 0.88rem; margin-bottom: 0.6rem;
  line-height: 1.45;
}
.popup-alerta-item.critico { background: #fbeaea; border-left: 4px solid var(--peligro); color: #6e2323; }
.popup-alerta-item.aviso { background: #fdf3e7; border-left: 4px solid var(--alerta); color: #6b4a1e; }

.aviso-ia {
  background: #fdf3e7; border: 1px solid #ecd9b8; color: #6b4a1e;
  padding: 0.7rem 1rem; border-radius: 8px; font-size: 0.85rem; margin-bottom: 1rem;
}

/* ---------- Guía de renovación (infografía) ---------- */
.linea-tiempo { position: relative; padding-left: 2.2rem; margin: 0.5rem 0; }
.linea-tiempo::before {
  content: ''; position: absolute; left: 0.65rem; top: 0.4rem; bottom: 0.4rem;
  width: 3px; background: linear-gradient(180deg, var(--azul-claro), var(--acento)); border-radius: 2px;
}
.hito { position: relative; padding: 0 0 1.3rem 0.4rem; }
.hito::before {
  content: ''; position: absolute; left: -1.94rem; top: 0.25rem; width: 14px; height: 14px;
  border-radius: 50%; background: #fff; border: 3.5px solid var(--azul-claro);
}
.hito.critico::before { border-color: var(--peligro); background: #fbeaea; }
.hito.pasado::before { border-color: var(--exito); background: #e2f3ea; }
.hito .cuando { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--azul-claro); }
.hito.critico .cuando { color: var(--peligro); }
.hito .que { font-size: 0.92rem; margin-top: 0.15rem; line-height: 1.45; }
.hito .fecha-real { display: inline-block; background: #eef3f8; border-radius: 6px; padding: 0.1rem 0.5rem; font-weight: 700; font-size: 0.85rem; color: var(--azul); }
.hito.critico .fecha-real { background: #fbeaea; color: var(--peligro); }

.lista-cotejo { display: grid; gap: 0.45rem; }
.item-cotejo {
  display: flex; align-items: flex-start; gap: 0.65rem; padding: 0.65rem 0.8rem;
  border: 1px solid var(--borde); border-radius: 8px; background: #fbfcfd; cursor: pointer;
  font-size: 0.9rem; line-height: 1.45; transition: background 0.15s;
}
.item-cotejo:hover { background: #f1f5f9; }
.item-cotejo input { width: 1.1rem; height: 1.1rem; margin-top: 0.15rem; flex-shrink: 0; cursor: pointer; }
.item-cotejo.marcado { background: #f0f9f4; border-color: #bfe3cf; }
.item-cotejo.marcado .texto-cotejo { text-decoration: line-through; color: var(--texto-suave); }
.item-cotejo .vigencia { display: inline-block; background: #fdf3e7; color: var(--alerta); border-radius: 5px; padding: 0.05rem 0.45rem; font-size: 0.74rem; font-weight: 700; margin-left: 0.35rem; white-space: nowrap; }

.botones-enlaces { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.botones-enlaces a {
  display: inline-block; padding: 0.6rem 1rem; border-radius: 8px; text-decoration: none;
  background: var(--azul); color: #fff; font-size: 0.88rem; font-weight: 600;
}
.botones-enlaces a.secundario { background: #e8edf2; color: var(--azul); }
.botones-enlaces a:hover { opacity: 0.9; }

.pasos-pcs { counter-reset: paso; display: grid; gap: 0.7rem; }
.paso-pcs { display: flex; gap: 0.9rem; align-items: flex-start; }
.paso-pcs .num {
  counter-increment: paso; flex-shrink: 0; width: 2rem; height: 2rem; border-radius: 50%;
  background: var(--acento); color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center;
}
.paso-pcs .num::before { content: counter(paso); }
.paso-pcs .cuerpo { font-size: 0.92rem; line-height: 1.5; }
.paso-pcs .cuerpo strong { color: var(--azul); }

@media (max-width: 800px) {
  #app { grid-template-columns: 1fr; }
  .lateral { flex-direction: row; align-items: center; overflow-x: auto; }
  .lateral nav { flex-direction: row; }
  .lateral .pie { display: none; }
  .contenido { padding: 1rem; }
}
