/* =====================================================================
 * Defensive reset - many WordPress themes apply global rules to bare
 * elements (button, input, select, ul/li, etc.) with equal or higher
 * CSS specificity than a single plugin class, and/or their stylesheet
 * loads after ours, so "last one wins" hands the fight to the theme.
 * Everything below is scoped under the two IDs the app root and popup
 * already have (#sbuy-pcb-app / #sbuy-pcb-popup) - an ID beats a plain
 * class/element selector in almost every real-world theme, so this
 * keeps the widget's own layout intact regardless of what the active
 * theme does to buttons, inputs, lists, headings, etc. elsewhere.
 * ===================================================================== */
#sbuy-pcb-app,
#sbuy-pcb-app *,
#sbuy-pcb-app *::before,
#sbuy-pcb-app *::after,
#sbuy-pcb-popup,
#sbuy-pcb-popup *,
#sbuy-pcb-popup *::before,
#sbuy-pcb-popup *::after {
    box-sizing: border-box !important;
}

#sbuy-pcb-app [hidden],
#sbuy-pcb-popup [hidden] {
    display: none !important;
}

#sbuy-pcb-app button,
#sbuy-pcb-popup button {
    -webkit-appearance: none !important;
    appearance: none !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: auto !important;
    max-width: none !important;
    min-width: 0 !important;
    height: auto !important;
    margin: 0 !important;
    font-family: inherit !important;
    line-height: 1.3 !important;
    text-transform: none !important;
    letter-spacing: normal !important;
    white-space: nowrap !important;
    word-break: normal !important;
    overflow-wrap: normal !important;
    background-image: none !important;
    box-shadow: none;
}

#sbuy-pcb-app ul,
#sbuy-pcb-popup ul {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

#sbuy-pcb-app input,
#sbuy-pcb-popup input {
    max-width: none !important;
    height: auto !important;
    margin: 0 !important;
}

.sbuy-pcb-app {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 20px;
    max-width: 1100px;
    margin: 0 auto;
    align-items: start;
}

.sbuy-pcb-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
    padding: 12px 20px;
    background: linear-gradient(145deg, #ffffff, #f8fafc);
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
    border: 1px solid rgba(226, 232, 240, 0.8);
}

