/**
 * Optimizaciones específicas para móviles y tablets
 * Mejoras de usabilidad táctil y rendimiento
 */

/* === OPTIMIZACIONES TÁCTILES === */

/* Tamaños mínimos táctiles (44px según Apple HIG) */
@media (hover: none) and (pointer: coarse) {
    .fmc-btn,
    .nav-link,
    .dropdown-toggle,
    .form-check-input,
    .btn-close,
    .pagination .page-link {
        min-height: 44px;
        min-width: 44px;
    }
    
    .fmc-form-control,
    .fmc-form-select {
        min-height: 44px;
        font-size: 16px; /* Evita zoom en iOS */
    }
    
    /* Espaciado adicional para elementos táctiles */
    .fmc-btn-group .fmc-btn {
        margin: 2px;
    }
    
    .nav-link {
        padding: 12px 16px;
    }
}

/* === MÓVILES PEQUEÑOS (320px - 479px) === */
@media (max-width: 479.98px) {
    /* Header compacto */
    .fmc-header {
        padding: var(--fmc-spacing-sm) 0;
    }
    
    .fmc-title h1 {
        font-size: var(--fmc-font-size-lg);
        line-height: 1.2;
    }
    
    .fmc-title .subtitle {
        font-size: var(--fmc-font-size-xs);
        display: none; /* Ocultar en pantallas muy pequeñas */
    }
    
    .user-welcome {
        font-size: var(--fmc-font-size-xs);
    }
    
    .user-name {
        font-size: var(--fmc-font-size-sm) !important;
    }
    
    /* Navegación compacta */
    .fmc-navbar {
        padding: var(--fmc-spacing-xs) 0;
    }
    
    .nav-link span {
        font-size: var(--fmc-font-size-sm);
    }
    
    /* Contenido principal */
    .fmc-main {
        padding: var(--fmc-spacing-sm) 0;
    }
    
    .fmc-main .container-fluid {
        padding: 0 var(--fmc-spacing-sm);
    }
    
    /* Tarjetas compactas */
    .fmc-card-header,
    .fmc-card-body,
    .fmc-card-footer {
        padding: var(--fmc-spacing-sm);
    }
    
    .fmc-card-title {
        font-size: var(--fmc-font-size-lg);
        margin-bottom: var(--fmc-spacing-sm);
    }
    
    /* Formularios compactos */
    .fmc-form-group {
        margin-bottom: var(--fmc-spacing-sm);
    }
    
    .fmc-form-label {
        font-size: var(--fmc-font-size-sm);
        margin-bottom: var(--fmc-spacing-xs);
    }
    
    /* Botones apilados */
    .fmc-btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .fmc-btn-group .fmc-btn {
        width: 100%;
        margin-bottom: var(--fmc-spacing-xs);
        border-radius: var(--fmc-radius) !important;
    }
    
    /* Tablas con scroll horizontal */
    .fmc-table-responsive {
        font-size: var(--fmc-font-size-xs);
        border: 1px solid var(--fmc-border-color);
        border-radius: var(--fmc-radius);
    }
    
    .fmc-table th,
    .fmc-table td {
        padding: var(--fmc-spacing-xs);
        white-space: nowrap;
    }
    
    /* Modales de pantalla completa */
    .fmc-modal-dialog {
        margin: 0;
        width: 100%;
        height: 100%;
        max-width: none;
    }
    
    .fmc-modal-content {
        height: 100%;
        border-radius: 0;
        border: none;
    }
}

/* === MÓVILES MEDIANOS (480px - 575px) === */
@media (min-width: 480px) and (max-width: 575.98px) {
    .fmc-title .subtitle {
        display: block;
        font-size: var(--fmc-font-size-sm);
    }
    
    /* Grid de 2 columnas para botones */
    .mobile-btn-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--fmc-spacing-sm);
    }
    
    .mobile-btn-grid .fmc-btn {
        width: 100%;
    }
    
    /* Formularios en 2 columnas para campos cortos */
    .mobile-form-row {
        display: flex;
        gap: var(--fmc-spacing-sm);
    }
    
    .mobile-form-row .fmc-form-group {
        flex: 1;
    }
}

/* === TABLETS VERTICALES (576px - 767px) === */
@media (min-width: 576px) and (max-width: 767.98px) {
    /* Header con mejor distribución */
    .fmc-header .row > div {
        text-align: center;
        margin-bottom: var(--fmc-spacing-md);
    }
    
    .fmc-header .row > div:last-child {
        margin-bottom: 0;
    }
    
    /* Navegación horizontal compacta */
    .navbar-nav {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .nav-link {
        padding: var(--fmc-spacing-sm) var(--fmc-spacing-md);
        margin: 0 var(--fmc-spacing-xs);
        border-radius: var(--fmc-radius);
    }
    
    /* Grid de tarjetas 2x2 */
    .tablet-card-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--fmc-spacing-md);
    }
    
    /* Formularios optimizados */
    .tablet-form-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--fmc-spacing-md);
    }
    
    .tablet-form-grid .fmc-form-group.full-width {
        grid-column: 1 / -1;
    }
    
    /* Tablas con mejor espaciado */
    .fmc-table th,
    .fmc-table td {
        padding: var(--fmc-spacing-sm) var(--fmc-spacing-md);
    }
    
    /* Modales centrados */
    .fmc-modal-dialog {
        max-width: 90%;
        margin: var(--fmc-spacing-lg) auto;
    }
}

