/**
 * QMF Lab Header — SaaS navigation
 * Design tokens from ui.quizzman.com/qmf
 */

:root {
    --qmf-header-h: 60px;
    --qmf-header-bg: rgba(255, 255, 255, 0.92);
    --qmf-header-border: #e2e8f0;
    --qmf-header-blur: blur(20px) saturate(1.8);
    --qmf-header-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.02);
    --qmf-header-text: #1e293b;
    --qmf-header-muted: #64748b;
    --qmf-header-btn-bg: rgba(255, 255, 255, 0.7);
    --qmf-header-btn-border: rgba(0, 0, 0, 0.1);
    --qmf-header-btn-hover-bg: rgba(99, 102, 241, 0.08);
    --qmf-header-btn-hover-color: #4f46e5;
    --qmf-header-brand-gradient: linear-gradient(135deg, #4f46e5, #7c3aed);
    --qm-color-border: #e2e8f0;
    --qm-color-accent: #4f46e5;
    --qm-color-accent-soft: rgba(79, 70, 229, 0.1);
    --qm-color-violet-soft: rgba(124, 58, 237, 0.12);
    --qm-color-amber-soft: rgba(245, 158, 11, 0.14);
    --qm-color-neutral-soft: rgba(100, 116, 139, 0.12);
}

[data-theme="dark"],
body.dark-mode {
    --qmf-header-bg: rgba(15, 23, 42, 0.95);
    --qmf-header-border: #1e293b;
    --qmf-header-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 4px 12px rgba(0, 0, 0, 0.15);
    --qmf-header-text: #e2e8f0;
    --qmf-header-muted: #94a3b8;
    --qmf-header-btn-bg: rgba(255, 255, 255, 0.06);
    --qmf-header-btn-border: rgba(255, 255, 255, 0.1);
    --qmf-header-btn-hover-bg: rgba(129, 140, 248, 0.14);
    --qmf-header-btn-hover-color: #a5b4fc;
    --qmf-header-brand-gradient: linear-gradient(135deg, #818cf8, #c4b5fd);
    --qm-color-border: #334155;
    --qm-color-accent: #818cf8;
    --qm-color-accent-soft: rgba(129, 140, 248, 0.16);
    --qm-color-violet-soft: rgba(167, 139, 250, 0.16);
    --qm-color-amber-soft: rgba(251, 191, 36, 0.16);
    --qm-color-neutral-soft: rgba(148, 163, 184, 0.16);
}

body {
    padding-top: var(--qmf-header-h);
}

.lab-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1001;
    height: var(--qmf-header-h);
    background: var(--qmf-header-bg);
    backdrop-filter: var(--qmf-header-blur);
    -webkit-backdrop-filter: var(--qmf-header-blur);
    border-bottom: 1px solid var(--qmf-header-border);
    box-shadow: var(--qmf-header-shadow);
    margin: 0;
    padding: 0;
    display: block;
}

.lab-header__inner {
    max-width: 1320px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px;
    position: relative;
}

.lab-header__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--qmf-header-text);
    transition: opacity 0.2s;
    flex-shrink: 0;
    min-width: 0;
}

.lab-header__brand:hover {
    opacity: 0.85;
}

.lab-header__logo {
    height: 32px;
    width: auto;
    border-radius: 8px;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.lab-header__brand:hover .lab-header__logo {
    transform: scale(1.04);
}

.lab-header__titles {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
}

.lab-header__name {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--qmf-header-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lab-header__sub {
    font-size: 0.68rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--qmf-header-muted);
    opacity: 0.8;
}

.lab-header__center,
.lab-header__qm-group {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--qmf-header-text);
}

.lab-header__qm-logo {
    height: 26px;
    width: auto;
    opacity: 0.85;
}

.lab-header__qm-name {
    font-size: 0.95rem;
    font-weight: 700;
    background: var(--qmf-header-brand-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.lab-header__qm-sub {
    display: none;
}

/* ── SaaS Navigation ─────────────────────────────────────── */
.lab-header__nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1 1 auto;
    min-width: 0;
    margin-left: 4px;
}

.lab-header__nav-link,
.lab-header__nav-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 12px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    color: var(--qmf-header-text);
    text-decoration: none;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    transition: background 180ms ease, color 180ms ease, transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
    white-space: nowrap;
    font-family: inherit;
    line-height: 1;
}

.lab-header__nav-link:hover,
.lab-header__nav-trigger:hover,
.lab-header__nav-item--dropdown:hover .lab-header__nav-trigger {
    background: var(--qmf-header-btn-hover-bg);
    color: var(--qmf-header-btn-hover-color);
    transform: translateY(-1px);
}

