/* ========================================
   MOBILE OPTIMIZATIONS - CNX
   Estilos para experiencia móvil nativa
   ======================================== */

/* ==================== VARIABLES ==================== */
:root {
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);

    --touch-target-size: 44px;
    --mobile-padding: 16px;
    --mobile-radius: 12px;

    --primary-color: #0d6efd;
    --primary-dark: #0b5ed7;
    --success-color: #198754;
    --danger-color: #dc3545;
    --warning-color: #ffc107;

    --shadow-sm: 0 2px 4px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}

/* ==================== SAFE AREAS (iPhone) ==================== */
@supports (padding: env(safe-area-inset-top)) {
    .mobile-header {
        padding-top: calc(var(--safe-area-inset-top) + 0.75rem);
    }

    .bottom-nav {
        padding-bottom: calc(var(--safe-area-inset-bottom) + 0.5rem);
        height: calc(70px + var(--safe-area-inset-bottom));
    }

    .main-content {
        padding-bottom: calc(90px + var(--safe-area-inset-bottom));
    }
}

/* ==================== TOUCH TARGETS ==================== */
/* Asegurar que todos los elementos táctiles sean de mínimo 44x44px */
@media (max-width: 768px) {
    button,
    .btn,
    a.nav-item,
    input[type="checkbox"],
    input[type="radio"],
    .form-check-input,
    label.capture-button {
        min-height: var(--touch-target-size);
        min-width: var(--touch-target-size);
    }

    /* Eliminar tap highlight color por defecto */
    * {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
    }

    /* Permitir selección de texto solo donde sea necesario */
    input,
    textarea {
        -webkit-user-select: text;
        user-select: text;
    }
}

/* ==================== PULL TO REFRESH ==================== */
.pull-to-refresh {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border-radius: 50%;
    box-shadow: var(--shadow-md);
    opacity: 0;
    pointer-events: none;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.pull-to-refresh i {
    font-size: 1.5rem;
    color: var(--primary-color);
    transition: transform 0.3s ease;
}

.pull-to-refresh.ready i {
    transform: rotate(180deg);
    color: var(--success-color);
}

.pull-to-refresh.loading i {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ==================== BOTONES NATIVOS ==================== */
@media (max-width: 768px) {
    .btn {
        font-weight: 600;
        border-radius: var(--mobile-radius);
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
        transition: all 0.2s ease;
        position: relative;
        overflow: hidden;
    }

    /* Efecto ripple */
    .btn::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 0;
        height: 0;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.5);
        transform: translate(-50%, -50%);
        transition: width 0.6s, height 0.6s;
    }

    .btn:active::after {
        width: 300px;
        height: 300px;
    }

    /* Botones de acción */
    .btn-primary {
        background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
        border: none;
        box-shadow: var(--shadow-sm);
    }

    .btn-primary:active {
        transform: scale(0.98);
        box-shadow: var(--shadow-md);
    }

    /* Botones flotantes */
    .btn-floating {
        position: fixed;
        bottom: calc(90px + var(--safe-area-inset-bottom));
        right: 1rem;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        box-shadow: var(--shadow-lg);
        z-index: 100;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .btn-floating:active {
        transform: scale(0.9);
    }
}

/* ==================== CARDS OPTIMIZADAS ==================== */
@media (max-width: 768px) {
    .card {
        border-radius: var(--mobile-radius);
        border: none;
        box-shadow: var(--shadow-sm);
        margin-bottom: 1rem;
        transition: all 0.3s ease;
    }

    .card:active {
        transform: scale(0.99);
        box-shadow: var(--shadow-md);
    }

    .card-header {
        background: white;
        border-bottom: 1px solid rgba(0,0,0,0.06);
        padding: 1rem var(--mobile-padding);
        font-weight: 600;
    }

    .card-body {
        padding: var(--mobile-padding);
    }
}

/* ==================== INPUTS Y FORMS ==================== */
@media (max-width: 768px) {
    .form-control,
    .form-select {
        font-size: 16px; /* Prevenir zoom en iOS */
        border-radius: var(--mobile-radius);
        padding: 0.75rem 1rem;
        border: 2px solid #dee2e6;
        transition: all 0.3s ease;
    }

    .form-control:focus,
    .form-select:focus {
        border-color: var(--primary-color);
        box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.1);
        transform: translateY(-1px);
    }

    .form-floating > label {
        padding-left: 1rem;
    }

    /* Checkbox y Radio mejorados */
    .form-check-input {
        width: 24px;
        height: 24px;
        margin-top: 0.125rem;
        border: 2px solid #dee2e6;
        transition: all 0.2s ease;
    }

    .form-check-input:checked {
        background-color: var(--primary-color);
        border-color: var(--primary-color);
        transform: scale(1.1);
    }

    .form-check-label {
        margin-left: 0.5rem;
        user-select: none;
    }
}

