/* =========================================================
   Floating Sections Menu — sits next to "سجل الآن" button.
   Opens a panel listing all index sections, and shows an
   animated tooltip whenever the user enters a new section.
   ========================================================= */

:root {
    --fm-primary: var(--color-primary, #128183);
    --fm-primary-light: var(--color-primary-light, #24929c);
    --fm-primary-dark: #0d6466;
    --fm-bg: #ffffff;
    --fm-text: #1f2d2e;
    --fm-text-muted: #5d7374;
    --fm-shadow: 0 18px 40px -14px rgba(18, 129, 131, 0.45),
                 0 6px 14px rgba(0, 0, 0, 0.06);
    --fm-shadow-hover: 0 26px 56px -16px rgba(18, 129, 131, 0.65),
                       0 8px 18px rgba(0, 0, 0, 0.08);
    --fm-ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ----- Wrapper positioned next to register button ------- */
.floating-menu-btn {
    position: fixed;
    bottom: 28px;
    /* Sit to the inside of the register button (which uses inset-inline-end: 28px + ~150px wide). */
    inset-inline-end: 200px;
    z-index: 2147483000;
    pointer-events: auto;
}

[dir="rtl"] .floating-menu-btn { left: 200px; right: auto; }
[dir="ltr"] .floating-menu-btn { right: 200px; left: auto; }

/* ----- Round trigger button ----------------------------- */
.floating-menu-btn__trigger {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, var(--fm-primary-light), var(--fm-primary));
    color: #ffffff;
    box-shadow: var(--fm-shadow),
                inset 0 0 0 1px rgba(255, 255, 255, 0.2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.4s var(--fm-ease),
                box-shadow 0.4s var(--fm-ease),
                filter 0.3s var(--fm-ease);
    isolation: isolate;
}

.floating-menu-btn__trigger:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: var(--fm-shadow-hover),
                inset 0 0 0 1px rgba(255, 255, 255, 0.3);
    filter: brightness(1.05);
}

.floating-menu-btn__trigger:focus-visible {
    outline: 3px solid rgba(36, 146, 156, 0.5);
    outline-offset: 3px;
}

/* ----- Pulse halo (matches register button vibe) -------- */
.floating-menu-btn__pulse {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--fm-primary-light), var(--fm-primary));
    opacity: 0.45;
    filter: blur(4px);
    z-index: -1;
    animation: fmPulse 2.6s var(--fm-ease) infinite;
}

@keyframes fmPulse {
    0%   { transform: scale(1);    opacity: 0.45; }
    70%  { transform: scale(1.35); opacity: 0; }
    100% { transform: scale(1.35); opacity: 0; }
}

/* ----- Icon swap (menu <-> close) ----------------------- */
.floating-menu-btn__icon-stack {
    position: relative;
    width: 1.25rem;
    height: 1.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.floating-menu-btn__icon {
    position: absolute;
    inset: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    transition: opacity 0.3s var(--fm-ease),
                transform 0.4s var(--fm-ease);
}

.floating-menu-btn__icon--close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.6);
}

.floating-menu-btn.is-open .floating-menu-btn__icon--menu {
    opacity: 0;
    transform: rotate(90deg) scale(0.6);
}

.floating-menu-btn.is-open .floating-menu-btn__icon--close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.floating-menu-btn.is-open .floating-menu-btn__pulse { display: none; }

/* =========================================================
   Section-change tooltip — appears beside the icon when
   the user scrolls into a new section.
   ========================================================= */
.floating-menu-btn__tooltip {
    position: absolute;
    bottom: 50%;
    transform: translateY(50%);
    inset-inline-end: calc(100% + 14px);
    background: linear-gradient(135deg, var(--fm-primary), var(--fm-primary-dark));
    color: #ffffff;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.2;
    padding: 8px 14px;
    border-radius: 999px;
    white-space: nowrap;
    box-shadow: 0 10px 24px -6px rgba(13, 100, 102, 0.55),
                inset 0 0 0 1px rgba(255, 255, 255, 0.18);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    opacity: 0;
    pointer-events: none;
    transform-origin: 100% 50%;
    transform: translateY(50%) scale(0.85) translateX(8px);
    transition: opacity 0.35s var(--fm-ease),
                transform 0.45s var(--fm-ease);
    z-index: 1;
}

