/*
 * T.G.T. multilingual layout safety — 0.6.2
 * Loaded last so translated headings, cards, forms and RTL content cannot
 * force a grid/flex item outside its own column.
 */

/* Every direct child of the main layout systems must be allowed to shrink. */
:is(
  .tgt-header__utility-inner,
  .tgt-header__main,
  .tgt-primary-nav,
  .tgt-home .tgt-hero__inner,
  .tgt-home .tgt-trust-strip__grid,
  .tgt-home .tgt-journeys-intro,
  .tgt-home .tgt-journey-grid,
  .tgt-home .tgt-commercial-focus__heading,
  .tgt-home .tgt-commercial-focus__grid,
  .tgt-home .tgt-specialty-grid,
  .tgt-home .tgt-final-cta,
  .tgt-section-heading,
  .tgt-content-hero,
  .tgt-gateway-grid,
  .tgt-service-grid,
  .tgt-property-grid,
  .tgt-split,
  .tgt-international-card,
  .tgt-commercial-center__proof,
  .tgt-commercial-actions,
  .tgt-commercial-process,
  .tgt-commercial-center__heading--split,
  .tgt-commercial-types,
  .tgt-commercial-search-results,
  .tgt-commercial-investment,
  .tgt-property-term__content,
  .tgt-property-term__application,
  .tgt-property-term__related-heading,
  .tgt-property-term__related-grid,
  .tgt-knowledge__topic-grid,
  .tgt-guide-topic__grid,
  .tgt-legal-page__grid,
  .tgt-regional-contacts__grid,
  .tgt-program-detail__hero-grid,
  .tgt-program-detail__fact-grid,
  .tgt-footer__grid,
  .tgt-footer__bottom
) > * {
  min-width: 0;
  max-width: 100%;
}

/* German compounds and long English/French labels wrap inside their boxes.
 * Automatic language-aware hyphenation is preferred; anywhere is the safe
 * fallback when a browser has no dictionary for the active language. */
:is(
  .tgt-home h1,
  .tgt-home h2,
  .tgt-home h3,
  .tgt-commercial-center h1,
  .tgt-commercial-center h2,
  .tgt-commercial-center h3,
  .tgt-property-term h1,
  .tgt-property-term h2,
  .tgt-property-term__application h2,
  .tgt-content-single h1,
  .tgt-content-single h2,
  .tgt-guide-topic h1,
  .tgt-guide-topic h2,
  .tgt-guide-topic h3,
  .tgt-content-hero h1,
  .tgt-content-hero h2,
  .tgt-knowledge h1,
  .tgt-knowledge h2,
  .tgt-knowledge h3,
  .tgt-404__title,
  .tgt-legal-page h1,
  .tgt-legal-page h2,
  .tgt-regional-contacts h2,
  .tgt-regional-contacts h3,
  .post-type-archive #tgt-main-content .wp-block-query-title,
  .post-type-archive #tgt-main-content .wp-block-post-title,
  .page:not(.home) #tgt-main-content h1,
  .page:not(.home) #tgt-main-content h2,
  .page:not(.home) #tgt-main-content h3,
  .tgt-commercial-actions strong,
  .tgt-commercial-type strong,
  .tgt-commercial-search-results strong,
  .tgt-property-term__related-grid strong,
  .tgt-knowledge__topic-card strong,
  .tgt-application-form label,
  .tgt-application-form legend,
  .tgt-program-public h1,
  .tgt-program-public h2,
  .tgt-program-detail h1,
  .tgt-program-detail h2
) {
  overflow-wrap: anywhere;
  word-break: normal;
  hyphens: auto;
}

.tgt-eyebrow {
  flex-wrap: wrap;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: normal;
  hyphens: auto;
}

/* Calls to action may be considerably longer after translation. */
:is(
  .tgt-button,
  .wp-block-button__link,
  .tgt-text-link,
  .tgt-home .tgt-commercial-focus__intro a,
  .tgt-home .tgt-specialty-card__cta,
  .tgt-property-term__back,
  .tgt-regional-contact-card a,
  .tgt-cookie-consent__button,
  .tgt-cookie-consent__details-toggle
) {
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
  text-align: center;
  hyphens: auto;
}

