/*
 * ShopApni Header Styles — sa-header.css
 * Place in: /wp-content/themes/YOUR-CHILD-THEME/sa-header.css
 * Enqueue via functions.php (see header.php for snippet)
 */

/* ─── Reset & base ─── */
.sa-header *,
.sa-header *::before,
.sa-header *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ─── Root vars (reuse your page vars if already defined globally) ─── */
.sa-header {
  --sa-green:       #80BB01;
  --sa-green-dark:  #5d8a00;
  --sa-green-deep:  #1a2e05;
  --sa-green-light: rgba(128,187,1,0.12);
  --sa-white:       #ffffff;
  font-family: 'Outfit', sans-serif;
}

/* ─── Scrolling offer bar ─── */
.sa-marquee-bar {
  width: 100%;
  overflow: hidden;
  background: var(--sa-green-deep);
  padding: 6px 0;
  white-space: nowrap;
}

.sa-marquee-track {
  display: inline-flex;
  align-items: center;
  width: max-content;
  animation: sa-marquee-scroll 22s linear infinite;
}

/* Pause so people can actually read it — hover on desktop, touch-hold on mobile */
.sa-marquee-bar:hover .sa-marquee-track,
.sa-marquee-track:active {
  animation-play-state: paused;
}

.sa-marquee-item {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--sa-white);
  padding: 0 6px;
}

.sa-marquee-sep {
  color: var(--sa-white);
  opacity: 0.5;
  padding: 0 6px;
}

.sa-marquee-sep:last-child { display: none; }

@keyframes sa-marquee-scroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); } /* messages are duplicated 2x in HTML, so -50% = one full loop */
}

/* Respect users who've asked for less motion */
@media (prefers-reduced-motion: reduce) {
  .sa-marquee-track {
    animation: none;
    overflow-x: auto;
  }
}

.sa-header {
  position: sticky;
  top: 0;
  z-index: 9999;
  background: var(--sa-green-deep);
  /* Break out to true viewport width regardless of any parent theme
     margin/padding. position:fixed used to do this for free via
     left:0/right:0; sticky doesn't — those properties only control
     *when* it sticks, not its width, since sticky stays in normal flow. */
  width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
}

/* No body padding-top needed anymore — sticky headers occupy their own
   space in normal document flow, so content can never render underneath
   them. This removes the entire class of offset-mismatch bugs that came
   from trying to keep a fixed header's height in sync with a manual
   push-down value (whether hardcoded or JS-measured).

   Explicitly zeroed (not just omitted) because the parent GreenFarm theme
   likely has its own body padding-top written for its native header —
   our old fixed-header offset rule used to override that by cascade order;
   deleting it silently would've re-exposed the parent's leftover value. */
body {
  padding-top: 0 !important;
  margin-top: 0 !important;
}

/* ─── Top info bar ─── */
.sa-top-bar {
  background: var(--sa-green);
  padding: 5px 5%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--sa-green-deep);
  font-weight: 500;
  gap: 1rem;
}
.sa-top-bar a {
  color: var(--sa-green-deep);
  font-weight: 600;
  text-decoration: none;
}
.sa-top-bar a:hover { text-decoration: underline; }
@media (max-width: 700px) {
  .sa-top-bar__left { display: none; }
  .sa-top-bar { justify-content: flex-end; }
}
@media (max-width: 900px) {
  /* Login/account access now lives in the account icon in the main row —
     no need for a whole separate bar just for one link */
  .sa-top-bar { display: none !important; }
}

/* ─── Main row ─── */
.sa-main-row {
  padding: 10px 5%;
  display: flex;
  align-items: center;
  gap: 16px;
}

