/**
 * menu.css - Menú y Navegación para CRESA
 * Header Responsivo sin Menú Hamburguesa
 */

/* ============================================
   HEADER CONTAINER - Desktop
   ============================================ */
@media (min-width: 769px) {
  .header-container {
    display: flex;
    align-items: center;
    justify-content: space-between; /* Logo a la izquierda, menú+íconos a la derecha */
    padding: 0.75rem var(--spacing-md);
    max-width: 1400px;
    margin: 0 auto;
    height: 140px;
    gap: 2rem;
    position: relative;
    box-sizing: border-box;
    width: 100%;
    direction: ltr; /* LTR para mantener orden correcto: Logo (izq), Nav+Iconos (der) */
    overflow: visible !important; /* Permite que el dropdown se muestre fuera del contenedor */
  }
}

/* ============================================
   LOGO SECTION - Desktop (Fijo)
   ============================================ */
@media (min-width: 769px) {
  .logo-section {
    display: flex;
    align-items: center;
    flex: 0 0 auto; /* Logo fijo */
    height: 100%;
    padding-left: 1.5rem; /* Padding para separar del borde izquierdo */
  }

  .logo-link {
    display: flex;
    align-items: center;
    text-decoration: none;
    height: 100%;
  }

  .logo-img {
    max-width: 257px;
    max-height: 86px;
    object-fit: contain;
    height: auto;
    width: auto;
  }
}

/* ============================================
   NAVEGACIÓN DESKTOP - Centrada y Adaptable
   ============================================ */
.nav-menu {
  display: none;
}

@media (min-width: 769px) {
  .nav-menu {
    display: flex;
    flex: 0 0 auto; /* No se expande, tamaño fijo */
    justify-content: flex-end; /* Alinear a la derecha */
    align-items: center;
    margin: 0;
    margin-right: 1.5rem; /* Espacio entre menú e iconos */
    position: relative;
    z-index: 1;
  }

  .nav-menu ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: row; /* Asegurar orden LTR: Inicio, Tienda, Contacto */
    direction: ltr; /* Forzar dirección LTR */
    gap: 2.5rem;
    justify-content: flex-end; /* Alinear items del menú a la derecha */
    align-items: center;
  }

  @media (min-width: 1024px) {
    .nav-menu ul {
      gap: 3rem;
    }
  }

  .nav-menu ul li a {
    color: #333;
    text-decoration: none;
    font-weight: 500;
    font-size: 1rem;
    transition: color 0.3s ease;
    padding: 0.5rem 0;
    position: relative;
    white-space: nowrap;
  }

  .nav-menu ul li a:hover {
    color: #E07A5F;
  }

  .nav-menu ul li a::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background-color: #E07A5F;
    transition: width 0.3s ease;
  }

  .nav-menu ul li a:hover::after,
  .nav-menu ul li a.active::after {
    width: 100%;
  }

  .nav-menu ul li a.active {
    color: #000;
    font-weight: 600;
  }
}

/* ============================================
   ÍCONOS DESKTOP (Carrito y Usuario) - Adaptables
   ============================================ */
.desktop-icons-container {
  display: none;
}

@media (min-width: 769px) {
  .desktop-icons-container {
    display: flex;
    flex-direction: row; /* Asegurar orden LTR */
    direction: ltr; /* Forzar dirección LTR */
    align-items: center;
    gap: 1rem;
    flex: 0 0 auto; /* Tamaño fijo, no se expande */
    justify-content: flex-end;
    position: relative;
    overflow: visible;
    z-index: 1010;
    padding-right: 1.5rem; /* Padding para separar del borde derecho */
  }
}

/* Carrito Desktop */
.desktop-cart-container {
  position: relative;
}

.cart-icon-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: transparent;
  border: 2px solid #333;
  border-radius: 50%;
  color: #333;
  text-decoration: none;
  transition: all 0.3s ease;
  position: relative;
}

.cart-icon-link:hover {
  background-color: rgba(0, 0, 0, 0.05);
  border-color: #E07A5F;
  color: #E07A5F;
}

.cart-icon {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
}

.cart-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background-color: #000000;
  color: #fff;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: bold;
  border: 2px solid #fff;
  padding: 0 4px;
  box-sizing: border-box;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.cart-badge:not(:empty) {
  display: flex;
}

/* Menú Usuario Desktop */
.desktop-user-menu-container {
  position: relative;
  z-index: 1013;
  overflow: visible; /* Permite que el dropdown se muestre fuera del contenedor */
  display: flex;
  align-items: center;
}

