/* ============================================================
   LUIBERA — Filtre & Sırala Offcanvas (v3, FİNAL)
   Swarovski / Pandora tarzı: ferah, hizalı, lüks-minimal
   Yapı: kategori.php + urunler.php + includes/product-filters.php
   ============================================================
   HTML hiyerarşisi (product-filters.php çıktısı):
   .lui-filter-canvas
     ├─ .lui-filter-header
     ├─ .lui-filter-body
     │   └─ form#filterForm.lui-filter-form
     │       └─ .lui-fg [.is-collapsed] [.lui-fg--toggle]
     │           ├─ .lui-fg-head (button) → .lui-fg-title + .lui-fg-chev
     │           ├─ .lui-fg-toggle-row (label, sadece toggle için)
     │           └─ .lui-fg-body
     │               ├─ .lui-input.lui-select
     │               ├─ .lui-range → .lui-range-field
     │               └─ .lui-check-list → li → .lui-check
     └─ .lui-filter-footer → .lui-filter-reset-btn + .lui-filter-apply-btn
   ============================================================ */

/* ============================================================
   0) DEĞİŞKENLER
   ============================================================ */
:root {
    --lui-canvas-width: 460px;
    --lui-sort-canvas-width: 420px;

    --lui-bg: #ffffff;
    --lui-bg-soft: #faf7f5;
    --lui-text: #1a1a1a;
    --lui-text-soft: #5d5d5d;
    --lui-text-muted: #9a9a9a;
    --lui-border: #ececec;
    --lui-border-mid: #d8d8d8;
    --lui-border-strong: #1a1a1a;
    --lui-accent: #301934;
    --lui-accent-soft: #faf6f8;
    --lui-track-off: #d8d8d8;

    --lui-pad-x: 32px;
    --lui-pad-y: 22px;
    --lui-header-pad-y: 24px;
    --lui-footer-pad-y: 18px;
    --lui-row-gap: 12px;

    --lui-radius: 0;
    --lui-btn-h: 50px;
    --lui-overlay: rgba(20, 20, 20, .4);
    --lui-font: 'Jost', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ============================================================
   1) OFFCANVAS KAPSAYICI
   ============================================================ */
.lui-filter-canvas,
.lui-sort-canvas {
    width: var(--lui-canvas-width) !important;
    max-width: 100vw;
    background: var(--lui-bg);
    border-left: 0;
    box-shadow: -16px 0 40px rgba(0, 0, 0, .08);
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
    overflow: hidden !important;
    font-family: var(--lui-font);
    color: var(--lui-text);
}
.lui-sort-canvas { width: var(--lui-sort-canvas-width) !important; }

/* Bootstrap'ın olası padding/sınır müdahalesi */
.lui-filter-canvas .offcanvas-body,
.lui-sort-canvas   .offcanvas-body { padding: 0 !important; }

/* Backdrop */
.offcanvas-backdrop.show { background-color: var(--lui-overlay); opacity: 1; }

/* Selection rengini başlıkta yumuşat (mavi highlight problemi) */
.lui-filter-canvas ::selection,
.lui-sort-canvas   ::selection { background: rgba(48, 25, 52, .12); color: inherit; }

/* ============================================================
   2) HEADER
   ============================================================ */
.lui-filter-header {
    flex: 0 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--lui-header-pad-y) var(--lui-pad-x);
    border-bottom: 1px solid var(--lui-border);
    background: var(--lui-bg);
    position: relative;
    z-index: 2;
    gap: 16px;
    min-height: 64px;
}

.lui-filter-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--lui-text);
    letter-spacing: .01em;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    user-select: none;
    -webkit-user-select: none;
    background: transparent !important;
}

.lui-filter-title-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    background: var(--lui-accent);
    color: #fff;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 600;
    line-height: 1;
    flex-shrink: 0;
}
.lui-filter-title-count[hidden] { display: none; }

