/**
 * AnchorExchange Bottom Navigation
 * iOS-style sticky bottom navigation bar
 * Version: 1.0
 * 
 * Features:
 * - Sticky bottom navigation (like iOS apps)
 * - Expandable Browse menu
 * - Smooth animations
 * - Touch-friendly on all devices
 */

/* ============================================
   BOTTOM NAVIGATION BAR
   ============================================ */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #ffffff;
    border-top: 1px solid rgba(0, 61, 92, 0.1);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
    z-index: var(--z-fixed, 1030);
    padding: 0.25rem 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    /* iOS safe area support */
    padding-bottom: calc(0.25rem + env(safe-area-inset-bottom));
    transition: all 0.3s ease-in-out;
}

/* Racing stripe accent at top */
.bottom-nav::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: repeating-linear-gradient(
        90deg,
        #003d5c 0px,
        #003d5c 4px,
        #0077be 4px,
        #0077be 8px
    );
}

/* Bottom nav item */
.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.375rem 0.25rem;
    color: #6c757d;
    text-decoration: none;
    transition: all 0.3s ease-in-out;
    position: relative;
    min-height: 48px;
    -webkit-tap-highlight-color: transparent;
    border: none;
    background: none;
    cursor: pointer;
    font-family: inherit;
}

.bottom-nav-item:focus {
    outline: none;
}

.bottom-nav-item i {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
    transition: all 0.3s ease-in-out;
}

.bottom-nav-item span {
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1;
    transition: all 0.3s ease-in-out;
    opacity: 1;
    max-height: 1.2em;
    overflow: hidden;
}

/* Collapsed state - slim mode */
.bottom-nav.collapsed {
    padding: 0.1rem 0;
    padding-bottom: calc(0.1rem + env(safe-area-inset-bottom));
    border-top-width: 0;
    box-shadow: 0 -1px 6px rgba(0, 0, 0, 0.05);
}

.bottom-nav.collapsed::before {
    height: 2px;
    opacity: 0.5;
}

.bottom-nav.collapsed .bottom-nav-item {
    min-height: 28px;
    padding: 0.15rem 0.25rem;
}

.bottom-nav.collapsed .bottom-nav-item i {
    font-size: 1.5rem; /* Keep original size for transform */
    margin-bottom: 0;
    transform: scale(0.45); /* 45% size - smaller */
}

.bottom-nav.collapsed .bottom-nav-item span {
    opacity: 0;
    max-height: 0;
    margin: 0;
    font-size: 0;
    overflow: hidden;
}

/* Active state */
.bottom-nav-item.active {
    color: #0077be;
}

.bottom-nav-item.active i {
    transform: scale(1.1);
}

.bottom-nav-item.active span {
    font-weight: 600;
}

/* Hover state (desktop) */
@media (hover: hover) {
    .bottom-nav-item:hover {
        color: #0077be;
    }
    
    .bottom-nav-item:hover i {
        transform: scale(1.1);
    }
}

/* Active tap effect */
.bottom-nav-item:active {
    transform: scale(0.95);
    opacity: 0.8;
}

/* ============================================
   BROWSE MENU (EXPANDABLE)
   ============================================ */

.bottom-nav-browse-wrapper {
    position: relative;
}

.bottom-nav-browse-menu {
    position: absolute;
    bottom: calc(100% + 0.5rem);
    left: 50%;
    transform: translateX(-50%);
    background-color: #ffffff;
    border-radius: 1rem;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.15);
    min-width: 280px;
    max-width: calc(100vw - 2rem);
    padding: 0.75rem;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%) translateY(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    pointer-events: none;
    border: 1px solid rgba(0, 61, 92, 0.1);
    box-sizing: border-box;
}

/* Mobile & Tablet: Center menus to viewport for full text visibility */
@media (max-width: 991px) {
    .bottom-nav-browse-menu {
        position: fixed !important;
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) translateY(10px) !important;
        max-width: calc(100vw - 2rem) !important;
        width: calc(100vw - 2rem) !important;
        min-width: auto !important;
        margin: 0 !important;
        bottom: calc(70px + 0.5rem) !important;
    }
    
    .bottom-nav-browse-menu.active {
        transform: translateX(-50%) translateY(0) !important;
    }
    
    /* Arrow repositioning for centered menu */
    .bottom-nav-browse-menu::before {
        left: 50% !important;
        transform: translateX(-50%) !important;
    }
}

