/* ============================================================
   IB Product Filter v5 — Light / clean theme
   ============================================================ */

:root {
    --ib-bg:        #f5f6f8;
    --ib-surface:   #ffffff;
    --ib-surface2:  #f0f2f5;
    --ib-border:    #e2e5ea;
    --ib-border2:   #d0d5dd;
    --ib-accent:    #0284c7;
    --ib-accent2:   #0369a1;
    --ib-text:      #111827;
    --ib-muted:     #6b7280;
    --ib-muted2:    #9ca3af;
    --ib-radius:    10px;
    --ib-shadow:    0 1px 4px rgba(0,0,0,0.07), 0 4px 16px rgba(0,0,0,0.05);
    --ib-shadow-hover: 0 4px 12px rgba(0,0,0,0.10), 0 16px 40px rgba(0,0,0,0.08);
}

/* ── Layout ─────────────────────────────────────────────── */

.ib-filter-wrap {
    display: flex;
    gap: 32px;
    align-items: flex-start;
    width: 100%;
    box-sizing: border-box;
}

.ib-filter-sidebar {
    width: 270px;
    min-width: 250px;
    flex-shrink: 0;
    background: var(--ib-surface);
    border: 1px solid var(--ib-border);
    border-radius: var(--ib-radius);
    box-shadow: var(--ib-shadow);
    padding: 0;
    position: sticky;
    top: 90px;
    max-height: calc(100vh - 110px);
    overflow-y: auto;
}

.ib-filter-content {
    flex: 1;
    min-width: 0;
}

/* ── Sidebar header ─────────────────────────────────────── */

.ib-filter-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--ib-border);
    position: sticky;
    top: 0;
    background: var(--ib-surface);
    z-index: 2;
}

.ib-filter-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ib-text);
    letter-spacing: 0;
}

.ib-filter-clear {
    font-size: 0.75rem;
    color: var(--ib-accent);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.ib-filter-clear:hover { color: var(--ib-accent2); }

/* ── Search panel ───────────────────────────────────────── */

.ib-panel-search {
    padding: 14px 16px;
    border-bottom: 1px solid var(--ib-border);
}

.ib-search-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.ib-keyword-input {
    width: 100%;
    box-sizing: border-box;
    background: var(--ib-surface2);
    border: 1px solid var(--ib-border2);
    border-radius: 8px;
    padding: 10px 34px 10px 14px;
    color: var(--ib-text);
    font-size: 0.875rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.ib-keyword-input::placeholder { color: var(--ib-muted2); }
.ib-keyword-input:focus {
    outline: none;
    border-color: var(--ib-accent);
    box-shadow: 0 0 0 3px rgba(2,132,199,0.10);
}

.ib-search-clear {
    position: absolute;
    right: 10px;
    background: none;
    border: none;
    color: var(--ib-muted2);
    font-size: 1rem;
    cursor: pointer;
    line-height: 1;
    padding: 2px;
}
.ib-search-clear:hover { color: var(--ib-text); }

/* ── Panels ─────────────────────────────────────────────── */

.ib-panel {
    border-bottom: 1px solid var(--ib-border);
}
.ib-panel:last-child { border-bottom: none; }

.ib-panel-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    background: none;
    border: none;
    color: var(--ib-text);
    font-size: 0.875rem;
    font-weight: 700;
    cursor: pointer;
    text-align: left;
}
.ib-panel-toggle:hover { color: var(--ib-accent); }

.ib-chevron {
    font-size: 1rem;
    color: var(--ib-muted);
    line-height: 1;
    font-weight: 400;
    font-style: normal;
    transition: none;
}
.ib-panel-toggle[aria-expanded="true"]  .ib-chevron::before { content: '—'; font-size: 0.8rem; }
.ib-panel-toggle[aria-expanded="false"] .ib-chevron::before { content: '+'; }

.ib-panel-body { padding: 0 0 8px; }
.ib-panel-toggle[aria-expanded="false"] + .ib-panel-body { display: none; }

/* ── Checkbox rows ──────────────────────────────────────── */

.ib-check-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--ib-muted);
    line-height: 1.4;
    transition: color 0.1s, background 0.1s;
}
.ib-check-label:hover {
    color: var(--ib-text);
    background: var(--ib-surface2);
}

