/*
 * TherapyBuilt — header.css
 * Site header, primary navigation, mobile drawer, overflow "More" menu.
 */

/* =========================================================================
 * Header shell
 * ========================================================================= */

.tb-header {
  position: sticky;
  top: 0;
  z-index: 200;
  background-color: var(--tb-bg, #F6F0EC);
  border-bottom: 1px solid var(--tb-border, #e2e5e0);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
  transition:
    background-color 0.3s ease,
    border-color 0.3s ease,
    box-shadow 0.3s ease;
}

/* Static — scrolls away with the page */
.tb-header--static {
  position: relative;
  top: auto;
}

.admin-bar .tb-header--static { top: auto; }
@media (max-width: 782px) {
  .admin-bar .tb-header--static { top: auto; }
}

/* At-top state — frosted glass so nav text stays legible over any hero */
.tb-header--transparent {
  background-color: rgba(246, 240, 236, 0.55);
  border-bottom-color: rgba(226, 229, 224, 0.4);
  box-shadow: none;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* Force fully solid on mobile — drawer needs opaque background */
@media (max-width: 1023px) {
  .tb-header--transparent {
    background-color: var(--tb-bg, #F6F0EC);
    border-bottom-color: var(--tb-border, #e2e5e0);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

/* Scrolled state — fully solid with a slightly deeper shadow */
.tb-header--scrolled {
  background-color: var(--tb-bg, #F6F0EC);
  border-bottom-color: var(--tb-border, #e2e5e0);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.09);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* Push header below the WP admin bar */
.admin-bar .tb-header { top: 32px; }
@media (max-width: 782px) {
  .admin-bar .tb-header { top: 46px; }
}

/*
 * Three-column grid: [logo auto] [nav 1fr] [actions auto]
 *
 * The nav column takes all available space.
 * Logo and actions are pinned — CTA is ALWAYS visible regardless of nav count.
 */
.tb-header__inner {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "logo nav actions";
  align-items: center;
  min-height: 58px;
  max-width: var(--container-xl, 1280px);
  margin: 0 auto;
  padding: 6px var(--section-padding-x, 1.5rem);
  user-select: none;
}

@media (max-width: 1023px) {
  .tb-header__inner {
    grid-template-columns: 1fr auto;
    grid-template-areas: "logo actions";
  }
}

/* =========================================================================
 * Logo
 * ========================================================================= */

.tb-header__logo {
  grid-area: logo;
  display: flex;
  align-items: center;
  text-decoration: none;
  padding-right: 1.25rem;
}

.tb-header__logo img {
  height: var(--tb-logo-height, 40px);
  width: auto;
  display: block;
  object-fit: contain;
  object-position: left center;
  transition: height 0.3s ease;
}

.tb-header--scrolled .tb-header__logo img {
  height: 34px;
}

.tb-header__logo-text {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--tb-heading, #1c1f1c);
  text-decoration: none;
  letter-spacing: -0.02em;
  white-space: nowrap;
  line-height: 1;
}

/* =========================================================================
 * Primary nav container — desktop only
 *
 * #tb-primary-nav is the DIRECT grid child (grid-area: nav).
 * overflow:clip hides overflowing nav items without creating a new stacking
 * context, so position:absolute dropdowns still escape and render on top.
 * ========================================================================= */

#tb-primary-nav {
  grid-area: nav;
  display: none;           /* hidden on mobile */
  align-items: center;
  min-width: 0;            /* CRITICAL: allows 1fr column to shrink below content width */
  /* No overflow:clip — that would clip absolutely-positioned dropdown panels */
}

@media (min-width: 1024px) {
  #tb-primary-nav { display: flex; justify-content: flex-start; }
}

/* The <ul> output by wp_nav_menu() */
.tb-nav {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  flex-grow: 0;            /* do not stretch — More button must follow immediately */
  flex-shrink: 1;
  list-style: none;
  padding: 0;
  margin: 0;
  margin-right: auto;      /* pushes More button to follow immediately after last item */
  min-width: 0;            /* prevents flex children from blowing out the column */
  overflow: visible;       /* dropdowns still escape */
}

.tb-nav__item {
  position: relative;
  flex-shrink: 0;
  margin: 0;
}

/* Top-level link — 13px keeps more items visible without cramping */
.tb-nav__link {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 6px 11px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--tb-text, #374151);
  text-decoration: none;
  border-radius: 6px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  line-height: 1.2;
  transition: color 0.12s, background-color 0.12s;
}

.tb-nav__link:hover,
.tb-nav__link:focus-visible {
  color: var(--tb-primary, #5a7a5e);
  background-color: var(--tb-primary-light, rgba(90, 122, 94, 0.09));
  outline: none;
}

.tb-nav__link--label { cursor: default; }

.tb-nav__item.current-menu-item > .tb-nav__link,
.tb-nav__item.current-page-ancestor > .tb-nav__link {
  color: var(--tb-primary, #5a7a5e);
  font-weight: 600;
}

.tb-nav__chevron {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  color: var(--tb-text-muted, #9ca3af);
  transition: transform 0.14s, color 0.12s;
}

/* =========================================================================
 * Desktop dropdown
 * ========================================================================= */

.tb-nav__sub-menu {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px) scale(0.98);
  transform-origin: top left;
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0s linear 0.14s;

  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 300;

  list-style: none;
  margin: 0;
  padding: 6px;
  min-width: 200px;

  background: var(--tb-bg, #F6F0EC);
  border: 1px solid var(--tb-border, #e2e5e0);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.10);
}

/* Invisible hover bridge — mouse can travel from link to dropdown */
.tb-nav__item--has-children > .tb-nav__link { position: relative; }
.tb-nav__item--has-children > .tb-nav__link::after {
  content: '';
  position: absolute;
  top: 100%;
  left: -8px;
  right: -8px;
  height: 12px;
  background: transparent;
  pointer-events: auto;
}

.tb-nav__item--has-children:hover > .tb-nav__sub-menu,
.tb-nav__item--has-children:focus-within > .tb-nav__sub-menu {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0s linear 0s;
}

.tb-nav__item--has-children:hover > .tb-nav__link .tb-nav__chevron,
.tb-nav__item--has-children:focus-within > .tb-nav__link .tb-nav__chevron {
  transform: rotate(180deg);
  color: var(--tb-primary, #5a7a5e);
}

.tb-nav__link[aria-expanded="true"] ~ .tb-nav__sub-menu {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}
.tb-nav__link[aria-expanded="true"] .tb-nav__chevron {
  transform: rotate(180deg);
  color: var(--tb-primary, #5a7a5e);
}

.tb-nav__sub-menu .tb-nav__item { display: block; }

.tb-nav__sub-menu .tb-nav__link {
  display: flex;
  width: 100%;
  padding: 7px 10px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--tb-text, #374151);
  border-radius: 6px;
  background: transparent;
  white-space: nowrap;
  transition: background-color 0.11s, color 0.11s;
}

.tb-nav__sub-menu .tb-nav__link:hover,
.tb-nav__sub-menu .tb-nav__link:focus-visible {
  background-color: var(--tb-primary-light, rgba(90, 122, 94, 0.09));
  color: var(--tb-primary, #5a7a5e);
  outline: none;
}

.tb-nav__sub-menu .tb-nav__item.current-menu-item > .tb-nav__link {
  color: var(--tb-primary, #5a7a5e);
  font-weight: 600;
  background-color: var(--tb-primary-light, rgba(90, 122, 94, 0.09));
}

@media (prefers-reduced-motion: reduce) {
  .tb-nav__sub-menu, .tb-nav__link, .tb-nav__chevron { transition: none; }
}

/* =========================================================================
 * "More" overflow dropdown — desktop only
 *
 * Always rendered in the DOM (inside #tb-primary-nav after .tb-nav).
 * JS sets .tb-nav__more--visible when items overflow, hides otherwise.
 * The panel (.tb-nav__more-menu) is populated with clones of hidden items.
 * ========================================================================= */

.tb-nav__more {
  position: relative;
  flex-shrink: 0;
  display: none;
}

.tb-nav__more--visible {
  display: flex;
  align-items: center;
}

.tb-nav__more-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 6px 11px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--tb-text, #374151);
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.12s, background-color 0.12s;
  line-height: 1.2;
}

.tb-nav__more-btn:hover,
.tb-nav__more-btn:focus-visible,
.tb-nav__more-btn[aria-expanded="true"] {
  color: var(--tb-primary, #5a7a5e);
  background-color: var(--tb-primary-light, rgba(90, 122, 94, 0.09));
  outline: none;
}

.tb-nav__more-chevron {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  color: var(--tb-text-muted, #9ca3af);
  transition: transform 0.14s, color 0.12s;
}

.tb-nav__more-btn[aria-expanded="true"] .tb-nav__more-chevron {
  transform: rotate(180deg);
  color: var(--tb-primary, #5a7a5e);
}

/* Panel — anchors left, directly below the More button */
.tb-nav__more-menu {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px) scale(0.98);
  transform-origin: top right;
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0s linear 0.14s;

  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 300;

  list-style: none;
  margin: 0;
  padding: 6px;
  min-width: 200px;

  background: var(--tb-bg, #F6F0EC);
  border: 1px solid var(--tb-border, #e2e5e0);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.10);
}

.tb-nav__more-menu.is-open {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0s linear 0s;
}

.tb-nav__more-menu > li { display: block; margin: 0; }

.tb-nav__more-menu > li > a,
.tb-nav__more-menu > li > span {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 7px 10px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--tb-text, #374151);
  text-decoration: none;
  border-radius: 6px;
  white-space: nowrap;
  transition: background-color 0.11s, color 0.11s;
}

.tb-nav__more-menu > li > a:hover,
.tb-nav__more-menu > li > a:focus-visible {
  background-color: var(--tb-primary-light, rgba(90, 122, 94, 0.09));
  color: var(--tb-primary, #5a7a5e);
  outline: none;
}

.tb-nav__more-menu > li.current-menu-item > a {
  color: var(--tb-primary, #5a7a5e);
  font-weight: 600;
  background-color: var(--tb-primary-light, rgba(90, 122, 94, 0.09));
}

/* Nested sub-menus inside More panel */
.tb-nav__more-menu .sub-menu {
  list-style: none;
  padding: 2px 0 4px 12px;
  margin: 0;
}

.tb-nav__more-menu .sub-menu > li > a {
  display: block;
  padding: 5px 10px;
  font-size: 0.75rem;
  color: var(--tb-text-muted, #6b7280);
  text-decoration: none;
  border-radius: 6px;
  transition: color 0.11s, background-color 0.11s;
}

.tb-nav__more-menu .sub-menu > li > a:hover {
  color: var(--tb-primary, #5a7a5e);
  background-color: var(--tb-primary-light, rgba(90, 122, 94, 0.09));
}

@media (prefers-reduced-motion: reduce) {
  .tb-nav__more-btn, .tb-nav__more-chevron, .tb-nav__more-menu { transition: none; }
}

/* =========================================================================
 * Header actions zone: CTA + mobile toggle
 * ========================================================================= */

.tb-header__actions {
  grid-area: actions;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-left: 0.75rem;
}

/* CTA only shows on desktop — it's also in the mobile drawer */
.tb-header__cta-wrap { display: none; }

@media (min-width: 1024px) {
  .tb-header__cta-wrap { display: flex; }
}

/* =========================================================================
 * Mobile toggle (hamburger)
 * ========================================================================= */

.tb-mobile-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: none;
  border: 1px solid var(--tb-border, #e2e5e0);
  border-radius: 6px;
  color: var(--tb-text, #374151);
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
  flex-shrink: 0;
}

.tb-mobile-toggle:hover {
  border-color: var(--tb-primary, #5a7a5e);
  color: var(--tb-primary, #5a7a5e);
}

@media (min-width: 1024px) {
  .tb-mobile-toggle { display: none; }
}

.tb-mobile-toggle__icon {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 18px;
  height: 18px;
  pointer-events: none;
}

.tb-mobile-toggle__icon span {
  display: block;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.15s ease;
  transform-origin: center;
}

.tb-mobile-toggle[aria-expanded="true"] .tb-mobile-toggle__icon span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.tb-mobile-toggle[aria-expanded="true"] .tb-mobile-toggle__icon span:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}
.tb-mobile-toggle[aria-expanded="true"] .tb-mobile-toggle__icon span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

@media (prefers-reduced-motion: reduce) {
  .tb-mobile-toggle__icon span { transition: none; }
}

/* =========================================================================
 * Mobile nav drawer
 * ========================================================================= */

.tb-mobile-nav {
  display: none;
  border-top: 1px solid var(--tb-border, #e2e5e0);
  background-color: var(--tb-bg, #F6F0EC);
  padding: 0.5rem var(--section-padding-x, 1.5rem) 1.5rem;
}

.tb-mobile-nav.is-open { display: block; }

@media (min-width: 1024px) {
  .tb-mobile-nav { display: none !important; }
}

/* Mobile list */
.tb-mobile-nav__list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}

.tb-mobile-nav__list > .menu-item {
  border-bottom: 1px solid var(--tb-border, #e2e5e0);
}
.tb-mobile-nav__list > .menu-item:last-child { border-bottom: none; }

.tb-mobile-nav__list > .menu-item > a,
.tb-mobile-nav__list > .menu-item > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  font-size: 1rem;
  font-weight: 500;
  color: var(--tb-text, #374151);
  text-decoration: none;
  line-height: 1.3;
  transition: color 0.12s;
}

.tb-mobile-nav__list > .menu-item > a:hover {
  color: var(--tb-primary, #5a7a5e);
}

/* Mobile sub-menu */
.tb-mobile-nav__list .sub-menu {
  list-style: none;
  margin: 0;
  padding: 0 0 8px 16px;
  display: none;
}

.tb-mobile-nav__list .sub-menu.is-open { display: block; }

.tb-mobile-nav__list .sub-menu > li > a {
  display: block;
  padding: 8px 0;
  font-size: 0.875rem;
  color: var(--tb-text-muted, #6b7280);
  text-decoration: none;
  transition: color 0.12s;
}

.tb-mobile-nav__list .sub-menu > li > a:hover {
  color: var(--tb-primary, #5a7a5e);
}

/* Chevron injected by JS */
.tb-mobile-chevron {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--tb-text-muted, #9ca3af);
  transition: transform 0.18s;
}

.menu-item-has-children.is-open > a .tb-mobile-chevron,
.menu-item-has-children.is-open > span .tb-mobile-chevron {
  transform: rotate(180deg);
  color: var(--tb-primary, #5a7a5e);
}

@media (prefers-reduced-motion: reduce) {
  .tb-mobile-chevron { transition: none; }
}

/* Mobile CTA */
.tb-mobile-nav__cta {
  padding-top: 1rem;
}

.tb-mobile-nav__cta .tb-btn {
  width: 100%;
  justify-content: center;
}
