/* ============================================================
   HEADER & TOPBAR STYLES
   segma-commerce-theme/assets/css/header.css
   ============================================================ */

/* ── TOP BAR (44px orange) ────────────────────────────────── */
.segma-topbar {
  background: var(--clr-topbar);
  color: var(--clr-white);
  height: 44px;
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
}

.topbar-inner {
  display: flex;
  align-items: center;
  height: 100%;
}

/* Phone — right side (RTL: first DOM element = right) */
.topbar-phone {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  padding: 0 4px;
}

.topbar-phone a {
  color: var(--clr-white);
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
}

.topbar-phone a:hover {
  opacity: 0.85;
}

/* Marquee — fills the center */
.topbar-marquee-wrapper {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}

.topbar-marquee {
  display: inline-flex;
  gap: 48px;
  animation: marqueeScroll 20s linear infinite;
  white-space: nowrap;
}

.marquee-item {
  font-size: 13px;
  font-weight: 600;
  opacity: 0.95;
}

@keyframes marqueeScroll {
  0% {
    transform: translateX(0);
  }

  100% {
    transform: translateX(-50%);
  }
}

/* Social icons — left side (RTL: last DOM element = left) */
.topbar-social {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
}

.social-icon {
  color: var(--clr-white);
  opacity: 0.9;
  transition: opacity var(--transition), transform var(--transition);
  display: flex;
  align-items: center;
}

.social-icon:hover {
  opacity: 1;
  transform: scale(1.15);
}

/* ── MAIN HEADER (white) ──────────────────────────────────── */
.segma-header {
  background: var(--clr-white);
  border-bottom: 1px solid var(--clr-border);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* ──────────────────────────────────────────────────────────
   DESKTOP HEADER
   RTL layout: Logo (right) | Search+Categories (center) | Cart (left)
   ────────────────────────────────────────────────────────── */
.header-inner {
  display: flex;
  align-items: center;
  height: 80px;
  gap: 16px;
}

/* Logo */
.header-logo {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  text-decoration: none;
}

.site-logo-img {
  max-height: 44px;
  width: auto;
}

.logo-fallback {
  display: flex;
  align-items: center;
}

/* Search + Categories — takes up remaining space */
.header-search-wrap {
  flex: 1;
  min-width: 0;
}

.search-categories-group {
  display: flex;
  align-items: stretch;
  border: 2px solid var(--clr-primary);
  border-radius: var(--radius-sm);
  overflow: visible;
  background: var(--clr-white);
  position: relative;
  height: 44px;
}

.header-search-form {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  height: 100%;
}

.search-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  padding: 0 12px;
  font-size: 14px;
  color: var(--clr-text);
  background: transparent;
  direction: rtl;
  height: 100%;
}

.search-input::placeholder {
  color: #bbb;
}

/* Search submit button (leftmost in RTL) */
.search-btn {
  background: var(--clr-primary);
  color: var(--clr-white);
  border: none;
  width: 46px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  transition: background var(--transition);
  flex-shrink: 0;
}

.search-btn:hover {
  background: var(--clr-primary-dark);
}

/* Category Dropdown toggle (rightmost in search bar for RTL) */
.categories-dropdown-wrap {
  flex-shrink: 0;
  position: relative;
}

.categories-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--clr-primary);
  color: var(--clr-white);
  border: none;
  padding: 0 14px;
  height: 44px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  transition: background var(--transition);
}

.categories-btn:hover {
  background: var(--clr-primary-dark);
}

.categories-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--clr-white);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  min-width: 220px;
  max-height: 380px;
  overflow-y: auto;
  z-index: 2000;
  display: none;
  padding: 6px 0;
}

.categories-dropdown.is-open {
  display: block;
}

.cat-item {
  display: block;
  padding: 9px 18px;
  color: var(--clr-text);
  font-size: 13px;
  transition: background var(--transition), color var(--transition);
}

