/* ===================================================
   GENERADOR DE HOJAS DE REGISTRO
   UI optimizada para usuarios +40 años
   Mobile-first | Botones grandes | Texto legible
   =================================================== */

/* ---------- RESET ---------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ---------- VARIABLES ---------- */
:root {
    --azul: #1e40af;
    --azul-claro: #dbeafe;
    --azul-hover: #1e3a8a;
    --verde: #16a34a;
    --verde-hover: #15803d;
    --rojo: #dc2626;
    --rojo-hover: #b91c1c;
    --naranja: #ea580c;
    --naranja-hover: #c2410c;
    --gris-50: #f9fafb;
    --gris-100: #f3f4f6;
    --gris-200: #e5e7eb;
    --gris-300: #d1d5db;
    --gris-500: #6b7280;
    --gris-700: #374151;
    --gris-900: #111827;
    --blanco: #ffffff;
    --radio: 12px;
    --sombra: 0 2px 8px rgba(0,0,0,.08);
    --sombra-md: 0 4px 16px rgba(0,0,0,.12);
}

/* ---------- BASE ---------- */
html {
    font-size: 18px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, 'Segoe UI', system-ui, Roboto, sans-serif;
    background: var(--gris-100);
    color: var(--gris-900);
    line-height: 1.6;
    min-height: 100vh;
    min-height: 100dvh;
}

/* ============================================
   APP CONTAINER
   ============================================ */
.app {
    max-width: 600px;
    margin: 0 auto;
    padding: 1rem;
    padding-bottom: 3rem;
}

/* ============================================
   HEADER
   ============================================ */
.header {
    background: var(--azul);
    color: var(--blanco);
    text-align: center;
    padding: 1.2rem 1rem;
    border-radius: var(--radio);
    margin-bottom: 1.2rem;
    box-shadow: var(--sombra-md);
}
.header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* ============================================
   ESTADO (info bar)
   ============================================ */
.estado {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    background: var(--blanco);
    border-radius: var(--radio);
    padding: 1rem 0.5rem;
    margin-bottom: 1.2rem;
    box-shadow: var(--sombra);
    border: 2px solid var(--azul-claro);
}

.estado-item {
    flex: 1;
    text-align: center;
    padding: 0.3rem 0.4rem;
}

.estado-separador {
    width: 2px;
    height: 40px;
    background: var(--gris-200);
    flex-shrink: 0;
}

.estado-numero {
    display: block;
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--azul);
    line-height: 1.1;
}

.estado-rango {
    font-size: 1.1rem;
}

.estado-texto {
    display: block;
    font-size: 0.72rem;
    color: var(--gris-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    margin-top: 0.15rem;
}

/* ============================================
   PASOS (1 -> 2)
   ============================================ */
.paso {
    display: flex;
    gap: 1rem;
    background: var(--blanco);
    border-radius: var(--radio);
    padding: 1.2rem;
    margin-bottom: 1rem;
    box-shadow: var(--sombra);
    border-left: 5px solid var(--azul);
    transition: opacity 0.3s, border-color 0.3s;
}

.paso-inactivo {
    opacity: 0.45;
    border-left-color: var(--gris-300);
}

.paso-activo {
    opacity: 1;
    border-left-color: var(--verde);
}

.paso-numero {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 50%;
    background: var(--azul);
    color: var(--blanco);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 800;
}

.paso-inactivo .paso-numero {
    background: var(--gris-300);
}

.paso-activo .paso-numero {
    background: var(--verde);
}

.paso-contenido {
    flex: 1;
    min-width: 0;
}

.paso-titulo {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gris-900);
    margin-bottom: 0.15rem;
}

.paso-desc {
    font-size: 0.82rem;
    color: var(--gris-500);
    margin-bottom: 0.8rem;
    line-height: 1.4;
}

/* ============================================
   BOTONES - Grandes y tactiles
   Min 56px de alto (recomendacion accesibilidad)
   ============================================ */
