/*
   RESPONSIVE GLOBAL - Sistema de Gestión Educativa
   Reglas de adaptación para escritorio, portátil, tablet y móvil.
   Se carga después de site.css para corregir desbordamientos sin alterar
   los estilos particulares de cada módulo.
*/
:root {
    --mobile-gutter: clamp(12px, 3.5vw, 24px);
}

html, body {
    width: 100%;
    max-width: 100%;
    min-width: 320px;
    overflow-x: hidden;
}

body, .app-shell, .main-area, .page-content, main,
.module-table-card, .form-section-card, .card,
.dashboard-overview, .dashboard-analytics, .report-results-card {
    min-width: 0;
}

img, svg, video, canvas, iframe {
    max-width: 100%;
}

img, video {
    height: auto;
}

.page-content > *, .page-content .row > *,
.module-header > *, .module-table-toolbar > *,
.report-header > *, .report-results-heading > * {
    min-width: 0;
}

/* Evita que formularios y botones fuercen el ancho de la pantalla. */
input, select, textarea, .form-control, .form-select {
    max-width: 100%;
}

.btn, button {
    max-width: 100%;
}

.module-header-actions, .welcome-actions, .report-result-actions,
.form-actions, .filter-actions, .enrollment-filter-actions {
    flex-wrap: wrap;
}

