/* ==========================================================================
   MAIN.CSS - Główne style sklepu (Siatka produktów, Sidebar, Kafelki)
   ========================================================================== */

/* =========================================
   1. USTAWIENIA GLOBALNE
   ========================================= */

html {
    scroll-behavior: smooth;
}

body {
    color: var(--textMain);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.content-area {
    max-width: 1200px;
    margin: 10px auto;
}

/* Główny kontener sklepu (Grid: Sidebar + Produkty) */
.shop-container {
    max-width: 1300px;
    margin: 40px auto;
    padding: 0 20px;
    display: grid;
    grid-template-columns: 260px 1fr; 
    gap: 40px;
    align-items: start;
}


/* =========================================
   2. SIDEBAR (LEWA KOLUMNA)
   ========================================= */

.shop-sidebar {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
    position: -webkit-sticky; 
    position: sticky;
    top: 160px; 
    align-self: start; 
    height: fit-content;
    margin-top: 70px;
    z-index: 10;
}

.sidebar-widget, 
.sticky-widget {
    position: static !important;
    top: auto !important;
}

.sidebar-widget {
    margin-bottom: 30px;
}

.sidebar-widget h4 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--textLight);
    font-weight: 700;
    margin: 0 0 14px;
    border-bottom: none;
    padding-bottom: 0;
}

.sidebar-widget h4 svg {
    width: 15px;
    height: 15px;
    color: var(--leadThemeDark);
    flex-shrink: 0;
}

/* Nawigacja w sidebarze (np. Kategorie) */
.sidebar-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav li {
    margin-bottom: 4px;
}

.sidebar-nav a {
    text-decoration: none;
    color: var(--textMain);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: 7px;
    transition: background 0.2s, color 0.2s;
    padding: 9px 10px;
}

.sidebar-nav a:hover {
    background: rgba(78, 210, 250, 0.08);
}

.sidebar-nav a.active {
    background: rgba(78, 210, 250, 0.1);
    color: var(--leadThemeDark);
    box-shadow: inset 3px 0 0 var(--leadTheme);
}

.sidebar-nav .count {
    font-size: 0.78rem;
    font-weight: 700;
    color: #fff;
    background: #cfd4d8;
    padding: 1px 8px;
    border-radius: 10px;
    transition: background 0.2s;
}

.sidebar-nav a.active .count {
    background: var(--leadTheme);
}

/* Wyszukiwarka w sidebarze */
.woocommerce-product-search .search-box {
    display: flex;
    align-items: center;
    border: 1px solid var(--borderColor, #ddd);
    border-radius: 8px;
    padding: 2px;
    background: #fcfcfc;
    transition: border-color 0.2s;
    box-sizing: border-box;
    width: 100%;
}

.woocommerce-product-search .search-box:focus-within {
    border-color: var(--leadTheme);
}

.woocommerce-product-search input {
    flex-grow: 1;
    width: 100%;
    border: none;
    background: none;
    padding: 9px 10px;
    font-size: 0.88rem;
    outline: none;
}

.woocommerce-product-search button {
    background: linear-gradient(135deg, var(--leadTheme) 0%, var(--leadThemeDark) 100%);
    border: none;
    color: #fff;
    width: 34px;
    height: 34px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.woocommerce-product-search button svg {
    width: 15px;
    height: 15px;
}

/* Przycisk koszyka w sidebarze - gradientowe CTA, podłączone do AJAX fragments */
.sidebar-cart-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    /* border-box, by padding nie wypychał przycisku poza sidebar (motyw nie ma
       globalnego box-sizing: border-box, domyślnie content-box). */
    box-sizing: border-box;
    border: none;
    background: linear-gradient(135deg, var(--leadTheme) 0%, var(--leadThemeDark) 100%);
    color: #fff !important;
    padding: 13px;
    font-size: 0.92rem;
    border-radius: 8px;
    font-weight: 800;
    text-decoration: none !important;
    text-align: center;
    box-shadow: 0 8px 18px rgba(78, 210, 250, 0.35);
    transition: transform 0.2s, box-shadow 0.2s;
}

.sidebar-cart-cta svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.sidebar-cart-cta:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 24px rgba(78, 210, 250, 0.45);
}


/* =========================================
   3. ZAWARTOŚĆ GŁÓWNA I SIATKA PRODUKTÓW
   ========================================= */

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    margin-top: 10px;
    /* Zapas przy kotwicach, by nagłówek sekcji nie chował się pod przyklejonym
       headerem (80px) po kliknięciu w kategorię. */
    scroll-margin-top: 100px;
}

.category-header h2 {
    font-size: 1.8em;
    margin: 0;
    color: var(--textMain);
}