.lui-filter-close {
    background: transparent;
    border: 0;
    width: 36px;
    height: 36px;
    color: var(--lui-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .18s, opacity .18s;
    flex-shrink: 0;
    padding: 0;
    border-radius: 50%;
}
.lui-filter-close:hover { background: var(--lui-bg-soft); }
.lui-filter-close:focus-visible { outline: 2px solid var(--lui-accent); outline-offset: 2px; }
.lui-filter-close i { font-size: 1.05rem; }

/* ============================================================
   3) BODY
   ============================================================ */
.lui-filter-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    background: var(--lui-bg);
}
.lui-filter-body::-webkit-scrollbar { width: 4px; }
.lui-filter-body::-webkit-scrollbar-track { background: transparent; }
.lui-filter-body::-webkit-scrollbar-thumb { background: #d8d4d0; border-radius: 999px; }
.lui-filter-body::-webkit-scrollbar-thumb:hover { background: #b0a8a4; }

/* ============================================================
   4) FORM + FİLTRE GRUPLARI
   ============================================================ */
.lui-filter-form {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
}

.lui-fg {
    border-bottom: 1px solid var(--lui-border);
    background: var(--lui-bg);
}
.lui-fg:last-child { border-bottom: 0; }

/* ============================================================
   4.1) ACCORDION BAŞLIK
   ============================================================ */
.lui-fg-head {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--lui-pad-y) var(--lui-pad-x);
    background: transparent;
    border: 0;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    color: var(--lui-text);
    transition: color .15s;
    line-height: 1.3;
    gap: 12px;
}
.lui-fg-head:hover { color: var(--lui-accent); }
.lui-fg-head:focus-visible { outline: 2px solid var(--lui-accent); outline-offset: -2px; }

.lui-fg-title {
    font-size: .92rem;
    font-weight: 400;
    color: inherit;
    letter-spacing: .01em;
    flex: 1;
    min-width: 0;
    text-align: left;
}

.lui-fg-chev {
    font-size: .8rem;
    color: var(--lui-text);
    transition: transform .28s ease, color .15s;
    flex-shrink: 0;
}
.lui-fg.is-collapsed .lui-fg-chev {
    transform: rotate(-90deg);
    color: var(--lui-text-muted);
}

/* ============================================================
   4.2) ACCORDION GÖVDE
   ============================================================ */
.lui-fg-body {
    padding: 0 var(--lui-pad-x) var(--lui-pad-y);
    transition: max-height .32s ease, opacity .22s ease, padding .32s ease, visibility 0s .32s;
    max-height: 1200px;
    overflow: hidden;
    opacity: 1;
    visibility: visible;
}
.lui-fg.is-collapsed .lui-fg-body {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
    visibility: hidden;
    transition: max-height .32s ease, opacity .15s ease, padding .32s ease, visibility 0s .32s;
}

/* ============================================================
   5) TOGGLE GRUBU (Stok Durumu, İndirimli vb.)
   ============================================================ */
.lui-fg--toggle .lui-fg-toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--lui-pad-y) var(--lui-pad-x);
    cursor: pointer;
    gap: 16px;
    margin: 0;
    user-select: none;
    -webkit-user-select: none;
    transition: color .15s;
}
.lui-fg--toggle .lui-fg-toggle-row:hover .lui-fg-title { color: var(--lui-accent); }

/* ============================================================
   5.1) Custom switch
   ============================================================ */
.lui-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}
.lui-switch-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}
.lui-switch-track {
    position: absolute;
    inset: 0;
    background: var(--lui-track-off);
    border-radius: 999px;
    transition: background-color .2s ease;
}
.lui-switch-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    transition: transform .22s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .15);
}
.lui-switch-input:checked ~ .lui-switch-track { background: var(--lui-text); }
.lui-switch-input:checked ~ .lui-switch-track .lui-switch-thumb { transform: translateX(20px); }
.lui-switch-input:focus-visible ~ .lui-switch-track {
    box-shadow: 0 0 0 3px rgba(48, 25, 52, .15);
}

/* ============================================================
   6) INPUT, SELECT
   ============================================================ */
.lui-input {
    width: 100%;
    border: 1px solid var(--lui-border-mid);
    border-radius: var(--lui-radius);
    background: var(--lui-bg);
    font-size: .88rem;
    padding: 12px 14px;
    color: var(--lui-text);
    line-height: 1.4;
    font-family: inherit;
    box-shadow: none;
    box-sizing: border-box;
    outline: none;
    transition: border-color .15s;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}
.lui-input::placeholder { color: var(--lui-text-muted); }
.lui-input:focus {
    border-color: var(--lui-border-strong);
    outline: 0;
}
.lui-input:hover { border-color: #b8b8b8; }

/* Number input arrow'larını kaldır */
.lui-input[type="number"]::-webkit-outer-spin-button,
.lui-input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.lui-input[type="number"] { -moz-appearance: textfield; }

/* Select için chevron */
.lui-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%231a1a1a' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.4' d='M3 6l5 5 5-5'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 14px;
    padding-right: 36px;
    cursor: pointer;
}

/* ============================================================
   7) RANGE (Min - Max)
   ============================================================ */
.lui-range {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--lui-row-gap);
}
.lui-range-field {
    position: relative;
    display: flex;
    align-items: stretch;
}
.lui-range-field .lui-input { flex: 1; min-width: 0; }
.lui-range-unit {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: .85rem;
    color: var(--lui-text-muted);
    pointer-events: none;
}

/* ============================================================
   8) CHECKBOX LİSTESİ
   ============================================================ */
.lui-check-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.lui-check {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    margin: 0;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
}

.lui-check-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.lui-check-box {
    width: 18px;
    height: 18px;
    border: 1.5px solid #b8b8b8;
    background: var(--lui-bg);
    border-radius: 2px;
    flex-shrink: 0;
    position: relative;
    transition: background-color .15s, border-color .15s;
    display: inline-block;
}
.lui-check:hover .lui-check-box { border-color: var(--lui-text); }

.lui-check-input:checked + .lui-check-box {
    background-color: var(--lui-text);
    border-color: var(--lui-text);
}
.lui-check-input:checked + .lui-check-box::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 1px;
    width: 5px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.lui-check-input:focus-visible + .lui-check-box {
    box-shadow: 0 0 0 3px rgba(48, 25, 52, .15);
    border-color: var(--lui-text);
}

