/* --- Header & Navbar --- */
header {
    background-color: var(--card-bg);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 2%;
    max-width: 1800px;
    margin: 0 auto;
    min-height: 60px;
    transition: justify-content 0.4s ease;
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-grow: 1;
    transition: opacity 0.4s ease, width 0.4s ease, overflow 0.4s ease;
}
.nav-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    transition: flex-grow 0.4s ease;
}

.logo a {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--text-color);
    font-weight: 600;
    font-size: 1.4rem;
}

.logo img {
    height: 35px;
    margin-right: 10px;
}

.nav-links {
    display: flex;
    list-style: none;
    gap: 2rem;
}

.nav-links a {
    text-decoration: none;
    color: var(--text-color);
    font-weight: 500;
    position: relative;
    padding-bottom: 5px;
}

.nav-links a::after {
    content: '';
    position: absolute;
    width: 0;
    height: 2px;
    bottom: 0;
    left: 0;
    background-color: var(--accent-color);
    transition: width 0.3s ease;
}

.nav-links a:hover::after {
    width: 100%;
}

.navbar-search {
    position: relative;
    width: 100%;
    max-width: 400px;
    margin-left: 1rem;
    transition: flex-grow 0.4s ease, max-width 0.4s ease;
}

.navbar-search input {
    width: 100%;
    padding: 0.5rem 1rem;
    padding-right: 2.5rem;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background-color: var(--search-bg);
    color: var(--text-color);
}

/* --- ADDED: Fix for browser autofill background in dark mode --- */
.navbar-search input:-webkit-autofill,
.navbar-search input:-webkit-autofill:hover, 
.navbar-search input:-webkit-autofill:focus, 
.navbar-search input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 30px var(--search-bg) inset !important;
    -webkit-text-fill-color: var(--text-color) !important;
    transition: background-color 5000s ease-in-out 0s;
}

.navbar-search input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 5px rgba(76, 175, 80, 0.5);
}

.navbar-search .search-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 0.5rem;
    font-size: 0.9rem;
}

.auth-toggle-btn {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    font-size: 1rem;
    cursor: pointer;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.auth-toggle-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
    transform: rotate(15deg);
}

.auth-buttons {
    display: flex;
    gap: 0.5rem;
    transition: opacity 0.4s ease, width 0.4s ease, overflow 0.4s ease;
}