/* === TABLETS HORIZONTALES (768px - 991px) === */
@media (min-width: 768px) and (max-width: 991.98px) {
    /* Layout de sidebar colapsable */
    .tablet-layout {
        display: grid;
        grid-template-columns: auto 1fr;
        gap: var(--fmc-spacing-lg);
    }
    
    .tablet-sidebar {
        width: 200px;
        background: var(--fmc-bg-primary);
        border-radius: var(--fmc-radius-md);
        padding: var(--fmc-spacing-md);
        height: fit-content;
        position: sticky;
        top: 100px;
    }
    
    .tablet-sidebar.collapsed {
        width: 60px;
    }
    
    .tablet-sidebar.collapsed .nav-text {
        display: none;
    }
    
    /* Grid de tarjetas 3 columnas */
    .tablet-card-grid-3 {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: var(--fmc-spacing-md);
    }
    
    /* Formularios en 3 columnas */
    .tablet-form-grid-3 {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: var(--fmc-spacing-md);
    }
    
    .tablet-form-grid-3 .fmc-form-group.span-2 {
        grid-column: span 2;
    }
    
    .tablet-form-grid-3 .fmc-form-group.span-3 {
        grid-column: span 3;
    }
}

/* === OPTIMIZACIONES DE RENDIMIENTO === */

/* Lazy loading para imágenes */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* Reducir animaciones en dispositivos de bajo rendimiento */
@media (prefers-reduced-motion: reduce) {
    .fmc-card,
    .fmc-btn,
    .nav-link,
    .dropdown-menu {
        transition: none !important;
        animation: none !important;
    }
}

/* Optimizaciones para conexiones lentas */
@media (prefers-reduced-data: reduce) {
    /* Ocultar elementos no esenciales */
    .decorative-bg,
    .hero-image,
    .background-pattern {
        display: none;
    }
    
    /* Simplificar sombras */
    .fmc-card,
    .fmc-navbar,
    .fmc-dropdown {
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
    }
}

/* === MEJORAS DE ACCESIBILIDAD MÓVIL === */

/* Aumentar contraste en pantallas pequeñas */
@media (max-width: 767.98px) {
    .fmc-text-muted {
        color: var(--fmc-text-secondary) !important;
    }
    
    .fmc-border {
        border-color: var(--fmc-text-secondary) !important;
    }
}

/* Focus mejorado para navegación táctil */
@media (hover: none) {
    .fmc-btn:focus,
    .nav-link:focus,
    .fmc-form-control:focus {
        outline: 3px solid var(--fmc-primary);
        outline-offset: 2px;
    }
}

/* === ORIENTACIÓN === */

/* Landscape en móviles */
@media (max-width: 767.98px) and (orientation: landscape) {
    .fmc-header {
        padding: var(--fmc-spacing-xs) 0;
    }
    
    .fmc-title h1 {
        font-size: var(--fmc-font-size-lg);
    }
    
    .fmc-title .subtitle {
        display: none;
    }
    
    .fmc-main {
        padding: var(--fmc-spacing-sm) 0;
    }
    
    /* Navegación horizontal compacta */
    .navbar-nav {
        flex-direction: row;
        justify-content: space-around;
    }
    
    .nav-link {
        padding: var(--fmc-spacing-xs) var(--fmc-spacing-sm);
        font-size: var(--fmc-font-size-sm);
    }
    
    .nav-link span {
        display: none;
    }
    
    .nav-link i {
        margin: 0;
    }
}

/* Portrait en tablets */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
    .tablet-portrait-stack {
        flex-direction: column;
    }
    
    .tablet-portrait-full {
        width: 100%;
    }
}

/* === UTILIDADES MÓVILES === */

/* Ocultar/mostrar por dispositivo */
.mobile-only {
    display: none;
}

.desktop-only {
    display: block;
}

@media (max-width: 767.98px) {
    .mobile-only {
        display: block;
    }
    
    .desktop-only {
        display: none;
    }
    
    .mobile-hidden {
        display: none !important;
    }
    
    .mobile-visible {
        display: block !important;
    }
}

