/* ==========================================================================
   WooGrub — header.css
   Main site header: layout, logo, navigation.
   ========================================================================== */

/* ── Header shell ────────────────────────────────────────────────────────── */
/* Defined on :root so elements outside .wg-header (e.g. the nav scrim, which
   is a direct child of <body>) can also resolve it. */
:root {
  --wg-header-height: 64px;
}

@media (max-width: 767px) {
  :root {
    --wg-header-height: 56px;
  }
}

.wg-header {
  position: relative;
  z-index: var(--wg-z-header);
  background-color: var(--wg-surface);
  border-bottom: 1px solid var(--wg-border);
  box-shadow: var(--wg-shadow-sm);
  width: 100%; /* full-width background */

  height: var(--wg-header-height);
}

/* Full-width background, constrained inner content */
.wg-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--wg-space-4);
  height: 100%;
  max-width: 1100px;
  margin-inline: auto;
  padding-inline: var(--wg-space-4);
}

@media (min-width: 640px) {
  .wg-header__inner {
    padding-inline: var(--wg-space-6);
  }
}

@media (min-width: 1024px) {
  .wg-header__inner {
    padding-inline: var(--wg-space-8);
  }
}

/* ── Logo ────────────────────────────────────────────────────────────────── */
.wg-header__logo {
  display: flex;
  align-items: center;
  gap: var(--wg-space-3);
  flex-shrink: 0;
  text-decoration: none;
}

/* Logo image rendered via wg_render_header() — plugin-uploaded image is
   higher resolution (reused elsewhere), so scale it down to fit the header */
.wg-header__logo-img {
  display: block;
  height: 40px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
}

@media (max-width: 767px) {
  .wg-header__logo-img {
    height: 32px;
  }
}

/* WordPress site-title block — shown when no logo image is set */
.wg-header__site-title {
  font-family: var(--wg-font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--wg-text);
  text-decoration: none;
  white-space: nowrap;
}

.wg-header__site-title a {
  color: inherit;
  text-decoration: none;
}

.wg-header__site-title a:hover {
  color: var(--wg-primary);
}

/* ── Primary navigation ──────────────────────────────────────────────────── */
.wg-header__nav {
  flex: 1;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.wg-header__nav-list {
  display: flex;
  align-items: center;
  gap: var(--wg-space-1);
  list-style: none;
  margin: 0;
  padding: 0;
}

.wg-header__nav-list li a {
  display: block;
  padding: var(--wg-space-2) var(--wg-space-3);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--wg-text);
  text-decoration: none;
  border-radius: var(--wg-radius-sm);
  transition: background-color var(--wg-transition), color var(--wg-transition);
  white-space: nowrap;
}

@media (hover: hover) {
  .wg-header__nav-list li a:hover {
    background-color: var(--wg-bg);
    color: var(--wg-primary);
  }
}

.wg-header__nav-list li.current-menu-item a {
  color: var(--wg-primary);
  font-weight: 600;
}


/* ── Hamburger toggle (hidden on desktop) ───────────────────────────────── */
.wg-nav-toggle {
  display: none;
}

/* ── Nav scrim: always out of layout flow ────────────────────────────────────
   The scrim is a fixed overlay that only becomes visible behind the open
   mobile drawer. It must be position:fixed on ALL viewports — not just inside
   the mobile media query — so it never counts as an in-flow child of the
   body grid (grid-template-rows: auto 1fr auto). On desktop, an in-flow scrim
   would occupy a phantom grid row and stretch the layout. The mobile media
   query below adds the visible offset/background; this base rule only removes
   it from flow. */
.wg-nav-scrim {
  position: fixed;
  inset: 0;
  z-index: 150;
  opacity: 0;
  pointer-events: none;
}