.desktop-user-menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: transparent;
  border: 2px solid #333;
  border-radius: 50%;
  color: #333;
  cursor: pointer;
  transition: all 0.3s ease;
  padding: 0;
  position: relative;
  z-index: 1013;
}

.desktop-user-menu-btn:hover {
  background-color: rgba(0, 0, 0, 0.05);
  border-color: #E07A5F;
  color: #E07A5F;
}

.desktop-user-icon {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
}

/* ============================================
   MENÚ USUARIO - Dropdown desplegable
   ============================================ */
/* Contenedor del menú */
.desktop-user-menu-dropdown {
  position: fixed !important; /* Fixed para que el JS pueda posicionarlo correctamente */
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  min-width: 280px;
  max-width: 320px;
  width: 280px;
  max-height: 400px;         /* altura máxima */
  overflow-y: auto;          /* scroll si se excede */
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  z-index: 9999 !important;
  pointer-events: none;
  display: block;
  /* Las coordenadas top/right se establecen dinámicamente por JavaScript */
  top: auto;
  right: auto;
  left: auto;
  bottom: auto;
}

/* Cuando el menú está abierto - soporta ambos selectores para compatibilidad */
.desktop-user-menu-dropdown[aria-hidden="false"],
.desktop-user-menu-dropdown.is-open {
  opacity: 1 !important;
  visibility: visible !important;
  transform: translateY(0) !important;
  pointer-events: auto !important;
}

/* Encabezado del menú */
.desktop-user-menu-header {
  padding: 1.25rem;
  background: linear-gradient(135deg, #2a2a2a 0%, #1f1f1f 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* Nombre del usuario */
.desktop-user-name {
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  margin: 0 0 0.5rem 0;
}

/* Etiqueta de perfil */
.desktop-user-profile-label {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.8);
  margin-top: 0.25rem;
}

/* Ítems del menú */
.desktop-user-menu-item {
  padding: 0.5rem 0;
}

/* Enlaces del menú */
.desktop-user-menu-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: #333;
  text-decoration: none;
  font-size: 0.95rem;
  transition: all 0.3s ease;
  white-space: nowrap;
  overflow: hidden;
  position: relative;
}

/* Asegurar que los SVG dentro de los enlaces tengan tamaño fijo */
.desktop-user-menu-link svg {
  width: 20px !important;
  height: 20px !important;
  min-width: 20px !important;
  max-width: 20px !important;
  min-height: 20px !important;
  max-height: 20px !important;
  flex-shrink: 0;
  box-sizing: border-box;
}

.desktop-user-menu-link:hover {
  background-color: rgba(0, 0, 0, 0.05);
  color: #E07A5F;
}

/* Íconos dentro del menú */
.desktop-user-menu-icon {
  width: 20px !important;
  height: 20px !important;
  min-width: 20px !important;
  max-width: 20px !important;
  min-height: 20px !important;
  max-height: 20px !important;
  stroke: currentColor;
  fill: none;
  flex-shrink: 0;
  box-sizing: border-box;
  display: block;
}

/* Separador entre secciones */
.desktop-user-menu-divider {
  height: 1px;
  background-color: #e0e0e0;
  margin: 0.5rem 0;
}

/* ============================================
   HEADER MÓVIL (max-width: 768px)
   ============================================ */

