/**
 * ПРОМТ G: меню/шапка — отступы и dropdown (только CSS override)
 * Пункт 8: focus-visible для ссылок/кнопок в меню
 * Отступы контента от фиксированной шапки для мобильной версии
 */
body.page-search .header__search-row {
    display: none !important;
}

/* На странице поиска убираем верхний отступ body (100px на мобильной) — контент ближе к шапке */
body.page-search {
    padding-top: 0 !important;
}

/* Баланс в мобильной шапке */
.header__balance-mobile {
    color: orange !important;
    font-size: 15px !important;
}

/* Хедер: всегда кликабельный поверх любых оверлеев/лейаутов */
.header__main {
    z-index: 1000001 !important;
    pointer-events: auto !important;
}
.header__main * {
    pointer-events: auto;
}
.header__mobile-menu {
    position: relative;
    z-index: 1000002;
}
.header__mobile-items {
    z-index: 1000002 !important;
}

/* Мобильное меню гамбургера: фикс. слой на весь экран, блокировка скролла страницы (Safari / iOS) */
html.mobile-menu-open,
body.mobile-menu-open {
    overflow: hidden !important;
    overscroll-behavior: none;
    height: 100%;
}

@media (max-width: 1200px) {
    ul.header__mobile-items.mobile-menu {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: none !important;
        z-index: 9999 !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        padding-top: calc(72px + env(safe-area-inset-top, 0px)) !important;
        padding-bottom: env(safe-area-inset-bottom, 0px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Строки под первой линией шапки — не поверх панели меню */
    html.mobile-menu-open .header__hotlinks-row,
    html.mobile-menu-open .header__search-row,
    html.mobile-menu-open .homepage-mobile-category-dropdown {
        visibility: hidden !important;
        pointer-events: none !important;
    }

    /* Первая линия шапки (лого, вход, гамбургер) — кликабельна поверх затемнения */
    html.mobile-menu-open .header__container > .header__inner {
        position: relative;
        z-index: 10000;
    }

    html.mobile-menu-open .header__mobile-menu {
        z-index: 10001 !important;
    }
}

main, .main, .page-container, .content, section {
    scroll-margin-top: calc(100px + env(safe-area-inset-top, 0px));
}

/* Страницы: стать писателем, форум, профиль, контент — отступ от шапки */
.profile_main, .authors-content-text, .forum_page, .forum_wrapper, .about_info, .cntl-wrapper {
    padding-top: 20px;
}

/* Все страницы: отступ контента от хидера */
.main-site-wrapper,
main .content,
.page-container,
.library-container {
    padding-top: 20px;
}

/* Не главная: заметный разрыв между шапкой и контентом */
.main-site-wrapper:not(:has(.homepage-block)),
.main-site-wrapper:not(:has(.homepage-block)) main .content,
.main-site-wrapper:not(:has(.homepage-block)) .page-container,
.main-site-wrapper:not(:has(.homepage-block)) .library-container,
.main-site-wrapper:not(:has(.homepage-block)) .cntl-wrapper {
    padding-top: 36px;
}
body.page-catalog .start_author {
    box-sizing: border-box;
    width: calc(100% - 32px) !important;
    max-width: 1200px !important;
    margin: 20px auto 0;
    left: auto !important;
    transform: none !important;
}
@media (max-width: 767px) {
    body {
        padding-top: 0 !important;
    }
    /* Сжатие шапки по ширине экрана без горизонтального overflow от вложенного flex */
    .header__main .header__container {
        min-width: 0;
        max-width: 100%;
    }
    .header__main {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
    }
    /* На странице поиска — margin-top: 0 вместо 100px (site.css задаёт html .main-site-wrapper) */
    body.page-search .main-site-wrapper {
        margin-top: 0 !important;
    }
    .header__inner {
        padding-bottom: 0;
    }
    .main, .page-container, .content {
        padding-top: 24px;
    }
    section {
        scroll-margin-top: calc(120px + env(safe-area-inset-top, 0px));
    }
    .profile_main, .authors-content-text, .forum_page, .forum_wrapper, .about_info, .cntl-wrapper {
        padding-top: 24px;
    }
    .main-site-wrapper,
    main .content,
    .page-container,
    .library-container {
        padding-top: 24px;
    }
    .main-site-wrapper:not(:has(.homepage-block)),
    .main-site-wrapper:not(:has(.homepage-block)) main .content,
    .main-site-wrapper:not(:has(.homepage-block)) .page-container,
    .main-site-wrapper:not(:has(.homepage-block)) .library-container,
    .main-site-wrapper:not(:has(.homepage-block)) .cntl-wrapper {
        padding-top: 32px;
    }
    /* Показываем оранжевый баланс в мобильной шапке */
    .header__balance-mobile {
        display: inline-flex !important;
        align-items: center;
        margin-left: 8px;
    }
    /* Боковые отступы 16px на мобильной убраны по запросу */
    .item.book-card-mini .toptile,
    .catalog-book-card,
    #search-page .catalog-book-card {
        margin-left: 0;
        margin-right: 0;
    }
}
.header__main a:focus-visible,
.header__main button:focus-visible {
    outline: 2px solid var(--bs-primary, #0fa6ab);
    outline-offset: 2px;
}

.header__items {
    gap: 18px;
    align-items: center;
}

.header__mobile-items {
    /* Должно быть поверх контента (меню position: fixed) */
    z-index: 1000002 !important;
}

/* Единая вертикальная сетка шапки (первый ряд) */
.header__main .header__inner {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

.header__main .header__nav,
.header__main .header__menu {
    min-height: 64px;
    align-items: center !important;
}

.header__main .header__items > .header__list {
    display: flex;
    align-items: center;
}

.header__main .header__buttons {
    min-height: 64px;
    display: flex;
    align-items: center;
}

.header__main .header__items > .header__list > a.header__link,
.header__main .header__items > .header__list > a.header__link-active,
.header__main .header__items > .header__list > button.header__link,
.header__main .header__items > .header__list > button.header__link-button {
    display: inline-flex !important;
    align-items: center !important;
    box-sizing: border-box;
    min-height: 40px;
    line-height: 40px !important;
    padding-top: 12px !important;
    padding-bottom: 12px !important;
}

/* Единая вертикальная сетка шапки (второй ряд: быстрые ссылки) */
.header__hotlinks-row {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

.header__hotlinks-inner {
    min-height: 40px;
    display: flex;
    align-items: center !important;
}

.header__hotlink {
    display: inline-flex;
    align-items: center;
    line-height: 40px;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

/* Мобильное меню: без flex, иконка + надпись в одну строку */
a.header__mobile-link,
button.header__mobile-link,
a.header__mobile-link-active {
    display: block !important;
    padding-left: 20px !important;
}

/* Иконка: inline-block, небольшой отступ до надписи */
a.header__mobile-link > i.fa,
button.header__mobile-link > i.fa,
a.header__mobile-link > img,
button.header__mobile-link > img,
a.header__mobile-link-active > i.fa {
    display: inline-block;
    vertical-align: middle;
    width: 22px;
    min-width: 22px;
    margin-right: 8px !important;
    margin-left: 0 !important;
    text-align: center;
}

button.header__mobile-link > i.fa[style] {
    margin-right: 8px !important;
    width: 22px !important;
    min-width: 22px !important;
}

/* Пункты без иконки — отступ слева, чтобы текст шёл в одну колонку */
a.header__mobile-link:not(:has(i)):not(:has(img)),
button.header__mobile-link:not(:has(i)):not(:has(img)) {
    padding-left: 56px !important;
}

/* Подменю: без flex, меньшие вертикальные отступы */
a.header__mobile-drop-down-link,
button.header__mobile-drop-down-link {
    display: block !important;
    padding: 6px 16px 6px 20px !important;
}

a.header__mobile-drop-down-link > i.fa,
a.header__mobile-drop-down-link > img,
button.header__mobile-drop-down-link > i.fa,
button.header__mobile-drop-down-link > img {
    display: inline-block;
    vertical-align: middle;
    width: 22px;
    min-width: 22px;
    margin-right: 8px !important;
    margin-left: 0 !important;
    text-align: center;
}

a.header__mobile-drop-down-link > img[style],
button.header__mobile-drop-down-link > img[style] {
    margin-right: 8px !important;
}

/* Пункты подменю без иконки — выравнивание текста в колонку */
a.header__mobile-drop-down-link:not(:has(i)):not(:has(img)),
button.header__mobile-drop-down-link:not(:has(i)):not(:has(img)) {
    padding-left: 56px !important;
}

.header__drop-down,
.header__mobile-drop-down {
    max-width: min(92vw, 360px);
}

/* «Книги» и «Авторам» — широкая панель как у Книг, не 360px */
.header__drop-down_books {
    max-width: min(1280px, calc(100vw - 32px));
}
.header__drop-down_authors {
    max-width: min(1280px, calc(100vw - 32px));
}

.header__mobile-drop-down-list {
    padding-top: 2px;
    padding-bottom: 2px;
}

.header__mobile-drop-down-link {
    padding: 6px 12px !important;
}

/* OG/FAQ: якоря и фокус не прячутся под фиксированную шапку */
.og_head {
    scroll-margin-top: calc(80px + env(safe-area-inset-top, 0px));
}
@media (max-width: 767px) {
    .og_head {
        scroll-margin-top: calc(100px + env(safe-area-inset-top, 0px));
    }
}

/* Иконка «Сообщения» в шапке (ряд с корзиной) — не только внутри «Сообщество» */
.header__mail-bell {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
    color: rgba(255, 255, 255, 0.92);
}
.header__mail-bell:hover,
.header__mail-bell:focus-visible {
    color: #fff;
}
.header__mail-bell-icon {
    font-size: 20px;
    line-height: 1;
}
.header__main .header__mail-bell,
.header__main .header__mail-bell:visited,
.header__main .header__mail-bell .header__mail-bell-icon,
.header__mail-bell.header__mail-bell--mobile,
.header__mail-bell.header__mail-bell--mobile:visited {
    color: #fff !important;
}
.header__theme-entry,
.header__theme-toggle--mobile {
    display: none !important;
}
.header__mail-bell-badge {
    position: absolute;
    top: 2px;
    right: 0;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    box-sizing: border-box;
    border-radius: 9px;
    background: #e74c3c;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.header__mail-bell.header__mail-bell--mobile {
    display: none !important;
}
.header__theme-entry {
    display: inline-flex;
    align-items: center;
}
.header__theme-toggle {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.94);
    border-radius: 22px;
    min-height: 40px;
    padding: 0 13px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color .16s ease, border-color .16s ease, color .16s ease;
}
.header__theme-toggle:hover,
.header__theme-toggle:focus-visible {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.28);
    color: #fff;
}
.header__theme-toggle:disabled {
    cursor: wait;
    opacity: .68;
}
.header__theme-icon {
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
}
.header__theme-icon--sun {
    color: #ffbd4a;
}
.header__theme-icon--moon {
    display: none;
    color: #dce8ff;
}
.header__theme-switch {
    width: 38px;
    height: 22px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.18);
    position: relative;
    flex: 0 0 auto;
}
.header__theme-switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
    transition: transform .16s ease;
}
.header__theme-toggle[aria-pressed="true"] .header__theme-switch::after {
    transform: translateX(16px);
}
.header__theme-toggle[aria-pressed="true"] .header__theme-icon--sun {
    display: none;
}
.header__theme-toggle[aria-pressed="true"] .header__theme-icon--moon {
    display: inline-flex;
}
.header__theme-label {
    min-width: 55px;
    text-align: left;
}
.header__theme-toggle--mobile {
    display: none;
}
@media (max-width: 1200px) {
    .header__main .header__items > .header__mail-entry {
        display: none !important;
    }
    .header__main .header__items > .header__theme-entry {
        display: none !important;
    }
    .header__mail-bell.header__mail-bell--mobile {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        min-height: 44px;
        color: rgba(255, 255, 255, 0.92);
    }
    .header__theme-toggle--mobile {
        display: inline-flex;
        min-height: 38px;
        padding: 0 10px;
        margin-left: 4px;
    }
    .header__theme-toggle--mobile .header__theme-label {
        display: none;
    }
}
.header__main {
    --header-menu-bg: #2d363e;
    --header-menu-accent: #0fa6ab;
    --header-menu-text: rgba(255, 255, 255, 0.92);
    --header-menu-muted: rgba(255, 255, 255, 0.56);
    --header-menu-hover: rgba(15, 166, 171, 0.15);
    --header-menu-border: rgba(255, 255, 255, 0.14);
    --header-menu-font: 16px;
    --header-menu-line: 1.35;
    --header-menu-icon: 20px;
    --header-menu-row: 40px;
    --header-menu-radius: 6px;
}
.header__main .header__items {
    gap: 18px !important;
    align-items: center !important;
}
.header__main .header__items > .header__list > a.header__link,
.header__main .header__items > .header__list > a.header__link-active,
.header__main .header__items > .header__list > button.header__link,
.header__main .header__items > .header__list > button.header__link-button {
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    min-height: var(--header-menu-row) !important;
    padding: 0 10px !important;
    box-sizing: border-box;
    border-radius: var(--header-menu-radius);
    font-family: inherit;
    font-size: var(--header-menu-font) !important;
    font-weight: 400;
    line-height: 20px !important;
    color: var(--header-menu-text);
    white-space: nowrap;
}
.header__main .header__items > .header__list > a.header__link:hover,
.header__main .header__items > .header__list > a.header__link-active:hover,
.header__main .header__items > .header__list > button.header__link:hover,
.header__main .header__items > .header__list > button.header__link-button:hover,
.header__main .header__items > .header__list:hover > a.header__link,
.header__main .header__items > .header__list:hover > button.header__link-button {
    color: var(--header-menu-accent) !important;
    text-decoration: none;
}
.header__main .header__link i.fa-chevron-down,
.header__main button.header__link i.fa-chevron-down,
.header__main button.header__link-button i.fa-chevron-down {
    width: 12px;
    min-width: 12px;
    margin: 1px 0 0 0 !important;
    font-size: 10px;
    line-height: 1;
    text-align: center;
}
.header__main a.header__link span,
.header__main button.header__link span,
.header__main button.header__link-button span {
    margin-left: 0 !important;
}
.header__main .header__drop-down {
    top: 100%;
    min-width: 220px;
    width: max-content;
    max-width: min(92vw, 360px);
    padding: 14px 16px !important;
    box-sizing: border-box;
    background-color: var(--header-menu-bg) !important;
    border-radius: 0 0 10px 10px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
}
.header__main .header__drop-down-list {
    margin: 0;
    padding: 0;
}
.header__main .header__drop-down-list + .header__drop-down-list {
    margin-top: 4px;
}
.header__main a.header__drop-down-link,
.header__main .header__drop-down-group-summary.header__drop-down-link {
    display: flex !important;
    align-items: flex-start !important;
    min-height: 32px;
    margin: 0 !important;
    padding: 6px 10px !important;
    box-sizing: border-box;
    border-radius: var(--header-menu-radius);
    color: var(--header-menu-text);
    font-size: var(--header-menu-font) !important;
    font-weight: 400;
    line-height: var(--header-menu-line) !important;
    text-align: left;
    text-decoration: none;
    white-space: normal;
    word-break: normal;
    overflow-wrap: anywhere;
}
.header__main a.header__drop-down-link:hover,
.header__main a.header__drop-down-link:focus,
.header__main a.header__drop-down-link.active,
.header__main .header__drop-down-group-summary.header__drop-down-link:hover,
.header__main .header__drop-down-group-summary.header__drop-down-link:focus {
    background-color: var(--header-menu-hover) !important;
    color: var(--header-menu-accent) !important;
}
.header__main .header__drop-down-link i.fa,
.header__main .header__drop-down-link img,
.header__main .header__drop-down-group-summary i.fa:first-child {
    flex: 0 0 var(--header-menu-icon);
    width: var(--header-menu-icon) !important;
    min-width: var(--header-menu-icon) !important;
    height: var(--header-menu-icon);
    margin: 1px 12px 0 0 !important;
    color: var(--header-menu-accent);
    font-size: 18px;
    line-height: var(--header-menu-icon);
    text-align: center;
    object-fit: contain;
    opacity: 0.78;
}
.header__main .header__drop-down-link img[style] {
    margin-right: 12px !important;
}
.header__main .header__drop-down-group-chevron {
    flex: 0 0 12px !important;
    width: 12px !important;
    min-width: 12px !important;
    height: auto !important;
    margin: 5px 0 0 auto !important;
    color: var(--header-menu-accent);
    font-size: 10px !important;
    line-height: 1 !important;
    opacity: 0.78;
}
.header__main .header__drop-down-title,
.header__main .header__drop-down-title_section {
    display: block;
    margin: 0 0 8px !important;
    padding: 0 0 8px !important;
    border-bottom: 1px solid var(--header-menu-border);
    color: var(--header-menu-muted) !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    line-height: 14px;
    letter-spacing: 0.08em !important;
    text-transform: uppercase;
}
.header__main .header__drop-down-list > .header__drop-down-title_section {
    margin: 8px 10px 4px !important;
}
.header__main .header__drop-down-list:first-child > .header__drop-down-title_section {
    margin-top: 0 !important;
}
.header__main .header__drop-down_books,
.header__main .header__drop-down_authors {
    width: min(1280px, calc(100vw - 32px)) !important;
    max-width: min(1280px, calc(100vw - 32px)) !important;
    padding: 0 !important;
    overflow-x: auto;
    overflow-y: auto;
}
.header__main #authors_nav_funnel.header__drop-down_authors {
    width: 300px !important;
    max-width: min(92vw, 300px) !important;
}
.header__main .header__drop-down_books .header__drop-down-columns,
.header__main .header__drop-down_authors .header__drop-down-columns {
    display: grid !important;
    gap: 24px !important;
    margin: 0 !important;
    padding: 20px 28px !important;
    list-style: none;
}
.header__main .header__drop-down_books .header__drop-down-columns {
    grid-template-columns: repeat(4, minmax(180px, 1fr)) !important;
}
.header__main .header__drop-down_authors .header__drop-down-columns {
    grid-template-columns: repeat(5, minmax(180px, 1fr)) !important;
}
.header__main #authors_nav_funnel .header__drop-down-columns {
    grid-template-columns: 1fr !important;
    padding: 14px 16px !important;
}
.header__main .header__drop-down-col {
    display: flex;
    min-width: 0 !important;
    flex-direction: column;
    gap: 4px !important;
}
.header__main .header__drop-down-group-items {
    margin: 2px 0 6px 32px !important;
    padding-left: 10px !important;
}
.header__main .header__drop-down-group-link {
    min-height: 28px;
    padding: 4px 10px !important;
    font-size: 14px !important;
    line-height: 1.35 !important;
}
@media (max-width: 1200px) {
    .header__main .header__items {
        gap: 8px !important;
    }
    .header__main .header__items > .header__list > a.header__link,
    .header__main .header__items > .header__list > a.header__link-active,
    .header__main .header__items > .header__list > button.header__link,
    .header__main .header__items > .header__list > button.header__link-button {
        min-height: 40px !important;
        padding-left: 8px !important;
        padding-right: 8px !important;
    }
}
