/* ==========================================================================
   Search and Grid — Frontend Styles
   Clean, modern design with smooth interactions
   ========================================================================== */

:root {
    --sag-primary:       #1a56db;
    --sag-primary-dark:  #1143b7;
    --sag-primary-light: #ebf0fe;
    --sag-accent:        #f56e28;
    --sag-text:          #1f2937;
    --sag-text-muted:    #6b7280;
    --sag-border:        #e5e7eb;
    --sag-bg:            #f9fafb;
    --sag-white:         #ffffff;
    --sag-radius:        10px;
    --sag-radius-sm:     6px;
    --sag-shadow:        0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
    --sag-transition:    .2s cubic-bezier(.4,0,.2,1);
    --sag-font:          -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

/* ==========================================================================
   SEARCH BAR
   ========================================================================== */
.sag-search-bar-wrapper {
    font-family: var(--sag-font);
}

.sag-search-bar {
    background: var(--sag-white);
    border: 1px solid var(--sag-border);
    border-radius: var(--sag-radius);
    box-shadow: var(--sag-shadow);
    padding: 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
}

/* --- Form fields --- */
.sag-form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1 1 200px;
    min-width: 0;
}

.sag-form-field label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--sag-text-muted);
}

.sag-form-field select,
.sag-form-field input[type="text"],
.sag-form-field input[type="search"],
.sag-form-field input[type="number"] {
    height: 42px;
    padding: 0 14px;
    border: 1.5px solid var(--sag-border);
    border-radius: var(--sag-radius-sm);
    font-family: var(--sag-font);
    font-size: 14px;
    color: var(--sag-text);
    background: var(--sag-white);
    width: 100%;
    box-sizing: border-box;
    transition: border-color var(--sag-transition), box-shadow var(--sag-transition);
    appearance: none;
    -webkit-appearance: none;
}

.sag-form-field select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 34px;
}

.sag-form-field select:focus,
.sag-form-field input:focus {
    outline: none;
    border-color: var(--sag-primary);
    box-shadow: 0 0 0 3px rgba(26,86,219,.15);
}

/* --- Range group --- */
.sag-range-group {
    display: flex;
    gap: 8px;
    align-items: center;
}
.sag-range-group input { flex: 1; }
.sag-range-group::before {
    content: '';
    width: 16px;
    height: 1.5px;
    background: var(--sag-border);
    flex-shrink: 0;
    order: 1;
    display: none;
}
.sag-range-group input:first-child { order: 0; }
.sag-range-group input:last-child  { order: 2; }

/* --- Checkbox group --- */
.sag-checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px 0;
}
.sag-checkbox-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--sag-text);
    cursor: pointer;
    padding: 5px 12px;
    border: 1.5px solid var(--sag-border);
    border-radius: 20px;
    background: var(--sag-white);
    transition: border-color var(--sag-transition), background var(--sag-transition);
}
.sag-checkbox-group label:hover {
    border-color: var(--sag-primary);
    background: var(--sag-primary-light);
}
.sag-checkbox-group input[type="checkbox"] {
    display: none;
}
.sag-checkbox-group input[type="checkbox"]:checked + span,
.sag-checkbox-group label:has(input:checked) {
    border-color: var(--sag-primary);
    background: var(--sag-primary-light);
    color: var(--sag-primary);
    font-weight: 600;
}

/* --- Action buttons --- */
.sag-form-actions {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    align-items: center;
}