.lui-check-label {
    font-size: .9rem;
    color: #2a2a2a;
    line-height: 1.4;
    font-weight: 400;
    flex: 1;
    min-width: 0;
    word-break: break-word;
}

/* ============================================================
   9) BOŞ DURUM
   ============================================================ */
.lui-empty {
    color: var(--lui-text-muted);
    font-size: .85rem;
    margin: 0;
    padding: 4px 0;
}

/* ============================================================
   10) FOOTER (Reset + Apply)
   ============================================================ */
.lui-filter-footer {
    flex: 0 0 auto;
    padding: var(--lui-footer-pad-y) var(--lui-pad-x);
    border-top: 1px solid var(--lui-border);
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: var(--lui-row-gap);
    background: var(--lui-bg);
    position: relative;
    z-index: 2;
    padding-bottom: calc(var(--lui-footer-pad-y) + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -8px 20px rgba(0, 0, 0, .03);
}

.lui-filter-reset-btn,
.lui-filter-apply-btn {
    height: var(--lui-btn-h);
    padding: 0 16px;
    font-size: .85rem;
    font-weight: 500;
    letter-spacing: .03em;
    text-decoration: none;
    text-align: center;
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: var(--lui-radius);
    transition: all .18s ease;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1;
}

.lui-filter-reset-btn {
    background: var(--lui-bg);
    border: 1px solid var(--lui-border-strong);
    color: var(--lui-text);
}
.lui-filter-reset-btn:hover { background: var(--lui-text); color: #fff; }

.lui-filter-apply-btn {
    background: var(--lui-text);
    border: 1px solid var(--lui-text);
    color: #fff;
}
.lui-filter-apply-btn:hover { background: var(--lui-accent); border-color: var(--lui-accent); }
.lui-filter-apply-btn:disabled {
    opacity: .55;
    cursor: not-allowed;
    background: #6c6c6c;
    border-color: #6c6c6c;
}

.lui-filter-reset-btn:focus-visible,
.lui-filter-apply-btn:focus-visible {
    outline: 2px solid var(--lui-accent);
    outline-offset: 2px;
}

.lui-apply-spinner {
    width: 13px;
    height: 13px;
    border: 2px solid rgba(255, 255, 255, .3);
    border-top-color: #fff;
    border-radius: 50%;
    display: none;
    animation: luiSpin .65s linear infinite;
    flex-shrink: 0;
}
.lui-filter-apply-btn.is-loading .lui-apply-spinner { display: inline-block; }
@keyframes luiSpin { to { transform: rotate(360deg); } }

/* ============================================================
   11) SIRALA OFFCANVAS LİSTESİ
   ============================================================ */
.lui-sort-list {
    list-style: none;
    padding: 8px 0;
    margin: 0;
}
.lui-sort-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px var(--lui-pad-x);
    color: var(--lui-text);
    text-decoration: none;
    font-size: .92rem;
    font-weight: 400;
    border-bottom: 1px solid var(--lui-border);
    transition: background .15s, color .15s;
    cursor: pointer;
    font-family: inherit;
    gap: 12px;
}
.lui-sort-item span { flex: 1; min-width: 0; }
.lui-sort-list li:last-child .lui-sort-item { border-bottom: 0; }
.lui-sort-item:hover { background: var(--lui-accent-soft); color: var(--lui-accent); }
.lui-sort-item.is-active {
    color: var(--lui-accent);
    font-weight: 500;
    background: var(--lui-accent-soft);
}
.lui-sort-item i { color: var(--lui-accent); font-size: 1rem; flex-shrink: 0; }

/* ============================================================
   12) RESPONSIVE
   ============================================================ */
@media (max-width: 991.98px) {
    :root {
        --lui-canvas-width: 420px;
        --lui-sort-canvas-width: 380px;
    }
}

@media (max-width: 767.98px) {
    :root {
        --lui-pad-x: 24px;
        --lui-pad-y: 20px;
        --lui-header-pad-y: 20px;
        --lui-footer-pad-y: 16px;
        --lui-btn-h: 48px;
    }
    .lui-filter-canvas,
    .lui-sort-canvas {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100% !important;
        box-shadow: none;
    }
    .lui-filter-reset-btn,
    .lui-filter-apply-btn { font-size: .8rem; }
}

@media (max-width: 380px) {
    :root { --lui-pad-x: 18px; --lui-pad-y: 18px; }
    .lui-filter-reset-btn,
    .lui-filter-apply-btn { font-size: .74rem; padding: 0 10px; }
}

/* ============================================================
   13) REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    .lui-fg-chev,
    .lui-fg-body,
    .lui-switch-thumb,
    .lui-switch-track,
    .lui-filter-reset-btn,
    .lui-filter-apply-btn,
    .lui-filter-close,
    .lui-sort-item,
    .lui-input { transition: none !important; }
    .lui-apply-spinner { animation: none !important; }
}