/* Product Images Slider */
.pm-product-images-wrapper {
    width: 100%;
}

.pm-product-main-slider {
    width: 100%;
    overflow: hidden;
}

.pm-product-main-slider .swiper-wrapper,
.pm-product-thumb-slider {
    width: 100%;
    overflow: hidden;
}

.pm-product-main-slider .swiper-slide {
    width: 100%;
    flex-shrink: 0;
    height: auto;
}

.pm-product-main-slider .swiper-slide a {
    display: block;
    width: 100%;
}

.pm-product-main-slider .swiper-slide img {
    width: 100%;
    height: auto;
    display: block;
}

.pm-product-main-slider .swiper-wrapper,
.pm-product-thumb-slider .swiper-wrapper {
    display: flex;
}

/* Fallback for when Swiper is not initialized */
.pm-product-thumb-slider:not(.swiper-initialized) .swiper-wrapper {
    display: flex;
    flex-wrap: nowrap;
    overflow: hidden;
}

.pm-product-thumb-slider:not(.swiper-initialized) .swiper-slide {
    width: 25%;
    flex: 0 0 25%;
    max-width: 25%;
    margin-right: 0;
    box-sizing: border-box;
}

.pm-product-thumb-slider .swiper-slide {
    opacity: 0.5;
    transition: opacity 0.3s;
    height: auto;
    box-sizing: border-box;
    flex-shrink: 0;
}

.pm-product-thumb-slider .swiper-slide-thumb-active {
    opacity: 1;
}

.pm-product-thumb-slider img {
    width: 100%;
    height: auto;
    display: block;
    transition: opacity 0.3s;
    object-fit: cover;
}

.pm-thumb-active {
    opacity: 1 !important;
}

.pm-thumb-active img {
    opacity: 1;
}

/* Discount Badge */
.discount-badge {
    /* Optional: Add default styles for discount badge if needed */
}

/* Breadcrumb */
.pm-breadcrumb {
    /* Optional: Add default styles for breadcrumb if needed */
}

/* ===== Terms List Widget – Đường nối phân cấp ===== */
.pm-terms-list .pm-term-children {
    border-left: 1px solid #e5e7eb;
    margin-left: 12px;
}

/* ===== Terms List Widget – Đường ngăn cách giữa các cate top-level ===== */
.pm-terms-list .pm-term-children + .pm-term-item.pm-depth-0,
.pm-terms-list .pm-all-products-link + .pm-term-item.pm-depth-0,
.pm-terms-list .pm-term-item.pm-depth-0 + .pm-term-item.pm-depth-0 {
    border-top: 1px solid #e5e7eb;
    padding-top: 12px;
    margin-top: 12px;
}

/* ===== PM Categories Grid Widget ===== */
.pm-cat-grid__section {
    width: 100%;
}

.pm-cat-grid__title {
    border-bottom: 2px solid #dc2626;
    padding-bottom: 8px;
    margin: 0 0 20px;
}

.pm-cat-grid__title a {
    text-decoration: none;
    color: inherit;
    transition: color 0.2s ease;
}

.pm-cat-grid__items {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 16px;
}