[dir="ltr"] .floating-menu-btn__tooltip {
    transform-origin: 0% 50%;
    transform: translateY(50%) scale(0.85) translateX(-8px);
}

/* Little arrow pointing toward the icon */
.floating-menu-btn__tooltip::after {
    content: "";
    position: absolute;
    top: 50%;
    inset-inline-end: -5px;
    transform: translateY(-50%) rotate(45deg);
    width: 10px;
    height: 10px;
    background: var(--fm-primary-dark);
    border-radius: 2px;
}

[dir="ltr"] .floating-menu-btn__tooltip::after {
    inset-inline-end: auto;
    inset-inline-start: -5px;
}

.floating-menu-btn__tooltip i {
    font-size: 0.85rem;
    transform: rotate(-90deg); /* point toward icon (RTL: leftwards) */
    animation: fmTooltipNudge 1.6s var(--fm-ease) infinite;
}

[dir="ltr"] .floating-menu-btn__tooltip i {
    transform: rotate(90deg);
}

@keyframes fmTooltipNudge {
    0%, 100% { transform: rotate(-90deg) translateX(0); }
    50%      { transform: rotate(-90deg) translateX(-4px); }
}

[dir="ltr"] @keyframes fmTooltipNudge {
    0%, 100% { transform: rotate(90deg) translateX(0); }
    50%      { transform: rotate(90deg) translateX(4px); }
}

/* Visible state — added by JS for a few seconds when section changes */
.floating-menu-btn__tooltip.is-visible {
    opacity: 1;
    transform: translateY(50%) scale(1) translateX(0);
    pointer-events: none;
    animation: fmTooltipBounce 0.8s var(--fm-ease) 1;
}

@keyframes fmTooltipBounce {
    0%   { transform: translateY(50%) scale(0.85) translateX(8px); opacity: 0; }
    55%  { transform: translateY(50%) scale(1.06) translateX(-2px); opacity: 1; }
    100% { transform: translateY(50%) scale(1) translateX(0); opacity: 1; }
}

/* Sync attention pulse on the icon while tooltip is visible */
.floating-menu-btn.has-new-section .floating-menu-btn__trigger {
    animation: fmAttentionShake 0.9s var(--fm-ease) 1;
}

@keyframes fmAttentionShake {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    20%      { transform: translateY(-3px) rotate(-6deg); }
    40%      { transform: translateY(-1px) rotate(6deg); }
    60%      { transform: translateY(-2px) rotate(-4deg); }
    80%      { transform: translateY(0) rotate(2deg); }
}

/* When the panel is open, hide the tooltip */
.floating-menu-btn.is-open .floating-menu-btn__tooltip {
    opacity: 0 !important;
    transform: translateY(50%) scale(0.85) translateX(8px) !important;
}

/* =========================================================
   Slide-up panel listing all sections
   ========================================================= */
.floating-menu-panel {
    position: absolute;
    bottom: calc(100% + 14px);
    inset-inline-end: 0;
    width: min(320px, calc(100vw - 40px));
    background: var(--fm-bg);
    border-radius: 18px;
    box-shadow: 0 24px 60px -10px rgba(0, 0, 0, 0.18),
                0 8px 18px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(0.96);
    transform-origin: 100% 100%;
    transition: opacity 0.3s var(--fm-ease),
                transform 0.35s var(--fm-ease),
                visibility 0s linear 0.35s;
    border: 1px solid rgba(18, 129, 131, 0.12);
}

[dir="ltr"] .floating-menu-panel { transform-origin: 0% 100%; }

.floating-menu-btn.is-open .floating-menu-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    transition: opacity 0.3s var(--fm-ease),
                transform 0.35s var(--fm-ease),
                visibility 0s linear;
}

.floating-menu-panel[aria-hidden="false"] { /* fallback */ }

