/* ===========================
   Header — доп. стили (clean)
   =========================== */

/* 1) «Избранное»: небольшой отступ только на узких */
@media (max-width: 991.98px) {
    .header-right .fav-link {
        margin-left: 8px;
    }
}

@media (min-width: 992px) {
    .header-right .fav-link {
        margin-left: 0;
    }
}

/* 2) Правый текст — резиновый блок, корректная обрезка */
.header-right-naming {
    min-width: 0;
}

.header-right-naming-item:first-child {
    max-width: 28ch;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-right-naming-item:last-child {
    max-width: 32ch;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 3) Базовая шапка: устойчивое сжатие и аккуратные отступы */
.header {
    justify-content: space-between !important;
    align-items: center;
    gap: .75rem;
    flex-wrap: nowrap;
    height: auto;
    min-height: 72px;
    padding: 0 12px;
    max-width: 100%;
    overflow-x: clip; /* страховка от горизонтального скролла */
}

/* 4) Левый блок и navbar — сжимаемые; dropdown не режем */
.header-left,
.header .navbar {
    flex: 1 1 auto;
    min-width: 0;
    overflow: visible !important;
}


/* 5) Логотипы не тянут строку */
.header-left-img {
    flex: 0 0 auto;
}

/* 6) Десктоп-меню: не переносить, чуть уплотнить */
@media (min-width: 992px) {
    .header .navbar-nav {
        display: flex;
        flex-wrap: nowrap;
        overflow: hidden;
    }

    .header .navbar-nav > li {
        flex: 0 0 auto;
    }

    .header .navbar-nav .nav-link {
        padding: .5rem .6rem;
    }
}

/* 7) Правый блок — МОЖЕТ сжиматься (фикс скролла) */
.header-right {
    flex: 0 1 auto;
    min-width: 0;
    gap: .5rem;
}

/* 8) Размеры иконок справа */
.header-right-img-item, .header-right-profile-item {
    width: 28px;
    height: 28px;
}

/* 9) Отступ у правого текста */
@media (max-width: 991.98px) {
    .header-right-naming {
        margin-left: 8px;
    }
}

@media (min-width: 992px) {
    .header-right-naming {
        margin-left: 20px;
    }
}

/* 10) Ранний переход в «Меню» на ≤1260px */
@media (max-width: 1260px) {
    .header .d-lg-flex {
        display: none !important;
    }

    /* скрыть десктоп-меню */
    .header .d-lg-none {
        display: block !important;
    }

    /* показать кнопку */
    .header .navbar {
        margin-left: .25rem !important;
    }
}

/* 11) < lg: компактные мелочи */
@media (max-width: 991.98px) {
    .header-left-img {
        width: auto !important;
        display: flex;
        align-items: center;
    }

    .header .navbar {
        margin-left: .25rem !important;
        flex: 0 1 auto;
    }

    .header {
        justify-content: space-between !important;
    }
}

/* 12) Кнопка «Меню» — как пункт навбара */
.btn-menu-link {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    padding: .5rem .6rem;
    line-height: 1.5;
    font-weight: 700;
    color: rgba(0, 0, 0, .55);
}

.btn-menu-link:hover, .btn-menu-link:focus {
    color: rgba(0, 0, 0, .9);
    background: transparent !important;
    box-shadow: none !important;
    outline: none !important;
    text-decoration: none;
}

.btn-menu-link:active {
    box-shadow: none !important;
}

.btn-menu-link.dropdown-toggle::after {
    margin-left: .25rem;
}

/* ===== Режим инициалов ===== */
.header-initials-btn {
    display: none !important; /* по умолчанию скрыта */
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-weight: 700;
    font-size: 14px;
    line-height: 1;
    text-decoration: none;
    background: #E9ECEF;
    border: 1px solid #102F8C;
    color: #343A40;
    position: relative;
    z-index: 2;
    pointer-events: auto;
}

.header-initials-btn:hover, .header-initials-btn:focus {
    background: #102F8C;
    color: #fff;
}

@media (max-width: 480px) {
    /* показываем инициалы, скрываем имя и «выход» */
    .header-right-naming h6,
    .header-right-naming .header-right-naming-item {
        display: none !important;
    }

    .header-initials-btn {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        transform: translateY(-3px);
    }

    .logout-link {
        display: none !important;
    }
}

/* 481–575px: оставляем подпись видимой, несмотря на d-none d-sm-block */
@media (min-width: 481px) and (max-width: 575.98px) {
    .header-right-naming .header-right-naming-item.d-none.d-sm-block {
        display: inline-block !important;
    }
}

/* ===== Profile dropdown: стиль как у меню ===== */
.header-right-naming {
    position: relative;
}

.profile-popover {
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 8px;
    min-width: 220px;
    max-width: min(90vw, 320px);
    max-height: min(70vh, 420px);
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
    padding: 8px;
    z-index: 2000;
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    transition: transform 140ms ease, opacity 140ms ease;
}

.profile-popover.is-open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.profile-popover::before {
    content: "";
    position: absolute;
    top: -6px;
    right: 16px;
    width: 10px;
    height: 10px;
    background: #fff;
    border-left: 1px solid #dee2e6;
    border-top: 1px solid #dee2e6;
    transform: rotate(45deg);
}

.pp-body {
    display: grid;
    gap: 6px;
}

.pp-name {
    font-weight: 700;
    color: #212529;
    line-height: 1.2;
    padding: 2px 2px 0;
}

.pp-email {
    font-size: 12px;
    color: #6c757d;
    word-break: break-all;
    padding: 0 2px 4px;
    border-bottom: 1px solid #edf0f2;
    margin-bottom: 4px;
}

.pp-actions {
    display: grid;
    gap: 4px;
}

.pp-link {
    display: block;
    padding: 8px 10px;
    border-radius: 8px;
    font-weight: 600;
    color: #212529;
    text-decoration: none;
}

.pp-link:hover, .pp-link:focus {
    background: #F1F3F5;
    color: #212529;
    text-decoration: none;
    outline: none;
}

.pp-link:active {
    background: #E9ECEF;
}

/* ===== Header dropdown (Меню): такой же стиль ===== */
.header .dropdown-menu {
    border: 1px solid #dee2e6;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
    padding: 8px;
    background: #fff;
    margin-top: 8px;
    transform: translateY(-4px);
    opacity: 0;
    transition: transform 140ms ease, opacity 140ms ease;
    overflow: visible;
    z-index: 2000;
    min-width: 220px;
    max-height: min(70vh, 420px);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.header .dropdown-menu.show {
    transform: translateY(0);
    opacity: 1;
}

.header .dropdown-menu::before {
    content: "";
    position: absolute;
    top: -6px;
    right: 16px;
    width: 10px;
    height: 10px;
    background: #fff;
    border-left: 1px solid #dee2e6;
    border-top: 1px solid #dee2e6;
    transform: rotate(45deg);
}

.header .dropdown-menu[data-popper-placement^="bottom-start"]::before,
.header .dropdown-menu[data-popper-placement^="top-start"]::before {
    right: auto;
    left: 16px;
}

.header .dropdown-item {
    border-radius: 8px;
    padding: 8px 10px;
    font-weight: 600;
    color: #212529;
}

.header .dropdown-item:hover, .header .dropdown-item:focus {
    background: #F1F3F5;
    color: #212529;
}

.header .dropdown-item.active, .header .dropdown-item:active {
    background: #E9ECEF;
    color: #212529;
}

.header .dropdown-divider {
    margin: 6px 4px;
    border-top: 1px solid #edf0f2;
}

@media (max-width: 480px) {
    .header .dropdown-menu {
        min-width: 200px;
    }

    .header .dropdown-item {
        padding: 8px 9px;
    }
}

/* === Показываем/скрываем ПЕРВЫЙ левый логотип по диапазонам === */
/* ≤650px — скрыт, без «дыры» */
@media (max-width: 650px) {
    .header-left-img-item:first-child {
        display: none !important;
    }

    .header-left-img-item:last-child {
        margin-left: 0 !important;
    }

    .header-left-img {
        width: auto !important;
    }

    /* убираем зазор слева у меню */
    .header .navbar.ms-3, .header .d-lg-flex.ms-3 {
        margin-left: 0 !important;
    }
}

/* 651–1259.98px — виден, с зазором 18px */
@media (min-width: 651px) and (max-width: 1259.98px) {
    .header-left-img-item:first-child {
        display: inline-block !important;
    }

    .header-left-img-item:last-child {
        margin-left: 18px !important;
    }

    .header .navbar.ms-3, .header .d-lg-flex.ms-3 {
        margin-left: 1rem !important;
    }

    /* ms-3 */
}

/* 1260–1599.98px — снова скрыт, без «дыры», меню прилипает */
@media (min-width: 1260px) and (max-width: 1599.98px) {
    .header-left-img-item:first-child {
        display: none !important;
    }

    .header-left-img-item:last-child {
        margin-left: 0 !important;
    }

    .header .navbar.ms-3, .header .d-lg-flex.ms-3 {
        margin-left: 0 !important;
    }
}

/* ≥1600px — виден, с зазором 18px */
@media (min-width: 1600px) {
    .header-left-img-item:first-child {
        display: inline-block !important;
    }

    .header-left-img-item:last-child {
        margin-left: 18px !important;
    }

    .header .navbar.ms-3, .header .d-lg-flex.ms-3 {
        margin-left: 1rem !important;
    }
}

/* === Единый размер для обоих логотипов слева === */
:root {
    --header-logo-h: 45px; /* высота логотипов в шапке; подгони при желании */
}

/* оба изображения слева (SVG и PNG) одинаковой высоты */
.header-left-img .header-left-img-item {
    height: var(--header-logo-h) !important;
    width: auto !important;
    display: inline-block;
    vertical-align: middle;
    object-fit: contain;
    line-height: 0; /* убираем возможный «воздух» по базовой линии */
}

/* на очень узких экранах чуть уменьшим высоту */
@media (max-width: 480px) {
    :root {
        --header-logo-h: 32px;
    }
}

