/* ================================================================
   MODERN HEADER - Theme-Aware Styling
   Uses CSS variables from theme-variables.css
   Optimized for touch devices (iPad/mobile)
   ================================================================ */

/* Modern Header Styling */
.modern-header {
    background-color: var(--header-bg);
    box-shadow: var(--shadow-sm);
    height: 64px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    border-bottom: 1px solid var(--border-light);
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.modern-header.scrolled {
    background-color: var(--bg-elevated);
    box-shadow: var(--shadow-md);
}

.header-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 24px;
    max-width: 1400px;
    margin: 0 auto;
}

.logo-wrapper {
    display: flex;
    align-items: center;
}

/* Hide logo on dashboard pages (sidebar already has logo) */
.dashboard-container .logo-wrapper {
    visibility: hidden;
}

.logo-link {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--text-primary);
    min-height: 44px;
    -webkit-tap-highlight-color: rgba(138, 43, 226, 0.2);
    touch-action: manipulation;
}

.logo {
    height: 28px;
    margin-right: 12px;
}

.logo-text {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.mobile-menu-toggle {
    display: none;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 12px;
    flex-direction: column;
    gap: 6px;
    min-width: 48px;
    min-height: 48px;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: rgba(138, 43, 226, 0.3);
    touch-action: manipulation;
    z-index: 1001;
    border-radius: 8px;
    transition: background-color 0.15s ease;
}

/* Visual feedback on tap */
.mobile-menu-toggle:active,
.mobile-menu-toggle.tapped {
    background-color: var(--accent-purple-10, rgba(138, 43, 226, 0.1));
}

.toggle-bar {
    display: block;
    width: 26px;
    height: 3px;
    background-color: var(--text-primary);
    transition: transform 0.3s ease, opacity 0.3s ease;
    border-radius: 2px;
    pointer-events: none;
}

/* Main Navigation */
.main-navigation {
    height: 100%;
}

.nav-menu {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    height: 100%;
}

.nav-item {
    height: 100%;
    display: flex;
    align-items: center;
    position: relative;
    margin: 0 2px;
}

.modern-header .nav-link {
    color: var(--text-secondary) !important;
    font-size: 0.95rem;
    font-weight: 500;
    padding: 0 16px;
    text-decoration: none;
    transition: color 0.2s ease, background-color 0.15s ease;
    display: flex;
    align-items: center;
    height: 100%;
    min-height: 44px;
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: rgba(138, 43, 226, 0.2);
    touch-action: manipulation;
    cursor: pointer;
    /* Ensure links are fully clickable */
    z-index: 1;
}

.modern-header .nav-link::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 0;
    height: 2px;
    background: var(--gradient-primary);
    transition: all 0.3s ease;
    transform: translateX(-50%);
}

/* Only apply hover styles on non-touch devices */
@media (hover: hover) and (pointer: fine) {
    .modern-header .nav-link:hover::after,
    .modern-header .nav-link.active::after {
        width: 100%;
    }
    
    .modern-header .nav-link:hover {
        color: var(--text-primary) !important;
    }
}

/* Active state always visible */
.modern-header .nav-link.active::after {
    width: 100%;
}

.modern-header .nav-link.active {
    color: var(--accent-purple) !important;
}

/* Tap feedback */
.modern-header .nav-link:active,
.modern-header .nav-link.tapped {
    background-color: var(--accent-purple-10, rgba(138, 43, 226, 0.1));
}

/* User Menu Styling */
.user-menu {
    position: relative;
}

.user-menu-button {
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    cursor: pointer;
    color: var(--text-secondary);
    height: 100%;
    min-height: 48px;
    transition: background-color 0.15s ease, color 0.2s ease;
    -webkit-tap-highlight-color: rgba(138, 43, 226, 0.2);
    touch-action: manipulation;
    border-radius: 8px;
}

/* Tap feedback */
.user-menu-button:active,
.user-menu-button.tapped {
    background: var(--accent-purple-10, rgba(138, 43, 226, 0.15));
}

@media (hover: hover) and (pointer: fine) {
    .user-menu-button:hover {
        color: var(--text-primary);
        background: var(--accent-purple-10);
    }
}

.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--gradient-primary);
    box-shadow: var(--shadow-glow-purple);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 500;
    pointer-events: none;
}

