/* Header */
.header {
    height: var(--header-height);
    background-color: var(--primary-color);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    position: relative;
    z-index: 10;
}

/* Фоновые «линии данных»: четыре тонкие строки из штрихов разной длины
   медленно едут в разные стороны, изредка по строке пробегает светящийся
   импульс. Шапка — своя стопка наложения (z-index: 10), поэтому слой с
   z-index: -1 ложится поверх её фона, но под логотипом и кнопками. Всё
   движение — transform на композиторе, без перерисовок. */
.header-lines {
    --header-lines-rgb: 93, 173, 226;
    position: absolute;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.header-lines span {
    position: absolute;
    left: 0;
    width: 100%;
    height: 1px;
}

/* Штрихи: рисунок на 520px повторяется, слой шире шапки на один период и
   сдвигается ровно на него — цикл замыкается без рывка. Чётные строки едут
   влево (та же анимация в обратную сторону). */
.header-lines span::before {
    content: '';
    position: absolute;
    top: 0;
    left: -520px;
    width: calc(100% + 520px);
    height: 100%;
    background-image: linear-gradient(90deg,
        rgba(var(--header-lines-rgb), 0.03) 0 64px, transparent 0 80px,
        rgba(var(--header-lines-rgb), 0.03) 0 92px, transparent 0 150px,
        rgba(var(--header-lines-rgb), 0.03) 0 238px, transparent 0 262px,
        rgba(var(--header-lines-rgb), 0.03) 0 270px, transparent 0 330px,
        rgba(var(--header-lines-rgb), 0.03) 0 372px, transparent 0 404px,
        rgba(var(--header-lines-rgb), 0.03) 0 452px, transparent 0);
    background-size: 520px 100%;
    animation: header-lines-scroll 60s linear infinite;
    will-change: transform;
}

/* Импульс: светлый хвост длиной 160px пролетает шапку за треть периода,
   остальное время ждёт за краем. */
.header-lines span::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(var(--header-lines-rgb), 0.11)) no-repeat;
    background-size: 160px 100%;
    transform: translateX(-160px);
    animation: header-lines-pulse 9s linear infinite;
    will-change: transform;
}

.header-lines span:nth-child(even)::before,
.header-lines span:nth-child(even)::after {
    animation-direction: reverse;
}

.header-lines span:nth-child(even)::after {
    background-image: linear-gradient(270deg, transparent, rgba(var(--header-lines-rgb), 0.11));
}

.header-lines span:nth-child(1) { top: 18%; }
.header-lines span:nth-child(2) { top: 39%; }
.header-lines span:nth-child(3) { top: 61%; }
.header-lines span:nth-child(4) { top: 82%; }

.header-lines span:nth-child(2)::before { background-position-x: -170px; animation-duration: 85s; }
.header-lines span:nth-child(3)::before { background-position-x: -310px; animation-duration: 70s; }
.header-lines span:nth-child(4)::before { background-position-x: -60px; animation-duration: 95s; }

.header-lines span:nth-child(1)::after { animation-delay: -2s; }
.header-lines span:nth-child(2)::after { animation-duration: 13s; animation-delay: -7s; }
.header-lines span:nth-child(3)::after { animation-duration: 11s; animation-delay: -4s; }
.header-lines span:nth-child(4)::after { animation-duration: 15s; animation-delay: -10s; }

@keyframes header-lines-scroll {
    to { transform: translateX(520px); }
}

@keyframes header-lines-pulse {
    from { transform: translateX(-160px); }
    35%, to { transform: translateX(100%); }
}

@media (prefers-reduced-motion: reduce) {
    .header-lines span::before {
        animation: none;
    }

    .header-lines span::after {
        display: none;
    }
}

/* Высота шапки задана жёстко, поэтому переносить строки в ней нельзя: при
   нехватке места подпись обрезается многоточием, а ниже 1100px убирается
   совсем (бренд уже назван логотипом). */
.header-title {
    margin: 0;
    font-size: 1.2rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-left {
    display: flex;
    align-items: center;
    gap: clamp(10px, 1.5vw, 20px);
    min-width: 0;
}

.logo {
    flex-shrink: 0;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
}

.user-name {
    font-size: 0.9rem;
    white-space: nowrap;
}

.login-link {
    color: var(--text-color);
    text-decoration: none;
    padding: 8px 15px;
    border-radius: 4px;
    transition: background-color 0.3s;
}

.login-link:hover {
    background-color: var(--hover-color);
}

/* User Dropdown */
.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 5px;
    border-radius: 20px;
    transition: background-color 0.3s;
}

.user-info:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.dropdown-arrow {
    transition: transform 0.3s ease;
}

.user-dropdown {
    position: absolute;
    top: calc(var(--header-height) + 5px);
    right: 20px;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 10px 0;
    min-width: 180px;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
}

.user-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    color: var(--primary-color);
    text-decoration: none;
    transition: background-color 0.2s;
}

.dropdown-item:hover {
    background-color: #f5f5f5;
}

/* Burger button */
.burger-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    z-index: 100;
    position: relative;
}

.burger-btn span {
    display: block;
    width: 24px;
    height: 2px;
    background: white;
    border-radius: 2px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center;
}

.burger-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.burger-btn.active span:nth-child(2) {
    opacity: 0;
}

.burger-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

/* Заголовок пропадает раньше остального: между 769 и 1100px он вставал в две
   строки и вылезал за 60px высоты шапки. */
@media (max-width: 1100px) {
    .header-title {
        display: none;
    }
}

/* Mobile header */
@media (max-width: 768px) {
    .burger-btn {
        display: flex;
    }

    .header {
        height: 50px;
        padding: 0 12px;
        position: sticky;
        top: 0;
        z-index: 1000;
    }

    .user-name {
        display: none;
    }

    .theme-switch-current {
        display: none;
    }
}

/* Выпадающие меню шапки: язык и тема оформления (js/app.js, initHeaderSwitch) */
.header-switch {
    position: relative;
}

.header-switch-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    background: none;
    border: none;
    color: white;
    font: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 5px 12px;
    border-radius: 20px;
    transition: background-color 0.3s;
}

.header-switch-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.header-switch-current {
    font-weight: 600;
    letter-spacing: 0.03em;
}

/* Кнопка темы: иконка текущей темы и её название (на телефоне — только иконка). */
.theme-switch-current {
    margin-left: 4px;
}

.theme-switch-icon {
    display: inline-flex;
}

.header-switch-arrow {
    transition: transform 0.3s ease;
}

.header-switch-btn[aria-expanded="true"] .header-switch-arrow {
    transform: rotate(180deg);
}

.header-switch-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 6px 0;
    min-width: 160px;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
}

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

.header-switch-option {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    background: none;
    border: none;
    font: inherit;
    font-size: 0.9rem;
    text-align: left;
    /* Как у пунктов меню пользователя (.dropdown-item): меню белое, а
       --text-color — светлый цвет текста самой шапки. */
    color: var(--primary-color);
    padding: 8px 16px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.header-switch-option:hover {
    background-color: #f5f5f5;
}

.header-switch-option.active {
    font-weight: 600;
}

.header-switch-mark {
    display: inline-flex;
    align-items: center;
    min-width: 24px;
    font-weight: 600;
    opacity: 0.7;
}

@media (max-width: 768px) {
    .header-switch-btn {
        padding: 5px 8px;
    }

    .header-switch-arrow {
        display: none;
    }
}