.pm-cat-grid__item {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    overflow: hidden;
    transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.pm-cat-grid__image {
    width: 100%;
    aspect-ratio: 1 / 1;
    background-color: #4f5b93;
    overflow: hidden;
    display: block;
}

.pm-cat-grid__image img,
.pm-cat-grid__image .pm-cat-grid__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.pm-cat-grid__name {
    padding: 8px 4px;
    font-weight: 500;
    line-height: 1.3;
}

@media (max-width: 1024px) {
    .pm-cat-grid__items { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
    .pm-cat-grid__items { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ===== PM Specs Table widget ===== */
.pm-specs-table {
    width: 100%;
}

.pm-specs-table__row {
    display: flex;
    align-items: center;
    gap: 16px;
    border-bottom: 1px solid #e2e8f0;
    padding: 14px 0;
}

.pm-specs-table__row:last-child {
    border-bottom: none;
}

.pm-specs-table__name {
    flex: 0 0 40%;
    color: #64748b;
}

.pm-specs-table__value {
    flex: 1;
    color: #1e3a8a;
    text-align: right;
    font-weight: 500;
}

/* ===== PM Document Buttons widget ===== */
.pm-doc-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pm-doc-btn,
button.pm-doc-btn,
a.pm-doc-btn {
    display: flex;
    width: 100%;
    box-sizing: border-box;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    margin: 0;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    color: #10b981;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    font-size: inherit;
    font-family: inherit;
    line-height: 1.4;
    appearance: none;
    -webkit-appearance: none;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.pm-doc-btn:hover {
    background: #f8fafc;
}

.pm-doc-btn__icon {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.pm-doc-btn__label {
    flex: 1 1 auto;
    min-width: 0;
    text-align: left;
}

.pm-doc-btn__arrow {
    flex: 0 0 auto;
    font-size: 0.9em;
    opacity: 0.7;
}

/* Modal */
.pm-doc-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    z-index: 99999;
    padding: 20px;
    align-items: center;
    justify-content: center;
}

.pm-doc-modal.is-open {
    display: flex;
}

.pm-doc-modal__inner {
    background: #fff;
    border-radius: 8px;
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pm-doc-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 2px solid #1e3a8a;
}

.pm-doc-modal__title {
    margin: 0;
    color: #1e3a8a;
    font-size: 20px;
}

.pm-doc-modal__close {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 24px;
    color: #64748b;
    line-height: 1;
}

.pm-doc-modal__body {
    flex: 1;
    overflow: auto;
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pm-doc-modal__body img {
    max-width: 100%;
    height: auto;
}

.pm-doc-modal__body iframe {
    width: 100%;
    height: 70vh;
    border: none;
}

.pm-doc-modal__footer {
    padding: 16px 24px;
    display: flex;
    justify-content: flex-end;
    border-top: 1px solid #e2e8f0;
}

.pm-doc-modal__download {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    background: #1e3a8a;
    color: #fff;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.pm-doc-modal__download:hover {
    background: #1e40af;
    color: #fff;
}

/* ===== PM Data Sheets widget ===== */
.pm-datasheets {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 24px;
}

.pm-datasheets__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: inherit;
    transition: opacity 0.2s ease, color 0.2s ease;
}

.pm-datasheets__icon {
    width: 100px;
    height: auto;
    transition: opacity 0.2s ease;
}

.pm-datasheets__label {
    font-size: 14px;
    line-height: 1.3;
    text-align: center;
}

@media (max-width: 1024px) {
    .pm-datasheets { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
    .pm-datasheets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ===== Auto-hide theo marker class trên <body> (single product) =====
   Cách dùng: user add các class `pm-hide-if-no-*` vào wrapper Elementor (button/section/container).
   Plugin tự thêm class `pm-has-*` vào <body> khi sản phẩm có data tương ứng.
   Body không có marker → wrapper bị ẩn. Hoạt động mọi browser, không cần `:has()`. */
body:not(.pm-has-drawing) .pm-hide-if-no-drawing,
body:not(.pm-has-catalogue) .pm-hide-if-no-catalogue,
body:not(.pm-has-export-catalogue) .pm-hide-if-no-export-catalogue,
body:not(.pm-has-datasheets) .pm-hide-if-no-datasheets,
body:not(.pm-has-contacts) .pm-hide-if-no-contacts,
body:not(.pm-has-related) .pm-hide-if-no-related {
    display: none !important;
}

/* ===== Auto-hide wrapper khi widget Related/Recently không có data =====
   Cách dùng: user thêm class `pm-hide-if-empty` vào Elementor wrapper (Section/Container).
   Plugin tự ẩn wrapper nếu KHÔNG có widget nào bên trong có data marker:
     - `.pm-related-grid--has-data` (Related Products render thành công)
     - `.pm-recently-viewed.is-loaded` (Recently Viewed AJAX load thành công)
   Yêu cầu trình duyệt hỗ trợ CSS `:has()` (Chrome/Edge/Safari/Firefox đời mới đều OK). */
.pm-hide-if-empty:not(:has(.pm-related-grid--has-data)):not(:has(.pm-recently-viewed.is-loaded)) {
    display: none !important;
}

/* ===== PM Category Pills widget ===== */
.pm-cat-pills {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 16px;
}

.pm-cat-pills__item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.pm-cat-pills__item:hover {
    border-color: #cbd5e1;
}

.pm-cat-pills__image {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pm-cat-pills__image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.pm-cat-pills__name {
    flex: 1;
    min-width: 0;
    font-weight: 600;
    color: #1f2937;
    line-height: 1.3;
    /* Cho text dài tự xuống dòng, không tràn */
    word-break: break-word;
}

.pm-cat-pills__arrow {
    flex-shrink: 0;
    color: #94a3b8;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, color 0.2s ease;
}

.pm-cat-pills__arrow svg {
    display: block;
}

@media (max-width: 1024px) {
    .pm-cat-pills { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
    .pm-cat-pills { grid-template-columns: repeat(1, minmax(0, 1fr)); }
}

/* ===== PM Carousel — fallback grid mode khi slides ≤ số cột (tránh Swiper bug) ===== */
.pm-carousel--as-grid .swiper-wrapper {
    display: grid !important;
    grid-template-columns: repeat(var(--pm-cols-mobile, 2), minmax(0, 1fr));
    gap: var(--pm-gap, 20px);
    transform: none !important;
}

@media (min-width: 768px) {
    .pm-carousel--as-grid .swiper-wrapper {
        grid-template-columns: repeat(var(--pm-cols-tablet, 3), minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    .pm-carousel--as-grid .swiper-wrapper {
        grid-template-columns: repeat(var(--pm-cols-desktop, 4), minmax(0, 1fr));
    }
}

.pm-carousel--as-grid .swiper-slide {
    width: auto !important;
    height: auto;
    margin: 0 !important;
    transform: none !important;
}

/* ===== PM Carousel — chung cho Recently Viewed + Related Products ===== */

/* Reset display của outer wrapper khi ở carousel mode để Swiper tính slide width đúng.
   Quan trọng: .pm-related-grid mặc định có display: grid → cần override. */
.pm-related-grid.pm-related-grid--carousel {
    display: block;
    grid-template-columns: none;
    gap: 0;
}

.pm-recently-viewed--carousel,
.pm-related-grid--carousel {
    position: relative;
}

.pm-recently-viewed__carousel-wrap {
    position: relative;
    overflow: hidden;
}

/* Swiper container cần overflow hidden để slides bên ngoài viewport bị clip */
.pm-related-grid--carousel .swiper,
.pm-recently-viewed--carousel .swiper {
    overflow: hidden;
    width: 100%;
}

/* Slide: width do Swiper tính inline; chỉ ép flex-shrink:0 để không bị co vô lý */
.pm-carousel .swiper-slide,
.pm-recently-viewed__swiper .swiper-slide,
.pm-related-grid--carousel .swiper-slide {
    flex-shrink: 0;
    height: auto;
    box-sizing: border-box;
}

/* Nav buttons */
.pm-recently-viewed--carousel .swiper-button-prev,
.pm-recently-viewed--carousel .swiper-button-next,
.pm-related-grid--carousel .swiper-button-prev,
.pm-related-grid--carousel .swiper-button-next {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #fff;
    color: #1e3a8a;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    z-index: 10;
}

.pm-recently-viewed--carousel .swiper-button-prev::after,
.pm-recently-viewed--carousel .swiper-button-next::after,
.pm-related-grid--carousel .swiper-button-prev::after,
.pm-related-grid--carousel .swiper-button-next::after {
    font-size: 16px;
    font-weight: 700;
}

.pm-recently-viewed--carousel .swiper-button-disabled,
.pm-related-grid--carousel .swiper-button-disabled {
    opacity: 0.35;
}

/* Khi watchOverflow disable swiper (số slide ≤ slidesPerView) → ẩn arrow */
.swiper-button-lock {
    display: none !important;
}

/* Pagination dots */
.pm-recently-viewed--carousel .swiper-pagination,
.pm-related-grid--carousel .swiper-pagination {
    position: relative;
    margin-top: 16px;
    text-align: center;
}

/* ===== PM Recently Viewed widget ===== */
.pm-recently-viewed__title {
    margin: 0 0 20px;
}

.pm-recently-viewed__grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 20px;
}

.pm-recently-viewed__item {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    overflow: hidden;
    transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.pm-recently-viewed__image {
    width: 100%;
    aspect-ratio: 1 / 1;
    background-color: #e5e7eb;
    overflow: hidden;
    display: block;
}

.pm-recently-viewed__image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.pm-recently-viewed__name {
    padding: 10px;
    font-weight: 500;
    line-height: 1.3;
}

@media (max-width: 1024px) {
    .pm-recently-viewed__grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
    .pm-recently-viewed__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ===== PM Related Products widget ===== */
.pm-related-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 20px;
}

.pm-related-grid__item {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    overflow: hidden;
    transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.pm-related-grid__image {
    width: 100%;
    aspect-ratio: 1 / 1;
    background-color: #e5e7eb;
    overflow: hidden;
    display: block;
}

.pm-related-grid__image img,
.pm-related-grid__image .pm-related-grid__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.pm-related-grid__name {
    padding: 10px;
    font-weight: 500;
    line-height: 1.3;
}

@media (max-width: 1024px) {
    .pm-related-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
    .pm-related-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ===== PM Contact List widget ===== */
.pm-contact-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.pm-contact-list__item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    color: inherit;
    text-decoration: none;
}

.pm-contact-list__icon {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #2563eb;
    color: #fff;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.pm-contact-list__icon--zalo { background: #0068ff; }
.pm-contact-list__icon--whatsapp { background: #25d366; }
.pm-contact-list__icon--telegram { background: #0088cc; }
.pm-contact-list__icon--phone { background: #2563eb; }

/* Khi user upload icon riêng → bỏ background mặc định, để image hiện đúng */
.pm-contact-list__icon--custom {
    background: transparent;
    overflow: hidden;
}

.pm-contact-list__icon--custom img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.pm-contact-list__label {
    flex: 0 0 auto;
}

.pm-contact-list__phone {
    flex: 1;
}

/* ===== Image Protection ===== */
img {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    pointer-events: auto;
}