/* ==========================================================================
   Component: Header
   Includes: site-header, nav, actions, info line, mobile menu
   ========================================================================== */

.site-header {
    position: sticky;
    top: 0;
    background: var(--color-bg);
    z-index: 100;
}

/* --- Header Top Line --- */
.header-top {
    position: relative;
    z-index: 100;
    padding: 8px var(--page-padding);
}

.header-top__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: var(--container-max);
    margin: 0 auto;
}

.header-top__logo {
    flex-shrink: 0;
    width: 200px;
    height: 80px;
    display: flex;
    align-items: center;
    overflow: hidden;
}

/* --- Logo --- */
.header-logo {
    position: relative;
    display: flex;
    align-items: center;
    width: 170px;
    height: 50px;
}

.header-logo:hover {
    opacity: 1;
}

.header-logo__img {
    width: 170px;
    height: 50px;
    display: block;
    object-fit: contain;
    object-position: left center;
}

.header-top__right {
    display: flex;
    align-items: center;
    gap: var(--spacing-lg);
}

/* --- Header Nav --- */
.header-nav__list {
    display: flex;
    list-style: none;
    gap: var(--spacing-lg);
}

.header-nav__list li {
    position: relative;
    display: flex;
    align-items: center;
}

.header-nav__list > li > a {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 2px;
    font-size: var(--font-size-base);
    font-weight: 500;
    color: var(--color-text);
    border-bottom: 3px solid transparent;
    transition: border-color 0.2s;
    white-space: nowrap;
}

.header-nav__list > li > a:hover {
    opacity: 1;
    border-bottom-color: var(--color-accent);
}

.header-nav__list .current-menu-item > a,
.header-nav__list .current_page_item > a {
    border-bottom-color: var(--color-accent);
}

/* Chevron for items with children — hidden on full desktop, shown only on compact */
.header-nav__list > li.menu-item-has-children > a::after {
    content: '';
    display: none;
    width: 8px;
    height: 5px;
    margin-left: 6px;
    background: currentColor;
    mask: url("data:image/svg+xml,%3Csvg width='8' height='5' viewBox='0 0 8 5' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L4 4L7 1' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat center;
    mask-size: contain;
    transition: transform 0.25s ease;
}

.header-nav__list > li.menu-item-has-children:hover > a::after {
    transform: rotate(180deg);
}

/* --- Dropdown Submenu --- */
.header-nav__list .sub-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    min-width: 112px;
    list-style: none;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0;
    z-index: 110;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* Invisible bridge to prevent hover gap between link and dropdown */
.header-nav__list .sub-menu::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 0;
    right: 0;
    height: 8px;
}

.header-nav__list li:hover > .sub-menu {
    display: flex;
}

.header-nav__list .sub-menu li {
    display: block;
    border-bottom: 1px solid var(--color-border);
}

.header-nav__list .sub-menu li:last-child {
    border-bottom: none;
}

.header-nav__list .sub-menu a {
    display: block;
    padding: 14px 16px;
    font-size: var(--font-size-base);
    font-weight: 500;
    color: var(--color-text);
    white-space: nowrap;
    transition: background 0.15s;
}

.header-nav__list .sub-menu a:hover {
    opacity: 1;
    background: var(--color-accent-100);
}

/* Touch device: open submenu via JS toggle */
.header-nav__list .sub-menu.is-open {
    display: flex;
}

/* --- Header Actions --- */
.header-actions {
    display: flex;
    align-items: center;
    gap: 3px;
}

.header-actions__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 6px;
    position: relative;
    color: var(--color-text);
    transition: color 0.2s;
}

.header-actions__icon:hover {
    opacity: 1;
    color: var(--color-dark-400);
}

.header-actions__counter {
    position: absolute;
    top: 2px;
    left: 23px;
    width: 18px;
    height: 18px;
    background: var(--color-accent);
    color: var(--color-text);
    font-size: var(--font-size-xs);
    font-weight: 600;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: -0.44px;
    line-height: 18px;
}

