/* ========================================
   MOBILE OPTIMIZATIONS
   Optimizaciones específicas para experiencia móvil
   ======================================== */

/* ===== VARIABLES MÓVILES ===== */
:root {
    --mobile-padding: 15px;
    --mobile-margin: 10px;
    --touch-target-min: 44px;
    --mobile-font-base: 14px;
}

/* ===== BREAKPOINTS ===== */
/* Tablet: 768px - 1024px */
/* Mobile Large: 480px - 767px */
/* Mobile Small: < 480px */

/* ===== TABLET (768px - 1024px) ===== */
@media (max-width: 1024px) {
    .container {
        padding: 0 20px;
    }
    
    .section {
        padding: 40px 0;
    }
}

/* ===== MOBILE GENERAL (max-width: 768px) ===== */
@media (max-width: 768px) {
    
    /* Container y Spacing */
    .container {
        padding: 0 var(--mobile-padding);
        max-width: 100%;
    }
    
    .section {
        padding: 30px 0;
    }
    
    /* Header */
    .header {
        padding: 12px 0;
    }
    
    .logo h1 {
        font-size: 0.9rem;
    }
    
    .logo-icon {
        width: 28px;
        height: 28px;
    }
    
    /* Navigation */
    .nav {
        display: none;
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        background: #000;
        border-top: 3px solid #fff;
        z-index: 999;
        max-height: calc(100vh - 60px);
        overflow-y: auto;
    }
    
    .nav.active {
        display: block;
    }
    
    .nav ul {
        flex-direction: column;
        padding: 10px 0;
    }
    
    .nav ul li {
        width: 100%;
        border-bottom: 1px solid #333;
    }
    
    .nav-link {
        padding: 15px 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        min-height: var(--touch-target-min);
    }
    
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        background: #fff;
        color: #000;
        border: 3px solid #000;
        padding: 10px 15px;
        font-family: 'JetBrains Mono', monospace;
        font-weight: 700;
        font-size: 14px;
        cursor: pointer;
        min-height: var(--touch-target-min);
        min-width: 80px;
    }
    
    .mobile-menu-toggle:hover {
        background: #000;
        color: #fff;
    }
    
    /* Dropdowns en móvil */
    .dropdown-content {
        position: static;
        display: none;
        border: 4px solid #fff;
        border-top: 2px solid #fff;
        box-shadow: 4px 4px 0 rgba(255,255,255,1);
        background: #000;
        margin: 8px 0;
    }
    
    .nav-dropdown.active .dropdown-content {
        display: block;
    }
    
    .dropdown-link {
        padding: 12px 30px;
        font-size: 0.9rem;
        border-bottom: 2px solid #fff;
    }
    
    .dropdown-link:last-child {
        border-bottom: none;
    }
    
    /* Hero Section */
    .hero-title {
        font-size: 1.5rem;
        line-height: 1.3;
    }
    
    .hero-subtitle {
        font-size: 0.9rem;
    }
    
    /* Buttons - Touch Optimized */
    .btn {
        min-height: var(--touch-target-min);
        padding: 12px 20px;
        font-size: 14px;
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
    }
    
    .btn-primary,
    .btn-secondary,
    .btn-outline {
        margin: 5px 0;
    }
    
    /* Forms */
    .form-group {
        margin-bottom: 15px;
    }
    
    .form-input,
    .form-select,
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="tel"],
    select,
    textarea {
        min-height: var(--touch-target-min);
        font-size: 16px; /* Previene zoom en iOS */
        padding: 12px 15px;
    }
    
    label {
        font-size: 14px;
        margin-bottom: 6px;
        display: block;
    }
    
    /* Filtros */
    .filters {
        flex-direction: column;
        gap: 10px;
    }
    
    .filters-row {
        flex-direction: column;
        gap: 10px;
    }
    
    .filter-group {
        width: 100%;
    }
    
    .filter-group select,
    .filter-group input {
        width: 100%;
    }
    
    /* Grid de Especies */
    .especies-grid {
        grid-template-columns: 1fr !important;
        gap: 15px;
    }
    
    .species-card {
        padding: 15px;
    }
    
    .species-card h3 {
        font-size: 1rem;
    }
    
    .species-card p {
        font-size: 0.85rem;
    }
    
    /* Tablas Responsive */
    .ranking-table-container,
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -15px;
        padding: 0 15px;
    }
    
    .ranking-table,
    table {
        min-width: 600px;
        font-size: 0.8rem;
    }
    
    .ranking-table th,
    .ranking-table td,
    table th,
    table td {
        padding: 8px 6px;
        white-space: nowrap;
    }
    
    /* Scroll indicator para tablas */
    .ranking-table-container::after,
    .table-container::after {
        content: '← Desliza para ver más →';
        display: block;
        text-align: center;
        font-size: 0.75rem;
        color: #666;
        padding: 8px;
        font-family: 'JetBrains Mono', monospace;
    }
    
    /* Modales en móvil */
    .modal-content,
    .modal-content-especie,
    .ai-render-content,
    .species-info-modal .modal-content {
        width: 95vw !important;
        max-width: 95vw !important;
        margin: 10px;
        max-height: 90vh;
    }
    
    .modal-header {
        padding: 12px 15px;
    }
    
    .modal-header h3,
    .modal-header h2 {
        font-size: 1.1rem;
    }
    
    .modal-body {
        padding: 15px;
    }
    
    .modal-close {
        width: 35px;
        height: 35px;
        font-size: 1.3rem;
    }
    
    /* Popup de Colaboración */
    .collaboration-popup {
        width: 95vw;
        max-height: 90vh;
    }
    
    .popup-content {
        grid-template-columns: 1fr;
        padding: 15px;
    }
    
    .form-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    /* Canvas y Gráficos */
    .chart-canvas-container {
        height: 300px !important;
    }
    
    #comparison-chart {
        max-height: 300px !important;
    }
    
    .spatial-canvas-container {
        width: 100%;
    }
    
    #terrain-canvas {
        max-width: 100%;
        height: auto;
    }
    
    /* Controles de Zoom */
    .zoom-controls {
        flex-wrap: wrap;
        gap: 5px;
    }
    
    .zoom-btn {
        min-width: 40px;
        min-height: 40px;
        padding: 8px;
        font-size: 0.75rem;
    }
    
    .zoom-indicator {
        min-width: 50px;
        padding: 8px 10px;
        font-size: 0.85rem;
    }
    
    /* Cards y Metric Cards */
    .metric-card,
    .stat-card {
        padding: 12px;
    }
    
    .metric-number {
        font-size: 1.5rem;
    }
    
    .metric-label {
        font-size: 0.75rem;
    }
    
    /* Section Headers */
    .section-header h2 {
        font-size: 1.5rem;
    }
    
    .section-header p {
        font-size: 0.9rem;
    }
    
    /* Banners informativos */
    .banner,
    [style*="padding: 20px"] {
        padding: 15px !important;
        margin-bottom: 20px !important;
    }
    
    /* Control Sections */
    .control-section,
    .criteria-filters-panel {
        padding: 15px;
        margin-bottom: 15px;
    }
    
    .control-section h3 {
        font-size: 1.1rem;
        margin-bottom: 12px;
    }
    
    /* Dashboard Grids */
    .analysis-controls-grid,
    .performance-metrics,
    .criteria-generator-dashboard {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    /* Stats Grid */
    .stats-grid,
    .stats-grid-combined {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    /* Pagination */
    .pagination {
        flex-wrap: wrap;
        gap: 5px;
        justify-content: center;
    }
    
    .page-btn {
        min-width: 40px;
        min-height: 40px;
        padding: 8px;
    }
    
    /* Footer */
    .footer {
        padding: 20px 0;
        font-size: 0.8rem;
    }
    
    /* Social Icons Fixed */
    .social-icons-fixed {
        right: 10px;
        bottom: 80px;
    }
    
    .social-icon-fixed {
        width: 45px;
        height: 45px;
    }
    
    /* Glossary */
    .alphabet-filter {
        display: grid;
        grid-template-columns: repeat(6, 1fr);
        gap: 5px;
    }
    
    .letter-btn {
        min-height: 40px;
        padding: 8px 4px;
        font-size: 0.8rem;
    }
    
    .terms-grid {
        grid-template-columns: 1fr;
    }
    
    /* Spatial Distribution */
    .spatial-dashboard {
        grid-template-columns: 1fr;
    }
    
    .spatial-controls {
        order: 2;
    }
    
    .spatial-canvas-container {
        order: 1;
        margin-bottom: 20px;
    }
    
    /* Species Management Tools */
    .species-management-tools {
        flex-direction: column;
    }
    
    .data-management-group {
        grid-template-columns: 1fr;
    }
    
    /* Import/Export Buttons */
    .import-buttons,
    .export-buttons {
        flex-direction: column;
    }
    
    /* Action Buttons */
    .action-buttons,
    .criteria-actions,
    .project-actions {
        flex-direction: column;
        gap: 10px;
    }
    
    .action-buttons .btn,
    .criteria-actions .btn {
        width: 100%;
        margin: 0;
    }
}

/* ===== MOBILE SMALL (max-width: 480px) ===== */
@media (max-width: 480px) {
    
    :root {
        --mobile-padding: 12px;
        --mobile-margin: 8px;
        --mobile-font-base: 13px;
    }
    
    /* Typography */
    body {
        font-size: var(--mobile-font-base);
    }
    
    h1 {
        font-size: 1.3rem;
    }
    
    h2 {
        font-size: 1.2rem;
    }
    
    h3 {
        font-size: 1.05rem;
    }
    
    h4 {
        font-size: 0.95rem;
    }
    
    /* Header */
    .header {
        padding: 10px 0;
    }
    
    .logo h1 {
        font-size: 0.75rem;
    }
    
    .logo-icon {
        width: 24px;
        height: 24px;
    }
    
    .mobile-menu-toggle {
        padding: 8px 12px;
        font-size: 12px;
        min-width: 70px;
    }
    
    /* Hero */
    .hero-title {
        font-size: 1.2rem;
    }
    
    .hero-subtitle {
        font-size: 0.85rem;
    }
    
    /* Buttons más pequeños */
    .btn {
        padding: 10px 15px;
        font-size: 13px;
    }
    
    .btn-icon {
        width: 14px;
        height: 14px;
    }
    
    /* Forms más compactos */
    .form-input,
    .form-select,
    input,
    select,
    textarea {
        padding: 10px 12px;
        font-size: 16px; /* Mantener 16px para iOS */
    }
    
    label {
        font-size: 13px;
    }
    
    /* Species Cards más compactas */
    .species-card {
        padding: 12px;
    }
    
    .species-card h3 {
        font-size: 0.9rem;
    }
    
    .species-card p {
        font-size: 0.8rem;
    }
    
    /* Tablas más pequeñas */
    .ranking-table,
    table {
        font-size: 0.7rem;
        min-width: 500px;
    }
    
    .ranking-table th,
    .ranking-table td {
        padding: 6px 4px;
    }
    
    /* Modales ocupan toda la pantalla */
    .modal-content,
    .modal-content-especie,
    .ai-render-content {
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        margin: 0;
        border-radius: 0;
    }
    
    .collaboration-popup {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
    }
    
    /* Charts más pequeños */
    .chart-canvas-container {
        height: 250px !important;
    }
    
    #comparison-chart {
        max-height: 250px !important;
    }
    
    /* Canvas controles más pequeños */
    .zoom-btn {
        min-width: 35px;
        min-height: 35px;
        padding: 6px;
        font-size: 0.7rem;
    }
    
    .zoom-indicator {
        min-width: 45px;
        padding: 6px 8px;
        font-size: 0.8rem;
    }
    
    /* Metric cards stack */
    .performance-metrics {
        grid-template-columns: 1fr;
    }
    
    .metric-number {
        font-size: 1.3rem;
    }
    
    .metric-label {
        font-size: 0.7rem;
    }
    
    /* Banners más compactos */
    [style*="padding: 20px"],
    [style*="padding: 15px"] {
        padding: 12px !important;
    }
    
    /* Control sections más pequeñas */
    .control-section {
        padding: 12px;
    }
    
    .control-section h3 {
        font-size: 1rem;
    }
    
    /* Glossary más compacto */
    .alphabet-filter {
        grid-template-columns: repeat(5, 1fr);
        gap: 4px;
    }
    
    .letter-btn {
        min-height: 35px;
        padding: 6px 2px;
        font-size: 0.75rem;
    }
    
    /* Social icons más pequeños */
    .social-icons-fixed {
        right: 8px;
        bottom: 70px;
    }
    
    .social-icon-fixed {
        width: 40px;
        height: 40px;
    }
    
    /* Footer más compacto */
    .footer {
        padding: 15px 0;
        font-size: 0.7rem;
    }
    
    /* Pagination más pequeña */
    .page-btn {
        min-width: 35px;
        min-height: 35px;
        padding: 6px;
        font-size: 0.8rem;
    }
}

