/**
 * Global Header Styles
 * Design System Compliant (design-system.md:367-810)
 * Phase 1: Base structure, Quick Nav, Profile Menu, Auth CTAs
 */

/* ========================================
   BASE HEADER STRUCTURE
   ======================================== */

.cjbb-global-header {
    background: var(--neutral-900);
    min-height: 64px;
    padding: 14px var(--space-6);
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    color: var(--neutral-000);
    box-sizing: border-box;
}

/* Theme-aware header background */
html.theme-light .cjbb-global-header {
    background: var(--neutral-900);
}

html.theme-dark .cjbb-global-header {
    background: #000000;
}

.header-container {
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-6);
}

/* Screen reader only text */
.screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ========================================
   LOGO
   ======================================== */

.header-logo {
    display: block;
    height: 40px;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.header-logo:hover {
    opacity: 0.85;
}

.header-logo:focus {
    outline: 2px solid var(--brand-primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.logo-image,
.header-logo img {
    height: 100%;
    max-height: 40px;
    width: auto;
    display: block;
}

.site-name {
    font-family: var(--font-heading);
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
    color: var(--neutral-000);
    display: block;
    line-height: 1.2;
}

/* ========================================
   SEARCH
   ======================================== */

.header-search {
    max-width: 400px;
    position: relative;
}

.search-form {
    position: relative;
    width: 100%;
    margin: 0;
}

.search-input {
    width: 100%;
    height: 40px;
    min-height: 40px;
    padding: 10px 16px 10px 40px;
    background: var(--neutral-000);
    border: 1px solid var(--neutral-300, #D1D5DB);
    border-radius: 9px;
    font-family: var(--font-body);
    font-size: var(--text-base);
    color: var(--neutral-900);
    box-sizing: border-box;
}

.search-input::placeholder {
    color: var(--neutral-500, #6B7280);
}

.search-input:focus {
    outline: 2px solid var(--brand-primary);
    outline-offset: 0;
    border-color: var(--brand-primary);
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--neutral-500, #6B7280);
    pointer-events: none;
    z-index: 1;
}

.search-toggle-mobile {
    display: none;
    width: 44px;
    height: 44px;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--neutral-000);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: background 0.2s ease;
    align-items: center;
    justify-content: center;
}

.search-toggle-mobile svg {
    width: 24px;
    height: 24px;
}

.search-toggle-mobile:hover {
    background: var(--neutral-800);
}

.search-toggle-mobile:focus {
    outline: 2px solid var(--brand-primary);
    outline-offset: 0;
}

/* ========================================
   HEADER ACTIONS (RIGHT SECTION)
   ======================================== */

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

/* ========================================
   ICON BUTTONS (QUICK NAV, MESSENGER, NOTIFICATIONS)
   ======================================== */

.header-icon-button {
    position: relative;
    width: 44px;
    height: 44px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--neutral-000);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.header-icon-button:hover {
    background: var(--neutral-800);
}

.header-icon-button:focus {
    outline: 2px solid var(--brand-primary);
    outline-offset: 0;
}

.header-icon-button svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

/* ========================================
   BADGE INDICATOR (UNREAD COUNTS)
   ======================================== */

.badge-indicator {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    padding: 0 var(--space-1);
    background: var(--error);
    color: var(--neutral-000);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    border-radius: var(--radius-full);
    border: 2px solid var(--neutral-900);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ========================================
   AVATAR BUTTON (PROFILE MENU)
   ======================================== */

.header-avatar-button {
    width: 44px;
    height: 44px;
    padding: 0;
    background: transparent;
    border: 2px solid transparent;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: border-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.header-avatar-button:hover {
    border-color: var(--brand-primary);
}

.header-avatar-button:focus {
    outline: 2px solid var(--brand-primary);
    outline-offset: 2px;
}

.header-avatar-button img {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    display: block;
    object-fit: cover;
}

/* ========================================
   DROPDOWN BASE
   ======================================== */

.header-dropdown-wrapper {
    position: relative;
}

.header-dropdown {
    position: absolute;
    top: calc(100% + var(--space-2));
    right: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: none;
    z-index: 1001;
}

.header-dropdown.is-open {
    display: block;
}

/* ========================================
   QUICK NAV DROPDOWN
   ======================================== */

.quick-nav-dropdown {
    width: 280px;
    padding: var(--space-4);
}

.quick-nav-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-3);
}

.quick-nav-tile {
    width: 80px;
    height: 80px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    text-decoration: none;
    transition: background 0.2s ease;
}

.quick-nav-tile:hover {
    background: var(--bg-tertiary);
}

.quick-nav-tile:focus {
    outline: 2px solid var(--brand-primary);
    outline-offset: 0;
}

.tile-icon {
    width: 32px;
    height: 32px;
    color: var(--brand-primary);
    stroke-width: 2;
}

.tile-label {
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    color: var(--text-primary);
    text-align: center;
}

/* ========================================
   MESSENGER DROPDOWN (PHASE 1: PLACEHOLDER)
   ======================================== */

.messenger-dropdown {
    width: 360px;
    max-height: 450px;
    overflow-y: auto;
}

/* ========================================
   NOTIFICATIONS DROPDOWN (PHASE 1: PLACEHOLDER)
   ======================================== */

.notifications-dropdown {
    width: 400px;
    max-height: 450px;
    overflow-y: auto;
}

/* ========================================
   DROPDOWN HEADER & BODY
   ======================================== */

.dropdown-header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dropdown-header h3 {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin: 0;
}

.mark-all-read {
    font-size: var(--text-sm);
    color: var(--brand-primary-dark);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: var(--space-2);
    font-family: var(--font-body);
    transition: opacity 0.2s ease;
}

.mark-all-read:hover:not(:disabled) {
    opacity: 0.7;
}

.mark-all-read:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.dropdown-body {
    padding: var(--space-4);
}

.placeholder-text {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    text-align: center;
    margin: var(--space-8) 0;
}

/* ========================================
   PROFILE MENU DROPDOWN
   ======================================== */

.profile-menu-dropdown {
    width: 220px;
    padding: var(--space-2);
}

.profile-menu-item {
    display: block;
    padding: var(--space-3) var(--space-4);
    font-family: var(--font-body);
    font-size: var(--text-base);
    font-weight: var(--font-medium);
    color: var(--text-primary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: background 0.2s ease;
}

.profile-menu-item:hover {
    background: var(--bg-secondary);
}

.profile-menu-item:focus {
    outline: 2px solid var(--brand-primary);
    outline-offset: -2px;
}

.profile-menu-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: var(--space-2) 0;
}

.profile-menu-logout {
    color: var(--error-dark, #DC2626);
}

/* ========================================
   THEME TOGGLE (CONTRACT 2: Dark Mode)
   ======================================== */

.theme-toggle-container {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-subtle);
    margin-top: var(--space-2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 44px;
}

html.theme-light .theme-toggle-container {
    border-top-color: var(--neutral-200);
}

html.theme-dark .theme-toggle-container {
    border-top-color: var(--dark-border-default);
}

.theme-toggle-label {
    font-family: var(--font-body);
    font-size: var(--text-base);
    font-weight: var(--font-medium);
    color: var(--text-primary);
}

html.theme-light .theme-toggle-label {
    color: var(--neutral-900);
}

html.theme-dark .theme-toggle-label {
    color: var(--dark-text-primary);
}

.theme-toggle-switch {
    position: relative;
    width: 52px;
    height: 28px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-default);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background 200ms ease;
    padding: 0;
}

html.theme-light .theme-toggle-switch {
    background: var(--neutral-300, #D1D5DB);
    border-color: var(--neutral-400);
}

html.theme-dark .theme-toggle-switch {
    background: var(--dark-bg-tertiary);
    border-color: var(--dark-border-default);
}

.theme-toggle-switch:hover {
    background: var(--bg-quaternary);
}

html.theme-light .theme-toggle-switch:hover {
    background: var(--neutral-400);
}

html.theme-dark .theme-toggle-switch:hover {
    background: var(--dark-bg-quaternary);
}

.theme-toggle-switch:focus {
    outline: 2px solid var(--brand-primary);
    outline-offset: 2px;
}

.theme-toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 24px;
    height: 24px;
    background: var(--neutral-000);
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-sm);
    transition: left 200ms ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

html.theme-light .theme-toggle-knob {
    background: var(--neutral-000);
    left: 2px;
}

html.theme-dark .theme-toggle-knob {
    background: var(--dark-text-primary);
    left: 24px;
}

.theme-icon {
    width: 16px;
    height: 16px;
    color: var(--brand-primary);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.theme-icon-sun {
    display: block;
}

.theme-icon-moon {
    display: none;
}

html.theme-dark .theme-icon-sun {
    display: none;
}

html.theme-dark .theme-icon-moon {
    display: block;
}

/* ========================================
   AUTHENTICATION CTAs (LOGGED-OUT)
   ======================================== */

.header-auth-ctas {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: var(--space-3) var(--space-6);
    font-family: var(--font-body);
    font-size: var(--text-base);
    font-weight: var(--font-medium);
    text-decoration: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 100px;
    box-sizing: border-box;
}

.btn-primary {
    background: var(--brand-primary);
    color: var(--neutral-000);
    border: none;
}

.btn-primary:hover {
    background: var(--brand-primary-dark);
    color: var(--neutral-000);
}

.btn-primary:focus {
    outline: 2px solid var(--brand-primary);
    outline-offset: 2px;
}

.btn-secondary {
    background: transparent;
    color: var(--neutral-000);
    border: 2px solid var(--neutral-600);
}

.btn-secondary:hover {
    background: var(--neutral-800);
}

.btn-secondary:focus {
    outline: 2px solid var(--neutral-600);
    outline-offset: 2px;
}

/* ========================================
   LOGIN MODAL
   ======================================== */

.login-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 1002;
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
}

.login-modal-overlay[style*="display: flex"],
.login-modal-overlay.is-open {
    display: flex;
}

.login-modal-dialog {
    background: var(--neutral-000);
    max-width: 600px;
    width: 100%;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    max-height: 90vh;
    overflow-y: auto;
}

.login-modal-header {
    padding: var(--space-6);
    border-bottom: 1px solid var(--neutral-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
}

.login-modal-title {
    font-size: var(--text-2xl);
    font-weight: var(--font-semibold);
    color: var(--neutral-900);
    margin: 0;
    font-family: var(--font-body);
}

.login-modal-close {
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--neutral-600);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, color 0.2s ease;
}

.login-modal-close:hover {
    background: var(--neutral-100);
    color: var(--neutral-900);
}

.login-modal-close:focus {
    outline: 2px solid var(--brand-primary);
    outline-offset: 0;
}

.login-modal-body {
    padding: var(--space-6);
}

.login-modal-body form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.login-modal-body label {
    font-family: var(--font-body);
    font-size: var(--text-base);
    font-weight: var(--font-medium);
    color: var(--neutral-900);
    margin-bottom: var(--space-2);
    display: block;
}

.login-modal-body input[type="text"],
.login-modal-body input[type="password"] {
    width: 100%;
    min-height: 44px;
    padding: var(--space-3) var(--space-4);
    background: var(--neutral-000);
    border: 1px solid var(--neutral-300);
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: var(--text-base);
    color: var(--neutral-900);
}

.login-modal-body input[type="text"]:focus,
.login-modal-body input[type="password"]:focus {
    outline: 2px solid var(--brand-primary);
    outline-offset: 0;
    border-color: var(--brand-primary);
}

.login-modal-body input[type="submit"] {
    min-height: 44px;
    padding: var(--space-3) var(--space-6);
    background: var(--brand-primary);
    color: var(--neutral-000);
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: var(--text-base);
    font-weight: var(--font-medium);
    cursor: pointer;
    transition: background 0.2s ease;
}

.login-modal-body input[type="submit"]:hover {
    background: var(--brand-primary-dark);
}

.login-modal-body input[type="submit"]:focus {
    outline: 2px solid var(--brand-primary);
    outline-offset: 2px;
}

/* ========================================
   MOBILE SEARCH OVERLAY
   ======================================== */

.mobile-search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--neutral-900);
    z-index: 1002;
    display: none;
    flex-direction: column;
}

.mobile-search-overlay.is-open {
    display: flex;
}

.mobile-search-header {
    height: 64px;
    padding: var(--space-4) var(--space-6);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    border-bottom: 1px solid var(--neutral-700);
}

.mobile-search-close {
    width: 44px;
    height: 44px;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--neutral-000);
    cursor: pointer;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-search-close:hover {
    background: var(--neutral-800);
}

.mobile-search-close:focus {
    outline: 2px solid var(--brand-primary);
    outline-offset: 0;
}

.mobile-search-form {
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.mobile-search-input {
    width: 100%;
    min-height: 56px;
    padding: var(--space-4) var(--space-4) var(--space-4) var(--space-8);
    background: var(--neutral-800);
    border: 1px solid var(--neutral-600);
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: var(--text-lg);
    color: var(--neutral-000);
}

.mobile-search-input::placeholder {
    color: var(--neutral-400);
}

.mobile-search-input:focus {
    outline: 2px solid var(--brand-primary);
    outline-offset: 0;
    border-color: var(--brand-primary);
}

.mobile-search-submit {
    min-height: 56px;
    padding: var(--space-4) var(--space-6);
    background: var(--brand-primary);
    color: var(--neutral-000);
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: var(--text-lg);
    font-weight: var(--font-medium);
    cursor: pointer;
    transition: background 0.2s ease;
}

.mobile-search-submit:hover {
    background: var(--brand-primary-dark);
}

.mobile-search-submit:focus {
    outline: 2px solid var(--brand-primary);
    outline-offset: 2px;
}

/* ========================================
   DESKTOP LAYOUT (≥1280px)
   ======================================== */

@media (min-width: 1280px) {
    .header-container {
        justify-content: flex-start;
    }

    .header-actions {
        margin-left: auto;
    }
}

/* ========================================
   MOBILE RESPONSIVE (<768px)
   ======================================== */

@media (max-width: 767px) {
    /* Header adjustments */
    .cjbb-global-header {
        padding: var(--space-4);
    }

    .header-container {
        gap: var(--space-4);
    }

    /* Logo smaller on mobile */
    .header-logo {
        height: 32px;
    }

    .logo-image,
    .header-logo img {
        max-height: 32px;
    }

    /* Hide desktop search, show mobile toggle */
    .search-form {
        display: none;
    }

    .search-toggle-mobile {
        display: flex;
    }

    /* Auth CTAs adjust */
    .header-auth-ctas {
        gap: var(--space-2);
    }

    .header-auth-ctas .btn {
        min-width: auto;
        padding: var(--space-2) var(--space-3);
        font-size: var(--text-sm);
        white-space: nowrap;
        height: 40px;
        min-height: 40px;
    }

    /* Dropdowns full-width on mobile */
    .quick-nav-dropdown.is-open,
    .messenger-dropdown.is-open,
    .notifications-dropdown.is-open {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        max-width: none;
        max-height: 100vh;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    .messenger-dropdown.is-open,
    .notifications-dropdown.is-open {
        max-height: 65vh;
    }

    /* Profile menu stays positioned */
    .profile-menu-dropdown {
        position: absolute;
        width: 220px;
    }

    /* Quick Nav grid adjusts */
    .quick-nav-grid {
        grid-template-columns: repeat(2, 1fr);
        padding: var(--space-4);
    }
}

/* ========================================
   KEYBOARD & ACCESSIBILITY
   ======================================== */

/* Focus visible enhancement */
:focus-visible {
    outline: 2px solid var(--brand-primary);
    outline-offset: 2px;
}

/* Ensure dropdowns are accessible */
.header-dropdown[aria-hidden="true"] {
    display: none;
}

/* Lock body scroll when mobile overlays open */
body.dropdown-open,
body.search-open,
body.modal-open {
    overflow: hidden;
}

/* CJBB Express: let search take the middle, actions stay right */
header.cjbb-global-header .header-search { flex: 1 1 auto; }
header.cjbb-global-header .header-actions { margin-left: auto; }
header.cjbb-global-header .header-container { display:flex; align-items:center; }