/* ==================== BOTTOM NAVIGATION ==================== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0.5rem 0;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
    transition: transform 0.3s ease;
}

.bottom-nav.hidden {
    transform: translateY(100%);
}

.bottom-nav .nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    color: #6c757d;
    text-decoration: none;
    transition: all 0.2s ease;
    position: relative;
    min-height: var(--touch-target-size);
}

.bottom-nav .nav-item i {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.bottom-nav .nav-item span {
    font-size: 0.7rem;
    font-weight: 500;
}

.bottom-nav .nav-item.active {
    color: var(--primary-color);
}

.bottom-nav .nav-item.active i {
    transform: scale(1.1);
}

/* Indicador activo */
.bottom-nav .nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 3px;
    background: var(--primary-color);
    border-radius: 0 0 3px 3px;
}

/* Ripple effect en tap */
.bottom-nav .nav-item::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
    transition: transform 0.4s, opacity 0.4s;
}

.bottom-nav .nav-item:active::after {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.2;
}

/* ==================== MOBILE HEADER ==================== */
.mobile-header {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    background: white;
    z-index: 999;
    box-shadow: var(--shadow-sm);
    padding: 0.75rem var(--mobile-padding);
    transition: all 0.3s ease;
}

.mobile-header.scrolled {
    box-shadow: var(--shadow-md);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    color: #212529;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
}

.user-avatar:active {
    transform: scale(0.95);
}

/* ==================== LISTAS OPTIMIZADAS ==================== */
@media (max-width: 768px) {
    .list-group-item {
        border-radius: var(--mobile-radius);
        border: none;
        margin-bottom: 0.5rem;
        padding: 1rem;
        box-shadow: var(--shadow-sm);
        transition: all 0.2s ease;
    }

    .list-group-item:active {
        transform: scale(0.99);
        background: #f8f9fa;
    }
}

/* ==================== MODALS MÓVILES ==================== */
@media (max-width: 768px) {
    .modal-content {
        border-radius: var(--mobile-radius) var(--mobile-radius) 0 0;
        border: none;
    }

    .modal.fade .modal-dialog {
        transform: translateY(100%);
    }

    .modal.show .modal-dialog {
        transform: translateY(0);
    }

    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100%;
        display: flex;
        align-items: flex-end;
    }

    .modal-header {
        padding: 1.25rem var(--mobile-padding);
        border-bottom: 1px solid rgba(0,0,0,0.06);
    }

    .modal-body {
        padding: var(--mobile-padding);
        max-height: 70vh;
        overflow-y: auto;
    }

    .modal-footer {
        padding: var(--mobile-padding);
        border-top: 1px solid rgba(0,0,0,0.06);
    }
}

/* ==================== LOADING STATES ==================== */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s ease-in-out infinite;
    border-radius: var(--mobile-radius);
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ==================== TOAST NOTIFICATIONS ==================== */
@media (max-width: 768px) {
    .toast-container {
        position: fixed;
        bottom: calc(90px + var(--safe-area-inset-bottom));
        left: var(--mobile-padding);
        right: var(--mobile-padding);
        z-index: 1050;
    }

    .toast {
        border-radius: var(--mobile-radius);
        box-shadow: var(--shadow-lg);
        border: none;
        backdrop-filter: blur(10px);
    }
}

/* ==================== SCROLL BEHAVIOR ==================== */
@media (max-width: 768px) {
    .main-content {
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
    }

    /* Ocultar scrollbar pero mantener funcionalidad */
    .main-content::-webkit-scrollbar {
        display: none;
    }

    .main-content {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
}

/* ==================== ANIMACIONES DE ENTRADA ==================== */
@media (max-width: 768px) {
    @keyframes slideInUp {
        from {
            opacity: 0;
            transform: translateY(20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }

    .animate-slide-in {
        animation: slideInUp 0.3s ease-out;
    }

    .animate-fade-in {
        animation: fadeIn 0.3s ease-out;
    }
}

/* ==================== DARK MODE SUPPORT ==================== */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1a1a1a;
        --text-color: #ffffff;
        --card-bg: #2d2d2d;
    }

    body {
        background: var(--bg-color);
        color: var(--text-color);
    }

    .card,
    .modal-content,
    .mobile-header,
    .bottom-nav {
        background: var(--card-bg);
        color: var(--text-color);
    }
}

/* ==================== PERFORMANCE ==================== */
/* GPU acceleration para elementos animados */
.btn,
.card,
.nav-item,
.modal-dialog {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}