.sag-form-actions button[type="submit"] {
    height: 42px;
    padding: 0 24px;
    border: none;
    border-radius: var(--sag-radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.sag-form-actions button[type="reset"] {
    height: 42px;
    padding: 0 16px;
    border-radius: var(--sag-radius-sm);
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}

/* ==========================================================================
   AKTYWNE FILTRY (tagi pod formularzem)
   ========================================================================== */
.sag-active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 12px;
    min-height: 0;
    transition: min-height var(--sag-transition);
}
.sag-active-filters:empty { display: none; }
.sag-active-filters-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--sag-text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.sag-filter-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--sag-primary-light);
    color: var(--sag-primary);
    border: 1px solid rgba(26,86,219,.2);
    border-radius: 20px;
    padding: 4px 12px 4px 12px;
    font-size: 13px;
    font-weight: 500;
    animation: sag-tag-in .2s ease;
}
.sag-filter-tag button {
    background: none;
    border: none;
    color: currentColor;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    font-size: 16px;
    opacity: .6;
    transition: opacity var(--sag-transition);
    margin-left: 2px;
}
.sag-filter-tag button:hover { opacity: 1; }
@keyframes sag-tag-in {
    from { opacity: 0; transform: scale(.9); }
    to   { opacity: 1; transform: scale(1); }
}

/* ==========================================================================
   GRID WRAPPER
   ========================================================================== */
.sag-grid-wrapper {
    font-family: var(--sag-font);
}

/* --- Toolbar (licznik + przełącznik widoku) --- */
.sag-grid-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    min-height: 36px;
    flex-wrap: wrap;
    gap: 10px;
}

.sag-results-count {
    font-size: 13px;
    color: var(--sag-text-muted);
}
.sag-results-count strong {
    color: var(--sag-text);
    font-weight: 700;
}

/* --- Przełącznik widoku (grid/lista) ---
   Pełna izolacja od styli motywu — all: unset jako reset,
   potem własne style które zawsze wygrają bez !important */
.sag-view-toggle {
    all: unset;
    display: flex;
    gap: 2px;
    background: #f0f0f0;
    border-radius: 8px;
    padding: 3px;
    box-sizing: border-box;
}

.sag-view-toggle .sag-view-btn {
    all: unset;
    box-sizing: border-box;
    width: 34px;
    height: 34px;
    border-radius: 6px;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease, color .15s ease, box-shadow .15s ease;
    flex-shrink: 0;
    line-height: 1;
    user-select: none;
    -webkit-user-select: none;
}

.sag-view-toggle .sag-view-btn:hover {
    color: #374151;
    background: rgba(255,255,255,.6);
}

.sag-view-toggle .sag-view-btn.active {
    background: #ffffff;
    color: #111827;
    box-shadow: 0 1px 3px rgba(0,0,0,.14), 0 1px 2px rgba(0,0,0,.1);
}

.sag-view-toggle .sag-view-btn:focus-visible {
    outline: 2px solid #6b7280;
    outline-offset: 1px;
}

.sag-view-toggle .sag-view-btn svg {
    width: 16px;
    height: 16px;
    display: block;
    flex-shrink: 0;
    pointer-events: none;
}

/* --- Loading overlay --- */
.sag-grid-wrapper.sag-loading .sag-grid-results {
    opacity: .4;
    pointer-events: none;
    transition: opacity .3s ease;
}

/* --- Results grid --- */
.sag-grid-results {
    display: grid;
    gap: 20px;
    transition: opacity .3s ease;
}

.sag-grid--1 { grid-template-columns: 1fr; }
.sag-grid--2 { grid-template-columns: repeat(2, 1fr); }
.sag-grid--3 { grid-template-columns: repeat(3, 1fr); }
.sag-grid--4 { grid-template-columns: repeat(4, 1fr); }
.sag-grid--5 { grid-template-columns: repeat(5, 1fr); }
.sag-grid--6 { grid-template-columns: repeat(6, 1fr); }

