/* Шапка сайта */
#navbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    padding: 1rem 5%;
    background: rgba(10, 10, 10, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    z-index: 1000;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-sizing: border-box;
}

#navbar.scrolled {
    padding: 0.8rem 5%;
    background: rgba(10, 10, 10, 0.95);
    box-shadow: none;
}

.skip-link {
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 2000;
    padding: 0.7rem 1rem;
    color: var(--bg-primary);
    background: var(--text-primary);
    border-radius: 8px;
    text-decoration: none;
    transform: translateY(-160%);
    transition: transform 0.2s ease;
}

.skip-link:focus {
    transform: translateY(0);
}

.brand-lockup {
    display: inline-flex;
    align-items: center;
    gap: 0.56rem;
    color: var(--text-primary);
    text-decoration: none;
    white-space: nowrap;
    transform-origin: left center;
    transition: transform 0.3s ease;
}

.brand-mark {
    display: block;
    width: 3.47rem;
    height: 2rem;
    flex: 0 0 auto;
    background-color: currentColor;
    -webkit-mask: url('../../assets/brand/codeak-mark.png') center / contain no-repeat;
    mask: url('../../assets/brand/codeak-mark.png') center / contain no-repeat;
}

.brand-name {
    font-size: 1.08rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.02em;
}

.brand-lockup:focus-visible,
.theme-toggle:focus-visible,
.mobile-menu-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
}

/* Светлые состояния шапки */
[data-theme="light"] #navbar {
    background: rgba(255, 255, 255, 0.8);
}

[data-theme="light"] #navbar.scrolled {
    background: rgba(255, 255, 255, 0.95);
}

.nav-actions {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    justify-content: flex-end;
    min-width: fit-content;
}

/* Выпадающая навигация */
.nav-links {
    display: none;
    position: absolute;
    top: calc(100% + 15px);
    right: 5%;
    left: auto;
    width: 260px;
    margin: 0;
    padding: 1rem 1.5rem;
    gap: 0;
    flex-direction: column;
    justify-content: center;
    list-style: none;
    background: transparent;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
    z-index: 1000;
}

[data-theme="light"] .nav-links {
    background: rgba(255, 255, 255, 0.85);
}

.nav-links.active {
    display: flex;
}

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.85rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    position: relative;
    white-space: nowrap;
    opacity: 0.7;
}

.nav-links a:hover {
    color: var(--text-primary);
    opacity: 1;
}

.nav-links a[aria-current="location"] {
    color: var(--text-primary);
    opacity: 1;
}

.nav-links a::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 0;
    width: 0;
    height: 1.5px;
    background: var(--accent);
    transition: width 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-links a:hover::after {
    width: 100%;
}

.nav-links a[aria-current="location"]::after {
    width: 100%;
}

/* Переключатель темы */
.theme-switcher {
    display: flex;
    align-items: center;
}

.theme-toggle {
    --moon-cutout-bg: var(--bg-primary);
    height: 2.6rem;
    width: 2.6rem;
    background: var(--bg-card);
    border: 1.5px solid var(--border-light);
    border-radius: 8px;
    cursor: pointer;
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
}

.theme-toggle:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 15px var(--accent-glow);
}

.theme-toggle .moon {
    position: absolute;
    width: 18px;
    height: 18px;
    opacity: 1;
    transform: scale(1) rotate(-45deg);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    margin-left: 2px;
    margin-bottom: 2px;
}

.theme-toggle .moon::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    background: var(--text-primary);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.theme-toggle .moon::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    background: var(--moon-cutout-bg);
    border-radius: 50%;
    top: 52%;
    left: 55%;
    transform: translate(-35%, -50%);
}

.theme-toggle .sun {
    position: absolute;
    width: 16px;
    height: 16px;
    opacity: 0;
    transform: scale(0.5) rotate(90deg);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.theme-toggle .sun::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background: var(--text-primary);
    border-radius: 50%;
}

.theme-toggle .sun::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 2px;
    border-radius: 50%;
    box-shadow:
        0 -7px 0 0 var(--text-primary),
        0 7px 0 0 var(--text-primary),
        7px 0 0 0 var(--text-primary),
        -7px 0 0 0 var(--text-primary),
        5px 5px 0 0 var(--text-primary),
        -5px -5px 0 0 var(--text-primary),
        5px -5px 0 0 var(--text-primary),
        -5px 5px 0 0 var(--text-primary);
}

