/**
 * Unified Navbar - Mobile-First Responsive Enhancement
 * Improves upon existing navbar with better mobile UX and progressive enhancement
 */

/* ========================================
   BASE / MOBILE STYLES (320px+)
   ======================================== */

.unified-navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(220, 20, 60, 0.2);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    min-height: 4rem;
    max-height: 4rem;
}

/* ========================================
   LOGO SECTION - Mobile Optimized
   ======================================== */

.navbar-logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    transition: opacity 0.2s;
    gap: 0.5rem;
    z-index: 1002;
    height: 2.5rem;
    max-height: 2.5rem;
    overflow: visible;
    position: relative;
    width: auto;
    background-color: #000000;
    padding: 0.5rem 1rem;
    border-radius: 4px;
}

.navbar-logo:hover {
    opacity: 0.8;
}

.logo-image {
    height: 2.5rem !important;
    width: auto !important;
    max-width: 15rem !important;
    object-fit: contain;
    object-position: center;
    display: block;
    max-height: 2.5rem;
    background-color: #000000;
    mix-blend-mode: normal;
}

.logo-text {
    font-family: 'UniformExtraCondensed', sans-serif;
    font-size: 1.1rem;
    font-weight: normal;
    color: #DC143C;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ========================================
   MOBILE MENU TOGGLE - Enhanced (Hamburger Menu)
   ======================================== */

.mobile-menu-toggle {
    display: flex !important; /* Always show on mobile */
    flex-direction: column;
    justify-content: space-around;
    gap: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    z-index: 1002;
    width: 40px;
    height: 40px;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.mobile-menu-toggle span {
    display: block;
    width: 24px;
    height: 2px;
    background: rgba(255, 255, 255, 0.9);
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    border-radius: 2px;
    transform-origin: center;
}

/* Animated hamburger to X */
.mobile-menu-toggle.active span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* ========================================
   NAVIGATION LINKS - Mobile Menu
   ======================================== */

.navbar-links {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 100vh;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.98);
    backdrop-filter: blur(20px);
    padding: 5rem 2rem 4rem 2rem;
    gap: 0;
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease-in-out;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 1001;
    display: flex;
    justify-content: flex-start;
}

.navbar-links.mobile-open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: all;
}

/* Style auth buttons inside mobile menu */
.navbar-links .mobile-menu-buttons {
    display: flex !important;
    flex-direction: column;
    width: 100%;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.navbar-links .mobile-menu-buttons .nav-btn {
    width: 100%;
    display: block;
}

.public-links,
.auth-links {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 0;
}

.nav-link {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    font-size: 1.05rem;
    transition: all 0.2s;
    font-weight: 500;
    width: 100%;
    padding: 1rem 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    -webkit-tap-highlight-color: transparent;
}

.nav-link:active {
    background: rgba(220, 20, 60, 0.1);
}

.nav-link:last-child {
    border-bottom: none;
}

.nav-link:hover {
    color: #DC143C;
    padding-left: 1.25rem;
    background: rgba(220, 20, 60, 0.05);
}

.nav-link.admin-only {
    color: rgba(255, 200, 100, 0.9);
    background: rgba(255, 200, 100, 0.05);
}

.nav-link.admin-only:hover {
    color: #FFD700;
    background: rgba(255, 200, 100, 0.1);
}

/* ========================================
   USER SECTION - Mobile
   ======================================== */

.navbar-user-section {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    z-index: 1002;
}

/* Hide detailed user info on mobile (but allow JS to show it on tablet+) */
#navbar-user-info {
    display: none;
}

/* Clerk User Button - Always visible */
#navbar-clerk-button {
    display: flex;
    align-items: center;
}

/* ========================================
   AUTH BUTTONS - Mobile (Hidden by default, shown in menu)
   ======================================== */

.navbar-auth-buttons {
    display: none; /* Hide on mobile - shown in mobile menu or overridden by JS */
}

.nav-btn {
    padding: 0.9rem 1.5rem;
    border-radius: 10px;
    font-family: 'CartographMono', monospace;
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
    display: block;
    text-align: center;
    cursor: pointer;
    width: 100%;
    -webkit-tap-highlight-color: transparent;
}

.nav-btn-primary {
    background: #bd001b;
    color: #fff;
    border: none;
    box-shadow: 0 4px 20px rgba(220, 20, 60, 0.4);
}

.nav-btn-primary:active {
    transform: scale(0.98);
}

.nav-btn-secondary {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.9);
}

