/* Product Archive Footer Menu — category / tag / taxonomy sản phẩm.
   Giao diện theo thanh điều hướng trang sản phẩm (css/product-navigation.css).
   Nitro ép `position: relative; z-index: 1` cho mọi div sau header (xem
   css/language-switcher.css) nên các lớp fixed phải dùng !important. */

.thean-apfm,
.thean-apfm *,
.thean-apfm-modal,
.thean-apfm-modal * {
    box-sizing: border-box;
}

.thean-apfm {
    --thean-apfm-surface: var(--default-color-white, #fff);
    --thean-apfm-text: var(--default-color-navy-blue, #001f3f);
    --thean-apfm-primary: var(--default-color-green, #08e097);
    --thean-apfm-radius: var(--md-radius, 8px);
    --thean-apfm-shadow: var(--md-shadow-2, 0 3px 6px rgba(0,0,0,.16));
    position: fixed !important;
    left: 12px;
    right: 12px;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    z-index: 1003 !important;
    color: var(--thean-apfm-text);
}

body.has-apfm {
    padding-bottom: 96px;
}

.thean-apfm__bar {
    display: flex;
    align-items: stretch;
    gap: 6px;
    padding: 6px;
    background: var(--thean-apfm-surface);
    border: 1px solid var(--default-color-grey, #ededed);
    border-radius: var(--thean-apfm-radius);
    box-shadow: var(--thean-apfm-shadow);
}

.thean-apfm__item {
    position: relative;
    display: inline-flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    min-height: 48px;
    margin: 0;
    padding: 5px 4px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: var(--default-color-grey-2, #f8f4f2);
    color: var(--thean-apfm-text);
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: var(--md-transition, all .25s cubic-bezier(.4,0,.2,1));
}

.thean-apfm__item:hover,
.thean-apfm__item:focus-visible {
    background: var(--thean-apfm-primary);
    border-color: var(--thean-apfm-primary);
    color: var(--default-color-navy-blue, #001f3f);
    text-decoration: none;
    outline: 0;
}

.thean-apfm__item--compare {
    background: var(--thean-apfm-primary);
    border-color: var(--thean-apfm-primary);
}

.thean-apfm__icon {
    display: inline-flex;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}

.thean-apfm__icon svg {
    width: 100%;
    height: 100%;
}

/* Mobile: tối đa 2 dòng để "So sánh sản phẩm" không bị cắt ở 3 cột hẹp. */
.thean-apfm__label {
    display: -webkit-box;
    max-width: 100%;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.thean-apfm__badge[hidden] {
    display: none;
}

.thean-apfm__badge {
    position: absolute;
    top: 3px;
    right: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--default-color-pink, #ff8189);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

@media (min-width: 768px) {
    .thean-apfm {
        left: 0;
        right: 0;
        bottom: 0;
    }

    body.has-apfm {
        padding-bottom: 62px;
    }

    .thean-apfm__bar {
        justify-content: center;
        gap: 6px;
        padding: 6px 16px;
        border-width: 1px 0 0;
        border-radius: 0;
    }

    .thean-apfm__item {
        flex: 0 1 220px;
        flex-direction: row;
        gap: 8px;
        min-height: 38px;
        padding: 6px 14px;
        font-size: 13px;
    }

    .thean-apfm__badge {
        position: static;
    }

    .thean-apfm__label {
        display: block;
        white-space: nowrap;
    }
}

/* ---------- Modal so sánh ---------- */

.thean-apfm-modal[hidden] {
    display: none !important;
}

.thean-apfm-modal {
    position: fixed !important;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 100010 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    color: var(--default-color-navy-blue, #001f3f);
}

.thean-apfm-modal__backdrop {
    position: absolute !important;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 0 !important;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    background: rgba(0, 31, 63, .55);
}

.thean-apfm-modal__panel {
    position: relative;
    z-index: 1 !important;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1600px;
    max-height: calc(100vh - 32px);
    border-radius: var(--md-radius, 8px);
    background: var(--default-color-white, #fff);
    box-shadow: var(--default-box-shadow, 0 20px 50px rgba(0,0,0,.3));
}

.thean-apfm-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--default-color-grey, #ededed);
}

.thean-apfm-modal__title {
    margin: 0;
    color: var(--default-color-navy-blue, #001f3f);
    font-size: 22px;
}

.thean-apfm-modal__close {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--default-color-black, #323232);
    font-size: 32px;
    line-height: 1;
    cursor: pointer;
}

.thean-apfm-modal__body {
    min-width: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 14px 18px 18px;
    -webkit-overflow-scrolling: touch;
}

.thean-apfm-modal__hint {
    margin: 0 0 8px;
    font-size: 14px;
}

/* Tiêu đề của shortcode trùng với tiêu đề modal. */
.thean-apfm-compare .tpc-header .tpc-title {
    display: none;
}

.thean-apfm-picks {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 8px;
    max-height: 260px;
    margin: 0 0 16px;
    padding: 0 2px 2px 0;
    overflow-y: auto;
    list-style: none;
}

.thean-apfm-picks li {
    margin: 0;
    padding: 0;
    list-style: none;
}

.thean-apfm-pick {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-width: 0;
    min-height: 60px;
    margin: 0;
    padding: 6px 10px 6px 6px;
    border: 1px solid var(--default-color-grey, #ededed);
    border-radius: var(--md-radius, 8px);
    background: #fff;
    color: var(--default-color-navy-blue, #001f3f);
    font: inherit;
    letter-spacing: 0;
    line-height: 1.3;
    text-align: left;
    text-transform: none;
    cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease;
}

.thean-apfm-pick:hover,
.thean-apfm-pick:focus-visible {
    border-color: var(--default-color-green, #08e097);
    outline: 0;
}

.thean-apfm-pick[aria-pressed="true"] {
    border-color: var(--default-color-green, #08e097);
    background: rgba(8, 224, 151, .1);
}

.thean-apfm-pick[aria-disabled="true"] {
    opacity: .5;
    cursor: not-allowed;
}

.thean-apfm-pick__thumb {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 6px;
    background: var(--default-color-grey-2, #f8f4f2);
    object-fit: cover;
}

.thean-apfm-pick__text {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.thean-apfm-pick__title {
    display: -webkit-box;
    overflow: hidden;
    font-size: 13px;
    font-weight: 700;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.thean-apfm-pick__price {
    color: var(--default-color-pink, #ff8189);
    font-size: 12px;
    font-weight: 700;
}

.thean-apfm-pick__price del {
    color: #8a94a0;
    font-weight: 400;
}

.thean-apfm-pick__state {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: 1.5px solid #cbd5e1;
    border-radius: 50%;
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
}

.thean-apfm-pick__state::before {
    content: "+";
}

.thean-apfm-pick[aria-pressed="true"] .thean-apfm-pick__state {
    border-color: var(--default-color-green, #08e097);
    background: var(--default-color-green, #08e097);
}

.thean-apfm-pick[aria-pressed="true"] .thean-apfm-pick__state::before {
    content: "\2713";
    font-size: 13px;
}

/* ---------- Bảng so sánh trong modal ----------
   Override CSS inline của [product_compare] (selector #tpc-compare-N ...), chỉ trong modal
   — trang /so-sanh/ giữ nguyên. Selector có #thean-apfm-compare + 3 class để thắng specificity
   vì <style> của shortcode in sau stylesheet này.
   Bảng luôn vừa khít chiều ngang modal (không cuộn ngang); modal body là vùng cuộn dọc
   duy nhất nên hàng ảnh + tên sản phẩm (sticky) bám được đầu modal khi cuộn. */

#thean-apfm-compare .thean-apfm-compare .tpc-compare-root {
    grid-template-columns: minmax(0, 1fr);
    min-width: 0;
}

#thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-table-shell,
#thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-table-scroll {
    min-width: 0;
    max-width: 100%;
    overflow: visible;
}

#thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-compare-table {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    table-layout: fixed;
    border-spacing: 0 8px;
}

#thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-compare-table th,
#thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-compare-table td {
    overflow-wrap: anywhere;
    word-break: normal;
}

#thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-section-head {
    display: table-row;
    width: auto;
    min-width: 0;
}

#thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-section-head th {
    display: table-cell;
    width: auto;
    min-width: 0;
    padding: 4px 0 0;
}

#thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-section-title {
    font-size: 18px;
    padding: 10px 14px;
    border-radius: 8px;
    box-shadow: none;
}

#thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-section-note {
    display: none;
}

#thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-product-summary-row td {
    position: sticky;
    top: -14px;
    z-index: 5;
}

#thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-product-image {
    max-width: 120px;
}

#thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-product-summary-title {
    font-size: 15px;
}

/* Nút .button của theme cha có min-width 150px + line-height 45px — phá cột hẹp. */
#thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-add-to-cart {
    min-width: 0 !important;
    max-width: 100%;
    height: auto !important;
    white-space: normal;
    text-align: center;
}

#thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-cell-content img,
#thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-cell-content iframe,
#thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-cell-content table {
    max-width: 100%;
    height: auto;
}

#thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-cell-content table {
    display: block;
    overflow-x: auto;
}

@media (max-width: 767px) {
    /* Danh sách chọn nhanh: 1 hàng cuộn ngang để nhường chỗ cho bảng. */
    .thean-apfm-picks {
        display: flex;
        gap: 8px;
        max-height: none;
        margin-bottom: 12px;
        padding-bottom: 6px;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
    }

    .thean-apfm-picks li {
        flex: 0 0 72%;
        max-width: 240px;
        scroll-snap-align: start;
    }

    .thean-apfm-pick {
        min-height: 56px;
    }

    .thean-apfm-pick__thumb {
        width: 40px;
        height: 40px;
    }

    /* Bảng: các sản phẩm đặt cạnh nhau vừa khít màn hình, chữ gọn, tiêu đề mục full-width. */
    #thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-compare-table {
        border-spacing: 0 6px;
        font-size: 12.5px;
        line-height: 1.45;
    }

    #thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-compare-table th,
    #thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-compare-table td {
        padding: 8px 6px;
    }

    #thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-section-row td + td {
        border-left: 1px solid #e3e8f2 !important;
    }

    #thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-section-head th {
        padding: 2px 0 0;
    }

    #thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-section-title {
        align-items: flex-start;
        padding: 7px 10px;
        font-size: 13px;
        text-align: left;
        letter-spacing: 0.02em;
    }

    /* Hàng sản phẩm dính đầu: ảnh nhỏ + tên 2 dòng để luôn biết cột nào là sản phẩm nào. */
    #thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-product-summary-row td {
        top: -12px;
        padding: 8px 6px;
    }

    #thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-product-summary {
        gap: 6px;
        justify-items: center;
        text-align: center;
    }

    #thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-product-image {
        width: 56px;
        max-width: 56px;
        height: 56px;
        object-fit: cover;
    }

    #thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-product-summary-title {
        display: -webkit-box;
        overflow: hidden;
        font-size: 12px;
        line-height: 1.3;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }

    #thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-cell-list {
        padding-left: 0;
        list-style: none;
    }

    #thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-variation-notes {
        font-size: 11px;
    }

    #thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-add-to-cart {
        width: 100%;
        min-height: 38px;
        margin: 0 !important;
        padding: 8px 4px !important;
        font-size: 11px !important;
        line-height: 1.25 !important;
        letter-spacing: 0 !important;
    }

    #thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-actions .button,
    #thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-table-actions .button {
        min-width: 0 !important;
        margin: 0 !important;
        padding: 0 14px !important;
        line-height: 40px !important;
        font-size: 12px !important;
    }

    #thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-actions,
    #thean-apfm-compare .thean-apfm-compare .tpc-compare-root .tpc-table-actions {
        gap: 10px;
    }
}

body.apfm-modal-open {
    overflow: hidden;
}

/* Nút VI/EN cố định góc trên (z-index tối đa) đè lên nút đóng của modal. */
body.apfm-modal-open .theanmarket-lang-switch {
    display: none !important;
}

@media (max-width: 767px) {
    .thean-apfm-modal {
        align-items: flex-end;
        padding: 0;
    }

    .thean-apfm-modal__panel {
        max-height: calc(100vh - 24px);
        max-height: calc(100dvh - 24px);
        border-radius: 12px 12px 0 0;
    }

    .thean-apfm-modal__title {
        font-size: 18px;
    }

    .thean-apfm-modal__body {
        padding: 12px 12px calc(16px + env(safe-area-inset-bottom, 0px));
    }
}

@media (prefers-reduced-motion: reduce) {
    .thean-apfm__item,
    .thean-apfm-pick {
        transition: none !important;
    }
}