/* Login button (guest) */
.header-actions__login-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 50px;
    min-width: 100px;
    padding: 15px 18px;
    margin-left: 13px;
    background: var(--color-accent);
    color: var(--color-text);
    font-size: var(--font-size-base);
    font-weight: 500;
    line-height: 18px;
    border-radius: var(--radius-btn);
    transition: opacity 0.2s;
}

.header-actions__login-btn:hover {
    opacity: 0.85;
}

/* Profile pill (logged in) */
.header-actions__profile {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 50px;
    min-width: 100px;
    padding-left: 5px;
    padding-right: 12px;
    margin-left: 13px;
    background: var(--color-dark-600);
    border-radius: 10px;
    transition: opacity 0.2s;
}

.header-actions__profile:hover {
    opacity: 1;
}

.header-actions__avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--color-accent-50);
    color: var(--color-dark-700);
    font-size: var(--font-size-base);
    font-weight: 500;
    border-radius: 5px;
    line-height: 1;
    transition: background 0.2s;
}

.header-actions__profile:hover .header-actions__avatar {
    background: var(--color-accent);
}

.header-actions__profile-btn {
    color: var(--color-accent);
    font-size: var(--font-size-base);
    font-weight: 500;
    line-height: 18px;
    white-space: nowrap;
}

/* --- Header Burger --- */
.header-burger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    padding: 10px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    margin-left: 16px;
    color: var(--color-text);
    transition: background 0.2s;
}

.header-burger:hover {
    background: var(--color-accent-100);
}

.header-burger__close {
    display: none;
}

.header-burger[aria-expanded="true"] .header-burger__open {
    display: none;
}

.header-burger[aria-expanded="true"] .header-burger__close {
    display: block;
}

/* --- Header Info Line --- */
.header-info {
    position: relative;
    z-index: 90;
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
    padding: 12px var(--page-padding);
}

.header-info__inner {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--spacing-lg);
    max-width: var(--container-max);
    margin: 0 auto;
}

.header-info__item {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text);
    line-height: 18px;
    white-space: nowrap;
}

.header-info__item:hover {
    opacity: 0.7;
}

.header-info__social {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.social-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

.social-icon:hover {
    opacity: 0.7;
}

.social-icon--lg {
    width: 32px;
    height: 32px;
}

/* ==========================================================================
   Scroll Lock — applied by JS when mobile menu is open.
   Uses position:fixed on body for bulletproof iOS Safari support.
   ========================================================================== */

html.menu-open,
html.menu-open body {
    overflow: hidden;
    height: 100%;
}

html.menu-open body {
    position: fixed;
    width: 100%;
}

/* ==========================================================================
   Mobile Menu
   ========================================================================== */

.mobile-menu {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99;
    display: flex;
    pointer-events: none;
    visibility: hidden;
}

.mobile-menu.is-open {
    pointer-events: auto;
    visibility: visible;
}

.mobile-menu[hidden] {
    display: none;
}

/* Dark backdrop overlay */
.mobile-menu__backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(16, 19, 23, 0.3);
    z-index: 0;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-menu.is-open .mobile-menu__backdrop {
    opacity: 1;
}

/* Slide-in panel */
.mobile-menu__panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 100%;
    height: 100%;
    background: var(--color-bg);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    transform: translateY(-100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-menu.is-open .mobile-menu__panel {
    transform: translateY(0);
}

/* Invisible spacer that clears the sticky header.
   Height is set per-breakpoint in the responsive section below. */
.mobile-menu__spacer {
    flex-shrink: 0;
}

.mobile-menu__body {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md);
    gap: 12px;
}

.mobile-menu__nav {
    text-align: center;
}

.mobile-menu__list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
}

.mobile-menu__list a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-sm) 2px;
    font-size: var(--font-size-base);
    font-weight: 500;
    color: var(--color-text);
    border-bottom: 3px solid transparent;
    transition: border-color 0.2s;
}

.mobile-menu__list a:hover {
    opacity: 1;
    border-bottom-color: var(--color-accent);
}

.mobile-menu__list .current-menu-item > a,
.mobile-menu__list .current_page_item > a {
    border-bottom-color: var(--color-accent);
}