@media (max-width: 1024px) {
    .sag-grid--4, .sag-grid--5, .sag-grid--6 { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 768px) {
    .sag-grid--3, .sag-grid--4, .sag-grid--5, .sag-grid--6 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
    .sag-grid--2, .sag-grid--3, .sag-grid--4, .sag-grid--5, .sag-grid--6 { grid-template-columns: 1fr; }
}

/* --- List view --- */
.sag-grid-results.sag-view-list {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
}

.sag-grid-results.sag-view-list .sag-item {
    display: grid;
    grid-template-columns: 200px 1fr auto;
    align-items: center;
    gap: 0;
    min-height: 120px;
    overflow: hidden;
}

/* Obrazek w widoku listy */
.sag-grid-results.sag-view-list .sag-item > a:first-child,
.sag-grid-results.sag-view-list .sag-item > a:has(img):first-of-type {
    width: 200px;
    height: 130px;
    flex-shrink: 0;
    overflow: hidden;
    display: block;
}

.sag-grid-results.sag-view-list .sag-item img {
    width: 200px !important;
    height: 130px !important;
    object-fit: cover !important;
    display: block;
    border-radius: 0 !important;
    transition: transform .4s ease;
}

.sag-grid-results.sag-view-list .sag-item:hover img {
    transform: scale(1.05);
}

/* Tytuł i treść w środku */
.sag-grid-results.sag-view-list .sag-item h3 {
    margin: 0;
    padding: 0 20px;
    font-size: 16px;
}

/* Przycisk po prawej — layout only, styl z motywu */

/* Fallback dla bardziej złożonych szablonów — wszystko po obrazku idzie w flex */
.sag-grid-results.sag-view-list .sag-item {
    display: flex;
    align-items: center;
}

.sag-grid-results.sag-view-list .sag-item > *:not(a:first-child):not(a:has(img)) {
    flex: 1;
    min-width: 0;
}

/* --- Default item card --- */
.sag-item {
    background: var(--sag-white);
    border: 1px solid var(--sag-border);
    border-radius: var(--sag-radius);
    overflow: hidden;
    transition: transform var(--sag-transition), box-shadow var(--sag-transition);
}
.sag-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0,0,0,.1);
}
.sag-item img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
    transition: transform .4s ease;
}
.sag-item:hover img { transform: scale(1.03); }
.sag-item h3 { margin: 16px 16px 8px; font-size: 16px; }
.sag-item h3 a { color: var(--sag-text); text-decoration: none; }
.sag-item h3 a:hover { color: var(--sag-primary); }

/* Przycisk w karcie — dziedziczy style z motywu WordPress.
   Dodajemy tylko margin i display żeby nie psuć layoutu.
   NIE nadpisujemy koloru, tła ani fontu — to należy do motywu. */
.sag-item .button {
    display: inline-block;
    margin: 0 16px 16px;
}

/* List view button — bez własnych stylów, tylko layout */
.sag-grid-results.sag-view-list .sag-item .button {
    margin: 0 16px 0 0;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ==========================================================================
   MOBILE — ukrywanie widoku listy
   ========================================================================== */

/* Gdy grid ma klasę sag-hide-list-mobile, ukryj przycisk listy na małych ekranach */
@media (max-width: 640px) {
    .sag-hide-list-mobile .sag-view-btn[data-view="list"] {
        display: none;
    }
    /* Upewnij się że siatka nie jest w trybie listy na mobile */
    .sag-hide-list-mobile .sag-grid-results.sag-view-list {
        grid-template-columns: 1fr !important;
    }
    .sag-hide-list-mobile .sag-grid-results.sag-view-list .sag-item {
        display: block !important;
        flex-direction: unset !important;
    }
    .sag-hide-list-mobile .sag-grid-results.sag-view-list .sag-item img {
        width: 100% !important;
        height: 200px !important;
        border-radius: 0 !important;
    }
}

/* ==========================================================================
   SKELETON LOADER
   ========================================================================== */
.sag-skeleton-grid {
    display: grid;
    gap: 20px;
}
.sag-skeleton-item {
    background: var(--sag-white);
    border: 1px solid var(--sag-border);
    border-radius: var(--sag-radius);
    overflow: hidden;
}
.sag-skeleton-img {
    width: 100%;
    height: 200px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: sag-shimmer 1.5s infinite;
}
.sag-skeleton-body { padding: 16px; }
.sag-skeleton-line {
    height: 14px;
    border-radius: 4px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: sag-shimmer 1.5s infinite;
    margin-bottom: 10px;
}
.sag-skeleton-line.short { width: 60%; }
.sag-skeleton-line.btn { width: 40%; height: 34px; border-radius: 6px; margin-top: 8px; }
@keyframes sag-shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position:  200% 0; }
}