/* ===== LANDSCAPE MODE (móvil horizontal) ===== */
@media (max-width: 768px) and (orientation: landscape) {
    
    .hero {
        padding: 20px 0;
    }
    
    .section {
        padding: 25px 0;
    }
    
    .modal-content,
    .modal-content-especie {
        max-height: 95vh;
    }
    
    .chart-canvas-container {
        height: 250px !important;
    }
    
    /* Header más compacto en landscape */
    .header {
        padding: 8px 0;
    }
    
    .nav {
        max-height: calc(100vh - 50px);
    }
}

/* ===== UTILIDADES MÓVILES ===== */
@media (max-width: 768px) {
    
    /* Hide on mobile */
    .hide-mobile {
        display: none !important;
    }
    
    /* Show only on mobile */
    .show-mobile {
        display: block !important;
    }
    
    /* Full width on mobile */
    .full-width-mobile {
        width: 100% !important;
    }
    
    /* Stack on mobile */
    .stack-mobile {
        flex-direction: column !important;
    }
    
    /* Center on mobile */
    .center-mobile {
        text-align: center !important;
        justify-content: center !important;
        align-items: center !important;
    }
    
    /* No padding on mobile */
    .no-padding-mobile {
        padding: 0 !important;
    }
    
    /* Touch-friendly spacing */
    .touch-spacing {
        margin: 10px 0;
    }
}

