﻿@keyframes headerIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.header {
  position: relative;
  width: 100%;
  background-color: var(--white);
  transition: box-shadow 0.35s ease;
  border-bottom: 1px solid var(--grey-border);
  z-index: 200;
  animation: headerIn 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.header.scrolled {
  box-shadow: 0 6px 24px rgba(0,0,0,0.08);
}

@media (prefers-reduced-motion: reduce) {
  .header { animation: none; }
}

.header-main {
  position: relative;
  z-index: 50;
  height: 80px;
  display: flex;
  align-items: center;
}

.header.scrolled .header-main {
  height: 56px;
}

.header-container {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 20px;
  width: 100%;
}

.header-logo a {
  font-family: var(--font-heading);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  transition: font-size 0.3s ease;
}

.header.scrolled .header-logo a {
  font-size: 20px;
}

@media (max-width: 768px) {
  .header-logo a {
    font-size: 18px;
  }
  
  .header.scrolled .header-logo a {
    font-size: 16px;
  }
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: space-between;
  width: 24px;
  height: 18px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  z-index: 1001;
}

.mobile-menu-toggle span {
  display: block;
  width: 100%;
  height: 2px;
  background-color: var(--black);
  border-radius: 2px;
  transition: all 0.3s ease;
}

/* Header Search Bar */
.header-search {
  position: relative;
  max-width: 450px;
  width: 100%;
  margin: 0 auto;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrapper input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  border: 1px solid var(--grey-border);
  border-radius: 50px;
  font-size: 14px;
  background-color: #f8f9fa;
  transition: all 0.3s ease;
}

.search-input-wrapper input:focus {
  background-color: var(--white);
  border-color: var(--black);
  box-shadow: 0 0 0 4px rgba(0,0,0,0.05);
  outline: none;
}

.search-icon {
  position: absolute;
  left: 14px;
  color: #888;
  pointer-events: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 100%;
  background: var(--white);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
  max-height: 400px;
  overflow-y: auto;
  z-index: 1000;
  display: none;
  border: 1px solid var(--grey-border);
}

.search-results.active {
  display: block;
}

.search-result-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  text-decoration: none;
  color: var(--black);
  transition: background 0.2s;
  border-bottom: 1px solid #f0f0f0;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background-color: #f8f9fa;
}

.search-result-img {
  width: 50px;
  height: 50px;
  border-radius: 8px;
  object-fit: cover;
  background: #eee;
}

.search-result-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.search-result-name {
  font-weight: 600;
  font-size: 14px;
}

.search-result-price {
  font-size: 13px;
  color: #666;
}

.search-no-results {
  padding: 20px;
  text-align: center;
  color: #888;
  font-size: 14px;
}

.nav-mobile-header {
  display: none;
}

.nav-icon,
.nav-badge,
.nav-mobile-featured {
  display: none;
}

.header-nav {
  height: 100%;
}

.header-nav > ul {
  display: flex;
  list-style: none;
  gap: 32px;
  height: 100%;
}

.header-nav li {
  display: flex;
  align-items: center;
  height: 100%;
}

.header-nav a {
  font-weight: 500;
  font-size: 14px;
  transition: color 0.2s;
  color: var(--black);
}

.header-nav a:hover {
  color: #666;
}

/* Dropdown Menu */
.has-dropdown {
  position: relative;
}

.has-dropdown > a {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background-color: var(--white);
  min-width: 240px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.1);
  border-radius: 8px;
  padding: 8px 0;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all 0.2s ease;
  z-index: 100;
  display: block !important;
  list-style: none !important;
}

.has-dropdown:hover .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-menu li {
  width: 100%;
  height: auto !important;
  padding: 0 !important;
  display: block !important;
}

.dropdown-menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  width: 100%;
  font-size: 14px;
  font-weight: 500;
  color: var(--black);
  transition: background 0.2s;
}

.dropdown-menu a:hover {
  background-color: var(--grey-light);
  color: var(--black);
}

.dropdown-menu a strong {
  color: var(--black);
  display: block;
  padding: 4px 0 8px;
  border-bottom: 1px solid #eee;
  width: 100%;
}

.dropdown-cat-img {
  width: 36px;
  height: 36px;
  border-radius: 7px;
  object-fit: cover;
  flex-shrink: 0;
  background: #eee;
}

.dropdown-cat-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #aaa;
  background: #f0f0f0;
}

/* Category img placeholder */
.category-img-placeholder {
  display: flex !important;
  justify-content: center;
  align-items: center;
  font-size: 40px;
  font-weight: 700;
  color: #aaa;
  background: #eee;
  width: 120px;
  height: 120px;
  border-radius: 12px;
}



