/* ==========================================================================
   Optimizaciones móviles para la aplicación de presupuestos
   ========================================================================== */

/* Variables CSS para móvil */
:root {
    --mobile-touch-target: 44px;
    --mobile-spacing-xs: 0.5rem;
    --mobile-spacing-sm: 0.75rem;
    --mobile-spacing-md: 1rem;
    --mobile-spacing-lg: 1.5rem;
    --mobile-font-size-xs: 0.75rem;
    --mobile-font-size-sm: 0.875rem;
    --mobile-font-size-base: 1rem;
    --mobile-font-size-lg: 1.125rem;
}

/* Mejoras de accesibilidad táctil */
.touch-manipulation {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Botones optimizados para móvil */
@media (max-width: 768px) {
    .btn, button, .mobile-nav-item, .mobile-dropdown-btn {
        min-height: var(--mobile-touch-target);
        min-width: var(--mobile-touch-target);
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Formularios móviles */
    .form-control, input, select, textarea {
        min-height: var(--mobile-touch-target);
        font-size: 16px; /* Previene zoom en iOS */
        padding: 0.75rem;
    }
    
    /* Tablas responsive */
    .table-responsive {
        border: none;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table {
        min-width: 600px;
        font-size: var(--mobile-font-size-sm);
    }
    
    .table th,
    .table td {
        padding: var(--mobile-spacing-sm);
        white-space: nowrap;
    }
    
    /* Cards móviles */
    .card {
        margin-bottom: var(--mobile-spacing-md);
        border-radius: 0.5rem;
    }
    
    .card-body {
        padding: var(--mobile-spacing-md);
    }
    
    /* Navegación móvil mejorada */
    .mobile-menu {
        max-height: calc(100vh - 80px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Espaciado móvil */
    .container, .container-fluid {
        padding-left: var(--mobile-spacing-sm);
        padding-right: var(--mobile-spacing-sm);
    }
    
    /* Títulos móviles */
    h1 {
        font-size: 1.75rem;
        line-height: 1.2;
    }
    
    h2 {
        font-size: 1.5rem;
        line-height: 1.3;
    }
    
    h3 {
        font-size: 1.25rem;
        line-height: 1.4;
    }
    
    /* Modales móviles */
    .modal-dialog {
        margin: var(--mobile-spacing-sm);
        max-width: calc(100vw - 1rem);
    }
    
    .modal-content {
        border-radius: 0.75rem;
    }
    
    /* Alertas móviles */
    .alert {
        margin-bottom: var(--mobile-spacing-md);
        padding: var(--mobile-spacing-md);
        border-radius: 0.5rem;
    }
    
    /* Badges móviles */
    .badge {
        font-size: var(--mobile-font-size-xs);
        padding: 0.25rem 0.5rem;
    }
}

/* Pantallas muy pequeñas (< 576px) */
@media (max-width: 575px) {
    /* Ajustes para pantallas muy pequeñas */
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn {
        border-radius: 0.375rem !important;
        margin-bottom: 0.25rem;
        width: 100%;
    }
    
    /* Formularios en pantallas pequeñas */
    .form-row {
        flex-direction: column;
    }
    
    .form-row .col {
        margin-bottom: var(--mobile-spacing-sm);
    }
    
    /* Tablas en tarjetas para móvil */
    .mobile-card-table {
        display: none;
    }
    
    .mobile-card-list {
        display: block;
    }
    
    .mobile-card-item {
        background: white;
        border: 1px solid #e5e7eb;
        border-radius: 0.5rem;
        padding: var(--mobile-spacing-md);
        margin-bottom: var(--mobile-spacing-sm);
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }
    
    .mobile-card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: var(--mobile-spacing-sm);
        padding-bottom: var(--mobile-spacing-sm);
        border-bottom: 1px solid #e5e7eb;
    }
    
    .mobile-card-title {
        font-weight: 600;
        color: #1f2937;
    }
    
    .mobile-card-content {
        display: grid;
        gap: var(--mobile-spacing-xs);
    }
    
    .mobile-card-field {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.25rem 0;
    }
    
    .mobile-card-label {
        font-size: var(--mobile-font-size-sm);
        color: #6b7280;
        font-weight: 500;
    }
    
    .mobile-card-value {
        font-size: var(--mobile-font-size-sm);
        color: #1f2937;
        text-align: right;
    }
    
    .mobile-card-actions {
        display: flex;
        gap: var(--mobile-spacing-xs);
        margin-top: var(--mobile-spacing-sm);
        padding-top: var(--mobile-spacing-sm);
        border-top: 1px solid #e5e7eb;
    }
    
    .mobile-card-actions .btn {
        flex: 1;
        font-size: var(--mobile-font-size-sm);
        padding: 0.5rem;
    }
}

/* Pantallas medianas y grandes - mostrar tabla normal */
@media (min-width: 576px) {
    .mobile-card-table {
        display: table;
    }
    
    .mobile-card-list {
        display: none;
    }
}

/* Mejoras de rendimiento para móvil */
@media (max-width: 768px) {
    /* Reducir animaciones en móvil para mejor rendimiento */
    .transition-all {
        transition-duration: 0.15s;
    }
    
    /* Optimizar transformaciones */
    .transform {
        will-change: transform;
    }
    
    /* Mejorar scroll en móvil */
    .overflow-auto {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Performance optimizations for mobile */
    * {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    input, textarea, select {
        -webkit-user-select: text;
        -moz-user-select: text;
        -ms-user-select: text;
        user-select: text;
    }
    
    /* Enhanced touch interactions */
    .touch-manipulation {
        touch-action: manipulation;
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* Improved button touch targets */
    button, .btn, a[role="button"] {
        min-height: 44px;
        min-width: 44px;
        touch-action: manipulation;
    }
    
    /* Smooth scrolling for mobile */
    html {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    /* Prevent zoom on input focus */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="search"],
    textarea,
    select {
        font-size: 16px;
    }
    
    /* Enhanced dropdown interactions */
    .dropdown-menu {
        touch-action: manipulation;
    }
    
    /* Better modal interactions */
    .modal {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Improved table scrolling */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }
}

/* Modo oscuro para móvil */
@media (prefers-color-scheme: dark) and (max-width: 768px) {
    .mobile-card-item {
        background: #374151;
        border-color: #4b5563;
        color: #f9fafb;
    }
    
    .mobile-card-header {
        border-bottom-color: #4b5563;
    }
    
    .mobile-card-title {
        color: #f9fafb;
    }
    
    .mobile-card-label {
        color: #d1d5db;
    }
    
    .mobile-card-value {
        color: #f9fafb;
    }
    
    .mobile-card-actions {
        border-top-color: #4b5563;
    }
}

/* Utilidades específicas para móvil */
.mobile-only {
    display: none;
}

.desktop-only {
    display: block;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block;
    }
    
    .desktop-only {
        display: none;
    }
    
    .mobile-flex {
        display: flex;
    }
    
    .mobile-grid {
        display: grid;
    }
    
    .mobile-hidden {
        display: none;
    }
    
    .mobile-full-width {
        width: 100%;
    }
    
    .mobile-text-center {
        text-align: center;
    }
    
    .mobile-text-left {
        text-align: left;
    }
    
    .mobile-text-right {
        text-align: right;
    }
}

/* Mejoras de accesibilidad */
@media (max-width: 768px) {
    /* Aumentar contraste en móvil */
    .text-muted {
        color: #4b5563 !important;
    }
    
    /* Mejorar focus visible en móvil */
    .btn:focus,
    .form-control:focus,
    .nav-link:focus {
        outline: 2px solid #3b82f6;
        outline-offset: 2px;
    }
    
    /* Mejorar legibilidad */
    body {
        line-height: 1.6;
    }
    
    p, li {
        line-height: 1.5;
    }
}

/* Animaciones optimizadas para móvil */
@media (max-width: 768px) {
    @keyframes mobileSlideIn {
        from {
            transform: translateX(-10px);
            opacity: 0;
        }
        to {
            transform: translateX(0);
            opacity: 1;
        }
    }
    
    .mobile-slide-in {
        animation: mobileSlideIn 0.2s ease-out;
    }
    
    @keyframes mobileFadeIn {
        from {
            opacity: 0;
        }
        to {
            opacity: 1;
        }
    }
    
    .mobile-fade-in {
        animation: mobileFadeIn 0.15s ease-out;
    }
}