/* Mobile submenu (e.g. Услуги children) */
.mobile-menu__list .sub-menu {
    list-style: none;
    display: none;
    flex-direction: column;
    gap: 2px;
    align-items: center;
    padding: var(--spacing-xs) 0;
}

.mobile-menu__list .sub-menu.is-open {
    display: flex;
}

.mobile-menu__list .sub-menu a {
    font-size: var(--font-size-sm);
    color: var(--color-dark-400);
    border-bottom: none;
    padding: 6px 2px;
}

.mobile-menu__list .sub-menu a:hover {
    color: var(--color-text);
}

/* Login button in mobile menu */
.mobile-menu__login-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 100px;
    max-width: 163px;
    width: 100%;
    padding: 15px 18px;
    background: var(--color-accent);
    color: var(--color-text);
    font-size: var(--font-size-base);
    font-weight: 500;
    line-height: 18px;
    border-radius: var(--radius-btn);
    transition: opacity 0.2s;
}

.mobile-menu__login-btn:hover {
    opacity: 0.85;
}

/* Profile pill in mobile menu */
.mobile-menu__profile {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    height: 50px;
    min-width: 100px;
    padding-left: 5px;
    padding-right: 12px;
    background: var(--color-dark-600);
    border-radius: var(--radius-lg);
    transition: opacity 0.2s;
}

.mobile-menu__profile:hover {
    opacity: 1;
}

.mobile-menu__avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--color-accent-50);
    color: var(--color-dark-700);
    font-size: var(--font-size-base);
    font-weight: 500;
    border-radius: 5px;
    line-height: 1;
    transition: background 0.2s;
}

.mobile-menu__profile:hover .mobile-menu__avatar {
    background: var(--color-accent);
}

.mobile-menu__profile-btn {
    color: var(--color-accent);
    font-size: var(--font-size-base);
    font-weight: 500;
    line-height: 18px;
    white-space: nowrap;
}

.mobile-menu__footer {
    flex-shrink: 0;
    background: var(--color-accent-100);
    padding: var(--spacing-lg) var(--spacing-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
}

.mobile-menu__contacts {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text);
    line-height: 18px;
}

.mobile-menu__contacts a {
    text-decoration: underline;
}

.mobile-menu__social {
    display: flex;
    gap: var(--spacing-md);
    align-items: center;
}

/* --- Nav Overflow Dropdown (compact desktop) --- */
.header-nav__overflow {
    display: none;
    position: relative;
}

.header-nav__overflow-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
}

.header-nav__overflow-dot {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: var(--color-accent-200);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    transition: background 0.15s;
}

.header-nav__overflow-btn:hover .header-nav__overflow-dot {
    background: var(--color-accent-100);
    border: 1px solid var(--color-border);
}

