/**
 * QMF Header Styles for Classroom
 * Unified UI/UX across Quizzman ecosystem
 * @version 2.0.0
 */

/* ================================
   CSS Custom Properties (Theme)
   ================================ */
:root {
    /* Brand Colors */
    --qmf-primary: #667eea;
    --qmf-primary-dark: #5a67d8;
    --qmf-primary-light: #7c8af2;
    --qmf-secondary: #764ba2;
    --qmf-gradient: linear-gradient(135deg, var(--qmf-primary) 0%, var(--qmf-secondary) 100%);
    
    /* Neutral Colors */
    --qmf-text: #1a1a2e;
    --qmf-text-secondary: #64748b;
    --qmf-bg: #ffffff;
    --qmf-bg-secondary: #f8fafc;
    --qmf-border: #e2e8f0;
    --qmf-shadow: rgba(0, 0, 0, 0.08);
    
    /* Header Specific */
    --qmf-header-height: 60px;
    --qmf-header-bg: var(--qmf-bg);
    --qmf-header-border: var(--qmf-border);
    --qmf-header-shadow: 0 1px 3px var(--qmf-shadow);
    
    /* Transitions */
    --qmf-transition-fast: 0.15s ease;
    --qmf-transition: 0.25s ease;
    
    /* Z-Index */
    --qmf-z-header: 1000;
    --qmf-z-dropdown: 1001;
    --qmf-z-overlay: 1002;
}

/* Dark Theme */
[data-theme="dark"] {
    --qmf-text: #e2e8f0;
    --qmf-text-secondary: #94a3b8;
    --qmf-bg: #1e293b;
    --qmf-bg-secondary: #0f172a;
    --qmf-border: #334155;
    --qmf-shadow: rgba(0, 0, 0, 0.3);
    --qmf-header-bg: #1e293b;
    --qmf-header-border: #334155;
}

/* ================================
   QMF Header Base
   ================================ */
.qmf-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--qmf-header-height);
    background: var(--qmf-header-bg);
    border-bottom: 1px solid var(--qmf-header-border);
    box-shadow: var(--qmf-header-shadow);
    z-index: var(--qmf-z-header);
    transition: background var(--qmf-transition), border var(--qmf-transition);
}

.qmf-header__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 1rem;
    gap: 1rem;
}

/* Body offset */
body.has-qmf-header {
    padding-top: var(--qmf-header-height);
}

/* ================================
   Header Clusters (4-Cluster Layout)
   ================================ */
.qmf-header__cluster {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Cluster 1: Brand */
.qmf-header__cluster--brand {
    flex: 0 0 auto;
}

/* Cluster 2: Main Logo (center) */
.qmf-header__cluster--logo {
    flex: 1 1 auto;
    justify-content: center;
}

/* Cluster 3: Social buttons */
.qmf-header__cluster--social {
    flex: 0 0 auto;
    gap: 0.25rem;
}

/* Cluster 4: User */
.qmf-header__cluster--user,
.qmf-header__cluster--login {
    flex: 0 0 auto;
}

/* ================================
   Brand Section
   ================================ */
.qmf-header__brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--qmf-text);
}

.qmf-header__sub-logo {
    width: 36px;
    height: 36px;
    object-fit: contain;
    border-radius: 8px;
}

.qmf-header__brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.qmf-header__brand-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--qmf-text);
}

.qmf-header__page-title {
    font-size: 0.75rem;
    color: var(--qmf-text-secondary);
}

/* ================================
   Main Logo
   ================================ */
.qmf-header__main-logo {
    display: flex;
    align-items: center;
}

.qmf-header__logo-img {
    height: 32px;
    width: auto;
    object-fit: contain;
}

/* ================================
   Social Buttons
   ================================ */
.qmf-header__social-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--qmf-text-secondary);
    border-radius: 10px;
    cursor: pointer;
    transition: all var(--qmf-transition-fast);
}

.qmf-header__social-btn:hover {
    background: var(--qmf-bg-secondary);
    color: var(--qmf-primary);
}

.qmf-header__social-btn i {
    font-size: 1.15rem;
}

.qmf-header__badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: #ef4444;
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qmf-header__badge:empty {
    display: none;
}

/* ================================
   User Dropdown
   ================================ */
.qmf-header__user-dropdown {
    position: relative;
}

.qmf-header__user-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem 0.4rem 0.4rem;
    border: 1px solid var(--qmf-border);
    background: var(--qmf-bg);
    border-radius: 25px;
    cursor: pointer;
    transition: all var(--qmf-transition-fast);
}

.qmf-header__user-toggle:hover {
    border-color: var(--qmf-primary);
    background: var(--qmf-bg-secondary);
}

.qmf-header__user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.qmf-header__user-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--qmf-text);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.qmf-header__chevron {
    font-size: 0.7rem;
    color: var(--qmf-text-secondary);
    transition: transform var(--qmf-transition-fast);
}

.qmf-header__user-toggle[aria-expanded="true"] .qmf-header__chevron {
    transform: rotate(180deg);
}