/* Form and programme markup is supplied by the companion plugin. Keep every
 * field and translated label within the page even when the plugin changes its
 * internal column count. */
:is(.tgt-application-form, .tgt-program-public, .tgt-program-detail),
:is(.tgt-application-form, .tgt-program-public, .tgt-program-detail) * {
  min-width: 0;
}

:is(.tgt-application-form, .tgt-program-public, .tgt-program-detail)
  :is(input, select, textarea, button, fieldset, table) {
  max-width: 100%;
}

:is(.tgt-program-public, .tgt-program-detail) table {
  width: 100%;
  table-layout: fixed;
}

:is(.tgt-application-form, .tgt-program-public, .tgt-program-detail)
  :is(label, legend, th, td, p, li, strong, small) {
  overflow-wrap: anywhere;
  word-break: normal;
  hyphens: auto;
}

/* The German homepage title contains 31-character compounds. Give the copy
 * column more room, then let the language-aware wrapping rule do its work. */
@media (min-width: 961px) {
  body.tgt-lang-de .tgt-home .tgt-commercial-focus__heading {
    grid-template-columns: minmax(0, 1.34fr) minmax(280px, .66fr);
    gap: clamp(28px, 4vw, 58px);
  }

  body.tgt-lang-de .tgt-home .tgt-commercial-focus__heading h2 {
    max-width: 100%;
    font-size: clamp(2.25rem, 3.35vw, 3.6rem);
    letter-spacing: -.042em;
  }
}

/* The full desktop navigation becomes a menu before translated labels collide
 * with the logo. The existing navigation script already manages this state. */
@media (max-width: 1100px) {
  .tgt-menu-toggle {
    display: inline-flex;
  }

  .tgt-primary-nav {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    display: none;
    max-height: calc(100vh - 108px);
    overflow-y: auto;
    padding: 1rem 20px 1.4rem;
    border-top: 1px solid var(--tgt-border);
    background: var(--tgt-white);
    box-shadow: 0 20px 50px rgba(16, 33, 63, .12);
  }

  .tgt-header.is-menu-open .tgt-primary-nav {
    display: grid;
    gap: .85rem;
  }

  .tgt-nav-group summary {
    padding: .45rem 0;
    font-size: .9rem;
  }

  .tgt-nav-group__panel {
    position: static;
    min-width: 0;
    margin-top: .45rem;
    padding: .4rem 0 .5rem 1rem;
    border: 0;
    border-left: 2px solid var(--tgt-gold-light);
    border-radius: 0;
    box-shadow: none;
    transform: none;
  }

  .tgt-nav-group__panel::before {
    display: none;
  }

  .tgt-nav-group[open] .tgt-nav-group__panel {
    animation: none;
  }

  .tgt-nav-group__panel a {
    padding: .5rem .65rem;
    white-space: normal;
    overflow-wrap: anywhere;
    hyphens: auto;
  }

  .tgt-nav-cta {
    text-align: center;
  }

  .tgt-header.is-menu-open .tgt-menu-toggle i {
    background: transparent;
  }

  .tgt-header.is-menu-open .tgt-menu-toggle i::before {
    top: 0;
    transform: rotate(45deg);
  }

  .tgt-header.is-menu-open .tgt-menu-toggle i::after {
    top: 0;
    transform: rotate(-45deg);
  }
}

/* Complete the RTL conversion for rules that still use physical left/right
 * properties in the base theme. */
html[dir="rtl"] .tgt-home .tgt-commercial-focus__intro {
  padding-right: 1.45rem;
  padding-left: 0;
  border-right: 2px solid rgba(229, 173, 112, .86);
  border-left: 0;
}

html[dir="rtl"] .tgt-home .tgt-process-steps li {
  border-right: 1px solid #e1e7ef;
  border-left: 0;
}

html[dir="rtl"] .tgt-commercial-process li + li {
  border-right: 1px solid var(--tgt-border);
  border-left: 0;
}

