/* --- Style chung --- */
#vcpi-root { position: relative; z-index: 2147483647; }
:root{ --vcpi-brand: #0a74c0; --vcpi-brand-dark: #005a9c; }
.vcpi { position: fixed; right: 24px; bottom: 120px; font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; line-height: 1.4; }
@media (max-width:640px){ .vcpi { bottom: 96px; right: 16px; } }

/* SỬAĐỔI: Logic hiển thị panel */
.vcpi-panel{ 
    display: none; 
    width: min(720px, calc(100vw - 32px)); 
    background: #fff; 
    border: 1px solid #0002; 
    border-radius: 20px; 
    box-shadow: 0 20px 60px rgba(0,0,0,.18); 
    overflow: hidden; 
    transform: translateY(8px); 
    max-height: calc(100vh - 150px); 
    flex-direction: column; 
}

/* Khi popup mở rộng */
.vcpi.is-expanded .vcpi-panel{ 
    display: flex; 
    animation: vcpiSlide .18s ease-out; 
}

/* Khi popup thu gọn */
.vcpi.is-collapsed .vcpi-panel{ 
    display: none; 
}

/* Hiển thị toggle button */
.vcpi.is-expanded .vcpi-toggle{ 
    display: none; 
}

.vcpi.is-collapsed .vcpi-toggle{ 
    display: block; 
}

@keyframes vcpiSlide{ 
    from{ opacity:0; transform: translateY(20px);} 
    to{ opacity:1; transform: translateY(8px);} 
}

.vcpi-header{ 
    display:flex; 
    justify-content:space-between; 
    align-items:center; 
    padding:12px 20px; 
    color:#fff; 
    background: linear-gradient(135deg, #006494 0%, #0077be 100%); 
    flex-shrink: 0; 
}
.vcpi-header strong { font-size: 16px; }

.vcpi-minimize{ 
    background: transparent; 
    border: 0; 
    color: #fff; 
    font-size: 20px; 
    cursor: pointer; 
    padding: 0 5px; 
    line-height: 1;
}
.vcpi-minimize:hover {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.vcpi-form{ position: relative; display: flex; padding: 16px 20px; }
.vcpi-input{ flex:1; height: 48px; border:1px solid #ccc; border-radius: 24px; padding: 0 50px 0 20px; font-size: 16px; outline: none; transition: border-color .2s; }
.vcpi-input:focus { border-color: var(--vcpi-brand); }
.vcpi-submit{ position: absolute; right: 22px; top: 18px; width:44px; height:44px; border-radius:50%; border:0; cursor:pointer; background: var(--vcpi-brand) var(--vcpi-icon-url) no-repeat center / 60%; color:#fff; box-shadow: 0 4px 12px rgba(10,116,192,.3); transition: background-color .2s; }
.vcpi-submit:hover { background-color: var(--vcpi-brand-dark); }
.vcpi-body{ padding: 0 20px 20px 20px; overflow-y: auto; flex-grow: 1; }
.vcpi-status{ min-height: 80px; display: flex; justify-content: center; align-items: center; }

/* --- Giao diện chi tiết sản phẩm --- */
.vcpi-product-summary { display: grid; grid-template-columns: 80px 1fr; gap: 14px; align-items: start; padding-bottom: 14px; border-bottom: 1px solid #eee; margin-bottom: 14px; }
.vcpi-img { width:100%; height:80px; object-fit: cover; border-radius:12px; border:1px solid #0001; }
.vcpi-title{ margin: 0 0 4px; font-size: 15px; font-weight: 600; line-height: 1.3; }
.vcpi-price{ font-weight: 700; color: var(--vcpi-brand); margin-bottom: 4px; }
.vcpi-exchange-rate { font-size: 12px; color: #666; background: #f0f6fc; padding: 2px 6px; border-radius: 4px; display: inline-block; }
.vcpi-variants-title { font-weight: 600; margin-bottom: 10px; font-size: 15px; }
.vcpi-sku-list { max-height: 300px; overflow-y: auto; padding-right: 5px; }
.vcpi-sku-item { display: grid; grid-template-columns: 50px 1fr 120px; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid #f0f0f0; }
.vcpi-sku-item:last-child { border-bottom: none; }
.vcpi-sku-img { width: 50px; height: 50px; object-fit: cover; border-radius: 6px; }
.vcpi-quantity-control { display: flex; align-items: center; justify-content: flex-end; }
.vcpi-quantity-btn { width: 32px; height: 32px; border: 1px solid #ccc; background: #f7f7f7; cursor: pointer; font-size: 18px; line-height: 1; }
.vcpi-quantity-input { width: 45px; height: 32px; text-align: center; border: 1px solid #ccc; border-left: none; border-right: none; padding: 0 2px; -moz-appearance: textfield; }
.vcpi-quantity-input::-webkit-outer-spin-button, .vcpi-quantity-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.vcpi-actions{ display:flex; gap:10px; margin-top:16px; border-top: 1px solid #eee; padding-top: 16px; }
.vcpi-add-to-cart{ background:var(--vcpi-brand); color:#fff; border:0; border-radius: 20px; padding:10px 16px; cursor:pointer; flex: 1; text-align: center; font-weight: bold; font-size: 15px; }
.vcpi-link { color: #555; font-size: 14px; text-decoration: none; align-self: center; }

/* --- Giao diện danh sách kết quả tìm kiếm (DẠNG LƯỚI) --- */
.vcpi-search-title { font-size: 16px; font-weight: 600; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid #eee; }
.vcpi-search-grid {
    display: grid;
    /* Responsive: 4 cột trên màn lớn, 3 trên tablet, 2 trên mobile */
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
    padding: 5px;
}
.vcpi-product-card {
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: #fff;
    transition: transform .2s ease, box-shadow .2s ease;
    cursor: pointer;
}
.vcpi-product-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0,0,0,.08);
}
.vcpi-card-img-wrapper {
    width: 100%;
    padding-top: 100%; /* Giữ tỷ lệ 1:1 cho ảnh */
    position: relative;
    background-color: #f5f5f5;
}
.vcpi-card-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.vcpi-card-body {
    padding: 12px;
    text-align: left;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}
.vcpi-card-title {
    font-size: 14px;
    line-height: 1.4;
    color: #333;
    margin: 0 0 8px;
    height: 3.9em; /* Giới hạn 3 dòng */
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-box-orient: vertical;
    display: -webkit-box;
    -webkit-line-clamp: 3;
}
.vcpi-card-footer {
    margin-top: auto; /* Đẩy footer xuống dưới */
    padding-top: 8px;
    border-top: 1px solid #f0f0f0;
}
.vcpi-card-price {
    font-size: 16px;
    font-weight: 700;
    color: #d9534f;
    margin-bottom: 4px;
}
.vcpi-card-sales {
    font-size: 12px;
    color: #777;
}

/* --- Các style cho bộ lọc --- */
.vcpi-filter-toggle-btn { display: block; width: calc(100% - 40px); margin: 0 auto 15px; padding: 10px 15px; background-color: #f7f7f7; border: 1px solid #ddd; border-radius: 8px; text-align: center; font-size: 15px; font-weight: 600; cursor: pointer; color: #333; transition: all .2s; }
.vcpi-filter-toggle-btn:hover { background-color: #e9e9e9; }
.vcpi-filter-toggle-btn.is-active { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.vcpi-arrow-down { display: inline-block; border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 4px solid #333; margin-left: 8px; transition: transform .3s; }
.vcpi-filter-toggle-btn.is-active .vcpi-arrow-down { transform: rotate(180deg); }
.vcpi-filter-options-container { padding: 0 20px 15px; }
.vcpi-filter-panel { border: 1px solid #ddd; border-top: none; padding: 15px; border-bottom-left-radius: 8px; border-bottom-right-radius: 8px; }
.vcpi-filter-options-container.is-hidden { display: none; }
.vcpi-filter-panel h4 { font-size: 15px; margin: 15px 0 8px 0; font-weight: 600; border-bottom: 1px solid #eee; padding-bottom: 5px; }
.vcpi-filter-panel h4:first-child { margin-top: 0; }
.vcpi-radio-group label { display: inline-block; margin-right: 15px; font-size: 14px; cursor: pointer; }
.vcpi-select-wrapper, .vcpi-price-range { display: flex; gap: 10px; align-items: center; }
.vcpi-select, .vcpi-price-range input { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; }
.vcpi-filter-actions { margin-top: 20px; display: flex; gap: 10px; }
.vcpi-button-primary, .vcpi-button-secondary { padding: 10px 15px; border: none; border-radius: 5px; font-size: 15px; cursor: pointer; flex: 1; }
.vcpi-button-primary { background-color: var(--vcpi-brand); color: white; }
.vcpi-button-secondary { background-color: #ccc; color: #333; }

/* --- Các style linh tinh khác --- */
.vcpi-toggle{ 
    position: relative; 
    width: 60px; 
    height: 60px; 
    border-radius: 50%; 
    border: 0; 
    cursor: pointer; 
    background: var(--vcpi-brand) var(--vcpi-icon-url) no-repeat center / 50%; 
    box-shadow: 0 8px 22px rgba(10,116,192,.35); 
    transition: transform .2s; 
}
.vcpi-toggle:hover{ transform: scale(1.05); }
.vcpi-loader { width: 48px; height: 48px; border: 5px solid #FFF; border-bottom-color: var(--vcpi-brand); border-radius: 50%; display: inline-block; box-sizing: border-box; animation: rotation 1s linear infinite; }
@keyframes rotation { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* ========================================= */
/* BỔ SUNG CSS CHO THUỘC TÍNH SẢN PHẨM */
/* ========================================= */

.vcpi-card-img-wrapper {
    position: relative;
}

.vcpi-card-platform-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: bold;
}

.vcpi-card-meta-tags {
    margin-bottom: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.vcpi-meta-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    border: 1px solid currentColor;
}

.vcpi-meta-tag.personal { /* Thương nhân */
    color: #28a745; 
}

.vcpi-meta-tag.factory { /* Nhà máy */
    color: #17a2b8;
}

.vcpi-meta-tag.retention { /* Tỷ lệ mua lại */
    color: #fd7e14;
}

.vcpi-card-actions {
    margin-top: 12px;
}

.vcpi-product-link-btn {
    display: block;
    width: 100%;
    text-align: center;
    padding: 8px;
    background-color: #f0f0f0;
    color: #333;
    text-decoration: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    transition: background-color .2s;
}

.vcpi-product-link-btn:hover {
    background-color: #e0e0e0;
    color: #000;
}

/* ========================================= */
/* BỔ SUNG CSS CHO TÊN BIẾN THỂ */
/* ========================================= */

.vcpi-sku-details {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.vcpi-sku-name {
    font-weight: 600;
    color: #333;
    font-size: 14px;
    margin-bottom: 4px;
    line-height: 1.3;
}

.vcpi-sku-meta {
    font-size: 13px;
    color: #666;
}

.vcpi-sku-meta .vcpi-sku-price {
    color: #D9534F;
    font-weight: bold;
    margin-right: 8px;
}

.vcpi-sku-meta .vcpi-sku-price-vnd {
    margin-right: 8px;
}