/**
 * Premium Bonds Calculator - Hamburger Menu for Mobile (FIXED)
 * Responsive navigation menu for mobile devices - Updated to fix overlapping
 */

/* ========================================
   HAMBURGER MENU BUTTON
   ======================================== */

.mobile-menu-toggle {
    display: none; /* Hidden by default */
    position: relative;
    width: 44px;
    height: 44px;
    padding: 10px;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 1001;
    transition: transform 0.3s ease;
    flex-shrink: 0; /* Prevent button from shrinking */
}

.mobile-menu-toggle:hover {
    transform: scale(1.05);
}

.mobile-menu-toggle:focus {
    outline: 2px solid var(--primary, #003366);
    outline-offset: 2px;
}

/* Hamburger Icon Lines */
.hamburger-icon {
    position: relative;
    display: block;
    width: 24px;
    height: 2px;
    background-color: var(--primary, #003366);
    transition: background-color 0.3s ease;
}

.hamburger-icon::before,
.hamburger-icon::after {
    content: '';
    position: absolute;
    left: 0;
    width: 24px;
    height: 2px;
    background-color: var(--primary, #003366);
    transition: transform 0.3s ease, top 0.3s ease, bottom 0.3s ease;
}

.hamburger-icon::before {
    top: -8px;
}

.hamburger-icon::after {
    bottom: -8px;
}

/* Animated X when menu is open */
.mobile-menu-toggle.active .hamburger-icon {
    background-color: transparent;
}

.mobile-menu-toggle.active .hamburger-icon::before {
    top: 0;
    transform: rotate(45deg);
}

.mobile-menu-toggle.active .hamburger-icon::after {
    bottom: 0;
    transform: rotate(-45deg);
}

/* For dark headers */
header.theme-d3 .hamburger-icon,
header.theme-d3 .hamburger-icon::before,
header.theme-d3 .hamburger-icon::after,
header.theme-d5 .hamburger-icon,
header.theme-d5 .hamburger-icon::before,
header.theme-d5 .hamburger-icon::after,
nav.theme-d5 .hamburger-icon,
nav.theme-d5 .hamburger-icon::before,
nav.theme-d5 .hamburger-icon::after {
    background-color: white;
}

/* ========================================
   MOBILE MENU OVERLAY
   ======================================== */

.mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-menu-overlay.active {
    display: block;
    opacity: 1;
}

/* ========================================
   MOBILE MENU PANEL
   ======================================== */

.mobile-menu {
    display: none;
    position: fixed;
    top: 0;
    right: -100%;
    width: 80%;
    max-width: 300px;
    height: 100vh;
    background: white;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-menu.active {
    display: block;
    right: 0;
}

/* For dark headers */
header.theme-d3 ~ .mobile-menu,
nav.theme-d3 ~ .mobile-menu {
    background: #002244;
    color: white;
}

header.theme-d5 ~ .mobile-menu,
nav.theme-d5 ~ .mobile-menu {
    background: #001122;
    color: white;
}

/* ========================================
   MOBILE MENU HEADER
   ======================================== */

.mobile-menu-header {
    padding: 1.5rem 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: linear-gradient(135deg, var(--primary, #003366), var(--primary-light, #004080));
}

header.theme-d3 ~ .mobile-menu .mobile-menu-header,
header.theme-d5 ~ .mobile-menu .mobile-menu-header,
nav.theme-d3 ~ .mobile-menu .mobile-menu-header,
nav.theme-d5 ~ .mobile-menu .mobile-menu-header {
    background: rgba(0, 0, 0, 0.2);
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

.mobile-menu-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    margin: 0;
}

.mobile-menu-subtitle {
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.8);
    margin: 0.25rem 0 0 0;
}

/* ========================================
   MOBILE MENU NAVIGATION
   ======================================== */

.mobile-menu-nav {
    padding: 1rem 0;
}

.mobile-menu-nav a {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    color: var(--gray-800, #262626);
    text-decoration: none;
    font-size: 1rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
}

header.theme-d3 ~ .mobile-menu .mobile-menu-nav a,
header.theme-d5 ~ .mobile-menu .mobile-menu-nav a,
nav.theme-d3 ~ .mobile-menu .mobile-menu-nav a,
nav.theme-d5 ~ .mobile-menu .mobile-menu-nav a {
    color: white;
}

.mobile-menu-nav a:hover {
    background: rgba(0, 51, 102, 0.05);
    border-left-color: var(--primary, #003366);
    padding-left: 1.75rem;
}

header.theme-d3 ~ .mobile-menu .mobile-menu-nav a:hover,
header.theme-d5 ~ .mobile-menu .mobile-menu-nav a:hover,
nav.theme-d3 ~ .mobile-menu .mobile-menu-nav a:hover,
nav.theme-d5 ~ .mobile-menu .mobile-menu-nav a:hover {
    background: rgba(255, 255, 255, 0.1);
    border-left-color: var(--primary-light, #4da3ff);
}

.mobile-menu-nav a.active {
    background: rgba(0, 51, 102, 0.1);
    border-left-color: var(--primary, #003366);
    color: var(--primary, #003366);
    font-weight: 600;
}

header.theme-d3 ~ .mobile-menu .mobile-menu-nav a.active,
header.theme-d5 ~ .mobile-menu .mobile-menu-nav a.active,
nav.theme-d3 ~ .mobile-menu .mobile-menu-nav a.active,
nav.theme-d5 ~ .mobile-menu .mobile-menu-nav a.active {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

/* Badge styling (for Checker) */
.mobile-menu-nav a .badge-1k {
    margin-left: auto;
    font-size: 0.65rem;
    padding: 0.2rem 0.5rem;
    background: var(--warning, #ff9800);
    color: white;
    border-radius: 3px;
    font-weight: 700;
}

/* ========================================
   MOBILE MENU FOOTER
   ======================================== */

.mobile-menu-footer {
    padding: 1.5rem;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

header.theme-d3 ~ .mobile-menu .mobile-menu-footer,
header.theme-d5 ~ .mobile-menu .mobile-menu-footer,
nav.theme-d3 ~ .mobile-menu .mobile-menu-footer,
nav.theme-d5 ~ .mobile-menu .mobile-menu-footer {
    border-top-color: rgba(255, 255, 255, 0.1);
}

.mobile-menu-footer a {
    display: block;
    padding: 0.75rem 1rem;
    background: var(--primary, #003366);
    color: white;
    text-align: center;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s ease;
}

.mobile-menu-footer a:hover {
    background: var(--primary-light, #004080);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.mobile-menu-footer .coffee-button {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.mobile-menu-footer small {
    display: block;
    text-align: center;
    color: var(--gray-500, #737373);
    font-size: 0.75rem;
    margin-top: 1rem;
}

header.theme-d3 ~ .mobile-menu .mobile-menu-footer small,
header.theme-d5 ~ .mobile-menu .mobile-menu-footer small,
nav.theme-d3 ~ .mobile-menu .mobile-menu-footer small,
nav.theme-d5 ~ .mobile-menu .mobile-menu-footer small {
    color: rgba(255, 255, 255, 0.6);
}

/* ========================================
   RESPONSIVE BEHAVIOR - CRITICAL FIXES
   ======================================== */

@media (max-width: 768px) {
    /* Show hamburger menu on mobile */
    .mobile-menu-toggle {
        display: block !important;
    }

    /* CRITICAL FIX: Hide ALL desktop navigation content */
    nav .nav-links,
    nav > div:not(.mobile-menu-toggle) {
        display: none !important;
    }
    
    /* Special handling for inline nav divs with theme classes */
    nav.theme-d5 > div,
    nav.theme-d3 > div {
        display: none !important;
    }
    
    /* But keep nav element itself for hamburger button */
    nav {
        display: flex !important;
        align-items: center;
        justify-content: flex-end;
        width: auto;
        overflow: visible;
        min-height: 44px;
        position: static !important;
        background: transparent !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    /* Keep hamburger button visible */
    nav .mobile-menu-toggle {
        display: block !important;
    }

    /* Fix header layout for mobile */
    header {
        padding: 1rem !important;
    }
    
    /* Header container adjustments */
    .header-container,
    header > div:first-child {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        flex-wrap: nowrap;
        width: 100%;
    }
    
    /* Header with integrated nav (theme-d3/d5) */
    header.theme-d3,
    header.theme-d5 {
        position: relative;
    }
    
    header.theme-d3 nav,
    header.theme-d5 nav {
        position: absolute !important;
        top: 1rem;
        right: 1rem;
        background: transparent !important;
        padding: 0 !important;
    }
    
    /* Adjust header title for mobile */
    header h1 {
        font-size: 1.25rem !important;
        margin: 0;
        max-width: calc(100% - 60px); /* Leave space for hamburger */
    }
    
    header h1 .line {
        display: inline;
        margin-right: 0.25rem;
    }
}

@media (min-width: 769px) {
    /* Ensure mobile menu is hidden on desktop */
    .mobile-menu,
    .mobile-menu-overlay,
    .mobile-menu-toggle {
        display: none !important;
    }
    
    /* Show desktop navigation */
    nav .nav-links,
    nav > div {
        display: flex !important;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

.mobile-menu-toggle:focus-visible {
    outline: 2px solid var(--primary, #003366);
    outline-offset: 2px;
    border-radius: 4px;
}

.mobile-menu-nav a:focus-visible {
    outline: 2px solid var(--primary, #003366);
    outline-offset: -2px;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ========================================
   ANIMATIONS
   ======================================== */

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.mobile-menu.active {
    animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-menu-overlay.active {
    animation: fadeIn 0.3s ease;
}

/* ========================================
   PREVENT BODY SCROLL WHEN MENU OPEN
   ======================================== */

body.mobile-menu-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* ========================================
   SAFE AREA INSETS (iPhone X+)
   ======================================== */

@supports (padding: max(0px)) {
    .mobile-menu {
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }

    .mobile-menu-header {
        padding-top: max(1.5rem, env(safe-area-inset-top));
    }
}

/* ========================================
   REDUCED MOTION
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .mobile-menu,
    .mobile-menu-overlay,
    .hamburger-icon,
    .hamburger-icon::before,
    .hamburger-icon::after {
        transition: none !important;
        animation: none !important;
    }
}
