/**
 * PWA MOBILE OPTIMIZATIONS
 * Campus Virtual CEC
 * Estilos optimizados para experiencia móvil
 */

/* ===================================
   VARIABLES Y CONFIGURACIÓN BASE
   =================================== */
:root {
    --pwa-primary: #667eea;
    --pwa-secondary: #764ba2;
    --pwa-success: #10b981;
    --pwa-danger: #ef4444;
    --pwa-warning: #f59e0b;
    --pwa-safe-area-top: env(safe-area-inset-top);
    --pwa-safe-area-bottom: env(safe-area-inset-bottom);
    --pwa-safe-area-left: env(safe-area-inset-left);
    --pwa-safe-area-right: env(safe-area-inset-right);
}

/* ===================================
   SAFE AREA (iPhone con notch)
   =================================== */
body {
    padding-top: var(--pwa-safe-area-top);
    padding-bottom: var(--pwa-safe-area-bottom);
    padding-left: var(--pwa-safe-area-left);
    padding-right: var(--pwa-safe-area-right);
}

/* Header con safe area */
header,
.navbar,
.app-header {
    padding-top: calc(12px + var(--pwa-safe-area-top));
}

/* Footer con safe area */
footer,
.app-footer {
    padding-bottom: calc(12px + var(--pwa-safe-area-bottom));
}

/* ===================================
   OPTIMIZACIONES PARA TÁCTIL
   =================================== */

/* Aumentar área táctil de botones */
@media (max-width: 768px) {
    button,
    .btn,
    a.btn,
    input[type="button"],
    input[type="submit"] {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 20px;
        font-size: 16px;
    }

    /* Inputs más grandes para móvil */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    input[type="date"],
    select,
    textarea {
        min-height: 44px;
        font-size: 16px; /* Prevenir zoom en iOS */
        padding: 12px;
    }

    /* Checkboxes y radios más grandes */
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 24px;
        min-height: 24px;
        cursor: pointer;
    }
}

/* ===================================
   NAVEGACIÓN MÓVIL
   =================================== */
@media (max-width: 768px) {
    /* Menú hamburguesa mejorado */
    .navbar-toggler {
        padding: 10px;
        border: none;
        background: transparent;
    }

    .navbar-toggler-icon {
        width: 28px;
        height: 3px;
        background: currentColor;
        display: block;
        position: relative;
        transition: all 0.3s ease;
    }

    .navbar-toggler-icon::before,
    .navbar-toggler-icon::after {
        content: '';
        width: 28px;
        height: 3px;
        background: currentColor;
        position: absolute;
        left: 0;
        transition: all 0.3s ease;
    }

    .navbar-toggler-icon::before {
        top: -8px;
    }

    .navbar-toggler-icon::after {
        bottom: -8px;
    }

    /* Menú móvil full-screen */
    .navbar-collapse {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: white;
        z-index: 9999;
        padding: 20px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .navbar-collapse.show {
        animation: slideInLeft 0.3s ease;
    }

    @keyframes slideInLeft {
        from {
            transform: translateX(-100%);
        }
        to {
            transform: translateX(0);
        }
    }
}

/* ===================================
   TABLAS RESPONSIVE
   =================================== */
@media (max-width: 768px) {
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
    }

    table {
        min-width: 600px;
        font-size: 14px;
    }

    /* Scroll horizontal con indicador */
    .table-responsive::after {
        content: '← Desliza para ver más →';
        display: block;
        text-align: center;
        padding: 10px;
        background: #f3f4f6;
        color: #6b7280;
        font-size: 12px;
        border-radius: 0 0 8px 8px;
    }
}

/* ===================================
   MODALES MÓVILES
   =================================== */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100%;
    }

    .modal-content {
        height: 100%;
        border-radius: 0;
        border: none;
    }

    .modal-body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 20px;
    }

    .modal-header,
    .modal-footer {
        position: sticky;
        background: white;
        z-index: 10;
    }

    .modal-header {
        top: 0;
        border-bottom: 2px solid #e5e7eb;
    }

    .modal-footer {
        bottom: 0;
        border-top: 2px solid #e5e7eb;
    }
}

/* ===================================
   CARDS OPTIMIZADOS
   =================================== */
@media (max-width: 768px) {
    .card {
        margin-bottom: 16px;
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .card-body {
        padding: 16px;
    }

    .card-title {
        font-size: 18px;
        margin-bottom: 12px;
    }
}

/* ===================================
   FORMULARIOS MEJORADOS
   =================================== */
@media (max-width: 768px) {
    .form-group {
        margin-bottom: 20px;
    }

    label {
        font-weight: 600;
        margin-bottom: 8px;
        display: block;
    }

    /* Prevenir zoom en iOS cuando se hace focus */
    input:focus,
    select:focus,
    textarea:focus {
        font-size: 16px;
    }

    /* Select mejorado para móvil */
    select {
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 12px center;
        padding-right: 40px;
    }
}

/* ===================================
   SCROLL PERSONALIZADO
   =================================== */
@media (max-width: 768px) {
    /* Scrollbar delgado para móviles */
    ::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }

    ::-webkit-scrollbar-track {
        background: transparent;
    }

    ::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.2);
        border-radius: 4px;
    }

    ::-webkit-scrollbar-thumb:hover {
        background: rgba(0, 0, 0, 0.3);
    }
}

