/* Unified application header */
.main-header,
.app-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    width: 100vw;
    max-width: none;
    margin: 0 calc(50% - 50vw) 16px;
    padding: 8px;
    background: color-mix(in srgb, var(--body-bg, #f8fafc) 82%, transparent);
    border: 0;
    box-shadow: none;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    overflow: visible;
}

.main-header::before,
.dot-pattern,
.geometric-shape {
    display: none;
}

.app-header__inner {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 62px;
    width: 100%;
    padding: 9px 12px;
    color: var(--text);
    background: var(--surface) !important;
    border: 1px solid var(--border) !important;
    border-radius: 14px;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08) !important;
    overflow: visible !important;
}

/* The home page still carries legacy header rules with higher specificity. */
body.index-page .main-header,
body.index-page .app-header,
body.index-page .app-header__inner {
    overflow: visible !important;
}

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

.app-header__brand-link {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--text);
    text-decoration: none;
}

.app-header__logo,
.header-logo {
    width: 76px;
    height: 34px;
    padding: 0 !important;
    object-fit: contain;
    background: transparent !important;
    border-radius: 0 !important;
}

.app-header__brand-copy {
    display: grid;
    gap: 1px;
    padding-inline-start: 9px;
    border-inline-start: 1px solid var(--border);
    white-space: nowrap;
}

.app-header__brand-copy strong {
    color: var(--text);
    font-size: 14px;
    font-weight: 900;
}

.app-header__brand-copy small {
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 700;
}

.app-header__menu-toggle {
    display: none;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    padding: 0;
    place-items: center;
    color: var(--text);
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
}

.app-header__meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    flex: 0 0 auto;
    min-width: 0;
}

.header-quick-action,
.header-message-link {
    position: relative !important;
    inset: auto !important;
    min-height: 40px;
    width: auto !important;
    height: 40px !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 11px !important;
    color: var(--text) !important;
    background: var(--surface-soft) !important;
    border: 1px solid var(--border) !important;
    border-radius: 10px !important;
    box-shadow: none !important;
    font-size: 12px;
    font-weight: 900;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    transform: none !important;
}

button.header-quick-action {
    font-family: inherit;
    cursor: pointer;
}

.header-quick-action:hover,
.header-quick-action.is-active,
.header-message-link:hover,
.header-message-link.has-unread {
    color: var(--primary) !important;
    background: var(--primary-50) !important;
    border-color: var(--primary-200, var(--primary-100)) !important;
}

.header-add-action {
    color: #fff !important;
    background: var(--primary) !important;
    border-color: var(--primary) !important;
}

.header-add-action:hover,
.header-add-action.is-active {
    color: #fff !important;
    background: var(--primary-700, var(--primary)) !important;
    border-color: var(--primary-700, var(--primary)) !important;
}

.header-barcode-action {
    color: #047857 !important;
    background: #ecfdf5 !important;
    border-color: #a7f3d0 !important;
}

.header-barcode-action:hover {
    color: #fff !important;
    background: #047857 !important;
    border-color: #047857 !important;
}

.header-barcode-dialog {
    width: min(92vw, 570px);
    max-width: none;
    padding: 0;
    color: var(--text);
    background: transparent;
    border: 0;
    border-radius: 18px;
    overflow: visible;
}

.header-barcode-dialog::backdrop {
    background: rgba(15, 23, 42, .58);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.header-barcode-dialog__card {
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: 0 26px 70px rgba(15, 23, 42, .28);
}

.header-barcode-dialog__heading,
.header-barcode-dialog__input-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-barcode-dialog__heading {
    justify-content: space-between;
    margin-bottom: 18px;
}

.header-barcode-dialog__eyebrow {
    display: block;
    margin-bottom: 3px;
    color: #047857;
    font-size: 11px;
    font-weight: 900;
}

.header-barcode-dialog h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    color: var(--text);
    font-size: 20px;
    font-weight: 900;
}

.header-barcode-dialog__close {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    flex: 0 0 38px;
    padding: 0;
    color: var(--text-muted);
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 10px;
    font: 700 24px/1 Arial, sans-serif;
    cursor: pointer;
}

.header-barcode-dialog__form > label {
    display: block;
    margin-bottom: 7px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 800;
}

.header-barcode-dialog__input-row input {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    padding: 10px 13px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 11px;
    outline: 0;
    font: 800 16px/1.2 Consolas, "Courier New", monospace;
    letter-spacing: .03em;
    text-align: left;
}

.header-barcode-dialog__input-row input:focus {
    border-color: #34d399;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, .14);
}

.header-barcode-dialog__input-row button {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 10px 16px;
    color: #fff;
    background: #047857;
    border: 1px solid #047857;
    border-radius: 11px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 900;
    white-space: nowrap;
    cursor: pointer;
}

.header-barcode-dialog__status {
    min-height: 20px;
    margin: 10px 0 0;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 700;
}

