/* ======================================
   HEADER & NAVIGATION STYLES
   ====================================== */

/* Main Header - Base styles first */
.main-header {
    background: #1440a6;
    color: #fff;
    padding: 20px 0;
    box-shadow: var(--shadow-sm, 0 2px 4px rgb(0 0 0 / 10%));
    position: sticky;
    top: 0;
    z-index: 100;
    transition: padding 0.3s ease;
}

.main-header .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    gap: 12px;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
}

.main-header h1 {
    margin: 0;
    font-size: 32px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    transition: font-size 0.3s ease;
}

.main-header nav {
    display: flex;
    overflow: visible;
    position: relative;
    z-index: 1000;
    gap: 12px;
    align-items: center;
    background: #1440a6;
}

.site-logo {
    height: 56px;
    width: 56px;
    vertical-align: middle;
    object-fit: contain;
    border-radius: 50%;
    transition: height 0.3s ease, width 0.3s ease;
}

/* Scrolled state - shrink header on scroll */
.main-header.scrolled {
    padding: 8px 0;
}

.main-header.scrolled h1 {
    font-size: 20px;
}

.main-header.scrolled .site-logo {
    height: 40px;
    width: 40px;
}

.header-title-link {
    text-decoration: none;
    color: inherit;
    display: inline-block;
    transition: opacity 0.2s ease;
    cursor: pointer;
}

.header-title-link:hover {
    opacity: 0.9;
    text-decoration: none;
}

/* User Welcome Message */
.user-welcome {
    color: #fff;
    font-size: 14px;
    margin-right: 12px;
    display: none;
    order: 1;
}

/* Auth buttons order */
.header-auth-buttons {
    display: flex;
    gap: 12px;
    order: 2;
}

.header-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: var(--font-size-base, 14px);
    border-radius: var(--border-radius, 6px);
    background: transparent;
    border: 1px solid rgb(255 255 255 / 30%);
    color: #fff;
    text-decoration: none;
    white-space: nowrap;
    transition: background var(--transition-base, 0.2s ease);
    box-shadow: var(--shadow-sm, 0 2px 4px rgb(0 0 0 / 15%));
}

.header-btn .menu-icon {
    font-size: 16px;
}

.header-btn .menu-label {
    font-size: var(--font-size-base, 14px);
}

.header-btn:hover {
    background: rgb(255 255 255 / 20%);
}

/* ======================================
   HAMBURGER MENU BUTTON
   ====================================== */

.hamburger,
button.hamburger,
#hamburger-menu {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border: none;
    cursor: pointer;
    position: relative;
    z-index: 10001;
    padding: 8px;
    border-radius: 8px;
    flex-shrink: 0;
    margin: 0;
    margin-left: auto;
    font-size: inherit;
    box-sizing: border-box;
    opacity: 1;
    visibility: visible;
    overflow: visible;
    transition: background var(--transition-base, 0.2s ease);
    order: 3;
    background: rgb(255 255 255 / 10%);
}

/* Hover should precede more specific nav hamburger to satisfy specificity */
.hamburger:hover {
    background: rgb(255 255 255 / 15%);
}

.main-header nav .hamburger,
.main-header nav button.hamburger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border: none;
    cursor: pointer;
    position: relative;
    z-index: 10001;
    padding: 8px;
    border-radius: 8px;
    flex-shrink: 0;
    margin: 0;
    margin-left: auto;
    font-size: inherit;
    box-sizing: border-box;
    opacity: 1;
    visibility: visible;
    overflow: visible;
    transition: background var(--transition-base, 0.2s ease);
    order: 3;
    background: rgb(255 255 255 / 10%);
}

/* Hamburger Bars */

/* Base hamburger bars - class selectors first */
.hamburger .bar {
    width: 28px;
    height: 4px;
    min-width: 28px;
    min-height: 4px;
    background: #fff;
    margin: 4px 0;
    border-radius: 2px;
    transition: transform 0.3s, opacity 0.3s;
    display: block;
    visibility: visible;
    position: relative;
    flex-shrink: 0;
    box-sizing: border-box;
}

