/*
 * Technical-support pages with the Ngoại thất / Nội thất filter (taxonomy-danh-muc-ky-thuat-canh-bao-an-toan.php,
 * taxonomy-danh-muc-ky-thuat-giai-dap-ky-thuat-thi-cong.php): layout on tablets and phones, and the mobile bottom
 * sheet that holds the filter. Enqueued only there (kosmos_ky_thuat_filter_assets, functions/actions.php).
 *
 * The templates print their own <style> in the body, i.e. after this file: every selector here starts with the
 * body class .tax-danh-muc-ky-thuat so it wins over the template rules it adjusts.
 */

/* ===== Tablet and phone: container width, columns ===== */
@media (max-width: 1024px) {
    /* The templates give section.post_detail .grid-container a 9rem side margin; three of these containers are
       nested, so on a tablet the filter and the posts ended up ~200 px wide each (one letter wide on a phone). */
    .tax-danh-muc-ky-thuat section.post_detail .grid-container {
        max-width: calc(100% - 2rem);
    }
}

@media (min-width: 768px) and (max-width: 1024px) {
    /* Filter a third, posts two thirds (was half / half). */
    .tax-danh-muc-ky-thuat .filter-section > .kt-filter-panel {
        width: 33.33333%;
    }

    .tax-danh-muc-ky-thuat .filter-section > .kt-filter-results {
        width: 66.66667%;
    }
}

/* ===== Desktop: full-width filter row, wider filter column ===== */
@media (min-width: 1025px) {
    /* The filter row is a .grid-container nested in another one: its own 9rem margin left a blank band on the right
       (150-230 px), and the filter column, 15% of what remained, was 116-156 px wide below 1366 px (one or two words
       per line). The row now takes the full width and the filter column at least 240 px. */
    .tax-danh-muc-ky-thuat section.post_detail .filter-section {
        max-width: none;
    }

    .tax-danh-muc-ky-thuat .filter-section > .kt-filter-panel {
        width: max(15%, 240px);
    }

    .tax-danh-muc-ky-thuat .filter-section > .kt-filter-results {
        width: calc(100% - max(15%, 240px));
    }
}

/* ===== Phone: filter in a bottom sheet opened by a "Bộ lọc" button ===== */
.kt-filter-bar,
.kt-filter-head,
.kt-filter-foot,
.kt-filter-backdrop {
    display: none;
}

@media (max-width: 767px) {
    /* sticky makes a stacking context, which kept the sheet under the fixed menu and the contact buttons; on a phone
       the column holds the whole list, so it never stuck anyway. */
    .tax-danh-muc-ky-thuat section.post_detail .filter-section {
        position: static;
        overflow: visible;
    }

    .tax-danh-muc-ky-thuat .kt-filter-bar {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        margin: 0 0 20px;
    }

    .tax-danh-muc-ky-thuat .kt-filter-toggle,
    .tax-danh-muc-ky-thuat .kt-filter-bar .kt-filter-clear {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        height: 42px;
        padding: 0 18px;
        border-radius: 99px;
        font-size: 15px;
        font-weight: 600;
        cursor: pointer;
    }

    .tax-danh-muc-ky-thuat .kt-filter-toggle {
        border: 1px solid #e31937;
        background: #fff;
        color: #e31937;
    }

    .tax-danh-muc-ky-thuat .kt-filter-toggle.has-filters {
        background: #e31937;
        color: #fff;
    }

    .tax-danh-muc-ky-thuat .kt-filter-toggle svg {
        width: 18px;
        height: 18px;
        flex: 0 0 auto;
    }

    .tax-danh-muc-ky-thuat .kt-filter-count {
        min-width: 22px;
        height: 22px;
        padding: 0 6px;
        border-radius: 99px;
        background: #fff;
        color: #e31937;
        font-size: 13px;
        line-height: 22px;
        text-align: center;
    }

    .tax-danh-muc-ky-thuat .kt-filter-bar .kt-filter-clear {
        border: 0;
        background: none;
        color: #494949;
        font-weight: 500;
        text-decoration: underline;
        padding: 0 6px;
    }

    .tax-danh-muc-ky-thuat .filter-section > .kt-filter-panel {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 100001;
        width: 100%;
        max-height: 85vh;
        margin: 0;
        padding: 0 16px;
        overflow-y: auto;
        overscroll-behavior: contain;
        background: #fff;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.18);
        transform: translateY(105%);
        visibility: hidden;
        transition: transform .25s ease, visibility 0s linear .25s;
    }

    .tax-danh-muc-ky-thuat .filter-section > .kt-filter-panel.is-open {
        transform: none;
        visibility: visible;
        transition: transform .25s ease;
    }

    .tax-danh-muc-ky-thuat .kt-filter-head,
    .tax-danh-muc-ky-thuat .kt-filter-foot {
        display: flex;
        align-items: center;
        position: sticky;
        z-index: 1;
        background: #fff;
    }

    .tax-danh-muc-ky-thuat .kt-filter-head {
        top: 0;
        justify-content: space-between;
        padding: 14px 0 10px;
        border-bottom: 1px solid #eee;
        margin-bottom: 14px;
        font-size: 17px;
        font-weight: 700;
        color: #222;
    }

    .tax-danh-muc-ky-thuat .kt-filter-close {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        padding: 0;
        border: 0;
        border-radius: 50%;
        background: #f2f2f2;
        color: #333;
        font-size: 24px;
        line-height: 1;
        cursor: pointer;
    }

    .tax-danh-muc-ky-thuat .kt-filter-foot {
        bottom: 0;
        gap: 10px;
        padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid #eee;
    }

    .tax-danh-muc-ky-thuat .kt-filter-foot button {
        flex: 1;
        height: 44px;
        border-radius: 8px;
        font-size: 15px;
        font-weight: 600;
        cursor: pointer;
    }

    .tax-danh-muc-ky-thuat .kt-filter-foot .kt-filter-clear {
        border: 1px solid #ccc;
        background: #fff;
        color: #333;
    }

    .tax-danh-muc-ky-thuat .kt-filter-foot .kt-filter-apply {
        border: 0;
        background: #e31937;
        color: #fff;
    }

    .tax-danh-muc-ky-thuat .kt-filter-panel .filter-box {
        border: 0;
        box-shadow: none;
        padding: 0;
    }

    .tax-danh-muc-ky-thuat .kt-filter-panel .filter-box label {
        padding: 4px 0;
    }

    .tax-danh-muc-ky-thuat .kt-filter-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 100000;
        background: rgba(0, 0, 0, 0.45);
        opacity: 0;
        visibility: hidden;
        transition: opacity .25s ease, visibility 0s linear .25s;
    }

    .tax-danh-muc-ky-thuat .kt-filter-backdrop.is-open {
        opacity: 1;
        visibility: visible;
        transition: opacity .25s ease;
    }

    html.kt-filter-lock,
    html.kt-filter-lock body {
        overflow: hidden;
    }

    /* The containers around the sheet are z-index 4 stacking contexts: lift them over the fixed header, menu and
       contact buttons only while the sheet is open. */
    html.kt-filter-lock .tax-danh-muc-ky-thuat section.post_detail .grid-container {
        z-index: 100001;
    }
}
