:root {
    --primary: #0056b3;
    --secondary: #004494;
    --bg-light: #f4f7f6;
    --text-dark: #333;
    --sidebar-width: 250px;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
body { display: flex; height: 100vh; height: 100dvh; background-color: var(--bg-light); overflow: hidden; }

/* LOGIN */
#pantalla-login { display: flex; justify-content: center; align-items: center; width: 100vw; height: 100vh; background-color: var(--bg-light); z-index: 9999; position: fixed; top: 0; left: 0; }
.login-box { background: white; padding: 30px; border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); width: 100%; max-width: 350px; }
.login-box h2 { text-align: center; margin-bottom: 20px; color: var(--primary); }
.login-box input { width: 100%; padding: 10px; margin-bottom: 15px; border: 1px solid #ccc; border-radius: 4px; }
.login-box button { width: 100%; background: var(--primary); color: white; padding: 10px; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; font-weight: bold; }

/* DASHBOARD */
#pantalla-erp { display: none; width: 100%; height: 100%; }
.sidebar { width: var(--sidebar-width); background-color: #1e2b3c; color: white; display: flex; flex-direction: column; }
.sidebar-header { padding: 20px; text-align: center; border-bottom: 1px solid #2c3e50; font-weight: bold; font-size: 18px; }
.sidebar-menu { flex: 1; overflow-y: auto; padding: 10px 0; }
.menu-item { padding: 15px 20px; color: #aab6c3; cursor: pointer; display: flex; align-items: center; gap: 15px; border-left: 4px solid transparent; }
.menu-item:hover, .menu-item.active { background-color: #2c3e50; color: white; border-left-color: #3498db; }
.menu-item i { width: 20px; text-align: center; font-size: 18px; }
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar { background-color: white; height: 60px; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.user-info { display: flex; align-items: center; gap: 15px; }
.btn-logout { background-color: #dc3545; color: white; border: none; padding: 8px 15px; border-radius: 4px; cursor: pointer; font-size: 13px; font-weight: bold; }
.content-area { padding: 20px; flex: 1; overflow-y: auto; }
.vista-modulo { display: none; animation: fadeIn 0.4s ease; }
.vista-modulo.active { display: block; }
.card { background: white; padding: 25px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); margin-bottom: 20px; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* MENÚ LATERAL COLAPSABLE (botón de tres rayitas) */
.btn-menu-lateral { background: none; border: none; font-size: 24px; color: var(--primary); cursor: pointer; padding: 8px 12px; margin-left: -8px; border-radius: 4px; line-height: 1; }
.btn-menu-lateral:hover { background: #eef2f7; }
.sidebar { transition: margin-left .25s ease, transform .25s ease; flex-shrink: 0; }
.sidebar-overlay { display: none; }
/* Escritorio: el menú se oculta/mostrar empujando el contenido */
#pantalla-erp.sidebar-oculto .sidebar { margin-left: calc(-1 * var(--sidebar-width)); }

/* UI FORMULARIOS */
.tab-menu { display: flex; flex-wrap: wrap; gap: 5px; border-bottom: 2px solid var(--primary); margin-bottom: 20px; padding-bottom: 10px; }
.tab-btn { background-color: #e9ecef; border: none; padding: 8px 12px; cursor: pointer; font-size: 13px; font-weight: bold; border-radius: 4px 4px 0 0; color: #333; }
.tab-btn.active { background-color: var(--primary); color: white; }
.tab-content { display: none; }
.tab-content.active { display: block; }
fieldset { border: 1px solid #ccc; border-radius: 5px; margin-bottom: 20px; padding: 15px; background-color: #fafafa; }
legend { background-color: var(--primary); color: white; padding: 5px 10px; border-radius: 4px; font-weight: bold; font-size: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 10px; }
input, select, textarea { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; margin-top: 5px; font-size: 13px; }
label { font-size: 12px; font-weight: bold; color: #333; display: block; margin-top: 8px; text-transform: uppercase; }
table { width: 100%; border-collapse: collapse; margin-top: 10px; }
th, td { border: 1px solid #ccc; padding: 6px; text-align: center; }
th { background-color: #e9ecef; font-size: 12px; }
.btn-form { background-color: var(--primary); color: white; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer; font-size: 14px; font-weight: bold; }
.btn-secundario { background-color: #6c757d; }
.btn-buscar { background-color: #28a745; padding: 8px 15px; margin-top: 5px; color: white; border: none; border-radius: 4px; cursor: pointer; }
.btn-copiar { background-color: #17a2b8; padding: 6px 12px; font-size: 12px; color: white; border: none; border-radius: 4px; cursor: pointer; }
.buscador-container { background: #e9ecef; padding: 12px; border-radius: 5px; margin-bottom: 15px; display: flex; gap: 10px; align-items: flex-end; justify-content: space-between; position: relative; }
.seccion-interna { background: #eef2f5; padding: 10px; border-radius: 5px; margin-bottom: 15px; border: 1px solid #d1d8dd; }
.sugerencias-flotantes { position: absolute; top: 100%; left: 0; right: 0; background: white; border: 1px solid #ccc; border-top: none; border-radius: 0 0 5px 5px; max-height: 200px; overflow-y: auto; z-index: 1000; box-shadow: 0 4px 6px rgba(0,0,0,0.1); display: none; }
.sugerencia-item { padding: 10px; cursor: pointer; border-bottom: 1px solid #eee; font-size: 13px; }
.sugerencia-item:hover { background-color: #f1f1f1; }

.doc-impresion { display: none; background: white; padding: 25px; border: 1px solid #ddd; max-width: 900px; margin: 0 auto; color: #000; }
.page-break { page-break-after: always !important; break-after: page !important; margin-bottom: 30px; }
.input-nota { width: 100%; border: 1px solid #ccc; border-radius: 3px; font-size: 13px; text-align: center; padding: 6px 2px; }
.input-nota:focus { border-color: var(--primary); outline: none; background-color: #e8f0fe; }

/* ==========================================================================
   RESPONSIVE (celular y tablet)
   ========================================================================== */
@media (max-width: 900px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    /* El menú pasa a ser un panel que se desliza sobre el contenido; oculto por defecto */
    .sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 2000; width: min(82vw, var(--sidebar-width)); transform: translateX(-100%); margin-left: 0 !important; box-shadow: none; }
    #pantalla-erp.sidebar-abierto .sidebar { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,.35); }
    .sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1999; }
    #pantalla-erp.sidebar-abierto .sidebar-overlay { display: block; }
    .main-content { width: 100%; }
    .topbar { padding: 0 12px; }
    .user-info { gap: 8px; }
    .user-correo { display: none; }
    .btn-logout { padding: 8px 12px; }
    .content-area { padding: 12px; }
    .card { padding: 15px; }
    .buscador-container { flex-wrap: wrap; }
    .login-box { margin: 0 16px; }
    /* Lo que sea más ancho que la pantalla se desplaza en horizontal en vez de romper el diseño */
    .content-area { overflow-x: auto; }
    /* 16px evita que iOS haga zoom al tocar un campo */
    input, select, textarea { font-size: 16px; }
}

/* OCULTAR PLANTILLAS EN PANTALLA NORMAL */
#ficha-impresion-oficial,
#print-lista-curso-container {
    display: none !important;
}

/* ==========================================================================
   REGLAS DE IMPRESIÓN MAESTRAS (CERTIFICADOS Y FICHA ESTUDIANTE)
   ========================================================================== */
@media print {
    /* 1. OCULTAR TODA LA INTERFAZ DEL ERP (Menús, botones, barra lateral) */
    .sidebar, .sidebar-overlay, .topbar, #pantalla-login, .tab-menu, .buscador-container, 
    button, select, input, label, fieldset, 
    #btnImprimirDoc, .card > div:first-child {
        display: none !important;
    }

    /* 2. RESETEAR CONTENEDORES PRINCIPALES AL TAMAÑO DEL PAPEL */
    body, html, #pantalla-erp, .main-content, .content-area {
        background: white !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        display: block !important;
        overflow: visible !important;
    }

    /* ==========================================================================
       MODO A: IMPRESIÓN DE LA FICHA DEL ESTUDIANTE (MÁXIMO 2 HOJAS)
       ========================================================================== */
    body.imprimir-ficha-estudiante .vista-modulo:not(#vista-estudiantes) {
        display: none !important;
    }
    
    /* Ocultar el formulario web de edición, dejar SOLO la plantilla de impresión */
    body.imprimir-ficha-estudiante #vista-estudiantes > *:not(#ficha-impresion-oficial) {
        display: none !important; 
    }
    
    body.imprimir-ficha-estudiante #ficha-impresion-oficial {
        display: block !important;
        visibility: visible !important;
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Reducir el tamaño de letra, tablas e imágenes drásticamente */
    #ficha-impresion-oficial * {
        font-size: 8pt !important; 
        line-height: 1.1 !important;
        color: #000 !important;
    }
    
    #ficha-impresion-oficial img, 
    #ficha-impresion-oficial svg {
        max-height: 45px !important; /* Evita que los logos ocupen una página entera */
        max-width: 60px !important;
        object-fit: contain !important;
    }

    #ficha-impresion-oficial table {
        width: 100% !important;
        border-collapse: collapse !important;
        margin-bottom: 4px !important;
    }

    #ficha-impresion-oficial td, 
    #ficha-impresion-oficial th {
        padding: 2px 4px !important;
        border: 1px solid #000 !important;
    }

    #ficha-impresion-oficial h2 { font-size: 11pt !important; margin: 4px 0 !important; text-align: center; }
    #ficha-impresion-oficial h3 { font-size: 9pt !important; margin: 3px 0 !important; background: #eee; padding: 2px; }

    /* Evitar que las tablas se corten por la mitad entre la hoja 1 y 2 */
    #ficha-impresion-oficial table, 
    #ficha-impresion-oficial tr { 
        page-break-inside: avoid !important; 
    }

 
    /* ==========================================================================
   ESTILOS EXCLUSIVOS: INFORMES DE NOTAS, PERSONALIDAD Y ALUMNO REGULAR
   ========================================================================== */
@media print {
    /* 1. Ocultar absolutamente todo en la pantalla */
    body.imprimir-documento-oficial * {
        visibility: hidden !important;
    }

    /* 2. Resetear el fondo de la página */
    body.imprimir-documento-oficial,
    body.imprimir-documento-oficial html {
        background: white !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* 3. Hacer visible ÚNICAMENTE el contenedor de documentos y todo lo que esté dentro */
    body.imprimir-documento-oficial #contenedor-documento-impresion,
    body.imprimir-documento-oficial #contenedor-documento-impresion * {
        visibility: visible !important;
    }

    /* 4. Forzar el contenedor a la esquina superior izquierda (Evita hojas en blanco por márgenes ocultos) */
    body.imprimir-documento-oficial #contenedor-documento-impresion {
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* 5. Asegurar que SOLO se imprima el documento activo (Notas, Personalidad o Regular) */
    body.imprimir-documento-oficial .doc-impresion:not(.active-print) {
        display: none !important;
    }

    body.imprimir-documento-oficial .doc-impresion.active-print {
        display: block !important;
        width: 100% !important;
        padding: 10mm 15mm !important; /* Margen interno del documento */
        box-sizing: border-box !important;
        border: none !important;
        box-shadow: none !important;
    }

    /* 6. Saltos de página y tamaño de papel */
    body.imprimir-documento-oficial .page-break {
        page-break-after: always !important;
        break-after: page !important;
        margin-bottom: 0 !important;
        border: none !important; /* Quita el borde de previsualización en papel */
    }

    @page {
        size: letter portrait;
        margin: 0mm !important; /* Margen 0 elimina la URL y la Fecha automáticas del navegador */
    }
}
    /* ==========================================================================
       CONFIGURACIÓN GENERAL DE LA PÁGINA
       ========================================================================== */
 /* CONFIGURACIÓN GENERAL DE LA PÁGINA */
    @page { 
        size: letter portrait; 
        margin: 0mm !important; /* Margen cero elimina la URL del navegador */
    }

    body.imprimir-ficha-estudiante #ficha-impresion-oficial {
        display: block !important;
        visibility: visible !important;
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 10mm 15mm !important; /* Compensa el margen cero para no cortar el texto */
        box-sizing: border-box !important;
    
    }
    /* ==========================================================================
       DISEÑO INTERNO DE LA FICHA DE MATRÍCULA Y SALUD
       ========================================================================== */
    
    /* 1. Cabecera con logos a los extremos */
    .print-header {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        border-bottom: 2px solid #000 !important;
        padding-bottom: 8px !important;
        margin-bottom: 12px !important;
    }
    .print-header img, .print-header svg {
        height: 55px !important;
        max-width: 80px !important;
        object-fit: contain !important;
    }
    .print-header-title {
        text-align: center !important;
        flex-grow: 1 !important;
    }
    .print-header-title h2 {
        font-size: 13pt !important;
        margin: 0 !important;
        font-weight: bold !important;
        text-transform: uppercase !important;
    }

    /* 2. Títulos de sección resaltados (Fondo negro, letra blanca) */
    .print-seccion-titulo {
        background-color: #94b3d3 !important; /* Azul muy oscuro/Casi negro */
        color: #f1eded !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        font-weight: bold !important;
        font-size: 9.5pt !important;
        padding: 5px 8px !important;
        margin-top: 12px !important;
        margin-bottom: 6px !important;
        text-transform: uppercase !important;
        text-align: left !important;
        border-radius: 3px !important;
    }

    /* 3. Contenedor de firma perfectamente centrado al final de la hoja */
   /* Contenedor de firma perfectamente centrado al final de la hoja */
    .contenedor-firma-apoderado {
        margin-top: 35px !important;
        display: flex !important;
        flex-direction: column !important; /* Corrige la alineación vertical */
        align-items: center !important;
        justify-content: center !important;
        page-break-inside: avoid !important;
        position: relative !important;
        width: 100% !important;
    }
    .linea-firma {
        width: 280px !important;
        border-top: 1.5px solid #000 !important;
        text-align: center !important;
        padding-top: 5px !important;
        font-weight: bold !important;
        font-size: 10pt !important;
        text-transform: uppercase !important;
    }
    .fecha-firma-derecha {
        position: absolute !important;
        right: 0 !important;
        bottom: 0 !important;
        font-size: 9pt !important;
    }
}
/* Selector del año de administración (barra superior) */
.selector-anio { display: flex; align-items: center; gap: 6px; margin-left: auto; margin-right: 14px; font-weight: bold; color: var(--primary); }
.selector-anio select { font-weight: bold; padding: 5px 8px; border: 2px solid var(--primary); border-radius: 6px; background: #fff; color: var(--primary); cursor: pointer; }
.selector-anio.otro-anio select { background: #fff3cd; border-color: #b45309; color: #7a4b00; }
.selector-anio.otro-anio i { color: #b45309; }
.banner-anio { background: #fff3cd; border-bottom: 2px solid #f3cf9a; color: #7a4b00; text-align: center; font-size: 13px; padding: 5px 10px; font-weight: bold; }
@media (max-width: 768px) { .selector-anio .txt-anio { display: none; } .selector-anio { margin-right: 6px; } }
@media print { .selector-anio, .banner-anio { display: none !important; } }
