/* Header CSS */
:root {
  --green: #8da731;
  --green-dark: #6d7a25;
  --black: #111111;
  --gray: #f5f5f5;
  --border-soft: #e5e5e5;
  --transition: 0.25s ease;
}

* {
  font-family: "Kanit", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Header */
header {
  position: sticky;
  top: 0;
  z-index: 9998;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
  width: 100%;
  box-sizing: border-box;
}

.nav {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  position: relative;
  width: 100%;
  box-sizing: border-box;
  isolation: isolate;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  z-index: 10001;
  position: relative;
}

.logo-icon {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  border: 2px solid var(--black);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.logo-text span:first-child {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.06em;
}

.logo-text span:last-child {
  font-size: 10px;
  color: #666;
  text-transform: uppercase;
}

.nav-menu {
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 14px;
}

.nav-menu a {
  padding: 8px 14px;
  border-radius: 999px;
  color: #333;
  transition: var(--transition);
  font-weight: 400;
  text-decoration: none;
}

.nav-menu a:hover {
  background: var(--gray);
  color: var(--black);
}

.nav-cta {
  padding: 8px 18px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--border-soft);
  color: var(--black);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition);
  text-decoration: none;
}

.nav-cta span.icon {
  font-size: 14px;
}

.nav-cta:hover {
  background: var(--gray);
  border-color: var(--green);
  color: var(--black);
}

/* Dropdown Menu */
.nav-dropdown {
  position: relative;
}

.nav-dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  border-radius: 999px;
  color: #333;
  transition: var(--transition);
  font-weight: 400;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}

.nav-dropdown-toggle::after {
  content: '▼';
  font-size: 8px;
  transition: transform var(--transition);
}

.nav-dropdown:hover .nav-dropdown-toggle {
  background: var(--gray);
  color: var(--black);
}

.nav-dropdown:hover .nav-dropdown-toggle::after {
  transform: rotate(180deg);
}

.nav-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 8px;
  /* Restore visual gap */
  min-width: 180px;
  background: #fff;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all var(--transition);
  z-index: 100;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Invisible bridge to prevent menu from closing when moving mouse over the gap */
.nav-dropdown-menu::before {
  content: '';
  position: absolute;
  top: -12px;
  left: 0;
  width: 100%;
  height: 12px;
  background: transparent;
}

.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown.active .nav-dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.nav-dropdown-menu a {
  padding: 8px 12px;
  border-radius: 8px;
  color: #333;
  font-size: 13px;
  transition: var(--transition);
  display: block;
  text-decoration: none;
}

.nav-dropdown-menu a:hover {
  background: var(--gray);
  color: var(--black);
}

/* Cart Button */
#cartTotal {
  margin-left: 4px;
  font-size: 11px;
  opacity: 0.9;
  font-weight: 600;
}

.nav-cta {
  position: relative;
}

/* Mobile Menu Toggle Button */
.mobile-menu-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px;
  justify-content: center;
  align-items: center;
  z-index: 10001;
  position: relative;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  flex-shrink: 0;
}

.mobile-menu-toggle span {
  width: 20px;
  height: 2px;
  background: var(--black);
  border-radius: 2px;
  transition: var(--transition);
}

.mobile-menu-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(6px, 6px);
}

.mobile-menu-toggle.active span:nth-child(2) {
  opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(6px, -6px);
}

/* Mobile Menu Overlay */
.mobile-menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.mobile-menu-overlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.mobile-menu {
  position: fixed;
  top: 0;
  right: -100%;
  width: 280px;
  max-width: 85%;
  height: 100vh;
  background: #fff;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 10000;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  will-change: right;
}

.mobile-menu-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border: none;
  background: transparent;
  font-size: 32px;
  color: var(--black);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10002;
  padding: 0;
  line-height: 1;
  transition: var(--transition);
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(141, 167, 49, 0.2);
  user-select: none;
  -webkit-user-select: none;
}

.mobile-menu-close:hover {
  color: var(--green);
  transform: scale(1.1);
  background: var(--gray);
  border-radius: 50%;
}