/* Hamburger Not Open State - class selectors */
.hamburger:not(.open) .bar {
    opacity: 1;
    transform: none;
    width: 28px;
    height: 4px;
    display: block;
    visibility: visible;
}

/* Main header nav hamburger bars */
.main-header nav .hamburger .bar {
    width: 28px;
    height: 4px;
    min-width: 28px;
    min-height: 4px;
    background: #fff;
    margin: 4px 0;
    border-radius: 2px;
    transition: transform 0.3s, opacity 0.3s;
    display: block;
    visibility: visible;
    position: relative;
    flex-shrink: 0;
    box-sizing: border-box;
}

/* Theme overrides for base hamburger bars */
html.light-mode .hamburger .bar {
    background: #000;
}

body.dark-mode .hamburger .bar {
    background: #fff;
}

/* Hamburger Open State - class selectors */
.hamburger.open .bar:nth-child(1) {
    transform: rotate(45deg);
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -14px;
    margin-top: -2px;
}

.hamburger.open .bar:nth-child(2) {
    opacity: 0;
}

.hamburger.open .bar:nth-child(3) {
    transform: rotate(-45deg);
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -14px;
    margin-top: -2px;
}

/* Main header nav hamburger not-open state */
.main-header nav .hamburger:not(.open) .bar {
    opacity: 1;
    transform: none;
    width: 28px;
    height: 4px;
    display: block;
    visibility: visible;
}

/* Main header nav hamburger open states */
.main-header nav .hamburger.open .bar:nth-child(1) {
    transform: rotate(45deg);
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -14px;
    margin-top: -2px;
}

.main-header nav .hamburger.open .bar:nth-child(2) {
    opacity: 0;
}

.main-header nav .hamburger.open .bar:nth-child(3) {
    transform: rotate(-45deg);
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -14px;
    margin-top: -2px;
}

/* ID-specific bars declared after all class-based rules */
#hamburger-menu .bar {
    width: 28px;
    height: 4px;
    min-width: 28px;
    min-height: 4px;
    background: #fff;
    margin: 4px 0;
    border-radius: 2px;
    transition: transform 0.3s, opacity 0.3s;
    display: block;
    visibility: visible;
    position: relative;
    flex-shrink: 0;
    box-sizing: border-box;
}

/* ID-based not-open state */
#hamburger-menu:not(.open) .bar {
    opacity: 1;
    transform: none;
    width: 28px;
    height: 4px;
    display: block;
    visibility: visible;
}

/* Theme overrides for ID-based hamburger bars */
html.light-mode #hamburger-menu .bar {
    background: #000;
}

body.dark-mode #hamburger-menu .bar {
    background: #fff;
}

/* ID-based open state rules */
#hamburger-menu.open .bar:nth-child(1) {
    transform: rotate(45deg);
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -14px;
    margin-top: -2px;
}

#hamburger-menu.open .bar:nth-child(2) {
    opacity: 0;
}

#hamburger-menu.open .bar:nth-child(3) {
    transform: rotate(-45deg);
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -14px;
    margin-top: -2px;
}

/* ======================================
   TEXT SIZE CONTROLS
   ====================================== */

.text-size-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    margin-top: auto;
    flex-wrap: nowrap;
    width: 100%;
    box-sizing: border-box;
    min-height: 60px;
    max-height: 60px;
}

.text-size-controls .text-size-btn {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: none;
    outline: none;
    background: transparent;
    box-shadow: none;
}

.text-size-controls .text-size-btn .menu-icon {
    font-size: 20px;
}