@media (max-width: 768px) {
    .header-container {
        padding: 0.75rem 1rem;
        height: 70px;
        min-height: 70px;
        max-height: 70px;
        flex-wrap: nowrap;
        align-items: center;
        gap: 0.75rem;
    }
    
    .logo-section {
        flex-shrink: 0;
        display: flex;
        align-items: center;
        height: 100%;
    }
    
    .logo-link {
        display: flex;
        align-items: center;
        height: 100%;
    }
    
    .logo-img {
        max-width: 140px;
        max-height: 50px;
        width: auto;
        height: auto;
        object-fit: contain;
    }
    
    /* Ocultar navegación desktop */
    .nav-menu {
        display: none !important;
    }
    
    /* Ocultar íconos desktop */
    .desktop-icons-container {
        display: none !important;
    }
    
    /* Contenedor de acciones móviles */
    .mobile-header-actions {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        flex-shrink: 0;
        margin-left: auto;
        height: 100%;
    }
    
    /* Menú Usuario Móvil */
    .mobile-user-menu-container {
        position: relative !important;
        flex-shrink: 0;
        z-index: 1013 !important;
        overflow: visible !important;
    }
    
    .mobile-user-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        background: transparent;
        border: 2px solid #333;
        border-radius: 50%;
        color: #333;
        cursor: pointer;
        transition: all 0.3s ease;
        padding: 0;
        position: relative;
        z-index: 1011;
        pointer-events: auto;
        flex-shrink: 0;
    }
    
    .mobile-user-menu-btn:hover {
        background-color: rgba(0, 0, 0, 0.05);
        border-color: #E07A5F;
        color: #E07A5F;
    }
    
    .mobile-user-icon {
        width: 18px;
        height: 18px;
        stroke: currentColor;
        fill: none;
        flex-shrink: 0;
    }
    
    .mobile-user-menu-dropdown {
        position: fixed !important;
        top: auto !important;
        bottom: auto !important;
        right: auto !important;
        left: auto !important;
        background: #fff !important;
        border: 1px solid #e0e0e0 !important;
        border-radius: 8px !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15) !important;
        min-width: 200px !important;
        max-width: calc(100vw - 2rem) !important;
        opacity: 0 !important;
        visibility: hidden !important;
        transform: translateY(-10px) !important;
        transition: all 0.3s ease !important;
        z-index: 9999 !important;
        pointer-events: none !important;
        overflow: visible !important;
        display: block !important;
    }
    
    .mobile-user-menu-dropdown[aria-hidden="false"],
    .mobile-user-menu-dropdown.is-open {
        opacity: 1 !important;
        visibility: visible !important;
        transform: translateY(0) !important;
        pointer-events: auto !important;
        display: block !important;
    }
    
    .mobile-user-menu-header {
        padding: 1rem;
        background: linear-gradient(135deg, #2a2a2a 0%, #1f1f1f 100%);
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .mobile-user-name {
        font-size: 0.9rem;
        font-weight: 600;
        color: #fff;
        margin: 0 0 0.25rem 0;
    }
    
    .mobile-user-email {
        font-size: 0.8rem;
        color: rgba(255, 255, 255, 0.7);
        margin: 0 0 0.25rem 0;
    }
    
    .mobile-user-role {
        font-size: 0.75rem;
        color: rgba(255, 255, 255, 0.8);
    }
    
    .mobile-user-menu-item {
        padding: 0.5rem 0;
    }
    
    .mobile-user-menu-divider {
        height: 1px;
        background-color: #e0e0e0;
        margin: 0.5rem 0;
    }
    
    .mobile-user-menu-link {
        display: block;
        padding: 0.75rem 1rem;
        color: #333;
        text-decoration: none;
        font-size: 0.9rem;
        transition: all 0.3s ease;
    }
    
    .mobile-user-menu-link:hover {
        background-color: rgba(0, 0, 0, 0.05);
        color: #E07A5F;
    }
    
    /* Ícono de Bolsa Móvil - Fijo a la derecha */
    .mobile-bolsa-link {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        background: transparent;
        border: 2px solid #333;
        border-radius: 50%;
        color: #333;
        text-decoration: none;
        transition: all 0.3s ease;
        position: relative;
        flex-shrink: 0;
    }
    
    .mobile-bolsa-link:hover {
        background-color: rgba(0, 0, 0, 0.05);
        border-color: #E07A5F;
        color: #E07A5F;
    }
    
    .bolsa-icon {
        width: 20px;
        height: 20px;
        stroke: currentColor;
        flex-shrink: 0;
        fill: none;
    }
    
    /* Contador de bolsa - Círculo negro */
    .bolsa-contador {
        position: absolute;
        top: -4px;
        right: -4px;
        background-color: #000000;
        color: #ffffff;
        border-radius: 50%;
        width: 18px;
        height: 18px;
        display: none;
        align-items: center;
        justify-content: center;
        font-size: 0.65rem;
        font-weight: bold;
        border: 2px solid #fff;
        min-width: 18px;
        padding: 0 3px;
        box-sizing: border-box;
        line-height: 1;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }
    
    /* Mostrar solo cuando tiene contenido y cantidad > 0 */
    .bolsa-contador:not(:empty) {
        display: flex;
    }
    
    .bolsa-contador:empty {
        display: none !important;
    }
}

/* Ocultar acciones móviles en desktop */
@media (min-width: 769px) {
    .mobile-header-actions {
        display: none !important;
    }
}