/* User Menu */
.qmf-header__user-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 180px;
    background: var(--qmf-bg);
    border: 1px solid var(--qmf-border);
    border-radius: 12px;
    box-shadow: 0 10px 40px var(--qmf-shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all var(--qmf-transition-fast);
    z-index: var(--qmf-z-dropdown);
    overflow: hidden;
}

.qmf-header__user-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.qmf-header__menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem 1rem;
    background: none;
    border: none;
    color: var(--qmf-text);
    font-size: 0.9rem;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--qmf-transition-fast);
}

.qmf-header__menu-item:hover {
    background: var(--qmf-bg-secondary);
}

.qmf-header__menu-item i {
    width: 18px;
    text-align: center;
    color: var(--qmf-text-secondary);
}

.qmf-header__menu-item.danger {
    color: #ef4444;
}

.qmf-header__menu-item.danger i {
    color: #ef4444;
}

.qmf-header__menu-divider {
    height: 1px;
    background: var(--qmf-border);
    margin: 0.25rem 0;
}

/* ================================
   Login Button
   ================================ */
.qmf-header__login-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    background: var(--qmf-gradient);
    color: white;
    font-weight: 500;
    border-radius: 25px;
    text-decoration: none;
    transition: all var(--qmf-transition-fast);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.qmf-header__login-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* ================================
   Mobile Header
   ================================ */
.qmf-header--mobile .qmf-header__inner {
    padding: 0 0.75rem;
}

.qmf-header__cluster--mobile-brand {
    flex: 0 0 auto;
    gap: 0.5rem;
}

.qmf-header__hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--qmf-text);
    font-size: 1.25rem;
    cursor: pointer;
    border-radius: 8px;
}

.qmf-header__hamburger:hover {
    background: var(--qmf-bg-secondary);
}

/* Touchbar (center) */
.qmf-header__cluster--touchbar {
    flex: 1 1 auto;
    justify-content: center;
}

.qmf-header__touchbar {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem 1rem;
    background: var(--qmf-bg-secondary);
    border-radius: 20px;
    min-width: 100px;
}

.qmf-header__status-text {
    font-size: 0.8rem;
    color: var(--qmf-text-secondary);
    white-space: nowrap;
}

/* Mobile User */
.qmf-header__cluster--mobile-user {
    flex: 0 0 auto;
}

.qmf-header__mobile-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    padding: 0;
    cursor: pointer;
}

.qmf-header__mobile-avatar img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.qmf-header__mobile-login {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--qmf-gradient);
    color: white;
    border-radius: 50%;
    text-decoration: none;
}

/* ================================
   Mobile User Menu
   ================================ */
.qmf-mobile-user-menu {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--qmf-z-overlay);
    opacity: 0;
    visibility: hidden;
    transition: all var(--qmf-transition);
}

.qmf-mobile-user-menu.show {
    opacity: 1;
    visibility: visible;
}

.qmf-mobile-menu__overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
}

.qmf-mobile-menu__content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--qmf-bg);
    border-radius: 20px 20px 0 0;
    padding: 1.5rem;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    transform: translateY(100%);
    transition: transform var(--qmf-transition);
}

.qmf-mobile-user-menu.show .qmf-mobile-menu__content {
    transform: translateY(0);
}

.qmf-mobile-menu__close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 36px;
    height: 36px;
    border: none;
    background: var(--qmf-bg-secondary);
    color: var(--qmf-text-secondary);
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
}

.qmf-mobile-menu__item {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    padding: 1rem;
    border: none;
    background: none;
    color: var(--qmf-text);
    font-size: 1rem;
    text-decoration: none;
    cursor: pointer;
    border-radius: 12px;
}

.qmf-mobile-menu__item:hover,
.qmf-mobile-menu__item:active {
    background: var(--qmf-bg-secondary);
}

.qmf-mobile-menu__item i {
    width: 24px;
    text-align: center;
    color: var(--qmf-text-secondary);
}

.qmf-mobile-menu__item.danger {
    color: #ef4444;
}

.qmf-mobile-menu__item.danger i {
    color: #ef4444;
}

.qmf-mobile-menu__divider {
    height: 1px;
    background: var(--qmf-border);
    margin: 0.5rem 0;
}

/* ================================
   Responsive Breakpoints
   ================================ */
@media (max-width: 768px) {
    :root {
        --qmf-header-height: 56px;
    }
    
    .qmf-header:not(.qmf-header--mobile) .qmf-header__cluster--social,
    .qmf-header:not(.qmf-header--mobile) .qmf-header__user-name {
        display: none;
    }
}

@media (max-width: 480px) {
    .qmf-header__brand-text {
        display: none;
    }
}

/* ================================
   Animation Keyframes
   ================================ */
@keyframes qmf-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes qmf-badge-pop {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.qmf-header__badge {
    animation: qmf-badge-pop 0.3s ease;
}

/* ================================
   Print Styles
   ================================ */
@media print {
    .qmf-header {
        display: none;
    }
    
    body.has-qmf-header {
        padding-top: 0;
    }
}
