/* ==========================================================================
   Floating Section Navigation Component
   ========================================================================== */

.floating-nav-container {
  position: fixed;
  bottom: 24px;
  right: 20px;
  z-index: 990;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

@media (min-width: 768px) {
  .floating-nav-container {
    bottom: 32px;
    right: 36px;
  }
}

/* Floating Action Trigger Button: Exactly Conforms to Button Shape */
.floating-nav-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background:
    radial-gradient(circle at center, var(--brand-dark-blue) 0%, var(--brand-dark-blue) 100%) padding-box,
    conic-gradient(from 0deg, var(--brand-primary) var(--scroll-percent, 0%), var(--brand-darker-purple) var(--scroll-percent, 0%)) border-box;
  background-clip: padding-box, border-box;
  color: var(--color-white);
  border: 2.5px solid transparent;
  box-shadow: 0 4px 16px rgba(7, 25, 67, 0.25);
  cursor: pointer;
  transition: background-color var(--transition-fast);
  user-select: none;
  -webkit-user-select: none;
}

.floating-nav-btn:focus,
.floating-nav-btn:focus-visible {
  outline: none;
}

/* Highlight button color ONLY when popover menu is actually OPEN */
.floating-nav-container.is-open .floating-nav-btn {
  background:
    radial-gradient(circle at center, var(--brand-primary) 0%, var(--brand-primary) 100%) padding-box,
    conic-gradient(from 0deg, var(--brand-dark-blue) var(--scroll-percent, 0%), var(--brand-darker-purple) var(--scroll-percent, 0%)) border-box;
  background-clip: padding-box, border-box;
}

/* Mobile & Mobile Preview Simulation: Circular Icon Button with Perfect Border */
@media (max-width: 900px) {
  .floating-nav-container {
    position: fixed;
    bottom: 24px;
    right: 20px;
    z-index: 999;
  }

  .floating-nav-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    padding: 0;
  }

  .floating-nav-label {
    display: none !important;
  }
}

/* Desktop Simulation Mode: Keep button anchored inside the mobile frame */
body.mobile-preview-active .floating-nav-container {
  position: fixed;
  bottom: 40px;
  right: calc(50% - 187px);
  z-index: 999;
}

body.mobile-preview-active .floating-nav-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  padding: 0;
}

body.mobile-preview-active .floating-nav-label {
  display: none !important;
}

/* Desktop: Pill Button with Label and Gradual Border Fill */
@media (min-width: 901px) {
  body:not(.mobile-preview-active) .floating-nav-btn {
    width: auto;
    height: 44px;
    padding: 0 20px;
    border-radius: var(--radius-pill);
    background:
      linear-gradient(var(--brand-dark-blue), var(--brand-dark-blue)) padding-box,
      conic-gradient(from 0deg, var(--brand-primary) var(--scroll-percent, 0%), var(--brand-darker-purple) var(--scroll-percent, 0%)) border-box;
    background-clip: padding-box, border-box;
  }

  body:not(.mobile-preview-active) .floating-nav-container.is-open .floating-nav-btn {
    background:
      linear-gradient(var(--brand-primary), var(--brand-primary)) padding-box,
      conic-gradient(from 0deg, var(--brand-dark-blue) var(--scroll-percent, 0%), var(--brand-darker-purple) var(--scroll-percent, 0%)) border-box;
    background-clip: padding-box, border-box;
  }

  body:not(.mobile-preview-active) .floating-nav-label {
    display: inline-block;
    font-family: var(--font-heading);
    font-size: 13.5px;
    font-weight: 600;
    color: var(--color-white);
    letter-spacing: -0.01em;
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.floating-nav-icon {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.floating-nav-icon svg {
  width: 16px;
  height: 16px;
  stroke: var(--color-white);
  fill: none;
}

.floating-nav-icon .icon-close {
  display: none;
}

/* When Menu is Open: Icon changes to Close (X) */
.floating-nav-container.is-open .floating-nav-icon .icon-list {
  display: none;
}

.floating-nav-container.is-open .floating-nav-icon .icon-close {
  display: block;
}

/* Popover Menu Card */
.floating-nav-popover {
  position: absolute;
  bottom: calc(100% + 12px);
  right: 0;
  min-width: 220px;
  max-width: 280px;
  max-height: calc(100vh - 150px);
  max-height: calc(100dvh - 150px);
  background-color: var(--color-white);
  border-radius: 16px;
  border: 1px solid rgba(7, 25, 67, 0.08);
  box-shadow: 0 16px 40px rgba(7, 25, 67, 0.16);
  padding: 16px 14px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  box-sizing: border-box;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
    visibility 0.25s;
}

.floating-nav-container.is-open {
  z-index: 1005;
}

.floating-nav-container.is-open .floating-nav-popover {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

/* Back to Top Row: Pinned at top of popover card, never scrolls away */
.popover-back-to-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 600;
  color: var(--color-grey-700);
  background: none;
  border: none;
  padding: 4px 0;
  cursor: pointer;
  text-align: left;
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.popover-back-to-top:hover {
  color: var(--brand-primary);
}

.popover-back-to-top svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
}

.popover-divider {
  width: 100%;
  height: 1px;
  background-color: var(--color-grey-100);
  margin: 2px 0 2px;
  flex-shrink: 0;
}

/* Section Navigation List: Smoothly scrollable when height is constrained */
.popover-section-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  list-style: none;
  padding: 0 6px 0 6px;
  margin: 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  margin-right: -4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(7, 25, 67, 0.2) transparent;
}

.popover-section-list::-webkit-scrollbar {
  width: 4px;
}

.popover-section-list::-webkit-scrollbar-track {
  background: transparent;
}

.popover-section-list::-webkit-scrollbar-thumb {
  background: rgba(7, 25, 67, 0.2);
  border-radius: 4px;
}

.popover-section-list::-webkit-scrollbar-thumb:hover {
  background: rgba(7, 25, 67, 0.4);
}

.popover-section-item {
  display: flex;
  align-items: center;
}

.popover-section-link {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-heading);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--color-grey-700);
  text-decoration: none;
  transition: all var(--transition-fast);
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
}

.section-bullet,
.popover-bullet {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--color-grey-400);
  flex-shrink: 0;
  margin-left: 2px;
  transform-origin: center center;
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.popover-section-link:hover {
  color: var(--brand-dark-blue);
  background-color: rgba(7, 25, 67, 0.04);
}

.popover-section-link:hover .section-bullet,
.popover-section-link:hover .popover-bullet {
  background-color: var(--brand-dark-blue);
  transform: scale(1.3);
}

/* Active Section Item */
.popover-section-link.is-active {
  color: var(--brand-primary);
  font-weight: 700;
}

.popover-section-link.is-active .section-bullet,
.popover-section-link.is-active .popover-bullet {
  background-color: var(--brand-primary);
  transform: scale(1.35);
}