.auth-link {
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    white-space: nowrap;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.auth-link.login-btn {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    color: var(--text-color);
}
.auth-link.login-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.auth-link.signup-btn {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}
.auth-link.signup-btn:hover {
    filter: brightness(1.15);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.avatar-container {
    position: relative;
    display: flex;
    justify-content: center;
    transition: opacity 0.4s ease, width 0.4s ease, overflow 0.4s ease;
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid var(--accent-color);
    transition: transform 0.2s ease;
}
.avatar:hover {
    transform: scale(1.1);
}

.dropdown-menu {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    left: 50%;
    top: 55px;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    width: 180px;
    z-index: 1001;
    overflow: hidden;
    transform: translate(-50%, 10px);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;
}

.dropdown-menu.show {
    visibility: visible;
    opacity: 1;
    transform: translate(-50%, 0);
}

.dropdown-menu::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid var(--card-bg);
    z-index: -1;
}

.dark-mode .dropdown-menu::before {
    border-bottom-color: var(--border-color);
}

.dropdown-menu a {
    display: flex;
    align-items: center;
    padding: 0.85rem 1.2rem;
    color: var(--text-color);
    text-decoration: none;
    font-size: 0.95rem;
    border-bottom: 1px solid var(--border-color);
}

.dropdown-menu a:last-child {
    border-bottom: none;
}

.dropdown-menu a:hover {
    background-color: var(--bg-color);
    padding-left: 1.5rem;
}

.dropdown-menu a i {
    margin-right: 10px;
    width: 18px;
    text-align: center;
}

.logged-in .auth-buttons,
.logged-out .avatar-container {
    display: none;
}


/* Add this to your header.css file */

.logout-form {
    margin: 0;
}

.logout-button {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.85rem 1.2rem;
    background-color: transparent;
    border: none;
    color: var(--text-color);
    font-size: 0.95rem;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
}

.logout-button:hover {
    background-color: var(--bg-color);
    padding-left: 1.5rem;
}

.logout-button i {
    margin-right: 10px;
    width: 18px;
    text-align: center;
}


.theme-btn {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    transition: transform 0.3s ease, opacity 0.4s ease, width 0.4s ease, overflow 0.4s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.theme-btn:hover {
    transform: scale(1.2);
}

.theme-btn svg {
    width: 1.2rem;
    height: 1.2rem;
    display: block;
}

.menu-btn {
    display: none;
    font-size: 1.5rem;
    cursor: pointer;
}

.sub-nav {
    background-color: var(--sub-nav-bg);
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
    -ms-overflow-style: none;
    scrollbar-width: none;
    border-top: 1px solid var(--border-color);
    min-height: 40px;
}
.sub-nav::-webkit-scrollbar {
    display: none;
}

.sub-nav a {
    padding: 0.5rem 1.5rem;
    color: white;
    text-decoration: none;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.sub-nav a:hover {
    background-color: var(--accent-color);
}

.mobile-nav-menu {
    display: none;
}

/* --- Header Responsive Design --- */
@media (max-width: 1024px) { 
    .navbar {
        padding: 0.8rem 4%;
        gap: 1rem;
    }
    
    .nav-left {
        flex-grow: 0;
    }

    .nav-right {
        flex-grow: 1;
        justify-content: flex-end;
        gap: 1rem;
    }

    .menu-btn { 
        display: block; 
    } 

    .nav-links {
        display: none;
    }

    .auth-toggle-btn {
        display: none;
    }

    .navbar-search {
        max-width: 200px;
        margin-left: 0;
        display: block;
    }

    .navbar-search input {
        padding: 0.4rem 0.8rem;
        padding-right: 2.2rem;
        height: 35px;
    }

    .auth-link {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }

    .sub-nav {
        border-top: none;
    }

    /* --- Slide-out Menu Styles --- */
    .mobile-nav-menu {
        display: block;
        position: fixed;
        top: 0;
        left: -100%;
        height: 100vh;
        width: 280px;
        background-color: var(--card-bg);
        padding: 3rem 0 2rem;
        box-shadow: 5px 0 15px rgba(0,0,0,0.1);
        transition: all 0.5s ease-in-out;
        z-index: 1002;
    }

    .mobile-nav-menu.active {
        left: 0;
    }

    .mobile-nav-menu .nav-close-btn {
        position: absolute;
        top: 1rem;
        right: 1.5rem;
        font-size: 1.8rem;
        cursor: pointer;
    }

    .mobile-nav-menu ul {
        list-style: none;
    }

    .mobile-nav-menu ul li a {
        display: block;
        padding: 0.8rem 2rem;
        text-decoration: none;
        color: var(--text-color);
        font-weight: 500;
    }

    .mobile-nav-menu ul li a:hover {
        background-color: var(--bg-color);
    }
}

@media (max-width: 768px) { 
    .navbar-search {
        max-width: 150px;
    }

    .nav-right {
        gap: 0.8rem;
    }

    .dropdown-menu { left: auto; right: 0; transform: translate(0, 10px); }
    .dropdown-menu.show { transform: translate(0, 0); }
    .dropdown-menu::before { left: auto; right: 15px; transform: translateX(0); }
}

/* --- UPDATED: Mobile search focus styles --- */
@media (max-width: 600px) {
    .navbar-search {
        flex-grow: 0;
    }
    
    /* When search is active, hide other elements */
    .navbar.search-active .nav-left,
    .navbar.search-active .auth-buttons,
    .navbar.search-active .avatar-container,
    .navbar.search-active .theme-btn {
        opacity: 0;
        width: 0;
        pointer-events: none;
        overflow: hidden;
    }

    /* Expand the container of the search bar */
    .navbar.search-active .nav-right {
        flex-grow: 1;
    }

    /* Expand the search bar itself */
    .navbar.search-active .navbar-search {
        flex-grow: 1;
        max-width: 100%;
    }
    
    header {
        position: fixed;
        top: 0;
        width: 100%;
        z-index: 1000;
    }
    
    .navbar {
        padding: 0.5rem 4%;
        min-height: 50px;
    }
    
    .sub-nav {
        position: fixed;
        top: 50px; /* Height of navbar */
        width: 100%;
        z-index: 999;
        min-height: 35px;
    }
    
    .sub-nav a {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .navbar {
        padding: 0.7rem 5%;
    }
    
    .logo a .logo-text {
        display: none;
    }
    
    .logo img {
        height: 30px;
        margin-right: 0;
    }
    
    .sub-nav a { 
        padding: 0.5rem 0.8rem; 
        font-size: 0.75rem; 
    }
    
    .auth-link {
        padding: 0.4rem 0.7rem;
        font-size: 0.75rem;
    }
}