/* ==========================================================================
   BRAK WYNIKÓW
   ========================================================================== */
.sag-no-results {
    text-align: center;
    padding: 60px 20px;
    color: var(--sag-text-muted);
}
.sag-no-results-icon {
    font-size: 48px;
    margin-bottom: 16px;
    display: block;
    opacity: .4;
}
.sag-no-results h3 { color: var(--sag-text); font-size: 18px; margin-bottom: 8px; }
.sag-no-results p { font-size: 14px; }

/* ==========================================================================
   PAGINACJA — dziedziczy kolory z motywu WordPress
   ========================================================================== */
.sag-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-top: 32px;
    flex-wrap: wrap;
}

/* Layout i rozmiar — bez kolorów, motywy je nadpisują */
.sag-pagination .page-numbers {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    padding: 0 10px;
    border-radius: var(--sag-radius-sm);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    transition: opacity var(--sag-transition);
}

/* Strona "dots" (...) — bez ramki */
.sag-pagination .page-numbers.dots {
    background: transparent !important;
    border: none !important;
    cursor: default;
    pointer-events: none;
}

/* ==========================================================================
   GALERIA (zachowane + ulepszone)
   ========================================================================== */
.asari-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 5px;
    margin-bottom: 1em;
    border-radius: var(--sag-radius-sm);
    overflow: hidden;
}
.asari-gallery a {
    display: block;
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
}
.asari-gallery img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transition: transform .3s ease, opacity .3s ease;
}
.asari-gallery a:hover img { transform: scale(1.1); opacity: .9; }

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 5px;
}
.gallery-item { width: 100%; margin: 0; }
.gallery-icon a {
    display: block;
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border-radius: var(--sag-radius-sm);
}
.gallery-icon img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transition: transform .3s ease;
}
.gallery-icon a:hover img { transform: scale(1.1); }
.gallery-caption { display: none; }

/* ==========================================================================
   SZYBKI FILTR (Quick Filter) — przyciski / select nad siatką
   ========================================================================== */

.sag-quick-filter {
    margin-bottom: 20px;
}

/* Przyciski */
.sag-qf-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.sag-qf-btn {
    all: unset;
    display: inline-flex;
    align-items: center;
    padding: 8px 18px;
    border: 1.5px solid #e3e8ee;
    border-radius: 100px;
    font-size: 14px;
    font-weight: 500;
    color: #425466;
    background: #fff;
    cursor: pointer;
    transition: all .15s ease;
    white-space: nowrap;
    line-height: 1.4;
}

.sag-qf-btn:hover {
    border-color: currentColor;
    color: #1a1f36;
}

.sag-qf-btn.active {
    background: #1a1f36;
    border-color: #1a1f36;
    color: #fff;
}

/* Select */
.sag-qf-select-wrap {
    display: none; /* domyślnie ukryty */
}

.sag-qf-select {
    width: 100%;
    max-width: 320px;
}

/* Tryb AUTO — przyciski na desktop, select na mobile */
.sag-quick-filter--auto .sag-qf-buttons { display: flex; }
.sag-quick-filter--auto .sag-qf-select-wrap { display: none; }

@media (max-width: 640px) {
    .sag-quick-filter--auto .sag-qf-buttons { display: none; }
    .sag-quick-filter--auto .sag-qf-select-wrap { display: block; }
}

/* Tryb ZAWSZE SELECT */
.sag-quick-filter--select .sag-qf-buttons { display: none; }
.sag-quick-filter--select .sag-qf-select-wrap { display: block; }

/* Tryb ZAWSZE PRZYCISKI */
.sag-quick-filter--buttons .sag-qf-buttons { display: flex; }
.sag-quick-filter--buttons .sag-qf-select-wrap { display: none; }