.ib-check-label input[type="checkbox"] {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    min-width: 16px;
    border: 1.5px solid var(--ib-border2);
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    position: relative;
    transition: border-color 0.15s, background 0.15s;
    flex-shrink: 0;
    margin: 0;
}
.ib-check-label input[type="checkbox"]:checked {
    background: var(--ib-accent);
    border-color: var(--ib-accent);
}
.ib-check-label input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 5px;
    height: 9px;
    border: 2px solid #fff;
    border-top: none;
    border-left: none;
    transform: rotate(45deg);
}
.ib-check-label input[type="checkbox"]:checked ~ .ib-label-text {
    color: var(--ib-accent);
    font-weight: 600;
}

.ib-checkmark { display: none; }
.ib-label-text { flex: 1; }

.ib-count {
    font-size: 0.75rem;
    color: var(--ib-accent);
    flex-shrink: 0;
    font-weight: 600;
}

/* ── Category row: checkbox + expand toggle side by side ── */

.ib-cat-row {
    display: flex;
    align-items: center;
}
.ib-cat-row .ib-check-label {
    flex: 1;
    padding-right: 4px;
}

.ib-subcat-toggle {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    margin-right: 8px;
    border-radius: 6px;
    color: var(--ib-muted);
    transition: background 0.12s, color 0.12s;
}
.ib-subcat-toggle:hover {
    background: var(--ib-surface2);
    color: var(--ib-accent);
}

.ib-sub-arrow {
    display: block;
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.2s;
    position: relative;
    top: -2px;
}
.ib-subcat-toggle[aria-expanded="true"] .ib-sub-arrow {
    transform: rotate(-135deg);
    top: 2px;
}

.ib-subcats {
    border-left: 2px solid var(--ib-border);
    margin-left: 28px;
    margin-bottom: 4px;
}
.ib-subcat-label {
    padding-left: 14px;
    font-size: 0.84rem;
}

/* ── Price panel ────────────────────────────────────────── */

.ib-price-histogram {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 52px;
    padding: 0 20px;
    margin-bottom: 10px;
}

.ib-hist-bar {
    flex: 1;
    background: var(--ib-accent);
    opacity: 0.2;
    border-radius: 2px 2px 0 0;
    min-height: 3px;
    transition: opacity 0.15s;
}
.ib-hist-bar.active { opacity: 0.65; }

.ib-price-display { display: none; }

.ib-range-wrap {
    position: relative;
    height: 20px;
    margin: 0 20px 14px;
}

.ib-range {
    position: absolute;
    left: 0;
    width: 100%;
    pointer-events: none;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: transparent;
    top: 50%;
    transform: translateY(-50%);
}
.ib-range::-webkit-slider-thumb {
    pointer-events: all;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--ib-accent);
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.ib-range::-moz-range-thumb {
    pointer-events: all;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--ib-accent);
    cursor: pointer;
}

.ib-range-track {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 4px;
    background: var(--ib-border);
    width: 100%;
    border-radius: 2px;
    pointer-events: none;
}
.ib-range-fill {
    position: absolute;
    height: 4px;
    background: var(--ib-accent);
    border-radius: 2px;
    pointer-events: none;
    top: 50%;
    transform: translateY(-50%);
}

.ib-price-inputs {
    display: flex;
    gap: 8px;
    padding: 0 20px 6px;
}

.ib-price-select {
    flex: 1;
    background: var(--ib-surface2);
    border: 1px solid var(--ib-border2);
    border-radius: 6px;
    color: var(--ib-text);
    font-size: 0.82rem;
    padding: 8px 10px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7280'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 24px;
}
.ib-price-select:focus { outline: 1px solid var(--ib-accent); }

.ib-price-apply { display: none; }

/* ── Brand search ───────────────────────────────────────── */

.ib-brand-search {
    width: calc(100% - 40px);
    box-sizing: border-box;
    background: var(--ib-surface2);
    border: 1px solid var(--ib-border2);
    border-radius: 7px;
    padding: 9px 32px 9px 12px;
    color: var(--ib-text);
    font-size: 0.85rem;
    margin: 0 20px 10px;
    display: block;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}