.user-name {
    font-size: 0.95rem;
    font-weight: 500;
    max-width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
    pointer-events: none;
}

.user-menu-button i {
    font-size: 0.8rem;
    transition: transform 0.2s ease;
    pointer-events: none;
}

/* Chevron rotation when active */
.user-menu.active .user-menu-button i {
    transform: rotate(180deg);
}

/* User Dropdown */
.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background-color: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    width: 200px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s ease;
    z-index: 100;
    list-style: none;
    padding: 8px 0;
    margin: 0;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* Show dropdown when .active class is added (via JS) */
.user-menu.active .user-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* For desktop non-touch: hover also works */
@media (hover: hover) and (pointer: fine) {
    .user-menu:hover .user-dropdown {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }
    
    .user-menu:hover .user-menu-button i {
        transform: rotate(180deg);
    }
}

.user-dropdown li {
    margin: 0;
}

.dropdown-link {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    min-height: 48px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background-color 0.15s ease, color 0.2s ease;
    font-size: 0.9rem;
    -webkit-tap-highlight-color: rgba(138, 43, 226, 0.2);
    touch-action: manipulation;
}

.dropdown-link i {
    width: 20px;
    margin-right: 10px;
    text-align: center;
    pointer-events: none;
}

/* Tap feedback */
.dropdown-link:active,
.dropdown-link.tapped {
    background: var(--accent-purple-10, rgba(138, 43, 226, 0.15));
}

@media (hover: hover) and (pointer: fine) {
    .dropdown-link:hover {
        background: var(--accent-purple-10);
        color: var(--text-primary);
    }
}

.dropdown-divider {
    height: 1px;
    background-color: var(--border-light);
    margin: 6px 0;
}

.text-danger {
    color: var(--accent-red) !important;
}

/* Login/Register Buttons */
.btn-login,
.btn-register {
    border-radius: 6px;
    font-weight: 500;
    height: 36px !important;
    min-height: 44px !important;
    margin: 0 4px;
    padding: 0 16px !important;
    -webkit-tap-highlight-color: rgba(138, 43, 226, 0.3);
    touch-action: manipulation;
}

.btn-login {
    border: 1px solid transparent;
    background: linear-gradient(var(--bg-card), var(--bg-card)) padding-box,
                var(--gradient-primary) border-box;
    color: var(--accent-purple) !important;
    transition: all 0.2s ease;
}

.btn-login:active,
.btn-login.tapped,
.btn-login:focus {
    background: var(--accent-purple-15, rgba(138, 43, 226, 0.15));
    color: var(--accent-purple) !important;
}

.btn-login:visited {
    color: var(--accent-purple) !important;
}

@media (hover: hover) and (pointer: fine) {
    .btn-login:hover {
        box-shadow: var(--shadow-glow-purple);
        transform: translateY(-1px);
        background: var(--accent-purple-10);
        color: var(--accent-purple);
    }
}

.btn-register {
    background: var(--gradient-primary);
    color: white !important;
    box-shadow: var(--shadow-glow-purple);
    transition: all 0.2s ease;
}

.btn-register:active,
.btn-register.tapped {
    filter: brightness(0.95);
    transform: scale(0.98);
}

@media (hover: hover) and (pointer: fine) {
    .btn-register:hover {
        transform: translateY(-1px);
        filter: brightness(1.1);
    }
}

/* Theme toggle button */
.theme-toggle {
    min-width: 48px;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    -webkit-tap-highlight-color: rgba(138, 43, 226, 0.3);
    touch-action: manipulation;
    border-radius: 8px;
    transition: background-color 0.15s ease, color 0.2s ease;
}

.theme-toggle:hover {
    background: var(--accent-purple-10);
    color: var(--text-primary);
}

.theme-toggle:active,
.theme-toggle.tapped {
    background-color: var(--accent-purple-10, rgba(138, 43, 226, 0.1));
}