.nav-btn-secondary:active {
    background: rgba(255, 255, 255, 0.05);
}

/* ========================================
   MOBILE - SMALL (375px+)
   ======================================== */

@media (min-width: 375px) {
    .nav-container {
        max-height: 3.75rem;
        padding: 2.5rem;
    }
    
    .navbar-logo {
        height: 2.25rem;
        max-height: 2.25rem;
    }
    
    .logo-image {
        height: 2.25rem !important;
        max-width: 14rem !important;
        width: auto !important;
    }

    .logo-text {
        font-size: 1.15rem;
    }

    .nav-link {
        font-size: 1.1rem;
        padding: 1.1rem 0.75rem;
    }
}

/* ========================================
   MOBILE - MEDIUM (425px+)
   ======================================== */

@media (min-width: 425px) {
    .nav-container {
        padding: 2.5rem;
        max-height: 3.75rem;
    }
    
    .navbar-logo {
        height: 2.25rem;
        max-height: 2.25rem;
    }

    .logo-image {
        height: 2.25rem !important;
        max-width: 14rem !important;
        width: auto !important;
    }

    .logo-text {
        font-size: 1.2rem;
    }

    .navbar-links {
        padding: 2rem 1.5rem;
    }

    .nav-btn {
        padding: 1rem 1.75rem;
        font-size: 1rem;
    }
}

/* ========================================
   TABLET - SMALL (640px+)
   ======================================== */

@media (min-width: 640px) {
    .nav-container {
        padding: 2.5rem;
        max-height: 4rem;
    }
    
    .navbar-logo {
        height: 2.5rem;
        max-height: 2.5rem;
    }

    .logo-image {
        height: 2.5rem !important;
        max-width: 15rem !important;
        width: auto !important;
    }

    .logo-text {
        font-size: 1.25rem;
    }

    .navbar-links {
        top: 3.75rem;
        padding: 2.5rem 2rem;
    }

    .nav-link {
        font-size: 1.15rem;
        padding: 1.2rem 1rem;
    }

    .navbar-auth-buttons {
        margin-top: 2.5rem;
        padding-top: 2rem;
    }
}

/* ========================================
   TABLET - MEDIUM (768px+)
   ======================================== */

@media (min-width: 768px) {
    /* Transition to horizontal layout */
    .nav-container {
        padding: 2.5rem;
        max-height: 4rem;
    }

    .navbar-logo {
        display: flex;
        height: 2.5rem;
        max-height: 2.5rem;
    }

    .logo-image {
        height: 2.5rem !important;
        max-width: 15rem !important;
        width: auto !important;
    }

    .logo-text {
        font-size: 1.4rem;
        gap: 0.75rem;
    }

    /* Hide mobile menu toggle on tablet+ */
    .mobile-menu-toggle {
        display: none !important;
    }

    /* Horizontal navigation */
    .navbar-links {
        position: static;
        flex-direction: row;
        background: transparent;
        backdrop-filter: none;
        padding: 0;
        gap: 1.5rem;
        transform: none;
        opacity: 1;
        pointer-events: all;
        overflow: visible;
    }

    .public-links,
    .auth-links {
        flex-direction: row;
        width: auto;
        gap: 1.5rem;
    }

    .nav-link {
        width: auto;
        padding: 0.5rem 0;
        border-bottom: none;
        font-size: 0.9rem;
        justify-content: flex-start;
    }

    .nav-link:hover {
        padding-left: 0;
        background: transparent;
    }

    .nav-link.admin-only {
        background: transparent;
    }

    .nav-link.admin-only:hover {
        background: transparent;
    }

    /* User section layout for tablet+ (visibility controlled by JS) */
    #navbar-user-info {
        font-size: 0.85rem;
        padding: 0.65rem 1rem;
    }

    .user-plan-badge,
    .user-credits-badge {
        font-size: 0.7rem;
        padding: 0.2rem 0.65rem;
    }

    /* Auth buttons horizontal - Layout for tablet+ (visibility controlled by JS) */
    .navbar-auth-buttons {
        flex-direction: row;
        width: auto;
        gap: 0.75rem;
        margin-top: 0;
        padding-top: 0;
        border-top: none;
    }

    .nav-btn {
        width: auto;
        padding: 0.7rem 1.4rem;
        font-size: 0.9rem;
    }

    .navbar-user-section {
        gap: 1rem;
    }
}

/* ========================================
   DESKTOP - SMALL (1024px+)
   ======================================== */