.lab-header__nav-link.is-active,
.lab-header__nav-item--dropdown.is-active > .lab-header__nav-trigger-wrap .lab-header__nav-trigger,
.lab-header__nav-item--dropdown.is-open > .lab-header__nav-trigger-wrap .lab-header__nav-trigger {
    background: var(--qm-color-accent-soft);
    color: var(--qm-color-accent);
    border-color: rgba(79, 70, 229, 0.18);
    box-shadow: inset 0 0 0 1px rgba(79, 70, 229, 0.08);
}

.lab-header__nav-badge {
    margin-left: 2px;
}

.lab-header__nav-item {
    position: relative;
}

.lab-header__nav-item--dropdown {
    display: flex;
    align-items: center;
}

.lab-header__nav-trigger-wrap {
    display: inline-flex;
    align-items: center;
    position: relative;
}

.lab-header__nav-chevron {
    opacity: 0.55;
    transition: transform 180ms ease;
}

.lab-header__nav-item--dropdown.is-open .lab-header__nav-chevron,
.lab-header__nav-item--dropdown:hover .lab-header__nav-chevron {
    transform: rotate(180deg);
}

.lab-header__nav-caret-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin-left: -6px;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--qmf-header-muted);
    cursor: pointer;
}

.lab-header__nav-caret-btn:focus-visible {
    outline: 2px solid var(--qm-color-accent);
    outline-offset: 2px;
}

@media (hover: none) {
    .lab-header__nav-caret-btn {
        display: inline-flex;
    }
}

/* Dropdown panel */
.lab-header__dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 320px;
    padding: 10px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid var(--qm-color-border);
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    transition: opacity 180ms ease, transform 180ms ease, visibility 180ms ease;
    z-index: 1100;
}

[data-theme="dark"] .lab-header__dropdown,
body.dark-mode .lab-header__dropdown {
    background: rgba(15, 23, 42, 0.94);
}

.lab-header__nav-item--dropdown.is-open .lab-header__dropdown,
.lab-header__nav-item--dropdown:hover .lab-header__dropdown,
.lab-header__nav-item--dropdown:focus-within .lab-header__dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.lab-header__dropdown-label {
    padding: 4px 10px 8px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--qmf-header-muted);
}

.lab-header__dropdown-item {
    display: grid;
    grid-template-columns: 36px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border-radius: 14px;
    text-decoration: none;
    color: inherit;
    transition: background 160ms ease, transform 160ms ease;
}

.lab-header__dropdown-item:hover,
.lab-header__dropdown-item:focus-visible {
    background: var(--qm-color-accent-soft);
    outline: none;
    transform: translateY(-1px);
}

.lab-header__dropdown-item.is-active {
    background: var(--qm-color-accent-soft);
}

.lab-header__dropdown-item--disabled {
    opacity: 0.62;
    cursor: not-allowed;
}

.lab-header__dropdown-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--qm-color-neutral-soft);
    font-size: 15px;
    font-weight: 700;
    color: var(--qm-color-accent);
}

.lab-header__dropdown-icon--dot::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--qm-color-accent);
}

.lab-header__dropdown-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.lab-header__dropdown-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--qmf-header-text);
}

.lab-header__dropdown-desc {
    font-size: 12px;
    line-height: 1.35;
    color: var(--qmf-header-muted);
}

/* Badges */
.lab-header__badge {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 7px;
    border-radius: 999px;
    line-height: 1.2;
    background: var(--qm-color-neutral-soft);
    color: var(--qmf-header-muted);
    white-space: nowrap;
}

.lab-header__badge--hsk {
    background: var(--qm-color-accent-soft);
    color: var(--qm-color-accent);
}

.lab-header__badge--tocfl {
    background: var(--qm-color-violet-soft);
    color: #7c3aed;
}

.lab-header__badge--soon {
    background: var(--qm-color-amber-soft);
    color: #b45309;
}

.lab-header__badge--beta {
    background: var(--qm-color-violet-soft);
    color: #6d28d9;
}

.lab-header__badge--new {
    background: var(--qm-color-accent-soft);
    color: #4338ca;
}

.lab-header__badge--lab,
.lab-header__badge--docs {
    background: var(--qm-color-neutral-soft);
    color: var(--qmf-header-muted);
}

.lab-header__badge--ontology {
    background: var(--qm-color-accent-soft);
    color: var(--qm-color-accent);
}

.lab-header__badge--yin {
    background: var(--qm-color-violet-soft);
    color: #6d28d9;
}

/* Actions */
.lab-header__actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    margin-left: auto;
}

.lab-header__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--qmf-header-btn-border);
    background: var(--qmf-header-btn-bg);
    color: var(--qmf-header-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    font-family: inherit;
    padding: 0;
}