.header-actions {
  display: flex;
  align-items: center;
}

#cart-toggle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cart-count {
  position: absolute;
  top: -8px;
  right: -8px;
  background-color: var(--black);
  color: var(--white);
  font-size: 10px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.header-carousel-wrapper {
  padding: 20px 0;
  overflow: hidden;
  max-height: 250px;
  transition: opacity 0.25s ease, max-height 0.3s ease, padding 0.3s ease;
  opacity: 1;
}

.header.scrolled .header-carousel-wrapper {
  opacity: 0;
  max-height: 0;
  padding: 0;
  pointer-events: none;
}

.carousel-container {
  position: relative;
  display: flex;
  align-items: center;
  max-width: 1600px; /* Mas ancho para PC */
  margin: 0 auto;
  padding: 0 20px;
}

.categories-carousel {
  display: flex;
  gap: 40px; /* Mas espacio entre items */
  overflow-x: auto;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 10px;
  width: 100%;
  justify-content: center; /* Center when items fit */
}

.categories-carousel.has-overflow {
  justify-content: flex-start; /* Start when overflow */
}

.categories-carousel::-webkit-scrollbar {
  display: none;
}

.category-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-width: 160px;
  max-width: 160px;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.category-item:hover {
  transform: translateY(-8px);
}

.category-img {
  width: 160px;
  height: 110px;
  background-color: #f5f5f5;
  border-radius: 20px;
  object-fit: cover;
  box-shadow: 0 6px 20px rgba(0,0,0,0.06);
  border: 1px solid rgba(0,0,0,0.03);
  transition: all 0.3s ease;
}

.category-item:hover .category-img {
  box-shadow: 0 12px 30px rgba(0,0,0,0.12);
  border-color: rgba(0,0,0,0.1);
}

.category-name {
  font-size: 10px;
  font-weight: 700;
  color: var(--black);
  text-transform: capitalize;
  letter-spacing: 0.2px;
  margin-top: 8px;
  line-height: 1.1;
  text-align: center;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: visible;
  height: auto;
  min-height: 2.2em;
}