[data-theme="light"] .theme-toggle .sun {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

[data-theme="light"] .theme-toggle .moon {
    opacity: 0;
    transform: scale(0.5) rotate(-45deg);
}

[data-theme="light"] .theme-toggle {
    background: var(--bg-card);
    border-color: var(--border);
}

/* Переключатель языка */
.lang-switcher {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.current-lang,
.lang-btn {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: color 0.3s;
}

.lang-btn {
    background: none;
    border: none;
    cursor: pointer;
}

.lang-switcher:hover .current-lang,
.lang-btn:hover {
    color: var(--text-primary);
}

/* Кнопка мобильного меню */
.mobile-menu-toggle {
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    z-index: 1001;
    position: relative;
}

.mobile-menu-toggle span {
    width: 25px;
    height: 3px;
    background: var(--text-primary);
    transition: all 0.3s ease;
    border-radius: 2px;
}

.mobile-menu-toggle.active span:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
    transform: translateX(-10px);
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
}

/* Инструменты внутри мобильного меню */
.mobile-only-450 {
    display: none;
}

.nav-links .mobile-only-450 {
    justify-content: center;
    align-items: center;
    padding: 0.9rem 0 0.45rem;
    margin-top: 0;
    border-top: none;
    width: 100%;
}

.mobile-tools-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.2rem;
    background: var(--bg-card);
    padding: 0.5rem 1.2rem;
    border-radius: 100px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 20px var(--shadow);
    margin: 0 auto;
}

.tool-divider {
    width: 1.5px;
    height: 25px;
    background: var(--border-light);
    opacity: 0.5;
    align-self: center;
    transform: translateX(6px);
}

.mobile-tools-wrapper .theme-toggle {
    --moon-cutout-bg: var(--bg-card) !important;
    margin: 0;
    border: none;
    background: transparent;
    box-shadow: none;
    height: 2rem;
    width: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.mobile-tools-wrapper .theme-toggle:hover {
    box-shadow: none;
}

/* Затемнение страницы под мобильным меню */
.mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 998;
}

.mobile-menu-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: var(--gradient-1);
    z-index: 1002;
    transition: width 0.1s;
}

/* Компактные элементы шапки */
:where(body:not(.page-verify)) .theme-toggle {
    background: transparent;
    border: none;
    width: auto;
    height: auto;
    padding: 0;
    color: var(--text-muted);
}

:where(body:not(.page-verify)) .theme-toggle:hover {
    color: var(--text-primary);
    box-shadow: none;
    border-color: transparent;
}

[data-theme="light"] :where(body:not(.page-verify)) .theme-toggle {
    background: transparent;
    border: none;
}

:where(body:not(.page-verify)) .nav-lang-desktop {
    margin-right: 0.5rem;
}

:where(body:not(.page-verify)) .nav-burger-toggle {
    margin-left: 0.5rem;
    margin-right: 0.5rem;
}

.nav-actions .nav-login-btn {
    padding: 0.7rem 1.6rem;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: 12px;
}

.nav-login-btn[hidden] {
    display: none !important;
}

/* Отличия главной страницы */
.page-home .nav-actions .theme-toggle {
    --moon-cutout-bg: rgba(10, 10, 10);
    width: 2.25rem;
    height: 2.25rem;
}

@media (min-width: 1298px) {
    .page-home .nav-links {
        display: flex;
        position: static;
        top: auto;
        right: auto;
        left: auto;
        width: auto;
        margin: 0 auto;
        padding: 0 1rem;
        gap: 2rem;
        flex-direction: row;
        background: transparent;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        z-index: auto;
    }

    .page-home .mobile-menu-toggle {
        display: none;
    }

    .page-home .nav-actions .btn-primary {
        display: inline-flex;
    }
}

/* Отличия внутренних страниц */
.page-internal #navbar {
    min-height: 80.17px;
    font-family: var(--font-stack);
}

.page-internal #navbar.scrolled {
    padding: 0.9rem 5%;
    min-height: 74px;
}

.page-internal .nav-links {
    display: none !important;
}

.page-internal .nav-links.active {
    display: flex !important;
}

[data-theme="light"] .page-internal .nav-links {
    border-color: var(--border);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.05);
}

.page-internal .nav-links a {
    display: block;
    padding: 0.65rem 0;
    opacity: 0.9;
    transition: all 0.2s;
    white-space: normal;
}

.page-internal .nav-links a::after {
    right: 0;
    bottom: 0;
    height: 1px;
    background: rgba(255, 255, 255, 0.12);
    opacity: 1;
    transition: background-color 0.2s ease, box-shadow 220ms;
    z-index: 2;
}

