/*
 * Mobile bottom navigation
 * -------------------------
 * This follows the reference site's compact-navigation pattern:
 * the fixed header keeps branding and the theme control, while this separate
 * dock keeps every primary destination reachable during a long page scroll.
 * The 991.98px cutoff intentionally matches the reference Bootstrap layout,
 * so narrow tablets do not fall into a gap between mobile and desktop nav.
 *
 * The component is isolated here so mobile positioning, safe-area spacing,
 * and dock states cannot leak into the existing header or page sections.
 */

.mobile-bottom-nav {
  display: none;
}

@media (max-width: 991.98px) {
  body {
    /* Prevent the fixed dock from covering the final content or footer. */
    padding-bottom: calc(92px + env(safe-area-inset-bottom));
  }

  /* The dock is the only compact navigation; the desktop link row is not. */
  .site-header .desktop-nav {
    display: none;
  }

  .mobile-bottom-nav {
    /*
     * Use physical inset properties with !important here. Mobile browsers
     * can retain a stale transform/position from a previous responsive
     * layout after orientation or viewport changes; an explicit fixed box
     * keeps the dock attached to the viewport instead of the page flow.
     */
    position: fixed !important;
    top: auto !important;
    right: 10px !important;
    bottom: 10px !important;
    left: 10px !important;
    width: calc(100vw - 20px) !important;
    max-width: calc(100vw - 20px) !important;
    box-sizing: border-box;
    /* Stay above the desktop shell traveler (z-index: 9000) when a
     * responsive resize lands in the compact/tablet range. */
    z-index: 10000 !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
    min-height: 70px;
    padding-block: 7px calc(7px + env(safe-area-inset-bottom));
    padding-inline: max(6px, env(safe-area-inset-left)) max(6px, env(safe-area-inset-right));
    /* Keep the control surface opaque so backdrop compositing cannot blur
     * the labels or icons on mobile Chrome. */
    /* A solid surface keeps the controls readable over hero artwork. */
    background: var(--paper-2) !important;
    border: 1px solid var(--line) !important;
    border-radius: 30px;
    box-shadow: none !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    filter: none !important;
    -webkit-filter: none !important;
    text-shadow: none !important;
    visibility: visible !important;
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
    transition: none !important;
    pointer-events: auto !important;
    overflow: hidden;
  }

  /* A filtered ancestor can turn fixed descendants into viewport-relative
   * elements in Chromium/WebKit. The dock is a sibling, but disabling the
   * header filter in the compact layout also makes resize/orientation changes
   * deterministic across mobile Chrome and Safari. */
  .site-header,
  .site-header .header-container {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .site-header::before {
    display: none;
  }

  /* Anchor the phone header to the visual viewport so its right-side
   * controls cannot be pushed outside the capture or the device screen. */
  .site-header .header-container {
    width: calc(100vw - 20px) !important;
    max-width: calc(100vw - 20px) !important;
    box-sizing: border-box;
    margin-inline: auto;
  }

  .site-header .header-inner {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .site-header .header-side-tools {
    flex: 0 0 auto;
  }

  /* Keep both header controls available on phones. The language switcher is
   * the existing flag control; it moves beside the theme button instead of
   * competing with the fixed navigation dock at the bottom. */
  .site-header .header-side-tools,
  .site-header .header-tools,
  .site-header .header-tools .icon-button {
    visibility: visible !important;
    opacity: 1 !important;
  }

  .site-header .header-tools .icon-button {
    display: grid !important;
    place-items: center;
    min-width: 44px;
    min-height: 44px;
    border: 1px solid var(--line) !important;
    border-radius: 50%;
    background: var(--paper-2) !important;
    color: var(--ink) !important;
    filter: none !important;
    -webkit-filter: none !important;
    box-shadow: none !important;
    transform: none !important;
  }

  .mobile-bottom-nav__list {
    display: grid !important;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    align-items: stretch;
    gap: 0;
    list-style: none;
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    min-width: 0;
    overflow: hidden;
    visibility: visible !important;
    opacity: 1 !important;
  }

  .mobile-bottom-nav__item {
    display: flex !important;
    min-width: 0;
    overflow: hidden;
    visibility: visible !important;
    opacity: 1 !important;
  }

  .mobile-bottom-nav__link {
    position: relative;
    isolation: isolate;
    width: 100%;
    min-width: 0;
    min-height: 54px;
    padding: 6px 2px;
    border-radius: 22px;
    display: inline-flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--ink) !important;
    font-size: clamp(.58rem, 2.1vw, .7rem);
    font-weight: 650;
    line-height: 1.05;
    text-align: center;
    white-space: nowrap;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: none !important;
    filter: none !important;
    -webkit-filter: none !important;
    text-shadow: none !important;
    visibility: visible !important;
    opacity: 1 !important;
    transform: none !important;
  }

  /*
   * Keep this defensive guard beside the dock styles. If another page-level
   * reveal hook is added later, a fixed navigation control must still remain
   * immediately readable instead of entering an opacity/blur start state.
   */
  .mobile-bottom-nav :is([data-text-reveal], .mobile-bottom-nav__link,
    .mobile-bottom-nav__label) {
    opacity: 1 !important;
    filter: none !important;
    -webkit-filter: none !important;
    transform: none !important;
    transition: none !important;
    text-shadow: none !important;
  }

  .mobile-bottom-nav__link::before {
    display: none;
  }

  .mobile-bottom-nav__link:hover,
  .mobile-bottom-nav__link:focus-visible {
    color: var(--ink);
    background: var(--paper) !important;
    transform: none !important;
  }

  .mobile-bottom-nav__link:hover::before,
  .mobile-bottom-nav__link:focus-visible::before,
  .mobile-bottom-nav__link.is-active::before {
    display: none;
  }

  .mobile-bottom-nav__link.is-active,
  .mobile-bottom-nav__link.is-active:hover,
  .mobile-bottom-nav__link.is-active:focus-visible {
    color: var(--copper) !important;
    background: var(--paper) !important;
    box-shadow: none !important;
  }

  .mobile-bottom-nav__link.is-active::after {
    position: absolute;
    inset-block-end: 3px;
    inset-inline-start: 50%;
    width: 4px;
    height: 4px;
    content: "";
    border-radius: 50%;
    background: currentColor;
    box-shadow: none;
    transform: translateX(-50%);
  }

  [dir="rtl"] .mobile-bottom-nav__link.is-active::after {
    transform: translateX(50%);
  }

  .mobile-bottom-nav__link:active {
    transform: none !important;
  }

  .mobile-bottom-nav__icon {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-height: 17px;
    font-size: 17px;
    line-height: 1;
    color: inherit !important;
    filter: none !important;
    -webkit-filter: none !important;
    text-shadow: none !important;
    visibility: visible !important;
    opacity: 1 !important;
    transform: none !important;
  }

  .mobile-bottom-nav__link.is-active .mobile-bottom-nav__icon {
    filter: none;
    transform: none !important;
  }

  .mobile-bottom-nav__label {
    display: inline-block !important;
    overflow: hidden;
    max-width: 100%;
    text-overflow: ellipsis;
    color: inherit !important;
    filter: none !important;
    -webkit-filter: none !important;
    text-shadow: none !important;
    visibility: visible !important;
    opacity: 1 !important;
  }

  /* Keep the language control floating above the dock, outside the header. */
  .floating-language {
    inset-block-start: auto !important;
    inset-block-end: calc(94px + env(safe-area-inset-bottom)) !important;
    inset-inline-end: clamp(16px, 2.4vw, 32px) !important;
    right: clamp(16px, 2.4vw, 32px) !important;
    left: auto !important;
    z-index: 10001 !important;
  }

  .floating-language-menu {
    inset-block-start: auto;
    inset-block-end: 58px;
    transform-origin: 100% 100%;
  }

  html[dir="rtl"] .floating-language-menu {
    transform-origin: 0 100%;
  }

  /* The mobile header theme control never enters the shared reveal/blur state
   * used by page text. */
  .site-header .header-tools .icon-button,
  .floating-language-toggle {
    animation: none !important;
  }

  .floating-language-toggle {
    filter: none !important;
    -webkit-filter: none !important;
    box-shadow: none !important;
    transform: none !important;
  }

}

@media (max-width: 560px) {
  /* On very narrow phones, anchor the two top controls to the viewport
   * rather than to the header flex row. Long hero/product stages can have a
   * wider layout box during their reveal, which would otherwise push a
   * right-aligned control beyond the visible phone edge. */
  .site-header .header-side-tools {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 10002;
    margin-inline-start: 0 !important;
  }

  html[dir="rtl"] .site-header .header-side-tools {
    right: auto;
    left: 14px;
  }

  .site-header .header-container {
    width: calc(100vw - 12px) !important;
    max-width: calc(100vw - 12px) !important;
  }

  .mobile-bottom-nav {
    right: 6px !important;
    left: 6px !important;
    width: calc(100vw - 12px) !important;
    max-width: calc(100vw - 12px) !important;
    border-radius: 27px;
    padding-inline: 3px;
  }

  .mobile-bottom-nav__link {
    min-height: 52px;
    font-size: clamp(.5rem, 2.15vw, .62rem);
    gap: 3px;
  }

  .mobile-bottom-nav__icon {
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-bottom-nav__link,
  .mobile-bottom-nav__link::before,
  .mobile-bottom-nav__icon {
    transition: none;
  }
}
