/**
 * Global Header and Navigation CSS
 * Reusable across Admin and Portal
 * Mobile-first responsive design
 */

/* Header Container */
.site-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: var(--color-link);
    z-index: 1000;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    max-width: 1400px;
    margin: 0 auto;
}

/* Logo/Brand */
.header-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--color-on-brand);
    font-weight: 700;
    font-size: 1.25rem;
    transition: opacity 0.2s ease;
}

.header-brand:hover {
    opacity: 0.9;
}

.header-logo {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-on-brand);
    padding: 0.15rem;
}

.header-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.brand-text {
    display: none;
}

/* Hamburger Menu (Mobile) */
.hamburger {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    z-index: 1001;
}

.hamburger:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-focus-ring);
    border-radius: var(--radius-sm);
}

.hamburger span {
    display: block;
    width: 24px;
    height: 3px;
    background: var(--color-on-brand);
    border-radius: 2px;
    transition: all 0.3s ease;
}

.hamburger.active span:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
}

.hamburger.active span:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

/* Navigation */
.main-nav {
    position: fixed;
    top: 0;
    right: -100%;
    width: 300px;
    height: 100vh;
    background: linear-gradient(180deg, var(--color-link) 0%, rgba(95, 118, 220, 0.95) 100%);
    padding: 5rem 0 0 0;
    transition: right 0.3s ease;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.main-nav.active {
    right: 0;
}

.nav-list {
    list-style: none;
    margin: 0;
    padding: 1rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.nav-item {
    margin-bottom: 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 1rem 1.25rem;
    color: var(--color-on-brand);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 1.05rem;
    transition: all 0.2s ease;
    position: relative;
    min-height: 44px;
}

.nav-link:hover {
    background: linear-gradient(135deg, rgba(208, 161, 235, 0.3), rgba(160, 177, 255, 0.3));
    transform: translateX(4px);
    color: var(--color-on-brand);
}

.nav-link.active {
    background-color: rgba(255, 255, 255, 0.2);
}

.nav-item.has-submenu > .nav-link::after {
    content: '›';
    position: absolute;
    right: 1rem;
    transition: transform 0.2s ease;
    font-size: 1.5rem;
}

.nav-item.has-submenu.open > .nav-link::after {
    transform: rotate(90deg);
}

/* Submenu */
.nav-submenu {
    list-style: none;
    margin: 0;
    padding: 0;
    display: none;
    background: rgba(0, 0, 0, 0.1);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.nav-item.has-submenu.open .nav-submenu {
    display: block;
    animation: slideDown 0.2s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 300px;
    }
}

.nav-submenu .nav-link {
    padding: 0.875rem 1.25rem 0.875rem 2.5rem;
    font-size: 0.95rem;
    font-weight: 400;
}

/* Mobile Logout Button */
.mobile-logout {
    padding: 1.5rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.logout-btn-mobile {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.875rem 1.25rem;
    background: var(--logout-color);
    color: var(--color-on-brand);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    text-align: center;
    transition: all 0.2s ease;
    min-height: 44px;
}

.logout-btn-mobile:hover {
    background: var(--logout-hover-color);
    transform: translateY(-2px);
}

/* Header Right (Logout, User info) */
.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info {
    display: none;
    color: var(--color-on-brand);
    font-size: 0.9rem;
    font-weight: 500;
}

.logout-btn {
    padding: 0.5rem 0.875rem;
    background: var(--logout-color);
    color: var(--color-on-brand);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
}

.nav-link:focus-visible,
.logout-btn-mobile:focus-visible,
.logout-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-focus-ring);
}

.logout-btn:hover {
    background: var(--logout-hover-color);
    transform: translateY(-1px);
    color: var(--color-on-brand);
}

.desktop-only {
    display: none;
}

/* Main Content Offset */
.main-content {
    padding-top: 65px; /* Height of header */
    min-height: calc(100vh - 65px);
}

/* Desktop Styles */
@media (min-width: 768px) {
    .hamburger {
        display: none;
    }

    .mobile-logout {
        display: none;
    }

    .desktop-only {
        display: block;
    }

    .header-content {
        padding: 0.75rem 2rem;
    }

    .header-brand {
        font-size: 1.4rem;
    }

    .brand-text {
        display: inline;
    }

    .header-logo {
        width: 44px;
        height: 44px;
    }

    .main-nav {
        position: static;
        width: auto;
        height: auto;
        padding: 0;
        background: transparent;
        box-shadow: none;
        overflow: visible;
        display: block;
    }

    .nav-list {
        display: flex;
        gap: 0.25rem;
        padding: 0;
        overflow-y: visible;
        min-height: auto;
    }

    .nav-item {
        position: relative;
        margin-bottom: 0;
    }

    /* Top-level nav links — underline style */
    .nav-list > .nav-item > .nav-link {
        padding: 0.5rem 0.875rem;
        font-size: 0.9rem;
        letter-spacing: 0.01em;
        font-weight: 500;
        border-radius: var(--radius-sm);
        /* Underline indicator via ::before */
        overflow: visible;
    }

    .nav-list > .nav-item > .nav-link::before {
        content: '';
        position: absolute;
        bottom: 2px;
        left: 10%;
        width: 80%;
        height: 2px;
        background: var(--color-on-brand);
        border-radius: 1px;
        transform: scaleX(0);
        transform-origin: center;
        transition: transform 0.2s ease;
    }

    .nav-list > .nav-item > .nav-link:hover {
        background: rgba(255, 255, 255, 0.1);
        transform: none;
        color: var(--color-on-brand);
    }

    .nav-list > .nav-item > .nav-link:hover::before,
    .nav-list > .nav-item > .nav-link.active::before {
        transform: scaleX(1);
    }

    .nav-list > .nav-item > .nav-link.active {
        background: rgba(255, 255, 255, 0.12);
        font-weight: 600;
    }

    .nav-item.has-submenu > .nav-link::after {
        content: '▾';
        font-size: 0.8rem;
        right: 0.4rem;
    }

    /* Keep submenu visible when hovering over parent OR submenu */
    .nav-item.has-submenu:hover .nav-submenu,
    .nav-submenu:hover {
        display: block;
    }

    .nav-submenu {
        position: absolute;
        top: 100%;
        left: 0;
        min-width: 240px;
        background: var(--color-surface);
        border-radius: var(--radius-md);
        border: 1px solid var(--color-border);
        box-shadow: 0 4px 16px var(--color-shadow);
        padding: 0.375rem 0;
        animation: fadeIn 0.15s ease;
    }

    @keyframes fadeIn {
        from { opacity: 0; transform: translateY(-6px); }
        to   { opacity: 1; transform: translateY(0); }
    }

    .nav-submenu .nav-link {
        color: var(--color-text);
        padding: 0.625rem 1.125rem;
        font-size: 0.875rem;
        font-weight: 400;
        border-radius: 0;
    }

    .nav-submenu .nav-link::before {
        display: none;
    }

    .nav-submenu .nav-link:hover {
        background: var(--btn-ghost-bg-hover);
        color: var(--color-text);
    }

    .user-info {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        color: rgba(255, 255, 255, 0.85);
        font-size: 0.85rem;
        font-weight: 500;
        padding: 0 0.25rem;
    }

    /* Logout button — subtle outline on desktop */
    .logout-btn {
        padding: 0.4rem 0.875rem;
        background: transparent;
        border: 1.5px solid rgba(255, 255, 255, 0.5);
        color: var(--color-on-brand);
        font-size: 0.85rem;
        font-weight: 500;
        border-radius: var(--radius-md);
        text-decoration: none;
        transition: background 0.2s ease, border-color 0.2s ease;
    }

    .logout-btn:hover {
        background: rgba(255, 255, 255, 0.12);
        border-color: var(--color-on-brand);
        color: var(--color-on-brand);
        transform: none;
    }

    .main-content {
        padding-top: 72px;
    }
}

[data-theme="dark"] .site-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

[data-theme="dark"] .main-nav {
    background: linear-gradient(180deg, var(--color-surface) 0%, var(--color-surface-muted) 100%);
}

[data-theme="dark"] .nav-link:hover {
    background: var(--btn-ghost-bg-hover);
    color: var(--color-on-brand);
}

[data-theme="dark"] .nav-link.active {
    background: rgba(255, 255, 255, 0.12);
    color: var(--color-on-brand);
}

[data-theme="dark"] .mobile-logout {
    border-top: 1px solid var(--color-border);
    background: rgba(0, 0, 0, 0.22);
}

@media (min-width: 1024px) {
    .nav-list {
        gap: 1rem;
    }
}

/* Teacher portal header shell */
.teacher-site-header {
    background-color: var(--color-link);
}

.teacher-header-brand {
    text-transform: lowercase;
    letter-spacing: 0.02em;
}

.teacher-nav {
    display: none;
    gap: 0.4rem;
    align-items: center;
}

.teacher-nav a {
    color: var(--color-on-brand);
    text-decoration: none;
    padding: 0.45rem 0.75rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
}

.teacher-nav a:hover,
.teacher-nav a.active {
    background: rgba(255, 255, 255, 0.16);
    color: var(--color-on-brand);
}

@media (min-width: 1024px) {
    .teacher-nav {
        display: flex;
    }
}

[data-theme="dark"] .teacher-site-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

[data-theme="dark"] .teacher-nav a {
    color: var(--color-text);
}

.teacher-bottom-tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: space-around;
    gap: 0.25rem;
    padding: 0.5rem;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    z-index: 20;
}

.teacher-bottom-tabs a {
    color: var(--color-text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.8rem;
    padding: 0.35rem 0.4rem;
    border-radius: var(--radius-sm);
}

.teacher-bottom-tabs a:hover {
    background: var(--btn-ghost-bg-hover);
}

@media (min-width: 1024px) {
    .teacher-bottom-tabs {
        display: none;
    }
}