html[dir="rtl"] :is(
  .tgt-legal-page__note,
  .tgt-knowledge__empty,
  .tgt-guide-topic__empty,
  .tgt-property-term__fallback
) {
  border-right: 4px solid var(--tgt-gold, #d7a65b);
  border-left: 0;
}

html[dir="rtl"] .tgt-nav-group summary::after {
  margin-right: .35rem;
  margin-left: 0;
}

html[dir="rtl"] .tgt-specialty-card__cta span {
  margin-right: 12px;
  margin-left: 0;
}

html[dir="rtl"] :is(
  .tgt-home .tgt-hero__tertiary,
  .tgt-home .tgt-commercial-focus__intro a,
  .tgt-home .tgt-text-link
) span[aria-hidden="true"] {
  display: inline-block;
  transform: scaleX(-1);
}

html[dir="rtl"] .tgt-home .tgt-text-link:hover span[aria-hidden="true"],
html[dir="rtl"] .tgt-home .tgt-text-link:focus-visible span[aria-hidden="true"] {
  transform: translateX(-3px) scaleX(-1);
}

html[dir="rtl"] :is(
  .tgt-commercial-actions a,
  .tgt-commercial-type,
  .tgt-commercial-search-results a,
  .tgt-property-term__related-grid a
):hover b,
html[dir="rtl"] :is(
  .tgt-commercial-actions a,
  .tgt-commercial-type,
  .tgt-commercial-search-results a,
  .tgt-property-term__related-grid a
):focus-visible b {
  transform: translate(-4px, -50%) scaleX(-1);
}

/* WordPress may insert visual line-break nodes around shortcode output. These
 * nodes must never occupy a grid cell or create an artificial menu row. */
.tgt-language-menu__panel br,
.tgt-commercial-actions > br,
.tgt-commercial-actions > p:empty {
  display: none !important;
}

/* Apply the same shortcode-line-break protection to every repeatable card and
 * list collection. A generated BR must not become an implicit grid cell. */
:is(
  .tgt-gateway-grid,
  .tgt-service-grid,
  .tgt-property-grid,
  .tgt-knowledge__topic-grid,
  .tgt-guide-topic__grid,
  .tgt-journey-grid,
  .tgt-commercial-focus__grid,
  .tgt-specialty-grid,
  .tgt-commercial-center__proof,
  .tgt-commercial-process,
  .tgt-commercial-types,
  .tgt-commercial-search-results,
  .tgt-property-term__related-grid,
  .tgt-regional-contacts__grid,
  .tgt-legal-page__grid,
  .tgt-process-steps
) > :is(br, p:empty) {
  display: none !important;
}

/* If wpautop wraps shortcode links in paragraphs, keep the links themselves as
 * the real layout items without introducing another grid level. */
.tgt-language-menu__panel > p,
.tgt-commercial-actions > p {
  display: contents;
}

:is(
  .tgt-gateway-grid,
  .tgt-service-grid,
  .tgt-property-grid,
  .tgt-knowledge__topic-grid,
  .tgt-guide-topic__grid,
  .tgt-journey-grid,
  .tgt-commercial-focus__grid,
  .tgt-specialty-grid,
  .tgt-commercial-types,
  .tgt-commercial-search-results,
  .tgt-property-term__related-grid,
  .tgt-regional-contacts__grid,
  .tgt-legal-page__grid
) > p {
  display: contents;
}

/* Compact, self-contained language selector shared by TR / EN / DE / AR / FR. */
.tgt-language-menu {
  position: relative;
  z-index: 40;
}

.tgt-language-menu__panel {
  position: absolute;
  inset-block-start: calc(100% + 8px);
  inset-inline-end: 0;
  inset-inline-start: auto;
  display: flex;
  width: 220px;
  min-width: 220px;
  max-width: calc(100vw - 28px);
  height: auto;
  min-height: 0;
  max-height: min(320px, calc(100vh - 72px));
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 3px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid #d9e2ee;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 18px 42px rgba(4, 20, 47, .18);
}

.tgt-language-menu__panel a {
  display: flex;
  min-height: 40px;
  flex: 0 0 auto;
  align-items: center;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--tgt-navy);
  font-size: .82rem;
  line-height: 1.25;
  text-align: start;
  text-decoration: none;
  white-space: normal;
}