.ib-brand-search::placeholder { color: var(--ib-muted2); }
.ib-brand-search:focus { outline: none; border-color: var(--ib-accent); box-shadow: 0 0 0 3px rgba(2,132,199,0.10); }

.ib-brand-list {
    max-height: 220px;
    overflow-y: auto;
}

/* ── Toolbar ─────────────────────────────────────────────── */

.ib-filter-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}

.ib-result-count {
    font-size: 0.85rem;
    color: var(--ib-muted);
}

.ib-sort-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--ib-muted);
}

.ib-sort-select {
    background: var(--ib-surface);
    border: 1px solid var(--ib-border2);
    border-radius: 7px;
    color: var(--ib-text);
    font-size: 0.85rem;
    padding: 7px 12px;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.ib-sort-select:focus { outline: 1px solid var(--ib-accent); }

/* ── Active filter tags ─────────────────────────────────── */

.ib-active-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 18px;
    min-height: 0;
}

.ib-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #e0f2fe;
    border: 1px solid #bae6fd;
    color: var(--ib-accent2);
    font-size: 0.78rem;
    font-weight: 600;
    padding: 5px 11px;
    border-radius: 20px;
    cursor: pointer;
}
.ib-tag:hover { background: #bae6fd; }
.ib-tag-x { font-size: 0.9rem; opacity: 0.7; }

/* ── Load More ──────────────────────────────────────────── */

.ib-load-more-wrap {
    text-align: center;
    padding: 32px 0 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.ib-load-more-btn {
    padding: 13px 40px;
    background: var(--ib-surface);
    border: 2px solid var(--ib-accent);
    border-radius: 8px;
    color: var(--ib-accent);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.ib-load-more-btn:hover { background: var(--ib-accent); color: #fff; box-shadow: 0 4px 14px rgba(2,132,199,0.25); }
.ib-load-more-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ib-load-more-btn.loading { pointer-events: none; opacity: 0.7; }

.ib-load-more-info {
    font-size: 0.8rem;
    color: var(--ib-muted2);
}

/* ── Homepage row ───────────────────────────────────────── */

.ib-row-heading {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--ib-text);
    margin: 0 0 20px;
}

.ib-products-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    width: 100%;
}

/* ── Product grid ───────────────────────────────────────── */

.ib-product-grid {
    display: grid;
    gap: 22px;
}

.ib-cols-2 { grid-template-columns: repeat(2, 1fr); }
.ib-cols-3 { grid-template-columns: repeat(3, 1fr); }
.ib-cols-4 { grid-template-columns: repeat(4, 1fr); }
.ib-cols-5 { grid-template-columns: repeat(5, 1fr); }
.ib-cols-6 { grid-template-columns: repeat(6, 1fr); }
.ib-product-grid:not([class*="ib-cols-"]) {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

/* ── Product card ───────────────────────────────────────── */

.ib-prod-card {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: var(--ib-surface);
    border: 1px solid var(--ib-border);
    box-shadow: var(--ib-shadow);
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: transform 0.22s cubic-bezier(.22,.68,0,1.2),
                box-shadow 0.22s ease,
                border-color 0.22s ease;
}
.ib-prod-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--ib-shadow-hover);
    border-color: var(--ib-accent);
    color: inherit;
    text-decoration: none;
}

/* Image area */
.ib-prod-img-wrap {
    position: relative;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    background: #f7f8fa;
    flex-shrink: 0;
    border-bottom: 1px solid var(--ib-border);
}

.ib-prod-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 16px;
    box-sizing: border-box;
    transition: transform 0.3s ease;
}
.ib-prod-card:hover .ib-prod-img { transform: scale(1.05); }