/* Extra small screens - reduce width further */
@media (max-width: 480px) {
    .bottom-nav-browse-menu {
        width: calc(100vw - 2rem) !important;
        max-width: calc(100vw - 2rem) !important;
        min-width: 200px !important;
        padding: 0.625rem !important;
    }
}

.bottom-nav-browse-menu::before {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #ffffff;
}

.bottom-nav-browse-menu.active {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0) !important;
    pointer-events: all;
}

.bottom-nav-browse-item {
    display: flex;
    align-items: center;
    padding: 0.875rem 1rem;
    color: #1a1a1a;
    text-decoration: none;
    border-radius: 0.5rem;
    transition: all 0.2s ease-in-out;
    margin-bottom: 0.25rem;
    font-size: 0.9375rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Mobile: Allow text wrapping and reduce padding */
@media (max-width: 991px) {
    .bottom-nav-browse-item {
        white-space: normal;
        padding: 0.75rem 0.875rem;
        font-size: 0.875rem;
    }
}

.bottom-nav-browse-item:last-child {
    margin-bottom: 0;
}

.bottom-nav-browse-item i {
    font-size: 1.25rem;
    margin-right: 0.75rem;
    color: #0077be;
    width: 24px;
    min-width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.bottom-nav-browse-item:hover,
.bottom-nav-browse-item:focus {
    background-color: rgba(0, 119, 190, 0.1);
    color: #0077be;
}

.bottom-nav-browse-item:active {
    background-color: rgba(0, 119, 190, 0.15);
    transform: scale(0.98);
}

/* ============================================
   ACCOUNT MENU (DROPDOWN)
   ============================================ */

.bottom-nav-account-menu {
    position: absolute;
    bottom: calc(100% + 0.5rem);
    left: 50%;
    transform: translateX(-50%);
    background-color: #ffffff;
    border-radius: 1rem;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.15);
    min-width: 240px;
    max-width: calc(100vw - 2rem);
    padding: 0.75rem;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%) translateY(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    pointer-events: none;
    border: 1px solid rgba(0, 61, 92, 0.1);
    box-sizing: border-box;
}

/* Mobile & Tablet: Center account menu to viewport */
@media (max-width: 991px) {
    .bottom-nav-account-menu {
        position: fixed !important;
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) translateY(10px) !important;
        max-width: calc(100vw - 2rem) !important;
        width: calc(100vw - 2rem) !important;
        min-width: auto !important;
        margin: 0 !important;
        bottom: calc(70px + 0.5rem) !important;
    }
    
    .bottom-nav-account-menu.active {
        transform: translateX(-50%) translateY(0) !important;
    }
    
    /* Arrow repositioning for centered menu */
    .bottom-nav-account-menu::before {
        left: 50% !important;
        transform: translateX(-50%) !important;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .bottom-nav-account-menu {
        width: calc(100vw - 2rem) !important;
        max-width: calc(100vw - 2rem) !important;
        min-width: 200px !important;
        padding: 0.625rem !important;
    }
}

.bottom-nav-account-menu::before {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #ffffff;
}

.bottom-nav-account-menu.active {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0) !important;
    pointer-events: all;
}

.bottom-nav-account-header {
    padding: 0.75rem;
    border-bottom: 1px solid rgba(0, 61, 92, 0.1);
    margin-bottom: 0.5rem;
}

.bottom-nav-account-name {
    font-weight: 600;
    color: #1a1a1a;
    font-size: 0.9375rem;
    margin-bottom: 0.25rem;
}

.bottom-nav-account-email {
    font-size: 0.8125rem;
    color: #6c757d;
}