.carousel-btn {
  position: absolute;
  top: 40%;
  transform: translateY(-50%);
  background: var(--white);
  border: 1px solid var(--grey-border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: all 0.2s;
  opacity: 0;
  visibility: hidden;
}

.carousel-btn.visible {
  opacity: 1;
  visibility: visible;
}

.carousel-btn:hover {
  background: var(--black);
  color: var(--white);
  border-color: var(--black);
}

.carousel-btn.prev { left: -18px; }
.carousel-btn.next { right: -18px; }

@media (max-width: 992px) {
  .header-container {
    grid-template-columns: auto 1fr auto auto;
    gap: 12px;
  }

  .header-search {
    max-width: 350px;
  }

  .search-input-wrapper input {
    padding: 8px 12px 8px 36px;
    font-size: 13px;
  }

  .search-icon {
    left: 10px;
    width: 16px;
    height: 16px;
  }
}

/* Breakpoint intermedio para pantallas estrechas (700px - 992px) */
@media (max-width: 900px) {
  .header-container {
    grid-template-columns: auto 1fr auto;
    gap: 10px;
  }

  .header-nav {
    display: none;
  }

  .header-search {
    max-width: none;
  }

  .search-input-wrapper input {
    padding: 8px 12px 8px 36px;
    font-size: 13px;
  }

  .search-icon {
    left: 10px;
    width: 16px;
    height: 16px;
  }
}

@media (max-width: 768px) {
  .header-main {
    height: auto !important;
    min-height: 56px;
    padding: 10px 0;
  }

  .header-container {
    grid-template-columns: 24px 1fr 24px;
    grid-template-areas:
      "toggle logo cart"
      "search search search";
    gap: 8px 10px;
    padding: 0 10px;
    align-items: center;
  }

  .header-logo {
    grid-area: logo;
    text-align: center;
  }

  .header-logo a {
    font-size: 20px;
  }

  .mobile-menu-toggle {
    grid-area: toggle;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    width: 24px;
    height: 18px;
    cursor: pointer;
  }

  .mobile-menu-toggle span {
    height: 2px;
  }

  .header-actions {
    grid-area: cart;
    display: flex;
    justify-content: flex-end;
    align-items: center;
  }

  .header-search {
    grid-area: search;
    display: block;
    padding: 0 0 8px 0;
    max-width: none;
  }

  .search-input-wrapper {
    display: flex;
    align-items: center;
  }

  .search-input-wrapper input {
    padding: 8px 12px 8px 32px;
    font-size: 13px;
    border-radius: 24px;
    width: 100%;
  }

  .search-icon {
    left: 12px;
    width: 16px;
    height: 16px;
  }

  #cart-toggle {
    width: 24px;
    height: 24px;
  }

  .header-nav {
    position: fixed;
    top: 0;
    left: -100%;
    width: 300px;
    height: 100vh;
    background-color: var(--white);
    z-index: 9999;
    flex-direction: column;
    padding: 0;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 10px 0 40px rgba(0,0,0,0.12);
    display: flex !important;
    overflow-y: auto;
  }

  .header-nav.active {
    left: 0;
  }

  /* Brand header */
  .nav-mobile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 18px 18px;
    border-bottom: 1px solid var(--grey-border);
  }

  .nav-mobile-brand {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .nav-mobile-logo {
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--black);
  }

  .nav-mobile-tagline {
    font-size: 11px;
    color: #aaa;
    font-weight: 500;
    letter-spacing: 0.3px;
  }

  #mobile-menu-close {
    background: #f4f4f4;
    border: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s;
  }

  #mobile-menu-close:hover {
    background: #e8e8e8;
  }

  /* Nav links */
  .header-nav > ul {
    flex-direction: column;
    gap: 0;
    width: 100%;
    padding: 8px 0;
  }

  .header-nav li {
    width: 100%;
    display: block;
    height: auto;
  }

  .header-nav li a {
    padding: 11px 18px;
    font-size: 15px;
    font-weight: 500;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 13px;
    border-bottom: 1px solid #f5f5f5;
    color: var(--black);
    transition: background 0.15s;
  }

  .header-nav li a:hover {
    background: #fafafa;
  }

  /* Link icons */
  .nav-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f4f4f4;
    border-radius: 10px;
    flex-shrink: 0;
    color: var(--black);
  }

  .nav-icon-red {
    background: #fff0f0;
    color: #d62828;
  }

  .nav-badge {
    margin-left: auto;
    background: #d62828;
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: 20px;
    letter-spacing: 0.5px;
  }

  .nav-ofertas {
    color: #d62828 !important;
    font-weight: 600 !important;
  }

  /* Featured offer banner */
  .nav-mobile-featured {
    padding: 12px 14px 28px;
    margin-top: 4px;
  }

  .nav-featured-card {
    display: block;
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    text-decoration: none;
  }

  .nav-featured-card img {
    width: 100%;
    height: 130px;
    object-fit: cover;
    display: block;
    transition: transform 0.35s ease;
  }

  .nav-featured-card:hover img {
    transform: scale(1.04);
  }

  .nav-featured-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(0,0,0,0.78) 0%, rgba(0,0,0,0.1) 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 18px;
    gap: 5px;
  }

  .nav-featured-tag {
    font-size: 9px;
    font-weight: 700;
    color: #ffcc00;
    text-transform: uppercase;
    letter-spacing: 1.5px;
  }

  .nav-featured-label {
    font-size: 16px;
    font-weight: 800;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.15;
  }

  .nav-featured-cta {
    font-size: 12px;
    font-weight: 600;
    color: rgba(255,255,255,0.8);
    margin-top: 2px;
  }

  /* Mobile nav - show these elements */
  .nav-mobile-featured {
    display: block;
    padding: 12px 14px 28px;
    margin-top: 4px;
  }

  /* Dropdown on mobile */
  .has-dropdown > a {
    justify-content: flex-start;
  }

  .has-dropdown > a > svg:last-child {
    margin-left: auto;
    transition: transform 0.25s ease;
  }

  .has-dropdown.active > a > svg:last-child {
    transform: rotate(180deg);
  }

  .dropdown-menu {
    position: static;
    opacity: 1;
    visibility: visible;
    transform: none;
    box-shadow: none;
    padding: 4px 0;
    display: none !important;
    background: #f8f8f8;
    border-radius: 0;
  }

  .dropdown-menu a {
    padding: 9px 16px;
    font-size: 14px;
    border-bottom: 1px solid #efefef;
    gap: 12px;
  }

  .dropdown-cat-img {
    width: 40px;
    height: 40px;
    border-radius: 8px;
  }

  .has-dropdown.active .dropdown-menu {
    display: block !important;
  }

  .carousel-btn {
    width: 30px;
    height: 30px;
    background: rgba(255,255,255,0.9);
  }
  .carousel-btn.prev { left: 5px; }
  .carousel-btn.next { right: 5px; }
  .categories-carousel { 
    gap: 15px;
    padding: 4px 20px;
  }
  .category-img {
    width: 85px;
    height: 85px;
  }
  .category-item {
    min-width: 85px;
  }
}

