/*
 * Full-name language selection.
 * JS measures the desktop indicator and manages dropdown inert/aria-hidden.
 * Without enhancement the three links remain directly available.
 */

/* Prevent native scroll anchoring from competing with translated-content positioning. */
html.is-changing-language {
  overflow-anchor: none;
  scroll-behavior: auto;
}

.language-switch {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  max-width: 100%;
  padding: 4px;
  gap: 0;
  border: 1px solid #cedbd3;
  border-radius: 999px;
  background: #f0f4ee;
}

.language-toggle {
  display: none;
  appearance: none;
  font: inherit;
}

.language-options {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0;
}

.language-switch .language-options a {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 999px;
  color: var(--ink);
  background: transparent;
  font-size: .8rem;
  font-weight: 600;
  line-height: 1.35;
  text-decoration: none;
  white-space: nowrap;
  /* The indicator is measured against these links, so their geometry is stable. */
  transform: none !important;
  translate: none !important;
  transition: color 160ms ease, background-color 160ms ease;
}

.language-switch .language-options a[aria-current="true"] {
  background: var(--navy);
  color: #fff;
}

.language-switch .language-options a:focus-visible,
.language-toggle:focus-visible {
  z-index: 3;
  outline: 3px solid #d99545;
  outline-offset: 3px;
}

.language-indicator {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 0;
  width: var(--language-width, 0px);
  height: var(--language-height, 44px);
  border-radius: 999px;
  background: var(--navy);
  box-shadow: 0 3px 8px rgb(11 31 68 / 12%);
  pointer-events: none;
  transform: translate3d(var(--language-x, 0px), var(--language-y, 0px), 0);
  transition: none;
}

.language-globe {
  display: block;
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  color: #497163;
}

.language-chevron {
  display: block;
  flex: 0 0 12px;
  width: 12px;
  height: 12px;
  margin-left: 1px;
  color: #63776d;
  transform-origin: center;
  transition: transform 240ms cubic-bezier(.22, 1, .36, 1);
}

.language-current {
  flex: 1 1 auto;
  text-align: left;
  white-space: nowrap;
}

/* The first measured position appears without an animation from zero. */
@media (min-width: 1101px) {
  .language-switch.is-enhanced.indicator-ready .language-indicator,
  .language-switch.is-enhanced .language-options.indicator-ready .language-indicator {
    display: block;
    transition:
      transform 360ms cubic-bezier(.22, 1, .36, 1),
      width 360ms cubic-bezier(.22, 1, .36, 1),
      height 360ms cubic-bezier(.22, 1, .36, 1);
  }

  .language-switch.is-enhanced.indicator-ready .language-options a[aria-current="true"],
  .language-switch.is-enhanced .language-options.indicator-ready a[aria-current="true"] {
    background: transparent;
    color: #fff;
  }
}

@media (hover: hover) and (pointer: fine) {
  .language-switch .language-options a:not([aria-current="true"]):hover {
    color: #174b38;
    background: #e3ece2;
    transform: none !important;
  }

  .language-switch.is-enhanced .language-toggle:hover {
    border-color: #9bb8a8;
    background: #edf3eb;
  }
}

/* Compact control. Visibility is delayed only while closing, not while opening. */
@media (max-width: 1100px) {
  .language-switch.is-enhanced {
    display: block;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .language-switch.is-enhanced .language-toggle {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: max-content;
    min-width: 140px;
    max-width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid #cedbd3;
    border-radius: 999px;
    color: var(--ink);
    background: #f0f4ee;
    font-size: .8rem;
    font-weight: 600;
    line-height: 1.35;
    cursor: pointer;
    transition:
      background-color 180ms ease,
      border-color 180ms ease,
      box-shadow 220ms ease;
  }

  .language-switch.is-enhanced .language-toggle[aria-expanded="true"] {
    background: #e8f0e5;
    border-color: #99b4a5;
    box-shadow: 0 3px 12px -7px rgb(11 31 68 / 18%);
  }

  .language-toggle[aria-expanded="true"] .language-chevron {
    transform: rotate(180deg);
  }

  .language-switch.is-enhanced .language-options {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
    width: 176px;
    max-width: calc(100vw - 32px);
    padding: 6px;
    border: 1px solid #d5e0d7;
    border-radius: 16px;
    background: #fbfcf9;
    box-shadow: 0 14px 34px -12px rgb(11 31 68 / 24%), 0 3px 8px rgb(11 31 68 / 5%);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-6px) scale(.98);
    transform-origin: top right;
    transition:
      opacity 180ms ease,
      transform 240ms cubic-bezier(.22, 1, .36, 1),
      visibility 0s linear 240ms;
  }

  .language-switch.is-enhanced.is-open .language-options {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
    transition-delay: 0s;
  }

  .language-switch.is-enhanced .language-options a {
    justify-content: flex-start;
    width: 100%;
    min-height: 44px;
    padding: 11px 14px;
    border-radius: 10px;
    font-size: .84rem;
  }

  .language-switch .language-indicator {
    display: none;
  }

  /* Direct language links stay reachable if JavaScript fails to initialize. */
  .language-switch:not(.is-enhanced) .language-options {
    flex-wrap: wrap;
  }
}

/* Allow text enlargement to wrap the header instead of clipping language names. */
@media (max-width: 600px) {
  .site-header .header-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
  }

  .language-switch.is-enhanced .language-toggle {
    min-width: 136px;
    padding-inline: 10px;
  }
}

@media (max-width: 360px) {
  .site-header .header-inner {
    width: calc(100% - 28px);
    gap: 8px;
  }

  .site-header .header-actions {
    gap: 4px;
  }

  .language-switch.is-enhanced .language-toggle {
    min-width: 132px;
  }
}

/* Preserve state changes while removing all selector movement and fading. */
@media (prefers-reduced-motion: reduce) {
  .language-switch,
  .language-toggle,
  .language-options,
  .language-options a,
  .language-indicator,
  .language-chevron {
    animation: none !important;
    transition: none !important;
  }

  .language-switch.is-enhanced .language-options {
    transform: none;
  }
}
