/* =========================================================
  Merkaia - mobile-navigation.css 
  Navegación móvil reutilizable para todas las páginas
  ========================================================= */

/* ===== BARRA INFERIOR MÓVIL MEJORADA ===== */
.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    background: var(--brand-green);
    border-top: 1px solid #e0e0e0;
    display: none;
    z-index: 1000;
    /* Aumentamos el padding inferior para separar los botones de la barra de sistema */
    padding: 12px 12px max(20px, env(safe-area-inset-bottom, 20px));
    box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.12);
    min-height: 80px;
    /* Aumentamos altura mínima */
    box-sizing: border-box;
    overflow: hidden;
    /* Forzar que permanezca fijo en la parte inferior sin moverse con el teclado */
    transform: translateZ(0);
    will-change: transform;
    contain: layout;
}

/* Cuando el teclado virtual está abierto, el nav permanece fijo
   en la parte inferior y es simplemente tapado por el teclado */
.mobile-bottom-nav.keyboard-open {
    /* Se mantiene fijo en su posición, el teclado lo tapará */
    transform: translateZ(0) !important;
    bottom: 0 !important;
    opacity: 1;
    pointer-events: auto;
}

.mobile-nav-btn {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: #666;
    padding: 8px 6px;
    position: relative;
    transition: color 0.3s ease, transform 0.1s ease;
    min-height: 56px;
    justify-content: center;
}

.mobile-nav-btn.active {
    color: var(--brand-green-dark);
}

.nav-icon {
    width: 28px;
    height: 28px;
    margin-bottom: 2px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-icon svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
    transition: fill 0.3s ease;
}

.nav-label {
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    margin-top: 2px;
    display: block;
    line-height: 1.2;
    color: inherit;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-badge {
    position: absolute;
    top: -6px;
    right: -8px;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 11px;
    display: none;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    border: 2px solid white;
}

.nav-badge.visible {
    display: flex;
}

.notificacion-icono-mobile,
.carrito-icono-mobile {
    position: relative;
}

.user-avatar-mobile {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid transparent;
    transition: border-color 0.3s;
    margin-bottom: 2px;
}

.user-avatar-mobile svg {
    width: 100%;
    height: 100%;
    display: block;
}

.avatar-img-mobile {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mensajes-btn {
    position: relative !important;
}

.mensaje-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 10px;
    display: none;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    border: 2px solid white;
}

.mensaje-badge.visible {
    display: flex;
}

.contador-notificaciones-mobile,
.contador-carrito-mobile {
    background-color: #ff4444;
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 10px;
    display: none;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: -4px;
    right: -4px;
    /* Adjusted from -8px for better containment within icon area if needed, or keeping tight */
    font-weight: bold;
    border: 2px solid white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.contador-notificaciones-mobile.visible,
.contador-carrito-mobile.visible {
    display: flex !important;
    /* Force flex to override any inline-block set by JS */
    align-items: center;
    justify-content: center;
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex;
    }

    html,
    body {
        overflow-x: hidden;
    }

    body {
        /* Ajustamos el padding del body para compensar la nueva altura del nav */
        padding-bottom: calc(80px + env(safe-area-inset-bottom, 20px)) !important;
    }

    main,
    .main-content,
    #productos,
    .pagina-notificaciones {
        margin-bottom: calc(80px + env(safe-area-inset-bottom, 20px)) !important;
    }
}

@media (max-width: 480px) {
    .mobile-bottom-nav {
        min-height: 75px;
        padding: 10px 8px max(18px, env(safe-area-inset-bottom, 18px));
    }

    .mobile-nav-btn {
        min-height: 52px;
        padding: 6px 4px;
    }

    .nav-icon {
        width: 26px;
        height: 26px;
    }

    .nav-icon svg {
        width: 26px;
        height: 26px;
    }

    .nav-label {
        font-size: 12px;
    }

    .user-avatar-mobile {
        width: 28px;
        height: 28px;
    }



    .nav-badge {
        width: 16px;
        height: 16px;
        font-size: 10px;
        top: -5px;
        right: -6px;
    }

    .contador-notificaciones-mobile,
    .contador-carrito-mobile {
        width: 18px;
        height: 18px;
        font-size: 10px;
        top: -5px;
        right: -6px;
        border-width: 2px;
    }

    body {
        padding-bottom: calc(75px + env(safe-area-inset-bottom, 18px)) !important;
    }
}




.mobile-nav-btn:hover {
    color: var(--brand-green-dark);
}

.mobile-nav-btn:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
}

.mobile-nav-btn.user-profile-mobile.active .user-avatar-mobile {
    border-color: var(--brand-green-dark);
}



.mobile-nav-btn.active::after {
    content: '';
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    background: var(--brand-green-dark);
    border-radius: 50%;
}

.mobile-bottom-nav,
.mobile-nav-btn,
.nav-icon,
.nav-label {
    transition: all 0.3s ease;
}

@supports (padding: max(0px)) {
    .mobile-bottom-nav {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}

@supports (-webkit-touch-callout: none) {
    .mobile-bottom-nav {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }

    body {
        padding-bottom: calc(85px + max(20px, env(safe-area-inset-bottom))) !important;
    }
}

@media (prefers-color-scheme: dark) {
    .mobile-bottom-nav {
        background: #1a1a1a;
        border-top-color: #333;
    }

    .mobile-nav-btn {
        color: #ccc;
    }

    .mobile-nav-btn.active {
        color: var(--brand-green);
    }
}