/* ============================================================================
   ZAMEL - Category Menu Styles (Unified)

   Połączenie stylów z:
   - custom-menu-prroducts.css
   - category-menu-context.css

   Wersja: 2.0
   Data: 2025-01-22
   ============================================================================ */

/* ============================================================================
   1. PODSTAWOWE STYLE DRZEWA KATEGORII
   ============================================================================ */

.zamel-tree {
    font-size: 0.875rem;
    list-style: none !important;
    margin: 0 !important;
}

.zamel-tree,
.zamel-tree ul {
    list-style: none !important;
    margin: 0 !important;
    padding-inline-start: 1.5em;
}

.zamel-tree > li::before {
    content: none !important;
    border-left: none !important;
}

/* ============================================================================
   2. KONTENER KATEGORII
   ============================================================================ */

/* Główny kontener kategorii */
.zamel-category-item {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    position: relative !important;
}

/* Nagłówek kategorii (przycisk + link) */
.zamel-category-header {
    display: flex;
    align-items: center;
    padding: 0.375em 0;
    position: relative;
}

/* ============================================================================
   3. PRZYCISK ROZWIJANIA (+/-)
   ============================================================================ */

.zamel-category-toggle {
    background: #fff !important;
    border: 1px solid #e6e6e6 !important;
    width: 20px !important;
    height: 20px !important;
    padding: 0 !important;
    margin: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    font-family: monospace !important;
    font-size: 16px !important;
    font-weight: bold !important;
    line-height: 1 !important;
    border-radius: 3px !important;
    transition: all 0.2s ease !important;
    flex-shrink: 0 !important;
    color: #747474 !important;
    text-decoration: none !important;
    box-shadow: none !important;
}

.zamel-category-toggle:hover {
    background-color: #ececec !important;
    border-color: #747474 !important;
    color: #000 !important;
}

.zamel-category-toggle:active {
    background-color: #e6e6e6 !important;
}

/* Przycisk rozwinięty - czerwony */
.zamel-category-toggle[aria-expanded="true"] {
    background-color: #DE000E !important;
    border-color: #DE000E !important;
    color: #fff !important;
}

.zamel-category-toggle[aria-expanded="true"]:hover {
    background-color: #000 !important;
    border-color: #000 !important;
}

/* Ikona w przycisku */
.zamel-toggle-icon {
    display: inline-block;
    font-style: normal;
    transition: transform 0.3s ease;
}

/* Animacja obrotu ikony przy rozwijaniu */
.zamel-category-toggle[aria-expanded="true"] .zamel-toggle-icon {
    transform: rotate(180deg);
}

/* ============================================================================
   4. LINKI KATEGORII
   ============================================================================ */

/* Link kategorii - podstawowe style */
.zamel-category-link {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-decoration: none;
    color: inherit;
    margin-left: 0.5em;
    border-radius: 3px;
    transition: background-color 0.2s ease;
    min-height: 28px;
}

.zamel-category-link:hover {
    background-color: #ececec;
    text-decoration: none;
}

/* Style dla kategorii głównych (root/brand) */
/* Bazowe style dla root category (z category-menu-context.css) */
.zamel-category-root {
    font-weight: 600;
    color: #333;
    text-decoration: none;
}

.zamel-category-root:hover {
    color: #c82333;
    text-decoration: underline;
}

