/* --- ОСНОВНІ ПАРАМЕТРИ ТА ЗМІННІ --- */
:root {
    --accent: #f97316;
    --bg-dark: #0a0a0a;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --border-color: rgba(255, 255, 255, 0.1);
    --transition: 0.3s ease;
    --radius-md: 12px;
    --radius-lg: 20px;
}

/* --- КОНТЕЙНЕР ХЕДЕРА --- */
.header {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 95%; 
    max-width: 1400px;
    z-index: 2000;
    
    /* ФОН ХЕДЕРА - суцільний темний колір */
    background-color: #0d0d12;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    
    padding: 15px 30px;
    margin-top: 15px; 
    
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    transition: all 0.3s ease;
}

.header__container {
    display: flex;
    align-items: center;
    gap: 30px; /* Акуратний відступ між усіма блоками */
}

/* --- ЛОГОТИП ТА НАЗВА --- */
.header__brand {
    display: flex;
    align-items: center;
    gap: 12px; 
    text-decoration: none;
}

.header__brand img {
    height: 48px; /* Збільшений логотип */
    width: auto;
    display: block;
}

.brand-name {
    color: #fff;
    font-family: 'Montserrat', 'Inter', system-ui, sans-serif; /* Сучасний та чистий шрифт */
    font-size: 1.35rem; /* Елегантний розмір */
    font-weight: 700;
    letter-spacing: 0.5px;
    transition: color 0.3s ease;
}

.header__brand:hover .brand-name {
    color: var(--accent); 
}

/* --- КАТАЛОГ (МЕГА-МЕНЮ) --- */
.catalog-wrapper {
    position: relative; 
    z-index: 2100;
}

.catalog-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-weight: 700;
    cursor: pointer;
    position: relative;
    z-index: 2105;
    transition: background 0.3s ease, transform 0.2s ease;
}

.catalog-btn:hover {
    background: #ea580c;
    transform: scale(1.02);
}

/* САМА ПАНЕЛЬ МЕНЮ */
.mega-menu {
    position: absolute;
    top: calc(100% + 15px);
    left: 0;
    width: 1100px; 
    height: 600px; 
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px rgba(0,0,0,0.8);
    display: none;
    z-index: 2101;
    overflow: hidden; 
}

.mega-menu.is-active {
    display: flex !important;
}

/* ЛІВА КОЛОНКА (Сайдбар) */
.mega-menu__sidebar {
    width: 270px;
    height: 100%; 
    background: rgba(255, 255, 255, 0.02);
    border-right: 1px solid var(--border-color);
    padding: 10px 0;
    overflow-y: auto; 
    flex-shrink: 0;
}

.mega-menu__list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.mega-menu__link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    transition: 0.2s;
}

.cat-link-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.cat-icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    background-color: var(--text-muted);
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    transition: 0.2s;
}

.mega-menu__item.is-active .mega-menu__link,
.mega-menu__item:hover .mega-menu__link {
    background: rgba(249, 115, 22, 0.1);
    color: var(--accent);
}

.mega-menu__item.is-active .cat-icon,
.mega-menu__item:hover .cat-icon {
    background-color: var(--accent);
}

/* ПРАВА КОЛОНКА (Контент) */
.mega-menu__content {
    flex: 1;
    height: 100%; 
    padding: 30px;
    overflow-y: auto; 
    background: transparent;
}

.mega-content-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr); 
    gap: 20px;
    align-items: start;
}