/* Responsive styles */
@media (max-width: 992px) {
    .mobile-menu-toggle {
        display: flex;
        position: relative;
        z-index: 1001;
    }
    
    /* Animated hamburger to X transformation */
    .mobile-menu-toggle.active .toggle-bar:nth-child(1) {
        transform: translateY(9px) rotate(45deg);
    }
    
    .mobile-menu-toggle.active .toggle-bar:nth-child(2) {
        opacity: 0;
        transform: scaleX(0);
    }
    
    .mobile-menu-toggle.active .toggle-bar:nth-child(3) {
        transform: translateY(-9px) rotate(-45deg);
    }
    
    .main-navigation {
        position: fixed;
        top: 64px;
        left: 0;
        right: 0;
        height: auto;
        max-height: calc(100vh - 64px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        background-color: var(--bg-card);
        border-top: 1px solid var(--border-light);
        transform: translateY(-100%);
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
        z-index: 999;
    }
    
    .main-navigation.active {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
    }
    
    .nav-menu {
        flex-direction: column;
        height: auto;
        padding: 16px;
    }
    
    .nav-item {
        height: auto;
        margin: 0;
    }
    
    .modern-header .nav-link {
        height: auto;
        padding: 16px;
        min-height: 52px;
        display: flex;
        align-items: center;
        border-radius: 8px;
        width: 100%;
        pointer-events: auto;
        /* Better touch target */
        -webkit-touch-callout: none;
    }
    
    .nav-item {
        width: 100%;
    }
    
    .user-menu-button {
        width: 100%;
        justify-content: space-between;
        padding: 16px;
        min-height: 56px;
    }
    
    .user-dropdown {
        position: static;
        visibility: visible;
        opacity: 1;
        transform: none;
        width: 100%;
        border: none;
        border-radius: 0;
        box-shadow: none;
        background-color: var(--bg-tertiary);
        display: none;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }
    
    .user-menu.active .user-dropdown {
        display: block;
        max-height: 500px;
    }
    
    .btn-login,
    .btn-register {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 8px 0;
        min-height: 52px;
    }
    
    /* Dropdown links touch target */
    .dropdown-link {
        min-height: 52px;
        padding: 14px 16px;
    }
}

/* Additional touch improvements for small screens */
@media (max-width: 576px) {
    .header-container {
        padding: 0 16px;
    }
    
    .logo-text {
        font-size: 1rem;
    }
    
    .logo {
        height: 24px;
        margin-right: 8px;
    }
    
    .modern-header .nav-link {
        padding: 14px 16px;
        font-size: 1rem;
        min-height: 56px;
    }
    
    /* Ensure buttons are large enough */
    .btn-login,
    .btn-register {
        min-height: 56px;
        font-size: 1rem;
    }
}

/* Touch device specific fixes */
.touch-device .user-menu:hover .user-dropdown {
    /* Disable hover on touch - rely on .active class */
    opacity: 0;
    visibility: hidden;
}

.touch-device .user-menu.active .user-dropdown {
    opacity: 1;
    visibility: visible;
}

/* Prevent text selection on interactive elements */
.mobile-menu-toggle,
.user-menu-button,
.modern-header .nav-link,
.btn-login,
.btn-register,
.theme-toggle,
.dropdown-link {
    -webkit-user-select: none;
    user-select: none;
}

/* ================================================================
   CREDITS DISPLAY - Header Credits Indicator
   ================================================================ */
.header-credits {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.15), rgba(245, 158, 11, 0.1));
    border: 1px solid rgba(251, 191, 36, 0.3);
    border-radius: 20px;
    color: #fbbf24;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: default;
    transition: all 0.2s ease;
}

.header-credits i {
    font-size: 0.9rem;
}

.header-credits:hover {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.2), rgba(245, 158, 11, 0.15));
    transform: scale(1.02);
}

/* Light theme credits */
[data-theme="light"] .header-credits {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(217, 119, 6, 0.08));
    border-color: rgba(217, 119, 6, 0.3);
    color: #d97706;
}

/* ================================================================
   NOTIFICATIONS - Header Notification Bell
   ================================================================ */
.notification-menu {
    position: relative;
}

.notification-button {
    position: relative;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: rgba(138, 43, 226, 0.2);
}

.notification-button:hover {
    background: var(--accent-purple-10);
    color: var(--text-primary);
}

.notification-button i {
    font-size: 1.1rem;
}

.notification-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--accent-red);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Notification Dropdown */
.notification-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    width: 320px;
    max-height: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s ease;
    z-index: 100;
    overflow: hidden;
}