.lab-header__btn:hover {
    background: var(--qmf-header-btn-hover-bg);
    color: var(--qmf-header-btn-hover-color);
    transform: translateY(-1px);
}

/* Mobile menu button */
.lab-header__menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--qmf-header-btn-border);
    background: var(--qmf-header-btn-bg);
    color: var(--qmf-header-text);
    cursor: pointer;
    transition: all 180ms ease;
    flex-shrink: 0;
}

.lab-header__menu-btn:hover {
    background: var(--qmf-header-btn-hover-bg);
    color: var(--qmf-header-btn-hover-color);
}

.lab-header__menu-btn:focus-visible {
    outline: 2px solid var(--qm-color-accent);
    outline-offset: 2px;
}

/* Mobile drawer */
.lab-header__drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.42);
    z-index: 1098;
}

.lab-header__drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: min(360px, 92vw);
    height: 100vh;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-left: 1px solid var(--qm-color-border);
    box-shadow: -18px 0 50px rgba(15, 23, 42, 0.12);
    z-index: 1099;
    transform: translateX(100%);
    transition: transform 220ms ease;
    display: flex;
    flex-direction: column;
}

[data-theme="dark"] .lab-header__drawer,
body.dark-mode .lab-header__drawer {
    background: rgba(15, 23, 42, 0.98);
}

.lab-header--drawer-open .lab-header__drawer {
    transform: translateX(0);
}

body.lab-header-drawer-open {
    overflow: hidden;
}

.lab-header__drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--qm-color-border);
}

.lab-header__drawer-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--qmf-header-text);
}

.lab-header__drawer-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--qmf-header-btn-border);
    border-radius: 10px;
    background: var(--qmf-header-btn-bg);
    color: var(--qmf-header-text);
    cursor: pointer;
}

.lab-header__drawer-body {
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.lab-header__drawer-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 48px;
    padding: 12px 14px;
    border-radius: 14px;
    text-decoration: none;
    color: var(--qmf-header-text);
    font-size: 15px;
    font-weight: 600;
    transition: background 160ms ease;
}

.lab-header__drawer-link:hover,
.lab-header__drawer-link.is-active {
    background: var(--qm-color-accent-soft);
    color: var(--qm-color-accent);
}

.lab-header__drawer-section {
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid var(--qm-color-border);
}

.lab-header__drawer-section-head {
    padding: 10px 14px;
    background: var(--qm-color-neutral-soft);
}

.lab-header__drawer-section-link {
    font-size: 14px;
    font-weight: 700;
    color: var(--qmf-header-text);
    text-decoration: none;
}

.lab-header__drawer-section-items {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px;
}

.lab-header__drawer-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 10px;
    padding: 12px;
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    transition: background 160ms ease;
}

.lab-header__drawer-item:hover,
.lab-header__drawer-item.is-active {
    background: var(--qm-color-accent-soft);
}

.lab-header__drawer-item--disabled {
    opacity: 0.62;
}

.lab-header__drawer-item-title {
    grid-column: 1;
    font-size: 14px;
    font-weight: 700;
    color: var(--qmf-header-text);
}

.lab-header__drawer-item-desc {
    grid-column: 1 / -1;
    font-size: 12px;
    color: var(--qmf-header-muted);
    line-height: 1.35;
}

/* Tablet: hide top-level badges to save space */
@media (max-width: 1100px) {
    .lab-header__nav-badge {
        display: none;
    }

    .lab-header__nav-link,
    .lab-header__nav-trigger {
        padding: 0 10px;
        font-size: 13px;
    }
}

/* Mobile */
@media (max-width: 900px) {
    .lab-header--has-nav .lab-header__nav {
        display: none;
    }

    .lab-header--has-nav .lab-header__menu-btn {
        display: inline-flex;
    }

    .lab-header--has-nav .lab-header__titles {
        display: none;
    }

    .lab-header--has-nav .lab-header__brand {
        max-width: 42px;
        overflow: hidden;
    }

    .lab-header--has-nav .lab-header__logo {
        height: 30px;
    }
}

@media (max-width: 768px) {
    .lab-header:not(.lab-header--has-nav) .lab-header__brand {
        display: none;
    }

    .lab-header:not(.lab-header--has-nav) .lab-header__qm-group {
        display: flex;
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
    }

    .lab-header__inner {
        padding: 0 12px;
        gap: 8px;
    }

    .lab-header__actions {
        gap: 6px;
    }
}

@media (max-width: 480px) {
    .lab-header__inner {
        padding: 0 10px;
    }

    .lab-header__actions {
        gap: 4px;
    }
}