/* ─── Logo ─── */
.sa-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  text-decoration: none;
}
.sa-logo__img {
  height: 48px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
  border-radius: 8px;
}
.sa-logo__fallback {
  width: 48px; height: 48px;
  border-radius: 10px;
  background: var(--sa-green);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
  color: var(--sa-green-deep);
}
.sa-logo__text { display: flex; flex-direction: column; line-height: 1.2; }
.sa-logo__name {
  font-family: 'Fraunces', serif;
  font-size: 1.35rem;
  font-weight: 500;
  color: var(--sa-green);
}
.sa-logo__name em { font-style: normal; color: var(--sa-white); }
.sa-logo__sub {
  font-size: 10px;
  color: rgba(255,255,255,0.38);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ─── Search ─── */
.sa-search-wrap {
  flex: 1;
  max-width: 520px;
}
/* Override WooCommerce default search form */
.sa-search-wrap form {
  display: flex;
  position: relative;
  margin: 0;
}
.sa-search-wrap input[type="search"] {
  width: 100% !important;
  background: rgba(255,255,255,0.08) !important;
  border: 1px solid rgba(128,187,1,0.25) !important;
  border-radius: 40px !important;
  padding: 10px 48px 10px 18px !important;
  font-size: 14px !important;
  font-family: 'Outfit', sans-serif !important;
  color: #fff !important;
  outline: none !important;
  box-shadow: none !important;
  height: auto !important;
}
.sa-search-wrap input[type="search"]::placeholder { color: rgba(255,255,255,0.35); }
.sa-search-wrap input[type="search"]:focus {
  border-color: rgba(128,187,1,0.5) !important;
}
.sa-search-wrap button[type="submit"],
.sa-search-wrap input[type="submit"] {
  position: absolute !important;
  right: 6px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  background: var(--sa-green) !important;
  border: none !important;
  border-radius: 40px !important;
  width: 34px !important; height: 34px !important;
  min-width: 0 !important;
  padding: 0 !important;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--sa-green-deep) !important;
  font-size: 0;
}
/* Search icon via pseudo */
.sa-search-wrap button[type="submit"]::after,
.sa-search-wrap input[type="submit"]::after {
  content: '';
  display: block;
  width: 14px; height: 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%231a2e05' stroke-width='2.5'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: contain;
}

/* ─── Header actions ─── */
.sa-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.sa-phone-chip {
  display: flex; align-items: center; gap: 7px;
  background: rgba(128,187,1,0.1);
  border: 1px solid rgba(128,187,1,0.22);
  border-radius: 40px;
  padding: 8px 14px;
  color: rgba(255,255,255,0.8);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.2s;
}
.sa-phone-chip svg { color: var(--sa-green); flex-shrink: 0; }
.sa-phone-chip:hover { background: rgba(128,187,1,0.18); color: #fff; }

.sa-icon-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  transition: all 0.2s;
  position: relative;
  cursor: pointer;
}
.sa-icon-btn:hover {
  background: rgba(128,187,1,0.12);
  border-color: rgba(128,187,1,0.3);
  color: var(--sa-green);
}