/* Espaciado móvil */
@media (max-width: 575.98px) {
    .mobile-p-0 { padding: 0 !important; }
    .mobile-p-1 { padding: var(--fmc-spacing-xs) !important; }
    .mobile-p-2 { padding: var(--fmc-spacing-sm) !important; }
    .mobile-p-3 { padding: var(--fmc-spacing-md) !important; }
    
    .mobile-m-0 { margin: 0 !important; }
    .mobile-m-1 { margin: var(--fmc-spacing-xs) !important; }
    .mobile-m-2 { margin: var(--fmc-spacing-sm) !important; }
    .mobile-m-3 { margin: var(--fmc-spacing-md) !important; }
    
    .mobile-mb-0 { margin-bottom: 0 !important; }
    .mobile-mb-1 { margin-bottom: var(--fmc-spacing-xs) !important; }
    .mobile-mb-2 { margin-bottom: var(--fmc-spacing-sm) !important; }
    .mobile-mb-3 { margin-bottom: var(--fmc-spacing-md) !important; }
}

/* Texto móvil */
@media (max-width: 575.98px) {
    .mobile-text-center { text-align: center !important; }
    .mobile-text-left { text-align: left !important; }
    .mobile-text-right { text-align: right !important; }
    
    .mobile-text-sm { font-size: var(--fmc-font-size-sm) !important; }
    .mobile-text-xs { font-size: var(--fmc-font-size-xs) !important; }
}

/* Flex móvil */
@media (max-width: 767.98px) {
    .mobile-flex-column { flex-direction: column !important; }
    .mobile-flex-row { flex-direction: row !important; }
    .mobile-flex-wrap { flex-wrap: wrap !important; }
    .mobile-justify-center { justify-content: center !important; }
    .mobile-align-center { align-items: center !important; }
}

/* Ancho móvil */
@media (max-width: 575.98px) {
    .mobile-w-100 { width: 100% !important; }
    .mobile-w-50 { width: 50% !important; }
    .mobile-w-auto { width: auto !important; }
}

/* === MEJORAS DE PERFORMANCE === */

/* Optimización de scroll */
.mobile-scroll-container {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Optimización de tap */
.mobile-tap-highlight {
    -webkit-tap-highlight-color: rgba(30, 58, 138, 0.2);
}

.mobile-no-tap-highlight {
    -webkit-tap-highlight-color: transparent;
}

/* Optimización de selección de texto */
.mobile-no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* === COMPONENTES MÓVILES ESPECÍFICOS === */

/* Bottom sheet para móviles */
.mobile-bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--fmc-bg-primary);
    border-top-left-radius: var(--fmc-radius-lg);
    border-top-right-radius: var(--fmc-radius-lg);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 1050;
    max-height: 80vh;
    overflow-y: auto;
}

.mobile-bottom-sheet.show {
    transform: translateY(0);
}

.mobile-bottom-sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--fmc-text-muted);
    border-radius: 2px;
    margin: var(--fmc-spacing-sm) auto;
}

/* Floating Action Button */
.mobile-fab {
    position: fixed;
    bottom: var(--fmc-spacing-lg);
    right: var(--fmc-spacing-lg);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--fmc-primary);
    color: var(--fmc-text-light);
    border: none;
    box-shadow: 0 4px 12px rgba(30, 58, 138, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fmc-font-size-xl);
    z-index: 1000;
    transition: all 0.2s ease;
}

.mobile-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(30, 58, 138, 0.4);
}

/* Swipe indicators */
.mobile-swipe-indicator {
    position: relative;
}

.mobile-swipe-indicator::after {
    content: '← Desliza →';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: var(--fmc-spacing-xs) var(--fmc-spacing-sm);
    border-radius: var(--fmc-radius);
    font-size: var(--fmc-font-size-xs);
    pointer-events: none;
    opacity: 0;
    animation: swipe-hint 3s ease-in-out infinite;
}

@keyframes swipe-hint {
    0%, 90%, 100% { opacity: 0; }
    10%, 80% { opacity: 1; }
}

/* Pull to refresh */
.mobile-pull-refresh {
    position: relative;
    overflow: hidden;
}

.mobile-pull-refresh-indicator {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: top 0.2s ease;
}

.mobile-pull-refresh.pulling .mobile-pull-refresh-indicator {
    top: 10px;
}

/* === DARK MODE MÓVIL === */
@media (prefers-color-scheme: dark) and (max-width: 767.98px) {
    .fmc-mobile-dark {
        --fmc-bg-primary: #1a1a1a;
        --fmc-bg-secondary: #2d2d2d;
        --fmc-bg-tertiary: #404040;
        --fmc-text-primary: #ffffff;
        --fmc-text-secondary: #cccccc;
        --fmc-text-muted: #999999;
        --fmc-border-color: #404040;
    }
    
    .fmc-mobile-dark .fmc-card {
        background: var(--fmc-bg-secondary);
        border-color: var(--fmc-border-color);
    }
    
    .fmc-mobile-dark .fmc-navbar {
        background: var(--fmc-bg-primary);
        border-color: var(--fmc-border-color);
    }
}