/* =============================================================================
   DISEÑO ADAPTABLE DE MOODLE (celular, tableta, laptop y pantallas grandes)
   Lo carga marca.php en todos los Moodles (el de CourseStudio y los propios). Corrige lo que en pantallas chicas quedaba
   apretado: los márgenes de página, sección y actividad que se sumaban (una lección incrustada quedaba de 136 px en un
   celular), las tablas y rúbricas que se salían de la pantalla y la barra superior en celulares chicos. El alto de las
   lecciones lo ajusta responsive.js (sin barras de desplazamiento dentro de otras).
   ============================================================================= */

/* Lecciones de CourseStudio: siempre al ancho disponible; su alto lo pone responsive.js. */
html body .coursestudio-page-container {
    max-width: 100% !important;
}

html body iframe.coursestudio-fullscreen-iframe,
html body iframe[src*="/interactive/curso_"] {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    border: 0;
}

/* Imágenes, videos e incrustados nunca más anchos que su espacio. */
html body #region-main img,
html body #region-main video,
html body #region-main iframe:not(.coursestudio-fullscreen-iframe) {
    max-width: 100%;
}

/* Los dibujos de «estado vacío» de Moodle («No hay cursos»…) tienen su alto fijo a propósito: no se agrandan. */
html body #region-main img:not([class*="empty-placeholder-image"]) {
    height: auto;
}

/* ----------------------------- Tabletas (< 992 px) ----------------------------- */
@media (max-width: 991.98px) {
    html body #page.drawers .main-inner {
        width: calc(100% - 1.5rem) !important;
        margin: 0.75rem auto !important;
        padding: 1.25rem 1rem !important;
    }

    html body .course-section,
    html body li.section.main,
    html body .format-topics .course-section,
    html body .format-weeks .course-section {
        padding: 1rem 0.9rem !important;
        margin-bottom: 1rem !important;
    }

    /* Cada actividad era una tarjeta dentro de otra (el SCSS del tema pone borde y 22 px a las dos): queda solo la de
       adentro, con márgenes más chicos. */
    html body .course-section li.activity,
    html body .course-section .activity:not(.activity-item) {
        padding: 0 !important;
        border: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
        margin-bottom: 0.6rem !important;
    }

    html body .course-section .activity-item {
        padding: 0.85rem 0.9rem !important;
    }

    /* Avisos de disponibilidad: dentro de su espacio. */
    html body .availability-excerpt,
    html body .availabilityinfo {
        max-width: 100%;
    }

    /* La descripción de la actividad (donde va la lección incrustada) usa todo el ancho, como Moodle en celulares. */
    html body .activity-item .activity-grid:not(.noname-grid) {
        grid-template-columns: min-content 1fr min-content min-content min-content;
        grid-template-rows: auto;
        grid-template-areas:
            "icon          name          actions"
            "icon          visibility    actions"
            "dates         dates         dates"
            "groupmode     groupmode     groupmode"
            "completion    completion    completion"
            "altcontent    altcontent    altcontent"
            "afterlink     afterlink     afterlink"
            "availability  availability  availability";
    }

    /* Tablas anchas: se desplazan de lado dentro de su espacio (la página no). */
    html body #region-main table.generaltable,
    html body #region-main table.table,
    html body #region-main .no-overflow > table {
        display: block;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Rúbricas: columnas legibles y desplazamiento de lado. */
    html body .gradingform_rubric {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    html body .gradingform_rubric .criterion .description {
        min-width: 170px;
    }

    html body .gradingform_rubric .criterion .levels .level {
        min-width: 140px;
    }
}

/* ----------------------------- Celulares (< 768 px) ----------------------------- */
@media (max-width: 767.98px) {
    html body #page.drawers .main-inner {
        width: calc(100% - 0.75rem) !important;
        margin: 0.4rem auto !important;
        padding: 0.85rem 0.6rem !important;
        border-radius: 10px !important;
    }

    html body .course-section,
    html body li.section.main,
    html body .format-topics .course-section,
    html body .format-weeks .course-section {
        padding: 0.75rem 0.5rem !important;
        border-radius: 12px !important;
    }

    html body .course-section .section-item,
    html body li.section.main .section-item {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    html body .course-section .activity-item {
        padding: 0.7rem 0.55rem !important;
    }

    /* Textos largos (avisos de disponibilidad, enlaces) nunca empujan la página de lado. */
    html body .availabilityinfo,
    html body .activity-altcontent,
    html body #region-main .box,
    html body #region-main .description {
        overflow-wrap: anywhere;
    }

    html body .activity-item .activity-altcontent {
        margin-top: 0.5rem !important;
    }

    /* Encabezado de la página y títulos: sin cortar palabras de más. */
    html body #page-header h1,
    html body .page-header-headings h1 {
        font-size: 1.35rem !important;
        line-height: 1.25 !important;
    }

    /* Botones de acción a lo ancho cuando no caben juntos. */
    html body #region-main .submissionlinks .btn,
    html body #region-main .singlebutton .btn {
        white-space: normal;
    }
}

/* ----------------------------- Celulares chicos (< 400 px) ----------------------------- */
@media (max-width: 399.98px) {
    /* Barra superior: sin separadores ni márgenes de más (antes se salía unos píxeles a 360 px). */
    html body .navbar .usernavigation .divider,
    html body #usernavigation .divider {
        display: none !important;
    }

    html body #usernavigation .popover-region,
    html body #usernavigation .usermenu-container {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    html body #usernavigation .nav-link,
    html body #usernavigation .popover-region-toggle {
        padding-left: 0.35rem !important;
        padding-right: 0.35rem !important;
    }
}

/* ----------------------------- Pantallas grandes (≥ 1600 px) ----------------------------- */
@media (min-width: 1600px) {
    html body #page.drawers .main-inner {
        max-width: 1480px !important;
    }
}