.category-header .see-all {
    text-decoration: none;
    color: var(--leadThemeDark);
    font-weight: 600;
    font-size: 0.9em;
}

.section-divider {
    border: 0;
    height: 1px;
    background: #e0e0e0;
    margin: 40px 0;
}

/* Automatycznie dopasowujący się Grid (min. 240px) */
.produkty-grid {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 25px;
}


/* =========================================
   4. KAFELEK PRODUKTU
   ========================================= */

.n-kafelek {
    display: flex; 
}

.kafelek-wrapper {
    background: var(--cardBg);
    border-radius: 8px;
    overflow: hidden; 
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    width: 100%;
    position: relative;
    border: 1px solid transparent;
}

.kafelek-wrapper:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
    border-color: var(--leadThemeDim);
}

/* Obrazek i nakładki */
.kafelek-img-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 5;
    overflow: hidden;
    background: #f4f4f4;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kafelek-img-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.kafelek-wrapper:hover .kafelek-img-container img {
    transform: scale(1.05);
}

/* Plakietka rabatu (-X%) - wspólna baza dla strony produktu i kafelków */
.price-badge {
    background: var(--assistTheme);
    color: #fff;
    font-size: 0.75em;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 5px;
}

.kafelek-img-container .price-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 2;
}

/* Tekst na obrazku przy najechaniu */
.kafelek-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: 0.3s;
}

.kafelek-wrapper:hover .kafelek-overlay {
    opacity: 1;
}

.overlay-text {
    background: rgba(255, 255, 255, 0.9);
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: bold;
    color: #333;
    transform: translateY(10px);
    transition: 0.3s;
}

.kafelek-wrapper:hover .overlay-text {
    transform: translateY(0);
}

/* Treść kafelka (Tytuł i Kategorie) */
.kafelek-content {
    padding: 15px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.kafelek-cats {
    margin-bottom: 8px !important;
    line-height: 1.2 !important;
}

.kafelek-cats .posted_in {
    display: inline-block;
    font-size: 0.75rem;          
    text-transform: uppercase;   
    letter-spacing: 0.5px;       
    color: #999;                 
    font-weight: 600;
}

.kafelek-cats .posted_in a {
    color: #999;
    text-decoration: none;
    transition: color 0.2s ease-in-out;
}

.kafelek-cats .posted_in a:hover {
    color: var(--leadTheme);     
}

.kafelek-title-link {
    text-decoration: none;
    color: var(--textMain);
}

.kafelek-title {
    font-size: 1.1em;
    margin: 0 0 10px 0;
    line-height: 1.3;
    font-weight: 600;
}

/* Stopka kafelka (Cena i Przycisk) */
.kafelek-footer {
    margin-top: auto; 
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #eee;
    padding-top: 10px;
}

/* Bazowy styl ceny - obejmuje też przypadek bez promocji (sam tekst, bez <ins>) */
.kafelek-price {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    font-weight: 800;
    color: var(--textMain);
    font-size: 1.25em;
}

.kafelek-price ins {
    text-decoration: none !important;
}

.kafelek-price del {
    opacity: 0.6;
    font-weight: 400 !important;
    font-size: 0.6em !important;
    order: -1; /* stara cena nad nową, niezależnie od kolejności w HTML */
}

.kafelek-add-cart {
    flex-shrink: 0;
}

/* Przycisk dodawania do koszyka w pętli - okrągła ikona */
.kafelek-add-cart .button {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0 !important;
    border-radius: 50% !important;
    background: linear-gradient(135deg, var(--leadTheme) 0%, var(--leadThemeDark) 100%) !important;
    color: transparent !important; /* chowamy tekst, zostaje tylko ikona z ::before */
    font-size: 0 !important;
    text-decoration: none !important;
    transition: transform 0.25s, box-shadow 0.25s !important;
    position: relative;
}

.kafelek-add-cart .button::before {
    content: "";
    width: 17px;
    height: 17px;
    background-repeat: no-repeat;
    background-size: contain;
    /* Ikona koszyka (produkty proste, dodawane przez AJAX) */
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%23fff%22%20stroke-width%3D%222.4%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Ccircle%20cx%3D%229%22%20cy%3D%2221%22%20r%3D%221%22%2F%3E%3Ccircle%20cx%3D%2220%22%20cy%3D%2221%22%20r%3D%221%22%2F%3E%3Cpath%20d%3D%22M1%201h4l2.68%2013.39a2%202%200%200%200%202%201.61h9.72a2%202%200%200%200%202-1.61L23%206H6%22%2F%3E%3C%2Fsvg%3E");
}

/* Produkty wariantowe/grupowe: link "Wybierz opcje" (bez AJAX) - ikona strzałki */
.kafelek-add-cart .button.product_type_variable::before,
.kafelek-add-cart .button.product_type_grouped::before,
.kafelek-add-cart .button.product_type_external::before {
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%23fff%22%20stroke-width%3D%222.4%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M9%2018l6-6-6-6%22%2F%3E%3C%2Fsvg%3E");
}

.kafelek-add-cart .button:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 14px rgba(78, 210, 250, 0.4);
}