/* ===== MEJORAS DE ACCESIBILIDAD TÁCTIL ===== */
@media (max-width: 768px) {
    
    /* Aumentar área de toque para links */
    a {
        padding: 8px 4px;
        margin: -8px -4px;
    }
    
    /* Mejorar contraste en touch */
    button:active,
    .btn:active {
        opacity: 0.8;
        transform: scale(0.98);
    }
    
    /* Feedback visual en select */
    select:focus,
    input:focus,
    textarea:focus {
        outline: 3px solid #000;
        outline-offset: 2px;
    }
    
    /* Prevent text selection durante gestos */
    .species-card,
    .metric-card,
    .btn {
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* Smooth scrolling en modales */
    .modal-body,
    .popup-content {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
}

/* ===== OPTIMIZACIÓN DE PERFORMANCE MÓVIL ===== */
@media (max-width: 768px) {
    
    /* Reducir animaciones complejas */
    * {
        transition-duration: 0.2s !important;
    }
    
    /* Desactivar transforms pesadas */
    .species-card:hover,
    .metric-card:hover {
        transform: none !important;
    }
    
    /* Lazy rendering para imágenes */
    img {
        loading: lazy;
    }
}

/* ===== FIX PARA iOS ===== */
@supports (-webkit-touch-callout: none) {
    
    /* Fix para iOS viewport height */
    .modal-content,
    .collaboration-popup {
        max-height: -webkit-fill-available;
    }
    
    /* Fix para iOS input zoom */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="tel"],
    select,
    textarea {
        font-size: 16px !important; /* Prevenir zoom automático */
    }
    
    /* Fix para iOS scroll bounce */
    body {
        -webkit-overflow-scrolling: touch;
    }
}

/* ===== FIX PARA ANDROID ===== */
@media (max-width: 768px) {
    
    /* Fix para teclado virtual */
    input:focus,
    textarea:focus,
    select:focus {
        scroll-margin-bottom: 200px;
    }
    
    /* Mejorar tap delay */
    a, button, input, select, textarea {
        touch-action: manipulation;
    }
}
