/* ------------------------------------------------------------------ base */
:root {
    --verde:        #00723f;
    --verde-oscuro: #00552f;
    --verde-suave:  #e8f4ee;
    --amarillo:     #f2b705;
    --rojo:         #c62828;
    --gris-texto:   #2c3338;
    --gris-suave:   #6b7280;
    --borde:        #dfe3e8;
    --fondo:        #f4f6f8;
    --blanco:       #ffffff;
    --radio:        10px;
    --sombra:       0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }

/* El atributo hidden debe ganarle al display de cualquier componente
   (por ejemplo .campo, que es flex). */
[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--gris-texto);
    background: var(--fondo);
}

h1, h2, h3 { margin: 0 0 .35rem; line-height: 1.25; }
code { background: #eef1f4; padding: .1em .35em; border-radius: 4px; font-size: .9em; }
.apagado { color: var(--gris-suave); }

/* -------------------------------------------------------------- cabecera */
.encabezado {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: var(--verde);
    color: #fff;
    box-shadow: var(--sombra);
}
.encabezado h1 { font-size: 1.15rem; }
.encabezado p  { margin: 0; font-size: .875rem; opacity: .85; }
.encabezado-acciones { display: flex; gap: .5rem; }

.boton-icono {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem .85rem;
    border: 1px solid rgba(255, 255, 255, .35);
    border-radius: var(--radio);
    background: rgba(255, 255, 255, .12);
    color: #fff;
    font: inherit;
    font-size: .875rem;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s ease;
}
.boton-icono:hover  { background: rgba(255, 255, 255, .25); }
.boton-icono:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.boton-icono svg {
    width: 18px; height: 18px;
    fill: none; stroke: currentColor;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* --------------------------------------------------------------- paneles */
.contenedor { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }

.panel {
    background: var(--blanco);
    border: 1px solid var(--borde);
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}
.panel h2 { display: flex; align-items: center; gap: .6rem; font-size: 1.05rem; }
.paso {
    display: inline-grid;
    place-items: center;
    width: 26px; height: 26px;
    border-radius: 50%;
    background: var(--verde);
    color: #fff;
    font-size: .8rem;
    font-weight: 700;
}
.ayuda { margin: .25rem 0 1rem; color: var(--gris-suave); font-size: .9rem; }

/* ---------------------------------------------------------------- campos */
.campo { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; }
.campo > span { font-weight: 600; color: #454c53; }
.obligatorio { color: var(--rojo); }

input, select, textarea {
    font: inherit;
    padding: .55rem .65rem;
    border: 1px solid var(--borde);
    border-radius: 8px;
    background: #fff;
    color: inherit;
    width: 100%;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--verde);
    box-shadow: 0 0 0 3px rgba(0, 114, 63, .15);
}
textarea { resize: vertical; }

.fila-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
    justify-content: space-between;
}
.fila-selector .campo { flex: 1 1 420px; }
.resumen-global { margin: 0; font-size: .85rem; }

.rejilla {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: .9rem;
}
.campo-ancho    { grid-column: span 2; }
.campo-completo { grid-column: 1 / -1; }
@media (max-width: 640px) {
    .campo-ancho { grid-column: span 1; }
}

/* --------------------------------------------------------------- botones */
.boton {
    font: inherit;
    font-size: .9rem;
    padding: .55rem 1.1rem;
    border: 1px solid var(--borde);
    border-radius: 8px;
    background: #fff;
    color: var(--gris-texto);
    cursor: pointer;
}
.boton:hover { background: #f6f8fa; }
.boton-primario {
    background: var(--verde);
    border-color: var(--verde);
    color: #fff;
    font-weight: 600;
}
.boton-primario:hover { background: var(--verde-oscuro); }
.boton:disabled { opacity: .6; cursor: not-allowed; }
.acciones-formulario {
    display: flex;
    gap: .6rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

/* -------------------------------------------------------- lista usuarios */
.lista-usuarios { display: grid; gap: .9rem; }

.usuario {
    border: 1px solid var(--borde);
    border-left: 5px solid var(--borde);
    border-radius: var(--radio);
    padding: .9rem 1rem;
    background: #fdfdfd;
}
.usuario[data-estado="ACTIVO"]     { border-left-color: var(--verde); background: #f6fbf8; }
.usuario[data-estado="INACTIVO"]   { border-left-color: var(--rojo);  background: #fdf7f7; }
.usuario[data-estado="PENDIENTE"]  { border-left-color: var(--amarillo); }

.usuario-cabecera {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem 1rem;
    align-items: baseline;
    justify-content: space-between;
}
.usuario-nombre { font-weight: 700; font-size: 1rem; }
.usuario-datos {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: .35rem 1rem;
    margin: .6rem 0 .8rem;
    font-size: .85rem;
    color: #4b5259;
}
.usuario-datos b { color: var(--gris-suave); font-weight: 600; display: block; font-size: .75rem; text-transform: uppercase; letter-spacing: .02em; }

.etiqueta {
    display: inline-block;
    padding: .15rem .55rem;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .02em;
    background: #eceff2;
    color: #4b5259;
}
.etiqueta-nuevo   { background: #e5f0ff; color: #1b5fbf; }
.etiqueta-revisar { background: #fff3d6; color: #8a5b00; }

/* selector de estado en forma de botones */
.estados { display: flex; flex-wrap: wrap; gap: .4rem; }
.estados label {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .4rem .8rem;
    border: 1px solid var(--borde);
    border-radius: 999px;
    background: #fff;
    font-size: .82rem;
    cursor: pointer;
    user-select: none;
}
.estados input { position: absolute; opacity: 0; width: 0; height: 0; }
/* La clase .sel la aplica el JavaScript; :has() es el respaldo en navegadores
   modernos por si el script aun no ha corrido. */
.estados label.sel,
.estados label:has(input:checked) { color: #fff; font-weight: 600; }
.estados label.act.sel, .estados label.act:has(input:checked) { background: var(--verde);  border-color: var(--verde); }
.estados label.ina.sel, .estados label.ina:has(input:checked) { background: var(--rojo);   border-color: var(--rojo); }
.estados label.pen.sel, .estados label.pen:has(input:checked) { background: var(--amarillo); border-color: var(--amarillo); color: #4a3800; }
.estados label:focus-within { outline: 2px solid var(--verde); outline-offset: 2px; }

@media (max-width: 520px) {
    /* En pantallas angostas los tres botones de estado reparten el ancho
       en lugar de dejar uno solo en la ultima linea. */
    .estados label { flex: 1 1 30%; justify-content: center; }
}

/* Aviso de cupo de personas activas por dependencia */
.cupo {
    display: inline-block;
    margin: 0 0 1rem;
    padding: .35rem .75rem;
    border-radius: 999px;
    background: var(--verde-suave);
    color: var(--verde-oscuro);
    font-size: .82rem;
    font-weight: 600;
}
.cupo.cupo-lleno { background: #fff3d6; color: #8a5b00; }

/* Opcion "Si continua" deshabilitada porque la dependencia llego al maximo */
.estados label.bloqueada {
    opacity: .45;
    cursor: not-allowed;
    background: #f2f4f6;
}

/* Bloque de vinculacion dentro de la ficha del usuario */
.usuario-vinculacion {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 260px));
    justify-content: start;
    gap: .6rem;
    margin-top: .75rem;
}

.usuario-pie {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    align-items: flex-end;
    justify-content: space-between;
    margin-top: .75rem;
}
.usuario-pie .campo { flex: 1 1 320px; }
.usuario-acciones { display: flex; gap: .5rem; }
.guardado { font-size: .78rem; color: var(--verde); }

.vacio {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--gris-suave);
    border: 1px dashed var(--borde);
    border-radius: var(--radio);
}

/* -------------------------------------------------------------- alertas */
.alerta {
    padding: .7rem .9rem;
    border-radius: 8px;
    font-size: .875rem;
    margin: .75rem 0;
}
.alerta-error { background: #fdecea; color: #8f1d15; border: 1px solid #f6c9c4; }
.alerta ul { margin: .35rem 0 0; padding-left: 1.1rem; }

/* --------------------------------------------------------------- modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 50;
}
.modal[hidden] { display: none; }
.modal-caja {
    background: #fff;
    border-radius: 12px;
    width: min(820px, 100%);
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(16, 24, 40, .25);
}
.modal-encabezado, .modal-pie {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: 1rem 1.25rem;
}
.modal-encabezado { border-bottom: 1px solid var(--borde); }
.modal-pie { border-top: 1px solid var(--borde); justify-content: flex-end; }
.modal-cuerpo { padding: 1.25rem; overflow: auto; }
.cerrar-modal {
    border: 0; background: none; font-size: 1.6rem; line-height: 1;
    cursor: pointer; color: var(--gris-suave); padding: 0 .25rem;
}

.tarjetas {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: .75rem;
    margin-bottom: 1.25rem;
}
.tarjeta {
    border: 1px solid var(--borde);
    border-radius: var(--radio);
    padding: .8rem;
    text-align: center;
    background: #fafbfc;
}
.tarjeta .numero { display: block; font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.tarjeta .rotulo { font-size: .78rem; color: var(--gris-suave); text-transform: uppercase; letter-spacing: .03em; }
.tarjeta.act .numero { color: var(--verde); }
.tarjeta.ina .numero { color: var(--rojo); }
.tarjeta.pen .numero { color: #a97c00; }

.barra {
    height: 10px;
    border-radius: 999px;
    background: #eceff2;
    overflow: hidden;
    display: flex;
    margin: .25rem 0 1rem;
}
.barra i { display: block; height: 100%; }
.barra .act { background: var(--verde); }
.barra .ina { background: var(--rojo); }
.barra .pen { background: var(--amarillo); }

table.informe { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.informe th, table.informe td {
    text-align: left;
    padding: .45rem .5rem;
    border-bottom: 1px solid var(--borde);
}
table.informe th { color: var(--gris-suave); font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; }
table.informe td.num, table.informe th.num { text-align: right; width: 70px; }
table.informe tr.completa td { background: #f6fbf8; }
table.informe tr.completa td:first-child::after {
    content: " (cupo completo)";
    color: var(--verde);
    font-size: .75rem;
}

/* --------------------------------------------------------------- avisos */
.avisos {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    display: grid;
    gap: .5rem;
    z-index: 60;
    pointer-events: none; /* informativos: nunca tapan un boton */
}
.aviso {
    background: #22303c;
    color: #fff;
    padding: .65rem 1rem;
    border-radius: 8px;
    font-size: .875rem;
    box-shadow: 0 6px 18px rgba(16, 24, 40, .25);
    animation: aparecer .18s ease;
    max-width: 340px;
}
.aviso.ok    { background: var(--verde-oscuro); }
.aviso.error { background: #98211a; }
@keyframes aparecer { from { opacity: 0; transform: translateY(6px); } }

/* --------------------------------------------------------------- ingreso */
.ingreso { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.tarjeta-ingreso {
    background: #fff;
    border: 1px solid var(--borde);
    border-radius: 12px;
    box-shadow: var(--sombra);
    padding: 1.75rem;
    width: min(400px, 100%);
    display: grid;
    gap: .4rem;
}
.tarjeta-ingreso h1 { font-size: 1.1rem; }
.tarjeta-ingreso label { font-size: .85rem; font-weight: 600; margin-top: .5rem; }
.tarjeta-ingreso button { margin-top: 1rem; }

.pie {
    text-align: center;
    padding: 1rem;
    font-size: .8rem;
    color: var(--gris-suave);
}

@media print {
    .encabezado-acciones, .modal-pie, .avisos, .acciones-formulario { display: none !important; }
}