.sub-column {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sub-column-title {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 8px;
    transition: 0.2s;
}

.sub-column-title:hover {
    color: var(--accent);
}

.sub-links-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sub-link-item {
    font-size: 13.5px;
    color: var(--text-muted);
    text-decoration: none;
    transition: 0.2s;
}

.sub-link-item:hover {
    color: #fff;
    padding-left: 4px;
}

/* --- ПОШУК --- */
.header__search {
    flex: 1; /* Змушує пошук розтягнутися і заповнити ВСЮ пусту відстань */
    max-width: 100%; /* Прибрано обмеження в 500px, яке робило "дірки" */
    position: relative;
}

.search-field {
    position: relative;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0 1rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.search-field input {
    background: none;
    border: none;
    color: var(--text-main);
    padding: 0.7rem 0;
    width: 100%;
    outline: none;
}

.search-results-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    width: 100%;
    max-height: 400px;
    background: #111;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    display: none;
    z-index: 3000;
}

/* --- КНОПКИ ДІЙ --- */
.header__actions {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    position: relative;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: var(--accent);
    color: white;
    font-size: 10px;
    font-weight: 800;
    min-width: 18px;
    height: 18px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #000;
}

/* --- КРАСИВИЙ СКРОЛБАР --- */
.mega-menu__sidebar::-webkit-scrollbar,
.mega-menu__content::-webkit-scrollbar {
    width: 4px;
}

.mega-menu__sidebar::-webkit-scrollbar-thumb,
.mega-menu__content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.mega-menu__sidebar::-webkit-scrollbar-thumb:hover,
.mega-menu__content::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* --- АДАПТАЦІЯ ДЛЯ ЕКРАНІВ --- */
@media (max-width: 1200px) {
    .mega-menu {
        width: 900px;
    }
    .mega-content-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 992px) {
    /* На мобільних приховуємо текст "Каталог" */
    .catalog-btn-text {
        display: none;
    }
    
    /* Робимо кнопку каталогу квадратною */
    .catalog-btn {
        padding: 10px 12px;
    }

    /* Ховаємо текст "Smartgad" щоб дати місце пошуку */
    .brand-name {
        display: none; 
    }
    
    /* Трохи зменшуємо логотип на маленьких екранах */
    .header__brand img {
        height: 38px;
    }
    
    /* Зменшуємо внутрішні відступи самого хедера */
    .header {
        padding: 10px 15px;
    }
    
    .header__container {
        gap: 1rem;
    }
}

/* МАГІЯ ДЛЯ МОБІЛЬНИХ ТЕЛЕФОНІВ */
@media (max-width: 768px) {
    .header__container {
        flex-wrap: wrap; 
        justify-content: space-between; 
    }
    
    .header__brand {
        order: 1; 
    }
    
    .catalog-wrapper {
        /* ВАЖЛИВО: Відв'язуємо меню від розмірів маленької кнопки */
        position: static; 
        order: 2; 
    }
    
    .header__actions {
        order: 3; 
        flex: 1; 
        justify-content: flex-end; 
    }

    .header__search {
        order: 4; 
        flex: 0 0 100%; 
        max-width: 100%;
        margin-top: 5px; 
    }

    .search-results-dropdown {
        max-height: 60vh; 
        overflow-y: auto;
        overflow-x: hidden;
    }

    /* ОНОВЛЕНЕ МЕГА-МЕНЮ ДЛЯ МОБІЛЬНИХ */
    .mega-menu {
        position: absolute;
        top: calc(100% + 10px); /* Відступаємо 10px від низу всього хедера */
        left: 0;
        width: 100%; /* Тепер 100% - це ширина екрана, а не кнопочки! */
        height: calc(100vh - 160px); /* Займаємо вільне місце на екрані */
        flex-direction: column;
    }
    
    .mega-menu__sidebar {
        width: 100%;
        height: 40%; /* Верхня частина для списку головних категорій */
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .mega-menu__content {
        padding: 15px;
        height: 60%; /* Нижня частина для підкатегорій */
    }
    
    .mega-content-grid {
        /* На телефоні робимо 1 колонку, щоб текст зручно читався і не стискався */
        grid-template-columns: 1fr; 
        gap: 15px;
    }
}

/* --- АДАПТАЦІЯ ДЛЯ ЕКРАНІВ --- */
@media (max-width: 1200px) {
    .mega-menu {
        width: 900px;
    }
    .mega-content-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 992px) {
    .catalog-btn-text {
        display: none;
    }
    .catalog-btn {
        padding: 10px 12px;
    }
    .brand-name {
        display: none; 
    }
    .header__brand img {
        height: 38px;
    }
    .header {
        padding: 10px 15px;
    }
    .header__container {
        gap: 15px;
    }
}

/* МАГІЯ ДЛЯ МОБІЛЬНИХ ТЕЛЕФОНІВ */
@media (max-width: 768px) {
    .header__container {
        flex-wrap: wrap; /* Дозволяємо блокам переноситися на новий рядок */
        justify-content: space-between; /* Розкидаємо логотип і іконки по краях */
    }
    
    .header__brand {
        order: 1; /* Логотип перший */
    }
    
    .catalog-wrapper {
        order: 2; /* Кнопка каталогу друга */
    }
    
    .header__actions {
        order: 3; /* Іконки треті */
        flex: 1; 
        justify-content: flex-end; /* Притискаємо іконки кошика/профілю до правого краю */
    }

    /* ПЕРЕНОСИМО ПОШУК НА ДРУГИЙ РЯДОК */
    .header__search {
        order: 4; /* Він буде останнім (внизу) */
        flex: 0 0 100%; /* Змушуємо його зайняти 100% ширини! */
        max-width: 100%;
        margin-top: 5px; /* Невеличкий відступ зверху */
    }

    /* Дропдаун тепер теж буде на всю ширину екрана */
    .search-results-dropdown {
        max-height: 60vh; /* Щоб можна було скролити результати */
        overflow-y: auto;
        overflow-x: hidden;
    }

    /* Мега-меню */
    .mega-menu {
        width: 100%;
        height: 80vh;
        flex-direction: column;
    }
    .mega-menu__sidebar {
        width: 100%;
        height: auto;
        max-height: 40%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    .mega-menu__content {
        padding: 15px;
    }
    .mega-content-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
}

/* ЗАХИСТ ТЕКСТУ В ПОШУКУ (щоб довгі назви не ламали дизайн) */
.search-results-dropdown a > div > div {
    white-space: normal !important; /* Дозволяє тексту переноситися на новий рядок */
    word-break: break-word; /* Розриває занадто довгі слова без пробілів */
}