/* Ukrycie domyślnego linku Woo "Zobacz koszyk" po dodaniu produktu */
a.added_to_cart.wc-forward {
    display: none !important;
}

/* Efekt ładowania AJAX przycisku */
.kafelek-add-cart .button.loading {
    opacity: 0.7 !important;
    pointer-events: none !important;
}

/* Stan Sukcesu (dodano do koszyka) */
.kafelek-add-cart .button.added {
    background: #46b450 !important;
}

.kafelek-add-cart .button.added::before {
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%23fff%22%20stroke-width%3D%222.8%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M20%206L9%2017l-5-5%22%2F%3E%3C%2Fsvg%3E");
}


/* =========================================
   5. RESPONSYWNOŚĆ (MOBILE)
   ========================================= */

@media (max-width: 900px) {
    /* Przejście z 2 kolumn na 1 na telefonach i małych tabletach.
       margin-top: 0 - panel przykleja się od razu pod headerem, bez luki na górze. */
    .shop-container {
        grid-template-columns: 1fr;
        margin-top: 0;
    }

    /* Panel boczny jako kompaktowy, przyklejony pasek-header na górze listy.
       Przykleja się tuż pod głównym headerem (sticky, 80px wysokości).
       transition - dla efektu Headroom (chowanie/pokazywanie przy scrollu). */
    .shop-sidebar {
        position: sticky !important;
        top: 80px;
        z-index: 50;
        margin: 0 0 20px !important;
        padding: 12px 14px 10px !important;
        border-radius: 0 0 14px 14px;
        height: auto !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
        transition: transform 0.3s ease;
        will-change: transform;
    }

    /* Stan ukryty (scroll w dół) - panel chowa się za headerem (z zapasem na cień) */
    .shop-sidebar.hsb-hidden {
        transform: translateY(calc(-100% - 16px));
    }

    /* Wewnątrz: bez nagłówków widgetów ("SZUKAJ"/"KATEGORIE") i bez marginesów */
    .shop-sidebar .sidebar-widget {
        margin-bottom: 0;
    }

    .shop-sidebar .sidebar-widget h4 {
        display: none;
    }

    .shop-sidebar .search-widget {
        margin-bottom: 12px;
    }

    /* Kategorie jako poziomo przewijane chipy */
    .shop-sidebar .sidebar-nav .cat-list {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 2px;
        scrollbar-width: none;
    }

    .shop-sidebar .sidebar-nav .cat-list::-webkit-scrollbar {
        display: none;
    }

    .shop-sidebar .sidebar-nav .cat-list li {
        margin-bottom: 0;
        flex-shrink: 0;
    }

    .shop-sidebar .sidebar-nav .cat-list a {
        gap: 6px;
        border: 1px solid var(--borderColor);
        background: #fff;
        border-radius: 18px;
        padding: 7px 14px;
        font-size: 0.83rem;
        white-space: nowrap;
        box-shadow: none;
    }

    .shop-sidebar .sidebar-nav .cat-list a.active {
        background: linear-gradient(135deg, var(--leadTheme) 0%, var(--leadThemeDark) 100%);
        color: #fff;
        box-shadow: none;
    }

    .shop-sidebar .sidebar-nav .cat-list a.active .count {
        background: rgba(255, 255, 255, 0.3);
    }

    /* Przycisk koszyka zbędny - koszyk jest już w głównym headerze */
    .shop-sidebar .sidebar-cart-cta {
        display: none;
    }

    /* Większy zapas kotwicy: header (80px) + przyklejony pasek kategorii (~110px) */
    .category-header {
        scroll-margin-top: 200px;
    }

    .sticky-widget {
        position: static;
    }

    /* Wymuszamy 2 kafelki w rzędzie na urządzeniach 900px-500px */
    .produkty-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
}

@media (max-width: 500px) {
    /* Na bardzo małych ekranach 1 duży kafelek w rzędzie */
    .produkty-grid {
        grid-template-columns: 1fr;
    }
    
    .kafelek-img-container {
        aspect-ratio: 4 / 3; /* Zmiana proporcji na poziome, by nie zajmowały całego ekranu */
    }
}