.page-internal .nav-links a:hover::after {
    background: color-mix(in srgb, var(--accent) 70%, #ffffff 30%);
    box-shadow: none;
}

.page-internal .nav-links li {
    border-bottom: 1px solid var(--border);
}

.page-internal .nav-links li:last-child {
    border-bottom: none;
}

.page-internal .mobile-only-450 {
    display: flex !important;
}

.page-internal .nav-actions .desktop-switcher {
    display: none !important;
}

.page-internal .logo {
    font-family: var(--font-stack);
}

.page-internal .theme-toggle {
    --moon-cutout-bg: var(--bg-card);
}

.page-internal .theme-toggle .moon,
.page-internal .theme-toggle .sun {
    transition: all 0.4s;
}

.page-internal .mobile-tools-wrapper .current-lang {
    display: block;
    line-height: 1;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.page-internal .theme-toggle:focus,
.page-internal .mobile-menu-toggle:focus {
    outline: none;
    box-shadow: none;
    border-radius: 8px;
}

.page-login .nav-login-btn,
.page-forgot .nav-login-btn,
.page-reset .nav-login-btn {
    display: none;
}

.page-contacts #navbar.scrolled {
    padding: 0.8rem 5%;
}

/* Планшетная версия */
@media (min-width: 451px) and (max-width: 1300px) {
    :where(body:not(.page-verify)) .nav-actions .desktop-switcher {
        display: flex;
    }

    :where(body:not(.page-verify)) #navLinks .mobile-only-450 {
        display: none;
    }
}

@media (max-width: 1300px) {
    .nav-actions .btn-primary {
        display: none;
    }

    :where(body:not(.page-verify)) #navLinks.active li {
        width: 100%;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    }

    :where(body:not(.page-verify)) #navLinks.active li:last-child {
        border-bottom: none;
    }

    :where(body:not(.page-verify)) #navLinks.active a {
        position: relative;
        display: flex;
        align-items: center;
        width: 100%;
        padding: 0.8rem 0 0.6rem;
        line-height: 1.25;
    }

    :where(body:not(.page-verify)) #navLinks.active a::after {
        content: '';
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        height: 1px;
        background: rgba(255, 255, 255, 0.12);
        transition: background-color 0.2s ease;
    }

    :where(body:not(.page-verify)) #navLinks.active a:hover::after {
        background: color-mix(in srgb, var(--accent) 70%, #ffffff 30%);
    }

    :where(body:not(.page-verify)) .lang-switcher {
        display: none;
    }
}

/* Мобильная версия */
@media (max-width: 450px) {
    .desktop-switcher {
        display: none !important;
    }

    .mobile-only-450,
    #navLinks .mobile-only-450 {
        display: flex !important;
    }

    .mobile-tools-wrapper .lang-switcher {
        font-weight: 700;
        color: var(--text-primary);
        cursor: pointer;
        font-size: 1rem;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0.2rem 0;
    }

    :where(body:not(.page-verify)) .mobile-tools-wrapper .current-lang {
        display: block;
        line-height: 1;
    }

    :where(body:not(.page-verify)) .mobile-tools-wrapper .lang-switcher {
        transform: translateX(5px);
    }

    :where(body:not(.page-verify)) .tool-divider {
        height: 20px;
    }

    :where(body:not(.page-verify)) .mobile-tools-wrapper .theme-toggle .moon {
        margin-left: 0;
        margin-bottom: 0;
    }

    .nav-actions .desktop-switcher,
    .nav-actions .lang-switcher,
    .nav-actions .theme-toggle {
        display: none;
    }

    :where(body:not(.page-verify)) #navbar {
        padding-left: clamp(10px, 3.5vw, 16px);
        padding-right: clamp(10px, 3.5vw, 16px);
    }

    :where(body:not(.page-verify)) .nav-actions {
        gap: clamp(0.35rem, 2.2vw, 0.9rem);
    }

    :where(body:not(.page-verify)) .nav-actions .btn-outline {
        padding: 0.52rem clamp(0.72rem, 2.6vw, 1.05rem);
        font-size: 0.85rem;
    }

    :where(body:not(.page-verify)) .mobile-menu-toggle {
        padding: 4px 2px 4px 4px;
    }

    .brand-lockup {
        gap: 0.5rem;
    }

    .brand-mark {
        width: 3.04rem;
        height: 1.75rem;
    }

    .brand-name {
        font-size: 0.98rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .skip-link,
    #navbar,
    .nav-links a,
    .theme-toggle,
    .mobile-menu-toggle span {
        transition-duration: 0.01ms;
    }

    .brand-lockup,
    .brand-lockup:hover {
        transform: none;
        transition-duration: 0s;
    }
}

@media (max-width: 360px) {
    :where(body.page-home:not(.page-verify)) .nav-links {
        width: min(92vw, 250px);
    }
}