.sbuy-pcb-toolbar-left {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.sbuy-pcb-toolbar-right {
    display: flex;
    flex-wrap: wrap;
}

.sbuy-pcb-reset {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: linear-gradient(135deg, #ffffff 0%, #f9f9f9 100%);
    border: 1px solid #e0e5ea;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: #4a5568;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02), 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sbuy-pcb-reset:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.05), 0 4px 8px rgba(34, 113, 177, 0.1);
    border-color: #2271b1;
    color: #2271b1;
}

.sbuy-pcb-reset:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* ===== Slot rows ===== */
.sbuy-pcb-slots {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sbuy-pcb-slots-divider {
    margin: 8px 0 -2px;
    padding: 4px 4px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #888;
}

.sbuy-pcb-slot {
    display: grid;
    grid-template-columns: 110px 90px 1fr 180px;
    align-items: center;
    gap: 16px;
    background: #fff;
    border: 1px solid #eaf0f5;
    border-radius: 6px;
    padding: 16px 20px;
}

.sbuy-pcb-slot.is-filled {
    border-color: #d1dbe6;
}

/* ===== Trạng thái khoá theo chuỗi phụ thuộc (CPU -> Mainboard -> RAM) ===== */
.sbuy-pcb-slot.is-locked {
    background: #fafbfc;
    border-style: dashed;
    border-color: #d8dee6;
}

.sbuy-pcb-slot.is-locked .sbuy-pcb-slot-thumb {
    opacity: 0.5;
}

.sbuy-pcb-slot-lockmsg {
    font-size: 12px;
    color: #999;
    font-style: italic;
    margin-top: 4px;
}

.sbuy-pcb-choose-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    opacity: 0.8;
}

.sbuy-pcb-choose-btn:disabled:hover {
    background: #cbd5e1;
}

.sbuy-pcb-qty-plus:disabled,
.sbuy-pcb-qty-minus:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Ghi chú "đã tự động lọc theo Socket/Loại RAM..." trong popup, thay cho facet
   Socket/Loại RAM có thể tự chọn khi slot đang bị khoá cứng theo bước trước. */
.sbuy-pcb-filter-lock-note {
    font-size: 12px;
    color: #2874a6;
    background: #eaf4fb;
    border: 1px solid #cfe6f5;
    border-radius: 4px;
    padding: 8px 10px;
    margin-bottom: 12px;
    line-height: 1.4;
}

.sbuy-pcb-slot-label {
    font-weight: 600;
    color: #222;
    font-size: 14px;
}

.sbuy-pcb-slot-thumb {
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f7f7f7;
    border-radius: 6px;
    overflow: hidden;
}

.sbuy-pcb-slot-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.sbuy-pcb-slot-info {
    min-width: 0;
}

.sbuy-pcb-slot-name {
    font-size: 14px;
    color: #888;
    line-height: 1.4;
}

.sbuy-pcb-slot.is-filled .sbuy-pcb-slot-name {
    color: #222;
    font-weight: 500;
}

.sbuy-pcb-slot-price {
    font-size: 14px;
    font-weight: 600;
    color: #d63638;
    margin-top: 4px;
}

/* Giá gốc (trước sale) - gạch ngang, xám, nhỏ hơn giá sale.
   Giá sale (hoặc giá thường nếu không sale) - giữ nguyên màu đỏ hiện có. */
.sbuy-pcb-price-regular {
    text-decoration: line-through;
    color: #999;
    font-weight: 400;
    font-size: 0.85em;
    margin-right: 6px;
}

.sbuy-pcb-price-sale {
    color: #d63638;
}

.sbuy-pcb-slot-warning {
    font-size: 12px;
    color: #d63638;
    margin-top: 4px;
}

.sbuy-pcb-slot-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
}

.sbuy-pcb-slot-qty {
    display: flex;
    align-items: stretch;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}

.sbuy-pcb-qty-minus,
.sbuy-pcb-qty-plus {
    width: 32px;
    flex: 0 0 32px;
    background: #f8fafc;
    border: none;
    color: #333;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    height: 100%;
}

.sbuy-pcb-qty-minus:hover,
.sbuy-pcb-qty-plus:hover {
    background: #ececec;
}

.sbuy-pcb-qty-input {
    width: 0;
    flex: 1 1 auto;
    min-width: 0;
    border: none !important;
    border-left: 1px solid #e2e8f0 !important;
    border-right: 1px solid #e2e8f0 !important;
    text-align: center;
    font-size: 14px;
    padding: 0 !important;
    margin: 0 !important;
    height: 100% !important;
    box-shadow: none !important;
    background: transparent !important;
    -moz-appearance: textfield;
}

.sbuy-pcb-qty-input::-webkit-outer-spin-button,
.sbuy-pcb-qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.sbuy-pcb-choose-btn {
    padding: 8px 16px;
    background: #2874a6;
    border: none;
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    text-transform: uppercase;
    white-space: nowrap;
    text-align: center;
    height: 36px;
}

.sbuy-pcb-choose-btn:hover {
    background: #135e96;
}

.sbuy-pcb-remove-btn {
    padding: 8px 16px;
    background: transparent;
    border: 1px solid #e74c3c;
    border-radius: 4px;
    color: #e74c3c;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    text-align: center;
    height: 36px;
}

.sbuy-pcb-remove-btn:hover {
    background: #d63638;
    color: #fff;
}

/* ===== Sidebar ===== */
.sbuy-pcb-sidebar {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    padding: 24px 20px;
    position: sticky;
    top: 20px;
}

.sbuy-pcb-summary-empty {
    color: #888;
    font-size: 13px;
    text-align: center;
    margin-bottom: 16px;
    line-height: 1.5;
}

.sbuy-pcb-summary-total {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid #eee;
}

.sbuy-pcb-summary-total-label {
    font-size: 14px;
    color: #555;
}

.sbuy-pcb-summary-total-prices {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.sbuy-pcb-summary-total-regular-value {
    font-size: 14px;
    font-weight: 400;
    color: #999;
    text-decoration: line-through;
}

.sbuy-pcb-summary-total-value {
    font-size: 20px;
    font-weight: 700;
    color: #d63638;
}

.sbuy-pcb-addtocart-btn {
    width: 100%;
    padding: 12px;
    background: #2271b1;
    border: none;
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

.sbuy-pcb-addtocart-btn:hover {
    background: #135e96;
}

.sbuy-pcb-addtocart-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.sbuy-pcb-summary-list {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px dashed #e2e2e2;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sbuy-pcb-summary-item {
    font-size: 13px;
    line-height: 1.4;
    padding-bottom: 8px;
    border-bottom: 1px solid #f5f5f5;
}

.sbuy-pcb-summary-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.sbuy-pcb-summary-item-slot {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: #888;
    margin-bottom: 2px;
}

.sbuy-pcb-summary-item-name {
    color: #333;
    margin-bottom: 8px;
}

.sbuy-pcb-summary-item-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.sbuy-pcb-summary-qty {
    width: 80px;
    flex-shrink: 0;
    height: 28px;
    border-color: #ddd;
}

.sbuy-pcb-summary-qty .sbuy-pcb-qty-minus,
.sbuy-pcb-summary-qty .sbuy-pcb-qty-plus {
    width: 24px;
    flex: 0 0 24px;
    font-size: 14px;
}

.sbuy-pcb-summary-qty .sbuy-pcb-qty-input {
    padding: 0;
    font-size: 12px;
}

.sbuy-pcb-summary-item-price {
    font-weight: 600;
    color: #d63638;
}

.sbuy-pcb-save-btn,
.sbuy-pcb-load-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: linear-gradient(135deg, #ffffff 0%, #f9f9f9 100%);
    border: 1px solid #e0e5ea;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: #4a5568;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02), 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sbuy-pcb-save-btn:hover,
.sbuy-pcb-load-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.05), 0 4px 8px rgba(34, 113, 177, 0.1);
    border-color: #2271b1;
    color: #2271b1;
}

.sbuy-pcb-save-btn:active,
.sbuy-pcb-load-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.sbuy-pcb-save-btn:disabled,
.sbuy-pcb-load-btn:disabled {
    background: #f6f7f7;
    color: #a7aaad;
    border-color: #dcdcde;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ===== Popup chọn sản phẩm ===== */
.sbuy-pcb-popup {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sbuy-pcb-popup-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.sbuy-pcb-popup-box {
    position: relative;
    background: #fff;
    border-radius: 8px;
    width: min(1280px, 95vw);
    max-height: 85vh;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden;
}

.sbuy-pcb-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
}

.sbuy-pcb-popup-title {
    font-size: 16px;
    font-weight: 600;
    color: #222;
}

.sbuy-pcb-popup-close {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: #888;
}

.sbuy-pcb-popup-close:hover {
    color: #d63638;
}

/* ===== Popup Grid Layout ===== */
.sbuy-pcb-popup-layout {
    display: flex !important;
    flex-direction: row !important;
    flex: 1;
    overflow: hidden;
}

.sbuy-pcb-popup-sidebar {
    width: 240px !important;
    flex: 0 0 240px !important;
    background: #fafbfc;
    border-right: 1px solid #eee;
    padding: 20px;
    overflow-y: auto;
}

.sbuy-pcb-popup-main {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden;
    background: #f0f2f5;
}

.sbuy-pcb-popup-topbar {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 12px 20px;
    background: #fff;
    border-bottom: 1px solid #eee;
    flex-wrap: wrap !important;
    row-gap: 12px;
    column-gap: 16px;
}

.sbuy-pcb-popup-search {
    flex: 1 1 220px !important;
    max-width: 400px;
    min-width: 160px;
}

.sbuy-pcb-popup-search-input {
    display: block !important;
    width: 100% !important;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.sbuy-pcb-popup-sorting {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    flex-wrap: wrap !important;
    gap: 10px 12px;
    flex: 1 1 auto !important;
    justify-content: flex-end;
}

.sbuy-pcb-sort-label {
    flex: 0 0 auto !important;
    font-size: 14px;
    color: #333;
    font-weight: 600;
    white-space: nowrap !important;
}

.sbuy-pcb-sort-group {
    display: flex !important;
    flex-direction: row !important;
    flex: 0 0 auto !important;
    gap: 8px;
    flex-wrap: wrap !important;
}

.sbuy-pcb-sort-btn {
    flex: 0 0 auto !important;
    padding: 6px 12px !important;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px !important;
    color: #555;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap !important;
    word-break: keep-all !important;
    min-width: max-content !important;
}

.sbuy-pcb-sort-btn:hover {
    border-color: #2271b1;
    color: #2271b1;
}

.sbuy-pcb-sort-btn.active {
    border-color: #2271b1;
    color: #2271b1;
    font-weight: 600;
}

/* ===== Filter Sidebar ===== */
.sbuy-pcb-filter-group {
    margin-bottom: 24px;
}

.sbuy-pcb-filter-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 12px;
    color: #222;
}

.sbuy-pcb-filter-items {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px;
}

.sbuy-pcb-filter-checkbox {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 8px;
    font-size: 13.5px;
    color: #444;
    cursor: pointer;
}

.sbuy-pcb-filter-price-inputs {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 8px;
}

.sbuy-pcb-filter-minprice,
.sbuy-pcb-filter-maxprice {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    -moz-appearance: textfield;
}

.sbuy-pcb-filter-minprice::-webkit-outer-spin-button,
.sbuy-pcb-filter-minprice::-webkit-inner-spin-button,
.sbuy-pcb-filter-maxprice::-webkit-outer-spin-button,
.sbuy-pcb-filter-maxprice::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.sbuy-pcb-popup-list {
    overflow-y: auto;
    padding: 20px;
    flex: 1;
}

.sbuy-pcb-popup-loading,
.sbuy-pcb-popup-empty {
    padding: 40px;
    text-align: center;
    color: #888;
    font-size: 15px;
}

/* ===== Product Grid & Cards ===== */
.sbuy-pcb-popup-grid {
    display: grid;
    /* auto-fit (chứ không phải auto-fill): khi danh mục chỉ có ít sản phẩm (vd Power
       Supply chỉ có 2), các cột trống sẽ co về 0 thay vì chiếm chỗ vô hình, giúp card
       thật sự giãn to lấp đầy khung thay vì bị dồn nhỏ về bên trái với khoảng trắng
       thừa bên phải. */
    grid-template-columns: repeat(auto-fit, minmax(190px, 260px));
    gap: 16px;
}

.sbuy-pcb-popup-card {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.sbuy-pcb-popup-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.sbuy-pcb-popup-card.is-disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sbuy-pcb-popup-card-thumb {
    width: 100%;
    aspect-ratio: 1;
    padding: 16px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sbuy-pcb-popup-card-thumb img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.sbuy-pcb-popup-card-content {
    padding: 12px 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.sbuy-pcb-popup-card-name {
    font-size: 13.5px;
    line-height: 1.4;
    color: #333;
    margin-bottom: 8px;
    flex: 1;
}

.sbuy-pcb-popup-card-price {
    font-size: 15px;
    font-weight: 700;
    color: #d63638;
    margin-bottom: 4px;
}

.sbuy-pcb-popup-card-meta {
    font-size: 12px;
    color: #666;
    background: #f5f5f5;
    padding: 4px 8px;
    border-radius: 4px;
    display: inline-block;
    align-self: flex-start;
}

.sbuy-pcb-popup-card-action {
    padding: 0 16px 16px;
}

.sbuy-pcb-popup-select-btn {
    width: 100%;
    padding: 8px;
    background: #fff;
    border: 1px solid #2271b1;
    border-radius: 4px;
    color: #2271b1;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.sbuy-pcb-popup-card:hover .sbuy-pcb-popup-select-btn {
    background: #2271b1;
    color: #fff;
}

.sbuy-pcb-popup-card.is-disabled .sbuy-pcb-popup-select-btn {
    border-color: #ccc;
    color: #999;
    background: #f9f9f9;
    cursor: not-allowed;
}

/* ===== AI Advisor: nút chat nổi ===== */
.sbuy-pcb-ai-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 99990;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    background: #2271b1;
    border: none;
    border-radius: 999px;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.sbuy-pcb-ai-fab:hover {
    background: #135e96;
}

.sbuy-pcb-ai-fab-label {
    white-space: nowrap;
}

/* ===== AI Advisor: panel chat ===== */
.sbuy-pcb-ai-panel {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 99991;
    width: min(380px, 92vw);
    height: min(520px, 75vh);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sbuy-pcb-ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: #2271b1;
    color: #fff;
    font-weight: 600;
    font-size: 14px;
}

.sbuy-pcb-ai-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.sbuy-pcb-ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sbuy-pcb-ai-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
}

.sbuy-pcb-ai-msg-bot {
    align-self: flex-start;
    background: #f1f4f7;
    color: #222;
    border-bottom-left-radius: 2px;
}

.sbuy-pcb-ai-msg-user {
    align-self: flex-end;
    background: #2271b1;
    color: #fff;
    border-bottom-right-radius: 2px;
}

.sbuy-pcb-ai-msg-error {
    align-self: flex-start;
    background: #fbeaea;
    color: #8a1f1f;
    border-bottom-left-radius: 2px;
}

/* ===== Quick-reply gợi ý sẵn khi mở chat ===== */
.sbuy-pcb-ai-quickreplies {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-self: stretch;
}

.sbuy-pcb-ai-quickreply {
    text-align: left;
    padding: 9px 12px;
    background: #fff;
    border: 1px solid #d8e3ee;
    border-radius: 8px;
    color: #2271b1;
    cursor: pointer;
    font-size: 12.5px;
    line-height: 1.4;
}

.sbuy-pcb-ai-quickreply:hover {
    background: #f1f7fc;
    border-color: #2271b1;
}

.sbuy-pcb-ai-build-card {
    align-self: flex-start;
    max-width: 92%;
    background: #fff;
    border: 1px solid #e2e2e2;
    border-radius: 10px;
    padding: 10px;
    font-size: 12px;
}

.sbuy-pcb-ai-build-item {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 2px;
    color: #333;
}

.sbuy-pcb-ai-build-item-price {
    color: #d63638;
    font-weight: 600;
    white-space: nowrap;
}

.sbuy-pcb-ai-apply-btn {
    margin-top: 8px;
    width: 100%;
    padding: 8px;
    background: #2271b1;
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
}

.sbuy-pcb-ai-apply-btn:hover {
    background: #135e96;
}

.sbuy-pcb-ai-inputrow {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #eee;
}

.sbuy-pcb-ai-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
}

.sbuy-pcb-ai-send {
    padding: 10px 16px;
    background: #2271b1;
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
}

.sbuy-pcb-ai-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* =====================================================================
 * Responsive
 * - Tablet (~1024px): chỉ co gọn khung ngoài, giữ nguyên bố cục 2 cột.
 * - Mobile (~800px): xếp lại toàn bộ - sidebar tổng lên trên, mỗi slot dồn
 *   2 cột, và QUAN TRỌNG: popup chọn sản phẩm phải xếp sidebar bộ lọc lên
 *   trên thay vì đứng cạnh (ở bản gốc, sidebar bộ lọc rộng cố định 240px
 *   đứng cạnh khung sản phẩm khiến khung sản phẩm gần như biến mất trên
 *   điện thoại - vd màn 375px chỉ còn khoảng 100px cho danh sách sản phẩm).
 * - Small mobile (~480px): thu nhỏ thêm số liệu/khoảng cách, gộp nút FAB AI.
 * ===================================================================== */

@media (max-width: 1024px) {
    .sbuy-pcb-app {
        grid-template-columns: 1fr 240px;
        gap: 16px;
        max-width: 100%;
    }

    .sbuy-pcb-popup-sidebar {
        width: 200px !important;
        flex: 0 0 200px !important;
        padding: 16px;
    }
}

@media (max-width: 800px) {
    .sbuy-pcb-app {
        grid-template-columns: 1fr;
        padding: 0 4px;
    }

    .sbuy-pcb-sidebar {
        position: static;
        order: -1;
    }

    /* ----- Toolbar: cho phép xuống dòng, nút chiếm nửa chiều rộng để dễ bấm ----- */
    .sbuy-pcb-toolbar {
        padding: 10px 14px;
    }

    .sbuy-pcb-toolbar-left {
        flex: 1 1 100%;
    }

    .sbuy-pcb-save-btn,
    .sbuy-pcb-load-btn {
        flex: 1 1 auto;
        padding: 8px 12px;
        font-size: 13px;
        justify-content: center;
    }

    /* ----- Slot rows: dồn 2 cột (ảnh + nội dung), actions xuống hàng riêng ----- */
    .sbuy-pcb-slot {
        grid-template-columns: 70px 1fr;
        grid-template-areas:
            "thumb label"
            "thumb info"
            "actions actions";
        padding: 12px 14px;
        gap: 10px 14px;
    }

    .sbuy-pcb-slot-label {
        grid-area: label;
    }

    .sbuy-pcb-slot-thumb {
        grid-area: thumb;
        width: 60px;
        height: 60px;
    }

    .sbuy-pcb-slot-info {
        grid-area: info;
    }

    .sbuy-pcb-slot-actions {
        grid-area: actions;
        flex-direction: row;
        flex-wrap: wrap;
        margin-top: 4px;
    }

    /* Ô số lượng chiếm trọn hàng riêng (dễ bấm hơn +/- bằng ngón tay), 2 nút
       Choose/Remove xuống hàng dưới chia đôi chiều rộng. */
    .sbuy-pcb-slot-qty {
        order: -1;
        flex: 1 1 100%;
        height: 38px;
    }

    .sbuy-pcb-choose-btn,
    .sbuy-pcb-remove-btn {
        flex: 1 1 auto;
        height: 38px;
    }

    /* ----- Popup: sidebar bộ lọc chuyển thành dải nằm ngang phía trên, cuộn
       riêng theo chiều dọc nếu dài, thay vì đứng cạnh khung sản phẩm ----- */
    .sbuy-pcb-popup-box {
        width: 100vw !important;
        max-height: 92vh;
        border-radius: 0;
    }

    .sbuy-pcb-popup-layout {
        flex-direction: column !important;
    }

    .sbuy-pcb-popup-sidebar {
        width: 100% !important;
        flex: 0 0 auto !important;
        max-height: 34vh;
        overflow-y: auto;
        border-right: none;
        border-bottom: 1px solid #eee;
        padding: 14px;
    }

    .sbuy-pcb-filter-group {
        margin-bottom: 16px;
    }

    .sbuy-pcb-popup-topbar {
        padding: 10px 14px;
    }

    .sbuy-pcb-popup-list {
        padding: 12px;
    }

    /* Card sản phẩm nhỏ lại để vừa 2 cột trên hầu hết điện thoại, đỡ phải cuộn dọc */
    .sbuy-pcb-popup-grid {
        grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
        gap: 10px;
    }

    .sbuy-pcb-popup-card-content {
        padding: 8px 10px;
    }

    .sbuy-pcb-popup-card-action {
        padding: 0 10px 10px;
    }

    .sbuy-pcb-popup-card-name {
        font-size: 12.5px;
        margin-bottom: 6px;
    }

    .sbuy-pcb-popup-card-price {
        font-size: 13.5px;
    }
}

@media (max-width: 480px) {
    .sbuy-pcb-toolbar-right {
        flex: 1 1 100%;
    }

    .sbuy-pcb-reset {
        width: 100%;
        justify-content: center;
    }

    .sbuy-pcb-popup-sorting {
        justify-content: flex-start;
    }

    .sbuy-pcb-popup-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 8px;
    }

    .sbuy-pcb-ai-fab-label {
        display: none;
    }

    .sbuy-pcb-ai-panel {
        right: 12px;
        left: 12px;
        bottom: 12px;
        width: auto;
    }
}