/* ─────────────────────────────────────────────
 * Multifilter — Filter UI Styles
 * Prefix: kre-mf-
 * ───────────────────────────────────────────── */

/* ── Base Container ── */
.kre-mf {
    margin-bottom: 24px;
    position: relative;
}

.kre-mf-toggle {
    display: none;
}

.kre-mf-toggle-count {
    display: none;
}

.kre-mf-toggle-reset {
    display: none !important;
}

/* ── Panel ── */
.kre-mf-panel {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* ── Layout: Sidebar (via .kre-mf-sidebar-wrap) ── */
.kre-mf-sidebar-wrap {
    display: flex;
    gap: 30px;
    align-items: flex-start;
}

.kre-mf-sidebar-wrap .kre-mf {
    flex: 0 0 250px;
    margin-bottom: 0;
}

.kre-mf-sidebar-wrap .kre-mf .kre-mf-panel {
    position: sticky;
    top: 80px;
}

.kre-mf-sidebar-wrap .kre-mf-grid-area {
    flex: 1;
    min-width: 0;
}

/* ── Layout: Sidebar Compact ── */
.kre-mf-sidebar-wrap .kre-mf[data-layout="sidebar_compact"] {
    flex: 0 0 210px;
}

.kre-mf[data-layout="sidebar_compact"] .kre-mf-panel {
    gap: 0;
}

.kre-mf[data-layout="sidebar_compact"] .kre-mf-group {
    border: none;
    border-radius: 0;
    border-bottom: 1px solid #eee;
    background: none;
    overflow: visible;
}

.kre-mf[data-layout="sidebar_compact"] .kre-mf-group:last-of-type {
    border-bottom: none;
}

.kre-mf[data-layout="sidebar_compact"] .kre-mf-group-header {
    padding: 8px 0;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #555;
}

.kre-mf[data-layout="sidebar_compact"] .kre-mf-group-header:hover {
    background: none;
}

.kre-mf[data-layout="sidebar_compact"] .kre-mf-group-header i {
    font-size: 14px;
    color: #999;
}

.kre-mf[data-layout="sidebar_compact"] .kre-mf-group-body {
    padding: 0 0 6px;
    max-height: 180px;
}

#page .kre-mf[data-layout="sidebar_compact"] .kre-mf-option,
.kre-mf[data-layout="sidebar_compact"] .kre-mf-panel .kre-mf-option {
    padding: 3px 0;
    font-size: 13px;
    gap: 6px;
    min-height: 0;
    line-height: 1.25;
}

.kre-mf[data-layout="sidebar_compact"] .kre-mf-option input[type="checkbox"],
.kre-mf[data-layout="sidebar_compact"] .kre-mf-option input[type="radio"] {
    width: 15px !important;
    height: 15px !important;
    min-width: 15px;
    flex-shrink: 0;
}

.kre-mf[data-layout="sidebar_compact"] .kre-mf-count-badge {
    font-size: 11px;
}

.kre-mf[data-layout="sidebar_compact"] .kre-mf-search {
    margin-bottom: 4px;
}

.kre-mf[data-layout="sidebar_compact"] .kre-mf-search input {
    padding: 6px 10px 6px 30px !important;
    font-size: 13px;
    border-radius: 5px;
}

.kre-mf[data-layout="sidebar_compact"] .kre-mf-search i {
    font-size: 15px;
    left: 9px;
}

.kre-mf[data-layout="sidebar_compact"] .kre-mf-group select {
    padding: 5px 8px;
    font-size: 13px;
    border-radius: 5px;
}

.kre-mf[data-layout="sidebar_compact"] .kre-mf-toggle-pills {
    padding: 2px;
    border-radius: 5px;
}

.kre-mf[data-layout="sidebar_compact"] .kre-mf-pill {
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 4px;
}

#page .kre-mf[data-layout="sidebar_compact"] .kre-mf-reset,
.kre-mf[data-layout="sidebar_compact"] .kre-mf-panel .kre-mf-reset {
    font-size: 11px;
    padding: 0;
    background: none !important;
    border: none;
    color: #999 !important;
    font-weight: 400;
    width: auto;
    justify-content: flex-start;
}

#page .kre-mf[data-layout="sidebar_compact"] .kre-mf-reset:hover,
.kre-mf[data-layout="sidebar_compact"] .kre-mf-panel .kre-mf-reset:hover {
    color: var(--accent, #2271b1) !important;
}

#page .kre-mf[data-layout="sidebar_compact"] .kre-mf-reset i,
.kre-mf[data-layout="sidebar_compact"] .kre-mf-panel .kre-mf-reset i {
    color: inherit !important;
    font-size: 13px;
}

.kre-mf[data-layout="sidebar_compact"] .kre-mf-count {
    font-size: 11px;
    color: #999;
}

.kre-mf[data-layout="sidebar_compact"] .kre-mf-actions {
    gap: 8px;
    margin-top: 2px;
}

/* ── Layout: Top (Button-Dropdowns) ── */
.kre-mf[data-layout="top"] .kre-mf-panel {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
}

.kre-mf[data-layout="top"] .kre-mf-group {
    position: relative;
    overflow: visible;
    border: none;
    background: none;
}

.kre-mf[data-layout="top"] .kre-mf-group-header {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 40px;
    padding: 0 16px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #fff;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    box-sizing: border-box;
    transition: border-color 0.15s, background 0.15s;
}

.kre-mf[data-layout="top"] .kre-mf-group-header:hover {
    border-color: #bbb;
    background: #fafafa;
}

.kre-mf[data-layout="top"] .kre-mf-group-header i {
    font-size: 16px;
    transition: transform 0.2s;
}

.kre-mf[data-layout="top"] .kre-mf-group.open .kre-mf-group-header {
    border-color: var(--accent, #2271b1);
    background: #f0f7fc;
}

.kre-mf[data-layout="top"] .kre-mf-group.open .kre-mf-group-header i {
    transform: rotate(180deg);
}

.kre-mf[data-layout="top"] .kre-mf-group.has-active .kre-mf-group-header {
    border-color: var(--accent, #2271b1);
    color: var(--accent, #2271b1);
}

.kre-mf[data-layout="top"] .kre-mf-group-body {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 220px;
    max-height: 300px;
    overflow-y: auto;
    padding: 12px 16px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    z-index: 100;
}

.kre-mf[data-layout="top"] .kre-mf-group.open .kre-mf-group-body {
    display: block;
}


.kre-mf[data-layout="top"] .kre-mf-search {
    flex: 0 0 auto;
    min-width: 200px;
    max-width: 280px;
    height: 40px;
}

.kre-mf[data-layout="top"] .kre-mf-search input {
    height: 40px;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    box-sizing: border-box;
    margin: 0 !important;
}

.kre-mf[data-layout="top"] .kre-mf-actions {
    margin-left: auto;
}

#page .kre-mf[data-layout="top"] .kre-mf-reset {
    width: auto;
    height: 40px;
    font-size: 14px;
    padding: 0 16px;
    box-sizing: border-box;
}

/* ── Layout: Topbar ── */
.kre-mf[data-layout="topbar"] .kre-mf-panel {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 12px;
}

.kre-mf[data-layout="topbar"] .kre-mf-group {
    flex: 0 0 auto;
    min-width: 180px;
}

.kre-mf[data-layout="topbar"] .kre-mf-group-header {
    display: none;
}

.kre-mf[data-layout="topbar"] .kre-mf-group-body {
    display: block !important;
}

.kre-mf[data-layout="topbar"] .kre-mf-search {
    flex: 1;
    min-width: 200px;
}

/* ── Search ── */
.kre-mf-search {
    position: relative;
}

.kre-mf-search i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
    font-size: 18px;
    pointer-events: none;
}

.kre-mf-search input {
    width: 100%;
    padding: 10px 14px 10px 38px !important;
    border: 1px solid #ddd !important;
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
    transition: border-color 0.2s;
}

.kre-mf-search input:focus {
    outline: none;
    border-color: var(--accent, #2271b1) !important;
    box-shadow: 0 0 0 2px rgba(34, 113, 177, 0.15);
}

/* ── Filter Groups ── */
.kre-mf-group {
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.kre-mf-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    user-select: none;
    transition: background 0.15s;
}

.kre-mf-group-header:hover {
    background: #f8f8f8;
}

.kre-mf-group-header i {
    transition: transform 0.2s;
    font-size: 18px;
    color: #666;
}

.kre-mf-group.collapsed .kre-mf-group-header i {
    transform: rotate(-90deg);
}

.kre-mf-group-body {
    padding: 8px 16px 16px;
    max-height: 280px;
    overflow-y: auto;
}

.kre-mf-group.collapsed .kre-mf-group-body {
    display: none;
}

/* ── Options (Checkbox / Radio) ── */
#page .kre-mf-option,
.kre-mf-panel .kre-mf-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    cursor: pointer;
    font-size: 14px;
    line-height: 1.3;
    margin: 0;
}

.kre-mf-option input {
    position: relative !important;
    margin: 0 !important;
}

.kre-mf-option span {
    flex: 1;
}

.kre-mf-count-badge {
    color: #999;
    font-size: 12px;
    font-weight: normal;
}

/* ── Disabled Options (0 results) ── */
.kre-mf-option.is-disabled {
    opacity: 0.45;
    cursor: default;
    pointer-events: none;
}

.kre-mf-option.is-disabled .kre-mf-count-badge {
    color: #c00;
}

.kre-mf-group select option:disabled {
    color: #999;
}

/* ── Select ── */
.kre-mf-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
    cursor: pointer;
}

.kre-mf-group select:focus {
    outline: none;
    border-color: var(--accent, #2271b1);
}

/* ── Range ── */
.kre-mf-range {
    display: flex;
    align-items: center;
    gap: 8px;
}

.kre-mf-range input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    min-width: 0;
}

.kre-mf-range input:focus {
    outline: none;
    border-color: var(--accent, #2271b1);
}

.kre-mf-range-sep {
    color: #999;
    flex-shrink: 0;
}

/* ── Actions ── */
.kre-mf-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

#page .kre-mf-reset,
.kre-mf-panel .kre-mf-reset {
    cursor: pointer;
    font-size: 1.3rem;
    display: flex;
    width: 100%;
    justify-content: center;
    align-items: center;
    background: var(--grey) !important;
    color: var(--dark) !important;
}

#page .kre-mf-reset i,
.kre-mf-panel .kre-mf-reset i {
    margin-right: 4px;
    color: var(--dark) !important;
}

.kre-mf-count {
    font-size: 14px;
    color: #666;
    font-weight: 500;
}

/* ── Toggle Pills (Segmented Control) ── */
.kre-mf-toggle-pills {
    display: flex;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background: #f5f5f5;
    padding: 3px;
    gap: 3px;
}

.kre-mf-pill {
    flex: 1;
    text-align: center;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
    margin: 0 !important;
    white-space: nowrap;
}

.kre-mf-pill input {
    position: absolute !important;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.kre-mf-pill:has(input:checked) {
    background: #fff;
    color: var(--accent, #2271b1);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.kre-mf-pill.is-disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

/* ── Loading State ── */
.kre-mf-loading {
    position: relative;
    pointer-events: none;
    min-height: 100px;
}

.kre-mf-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.7);
    z-index: 10;
}

.kre-mf-loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 36px;
    height: 36px;
    margin: -18px 0 0 -18px;
    border: 3px solid #e8e8e8;
    border-top-color: var(--accent, #2271b1);
    border-radius: 50%;
    animation: kre-mf-spin 0.7s linear infinite;
    z-index: 11;
}

@keyframes kre-mf-spin {
    to { transform: rotate(360deg); }
}

/* ── Pagination ── */
.kre-mf-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    padding: 24px 0 8px;
}

.kre-mf-pagination a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    text-decoration: none;
    color: #333;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
}

.kre-mf-pagination a:hover {
    border-color: var(--accent, #2271b1);
    color: var(--accent, #2271b1);
}

.kre-mf-pagination a.active {
    background: var(--accent, #2271b1);
    border-color: var(--accent, #2271b1);
    color: #fff;
}

/* ── Mobile Buttons (hidden on desktop) ── */
.kre-mf-mobile-btns {
    display: none;
}

/* ── Mobile (< 1241px) ── */
@media (max-width: 1240px) {
    .kre-mf-toggle {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        margin-bottom: 12px;
    }

    .kre-mf-toggle i {
        font-size: 18px;
    }

    /* Badge: active filter count on toggle button */
    .kre-mf.has-filters .kre-mf-toggle-count {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 22px;
        height: 22px;
        padding: 0 6px;
        background: #fff;
        color: var(--accent, #2271b1);
        border-radius: 11px;
        font-size: 12px;
        font-weight: 700;
        margin-left: 4px;
    }

    /* Reset button next to toggle */
    .kre-mf.has-filters .kre-mf-toggle-reset {
        display: inline-flex !important;
        align-items: center;
        gap: 4px;
        margin-bottom: 12px;
        margin-left: 8px;
        font-size: 14px;
        height: auto;
        padding: 8px 14px;
    }

    .kre-mf-panel {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 99999;
        background: #fff;
        padding: 20px 16px calc(100px + env(safe-area-inset-bottom, 0px));
        overflow-y: auto;
    }

    .kre-mf.panel-open .kre-mf-panel,
    .kre-mf-panel.is-open {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    body.kre-mf-overlay-open {
        overflow: hidden;
    }

    /* ── Mobile: Panel title ── */
    .kre-mf-panel::before {
        content: 'Filter';
        display: block;
        font-size: 17px;
        font-weight: 700;
        padding-bottom: 6px;
        border-bottom: 1px solid #e8e8e8;
        margin-bottom: 2px;
    }

    /* ── Mobile: Groups — always open, no accordion ── */
    .kre-mf-group {
        border: none !important;
        border-radius: 0 !important;
        background: transparent !important;
        overflow: visible !important;
    }

    .kre-mf-group.collapsed .kre-mf-group-body {
        display: block !important;
    }

    .kre-mf-group + .kre-mf-group {
        border-top: 1px solid #e8e8e8 !important;
        padding-top: 8px;
    }

    .kre-mf-group-header {
        padding: 6px 0 4px !important;
        font-size: 11px !important;
        font-weight: 600 !important;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: #999;
        background: none !important;
        border: none !important;
        border-radius: 0 !important;
        height: auto !important;
        cursor: default !important;
        pointer-events: none;
    }

    .kre-mf-group-header i {
        display: none !important;
    }

    .kre-mf-group-body {
        padding: 0 !important;
        max-height: none !important;
        overflow: visible !important;
    }

    /* ── Mobile: Custom Checkboxes & Radios ── */
    .kre-mf-option input[type="checkbox"],
    .kre-mf-option input[type="radio"] {
        -webkit-appearance: none;
        appearance: none;
        width: 18px !important;
        height: 18px !important;
        min-width: 18px;
        flex-shrink: 0;
        border: 2px solid #ccc;
        border-radius: 4px;
        background: #fff;
        position: relative !important;
        cursor: pointer;
        transition: border-color 0.15s, background 0.15s;
    }

    .kre-mf-option input[type="radio"] {
        border-radius: 50%;
    }

    .kre-mf-option input[type="checkbox"]:checked,
    .kre-mf-option input[type="radio"]:checked {
        background: var(--accent, #2271b1);
        border-color: var(--accent, #2271b1);
    }

    .kre-mf-option input[type="checkbox"]:checked::after {
        content: '';
        position: absolute;
        left: 4px;
        top: 1px;
        width: 5px;
        height: 9px;
        border: solid #fff;
        border-width: 0 2px 2px 0;
        transform: rotate(45deg);
    }

    .kre-mf-option input[type="radio"]:checked::after {
        content: '';
        position: absolute;
        left: 4px;
        top: 4px;
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: #fff;
    }

    /* ── Mobile: Options ── */
    .kre-mf-panel .kre-mf-option {
        display: flex !important;
        align-items: center !important;
        padding: 8px 6px !important;
        margin: 0 !important;
        border-radius: 6px;
        font-size: 14px !important;
        line-height: 1.35 !important;
        gap: 10px !important;
        min-height: 40px;
        transition: background 0.15s;
    }

    .kre-mf-panel .kre-mf-option:active {
        background: #f4f4f4;
    }

    .kre-mf-panel .kre-mf-option:has(input:checked) {
        background: rgba(34, 113, 177, 0.06);
    }

    .kre-mf-panel .kre-mf-option span {
        flex: 1;
        min-width: 0;
    }

    .kre-mf-count-badge {
        font-size: 12px !important;
        color: #999;
        flex-shrink: 0;
        margin-left: auto;
    }

    /* ── Mobile: Toggle Pills ── */
    .kre-mf-toggle-pills {
        border-radius: 8px;
        padding: 3px;
    }

    .kre-mf-pill {
        padding: 8px 12px;
        font-size: 14px;
        min-height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 6px;
    }

    /* ── Mobile: Search ── */
    .kre-mf-search input {
        height: 40px;
        font-size: 16px !important; /* 16px prevents iOS zoom */
        border-radius: 8px;
    }

    .kre-mf-search i {
        font-size: 18px;
    }

    /* ── Mobile: Select ── */
    .kre-mf-group select {
        height: 40px;
        font-size: 16px; /* 16px prevents iOS zoom */
        border-radius: 8px;
    }

    /* ── Mobile: Bottom buttons ── */
    .kre-mf-mobile-btns {
        display: flex;
        gap: 6px;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 6px 16px;
        padding-bottom: max(6px, env(safe-area-inset-bottom));
        background: #fff;
        border-top: 1px solid #e8e8e8;
        z-index: 100000;
    }

    .kre-mf-mobile-btns .btn {
        flex: 1;
        min-height: 36px;
        font-size: 13px;
    }

    /* ── Mobile: Actions (hide in panel, use bottom buttons instead) ── */
    .kre-mf-actions {
        display: none !important;
    }

    /* Reset sidebar layout on mobile */
    .kre-mf-sidebar-wrap {
        display: block;
    }

    .kre-mf-sidebar-wrap .kre-mf .kre-mf-panel {
        position: fixed;
    }

    /* Topbar becomes stacked on mobile */
    .kre-mf[data-layout="topbar"] .kre-mf-panel {
        flex-direction: column;
    }

    .kre-mf[data-layout="topbar"] .kre-mf-group-header {
        display: flex;
    }

    /* Top layout on mobile */
    .kre-mf[data-layout="top"] .kre-mf-panel {
        flex-direction: column;
    }

    .kre-mf[data-layout="top"] .kre-mf-group-body {
        display: block;
        position: static;
        box-shadow: none;
        min-width: 0;
    }

    .kre-mf[data-layout="top"] .kre-mf-search {
        max-width: none;
        height: auto;
    }

    .kre-mf[data-layout="top"] .kre-mf-actions {
        margin-left: 0;
    }
}

/* ── Scrollbar styling for filter body ── */
.kre-mf-group-body::-webkit-scrollbar {
    width: 5px;
}

.kre-mf-group-body::-webkit-scrollbar-track {
    background: #f5f5f5;
    border-radius: 3px;
}

.kre-mf-group-body::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.kre-mf-group-body::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}