.text-size-controls .text-size-btn .menu-label {
    font-size: 12px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.text-size-label {
    color: #fff;
    font-size: 14px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-weight: 500;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.text-size-line1,
.text-size-line2 {
    display: block;
}

/* ======================================
   MOBILE: HAMBURGER MENU
   ====================================== */

/* Hide nav-links by default (both mobile and desktop) */
.nav-links {
    display: none;
    order: 4;
}

@media (width <=900px) {
    .nav-links {
        flex-direction: column;
        gap: 0;
        align-items: flex-end;
        position: fixed;
        top: 0;
        right: 0;
        background: #1440a6;
        width: 260px;
        height: 100vh;
        padding: 60px 0 0;
        border-radius: 0 0 0 12px;
        box-shadow: var(--shadow-md, 0 2px 16px rgb(0 0 0 / 20%));
        z-index: 9999;
    }

    /* Mobile menu items styling */
    .nav-links a,
    .nav-links button {
        width: 100%;
        text-align: right;
        padding: 12px 24px;
        font-size: var(--font-size-md, 16px);
        border-radius: 0;
        background: transparent;
        border: none;
        color: #fff;
    }

    .nav-links.open {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px 0;
        place-items: stretch center;
        width: 260px;
        min-width: 160px;
        max-width: 90vw;
        height: auto;
        max-height: calc(100vh - 80px);
        overflow: hidden;
        padding: 16px 0;
        background: #1440a6;
        border-radius: var(--border-radius-large, 12px);
        box-shadow: var(--shadow-xl, 0 4px 24px rgb(0 0 0 / 18%));
        position: absolute;
        top: 90px;
        right: 0;
        z-index: 9999;
    }

    .nav-links.open a,
    .nav-links.open button {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-height: 100px;
        max-height: 100px;
        text-align: center;
        padding: 16px 8px;
        font-size: 14px;
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        background: transparent;
        border: none;
        outline: none;
        color: #fff;
        overflow: hidden;
        box-shadow: none;
    }

    .nav-links.open a .menu-icon,
    .nav-links.open button .menu-icon {
        font-size: 28px;
        margin-bottom: 8px;
        margin-right: 0;
        display: block;
        flex-shrink: 0;
        line-height: 1;
    }

    .nav-links.open a .menu-label,
    .nav-links.open button .menu-label {
        display: block;
        font-size: 14px;
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        font-weight: 500;
        line-height: 1.2;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .nav-links.open a:hover,
    .nav-links.open button:hover {
        background: transparent;
        color: #ffd700;
    }

    .nav-links.open a:hover .menu-icon,
    .nav-links.open button:hover .menu-icon {
        text-shadow: 0 0 10px rgb(255 215 0 / 80%), 0 0 20px rgb(255 215 0 / 60%);
        transform: scale(1.1);
    }

    .nav-links.open a:hover .menu-label,
    .nav-links.open button:hover .menu-label {
        text-shadow: 0 0 8px rgb(255 215 0 / 60%);
    }

    /* Text size controls in mobile menu */
    .nav-links.open .text-size-controls {
        grid-column: 1 / -1;
        width: 100%;
        margin-top: auto;
        padding: 12px 16px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        order: 999;
    }

    /* Mobile: show mobile auth buttons in hamburger menu */
    .nav-links.open .auth-btn-mobile,
    .nav-links.open .register-btn-mobile {
        display: flex;
    }
}

/* Desktop: hide mobile auth buttons, show desktop header buttons */
@media (width >=901px) {
    /* Show desktop auth buttons */
    .main-header .header-auth-buttons {
        display: flex;
    }

    /* Hide mobile auth buttons */
    .main-header .auth-btn-mobile,
    .main-header .register-btn-mobile {
        display: none;
    }

    /* Desktop hamburger menu - match mobile styling */
    .nav-links.open {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px 0;
        place-items: stretch center;
        width: 260px;
        min-width: 160px;
        max-width: 90vw;
        height: auto;
        max-height: calc(100vh - 80px);
        overflow: hidden;
        padding: 16px 0;
        background: #1440a6;
        border-radius: var(--border-radius-large, 12px);
        box-shadow: var(--shadow-xl, 0 4px 24px rgb(0 0 0 / 18%));
        position: absolute;
        top: 90px;
        right: 0;
        z-index: 9999;
    }

    /* Desktop menu items styling - match mobile */
    .nav-links.open a,
    .nav-links.open button {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-height: 100px;
        max-height: 100px;
        text-align: center;
        padding: 16px 8px;
        font-size: 14px;
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        background: transparent;
        border: none;
        outline: none;
        color: #fff;
        overflow: hidden;
        box-shadow: none;
    }

    .nav-links.open a .menu-icon,
    .nav-links.open button .menu-icon {
        font-size: 28px;
        margin-bottom: 8px;
        margin-right: 0;
        display: block;
        flex-shrink: 0;
        line-height: 1;
    }

    .nav-links.open a .menu-label,
    .nav-links.open button .menu-label {
        display: block;
        font-size: 14px;
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        font-weight: 500;
        line-height: 1.2;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .nav-links.open a:hover,
    .nav-links.open button:hover {
        background: transparent;
        color: #ffd700;
    }

    .nav-links.open a:hover .menu-icon,
    .nav-links.open button:hover .menu-icon {
        text-shadow: 0 0 10px rgb(255 215 0 / 80%), 0 0 20px rgb(255 215 0 / 60%);
        transform: scale(1.1);
    }

    .nav-links.open a:hover .menu-label,
    .nav-links.open button:hover .menu-label {
        text-shadow: 0 0 8px rgb(255 215 0 / 60%);
    }

    /* Text size controls in desktop menu - match mobile */
    .nav-links.open .text-size-controls {
        grid-column: 1 / -1;
        width: 100%;
        margin-top: auto;
        padding: 12px 16px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        order: 999;
        min-height: 0;
        max-height: none;
    }
}

/* Mobile Responsive */
@media (width <=768px) {
    .main-header .container {
        flex-wrap: nowrap;
        gap: 8px;
    }

    .main-header h1 {
        font-size: 20px;
        min-width: 0;
        flex: 1;
    }

    .main-header nav {
        flex-shrink: 0;
        gap: 8px;
    }

    .site-logo {
        height: 40px;
        width: 40px;
        border-radius: 50%;
    }

    /* Mobile-specific scrolled state - shrink further */
    .main-header.scrolled h1 {
        font-size: 16px;
    }

    .main-header.scrolled .site-logo {
        height: 32px;
        width: 32px;
    }
}

/* Hide desktop auth buttons on small screens - they appear in hamburger menu */

/* Keep !important to override any inline styles */
@media (width <=900px) {
    .header-auth-buttons {
        display: none !important;
    }
}

/* ======================================
   LIGHT MODE OVERRIDES
   (Come last to properly override base styles)
   ====================================== */

html.light-mode .main-header {
    background: #1440a6;
    color: #fff;
}

html.light-mode .main-header h1 {
    color: #fff;
}

html.light-mode .nav-links {
    background: #1440a6;
}

html.light-mode .nav-links.open {
    background: #1440a6;
}

html.light-mode .nav-links.open a,
html.light-mode .nav-links.open button {
    color: #fff;
}

html.light-mode .header-btn {
    color: #fff;
    border-color: rgb(255 255 255 / 30%);
}

/* ======================================
   DARK MODE OVERRIDES
   (Come after light mode)
   ====================================== */

body.dark-mode .main-header {
    background: #1e3a5f;
}

body.dark-mode .main-header nav {
    background: #1e3a5f;
}

body.dark-mode .nav-links {
    background: #1e3a5f;
}

body.dark-mode .hamburger {
    background: rgb(255 255 255 / 15%);
}

@media (width <=900px) {
    body.dark-mode .nav-links {
        background: #1e3a5f;
    }

    body.dark-mode .nav-links.open {
        background: #1e3a5f;
        background-color: #1e3a5f;
    }
}

@media (width >=901px) {
    body.dark-mode .nav-links.open {
        background: #1e3a5f;
        background-color: #1e3a5f;
    }
}