/* ========================================
   UNIFIED FLOATING ELEMENTS
   St. Lawrence Junior School - Kabowa
   
   Clean, conflict-free floating elements
   with proper z-index hierarchy & perfect vertical alignment
   ======================================== */

/* ========== Z-INDEX HIERARCHY ========== */
:root {
    --z-sweetalert: 999999;      /* SweetAlert modals - highest priority */
    --z-hamburger: 10000;        /* Mobile hamburger menu */
    --z-back-to-top: 10001;      /* Back to top button - above chatbot */
    --z-chatbot: 9999;           /* AI chatbot button */
    --z-page-loader: 9997;       /* Page loading screen */
    --z-dropdown: 1000;          /* Navigation dropdowns */
}

/* ========== BACK-TO-TOP BUTTON (REDUCED & COMPACT) ========== */
.back-to-top,
#backToTop {
    position: fixed;
    bottom: 24px;
    right: 27px;
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    background: #dc3545;
    color: #ffffff;
    border: none;
    border-radius: 50%;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-back-to-top);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease, background 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 3px 10px rgba(220, 53, 69, 0.35);
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.back-to-top.show,
#backToTop.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover,
#backToTop:hover {
    background: #c82333;
    transform: translateY(-2px);
    box-shadow: 0 5px 14px rgba(220, 53, 69, 0.45);
}

/* ========== CHATBOT BUTTON (COMPACT & SLEEK) ========== */
.chat-button,
#chatButton {
    position: fixed;
    bottom: 68px;
    right: 24px;
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    background: linear-gradient(135deg, #0066cc 0%, #0052a3 100%);
    border-radius: 50%;
    box-shadow: 0 4px 14px rgba(0, 102, 204, 0.35);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-chatbot);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: 2px solid #ffffff;
    opacity: 1;
    visibility: visible;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.chat-button:hover,
#chatButton:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 102, 204, 0.45);
}

.chat-button img,
#chatButton img {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: contain;
    display: block;
    pointer-events: none;
    margin: 0 auto;
}

/* Red notification dot */
.chat-button .chat-unread-dot,
#chatButton .chat-unread-dot {
    position: absolute;
    top: 1px;
    right: 1px;
    width: 7.5px;
    height: 7.5px;
    background: #dc3545;
    border: 1.5px solid #ffffff;
    border-radius: 50%;
    pointer-events: none;
}

/* ========== HAMBURGER MENU ========== */
.hamburger,
#hamburger {
    z-index: var(--z-hamburger) !important;
}

.nav-menu,
#navMenu {
    z-index: calc(var(--z-hamburger) - 1) !important;
}

/* ========== MOBILE RESPONSIVE (PERFECT VERTICAL ALIGNMENT) ========== */
@media (max-width: 768px) {
    /* Reset margins & left position */
    .chat-button,
    #chatButton,
    .back-to-top,
    #backToTop {
        left: auto;
        margin: 0;
        margin-right: 0;
        margin-left: 0;
        box-sizing: border-box;
    }

    /* Back-to-top: reduced to 34px, center-aligned below chatbot */
    .back-to-top,
    #backToTop {
        width: 34px;
        height: 34px;
        min-width: 34px;
        min-height: 34px;
        bottom: 18px;
        right: 20px;
        font-size: 13px;
    }

    /* Chatbot: 38px, directly above back-to-top with 8px vertical gap */
    .chat-button,
    #chatButton {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
        bottom: 60px;
        right: 18px;
    }

    .chat-button img,
    #chatButton img {
        width: 24px;
        height: 24px;
    }
}

/* ========== SAFE AREA SUPPORT ========== */
@supports (bottom: env(safe-area-inset-bottom)) {
    .back-to-top,
    #backToTop {
        bottom: max(24px, calc(18px + env(safe-area-inset-bottom, 0px)));
        right: max(27px, calc(21px + env(safe-area-inset-right, 0px)));
    }
    
    .chat-button,
    #chatButton {
        bottom: max(68px, calc(62px + env(safe-area-inset-bottom, 0px)));
        right: max(24px, calc(18px + env(safe-area-inset-right, 0px)));
    }
    
    @media (max-width: 768px) {
        /* Back-to-top center-aligned with chatbot */
        .back-to-top,
        #backToTop {
            right: max(20px, calc(16px + env(safe-area-inset-right, 0px)));
            bottom: max(18px, calc(14px + env(safe-area-inset-bottom, 0px)));
            left: auto;
            margin: 0;
        }

        /* Chatbot stacked directly above */
        .chat-button,
        #chatButton {
            right: max(18px, calc(14px + env(safe-area-inset-right, 0px)));
            bottom: max(60px, calc(56px + env(safe-area-inset-bottom, 0px)));
            left: auto;
            margin: 0;
        }
    }
}