/*
 * 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;
  min-width: 0;
  max-width: min(32vw, 320px);
  text-decoration: none;
  padding-right: 1.25rem;
}

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

@media (max-width: 1023px) {
  .tb-header__logo {
    max-width: min(68vw, 280px);
    padding-right: 0.75rem;
  }
}

.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;
    column-gap: 2px;
  }
}

/*
 * Runtime escape hatch: when even a priority+ More button cannot fit safely,
 * JavaScript switches the desktop header to the complete mobile drawer.
 * This protects unusual logo proportions, translated labels, browser zoom,
 * custom fonts, and narrow embedded browser windows.
 */
@media (min-width: 1024px) {
  .tb-header.tb-header--nav-compact .tb-header__inner {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "logo actions";
  }

  .tb-header.tb-header--nav-compact #tb-primary-nav,
  .tb-header.tb-header--nav-compact .tb-header__cta-wrap,
  .tb-header.tb-header--nav-compact .tb-header__utility-wrap {
    display: none;
  }

  .tb-header.tb-header--nav-compact .tb-mobile-toggle {
    display: flex;
  }

  .tb-header.tb-header--nav-compact .tb-mobile-nav.is-open {
    display: block !important;
  }

  .tb-header.tb-header--nav-compact .tb-header__logo {
    max-width: min(72vw, 360px);
    padding-right: 0.75rem;
  }
}

/* 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;
  border: 0;
  background: transparent;
  font-family: inherit;
  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__link--label:hover { background-color: transparent; }

.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;
  max-width: min(320px, calc(100vw - 2rem));
  max-height: min(70vh, 520px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;

  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 {
  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 {
  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);
}

/* Applied at runtime when a dropdown would cross the right viewport edge. */
.tb-nav__sub-menu.tb-nav__sub-menu--align-right {
  right: 0;
  left: auto;
  transform-origin: top right;
}

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

/* Presentation-only headings inside mixed dropdowns (for example What We Offer).
 * These intentionally read as section labels rather than menu links. Every
 * visual value comes from Style Controller tokens so the treatment adapts to
 * each practice palette. */
.tb-nav__section-heading {
  display: block;
  margin: 8px 4px 4px;
  padding: 7px 9px 7px 10px;
  background: var(--tb-surface-soft, #f3f5f1);
  border: 1px solid var(--tb-border, #e2e5e0);
  border-left: 3px solid var(--tb-primary, #5a7a5e);
  border-radius: var(--tb-radius-control, 7px);
  color: var(--tb-primary-dark, var(--tb-primary, #5a7a5e));
  font-size: 0.625rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  line-height: 1.25;
  text-transform: uppercase;
  pointer-events: none;
}

.tb-nav__section-heading > span {
  display: block;
}

.tb-nav__sub-menu > .tb-nav__section-heading:first-child,
.tb-nav__more-menu .sub-menu > .tb-nav__section-heading:first-child {
  margin-top: 2px;
}

.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 — right-aligned so it cannot run beyond the viewport edge. */
.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);
  right: 0;
  left: auto;
  z-index: 300;

  list-style: none;
  margin: 0;
  padding: 6px;
  min-width: 200px;
  max-width: min(320px, calc(100vw - 2rem));
  max-height: min(70vh, 520px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;

  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,
.tb-nav__more-menu > li > button {
  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;
  border: 0;
  background: transparent;
  font-family: inherit;
  text-align: left;
}

.tb-nav__more-menu > li > a:hover,
.tb-nav__more-menu > li > a:focus-visible,
.tb-nav__more-menu > li > button:hover,
.tb-nav__more-menu > li > button: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;
}

/* Primary CTA and existing-client access show on desktop; both are repeated
 * in the mobile drawer. Client Portal intentionally mirrors the primary button
 * shape while using the outline treatment so the hierarchy stays obvious. */
.tb-header__cta-wrap,
.tb-header__utility-wrap { display: none; }

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

.tb-header__portal-btn {
  box-shadow: none;
}

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

.tb-mobile-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  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;
  max-height: calc(100dvh - 58px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.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,
.tb-mobile-nav__list > .menu-item > button {
  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;
  width: 100%;
  border: 0;
  background: transparent;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.tb-mobile-nav__link--group { cursor: default; }

.tb-mobile-nav__list > .menu-item > a:hover,
.tb-mobile-nav__list > .menu-item > button: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__section-heading {
  display: block;
  margin: 10px 0 4px;
  padding: 8px 10px;
  background: var(--tb-surface-soft, #f3f5f1);
  border: 1px solid var(--tb-border, #e2e5e0);
  border-left: 3px solid var(--tb-primary, #5a7a5e);
  border-radius: var(--tb-radius-control, 7px);
  color: var(--tb-primary-dark, var(--tb-primary, #5a7a5e));
  font-size: 0.625rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  line-height: 1.25;
  text-transform: uppercase;
}

.tb-mobile-nav__list .sub-menu > .tb-mobile-nav__section-heading:first-child {
  margin-top: 4px;
}

.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,
.menu-item-has-children.is-open > button .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 {
  display: grid;
  gap: .65rem;
  padding-top: 1rem;
}

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

.tb-mobile-nav__portal{background:transparent;}

/* rc11 — complete-desktop-nav contract.
 * The full primary menu gets a tighter fit pass before TherapyBuilt switches
 * to the complete drawer. Primary destinations are never hidden behind a
 * catch-all “More” label. */
@media (min-width: 1024px) {
  .tb-header.tb-header--nav-tight .tb-header__inner {
    max-width: var(--container-2xl, 1440px);
    padding-inline: clamp(14px, 1.5vw, 24px);
  }

  .tb-header.tb-header--nav-tight .tb-header__logo {
    max-width: min(24vw, 270px);
    padding-right: 0.8rem;
  }

  .tb-header.tb-header--nav-tight .tb-nav__link {
    gap: 2px;
    padding-inline: 8px;
    font-size: 0.875rem;
  }

  .tb-header.tb-header--nav-tight .tb-header__actions {
    gap: 0.5rem;
    padding-left: 0.5rem;
  }

  .tb-header.tb-header--nav-tight .tb-header__actions .tb-btn {
    padding-inline: 0.9rem;
    white-space: nowrap;
  }
}