.header-nav__overflow-list {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 112px;
    list-style: none;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0;
    margin-top: 8px;
    z-index: 110;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.header-nav__overflow-list.is-open {
    display: flex;
}

.header-nav__overflow-list li {
    border-bottom: 1px solid var(--color-border);
}

.header-nav__overflow-list li:last-child {
    border-bottom: none;
}

.header-nav__overflow-list a {
    display: block;
    padding: 14px 16px;
    font-size: var(--font-size-base);
    font-weight: 500;
    color: var(--color-text);
    white-space: nowrap;
    transition: background 0.15s;
}

.header-nav__overflow-list a:hover {
    opacity: 1;
    background: var(--color-accent-100);
}

/* ==========================================================================
   Header Responsive
   ========================================================================== */

/* --- Compact desktop: overflow dropdown + reduced gap (1154px per Figma) --- */
@media (max-width: 1154px) and (min-width: 1025px) {
    .header-nav__list {
        gap: 12px;
    }

    .header-top__right {
        gap: 16px;
    }

    .header-nav__list > li:nth-child(n+7) {
        display: none;
    }

    /* Show chevron on items with children at compact breakpoint */
    .header-nav__list > li.menu-item-has-children > a::after {
        display: inline-block;
    }

    .header-nav__overflow {
        display: flex;
        align-items: center;
    }
}

/* --- Tablet: <=1024px --- */
@media (max-width: 1024px) {
    .header-top {
        padding: 16px var(--page-padding);
    }

    .header-top__logo {
        width: 100px;
        height: auto;
    }

    .header-logo {
        width: 89px;
        height: 45px;
    }

    .header-logo__img {
        width: 89px;
        height: 45px;
    }

    .header-nav {
        display: none;
    }

    .header-nav__overflow {
        display: none;
    }

    .header-burger {
        display: flex;
        margin-left: 6px;
    }

    /* Profile: avatar-only circle on tablet */
    .header-actions__profile-btn {
        display: none;
    }

    .header-actions__profile {
        gap: 0;
        height: auto;
        min-width: 0;
        padding: 0;
        background: none;
        border-radius: 0;
    }

    .header-actions__avatar {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background: var(--color-accent);
        color: var(--color-text);
    }

    .header-actions__profile:hover .header-actions__avatar {
        opacity: 0.85;
    }
}

/* --- Tablet mobile menu: 769-1024px --- */
@media (min-width: 769px) and (max-width: 1024px) {
    /* Panel slides down from behind the header as a dropdown overlay.
       Height adapts to content; backdrop is visible below. */
    .mobile-menu__panel {
        height: auto;
        max-height: 100%;
        overflow-y: auto;
    }

    /* Spacer clears the sticky header (header-top ~77px + header-info ~43px) */
    .mobile-menu__spacer {
        height: 120px;
    }

    .mobile-menu__body {
        flex: none;
        padding: var(--spacing-xl) var(--spacing-lg);
        gap: var(--spacing-lg);
    }

    .mobile-menu__list {
        gap: var(--spacing-md);
    }

    .mobile-menu__list a {
        font-size: var(--font-size-lg);
        line-height: 20px;
    }

    /* Hide submenus on tablet — parent items navigate directly */
    .mobile-menu__list .sub-menu {
        display: none;
    }

    .mobile-menu__list > li.menu-item-has-children > a::after {
        display: none;
    }

    /* Login/profile visible in header bar — hide duplicate in menu on tablet */
    .mobile-menu__login-btn,
    .mobile-menu__profile {
        display: none;
    }

    /* Show footer on tablet with contacts and social */
    .mobile-menu__footer {
        padding: var(--spacing-lg);
    }
}

/* --- Mobile: <=768px --- */
@media (max-width: 768px) {
    /* Hide login/profile in header bar — it moves into the mobile menu */
    .header-actions__login-btn,
    .header-actions__profile {
        display: none;
    }

    /* Full-screen panel on mobile */
    .mobile-menu__panel {
        height: 100%;
    }

    /* Spacer clears header-top ~77px + header-info ~43px = ~120px */
    .mobile-menu__spacer {
        height: 120px;
    }

    .mobile-menu__list {
        gap: var(--spacing-sm);
    }

    .mobile-menu__list a {
        font-size: var(--font-size-base);
    }

    .mobile-menu__body {
        gap: var(--spacing-md);
    }

    .mobile-menu__footer {
        padding: var(--spacing-lg);
    }

    .mobile-menu__contacts {
        flex-direction: column;
        align-items: center;
        gap: var(--spacing-md);
    }

    .mobile-menu__contacts a {
        text-decoration: underline;
    }

    /* Hide submenus on mobile — parent items navigate directly */
    .mobile-menu__list .sub-menu {
        display: none;
    }

    .mobile-menu__list > li.menu-item-has-children > a::after {
        display: none;
    }
}

/* --- Small tablet: <=600px — hide info line --- */
@media (max-width: 600px) {
    .header-info {
        display: none;
    }

    /* Info line is hidden, so spacer only needs to clear header-top ~77px */
    .mobile-menu__spacer {
        height: 80px;
    }
}

/* --- Mobile small: <=430px --- */
@media (max-width: 430px) {
    .mobile-menu__list {
        gap: var(--spacing-xs);
    }

    .mobile-menu__body {
        gap: 12px;
    }

    .mobile-menu__footer {
        padding: var(--spacing-md);
    }

    .mobile-menu__contacts {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 12px;
    }
}