.cat-item:hover {
  background: var(--shadow-primary-soft);
  color: var(--clr-primary);
}

/* Cart (leftmost on desktop in RTL) */
.header-cart {
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: center;
  color: var(--clr-text);
  transition: color var(--transition);
  text-decoration: none;
}

.header-cart:hover {
  color: var(--clr-primary);
}

.cart-icon-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

/* Badge — WHITE bg + orange text so it pops on both desktop AND the orange mobile button */
.cart-count {
  position: absolute;
  top: -8px;
  left: -8px;
  background: #ffffff;
  color: var(--clr-primary);
  border: 2px solid var(--clr-primary);
  font-size: 10px;
  font-weight: 800;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  line-height: 1;
  transition: transform 0.3s cubic-bezier(.34, 1.56, .64, 1);
  /* Hide when 0 */
  opacity: 1;
}

.cart-count[data-count="0"],
.cart-count:empty {
  display: none;
}

/* Bump animation on add-to-cart */
.cart-count.bump {
  transform: scale(1.5);
}

/* ────────────────────────────────────────────────────────────
   CART GENTLE WIGGLE — plays every 5s when cart has items.
   Subtle: just a soft rock, not a shake. User notices it
   without being annoyed.
   ──────────────────────────────────────────────────────────── */
@keyframes cartWiggle {
  0% {
    transform: rotate(0deg) scale(1);
  }

  15% {
    transform: rotate(-10deg) scale(1.08);
  }

  30% {
    transform: rotate(8deg) scale(1.05);
  }

  45% {
    transform: rotate(-6deg) scale(1.03);
  }

  60% {
    transform: rotate(4deg) scale(1.01);
  }

  75% {
    transform: rotate(-2deg) scale(1);
  }

  100% {
    transform: rotate(0deg) scale(1);
  }
}

/* Applied via JS when cart count > 0 */
.header-cart.has-items .cart-icon-wrap {
  animation: cartWiggle 5s ease-in-out 3s infinite;
  transform-origin: center bottom;
}

/* Pause on hover so the user can click comfortably */
.header-cart.has-items:hover .cart-icon-wrap {
  animation-play-state: paused;
}

/* Mobile toggles: hidden on desktop */
.mobile-menu-toggle,
.mobile-search-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--clr-text);
  flex-shrink: 0;
}

/* ── MOBILE SEARCH BAR (slide-down below header) ─────────── */
.mobile-search-bar {
  display: none;
  background: var(--clr-white);
  border-top: 1px solid var(--clr-border);
  padding: 10px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.mobile-search-bar.is-open {
  display: block;
}

.mobile-search-form {
  display: flex;
  align-items: center;
  border: 2px solid var(--clr-primary);
  border-radius: var(--radius-sm);
  overflow: hidden;
  height: 44px;
}

.mobile-search-form input {
  flex: 1;
  border: none;
  outline: none;
  padding: 0 12px;
  font-size: 14px;
  background: transparent;
  direction: rtl;
}

.mobile-search-form button {
  background: var(--clr-primary);
  color: #fff;
  border: none;
  width: 46px;
  height: 100%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── MOBILE CATEGORIES PANEL ─────────────────────────────── */
.mobile-categories-panel {
  display: none;
  background: var(--clr-white);
  border-top: 2px solid var(--clr-primary);
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.10);
}

.mobile-categories-panel.is-open {
  display: block;
  max-height: 70vh;
  overflow-y: auto;
}

.mobile-cats-inner {
  padding: 0;
}

.mobile-cats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--clr-border);
  font-size: 14px;
  font-weight: 700;
  color: var(--clr-text);
}

.mobile-cats-close {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--clr-text);
  display: flex;
  align-items: center;
  padding: 4px;
}

.mobile-cats-list {
  display: flex;
  flex-direction: column;
}

