/* ==========================================================================
   TSI Custom Header
   Breakpoint: 900px — below this, horizontal nav becomes hamburger + drill-down
   ========================================================================== */

:root {
  --tsi-green: #629643;
  --tsi-green-dark: #547d38;
  --tsi-white: #ffffff;
  --tsi-off-white: #f5f5f5;
  --tsi-font: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --tsi-header-h: 104px;
  --tsi-header-h-scrolled: 82px;
  --tsi-nav-breakpoint: 900px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--tsi-font);
}

.tsi-skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--tsi-white);
  color: var(--tsi-green);
  padding: 10px 16px;
  z-index: 2000;
}
.tsi-skip-link:focus {
  left: 8px;
  top: 8px;
}

/* Hide Divi's own header — this plugin's header (injected via wp_body_open)
   replaces it visually. Divi's page wrappers (#page-container etc.) are left
   completely untouched, so the rest of the Divi-built page is unaffected. */
.et-l--header,
#main-header {
  display: none !important;
}

/* ---------- Top bar (contact details + CTA, stays visible on scroll) ---------- */

.tsi-topbar {
  position: sticky;
  top: 0;
  z-index: 1001;
  background: var(--tsi-green);
  border-bottom: 2px solid var(--tsi-white);
}

.tsi-topbar__inner {
  max-width: 1280px;
  margin: 0 auto;
  height: 56px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.tsi-topbar__contact,
.tsi-topbar__actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.tsi-topbar__contact a {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--tsi-white);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  opacity: 0.92;
}
.tsi-topbar__contact a:hover,
.tsi-topbar__contact a:focus {
  opacity: 1;
  text-decoration: underline;
}

.tsi-topbar__divider {
  width: 1px;
  height: 14px;
  background: rgba(255, 255, 255, 0.35);
  flex-shrink: 0;
}

.tsi-topbar__btn {
  display: inline-flex;
  align-items: center;
  padding: 8px 20px;
  border-radius: 0.5rem;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  border: 1.5px solid var(--tsi-white);
  transition: background-color 0.15s ease, color 0.15s ease;
}
.tsi-topbar__btn--solid {
  color: var(--tsi-green-dark);
  background: var(--tsi-white);
}
.tsi-topbar__btn--solid:hover,
.tsi-topbar__btn--solid:focus {
  background: transparent;
  color: var(--tsi-white);
}

@media (max-width: 900px) {
  .tsi-topbar__inner {
    height: auto;
    padding: 10px 16px;
    justify-content: flex-end; /* right edge lines up with the hamburger's outer edge below */
    flex-wrap: wrap;
    row-gap: 8px;
  }
  .tsi-topbar__contact {
    flex-wrap: wrap;
    row-gap: 6px;
  }
}

@media (max-width: 600px) {
  .tsi-topbar__inner {
    justify-content: center;
  }
}

/* ---------- Header shell ---------- */

.tsi-header {
  position: sticky;
  top: var(--tsi-topbar-h, 56px); /* sits directly below the sticky top bar; JS keeps this in sync with the bar's real height */
  z-index: 1000;
  background: var(--tsi-green);
  width: 100%;
}

.tsi-header__inner {
  max-width: 1280px;
  margin: 0 auto;
  height: var(--tsi-header-h);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 32px;
  transition: height 0.2s ease;
}

.tsi-header.is-scrolled .tsi-header__inner {
  height: var(--tsi-header-h-scrolled);
}

/* ---------- Logo ---------- */

.tsi-header__logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  line-height: 0;
}

.tsi-header__logo-img {
  display: block;
  height: 60px;
  width: auto;
}

.tsi-header__logo-img--mobile { display: none; }

@media (max-width: 640px) {
  .tsi-header__logo-img--desktop { display: none; }
  .tsi-header__logo-img--mobile {
    display: block;
    height: 80px;
    width: 80px;
  }
}

/* ---------- Desktop nav ---------- */

.tsi-nav {
  flex: 1;
  display: flex;
  justify-content: flex-end;
}

.tsi-menu {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 0;
}

.tsi-menu > .menu-item {
  position: relative;
}

.tsi-menu a {
  display: block;
  padding: 10px 14px;
  color: var(--tsi-white);
  text-decoration: none;
  font-weight: 500;
  font-size: 18px;
  border-radius: 1rem;
  white-space: nowrap;
  transition: background-color 0.15s ease;
}

/* Flush the last item's text with the header's right edge, matching the
   outer edge of the CTA button in the top bar above. */
.tsi-menu > .menu-item:last-child > a {
  padding-right: 0;
}

.tsi-menu-has-children-marker > a::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  margin-left: 6px;
  margin-bottom: 2px;
}

/* dropdown panels (desktop) — right-aligned to the parent item so they can
   never overflow past the right edge of the header (the nav itself is
   right-aligned, so items sit close to that edge). */
.tsi-menu .sub-menu {
  list-style: none;
  margin: 0;
  padding: 8px;
  position: absolute;
  top: 100%;
  left: auto;
  right: 0;
  width: max-content;
  max-width: 320px;
  background: var(--tsi-off-white);
  border-radius: 1rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16);
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
  z-index: 10;
}

