/**
 * Mobile Optimizations para iPhone y dispositivos móviles
 * Añadir este CSS al layout principal
 */

/* ==============================================
   MEJORAS GENERALES PARA MÓVIL
   ============================================== */

/* Asegurar que todo el texto sea legible en móvil */
body {
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}


/* Botones táctiles más grandes (mínimo 44x44px según Apple HIG) */
.btn {
    min-height: 44px;
    padding: 0.5rem 1rem;
}

.btn-sm {
    min-height: 38px;
    padding: 0.4rem 0.8rem;
}

/* Pantallas táctiles: objetivo táctil de 44px; en tablas de admin se queda compacto (36px) */
@media (pointer: coarse) {
    .btn-sm {
        min-height: 44px;
    }

    .table .btn-sm,
    .table-responsive .btn-sm {
        min-height: 36px;
    }
}


.btn-lg {
    min-height: 50px;
    padding: 0.75rem 1.5rem;
}

/* Enlaces táctiles más grandes (solo en móvil, nav links) */
@media (max-width: 991.98px) {
    nav a:not(.btn):not(.navbar-brand),
    .offcanvas a:not(.btn) {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
}

/* Inputs y formularios más grandes para toque */
.form-control,
.form-select {
    min-height: 44px;
    font-size: 16px; /* Evita zoom automático en iPhone */
}

/* ==============================================
   MOBILE-SPECIFIC RESPONSIVE FIXES
   ============================================== */

@media (max-width: 991.98px) {
    /* Stats cards en móvil - stack verticalmente */
    .stat-card {
        margin-bottom: 1rem;
    }

    .stat-value {
        font-size: 2rem !important;
    }

    /* Charts más pequeños en móvil */
    .chart-container {
        height: 250px !important;
    }

    /* Tablas responsivas - scroll horizontal */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }

    /* Navbar user info oculto en móvil */
    .navbar .text-white-50 {
        display: none !important;
    }

    /* Week info banner responsive */
    .week-info {
        text-align: center;
    }

    .week-info .row > div {
        margin-bottom: 0.5rem;
    }

    /* Modal full-width en móvil */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    /* Checkout modal específico */
    #checkoutModal .modal-dialog {
        margin: 1rem 0.5rem;
    }

    #checkout-course-image {
        width: 50px !important;
        height: 50px !important;
    }

    .stat-label {
        font-size: 0.75rem;
    }
}

@media (max-width: 575.98px) {
    /* Extra small devices */
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .stat-value {
        font-size: 1.75rem !important;
    }

    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.25rem;
    }

    /* Botones full-width en muy pequeño */
    .btn-block-mobile {
        display: block;
        width: 100%;
    }

    /* Cards con menos padding */
    .card-body {
        padding: 1rem;
    }

    /* Navbar brand más pequeño */
    .navbar-brand {
        font-size: 1rem;
    }
}

/* ==============================================
   MODAL FIXES FOR SAFARI MOBILE
   ============================================== */

/* ==============================================
   CHECKOUT MODAL OPTIMIZATIONS
   ============================================== */

/* Mejorar legibilidad del modal de checkout */
#checkoutModal .modal-title {
    font-size: 1.1rem;
}

#checkoutModal .modal-body {
    padding: 1rem;
}

#checkoutModal .modal-footer {
    padding: 1rem;
    flex-direction: column;
    gap: 0.5rem;
}

@media (max-width: 575.98px) {
    #checkoutModal .modal-footer .btn {
        width: 100%;
    }

    #checkout-price-mxn {
        font-size: 1.25rem !important;
    }
}

/* ==============================================
   STRIPE PAYMENT ELEMENT MOBILE
   ============================================== */

#payment-element {
    min-height: 200px;
}

/* Asegurar que Stripe Elements sean táctiles */
#payment-element iframe {
    min-height: 200px;
}

/* ==============================================
   TABLAS RESPONSIVE
   ============================================== */

@media (max-width: 991.98px) {
    /* Las tablas se contienen dentro de .table-responsive */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    .table-responsive table th {
        white-space: nowrap;
    }

    /* Reducir padding de celdas */
    .table td,
    .table th {
        padding: 0.5rem 0.25rem;
        font-size: 0.875rem;
    }
}

/* ==============================================
   NAVBAR MOBILE IMPROVEMENTS
   ============================================== */