.mobile-menu-overlay.active .mobile-menu {
  right: 0;
}

.mobile-menu>.mobile-menu-link:first-of-type {
  margin-top: 60px;
}

.mobile-menu-link {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  border-radius: 8px;
  color: var(--black);
  font-size: 15px;
  font-weight: 400;
  text-decoration: none;
  transition: var(--transition);
  margin: 2px 12px;
  width: calc(100% - 24px);
  box-sizing: border-box;
}

.mobile-menu-link:hover {
  background: var(--gray);
  color: var(--black);
}

.mobile-menu-cta {
  margin-top: 8px;
  margin-bottom: 12px;
  background: var(--gray);
  border: 1px solid var(--border-soft);
  font-weight: 500;
  justify-content: center;
}

.mobile-menu-cta:hover {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.mobile-menu-dropdown {
  margin: 2px 12px;
  width: calc(100% - 24px);
  box-sizing: border-box;
}

.mobile-menu-toggle-dropdown {
  justify-content: space-between;
}

.mobile-menu-toggle-dropdown span {
  font-size: 10px;
  transition: transform var(--transition);
}

.mobile-menu-dropdown.active .mobile-menu-toggle-dropdown span {
  transform: rotate(180deg);
}

.mobile-menu-dropdown-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  margin: 0;
  padding: 0;
}

.mobile-menu-dropdown-content .mobile-menu-link {
  margin: 2px 0;
  padding-left: 36px;
  font-size: 14px;
  width: 100%;
}

.mobile-menu-dropdown.active .mobile-menu-dropdown-content {
  max-height: 500px;
  padding-top: 4px;
  padding-bottom: 4px;
}

/* Responsive */
@media (max-width: 768px) {
  .nav-menu {
    display: none !important;
  }

  .mobile-menu-toggle {
    display: flex !important;
  }

  header {
    z-index: 9998;
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    box-sizing: border-box;
  }

  .nav {
    justify-content: space-between;
    position: relative;
    z-index: 9998;
    padding: 12px 16px;
    gap: 16px;
    width: 100%;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
  }

  .logo {
    z-index: 9999;
    position: relative;
    flex-shrink: 0;
    pointer-events: auto;
    isolation: isolate;
  }

  .logo img {
    max-height: 36px;
    width: auto;
    display: block;
  }

  .mobile-menu-toggle {
    z-index: 10000;
    position: relative;
    flex-shrink: 0;
    pointer-events: auto;
    isolation: isolate;
  }

  /* Mobile menu overlay should be outside nav's stacking context */
  .mobile-menu-overlay {
    z-index: 10001;
    position: fixed !important;
  }

  .mobile-menu {
    z-index: 10002;
  }

  .mobile-menu-close {
    z-index: 10003;
  }

  /* Prevent body scroll when menu is open */
  body.menu-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
    touch-action: none;
  }

  /* Ensure header doesn't overlap content */
  main {
    position: relative;
    z-index: 1;
  }

  /* Prevent touch scrolling issues */
  .mobile-menu-overlay.active {
    touch-action: none;
  }

  .mobile-menu {
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }

  /* Ensure mobile menu overlay covers everything when active */
  .mobile-menu-overlay.active {
    z-index: 10001;
  }

  .mobile-menu-overlay.active .mobile-menu {
    z-index: 10002;
  }

  .mobile-menu-overlay.active .mobile-menu-close {
    z-index: 10003;
  }

  /* Ensure nav items don't overlap */
  .nav>.logo {
    z-index: 9999;
    position: relative;
  }

  .nav>.mobile-menu-toggle {
    z-index: 10000;
    position: relative;
  }

  /* Mobile menu overlay is positioned fixed, so it's outside nav's stacking context */
  .nav>.mobile-menu-overlay {
    position: fixed !important;
    z-index: 10001 !important;
  }

  /* When menu is open, toggle should be clickable above overlay */
  .mobile-menu-toggle.active {
    z-index: 10005 !important;
    position: relative;
  }
}