/* Stock badge */
.ib-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 20px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    z-index: 1;
}
.ib-badge-stock { background: #dcfce7; color: #15803d; }
.ib-badge-oos   { background: #fee2e2; color: #b91c1c; }

/* Card body */
.ib-prod-info {
    padding: 14px 16px 16px;
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 5px;
}

/* Brand label */
.ib-prod-brand {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--ib-accent);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding-left: 8px;
    border-left: 2px solid var(--ib-accent);
    line-height: 1.3;
}

/* Product name — 3 lines, normal weight like Takealot */
.ib-prod-name {
    font-size: 0.875rem;
    font-weight: 400;
    line-height: 1.5;
    margin: 0;
    color: var(--ib-text);
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.ib-prod-card:hover .ib-prod-name { color: var(--ib-accent); }

/* Price — inline R symbol aligned, normal weight */
.ib-prod-price {
    font-size: 1rem;
    font-weight: 500;
    color: var(--ib-text);
    line-height: 1.3;
    padding-top: 10px;
    border-top: 1px solid var(--ib-border);
    margin-top: auto;
    white-space: normal;
    word-break: break-word;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px;
}
/* R symbol — exact same size as price number */
.ib-prod-price .woocommerce-Price-currencySymbol {
    font-size: 1em;
    font-weight: 500;
    vertical-align: baseline;
    margin-right: 0;
    margin-right: 0;
    opacity: 1;
}
/* Sale: struck-through old price inline before new */
.ib-prod-price del {
    font-size: 0.82rem;
    font-weight: 400;
    color: var(--ib-muted2);
    text-decoration: line-through;
}
.ib-prod-price ins {
    text-decoration: none;
    font-weight: 600;
    color: var(--ib-text);
}

/* Remove old button — whole card is the link now */
.ib-prod-btn,
.ib-prod-footer { display: none; }

/* ── Pagination ─────────────────────────────────────────── */

.ib-pagination {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 30px;
}

.ib-page-btn {
    min-width: 40px;
    height: 40px;
    padding: 0 12px;
    background: var(--ib-surface);
    border: 1px solid var(--ib-border2);
    border-radius: 7px;
    color: var(--ib-text);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.15s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.ib-page-btn:hover   { background: var(--ib-surface2); border-color: var(--ib-accent); }
.ib-page-btn.active  { background: var(--ib-accent); border-color: var(--ib-accent); color: #fff; }
.ib-page-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── Loading / empty ────────────────────────────────────── */

.ib-loading, .ib-no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--ib-muted);
    font-size: 0.9rem;
}

.ib-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--ib-border);
    border-top-color: var(--ib-accent);
    border-radius: 50%;
    animation: ib-spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}
@keyframes ib-spin { to { transform: rotate(360deg); } }

/* ── Mobile ─────────────────────────────────────────────── */

.ib-mobile-toggle {
    display: none;
    width: 100%;
    padding: 13px 18px;
    background: var(--ib-surface);
    border: 1px solid var(--ib-border2);
    border-radius: var(--ib-radius);
    color: var(--ib-text);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 16px;
    text-align: left;
    box-shadow: var(--ib-shadow);
}

@media (max-width: 900px) {
    .ib-filter-wrap { flex-direction: column; }
    .ib-filter-sidebar { width: 100%; min-width: unset; position: static; max-height: none; }
    .ib-mobile-toggle { display: block; }
    .ib-filter-sidebar.ib-sidebar-hidden { display: none; }
    .ib-product-grid,
    .ib-cols-4, .ib-cols-5, .ib-cols-6 { grid-template-columns: repeat(3, 1fr) !important; gap: 16px; }
    .ib-products-row { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 600px) {
    .ib-product-grid,
    .ib-cols-3, .ib-cols-4, .ib-cols-5, .ib-cols-6 { grid-template-columns: repeat(2, 1fr) !important; gap: 12px; }
    .ib-products-row { grid-template-columns: repeat(2, 1fr); }
}

/* ── Scrollbar ───────────────────────────────────────────── */

.ib-filter-sidebar::-webkit-scrollbar,
.ib-brand-list::-webkit-scrollbar { width: 4px; }
.ib-filter-sidebar::-webkit-scrollbar-track,
.ib-brand-list::-webkit-scrollbar-track { background: var(--ib-surface2); }
.ib-filter-sidebar::-webkit-scrollbar-thumb,
.ib-brand-list::-webkit-scrollbar-thumb { background: var(--ib-border2); border-radius: 2px; }

/* ── Black Friday badge ──────────────────────────────────── */

.ib-bf-save-badge {
    display: inline-block;
    background: #dc2626;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 2px 7px;
    border-radius: 4px;
    margin-top: 4px;
    white-space: nowrap;
}

.ib-prod-price .ib-bf-save-badge {
    display: block;
    width: fit-content;
}