/* Todas las tablas pueden desplazarse horizontalmente en pantallas estrechas. */
.table-responsive, .cortes-tabla-wrap, .report-table-wrap {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.gradebook-table-wrap {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.table-responsive > .table,
.gradebook-table-wrap > .table,
.report-table-wrap > .table {
    margin-bottom: 0;
}

.module-table {
    min-width: 680px;
}

/* Las matrices de calificaciones necesitan conservar su estructura. */
.gradebook-table {
    width: max-content;
    min-width: 100%;
}

/* Navegación y encabezado en tablets y móviles. */
@media (max-width: 1100px) {
    .page-content {
        padding-left: 20px;
        padding-right: 20px;
    }

    .dashboard-lower, .dashboard-analytics {
        grid-template-columns: minmax(0, 1fr);
    }

    .overview-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .topbar {
        gap: 10px;
        padding-left: 18px;
        padding-right: 18px;
    }
}

@media (max-width: 900px) {
    .sidebar {
        width: min(320px, 88vw);
        max-width: 88vw;
        padding-top: max(18px, env(safe-area-inset-top));
        padding-bottom: max(14px, env(safe-area-inset-bottom));
        transform: translateX(-105%);
        transition: transform .22s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop.visible {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1020;
        background: rgba(8, 18, 33, .48);
        -webkit-backdrop-filter: blur(2px);
        backdrop-filter: blur(2px);
    }

    .main-area {
        width: 100%;
        margin-left: 0;
    }

    .sidebar-mobile-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 42px;
        width: 42px;
        height: 42px;
        border-radius: 11px;
        background: #f1f5fb;
        color: #243650;
    }

    .topbar {
        min-height: 68px;
        height: auto;
        padding: 10px 18px;
    }

    .topbar-heading {
        flex: 1 1 auto;
        min-width: 0;
    }

    .topbar-heading strong {
        overflow-wrap: anywhere;
    }

    .page-content {
        padding: 22px 18px 40px;
    }

    .page-footer {
        flex-wrap: wrap;
        gap: 6px 14px;
        padding: 14px 18px;
    }

    .dashboard-lower, .dashboard-analytics {
        grid-template-columns: minmax(0, 1fr);
    }

    .overview-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .module-summary-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .enrollment-filter-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .module-table-toolbar {
        flex-wrap: wrap;
    }

    .module-search {
        width: 100%;
        max-width: 100%;
    }
}

@media (max-width: 700px) {
    .page-content {
        padding: 18px var(--mobile-gutter) 32px;
    }

    .topbar {
        min-height: 62px;
        padding: 8px var(--mobile-gutter);
    }

    .topbar-kicker, .system-status, .topbar-divider {
        display: none !important;
    }

    .topbar-right {
        gap: 8px;
        margin-left: auto;
        min-width: 0;
    }

    .topbar-user {
        display: block;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .dashboard-heading, .module-header, .report-header,
    .overview-heading, .analytics-heading, .report-results-heading {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
    }

    .dashboard-heading h1, .module-header h1, .report-header h1 {
        font-size: clamp(22px, 6vw, 28px);
        overflow-wrap: anywhere;
    }

    .dashboard-date, .report-header-icon {
        align-self: flex-start;
    }

    .module-header-actions, .report-result-actions,
    .welcome-actions, .form-actions {
        width: 100%;
    }

    .module-header-actions .btn, .report-result-actions .btn,
    .welcome-actions a {
        flex: 1 1 auto;
        justify-content: center;
    }

    .stat-card {
        min-height: 104px;
        height: auto;
        padding: 15px;
    }

    .stat-card strong, .overview-value {
        overflow-wrap: anywhere;
    }

    .welcome-card, .module-roadmap-card {
        padding: 20px;
    }

    .dashboard-overview, .analytics-card,
    .report-filter-card, .report-results-card {
        padding: 16px;
    }

    .report-results-card {
        padding: 0;
    }

    .module-table-toolbar {
        align-items: stretch;
        padding: 16px;
    }

    .module-table-footer {
        flex-direction: column;
    }

    .module-summary-row {
        grid-template-columns: minmax(0, 1fr);
    }

    .student-filter-grid, .enrollment-filter-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filter-actions, .enrollment-filter-actions {
        grid-column: 1 / -1;
        display: flex;
    }

    .form-section-card {
        padding: 16px;
    }

    .form-section-heading {
        align-items: flex-start;
    }

    .form-actions {
        position: static;
        justify-content: stretch;
        padding: 10px;
        border-radius: 12px;
    }

    .form-actions .btn {
        flex: 1 1 0;
        min-width: 0;
        padding: 10px 8px;
    }

    .grade-row {
        grid-template-columns: minmax(65px, 90px) minmax(40px, 1fr) 32px;
        gap: 8px;
    }

    .report-table {
        min-width: 620px;
    }

    .pagination {
        flex-wrap: wrap;
    }
}

@media (max-width: 480px) {
    .page-content {
        padding-left: 12px;
        padding-right: 12px;
    }

    .topbar-heading strong {
        font-size: 12px;
    }

    .topbar-user {
        max-width: 86px;
        font-size: 10px;
    }

    .overview-grid, .quick-access-grid,
    .student-filter-grid, .enrollment-filter-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .student-search-field, .student-grade-field,
    .enrollment-search-field, .enrollment-filter-grid > .filter-field,
    .enrollment-pagesize-field, .filter-actions,
    .enrollment-filter-actions {
        grid-column: 1 / -1;
    }

    .filter-actions, .enrollment-filter-actions {
        flex-direction: column;
    }

    .filter-actions .btn, .enrollment-filter-actions .btn {
        width: 100%;
    }

    .module-header-actions {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
    }

    .module-header-actions .btn {
        width: 100%;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }

    .login-panel {
        padding: 22px 16px;
    }

    .login-card h2 {
        font-size: 26px;
    }

    .report-results-heading {
        padding: 16px;
    }

    .report-result-actions {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
    }

    .report-result-actions .btn {
        width: 100%;
    }
}

@media (max-width: 360px) {
    .sidebar {
        width: 90vw;
        max-width: 90vw;
    }

    .brand strong {
        font-size: 12px;
    }

    .brand small {
        font-size: 8px;
    }

    .sidebar-footer {
        gap: 7px;
    }

    .user-meta strong {
        font-size: 10px;
    }
}

@media (orientation: landscape) and (max-height: 500px) and (max-width: 900px) {
    .sidebar {
        overflow-y: auto;
    }

    .sidebar-footer {
        margin-top: 18px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
    }
}