.boton {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    min-height: 56px;
    padding: 0.8rem 1.2rem;
    font-size: 1.05rem;
    font-weight: 700;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s, opacity 0.2s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    line-height: 1.3;
}
.boton:active {
    transform: scale(0.97);
}
.boton:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}
.boton svg {
    flex-shrink: 0;
}

.boton-principal {
    background: var(--azul);
    color: var(--blanco);
    font-size: 1.15rem;
    min-height: 62px;
    box-shadow: 0 4px 12px rgba(30, 64, 175, 0.3);
}
.boton-principal:hover:not(:disabled) { background: var(--azul-hover); }

.boton-verde {
    background: var(--verde);
    color: var(--blanco);
    font-size: 1.15rem;
    min-height: 62px;
    box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3);
}
.boton-verde:hover:not(:disabled) { background: var(--verde-hover); }

.boton-gris {
    background: var(--gris-200);
    color: var(--gris-700);
}
.boton-gris:hover { background: var(--gris-300); }

.boton-naranja {
    background: var(--naranja);
    color: var(--blanco);
}
.boton-naranja:hover { background: var(--naranja-hover); }

.boton-rojo {
    background: var(--rojo);
    color: var(--blanco);
}
.boton-rojo:hover { background: var(--rojo-hover); }

/* ============================================
   SECCION EXTRA (opciones avanzadas / historial)
   ============================================ */
.extra {
    background: var(--blanco);
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    margin-bottom: 0.8rem;
    overflow: hidden;
}

.extra-toggle {
    display: block;
    padding: 1rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gris-500);
    cursor: pointer;
    user-select: none;
    list-style: none;
    transition: color 0.2s;
}
.extra-toggle::-webkit-details-marker { display: none; }
.extra-toggle::before {
    content: '+ ';
    font-weight: 800;
    color: var(--gris-500);
}
details[open] > .extra-toggle::before {
    content: '- ';
}
.extra-toggle:hover {
    color: var(--azul);
}

.extra-contenido {
    padding: 0 1.2rem 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.extra-grupo {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.extra-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--gris-700);
}

.extra-input {
    padding: 0.75rem 1rem;
    border: 2px solid var(--gris-300);
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    width: 100%;
    outline: none;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    appearance: none;
}
.extra-input:focus {
    border-color: var(--azul);
    box-shadow: 0 0 0 3px rgba(30,64,175,.12);
}

.extra-linea {
    border: none;
    border-top: 2px solid var(--gris-100);
    margin: 0.3rem 0;
}

/* ============================================
   HISTORIAL
   ============================================ */
.historial {
    padding: 0 1.2rem 1.2rem;
    max-height: 300px;
    overflow-y: auto;
}

.historial-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--gris-100);
    font-size: 0.88rem;
}
.historial-item:last-child { border-bottom: none; }

.historial-pagina {
    font-weight: 700;
    color: var(--azul);
    min-width: 60px;
}
.historial-rango {
    color: var(--gris-700);
    font-weight: 600;
}
.historial-fecha {
    color: var(--gris-500);
    font-size: 0.75rem;
}

.sin-datos {
    text-align: center;
    padding: 1.2rem;
    color: var(--gris-500);
    font-size: 0.9rem;
}

/* ============================================
   TOAST (notificacion)
   ============================================ */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(120%);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    color: var(--blanco);
    font-size: 0.95rem;
    font-weight: 600;
    z-index: 9000;
    opacity: 0;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 8px 30px rgba(0,0,0,.2);
    max-width: 90vw;
    text-align: center;
    line-height: 1.3;
}
.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.toast.exito  { background: var(--verde); }
.toast.error  { background: var(--rojo); }
.toast.alerta { background: var(--naranja); }

/* ============================================
   HOJA A4 - Vista previa en pantalla
   ============================================ */
.hoja-a4 {
    display: none;
}

/* ============================================
   TABLA DE REGISTRO
   ============================================ */
.tabla-registro {
    width: 100%;
    border-collapse: collapse;
    font-family: -apple-system, 'Segoe UI', Arial, sans-serif;
    font-size: 9pt;
    table-layout: fixed;
    border: 2px solid #1a1a1a;
}