.tgt-language-menu__panel .is-current {
  color: #8b5a27;
  background: #f8f2e9;
  font-weight: 800;
}

.tgt-language-menu__panel a:hover,
.tgt-language-menu__panel a:focus-visible {
  color: var(--tgt-navy);
  background: #eef4fb;
  text-decoration: none;
}

html[dir="rtl"] .tgt-language-menu__panel {
  inset-inline-end: 0;
  inset-inline-start: auto;
  text-align: right;
}

/* Property-owner choices form a predictable professional grid. Resetting
 * implicit placement prevents inserted BR/P nodes from scattering the cards. */
.tgt-commercial-actions,
.tgt-commercial-actions--owner,
.tgt-commercial-actions--compact {
  display: grid;
  grid-auto-flow: row;
  grid-auto-rows: 1fr;
  align-items: stretch;
  justify-content: stretch;
  gap: 16px;
}

.tgt-commercial-actions--owner,
.tgt-commercial-actions--compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.tgt-commercial-actions > a {
  grid-column: auto !important;
  grid-row: auto !important;
  width: 100%;
  min-width: 0;
  height: 100%;
  margin: 0;
}

@media (max-width: 1100px) {
  .tgt-commercial-actions--owner,
  .tgt-commercial-actions--compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .tgt-language-menu__panel {
    width: min(220px, calc(100vw - 28px));
  }

  .tgt-commercial-actions,
  .tgt-commercial-actions--owner,
  .tgt-commercial-actions--compact {
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: auto;
    gap: 12px;
  }

  .tgt-commercial-actions > a {
    min-height: 132px;
  }
}

@media (max-width: 760px) {
  html[dir="rtl"] .tgt-commercial-process li + li {
    border-top: 1px solid var(--tgt-border);
    border-right: 0;
  }
}

@media (max-width: 700px) {
  html[dir="rtl"] .tgt-home .tgt-commercial-focus__intro {
    padding-right: 1rem;
  }
}

@media (max-width: 1100px) {
  html[dir="rtl"] .tgt-nav-group__panel {
    padding-right: 1rem;
    padding-left: 0;
    border-right: 2px solid var(--tgt-gold-light);
    border-left: 0;
  }
}

@media (max-width: 440px) {
  .tgt-home .tgt-process-steps {
    grid-template-columns: minmax(0, 1fr);
  }

  .tgt-home .tgt-process-steps li {
    min-height: 0;
  }
}

/* Mobile conversion controls: keep the three final actions aligned and stop
 * the persistent expert shortcut from covering primary page content. */
@media (max-width: 700px) {
  .tgt-home .tgt-final-cta__actions {
    width: 100%;
    gap: 14px;
  }

  .tgt-home .tgt-final-cta__actions .tgt-button {
    width: 100%;
    min-height: 58px;
    padding: .8rem 1rem;
    line-height: 1.2;
  }

  .tgt-home .tgt-final-cta__phone {
    font-size: clamp(.84rem, 3.8vw, 1rem);
    letter-spacing: -.015em;
    white-space: nowrap;
  }

  .tgt-quick-expert {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    width: 52px;
  }

  .tgt-quick-expert__toggle {
    width: 52px;
    min-width: 52px;
    height: 52px;
    min-height: 52px;
    justify-content: center;
    gap: 0;
    padding: 0;
    border-radius: 50%;
  }

  .tgt-quick-expert__toggle .tgt-quick-expert__label {
    display: none;
  }

  .tgt-quick-expert__toggle .tgt-quick-expert__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #f1b96f;
    font-size: 1.22rem;
    line-height: 1;
  }

  .tgt-quick-expert__panel {
    position: fixed;
    right: max(12px, env(safe-area-inset-right));
    bottom: calc(76px + env(safe-area-inset-bottom));
    width: min(292px, calc(100vw - 24px));
  }
}

@media (max-width: 370px) {
  .tgt-home .tgt-final-cta__phone {
    padding-inline: .65rem;
    font-size: .8rem;
  }
}
