/* =========================================================
   USER APP — HEADER
   File: user_app/assets/css/header.css

   Responsibility:
   - Application header
   - Topbar
   - Header branding
   - Header actions
   - Mobile menu trigger
   - User header area
   - Notification trigger
   - Header search
   - Header states

   Dependencies:
   - variables.css
   - reset.css
   - base.css
   - layout.css

   Do NOT put:
   - Sidebar styles
   - Navigation menu styles
   - Page-specific styles
   - Button component styles
   ========================================================= */


/* =========================================================
   1. HEADER ROOT
   ========================================================= */

.app-header {
    position: relative;
    z-index: var(--z-header, 100);

    width: 100%;
    min-height: var(--header-height, 64px);

    background: var(--color-surface, #ffffff);
    border-bottom: 1px solid var(--color-border, #e2e8f0);

    color: var(--color-text, #0f172a);

    transition:
        background-color var(--transition-normal, 200ms ease),
        border-color var(--transition-normal, 200ms ease),
        box-shadow var(--transition-normal, 200ms ease);
}


/* Sticky header support */

.app-header--sticky {
    position: sticky;
    top: 0;
}


/* Elevated header */

.app-header--elevated {
    box-shadow: var(
        --shadow-sm,
        0 1px 3px rgba(15, 23, 42, 0.08)
    );
}


/* Transparent variant */

.app-header--transparent {
    background: transparent;
    border-bottom-color: transparent;
    box-shadow: none;
}


/* =========================================================
   2. HEADER INNER
   ========================================================= */

.app-header__inner {
    width: 100%;
    max-width: var(
        --container-xl,
        1280px
    );

    min-height: var(--header-height, 64px);

    margin-inline: auto;
    padding-inline: var(--space-4, 1rem);

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: var(--space-4, 1rem);
}


/* Full width header inner */

.app-header__inner--fluid {
    max-width: none;
}


/* =========================================================
   3. HEADER LEFT
   ========================================================= */

.app-header__left {
    min-width: 0;

    display: flex;
    align-items: center;

    gap: var(--space-3, 0.75rem);
}


/* =========================================================
   4. HEADER CENTER
   ========================================================= */

.app-header__center {
    min-width: 0;
    flex: 1;

    display: flex;
    align-items: center;
    justify-content: center;

    gap: var(--space-3, 0.75rem);
}


/* =========================================================
   5. HEADER RIGHT
   ========================================================= */

.app-header__right {
    min-width: 0;

    display: flex;
    align-items: center;
    justify-content: flex-end;

    gap: var(--space-2, 0.5rem);
}


/* =========================================================
   6. BRAND
   ========================================================= */

.app-header__brand {
    min-width: 0;

    display: inline-flex;
    align-items: center;

    gap: var(--space-3, 0.75rem);

    color: var(--color-text, #0f172a);
    text-decoration: none;

    white-space: nowrap;

    transition:
        color var(--transition-fast, 150ms ease),
        opacity var(--transition-fast, 150ms ease);
}


.app-header__brand:hover {
    color: var(--color-primary, #2563eb);
}


.app-header__brand:focus-visible {
    outline: 2px solid var(--color-primary, #2563eb);
    outline-offset: 4px;
    border-radius: var(--radius-sm, 0.375rem);
}


/* =========================================================
   7. BRAND LOGO
   ========================================================= */

.app-header__logo {
    width: var(--avatar-lg, 44px);
    height: var(--avatar-lg, 44px);

    flex: 0 0 auto;

    display: grid;
    place-items: center;

    overflow: hidden;

    border-radius: var(
        --radius-md,
        0.625rem
    );

    background: var(
        --color-primary,
        #2563eb
    );

    color: #ffffff;

    box-shadow: var(
        --shadow-xs,
        0 1px 2px rgba(15, 23, 42, 0.08)
    );
}


.app-header__logo img,
.app-header__logo svg {
    display: block;

    width: 100%;
    height: 100%;

    object-fit: contain;
}


/* Logo icon only */

.app-header__logo--icon {
    width: 40px;
    height: 40px;
}


/* =========================================================
   8. BRAND TEXT
   ========================================================= */

.app-header__brand-text {
    min-width: 0;

    display: flex;
    flex-direction: column;

    justify-content: center;
}


.app-header__title {
    margin: 0;

    color: var(--color-text, #0f172a);

    font-size: var(
        --font-size-lg,
        1.125rem
    );

    font-weight: var(
        --font-weight-bold,
        700
    );

    line-height: 1.2;

    overflow: hidden;
    text-overflow: ellipsis;
}


.app-header__subtitle {
    margin-top: 2px;

    color: var(
        --color-text-muted,
        #64748b
    );

    font-size: var(
        --font-size-xs,
        0.75rem
    );

    font-weight: var(
        --font-weight-medium,
        500
    );

    line-height: 1.3;

    overflow: hidden;
    text-overflow: ellipsis;
}


/* =========================================================
   9. HEADER ACTIONS
   ========================================================= */

.app-header__actions {
    display: flex;
    align-items: center;

    gap: var(--space-1, 0.25rem);
}


.app-header__action {
    position: relative;

    width: 40px;
    height: 40px;

    flex: 0 0 auto;

    display: inline-grid;
    place-items: center;

    padding: 0;

    border: 1px solid transparent;
    border-radius: var(
        --radius-md,
        0.625rem
    );

    background: transparent;
    color: var(
        --color-text-secondary,
        #475569
    );

    cursor: pointer;

    transition:
        background-color var(--transition-fast, 150ms ease),
        border-color var(--transition-fast, 150ms ease),
        color var(--transition-fast, 150ms ease),
        transform var(--transition-fast, 150ms ease);
}


.app-header__action:hover {
    background: var(
        --color-background-secondary,
        #f8fafc
    );

    color: var(
        --color-primary,
        #2563eb
    );
}


.app-header__action:active {
    transform: scale(0.96);
}


.app-header__action:focus-visible {
    outline: none;

    border-color: var(
        --color-primary,
        #2563eb
    );

    box-shadow: 0 0 0 3px var(
        --focus-ring,
        rgba(37, 99, 235, 0.15)
    );
}


/* Action icon */

.app-header__action svg,
.app-header__action img {
    width: 20px;
    height: 20px;

    display: block;

    flex: 0 0 auto;
}


/* =========================================================
   10. MOBILE MENU BUTTON
   ========================================================= */

.app-header__menu-toggle {
    width: 40px;
    height: 40px;

    flex: 0 0 auto;

    display: inline-grid;
    place-items: center;

    padding: 0;

    border: 1px solid var(
        --color-border,
        #e2e8f0
    );

    border-radius: var(
        --radius-md,
        0.625rem
    );

    background: var(
        --color-surface,
        #ffffff
    );

    color: var(
        --color-text,
        #0f172a
    );

    cursor: pointer;

    transition:
        background-color var(--transition-fast, 150ms ease),
        border-color var(--transition-fast, 150ms ease),
        color var(--transition-fast, 150ms ease),
        transform var(--transition-fast, 150ms ease);
}


.app-header__menu-toggle:hover {
    background: var(
        --color-background-secondary,
        #f8fafc
    );

    border-color: var(
        --color-border-strong,
        #cbd5e1
    );

    color: var(
        --color-primary,
        #2563eb
    );
}


.app-header__menu-toggle:active {
    transform: scale(0.96);
}


.app-header__menu-toggle:focus-visible {
    outline: none;

    border-color: var(
        --color-primary,
        #2563eb
    );

    box-shadow: 0 0 0 3px var(
        --focus-ring,
        rgba(37, 99, 235, 0.15)
    );
}


.app-header__menu-toggle svg {
    width: 21px;
    height: 21px;

    display: block;
}


/* =========================================================
   11. HEADER SEARCH
   ========================================================= */

.app-header__search {
    width: min(
        100%,
        var(--header-search-width, 460px)
    );

    min-width: 0;
}


.app-header__search-inner {
    position: relative;

    display: flex;
    align-items: center;

    width: 100%;
}


.app-header__search-icon {
    position: absolute;
    left: 14px;
    top: 50%;

    width: 18px;
    height: 18px;

    transform: translateY(-50%);

    color: var(
        --color-text-muted,
        #64748b
    );

    pointer-events: none;
}


.app-header__search-input {
    width: 100%;
    min-height: 42px;

    padding: 0 44px 0 42px;

    border: 1px solid var(
        --color-border,
        #e2e8f0
    );

    border-radius: var(
        --radius-lg,
        0.75rem
    );

    background: var(
        --color-background-secondary,
        #f8fafc
    );

    color: var(
        --color-text,
        #0f172a
    );

    font: inherit;
    font-size: var(
        --font-size-sm,
        0.875rem
    );

    outline: none;

    transition:
        background-color var(--transition-fast, 150ms ease),
        border-color var(--transition-fast, 150ms ease),
        box-shadow var(--transition-fast, 150ms ease);
}


.app-header__search-input::placeholder {
    color: var(
        --color-text-muted,
        #64748b
    );
}


.app-header__search-input:hover {
    border-color: var(
        --color-border-strong,
        #cbd5e1
    );
}


.app-header__search-input:focus {
    background: var(
        --color-surface,
        #ffffff
    );

    border-color: var(
        --color-primary,
        #2563eb
    );

    box-shadow: 0 0 0 3px var(
        --focus-ring,
        rgba(37, 99, 235, 0.15)
    );
}


/* Search clear button */

.app-header__search-clear {
    position: absolute;
    right: 8px;
    top: 50%;

    width: 30px;
    height: 30px;

    display: grid;
    place-items: center;

    padding: 0;

    transform: translateY(-50%);

    border: 0;
    border-radius: 50%;

    background: transparent;

    color: var(
        --color-text-muted,
        #64748b
    );

    cursor: pointer;
}


.app-header__search-clear:hover {
    background: var(
        --color-background-tertiary,
        #f1f5f9
    );

    color: var(
        --color-text,
        #0f172a
    );
}


/* =========================================================
   12. NOTIFICATION
   ========================================================= */

.app-header__notification {
    position: relative;
}


.app-header__notification-badge {
    position: absolute;

    top: 3px;
    right: 3px;

    min-width: 17px;
    height: 17px;

    padding-inline: 4px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    border: 2px solid var(
        --color-surface,
        #ffffff
    );

    border-radius: 999px;

    background: var(
        --color-danger,
        #ef4444
    );

    color: #ffffff;

    font-size: 9px;
    font-weight: 700;

    line-height: 1;

    pointer-events: none;
}


/* =========================================================
   13. USER AREA
   ========================================================= */

.app-header__user {
    position: relative;

    display: flex;
    align-items: center;

    min-width: 0;
}


.app-header__user-button {
    min-width: 0;

    display: inline-flex;
    align-items: center;

    gap: var(--space-2, 0.5rem);

    padding: 5px 8px 5px 5px;

    border: 1px solid transparent;
    border-radius: var(
        --radius-lg,
        0.75rem
    );

    background: transparent;

    color: var(
        --color-text,
        #0f172a
    );

    cursor: pointer;

    transition:
        background-color var(--transition-fast, 150ms ease),
        border-color var(--transition-fast, 150ms ease);
}


.app-header__user-button:hover {
    background: var(
        --color-background-secondary,
        #f8fafc
    );

    border-color: var(
        --color-border,
        #e2e8f0
    );
}


.app-header__user-button:focus-visible {
    outline: none;

    border-color: var(
        --color-primary,
        #2563eb
    );

    box-shadow: 0 0 0 3px var(
        --focus-ring,
        rgba(37, 99, 235, 0.15)
    );
}


/* =========================================================
   14. USER AVATAR
   ========================================================= */

.app-header__avatar {
    width: var(
        --avatar-md,
        40px
    );

    height: var(
        --avatar-md,
        40px
    );

    flex: 0 0 auto;

    display: grid;
    place-items: center;

    overflow: hidden;

    border-radius: 50%;

    background: var(
        --color-primary,
        #2563eb
    );

    color: #ffffff;

    font-size: var(
        --font-size-sm,
        0.875rem
    );

    font-weight: var(
        --font-weight-semibold,
        600
    );

    line-height: 1;
}


.app-header__avatar img {
    width: 100%;
    height: 100%;

    display: block;

    object-fit: cover;
}


/* =========================================================
   15. USER INFORMATION
   ========================================================= */

.app-header__user-info {
    min-width: 0;

    display: flex;
    flex-direction: column;

    text-align: left;
}


.app-header__user-name {
    max-width: 160px;

    color: var(
        --color-text,
        #0f172a
    );

    font-size: var(
        --font-size-sm,
        0.875rem
    );

    font-weight: var(
        --font-weight-semibold,
        600
    );

    line-height: 1.3;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


.app-header__user-role {
    max-width: 160px;

    margin-top: 1px;

    color: var(
        --color-text-muted,
        #64748b
    );

    font-size: var(
        --font-size-xs,
        0.75rem
    );

    line-height: 1.3;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* User dropdown indicator */

.app-header__user-chevron {
    width: 16px;
    height: 16px;

    flex: 0 0 auto;

    color: var(
        --color-text-muted,
        #64748b
    );

    transition:
        transform var(--transition-fast, 150ms ease);
}


.app-header__user-button[aria-expanded="true"]
.app-header__user-chevron {
    transform: rotate(180deg);
}


/* =========================================================
   16. HEADER STATUS
   ========================================================= */

.app-header__status {
    display: inline-flex;
    align-items: center;

    gap: 7px;

    color: var(
        --color-text-secondary,
        #475569
    );

    font-size: var(
        --font-size-xs,
        0.75rem
    );

    font-weight: var(
        --font-weight-medium,
        500
    );
}


.app-header__status-dot {
    width: 8px;
    height: 8px;

    flex: 0 0 auto;

    border-radius: 50%;

    background: var(
        --color-success,
        #22c55e
    );

    box-shadow: 0 0 0 3px var(
        --color-success-soft,
        rgba(34, 197, 94, 0.12)
    );
}


.app-header__status--offline
.app-header__status-dot {
    background: var(
        --color-text-muted,
        #64748b
    );

    box-shadow: none;
}


.app-header__status--warning
.app-header__status-dot {
    background: var(
        --color-warning,
        #f59e0b
    );
}


/* =========================================================
   17. HEADER DIVIDER
   ========================================================= */

.app-header__divider {
    width: 1px;
    height: 28px;

    flex: 0 0 auto;

    background: var(
        --color-border,
        #e2e8f0
    );
}


/* =========================================================
   18. HEADER SPACER
   ========================================================= */

.app-header__spacer {
    flex: 1 1 auto;
    min-width: 0;
}


/* =========================================================
   19. HEADER COLLAPSED STATE
   ========================================================= */

.app-header.is-collapsed {
    box-shadow: var(
        --shadow-sm,
        0 1px 3px rgba(15, 23, 42, 0.08)
    );
}


.app-header.is-hidden {
    transform: translateY(-100%);
    pointer-events: none;
}


/* =========================================================
   20. HEADER LOADING STATE
   ========================================================= */

.app-header.is-loading {
    pointer-events: none;
}


.app-header__loading-bar {
    position: absolute;

    left: 0;
    top: 0;

    width: 100%;
    height: 2px;

    overflow: hidden;

    background: transparent;
}


.app-header__loading-bar::after {
    content: "";

    position: absolute;

    top: 0;
    left: -35%;

    width: 35%;
    height: 100%;

    background: var(
        --color-primary,
        #2563eb
    );

    animation: app-header-loading 1.2s ease-in-out infinite;
}


@keyframes app-header-loading {
    0% {
        left: -35%;
    }

    60% {
        left: 100%;
    }

    100% {
        left: 100%;
    }
}


/* =========================================================
   21. DARK THEME
   ========================================================= */

[data-theme="dark"] .app-header {
    background: var(
        --color-surface,
        #0f172a
    );

    border-bottom-color: var(
        --color-border,
        #334155
    );

    color: var(
        --color-text,
        #f8fafc
    );
}


[data-theme="dark"] .app-header__brand,
[data-theme="dark"] .app-header__title,
[data-theme="dark"] .app-header__user-name {
    color: var(
        --color-text,
        #f8fafc
    );
}


[data-theme="dark"] .app-header__subtitle,
[data-theme="dark"] .app-header__user-role {
    color: var(
        --color-text-muted,
        #94a3b8
    );
}


[data-theme="dark"] .app-header__action:hover,
[data-theme="dark"] .app-header__user-button:hover {
    background: var(
        --color-background-secondary,
        #1e293b
    );

    border-color: var(
        --color-border,
        #334155
    );
}


[data-theme="dark"] .app-header__menu-toggle {
    background: var(
        --color-surface,
        #0f172a
    );

    border-color: var(
        --color-border,
        #334155
    );

    color: var(
        --color-text,
        #f8fafc
    );
}


[data-theme="dark"] .app-header__search-input {
    background: var(
        --color-background-secondary,
        #1e293b
    );

    border-color: var(
        --color-border,
        #334155
    );

    color: var(
        --color-text,
        #f8fafc
    );
}


[data-theme="dark"] .app-header__search-input:focus {
    background: var(
        --color-surface,
        #0f172a
    );
}


[data-theme="dark"] .app-header__notification-badge {
    border-color: var(
        --color-surface,
        #0f172a
    );
}


[data-theme="dark"] .app-header__divider {
    background: var(
        --color-border,
        #334155
    );
}


/* =========================================================
   22. COMPACT HEADER
   ========================================================= */

.app-header--compact {
    min-height: 56px;
}


.app-header--compact .app-header__inner {
    min-height: 56px;
}


.app-header--compact .app-header__logo {
    width: 36px;
    height: 36px;
}


.app-header--compact .app-header__action,
.app-header--compact .app-header__menu-toggle {
    width: 36px;
    height: 36px;
}


.app-header--compact .app-header__avatar {
    width: 34px;
    height: 34px;
}


/* =========================================================
   23. LARGE HEADER
   ========================================================= */

.app-header--large {
    min-height: 76px;
}


.app-header--large .app-header__inner {
    min-height: 76px;
}


.app-header--large .app-header__logo {
    width: 48px;
    height: 48px;
}


/* =========================================================
   24. RESPONSIVE — TABLET
   ========================================================= */

@media (max-width: 900px) {

    .app-header__inner {
        padding-inline: var(--space-3, 0.75rem);
        gap: var(--space-3, 0.75rem);
    }

    .app-header__center {
        justify-content: flex-start;
    }

    .app-header__search {
        width: min(
            100%,
            360px
        );
    }

    .app-header__user-info {
        display: none;
    }

    .app-header__user-button {
        padding-right: 5px;
    }

    .app-header__user-chevron {
        display: none;
    }
}


/* =========================================================
   25. RESPONSIVE — MOBILE
   ========================================================= */

@media (max-width: 640px) {

    .app-header {
        min-height: 58px;
    }

    .app-header__inner {
        min-height: 58px;

        padding-inline: var(--space-2, 0.5rem);

        gap: var(--space-2, 0.5rem);
    }

    .app-header__left,
    .app-header__right {
        gap: var(--space-1, 0.25rem);
    }

    .app-header__center {
        flex: 1 1 auto;
    }

    .app-header__brand-text {
        display: none;
    }

    .app-header__logo {
        width: 38px;
        height: 38px;
    }

    .app-header__menu-toggle,
    .app-header__action {
        width: 38px;
        height: 38px;
    }

    .app-header__search {
        width: 100%;
    }

    .app-header__search-input {
        min-height: 38px;

        padding-left: 38px;
        padding-right: 38px;

        border-radius: var(
            --radius-md,
            0.625rem
        );
    }

    .app-header__search-icon {
        left: 12px;

        width: 17px;
        height: 17px;
    }

    .app-header__search-clear {
        right: 4px;
    }

    .app-header__avatar {
        width: 36px;
        height: 36px;
    }

    .app-header__divider,
    .app-header__status {
        display: none;
    }
}


/* =========================================================
   26. VERY SMALL MOBILE
   ========================================================= */

@media (max-width: 420px) {

    .app-header__search {
        display: none;
    }

    .app-header__center {
        flex: 1;
    }

    .app-header__right {
        margin-left: auto;
    }

    .app-header__notification-badge {
        top: 1px;
        right: 1px;
    }
}


/* =========================================================
   27. REDUCED MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {

    .app-header,
    .app-header *,
    .app-header__loading-bar::after {
        animation: none !important;
        transition: none !important;
    }
}


/* =========================================================
   END OF HEADER.CSS
   ========================================================= */