.header-barcode-dialog__status.is-error {
    color: var(--danger, #dc2626);
}

.header-message-link .messages-float__badge {
    top: -6px !important;
    inset-inline-start: -5px !important;
    right: auto !important;
}

.header-user-menu {
    position: relative;
}

.header-user-menu > summary {
    list-style: none;
}

.header-user-menu > summary::-webkit-details-marker {
    display: none;
}

.header-user-trigger {
    min-height: 40px;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 3px 6px;
    color: var(--text);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
}

.header-user-trigger:hover,
.header-user-menu[open] .header-user-trigger {
    background: var(--surface-soft);
    border-color: var(--border);
}

.header-user-avatar {
    width: 34px;
    height: 34px;
    display: inline-grid;
    place-items: center;
    flex: 0 0 34px;
    color: var(--primary);
    background: var(--primary-50);
    border: 1px solid var(--primary-100);
    border-radius: 50%;
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
}

.header-user-summary {
    display: grid;
    min-width: 0;
    text-align: start;
}

.header-user-summary strong {
    max-width: 92px;
    overflow: hidden;
    color: var(--text);
    font-size: 12px;
    font-weight: 900;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-user-summary small {
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 700;
}

.header-user-chevron {
    color: var(--text-muted);
    font-size: 9px;
    transition: transform 0.18s ease;
}

.header-user-menu[open] .header-user-chevron {
    transform: rotate(180deg);
}

.header-user-dropdown {
    position: absolute;
    top: calc(100% + 9px);
    inset-inline-end: 0;
    z-index: 110;
    width: 220px;
    padding: 7px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.16);
}

@media (min-width: 1181px) and (hover: hover) and (pointer: fine) {
    .header-user-dropdown::before {
        content: "";
        position: absolute;
        inset-inline: 0;
        top: -10px;
        height: 10px;
    }
}

.header-user-dropdown a,
.header-user-dropdown button {
    width: 100%;
    min-height: 40px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    color: var(--text);
    background: transparent;
    border: 0;
    border-radius: 8px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 800;
    text-align: start;
    text-decoration: none;
    cursor: pointer;
}

.header-user-dropdown a:hover,
.header-user-dropdown button:hover,
.header-user-dropdown a.is-active {
    color: var(--primary);
    background: var(--primary-50);
}

.header-user-dropdown .header-logout-link {
    color: var(--danger);
    border-top: 1px solid var(--border);
    border-radius: 0 0 8px 8px;
}

.header-user-dropdown .header-logout-link:hover {
    color: var(--danger-600, var(--danger));
    background: var(--danger-50);
}

@media (max-width: 1180px) {
    .app-header__menu-toggle {
        display: inline-grid;
        order: 2;
    }

    .app-header__brand {
        order: 1;
        margin-inline-end: auto;
    }

    .app-header__meta {
        order: 3;
    }
}

@media (max-width: 680px) {
    .main-header,
    .app-header {
        padding: 6px;
        margin-bottom: 10px;
    }

    .app-header__inner {
        min-height: 56px;
        gap: 5px;
        padding: 7px;
        border-radius: 12px;
    }

    .app-header__logo,
    .header-logo {
        width: 58px;
        height: 30px;
    }

    .app-header__brand-copy,
    .header-user-summary,
    .header-user-chevron,
    .header-quick-action span {
        display: none;
    }

    .header-quick-action,
    .header-message-link {
        width: 38px !important;
        height: 38px !important;
        min-height: 38px;
        padding: 0 !important;
    }

    .app-header__menu-toggle {
        width: 38px;
        height: 38px;
        flex-basis: 38px;
    }

    .header-user-trigger {
        padding: 2px;
    }

    .header-user-avatar {
        width: 34px;
        height: 34px;
    }

    .header-barcode-dialog__card {
        padding: 16px;
    }

    .header-barcode-dialog__input-row {
        align-items: stretch;
        flex-direction: column;
    }

    .header-barcode-dialog__input-row button {
        width: 100%;
    }
}

@media (max-width: 390px) {
    .app-header__logo,
    .header-logo {
        width: 48px;
    }

    .app-header__meta {
        gap: 3px;
    }
}

/* Keep existing page-level title blocks as the contextual toolbar below the global header. */
html,
body {
    overflow-x: clip;
}

body:not(.login-page) .page-header,
body:not(.login-page) .page-header-card {
    padding: 0 0 13px !important;
    margin: 0 0 16px !important;
    color: var(--text) !important;
    background: transparent !important;
    border: 0 !important;
    border-bottom: 1px solid var(--border) !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

body:not(.login-page) .page-header .header-content,
body:not(.login-page) .page-header-card .header-content {
    gap: 12px;
    align-items: center;
}

body:not(.login-page) .page-header h1,
body:not(.login-page) .page-header h2,
body:not(.login-page) .page-header-card h1,
body:not(.login-page) .page-header-card h2,
body:not(.login-page) .page-title {
    color: var(--text) !important;
    font-size: 22px !important;
    line-height: 1.35;
    font-weight: 900 !important;
}

body:not(.login-page) .page-header p,
body:not(.login-page) .page-header-card p,
body:not(.login-page) .page-subtitle {
    color: var(--text-muted) !important;
    font-size: 13px !important;
    font-weight: 700 !important;
}

body:not(.login-page) .page-header .header-icon-wrapper,
body:not(.login-page) .page-header-card .header-icon-wrapper {
    width: 36px;
    height: 36px;
    color: var(--primary) !important;
    background: var(--primary-50) !important;
    border: 1px solid var(--primary-100);
    border-radius: var(--radius-md);
}

[data-theme="dark"] .app-header__inner,
[data-theme="dark"] body.index-page .app-header__inner {
    color: var(--text) !important;
    background: var(--surface) !important;
    border-color: var(--border) !important;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24) !important;
}