.tabla-registro thead tr {
    background: #1e293b;
    color: #ffffff;
}
.tabla-registro th {
    padding: 8px 4px;
    text-align: center;
    font-weight: 700;
    font-size: 7pt;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border: 1.5px solid #0f172a;
    border-bottom: 2.5px solid #0f172a;
    vertical-align: middle;
    line-height: 1.25;
}

.tabla-registro td {
    padding: 4px 5px;
    text-align: center;
    border-right: 1px solid #94a3b8;
    border-bottom: 1px solid #cbd5e1;
    height: 20px;
    vertical-align: middle;
    font-size: 9pt;
}
.tabla-registro td:last-child { border-right: none; }

.tabla-registro td:first-child {
    font-weight: 700;
    font-size: 8.5pt;
    border-right: 1.5px solid #64748b;
    background: #f8fafc;
}

.tabla-registro .fila-impar td:first-child { color: #1e293b; }
.tabla-registro .fila-par td:first-child { color: #b45309; }
.tabla-registro .fila-impar { background: #ffffff; }
.tabla-registro .fila-par { background: #f1f5f9; }
.tabla-registro .fila-separador td { border-bottom: 2px solid #334155; }

.col-codigo    { width: 5.5%; }
.col-hoja      { width: 8%; }
.col-cedula    { width: 8%; }
.col-delegacion { width: 9.5%; }
.col-cadena    { width: 8.5%; }
.col-ingreso   { width: 7.5%; }
.col-protocolo { width: 8%; }
.col-necro     { width: 7%; }
.col-inec      { width: 7%; }
.col-doctor    { width: 12%; }
.col-firma     { width: 11%; }
.col-otros     { width: 8%; }

/* ============================================
   IMPRESION A4 LANDSCAPE - B/N
   ============================================ */
@media print {
    @page { size: A4 landscape; margin: 0; }
    * { margin: 0; padding: 0; box-sizing: border-box; }
    html, body { width: 100%; height: 100%; background: white; overflow: hidden; }
    .no-print { display: none !important; }

    .hoja-a4 {
        display: block !important;
        width: 100%; height: 100vh;
        margin: 0; padding: 3mm;
        box-shadow: none; overflow: hidden;
        background: white;
    }
    .tabla-registro {
        width: 100%; height: 100%;
        border: 1.5px solid #000; font-size: 8.5pt;
    }
    .tabla-registro thead tr {
        background: #000 !important; color: #fff !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
    .tabla-registro th {
        padding: 4px 3px; font-size: 7.5pt; font-weight: 800;
        letter-spacing: 0.4px; border-color: #000; line-height: 1.2;
    }
    .tabla-registro td {
        padding: 1px 3px; font-size: 8pt;
        border-right: 1px solid #999; border-bottom: 1px solid #ccc; color: #000;
    }
    .tabla-registro td:first-child {
        background: transparent !important; font-weight: 700;
        font-size: 8pt; color: #000 !important; border-right: 1.5px solid #000;
    }
    .tabla-registro .fila-impar,
    .tabla-registro .fila-par { background: #fff !important; }
    .tabla-registro .fila-par td:first-child { color: #000 !important; }
    .tabla-registro .fila-separador td { border-bottom: 1.5px solid #000 !important; }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 640px) {
    html { font-size: 16px; }
    .app { padding: 0.8rem; }
    .header { padding: 1rem; border-radius: 10px; }
    .header h1 { font-size: 1.2rem; }
    .estado { padding: 0.8rem 0.3rem; }
    .estado-numero { font-size: 1.5rem; }
    .estado-rango { font-size: 0.95rem; }
    .paso { padding: 1rem; }
    .hoja-a4 { width: 100%; min-height: auto; padding: 2mm; overflow-x: auto; }
}

@media (min-width: 641px) and (max-width: 1024px) {
    .app { max-width: 700px; }
}

@media (min-width: 1025px) {
    html { font-size: 19px; }
    .app { max-width: 640px; padding: 2rem 1rem; }
}