/* Asegurar que el toggler sea visible y táctil */
.navbar-toggler {
    min-width: 44px;
    min-height: 44px;
    padding: 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.navbar-toggler:focus {
    box-shadow: 0 0 0 0.2rem rgba(255, 255, 255, 0.25);
}

/* Menú móvil con mejor espaciado */
@media (max-width: 991.98px) {
    .navbar-collapse {
        margin-top: 1rem;
        padding: 1rem 0;
        background: rgba(0, 0, 0, 0.1);
        border-radius: 0.5rem;
    }

    .navbar-nav .nav-link {
        padding: 0.75rem 1rem;
        border-radius: 0.25rem;
    }

    .navbar-nav .nav-link:hover {
        background: rgba(255, 255, 255, 0.1);
    }

    /* Form de logout full-width en móvil */
    .navbar-collapse form {
        margin-top: 1rem;
        padding-top: 1rem;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .navbar-collapse form .btn {
        width: 100%;
    }
}

/* ==============================================
   COURSE CARDS MOBILE
   ============================================== */

@media (max-width: 767.98px) {
    /* Course cards stack en móvil */
    .course-card {
        margin-bottom: 1.5rem;
    }

    .course-card img {
        max-height: 200px;
        object-fit: cover;
    }

    .course-card .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}

/* ==============================================
   LESSON VIEWER MOBILE
   ============================================== */

@media (max-width: 991.98px) {
    /* Video responsive */
    .lesson-video {
        width: 100%;
        height: auto;
        aspect-ratio: 16/9;
    }

    /* Sidebar de navegación visible en móvil. En ≤767px lessons/show.blade.php lo
       muestra arriba como índice plegable (flex + order). */
    .lesson-sidebar {
        display: block;
    }

    /* Botones de navegación full-width */
    .lesson-navigation {
        flex-direction: column;
        gap: 0.5rem;
    }

    .lesson-navigation .btn {
        width: 100%;
    }
}

/* ==============================================
   SAFE AREA INSETS (iPhone X+)
   ============================================== */

/* Soporte para notch y bottom bar de iPhone */
@supports (padding: max(0px)) {
    /* Zonas seguras (iPhone en horizontal): se aplican al contenido, no al body,
       para que cabecera y pie lleguen hasta el borde */
    .container,
    .container-fluid {
        padding-left: max(calc(var(--bs-gutter-x, 1.5rem) * 0.5), env(safe-area-inset-left));
        padding-right: max(calc(var(--bs-gutter-x, 1.5rem) * 0.5), env(safe-area-inset-right));
    }

    .navbar {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .modal-dialog {
        margin-left: max(0.5rem, env(safe-area-inset-left));
        margin-right: max(0.5rem, env(safe-area-inset-right));
    }
}

/* ==============================================
   SCROLL BEHAVIOR
   ============================================== */

/* Smooth scrolling en iOS */
html {
    -webkit-overflow-scrolling: touch;
}

/* Prevenir zoom en inputs */
@media (max-width: 575.98px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* ==============================================
   LOADING STATES
   ============================================== */

/* Spinners más visibles en móvil */
.spinner-border {
    width: 3rem;
    height: 3rem;
    border-width: 0.3rem;
}

.spinner-border-sm {
    width: 1.5rem;
    height: 1.5rem;
    border-width: 0.2rem;
}

/* ==============================================
   TOAST/ALERTS MOBILE
   ============================================== */

@media (max-width: 575.98px) {
    .alert {
        font-size: 0.875rem;
        padding: 0.75rem;
    }

    /* SweetAlert2 mobile */
    .swal2-popup {
        font-size: 0.875rem;
        padding: 1.5rem;
    }

    .swal2-title {
        font-size: 1.25rem;
    }
}

/* ==============================================
   FOOTER (compacto en móvil, siempre al final del documento)
   ============================================== */

.footer-logo { height: 50px; }

@media (max-width: 767.98px) {
    .footer-logo { height: 32px; }
    footer .footer-legal { font-size: 0.75rem; line-height: 1.5; }
}

/* Insignias: ver ui.css */

/* ==============================================
   FEEDBACK INSTANTANEO EN BOTONES
   Responder al toque/click ANTES de que la accion se complete,
   nunca solo al soltar (principio "Response" de diseño de Apple).
   ============================================== */

.btn {
    transition: transform 100ms ease-out, box-shadow 100ms ease-out, background-color 0.3s ease, border-color 0.3s ease;
}

.btn:active {
    transform: scale(0.97);
}

/* ==============================================
   REDUCED MOTION
   Quitar movimiento no esencial a quien lo pidio en su SO/navegador,
   sin perder los cambios de color/estado que ayudan a entender la UI.
   ============================================== */

@media (prefers-reduced-motion: reduce) {
    .btn,
    .btn:active,
    .card,
    .card:hover,
    .nav-link {
        transition: none !important;
        transform: none !important;
    }
}

/* ==============================================
   BOTON FLOTANTE DE WHATSAPP
   ============================================== */

.wa-fab {
    position: fixed;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    width: 48px;
    height: 48px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1040;
}

@media (min-width: 768px) {
    .wa-fab {
        right: 24px;
        bottom: 24px;
        width: 56px;
        height: 56px;
    }
}