.notification-menu.active .notification-dropdown,
.notification-menu:focus-within .notification-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

@media (hover: hover) and (pointer: fine) {
    .notification-menu:hover .notification-dropdown {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }
}

.notification-dropdown .dropdown-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
}

.notification-dropdown .dropdown-header h4 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.mark-read-btn {
    background: none;
    border: none;
    color: var(--accent-purple);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.mark-read-btn:hover {
    background: var(--accent-purple-10);
}

.notification-list {
    max-height: 320px;
    overflow-y: auto;
}

.notification-item {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    transition: background 0.2s;
    cursor: pointer;
}

.notification-item:hover {
    background: var(--bg-tertiary);
}

.notification-item.unread {
    background: rgba(138, 43, 226, 0.05);
}

.notification-item .notification-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-purple-10);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-purple);
    flex-shrink: 0;
}

.notification-item .notification-content {
    flex: 1;
    min-width: 0;
}

.notification-item .notification-content p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-primary);
    line-height: 1.4;
}

.notification-item .notification-time {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 4px;
    display: block;
}

.empty-notification {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-tertiary);
}

.empty-notification i {
    font-size: 2rem;
    margin-bottom: 8px;
    opacity: 0.5;
}

.empty-notification p {
    margin: 0;
    font-size: 0.9rem;
}

/* ================================================================
   LOGOUT BUTTON - Styled Logout
   ================================================================ */
.logout-btn {
    width: 100%;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    color: var(--accent-red) !important;
}

.logout-btn:hover {
    background: rgba(239, 68, 68, 0.1) !important;
}

/* ================================================================
   USER AVATAR WITH IMAGE
   ================================================================ */
.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* ================================================================
   MOBILE RESPONSIVE ADJUSTMENTS
   ================================================================ */
@media (max-width: 992px) {
    .header-credits {
        width: 100%;
        justify-content: center;
        padding: 12px;
        margin: 8px 0;
    }
    
    .notification-menu {
        width: 100%;
    }
    
    .notification-button {
        width: 100%;
        justify-content: space-between;
        padding: 16px;
        min-height: 52px;
    }
    
    .notification-button::after {
        content: 'Notifications';
        margin-left: 12px;
        flex: 1;
        text-align: left;
        font-size: 0.95rem;
    }
    
    .notification-dropdown {
        position: static;
        width: 100%;
        max-height: none;
        border: none;
        border-radius: 0;
        box-shadow: none;
        background: var(--bg-tertiary);
        display: none;
    }
    
    .notification-menu.active .notification-dropdown {
        display: block;
    }
}

@media (max-width: 576px) {
    .notification-dropdown {
        width: 100%;
    }
}

/* ================================================================
   LIGHT THEME OVERRIDES
   ================================================================ */
[data-theme="light"] .modern-header {
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-light);
}

[data-theme="light"] .modern-header .nav-link {
    color: var(--text-secondary) !important;
}

[data-theme="light"] .modern-header .nav-link:hover {
    color: var(--text-primary) !important;
}

[data-theme="light"] .modern-header .nav-link.active {
    color: var(--accent-purple) !important;
}

[data-theme="light"] .toggle-bar {
    background-color: var(--text-primary);
}

[data-theme="light"] .user-menu-button {
    color: var(--text-secondary);
}

[data-theme="light"] .user-menu-button:hover {
    color: var(--text-primary);
}

[data-theme="light"] .user-name {
    color: var(--text-primary);
}

[data-theme="light"] .user-dropdown {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
}

[data-theme="light"] .dropdown-item {
    color: var(--text-primary);
}

[data-theme="light"] .dropdown-item:hover {
    background: var(--bg-tertiary);
}

[data-theme="light"] .notification-button {
    color: var(--text-secondary);
}

[data-theme="light"] .notification-button:hover {
    color: var(--text-primary);
}

[data-theme="light"] .notification-dropdown {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
}

[data-theme="light"] .notification-dropdown .dropdown-header h4 {
    color: var(--text-primary);
}

[data-theme="light"] .notification-item {
    border-bottom-color: var(--border-light);
}

[data-theme="light"] .notification-content p {
    color: var(--text-primary);
}

[data-theme="light"] .notification-time {
    color: var(--text-muted);
}