.floating-menu-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: linear-gradient(135deg, var(--fm-primary), var(--fm-primary-dark));
    color: #ffffff;
}

.floating-menu-panel__title {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 0.2px;
}

.floating-menu-panel__close {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.18);
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.95rem;
    transition: background 0.25s var(--fm-ease), transform 0.25s var(--fm-ease);
}

.floating-menu-panel__close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.floating-menu-panel__list {
    list-style: none;
    margin: 0;
    padding: 8px 6px;
    max-height: min(60vh, 480px);
    overflow-y: auto;
}

.floating-menu-panel__item {
    margin: 2px 0;
}

.floating-menu-panel__link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 12px;
    color: var(--fm-text);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: background 0.25s var(--fm-ease),
                color 0.25s var(--fm-ease),
                transform 0.25s var(--fm-ease);
    position: relative;
}

.floating-menu-panel__link:hover {
    background: rgba(18, 129, 131, 0.08);
    color: var(--fm-primary-dark);
    transform: translateX(-3px);
}

[dir="ltr"] .floating-menu-panel__link:hover { transform: translateX(3px); }

.floating-menu-panel__link i {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: rgba(18, 129, 131, 0.12);
    color: var(--fm-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    flex-shrink: 0;
    transition: background 0.25s var(--fm-ease), color 0.25s var(--fm-ease);
}

.floating-menu-panel__link:hover i {
    background: var(--fm-primary);
    color: #ffffff;
}

/* Highlight the section the user is currently in */
.floating-menu-panel__item.is-active .floating-menu-panel__link {
    background: linear-gradient(135deg, rgba(36, 146, 156, 0.12), rgba(18, 129, 131, 0.08));
    color: var(--fm-primary-dark);
    font-weight: 700;
}

.floating-menu-panel__item.is-active .floating-menu-panel__link i {
    background: var(--fm-primary);
    color: #ffffff;
}

.floating-menu-panel__item.is-active .floating-menu-panel__link::after {
    content: "";
    position: absolute;
    inset-inline-start: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 60%;
    border-radius: 4px;
    background: var(--fm-primary);
}

/* Scrollbar polish */
.floating-menu-panel__list::-webkit-scrollbar { width: 6px; }
.floating-menu-panel__list::-webkit-scrollbar-thumb {
    background: rgba(18, 129, 131, 0.3);
    border-radius: 999px;
}
.floating-menu-panel__list::-webkit-scrollbar-track { background: transparent; }

/* Hide alongside the register button */
.floating-menu-btn.is-hidden {
    transform: translateY(140%) scale(0.92);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.45s var(--fm-ease),
                opacity 0.4s var(--fm-ease),
                visibility 0s linear 0.45s;
}

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 600px) {
    .floating-menu-btn {
        bottom: 18px;
        inset-inline-end: 175px;
    }
    [dir="rtl"] .floating-menu-btn { left: 30px; right: auto; }
    [dir="ltr"] .floating-menu-btn { right: 30px; left: auto; }

    .floating-menu-btn__trigger {
        width: 48px;
        height: 48px;
    }

    .floating-menu-btn__tooltip {
        font-size: 0.78rem;
        padding: 7px 11px;
        max-width: 60vw;
        white-space: normal;
        text-align: center;
        line-height: 1.3;
    }

    .floating-menu-panel {
        width: min(280px, calc(100vw - 40px));
    }
}

@media (max-width: 420px) {
    .floating-menu-btn { inset-inline-end: 158px; }
    [dir="rtl"] .floating-menu-btn { left: 30px; }
    [dir="ltr"] .floating-menu-btn { right: 30px; }
}

@media (prefers-reduced-motion: reduce) {
    .floating-menu-btn__pulse,
    .floating-menu-btn__tooltip,
    .floating-menu-btn__tooltip i,
    .floating-menu-btn__trigger,
    .floating-menu-panel,
    .floating-menu-panel__link {
        animation: none !important;
        transition: opacity 0.2s linear, visibility 0s linear !important;
    }
}