.mobile-cat-item {
  display: block;
  padding: 13px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--clr-text);
  border-bottom: 1px solid var(--clr-border);
  transition: background var(--transition), color var(--transition);
}

.mobile-cat-item:hover {
  background: var(--shadow-primary-soft);
  color: var(--clr-primary);
}

/* Accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── DESKTOP ONLY — hide mobile elements ─────────────────── */
@media (min-width: 769px) {
  .mobile-menu-toggle {
    display: none !important;
  }

  .mobile-search-toggle {
    display: none !important;
  }

  .mobile-search-bar {
    display: none !important;
  }

  .mobile-categories-panel {
    display: none !important;
  }
}

/* ── MOBILE (≤768px) ──────────────────────────────────────── */
@media (max-width: 768px) {

  /* Topbar: show only marquee, centered */
  .topbar-phone {
    display: none !important;
  }

  .topbar-social {
    display: none !important;
  }

  .topbar-marquee-wrapper {
    width: 100%;
    justify-content: center;
    flex: 1;
  }

  /* ────────────────────────────────────────────────────────
     White header mobile layout (RTL):
     RIGHT side: Logo
     LEFT side:  [☰ Menu] [🛒 Cart] [🔍 Search]
     The three buttons are pushed to the left via margin trick.
     ──────────────────────────────────────────────────────── */
  .header-inner {
    height: 62px;
    padding: 0 12px;
    gap: 8px;
    justify-content: flex-start;
    /* items start from the RIGHT in RTL */
  }

  /* Logo stays on the FAR RIGHT (flex-start = right in RTL) */
  .header-logo {
    order: 1;
    flex-shrink: 0;
  }

  /* Hide desktop search bar completely */
  .header-search-wrap {
    display: none !important;
  }

  /* ── PUSH BUTTONS TO THE LEFT ────────────────────────────
     In RTL flex-direction:row, adding margin-left:auto on the
     first button absorbs all remaining space, pushing that
     button and all subsequent buttons to the LEFT end.
     ──────────────────────────────────────────────────────── */

  /* Search icon — first mobile button (pushed left via margin) */
  .mobile-search-toggle {
    order: 2;
    display: flex !important;
    background: var(--clr-primary);
    color: var(--clr-white);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    flex-shrink: 0;
    margin-left: auto;
    /* KEY: pushes this + following items to the LEFT */
  }

  /* Cart */
  .header-cart {
    order: 3;
    background: var(--clr-primary);
    color: var(--clr-white);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex !important;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .header-cart:hover {
    color: var(--clr-white);
    opacity: 0.88;
  }

  .cart-count {
    top: -5px;
    left: -5px;
  }

  /* Hamburger menu — leftmost */
  .mobile-menu-toggle {
    order: 4;
    display: flex !important;
    background: transparent;
    border: 1.5px solid #ccc;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    color: var(--clr-text);
    flex-shrink: 0;
  }
}

/* ── HEADER NAV (optional) ────────────────────────────────── */
.header-nav {
  display: flex;
  align-items: center;
  gap: 20px;
  list-style: none;
}

.header-nav a {
  font-size: 14px;
  font-weight: 600;
  color: var(--clr-text);
  transition: color var(--transition);
}

.header-nav a:hover {
  color: var(--clr-primary);
}

/* Shopingo French/LTR overrides */
body.segma-preset-shopingo .header-inner { flex-direction: row; }
body.segma-preset-shopingo .search-input,
body.segma-preset-shopingo .mobile-search-form input { direction: ltr; text-align: left; }
body.segma-preset-shopingo .search-btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
body.segma-preset-shopingo .categories-btn { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
body.segma-preset-shopingo .categories-dropdown { left: 0; right: auto; text-align: left; }
body.segma-preset-shopingo .cart-count { right: -8px; left: auto; }
body.segma-preset-shopingo .cat-item:hover,
body.segma-preset-shopingo .mobile-cat-item:hover { background: var(--shadow-primary-soft); }