/* Style dla linków kategorii głównych (wyższa specyficzność) */
.zamel-category-link.zamel-category-root {
    font-weight: normal !important;
    color: #000;
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.zamel-category-link.zamel-category-root:hover {
    background-color: #f9faf6;
    border-color: #DE000E;
    color: #DE000E;
}

/* Ikona strzałki dla kategorii głównych */
.zamel-category-link.zamel-category-root::before {
    content: '▸';
    margin-right: 0.5em;
    color: #747474;
    font-size: 0.8em;
    transition: transform 0.2s ease;
}

.zamel-category-link.zamel-category-root:hover::before {
    transform: translateX(3px);
    color: #DE000E;
}

/* Style dla podkategorii (child) */
/* Bazowe style dla child category (z category-menu-context.css) */
.zamel-category-child {
    color: #666;
    text-decoration: none;
    display: block;
    padding: 4px 8px;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.zamel-category-child:hover {
    color: #c82333;
    text-decoration: none;
}

/* Style dla linków podkategorii (wyższa specyficzność) */
.zamel-category-link.zamel-category-child {
    color: #000;
    font-weight: 400;
}

.zamel-category-link.zamel-category-child:hover {
    background-color: #ececec;
    color: #DE000E;
}

/* ============================================================================
   5. AKTYWNA KATEGORIA
   ============================================================================ */

/* Aktywna kategoria - czerwone podświetlenie */
.zamel-category-link.zamel-active {
    background-color: #fce4e4;
    color: #DE000E;
    font-weight: 700;
}

.zamel-category-link.zamel-active:hover {
    background-color: #f8d7da;
}

/* Aktywna kategoria główna */
.zamel-category-link.zamel-category-root.zamel-active {
    background-color: #ececec;
    color: #DE000E;
    border-color: #DE000E;
}

.zamel-category-link.zamel-category-root.zamel-active:hover {
    background-color: #e6e6e6;
}

/* ============================================================================
   6. NAZWA I LICZNIK KATEGORII
   ============================================================================ */

/* Nazwa kategorii - flex column dla wieloliniowych nazw (root categories z brand) */
.zamel-category-name {
    flex: 1;
    padding-right: 0.5em; /* Minimalne odstęp od licznika */
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 2px;
}

/* OVERRIDE: Child categories - inline layout (tekst + licznik w jednej linii) */
.zamel-category-child .zamel-category-name {
    flex-direction: row !important; /* Child categories w poziomie */
    align-items: baseline !important;
    justify-content: space-between !important;
}

/* OVERRIDE: Root categories bez brand attributes - PROSTY SELEKTOR z klasą helper */
.zamel-category-name--inline {
    flex-direction: row !important; /* W poziomie, tak jak child */
    align-items: baseline !important;
    justify-content: space-between !important;
}

/* FALLBACK: Root categories bez brand attributes (ma .zamel-category-text lub .zamel-fw-bold BEZ licznika) */
.zamel-category-root .zamel-category-name:has(> .zamel-category-text),
.zamel-category-root .zamel-category-name:has(> .zamel-fw-bold:not(:has(.zamel-category-count))) {
    flex-direction: row !important; /* W poziomie, tak jak child */
    align-items: baseline !important;
    justify-content: space-between !important;
}

/* Tekst kategorii - flex item (dla root bez brand i dla child) */
.zamel-category-text {
    flex: 1; /* Zajmuje dostępną przestrzeń */
}

/* .zamel-fw-bold który NIE zawiera licznika - też flex: 1 */
.zamel-category-root .zamel-category-name > .zamel-fw-bold:not(:has(.zamel-category-count)) {
    flex: 1; /* Zajmuje dostępną przestrzeń */
}

/* Brand name - pierwsza linia (TYLKO gdy .zamel-fw-bold ZAWIERA licznik) */
.zamel-category-name > .zamel-fw-bold:has(.zamel-category-count) {
    font-weight: 700;
    display: flex !important; /* Flex aby licznik był w tej samej linii */
    align-items: baseline !important;
    gap: 0.5em; /* Odstęp między tekstem a licznikiem */
}

/* Licznik w brand name (bez description) - gdy .zamel-fw-bold ZAWIERA licznik */
.zamel-fw-bold:has(.zamel-category-count) .zamel-category-count {
    margin-left: auto; /* Przesuwamy licznik na prawo */
}

/* Wspólny styl bold dla brand names i root categories bez brand */
.zamel-fw-bold {
    font-weight: 700;
}

/* Brand description - druga linia pod brand name */
.zamel-brand-description {
    font-size: 0.95em !important;
    font-weight: 400 !important;
    /*color: #666 !important;*/
    line-height: 1.2;
    display: flex !important; /* Flex aby licznik był w tej samej linii */
    align-items: baseline !important;
    gap: 0.5em; /* Odstęp między tekstem a licznikiem */
}

/* Licznik produktów - zawsze jedna spacja przed licznikiem */
.zamel-category-count {
    color: #747474;
    font-size: 0.875em;
    font-weight: 400;
    white-space: nowrap;
    margin-left: 0.5em; /* Jedna spacja przed licznikiem */
}

/* Licznik w brand description - specjalne style */
.zamel-brand-description .zamel-category-count {
    margin-left: auto; /* W brand description przesuwamy na prawo */
}

/* Licznik w child categories - przesunięcie na prawo */
.zamel-category-child .zamel-category-count {
    margin-left: auto; /* W child categories przesuwamy licznik na prawo */
}

/* Licznik w root categories bez brand - przesunięcie na prawo */
.zamel-category-name--inline .zamel-category-count,
.zamel-category-root .zamel-category-name:has(> .zamel-category-text) .zamel-category-count,
.zamel-category-root .zamel-category-name:has(> .zamel-fw-bold:not(:has(.zamel-category-count))) .zamel-category-count {
    margin-left: auto; /* W root bez brand przesuwamy licznik na prawo */
}

.zamel-category-link.zamel-active .zamel-category-count {
    color: #a02b36;
}

.zamel-category-link.zamel-category-root .zamel-category-count {
    color: #747474;
}

/* ============================================================================
   7. KONTENER PODKATEGORII
   ============================================================================ */

.zamel-category-children {
    margin: 0;
    padding: 0;
    margin-left: 20px;
    padding-left: 20px;
    position: relative;
    overflow: hidden;
    transition: max-height 0.3s ease-out, opacity 0.3s ease-out;
}

.zamel-category-children:not(.zamel-hidden) {
    display: block;
    max-height: 5000px; /* Zwiększone aby pomieścić długie listy */
    opacity: 1;
}

.zamel-category-children.zamel-hidden {
    max-height: 0;
    opacity: 0;
}

/* Klasa ukrywająca */
.zamel-hidden {
    display: none !important;
}

/* ============================================================================
   8. LINIE ŁĄCZĄCE KATEGORIE
   ============================================================================ */

/* Linia pionowa łącząca podkategorie */
.zamel-category-children::before {
    content: '';
    position: absolute;
    left: 10px;
    top: 0;
    bottom: 0;
    width: 1px !important;
    background-color: red !important;
    border: none !important;
}

/* Pozioma linia dla każdej podkategorii */
.zamel-category-children > .zamel-category-item::before {
    content: '';
    position: absolute;
    left: -10px;
    top: 18px;
    width: 12px !important;
    height: 1px !important;
    background-color: red !important;
    border: none !important;
}

/* Ostatnia podkategoria - skróć linię pionową */
.zamel-category-children > .zamel-category-item:last-child::after {
    content: '';
    position: absolute;
    left: -11px;
    top: 19px;
    bottom: 0;
    width: 1px;
    background-color: #fff;
}

/* ============================================================================
   9. SCROLLABLE CONTAINER
   ============================================================================ */

/* Główny kontener kategorii z scrollowaniem */
.zamel-b:has(.zamel-categories-tree) {
    display: flex;
    flex-direction: column;
    max-height: min(800px, calc(100vh - 250px));
    overflow: hidden; /* Zapobiega "wypływaniu" rozwiniętych kategorii */
}

/* Sticky header dla kategorii */
.zamel-b:has(.zamel-categories-tree) > h3 {
    position: sticky;
    top: 0;
    background: white;
    flex-shrink: 0;
}

/* Scrollable tree container */
.zamel-b:has(.zamel-categories-tree) > .zamel-tree {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 0.5em;
    scroll-behavior: smooth;
    padding-bottom: 1em;
}

/* Thin scrollbar (Chromium/Safari) */
.zamel-b:has(.zamel-categories-tree) > .zamel-tree::-webkit-scrollbar {
    width: 2px;
}

.zamel-b:has(.zamel-categories-tree) > .zamel-tree::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.zamel-b:has(.zamel-categories-tree) > .zamel-tree::-webkit-scrollbar-thumb {
    background: #c82333;
    border-radius: 3px;
}

.zamel-b:has(.zamel-categories-tree) > .zamel-tree::-webkit-scrollbar-thumb:hover {
    background: #a01e2a;
}

/* Thin scrollbar (Firefox) */
.zamel-b:has(.zamel-categories-tree) > .zamel-tree {
    scrollbar-width: thin;
    scrollbar-color: #c82333 #f1f1f1;
}

/* ============================================================================
   10. FOCUS & ACCESSIBILITY
   ============================================================================ */

/* Focus dla dostępności */
.zamel-category-toggle:focus,
.zamel-category-link:focus {
    outline: 2px solid #DE000E;
    outline-offset: 2px;
}

/* Wyłącz domyślne style przeglądarki */
.zamel-category-toggle::-moz-focus-inner {
    border: 0;
}

/* NADPISANIE focus styles - usuń outline po kliknięciu (z category-menu-context.css) */
.zamel-categories-tree .zamel-category-link:focus {
    outline: none !important;
    border: none !important;
    box-shadow: none !important;
}

.zamel-categories-tree .zamel-category-link.zamel-active:focus {
    outline: none !important;
    border: none !important;
    box-shadow: none !important;
    border-left: 3px solid #c82333 !important; /* Zachowaj tylko lewą kreskę */
}

/* Usuń focus outline z przycisków toggle */
.zamel-categories-tree .zamel-category-toggle:focus {
    outline: none !important;
    border-color: #e6e6e6 !important; /* Zachowaj normalny border */
    box-shadow: none !important;
}

.zamel-categories-tree .zamel-category-toggle:focus-visible {
    outline: none !important;
    box-shadow: none !important;
}

/* Screen reader only */
.zamel-screen-reader-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================================================
   11. CONTEXT-AWARE STYLES (z category-menu-context.css)
   ============================================================================ */

/* Bazowy styl dla drzewa kategorii */
.zamel-categories-tree {
    transition: all 0.3s ease;
}

/* Context indicators */
.zamel-categories-tree.context-global {
    /* Główna strona produktów - standardowe zachowanie */
}

.zamel-categories-tree.context-brand {
    /* Strona brandu - bardziej otwarte menu */
}

.zamel-categories-tree.context-filtered {
    /* Tryb filtrowania - zachowaj otwarte sekcje */
}

/* Visual hierarchy based on level */
.zamel-category-item[data-level="0"] {
    border-bottom: 1px solid #eee;
    margin-bottom: 8px;
    padding-bottom: 8px;
}

.zamel-category-item[data-level="1"] {
    margin-left: 12px;
}

.zamel-category-item[data-level="2"] {
    margin-left: 24px;
}

/* Loading states */
.zamel-category-link[aria-busy="true"]::after {
    content: "...";
    color: #999;
    margin-left: 8px;
}

/* HIGH-SPECIFICITY OVERRIDES (z category-menu-context.css) */
/* Usuń szare tło hover i czerwoną obramówkę - przywróć transparent */
.zamel-categories-tree .zamel-category-link:hover {
    background-color: transparent !important;
    color: #c82333 !important;
}

.zamel-categories-tree .zamel-category-link.zamel-category-root:hover {
    background-color: transparent !important;
    color: #c82333 !important;
    border-color: transparent !important; /* Usuń czerwoną obramówkę */
}

.zamel-categories-tree .zamel-category-link.zamel-category-child:hover {
    background-color: transparent !important;
    color: #c82333 !important;
}

/* Nadpisz active styles - usuń różową obramówkę, tylko lewa kreska */
.zamel-categories-tree .zamel-category-link.zamel-active {
    background-color: #f8f9fa !important; /* Zachowaj subtelne tło */
    color: #c82333 !important;
    font-weight: 600 !important;
    border: none !important; /* Usuń obramówkę */
    padding-left: 8px !important;
    border-left: 3px solid #c82333 !important; /* Tylko lewa kreska */
}

.zamel-categories-tree .zamel-category-link.zamel-active:hover {
    background-color: #f8f9fa !important;
    color: #c82333 !important;
}

.zamel-categories-tree .zamel-category-link.zamel-active .zamel-category-name {
    color: #c82333 !important;
}

.zamel-categories-tree .zamel-category-link.zamel-active .zamel-category-count {
    color: #c82333 !important;
    font-weight: 500 !important;
}

/* Context-specific toggle styling */
.context-brand .zamel-category-toggle {
    border-color: #6c757d;
}

.context-filtered .zamel-category-toggle {
    border-color: #c82333;
}

/* Context-aware spacing */
.context-brand .zamel-category-item {
    margin-bottom: 4px;
}

.context-filtered .zamel-category-item {
    margin-bottom: 6px;
}

/* Brand page context styling */
.context-brand .zamel-category-root {
    background-color: #f8f9fa;
    padding: 8px 12px;
    border-radius: 4px;
    border-left: 4px solid #6c757d;
}

/* Filtered state highlighting */
.context-filtered .zamel-categories-tree .zamel-category-link.zamel-active {
    background-color: #f8f9fa !important;
    border-left-color: #c82333 !important;
}

.context-filtered .zamel-categories-tree .zamel-category-link.zamel-active .zamel-category-name {
    color: #c82333 !important;
}

/* ============================================================================
   12. SPECIAL STATES
   ============================================================================ */

/* Wyrównanie w kontenerze */
.zamel-b h3 + .zamel-tree {
    margin-top: 0;
}

/* Wyrównanie pierwszego i ostatniego poziomu */
.zamel-tree > .zamel-category-item:first-child {
    margin-top: 0;
}

.zamel-tree > .zamel-category-item:last-child {
    margin-bottom: 0;
}

/* Subtelna linia separująca kategorie główne */
.zamel-tree > .zamel-category-item + .zamel-category-item {
    margin-top: 0.5em;
    padding-top: 0.5em;
}

/* Styl dla pustych kategorii */
.zamel-category-item.zamel-empty > .zamel-category-header .zamel-category-link {
    opacity: 0.6;
}

/* Kategorie bez dzieci */
.zamel-category-item[data-no-children] > .zamel-category-header {
    padding-left: 20px;
}

/* Hover effect dla całej linii kategorii */
.zamel-category-item:hover > .zamel-category-header .zamel-category-toggle {
    border-color: #747474;
}

/* Dodatkowe wyróżnienie dla kategorii z produktami */
.zamel-category-item[data-has-products="true"] > .zamel-category-header .zamel-category-link {
    position: relative;
}

.zamel-category-item[data-has-products="true"] > .zamel-category-header .zamel-category-link::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 1px;
    background-color: transparent;
    transition: background-color 0.2s ease;
}

.zamel-category-item[data-has-products="true"] > .zamel-category-header .zamel-category-link:hover::after {
    background-color: #DE000E;
}

/* ============================================================================
   13. RESPONSIVE - MEDIA QUERIES
   ============================================================================ */

/* Bardzo duże ekrany (4K, iMac 27") - 1920px+ */
@media (min-width: 1920px) {
    .zamel-b:has(.zamel-categories-tree) {
        max-height: min(1000px, calc(100vh - 280px));
    }
}

/* Duże monitory - 1440px-1919px */
@media (min-width: 1440px) and (max-width: 1919px) {
    .zamel-b:has(.zamel-categories-tree) {
        max-height: min(940px, calc(100vh - 220px));
    }
}

/* Standardowe desktopy - 1024px-1439px */
@media (min-width: 1024px) and (max-width: 1439px) {
    .zamel-b:has(.zamel-categories-tree) {
        max-height: min(700px, calc(100vh - 240px));
    }
}

/* Tablety - 768px-1023px */
@media (min-width: 768px) and (max-width: 1023px) {
    .zamel-b:has(.zamel-categories-tree) {
        max-height: min(600px, calc(100vh - 220px));
    }
}

/* Mobile - <768px */
@media (max-width: 767px) {
    .zamel-b:has(.zamel-categories-tree) {
        max-height: calc(100vh - 180px);
    }
}

/* Mobile responsive adjustments */
@media (max-width: 48em) {
    .zamel-category-link {
        padding: 0.5em 0.75em;
        font-size: 0.95em;
    }

    .zamel-category-children {
        margin-left: 15px;
        padding-left: 15px;
    }

    .zamel-category-children::before {
        left: 7px;
    }

    .zamel-category-children > .zamel-category-item::before {
        left: -8px;
        width: 8px;
    }

    .zamel-category-toggle {
        width: 24px;
        height: 24px;
        min-width: 24px;
        font-size: 18px;
    }

    .zamel-category-item[data-level="1"] {
        margin-left: 8px;
    }

    .zamel-category-item[data-level="2"] {
        margin-left: 16px;
    }
}