/* WhatsApp chat button: icon only, opens a chat (not a calling number) */
.sa-icon-btn.sa-wa-btn { color: #25D366; }
.sa-icon-btn.sa-wa-btn:hover { color: #25D366; background: rgba(37,211,102,0.12); border-color: rgba(37,211,102,0.35); }

/* Desktop shows the search input directly — the toggle icon is mobile-only */
.sa-search-toggle {
  display: none;
  border: none;
  padding: 0;
}
.sa-cart-count {
  position: absolute;
  top: -6px; right: -6px;
  background: var(--sa-green);
  color: var(--sa-green-deep);
  font-size: 10px;
  font-weight: 700;
  border-radius: 40px;
  min-width: 17px; height: 17px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
  line-height: 1;
}
.sa-cart-count:empty,
.sa-cart-count[data-count="0"] { display: none; }

/* ─── Hamburger ─── */
.sa-hamburger {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  cursor: pointer;
  padding: 0;
}
.sa-hamburger span {
  display: block;
  width: 18px; height: 2px;
  background: rgba(255,255,255,0.75);
  border-radius: 2px;
  transition: all 0.25s;
  pointer-events: none;
}
.sa-hamburger--open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.sa-hamburger--open span:nth-child(2) { opacity: 0; }
.sa-hamburger--open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ─── Nav row ─── */
.sa-nav {
  background: rgba(0,0,0,0.28);
  border-top: 1px solid rgba(128,187,1,0.12);
  padding: 0 5%;
  display: flex;
  align-items: center;
}
.sa-nav__list {
  display: flex;
  list-style: none;
  margin: 0; padding: 0;
  align-items: center;
  flex-wrap: nowrap;
  overflow: visible; /* was overflow-x:auto — clips absolute dropdowns */
}
.sa-nav__list li a,
.sa-nav__list li > span {
  display: block;
  color: rgba(255,255,255,0.6);
  font-size: 13.5px;
  font-weight: 400;
  padding: 11px 16px;
  border-bottom: 2px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.2s, border-color 0.2s;
}
.sa-nav__list li a:hover,
.sa-nav__list li.current-menu-item > a,
.sa-nav__list li.current-page-ancestor > a {
  color: var(--sa-green);
  border-bottom-color: var(--sa-green);
}
/* Dropdown indicator */
.sa-nav__list .menu-item-has-children > a::after {
  content: ' ▾';
  font-size: 10px;
  opacity: 0.6;
}
/* Basic dropdown */
.sa-nav__list .sub-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: #1a2e05;
  border: 1px solid rgba(128,187,1,0.2);
  border-radius: 10px;
  min-width: 200px;
  padding: 6px 0;
  list-style: none;
  z-index: 10000; /* must exceed header z-index of 9999 */
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}
.sa-nav__list .menu-item-has-children {
  position: relative;
}
.sa-nav__list .menu-item-has-children:hover > .sub-menu { display: block; }
.sa-nav__list .sub-menu li a {
  padding: 9px 18px;
  border-bottom: none;
  font-size: 13px;
  color: rgba(255,255,255,0.65);
}
.sa-nav__list .sub-menu li a:hover { color: var(--sa-green); background: rgba(128,187,1,0.07); }

/* CTA button in nav */
.sa-nav__cta {
  margin-left: auto;
  flex-shrink: 0;
  background: var(--sa-green);
  color: var(--sa-green-deep) !important;
  padding: 7px 18px;
  border-radius: 40px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.2s;
}
.sa-nav__cta:hover { background: #95d000; }

/* ─── Responsive ─── */
@media (max-width: 900px) {

  /* Hide phone chip, show hamburger */
  .sa-phone-chip { display: none !important; }

  .sa-hamburger {
    display: flex !important;
    flex-direction: column;
    gap: 5px;
    align-items: center;
    justify-content: center;
  }

  /* Nav: hidden by default, revealed on toggle */
  .sa-nav {
    display: none !important;
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 0.5rem 5% 1rem !important;
    background: var(--sa-green-deep) !important;
    border-top: 1px solid rgba(128,187,1,0.15) !important;
  }

  .sa-nav.sa-nav--open {
    display: flex !important;
  }

  /* Nav list: vertical stack */
  .sa-nav__list {
    flex-direction: column !important;
    align-items: stretch !important;
    overflow-x: visible !important;
    width: 100% !important;
  }

  .sa-nav__list li {
    width: 100% !important;
    background: transparent !important;
  }

  .sa-nav__list li a {
    display: block !important;
    padding: 12px 4px !important;
    font-size: 15px !important;
    font-weight: 500 !important;
    color: rgba(255,255,255,0.85) !important;
    border-bottom: none !important;
    border-top: 1px solid rgba(255,255,255,0.07) !important;
    background: transparent !important;
    background-image: none !important;
    border-radius: 0 !important;
  }

  .sa-nav__list li:first-child > a {
    border-top: none !important;
  }

  .sa-nav__list li a:hover,
  .sa-nav__list li a:active {
    color: var(--sa-green) !important;
    background: rgba(128,187,1,0.08) !important;
    padding-left: 10px !important;
    transition: all 0.2s;
  }

  /* Sub-menus: collapsed by default, expanded via JS accordion toggle */
  .sa-nav__list .sub-menu {
    display: none;
    position: static !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    background: rgba(255,255,255,0.04) !important;
    padding: 0 0 0 16px !important;
    min-width: 0 !important;
    width: 100% !important;
    z-index: auto !important;
  }
  .sa-nav__list .sub-menu.sub-menu--open {
    display: block !important;
  }
  .sa-nav__list .sub-menu li a {
    font-size: 13.5px !important;
    padding: 10px 8px !important;
    color: rgba(255,255,255,0.65) !important;
    border-top: 1px solid rgba(255,255,255,0.05) !important;
  }
  /* Rotate chevron arrow when submenu is open */
  .sa-nav__list .menu-item-has-children.submenu-open > a::after {
    display: inline-block;
    transform: rotate(180deg);
  }

  /* CTA button */
  .sa-nav__cta {
    display: block !important;
    margin: 14px 0 0 !important;
    text-align: center !important;
    padding: 13px !important;
    font-size: 14px !important;
    border-radius: 40px !important;
    background: var(--sa-green) !important;
    color: var(--sa-green-deep) !important;
    font-weight: 600 !important;
  }
}

@media (max-width: 900px) {

  .sa-main-row {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 10px !important;
    padding: 8px 4% !important;
    position: relative !important; /* anchors the search dropdown below */
  }

  .sa-logo {
    flex-shrink: 1 !important;
    min-width: 0 !important;
  }

  .sa-header-actions {
    flex-shrink: 0 !important;
    gap: 6px !important;
  }

  .sa-search-toggle {
    display: flex !important;
  }

  /* Collapsed by default on mobile — no permanent row, no wasted height */
  .sa-search-wrap {
    display: none;
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    right: 0 !important;
    max-width: none !important;
    padding: 8px 4% 12px !important;
    background: var(--sa-green-deep);
    box-shadow: 0 8px 16px rgba(0,0,0,0.25);
    z-index: 20;
  }

  .sa-search-wrap.sa-search-wrap--open {
    display: block;
    animation: sa-search-drop 0.18s ease-out;
  }

  @keyframes sa-search-drop {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  .sa-logo__sub { display: none !important; }
  .sa-logo__name { font-size: 1.15rem !important; }
  .sa-logo__img { max-width: 110px !important; }

  /* Defense-in-depth: even if the action row gets crowded again later,
     the logo truncates instead of overflowing/overlapping siblings. */
  .sa-logo {
    overflow: hidden !important;
  }
  .sa-logo__text {
    overflow: hidden !important;
    min-width: 0 !important;
  }
  .sa-logo__name {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: inline-block !important;
    max-width: 100% !important;
  }

  /* Bottom nav duplicates BOTH account and cart — but account matters
     more than cart in the header itself, so cart is the one that goes. */
  .sa-icon-btn.sa-cart-btn {
    display: none !important;
  }

  .sa-icon-btn.sa-wa-btn,
  .sa-icon-btn.sa-account-btn,
  .sa-icon-btn.sa-search-toggle {
    display: flex !important;
  }

  .sa-hamburger {
    display: flex !important;
  }
}

/* ─── Kill old theme nav backgrounds (top-level only, preserve sub-menu bg) ─── */
#sa-nav .sa-nav__list,
#sa-nav ul.menu {
  background: transparent !important;
  background-image: none !important;
  background-color: transparent !important;
}
/* Top-level <li> only — NOT .sub-menu li */
.sa-nav__list > li {
  background: transparent !important;
  background-image: none !important;
  background-color: transparent !important;
}

/* Remove any gradient or colored box from top-level nav links */
.sa-nav__list > li > a,
.sa-nav__list > li > span {
  background: transparent !important;
  background-image: none !important;
  border-radius: 0 !important;
}

/* ─── Final nav background cleanup ─── */
.sa-nav {
  background: var(--sa-green-deep) !important;
  backdrop-filter: none !important;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  overflow: visible !important; /* must be visible or dropdowns get clipped */
}

/* Top-level links only */
.sa-nav__list > li > a {
  background: transparent !important;
  color: rgba(255,255,255,0.85);
}

.sa-nav__list > li > a:hover {
  background: rgba(128,187,1,0.15) !important;
  color: var(--sa-green);
}

/* Sub-menu link overrides — keep these separate */
.sa-nav__list .sub-menu li a {
  background: transparent !important;
  color: rgba(255,255,255,0.65);
}
.sa-nav__list .sub-menu li a:hover {
  color: var(--sa-green) !important;
  background: rgba(128,187,1,0.10) !important;
}
/* ─── Mobile submenu chevron toggle button ─── */
.sa-submenu-toggle {
  display: none; /* hidden on desktop */
}
@media (max-width: 900px) {
  /* Wrap the li in relative so we can position the button */
  .sa-nav__list .menu-item-has-children {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
  }
  /* Parent link takes most of the row */
  .sa-nav__list .menu-item-has-children > a {
    flex: 1 !important;
  }
  /* Sub-menu spans full width below */
  .sa-nav__list .menu-item-has-children > .sub-menu {
    flex: 0 0 100% !important;
    width: 100% !important;
  }
  /* Chevron button */
  .sa-submenu-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    flex-shrink: 0;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    transition: background 0.2s, color 0.2s, transform 0.25s;
    margin-right: 4px;
  }
  .sa-submenu-toggle:hover {
    background: rgba(128,187,1,0.15);
    color: var(--sa-green);
  }
  /* Rotate chevron when open */
  .menu-item-has-children.submenu-open > .sa-submenu-toggle {
    transform: rotate(180deg);
    color: var(--sa-green);
    background: rgba(128,187,1,0.12);
  }
  /* Remove the old CSS ::after arrow on parent links — button replaces it */
  .sa-nav__list .menu-item-has-children > a::after {
    display: none !important;
  }
}

/* FarmCoins chip base style */
.sa-farmcoin-chip {
  margin-left: 10px;
  background: #80bb01; /* ShopApni brand green */
  color: #fff;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}

/* Ensure chip stays visible in mobile header */
@media (max-width: 900px) {
  .sa-header-actions {
    display: flex !important;
    flex-wrap: nowrap !important;
    justify-content: flex-end !important;
    align-items: center !important;
    gap: 6px !important;
  }

  /* Force chip visible even if phone-chip hidden */
  .sa-farmcoin-chip {
    display: inline-flex !important;   /* override any hidden rule */
    flex-shrink: 0 !important;         /* prevent shrinking */
    font-size: 13px !important;
    padding: 3px 8px !important;
    margin-left: 6px !important;
    background: #80bb01 !important;
    color: #fff !important;
    border-radius: 20px !important;
    font-weight: 600 !important;
    line-height: 1 !important;
  }

  .sa-header-actions .sa-farmcoin-chip {
    order: 99 !important; /* keep after cart */
  }

  /* Coin icon + number only on mobile — the "FarmCoins" word was the
     single biggest space cost in the action row, and was forcing the
     logo to shrink down to a couple of truncated characters. */
  .sa-farmcoin-label {
    display: none !important;
  }
}