.bottom-nav-account-item {
    display: flex;
    align-items: center;
    padding: 0.875rem 1rem;
    color: #1a1a1a;
    text-decoration: none;
    border-radius: 0.5rem;
    transition: all 0.2s ease-in-out;
    margin-bottom: 0.25rem;
    font-size: 0.9375rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Mobile: Allow text wrapping and reduce padding */
@media (max-width: 991px) {
    .bottom-nav-account-item {
        white-space: normal;
        padding: 0.75rem 0.875rem;
        font-size: 0.875rem;
    }
}

.bottom-nav-account-item:last-child {
    margin-bottom: 0;
}

.bottom-nav-account-item i {
    font-size: 1.125rem;
    margin-right: 0.75rem;
    color: #0077be;
    width: 24px;
    min-width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.bottom-nav-account-item:hover,
.bottom-nav-account-item:focus {
    background-color: rgba(0, 119, 190, 0.1);
    color: #0077be;
}

.bottom-nav-account-item.danger {
    color: #dc3545;
}

.bottom-nav-account-item.danger i {
    color: #dc3545;
}

.bottom-nav-account-item.danger:hover,
.bottom-nav-account-item.danger:focus {
    background-color: rgba(220, 53, 69, 0.1);
    color: #dc3545;
}

.bottom-nav-divider {
    height: 1px;
    background-color: rgba(0, 61, 92, 0.1);
    margin: 0.5rem 0;
}

/* ============================================
   GENERAL MENU (DROPDOWN)
   ============================================ */

.bottom-nav-general-menu {
    position: absolute;
    bottom: calc(100% + 0.5rem);
    left: 50%;
    transform: translateX(-50%);
    background-color: #ffffff;
    border-radius: 1rem;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.15);
    min-width: 240px;
    max-width: calc(100vw - 2rem);
    padding: 0.75rem;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%) translateY(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    pointer-events: none;
    border: 1px solid rgba(0, 61, 92, 0.1);
    box-sizing: border-box;
}

/* Mobile & Tablet: Center general menu to viewport */
@media (max-width: 991px) {
    .bottom-nav-general-menu {
        position: fixed !important;
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) translateY(10px) !important;
        max-width: calc(100vw - 2rem) !important;
        width: calc(100vw - 2rem) !important;
        min-width: auto !important;
        margin: 0 !important;
        bottom: calc(70px + 0.5rem) !important;
    }
    
    .bottom-nav-general-menu.active {
        transform: translateX(-50%) translateY(0) !important;
    }
    
    /* Arrow repositioning for centered menu */
    .bottom-nav-general-menu::before {
        left: 50% !important;
        transform: translateX(-50%) !important;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .bottom-nav-general-menu {
        width: calc(100vw - 2rem) !important;
        max-width: calc(100vw - 2rem) !important;
        min-width: 200px !important;
        padding: 0.625rem !important;
    }
}

.bottom-nav-general-menu::before {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #ffffff;
}

.bottom-nav-general-menu.active {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0) !important;
    pointer-events: all;
}