@media (min-width: 1024px) {
    .navbar-links {
        gap: 2rem;
    }

    .public-links,
    .auth-links {
        gap: 2rem;
    }

    .nav-link {
        font-size: 0.95rem;
    }

    .nav-link:hover {
        transform: translateY(-1px);
    }

    #navbar-user-info {
        font-size: 0.9rem;
        padding: 0.75rem 1.25rem;
    }

    .user-plan-badge,
    .user-credits-badge {
        font-size: 0.75rem;
        padding: 0.25rem 0.75rem;
    }

    .nav-btn {
        padding: 0.75rem 1.5rem;
    }

    .nav-btn-primary:hover {
        background: #E8303C;
        color: #fff;
        transform: translateY(-2px);
        box-shadow: 0 8px 32px rgba(220, 20, 60, 0.6);
    }

    .nav-btn-secondary:hover {
        border-color: #DC143C;
        color: #DC143C;
    }
}

/* ========================================
   DESKTOP - LARGE (1280px+)
   ======================================== */

@media (min-width: 1280px) {
    .navbar-links {
        gap: 2.5rem;
    }

    .public-links,
    .auth-links {
        gap: 2.5rem;
    }

    .nav-link {
        font-size: 1rem;
    }
}

/* ========================================
   LANDSCAPE MOBILE OPTIMIZATION
   ======================================== */

@media (max-height: 600px) and (max-width: 767px) and (orientation: landscape) {
    .navbar-links {
        top: 50px;
        padding: 1rem;
    }

    .nav-link {
        padding: 0.75rem 0.5rem;
        font-size: 0.95rem;
    }

    .navbar-auth-buttons {
        margin-top: 1rem;
        padding-top: 1rem;
    }

    .nav-btn {
        padding: 0.7rem 1.25rem;
        font-size: 0.9rem;
    }
}

/* ========================================
   TOUCH DEVICE OPTIMIZATIONS
   ======================================== */

@media (hover: none) and (pointer: coarse) {
    /* Larger tap targets */
    .nav-link {
        padding: 1.25rem 0.75rem;
        min-height: 48px;
    }

    .nav-btn {
        min-height: 48px;
        padding: 0.9rem 1.5rem;
    }

    .mobile-menu-toggle {
        min-width: 48px;
        min-height: 48px;
    }

    /* Remove hover effects on touch */
    .nav-link:hover {
        padding-left: 0.75rem;
    }

    /* Prevent double-tap zoom */
    a, button {
        touch-action: manipulation;
    }
}

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

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .navbar-links {
        transition: opacity 0.15s ease;
    }

    .mobile-menu-toggle span {
        transition: none;
    }
}

/* ========================================
   HIGH CONTRAST MODE
   ======================================== */

@media (prefers-contrast: high) {
    .unified-navbar {
        background: rgba(0, 0, 0, 1);
        border-bottom: 2px solid rgba(220, 20, 60, 0.5);
    }

    .navbar-links {
        background: rgba(0, 0, 0, 1);
    }

    .nav-link {
        color: rgba(255, 255, 255, 1);
        border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    }

    .nav-btn-secondary {
        border: 2px solid rgba(255, 255, 255, 0.6);
    }
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

.hidden {
    display: none !important;
}

.visible {
    display: flex !important;
}

/* Adjust page content for fixed navbar */
body {
    padding-top: 55px;
}

@media (min-width: 640px) {
    body {
        padding-top: 4rem;
    }
}

@media (min-width: 768px) {
    body {
        padding-top: 4rem;
    }
}

/* ========================================
   MOBILE MENU OVERLAY (Optional Enhancement)
   ======================================== */

.nav-overlay {
    display: none;
    position: fixed;
    top: 55px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.nav-overlay.active {
    display: block;
    opacity: 1;
    pointer-events: all;
}

@media (min-width: 768px) {
    .nav-overlay {
        display: none !important;
    }
}

/* ========================================
   LOADING STATE
   ======================================== */

.navbar-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, #DC143C 0%, #FF5733 50%, #DC143C 100%);
    background-size: 200% 100%;
    animation: loading-animation 2s linear infinite;
    opacity: 0;
    transition: opacity 0.3s;
}

.navbar-loading.active {
    opacity: 1;
}

@keyframes loading-animation {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ========================================
   SCROLL BEHAVIOR
   ======================================== */

.unified-navbar.scrolled {
    background: rgba(0, 0, 0, 0.98);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.unified-navbar.scrolled .navbar-links {
    background: rgba(0, 0, 0, 0.99);
}
