/**
 * Memip Mobile Filter — chip bar + bottom sheet kiểu Vivino
 * Chỉ hiện ≤ 768px
 */

/* Ẩn trên desktop */
.memip-mfilter { display: none; }

@media (max-width: 849px) {
    .memip-mfilter { display: block; }

    /* === Chip bar === */
    .memip-mfilter__bar {
        position: sticky;
        top: 0;
        z-index: 95;
        background: #fff;
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 10px 12px;
        border-bottom: 1px solid #eee;
        box-shadow: 0 2px 4px rgba(0,0,0,.04);
    }

    .memip-mfilter__btn-all {
        flex: 0 0 auto;
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 8px 14px;
        background: #ed1c24;
        color: #fff;
        border: 0;
        border-radius: 999px;
        font-size: 13px;
        font-weight: 700;
        line-height: 1;
        cursor: pointer;
        white-space: nowrap;
        position: relative;
    }
    .memip-mfilter__btn-all svg { width: 14px; height: 14px; }

    .memip-mfilter__badge {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 18px;
        height: 18px;
        padding: 0 5px;
        background: #fff;
        color: #ed1c24;
        font-size: 11px;
        font-weight: 800;
        border-radius: 999px;
        margin-left: 2px;
    }

    .memip-mfilter__chips {
        flex: 1 1 auto;
        display: flex;
        gap: 8px;
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        padding: 0 2px;
    }
    .memip-mfilter__chips::-webkit-scrollbar { display: none; }

    .memip-mfilter__chip {
        flex: 0 0 auto;
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 8px 12px;
        background: #f5f5f5;
        color: #333;
        border: 1px solid #e8e8e8;
        border-radius: 999px;
        font-size: 13px;
        font-weight: 500;
        line-height: 1;
        cursor: pointer;
        white-space: nowrap;
    }
    .memip-mfilter__chip svg { opacity: .55; }

    .memip-mfilter__chip.is-active {
        background: #fff5f5;
        border-color: #ed1c24;
        color: #ed1c24;
        font-weight: 700;
    }

    .memip-mfilter__chip-cnt {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 18px;
        height: 18px;
        padding: 0 5px;
        background: #ed1c24;
        color: #fff;
        font-size: 11px;
        font-weight: 800;
        border-radius: 999px;
        margin-left: 2px;
    }

    /* === Bottom sheet === */
    .memip-mfilter__sheet {
        position: fixed;
        inset: 0;
        z-index: 9999;
        display: block;
    }
    .memip-mfilter__sheet[hidden] { display: none; }

    .memip-mfilter__backdrop {
        position: absolute;
        inset: 0;
        background: rgba(0,0,0,.5);
        opacity: 0;
        transition: opacity .25s ease;
    }
    .memip-mfilter__sheet.is-open .memip-mfilter__backdrop { opacity: 1; }

    .memip-mfilter__panel {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        max-height: 88vh;
        background: #fff;
        border-radius: 16px 16px 0 0;
        display: flex;
        flex-direction: column;
        transform: translateY(100%);
        transition: transform .28s cubic-bezier(.22,.61,.36,1);
        box-shadow: 0 -8px 24px rgba(0,0,0,.18);
    }
    .memip-mfilter__sheet.is-open .memip-mfilter__panel {
        transform: translateY(0);
    }

    .memip-mfilter__handle {
        width: 40px;
        height: 4px;
        background: #ddd;
        border-radius: 2px;
        margin: 8px auto 0;
        flex: 0 0 auto;
    }

    .memip-mfilter__head {
        position: relative;
        display: flex;
        align-items: center;
        padding: 12px 16px 12px;
        border-bottom: 1px solid #f0f0f0;
        flex: 0 0 auto;
    }
    .memip-mfilter__title {
        flex: 1 1 auto;
        font-size: 16px;
        font-weight: 700;
        color: #222;
    }
    .memip-mfilter__clear {
        background: none;
        border: 0;
        color: #ed1c24;
        font-size: 13px;
        font-weight: 600;
        padding: 4px 8px;
        cursor: pointer;
    }
    .memip-mfilter__close {
        background: none;
        border: 0;
        color: #555;
        padding: 4px;
        margin-left: 6px;
        display: inline-flex;
        cursor: pointer;
    }

    .memip-mfilter__body {
        flex: 1 1 auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 8px 0 16px;
    }

    .memip-mfilter__group {
        padding: 12px 16px;
        border-bottom: 1px solid #f5f5f5;
    }
    .memip-mfilter__group:last-child { border-bottom: 0; }
    .memip-mfilter__group-title {
        font-size: 14px;
        font-weight: 700;
        color: #ed1c24;
        margin: 0 0 12px;
        text-transform: uppercase;
        letter-spacing: .3px;
    }
    .memip-mfilter__group[hidden] { display: none; }

    .memip-mfilter__search {
        margin-bottom: 12px;
    }
    .memip-mfilter__search input {
        width: 100%;
        padding: 10px 14px;
        font-size: 14px;
        border: 1.5px solid #e8e8e8;
        border-radius: 8px;
        background: #fafafa;
        outline: none;
        box-sizing: border-box;
    }
    .memip-mfilter__search input:focus {
        border-color: #ed1c24;
        background: #fff;
    }

    .memip-mfilter__options {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    .memip-mfilter__opt[hidden] { display: none; }

    .memip-mfilter__opt {
        position: relative;
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 9px 14px;
        background: #fff;
        border: 1.5px solid #e8e8e8;
        border-radius: 999px;
        font-size: 13px;
        font-weight: 500;
        color: #333;
        cursor: pointer;
        line-height: 1;
        user-select: none;
        transition: all .15s ease;
    }
    .memip-mfilter__opt input[type="checkbox"] {
        position: absolute;
        opacity: 0;
        pointer-events: none;
        width: 0;
        height: 0;
    }
    .memip-mfilter__opt.is-checked {
        background: #fff5f5;
        border-color: #ed1c24;
        color: #ed1c24;
        font-weight: 700;
    }
    .memip-mfilter__opt-cnt {
        color: #999;
        font-size: 11px;
        font-weight: 400;
    }
    .memip-mfilter__opt.is-checked .memip-mfilter__opt-cnt {
        color: #ed1c24;
    }

    /* List dài (Giống nho 172 items) — đổi sang list dọc thay vì chips */
    .memip-mfilter__group[data-large="1"] .memip-mfilter__options {
        flex-direction: column;
        gap: 0;
    }
    .memip-mfilter__group[data-large="1"] .memip-mfilter__opt {
        width: 100%;
        justify-content: flex-start;
        background: transparent;
        border: 0;
        border-bottom: 1px solid #f0f0f0;
        border-radius: 0;
        padding: 14px 4px;
        font-size: 14px;
    }
    .memip-mfilter__group[data-large="1"] .memip-mfilter__opt::before {
        content: "";
        width: 20px;
        height: 20px;
        border: 2px solid #ccc;
        border-radius: 4px;
        margin-right: 12px;
        background: #fff;
        flex: 0 0 auto;
        position: relative;
    }
    .memip-mfilter__group[data-large="1"] .memip-mfilter__opt.is-checked::before {
        background: #ed1c24;
        border-color: #ed1c24;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
        background-size: 14px;
        background-position: center;
        background-repeat: no-repeat;
    }
    .memip-mfilter__group[data-large="1"] .memip-mfilter__opt-label {
        flex: 1 1 auto;
    }

    .memip-mfilter__foot {
        flex: 0 0 auto;
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
        border-top: 1px solid #f0f0f0;
        background: #fff;
    }
    .memip-mfilter__apply {
        width: 100%;
        padding: 14px 16px;
        background: #ed1c24;
        color: #fff;
        border: 0;
        border-radius: 8px;
        font-size: 15px;
        font-weight: 700;
        cursor: pointer;
        line-height: 1;
    }
    .memip-mfilter__apply:active { background: #b71c1c; }

    /* Khi sheet mở → khoá scroll body */
    body.memip-mfilter-open { overflow: hidden; }
}