/* ===================================
   PULL TO REFRESH (Efecto visual)
   =================================== */
@media (max-width: 768px) {
    .pull-to-refresh {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: var(--pwa-primary);
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        transform: translateY(-60px);
        transition: transform 0.3s ease;
        z-index: 9999;
    }

    .pull-to-refresh.active {
        transform: translateY(0);
    }
}

/* ===================================
   LOADING STATES
   =================================== */
@media (max-width: 768px) {
    .btn-loading {
        position: relative;
        pointer-events: none;
        opacity: 0.7;
    }

    .btn-loading::after {
        content: '';
        position: absolute;
        width: 16px;
        height: 16px;
        top: 50%;
        left: 50%;
        margin-left: -8px;
        margin-top: -8px;
        border: 2px solid white;
        border-radius: 50%;
        border-top-color: transparent;
        animation: spin 1s linear infinite;
    }

    @keyframes spin {
        to { transform: rotate(360deg); }
    }
}

/* ===================================
   NOTIFICACIONES TOAST
   =================================== */
@media (max-width: 768px) {
    .toast-container {
        position: fixed;
        top: 20px;
        right: 20px;
        left: 20px;
        z-index: 999999;
    }

    .toast {
        background: white;
        padding: 16px;
        border-radius: 12px;
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
        margin-bottom: 12px;
        animation: slideInRight 0.3s ease;
    }

    @keyframes slideInRight {
        from {
            transform: translateX(400px);
            opacity: 0;
        }
        to {
            transform: translateX(0);
            opacity: 1;
        }
    }
}

/* ===================================
   FAB (Floating Action Button)
   =================================== */
@media (max-width: 768px) {
    .fab {
        position: fixed;
        bottom: calc(20px + var(--pwa-safe-area-bottom));
        right: 20px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: var(--pwa-primary);
        color: white;
        border: none;
        box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 24px;
        cursor: pointer;
        transition: all 0.3s ease;
        z-index: 9998;
    }

    .fab:hover,
    .fab:active {
        transform: scale(1.1);
        box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6);
    }
}

/* ===================================
   SPLASH SCREEN (mientras carga)
   =================================== */
.pwa-splash {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 999999;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.pwa-splash.hide {
    opacity: 0;
    pointer-events: none;
}

.pwa-splash-logo {
    width: 120px;
    height: 120px;
    margin-bottom: 20px;
    animation: pulse 2s infinite;
}

.pwa-splash-text {
    color: white;
    font-size: 24px;
    font-weight: 600;
    text-align: center;
}

/* ===================================
   OFFLINE INDICATOR
   =================================== */
.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #ef4444;
    color: white;
    padding: 12px;
    text-align: center;
    font-weight: 600;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    z-index: 999998;
}

.offline-indicator.show {
    transform: translateY(0);
}

/* ===================================
   UTILIDADES MÓVILES
   =================================== */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }

    .show-mobile {
        display: block !important;
    }

    /* Espaciado móvil */
    .mb-mobile {
        margin-bottom: 16px !important;
    }

    .mt-mobile {
        margin-top: 16px !important;
    }

    .p-mobile {
        padding: 16px !important;
    }

    /* Texto móvil */
    .text-mobile-center {
        text-align: center !important;
    }

    .text-mobile-small {
        font-size: 14px !important;
    }
}

/* ===================================
   ORIENTACIÓN LANDSCAPE
   =================================== */
@media (max-width: 768px) and (orientation: landscape) {
    body {
        font-size: 14px;
    }

    h1 { font-size: 24px; }
    h2 { font-size: 20px; }
    h3 { font-size: 18px; }

    .modal-dialog {
        max-width: 90%;
        height: auto;
        margin: 20px auto;
    }
}

/* ===================================
   ACCESIBILIDAD
   =================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===================================
   DARK MODE (si el sistema lo usa)
   =================================== */
@media (prefers-color-scheme: dark) {
    body {
        background: #1a1a1a;
        color: #ffffff;
    }

    .card {
        background: #2d2d2d;
        border-color: #3d3d3d;
    }

    .modal-content {
        background: #2d2d2d;
        color: #ffffff;
    }

    input,
    select,
    textarea {
        background: #3d3d3d;
        color: #ffffff;
        border-color: #4d4d4d;
    }
}

/* ===================================
   PERFORMANCE
   =================================== */
@media (max-width: 768px) {
    /* GPU Acceleration para animaciones suaves */
    .modal,
    .toast,
    .navbar-collapse,
    .fab,
    .btn {
        will-change: transform;
        transform: translateZ(0);
        backface-visibility: hidden;
    }
}

console.log('✅ [PWA] Estilos móviles cargados');
