/* 
 * SGAc 2025 - Design System 
 * Basado en Estética Premium y Dinámica
 */

:root {
    /* Paleta de Colores Institucional (Editable por Tenant) */
    --primary: #2563eb;         /* Azul Premium */
    --primary-dark: #1e40af;
    --primary-light: #dbeafe;
    
    --secondary: #64748b;
    --accent: #f59e0b;          /* Ámbar para alertas */
    
    /* Colores de Fondo y Superficie */
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    
    /* Estados de Evaluación */
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    
    /* Bordes y Sombras */
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    /* Radio de Borde */
    --radius: 0.75rem;
}

/* Modo Oscuro (Opcional) */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-main: #0f172a;
        --bg-card: #1e293b;
        --text-main: #f8fafc;
        --text-muted: #94a3b8;
        --border-color: #334155;
    }
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.card {
    background-color: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    padding: 1.5rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

.btn {
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background-color: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-back:hover {
    background-color: #e2e8f0;
    color: var(--primary-dark);
    transform: translateX(-2px);
}

/* Pagination Styles */
.pagination-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 1rem;
}

.pagination {
    display: flex;
    gap: 0.25rem;
}

.page-link {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    text-decoration: none;
    color: var(--text-main);
    font-size: 0.85rem;
    background: white;
    transition: all 0.2s;
}

.page-link:hover:not(.active) {
    background: var(--bg-main);
    border-color: var(--primary);
}

.page-link.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.page-link.disabled {
    opacity: 0.5;
    pointer-events: none;
    background: #f1f5f9;
}

.pagination-info {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.rows-per-page {
    padding: 0.3rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    font-size: 0.85rem;
}

/* Utils Responsivos */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

@media (max-width: 768px) {
    /* 1. Prevenir scroll horizontal global en la página */
    html, body {
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    /* 2. Ajuste responsivo de contenedores principales */
    .container, main, .main-content {
        width: 100% !important;
        max-width: 100% !important;
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
        box-sizing: border-box !important;
    }

    /* 3. Escalar títulos y encabezados para evitar desborde de texto */
    h1, .h1, h2, .h2, h3, .h3 {
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
    }
    h1, .h1 { font-size: 1.35rem !important; }
    h2, .h2 { font-size: 1.15rem !important; }
    h3, .h3 { font-size: 1.05rem !important; }

    /* 4. Envolver automáticamente las barras de navegación, botones y cabeceras con flexbox */
    div[style*="display: flex"], 
    div[style*="display:flex"],
    header[style*="display: flex"],
    header[style*="display:flex"],
    section[style*="display: flex"],
    section[style*="display:flex"],
    nav[style*="display: flex"],
    nav[style*="display:flex"] {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }

    header {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }

    /* Protección de logotipos en dispositivos móviles contra deformación / aplastamiento */
    img, .logo img, .hero-logo img, .institution-logo, img[src*="logo"], img[alt*="Logo"], img[alt*="Silabnet"] {
        flex-shrink: 0 !important;
        object-fit: contain !important;
        height: auto !important;
        max-height: 60px !important;
        width: auto !important;
        max-width: 100% !important;
    }

    /* 5. Asegurar que las tarjetas y botones no excedan ni deformen el ancho de pantalla */
    .card, .action-card, .work-menu-item {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Evitar que los botones de cabecera (ej: Nómina de Estudiantes) se aplasten verticalmente */
    header .btn, header a.btn, div[style*="display: flex"] > .btn, div[style*="display:flex"] > .btn {
        flex: 1 1 auto !important;
        min-width: 120px !important;
        max-width: 100% !important;
        white-space: normal !important;
        word-break: break-word !important;
        text-align: center !important;
        justify-content: center !important;
        padding: 0.6rem 0.5rem !important;
        font-size: 0.85rem !important;
    }

    /* Excluir botones compactos de tabla y acciones para que no se deformen en móvil */
    td .btn, td .btn-sm, td .btn-icon, td a.btn, .btn-icon, .btn-sm {
        min-width: auto !important;
        flex: 0 0 auto !important;
        padding: 0.35rem 0.6rem !important;
    }

    .btn, button, input[type="submit"], input[type="button"], a.btn {
        max-width: 100% !important;
        white-space: normal !important;
        word-break: break-word !important;
    }

    /* 6. Garantizar desplazamiento horizontal fluido dentro de las tarjetas de tablas (Docentes, Estudiantes, Colecturía, etc.) */
    .table-responsive, .table-card, div[class*="table"], div[style*="overflow-x: auto"], div[style*="overflow-x:auto"] {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        box-sizing: border-box !important;
    }

    /* Garantizar ancho mínimo a las tablas para que las columnas no se corten y permitan scroll limpio */
    .table-responsive table, .table-card table, div[class*="table"] table {
        min-width: 600px !important;
        width: 100% !important;
    }

    .controls {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    .grid {
        grid-template-columns: 1fr !important;
    }

    /* 7. Modales adaptados para móviles (especialmente posición vertical / portrait) */
    div[style*="position:fixed"], div[style*="position: fixed"], .ficha-modal-overlay {
        padding: 0.75rem !important;
        align-items: center !important;
        justify-content: center !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    div[style*="position:fixed"] > .card, 
    div[style*="position: fixed"] > .card,
    .ficha-modal {
        width: 100% !important;
        max-width: min(550px, 96vw) !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 1.25rem 1rem !important;
        margin: auto !important;
    }
}

/* Optimización para orientación vertical en móviles estrechos (<= 640px) */
@media (max-width: 640px) {
    div[style*="position:fixed"] form div[style*="grid-template-columns"],
    div[style*="position: fixed"] form div[style*="grid-template-columns"],
    .ficha-modal form div[style*="grid-template-columns"],
    .ficha-grid,
    .ficha-grid.cols3 {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }
    .ficha-field[style*="grid-column"],
    div[style*="grid-column:span"],
    div[style*="grid-column: span"] {
        grid-column: span 1 !important;
    }
    .ficha-header {
        flex-direction: column !important;
        text-align: center !important;
        padding: 1.25rem 1rem !important;
        gap: 1rem !important;
    }
    .ficha-header > div:last-child {
        width: 100% !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 0.5rem !important;
    }
    .ficha-section {
        padding: 1rem 1rem !important;
    }
}

/* 
 * Estilos para Modo Fuera de Línea (Offline)
 * Sombrea y deshabilita menús no disponibles en offline, manteniendo los habilitados.
 */
body.offline-mode .action-card,
body.offline-mode .work-menu-item {
    opacity: 0.45;
    filter: grayscale(80%);
    pointer-events: none;
    cursor: not-allowed;
    transition: all 0.3s ease;
}

body.offline-mode .offline-enabled {
    opacity: 1 !important;
    filter: none !important;
    pointer-events: auto !important;
    cursor: pointer !important;
}