/* ── Mobile: slide-out drawer ───────────────────────────────────────────── */
@media (max-width: 767px) {

  /* Hamburger button — sits at the right of the header */
  .wg-nav-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    padding: 0;
    background: none;
    border: none;
    border-radius: var(--wg-radius-sm);
    color: var(--wg-text);
    cursor: pointer;
    transition: background-color var(--wg-transition);
  }

  @media (hover: hover) {
    .wg-nav-toggle:hover {
      background-color: var(--wg-bg);
    }
  }

  /* Three-bar icon — morphs into an X when the drawer is open */
  .wg-nav-toggle__bars {
    position: relative;
    display: block;
    width: 22px;
    height: 16px;
  }

  .wg-nav-toggle__bar {
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    border-radius: 2px;
    background-color: currentColor;
    transition:
      transform var(--wg-transition),
      opacity var(--wg-transition),
      top var(--wg-transition);
  }

  .wg-nav-toggle__bar:nth-child(1) { top: 0; }
  .wg-nav-toggle__bar:nth-child(2) { top: 7px; }
  .wg-nav-toggle__bar:nth-child(3) { top: 14px; }

  /* Open state → X */
  .wg-nav-toggle[aria-expanded="true"] .wg-nav-toggle__bar:nth-child(1) {
    top: 7px;
    transform: rotate(45deg);
  }
  .wg-nav-toggle[aria-expanded="true"] .wg-nav-toggle__bar:nth-child(2) {
    opacity: 0;
  }
  .wg-nav-toggle[aria-expanded="true"] .wg-nav-toggle__bar:nth-child(3) {
    top: 7px;
    transform: rotate(-45deg);
  }

  /* Drawer panel — slides in from the right, below the header */
  .wg-header__nav {
    /* Offset from the top of the viewport: closed-banner height (0 when
       absent) + header height, plus the WP admin bar when present
       (see body.admin-bar override below). */
    --wg-drawer-top: calc(var(--wg-banner-height, 0px) + var(--wg-header-height));

    position: fixed;
    top: var(--wg-drawer-top);
    right: 0;
    bottom: 0;
    z-index: var(--wg-z-cart);   /* above scrim, below product modal */
    width: min(320px, 80vw);
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0;
    padding: var(--wg-space-4);
    background-color: var(--wg-surface);
    border-left: 1px solid var(--wg-border);
    box-shadow: var(--wg-shadow-lg);
    transform: translateX(100%);
    transition: transform var(--wg-transition);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  /* Push the drawer below the admin bar for logged-in users */
  body.admin-bar .wg-header__nav {
    --wg-drawer-top: calc(var(--wg-banner-height, 0px) + var(--wg-header-height) + 46px);
  }

  .wg-header__nav.is-open {
    transform: translateX(0);
  }

  /* Stacked nav links inside the drawer, separated by dividers */
  .wg-header__nav-list {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: 100%;
  }

  .wg-header__nav-list li + li {
    border-top: 1px solid var(--wg-border);
  }

  .wg-header__nav-list li a {
    padding: var(--wg-space-3) var(--wg-space-2);
    font-size: 1.0625rem;
    border-radius: 0;
  }

  /* Scrim — dims the page behind the open drawer, below the header.
     Uses pointer-events (not visibility) to control click-through, matching
     the established .wg-overlay pattern.

     z-index note: the drawer lives inside .wg-header, which establishes its
     own stacking context at --wg-z-header (200). The drawer's own z-index is
     therefore clamped relative to the header, so the scrim must sit BELOW the
     header context (not below the drawer's nominal z-index) to render beneath
     the drawer. 150 is above all page content (category nav at 100, cards with
     no z-index) but below the header at 200. */
  .wg-nav-scrim {
    --wg-scrim-top: calc(var(--wg-banner-height, 0px) + var(--wg-header-height));

    position: fixed;
    top: var(--wg-scrim-top);
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 150;
    background-color: rgba(0, 0, 0, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--wg-transition);
  }

  body.admin-bar .wg-nav-scrim {
    --wg-scrim-top: calc(var(--wg-banner-height, 0px) + var(--wg-header-height) + 46px);
  }

  .wg-nav-scrim.is-open {
    opacity: 1;
    pointer-events: auto;
  }
}

/* ── Dark mode overrides ─────────────────────────────────────────────────── */
[data-theme="dark"] .wg-header {
  background-color: var(--wg-surface);
  border-bottom-color: var(--wg-border);
  box-shadow: 0 1px 0 var(--wg-border);
}