.tsi-menu > .menu-item-has-children:hover > .sub-menu,
.tsi-menu > .menu-item-has-children:focus-within > .sub-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.tsi-menu .sub-menu a {
  color: #2b2b2b;
  padding: 9px 12px;
  font-size: 16px;
  border-radius: 1rem;
}

.tsi-menu .sub-menu a:hover,
.tsi-menu .sub-menu a:focus {
  color: var(--tsi-green);
}

/* nested (level 3) flyout — opens to the left, since its parent dropdown
   already sits flush against the right edge of the viewport. */
.tsi-menu .sub-menu .sub-menu {
  top: -8px;
  left: auto;
  right: 100%;
  margin-right: 6px;
}

.tsi-menu .sub-menu .menu-item-has-children:hover > .sub-menu,
.tsi-menu .sub-menu .menu-item-has-children:focus-within > .sub-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.tsi-menu .sub-menu .menu-item-has-children > a {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tsi-menu .sub-menu .menu-item-has-children > a::after {
  content: '';
  width: 6px;
  height: 6px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(135deg);
  margin-left: 10px;
}

/* ---------- Hamburger toggle ---------- */

.tsi-header__toggle {
  display: none;
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.tsi-header__toggle-bar {
  display: block;
  width: 32px;
  height: 3px;
  background: var(--tsi-white);
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.tsi-header__toggle[aria-expanded="true"] .tsi-header__toggle-bar:nth-child(1) {
  transform: translateY(10px) rotate(45deg);
}
.tsi-header__toggle[aria-expanded="true"] .tsi-header__toggle-bar:nth-child(2) {
  opacity: 0;
}
.tsi-header__toggle[aria-expanded="true"] .tsi-header__toggle-bar:nth-child(3) {
  transform: translateY(-10px) rotate(-45deg);
}

/* ==========================================================================
   Mobile (< 900px): hide desktop nav + CTA, show hamburger + drill-down panel
   ========================================================================== */

@media (max-width: 900px) {
  .tsi-header__inner { gap: 12px; }
  .tsi-nav { display: none; }
  .tsi-header__toggle { display: flex; margin-left: auto; }
}

.tsi-mobile-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s;
  z-index: 998;
}
.tsi-mobile-backdrop.is-visible {
  opacity: 1;
  visibility: visible;
}

.tsi-mobile-panel {
  position: fixed;
  top: calc(var(--tsi-topbar-h, 56px) + var(--tsi-header-h));
  right: 16px;
  width: min(260px, calc(100vw - 32px)); /* fallback; JS sizes this to content each time a level renders */
  max-width: calc(100vw - 32px);
  max-height: min(70vh, 520px);
  background: var(--tsi-off-white);
  border-radius: 1rem;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s, top 0.2s ease, width 0.2s ease;
  z-index: 999;
}

.tsi-header.is-scrolled ~ .tsi-mobile-panel {
  top: calc(var(--tsi-topbar-h, 56px) + var(--tsi-header-h-scrolled));
}

.tsi-mobile-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.tsi-mobile-panel__viewport {
  position: relative;
  overflow-y: auto;
  max-height: min(70vh, 520px);
}

.tsi-mobile-level {
  padding: 6px;
}

.tsi-mobile-level__back {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 12px 10px;
  font-family: var(--tsi-font);
  font-weight: 600;
  font-size: 16px;
  color: var(--tsi-green);
  cursor: pointer;
  border-bottom: 1px solid #eee;
  margin-bottom: 4px;
}
.tsi-mobile-level__back::before {
  content: '';
  width: 8px;
  height: 8px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}

.tsi-mobile-row {
  display: flex;
  align-items: stretch;
  border-radius: 1rem;
  overflow: hidden;
}

.tsi-mobile-row__link {
  flex: 1;
  padding: 12px 10px;
  color: #2b2b2b;
  text-decoration: none;
  font-size: 17px;
  font-weight: 500;
}
.tsi-mobile-row__link:hover,
.tsi-mobile-row__link:focus {
  color: var(--tsi-green);
}

.tsi-mobile-row__expand {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--tsi-green);
}
.tsi-mobile-row__expand::after {
  content: '';
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
}

/* sliding transition between drill-down levels */
.tsi-mobile-level {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  transition: transform 0.22s ease, opacity 0.22s ease;
}
.tsi-mobile-level[data-state="current"] {
  position: relative;
  transform: translateX(0);
  opacity: 1;
}
.tsi-mobile-level[data-state="entering"] {
  transform: translateX(100%);
  opacity: 0;
}
.tsi-mobile-level[data-state="leaving"] {
  transform: translateX(-100%);
  opacity: 0;
}
.tsi-mobile-level[data-state="entering-back"] {
  transform: translateX(-100%);
  opacity: 0;
}
.tsi-mobile-level[data-state="leaving-back"] {
  transform: translateX(100%);
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .tsi-header__inner,
  .tsi-header__logo-img,
  .tsi-mobile-panel,
  .tsi-mobile-level,
  .tsi-mobile-backdrop {
    transition: none !important;
  }
}