.bottom-nav-general-item {
    display: flex;
    align-items: center;
    padding: 0.875rem 1rem;
    color: #1a1a1a;
    text-decoration: none;
    border-radius: 0.5rem;
    transition: all 0.2s ease-in-out;
    margin-bottom: 0.25rem;
    font-size: 0.9375rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Mobile: Allow text wrapping and reduce padding */
@media (max-width: 991px) {
    .bottom-nav-general-item {
        white-space: normal;
        padding: 0.75rem 0.875rem;
        font-size: 0.875rem;
    }
}

.bottom-nav-general-item:last-child {
    margin-bottom: 0;
}

.bottom-nav-general-item i {
    font-size: 1.125rem;
    margin-right: 0.75rem;
    color: #0077be;
    width: 24px;
    min-width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.bottom-nav-general-item:hover,
.bottom-nav-general-item:focus {
    background-color: rgba(0, 119, 190, 0.1);
    color: #0077be;
}

/* ============================================
   SEARCH OVERLAY
   ============================================ */

.bottom-nav-search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1020;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease-in-out;
    backdrop-filter: blur(4px);
}

.bottom-nav-search-overlay.active {
    opacity: 1;
    visibility: visible;
}

.bottom-nav-search-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: #ffffff;
    padding: 1rem;
    padding-top: calc(1rem + env(safe-area-inset-top));
    z-index: 1021;
    transform: translateY(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.bottom-nav-search-container.active {
    transform: translateY(0);
}

.bottom-nav-search-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.bottom-nav-search-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #6c757d;
    cursor: pointer;
    padding: 0.5rem;
    line-height: 1;
    transition: color 0.2s ease-in-out;
}

.bottom-nav-search-close:hover,
.bottom-nav-search-close:focus {
    color: #0077be;
}

.bottom-nav-search-form {
    display: flex;
    gap: 0.75rem;
}

.bottom-nav-search-input {
    flex: 1;
    padding: 0.875rem 1rem;
    border: 2px solid rgba(0, 61, 92, 0.2);
    border-radius: 0.75rem;
    font-size: 1rem;
    transition: border-color 0.2s ease-in-out;
}

.bottom-nav-search-input:focus {
    outline: none;
    border-color: #0077be;
}

.bottom-nav-search-submit {
    padding: 0.875rem 1.5rem;
    background-color: #0077be;
    color: #ffffff;
    border: none;
    border-radius: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out;
}

.bottom-nav-search-submit:hover,
.bottom-nav-search-submit:focus {
    background-color: #003d5c;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

/* Note: Body padding for bottom nav is handled in global.css */

main {
    padding-bottom: 1rem;
}

/* Ensure bottom nav is always visible and properly layered */
body {
    padding-bottom: 60px;
    transition: padding-bottom 0.3s ease-in-out;
}

/* Reduce padding when nav is collapsed */
body:has(.bottom-nav.collapsed) {
    padding-bottom: 32px;
}

/* Fallback for browsers without :has() support */
.bottom-nav.collapsed ~ body {
    padding-bottom: 32px;
}

/* Fix for overlapping content */
.bottom-nav-force-visible {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Mobile - Apply collapsed state styles */
@media (max-width: 767px) {
    .bottom-nav.collapsed {
        padding: 0.08rem 0;
        padding-bottom: calc(0.08rem + env(safe-area-inset-bottom));
    }

    .bottom-nav.collapsed .bottom-nav-item {
        min-height: 24px;
        padding: 0.1rem 0.15rem;
    }

    .bottom-nav.collapsed .bottom-nav-item i {
        transform: scale(0.4); /* Even smaller on mobile */
    }

    body:has(.bottom-nav.collapsed) {
        padding-bottom: 28px;
    }
}

/* Tablet and Desktop - Show bottom nav but with better spacing */
@media (min-width: 768px) {
    .bottom-nav {
        justify-content: center;
        gap: 2rem;
        padding: 0.75rem 2rem;
    }

    .bottom-nav.collapsed {
        padding: 0.2rem 2rem;
        padding-bottom: calc(0.2rem + env(safe-area-inset-bottom));
    }

    .bottom-nav-item {
        max-width: 120px;
        padding: 0.75rem 0.5rem;
        flex: 0 0 auto;
    }

    .bottom-nav-item i {
        font-size: 1.75rem;
    }

    .bottom-nav-item span {
        font-size: 0.8125rem;
    }

    /* Better desktop menu positioning - center under button */
    .bottom-nav-browse-menu,
    .bottom-nav-account-menu,
    .bottom-nav-general-menu {
        left: 50%;
        transform: translateX(-50%);
    }
}

/* Large screens - Keep bottom nav for consistency */
@media (min-width: 1200px) {
    .bottom-nav {
        padding: 0.75rem 4rem;
        gap: 3rem;
    }
    
    .bottom-nav-item {
        max-width: 140px;
    }
}

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

/* Focus styles for keyboard navigation */
.bottom-nav-item:focus-visible {
    outline: 2px solid #0077be;
    outline-offset: -2px;
    border-radius: 0.5rem;
}

.bottom-nav-browse-item:focus-visible,
.bottom-nav-account-item:focus-visible,
.bottom-nav-general-item:focus-visible {
    outline: 2px solid #0077be;
    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;
}

