/* ==========================================
   PRODUCTS PAGE - FINAL OPTIMIZED VERSION
   - Compact spacing between name and description
   - Full description display
   - Clean price/views (no background divs)
   - Proper badge colors from database
   - ✅ FIX: Ảnh hiển thị đầy đủ không bị cắt (object-fit: contain)
   - ✅ NEW: Hỗ trợ trạng thái hết hàng
   ========================================== */

.products-page {
    padding: 20px 0 40px;
    background: #f8f9fa;
}

.products-page .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
}

/* ==========================================
   PAGE HEADER
   ========================================== */
.page-header {
    text-align: center;
    margin-bottom: 20px;
    padding: 0;
}

.page-header h1 {
    font-size: 28px;
    color: #1e5ba8;
    margin: 0 0 2px 0;
    font-weight: 700;
}

.page-header p {
    font-size: 14px;
    color: #666;
    margin: 0;
}

/* ==========================================
   FILTER SECTION
   ========================================== */
/* ==========================================
   FILTER SECTION - RESPONSIVE & CONTAINED
   Elements scale với container, không tràn ra ngoài
   ========================================== */
.products-filter-section {
    background: white;
    padding: 12px 15px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    margin-bottom: 20px;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.filter-form {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr auto;
    gap: 10px;
    margin-bottom: 12px;
    width: 100%;
    box-sizing: border-box;
}

.filter-search {
    display: flex;
    gap: 8px;
    min-width: 0;
}

.search-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.3s;
    min-width: 0;
    box-sizing: border-box;
}

.search-input:focus {
    outline: none;
    border-color: #1e5ba8;
}

.search-btn {
    padding: 10px 20px;
    background: #1e5ba8;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
    box-sizing: border-box;
    flex-shrink: 0;
    white-space: nowrap;
}

.search-btn:hover {
    background: #164a8a;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
    box-sizing: border-box;
}

.filter-group label {
    font-size: 12px;
    color: #666;
    font-weight: 600;
}

.filter-group select {
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    background: white;
    cursor: pointer;
    transition: border-color 0.3s;
    min-width: 0;
    box-sizing: border-box;
}

.filter-group select:focus {
    outline: none;
    border-color: #1e5ba8;
}

.clear-filter-btn {
    padding: 10px 15px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 6px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    transition: background 0.3s;
    box-sizing: border-box;
    flex-shrink: 0;
}

.clear-filter-btn:hover {
    background: #c82333;
}

.results-info {
    padding: 8px 0 0;
    border-top: 1px solid #eee;
}

.results-info p {
    font-size: 13px;
    color: #666;
    margin: 0;
}

/* ==========================================
   PRODUCTS GRID - DESKTOP 4 COLUMNS
   ========================================== */
.products-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px; /* SPACING BETWEEN CARDS */
    margin-bottom: 30px;
}

/* ==========================================
   PRODUCT CARD
   ========================================== */
.product-card {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    transition: all 0.3s ease;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.product-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.15);
}

.product-link {
    display: flex;
    flex-direction: column;
    height: 100%;
    text-decoration: none;
    color: inherit;
}

/* ==========================================
   PRODUCT IMAGE - ✅ FIXED: Hiển thị đầy đủ không bị cắt
   ========================================== */
.product-image {
    position: relative;
    width: 100%;
    height: 180px; /* IMAGE HEIGHT DESKTOP */
    overflow: hidden;
    background: #fff;
    flex-shrink: 0;
    padding: 8px !important; /* ✅ Thêm padding để ảnh không chạm viền */
    margin: 0 !important;
    border: none !important;
}

.product-image img {
    width: 100%;
    height: 100%;
    object-fit: contain; /* ✅ THAY ĐỔI: Hiển thị đầy đủ ảnh, không bị cắt */
    display: block;
    transition: transform 0.3s ease;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

.product-card:hover .product-image img {
    transform: scale(1.05);
}

/* ==========================================
   CATEGORY BADGE - OVERLAY ON IMAGE
   Colors come from database: bg_color and text_color
   ========================================== */
.product-category-badge {
    position: absolute;
    top: 8px; /* BADGE TOP POSITION */
    left: 8px; /* BADGE LEFT POSITION */
    padding: 5px 12px; /* BADGE PADDING */
    font-size: 11px; /* BADGE FONT SIZE */
    font-weight: 600;
    /* Color is set inline from PHP - both background and text color */
    border-radius: 12px;
    z-index: 2;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
    backdrop-filter: blur(4px);
}

/* ✅ OUT OF STOCK BADGE - CENTER - Tạm hết hàng ở CHÍNH GIỮA ảnh */
.out-of-stock-badge {
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important; /* ✅ Căn giữa hoàn hảo */
    padding: 8px 16px;
    background: rgba(220, 53, 69, 0.95);
    color: white;
    font-size: 12px;
    font-weight: 700;
    border-radius: 8px;
    z-index: 10 !important;
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

/* ==========================================
   PRODUCT INFO CONTAINER
   COMPACT SPACING - Minimal gaps
   ========================================== */
.product-info {
    padding: 10px; /* CARD INNER PADDING */
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 2px; /* MINIMAL GAP - Very compact spacing between elements */
}

/* ==========================================
   PRODUCT NAME (TITLE)
   ========================================== */
.product-name {
    font-size: 14px; /* NAME FONT SIZE */
    margin: 0 0 2px 0; /* MINIMAL BOTTOM MARGIN - Reduces space to description */
    line-height: 1.3;
    font-weight: 600;
    color: #333;
    display: -webkit-box;
    -webkit-line-clamp: 2; /* NAME MAX LINES - Show 2 lines */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 36px;
}

/* ==========================================
   PRODUCT DESCRIPTION
   SHOWS FULL TEXT - No truncation
   COMPACT SPACING - Minimal margin
   ========================================== */
.product-description {
    font-size: 12px; /* DESCRIPTION FONT SIZE */
    color: #666;
    margin: 0 !important; /* NO MARGIN - Removes all unnecessary space */
    padding: 0 !important; /* NO PADDING */
    line-height: 1.4;
    /* NO LINE CLAMP - Shows complete description */
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* ==========================================
   PRODUCT META (PRICE & VIEWS)
   CLEAN LAYOUT - No background divs
   SINGLE LINE - Always horizontal
   ========================================== */
.product-meta {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    margin-top: auto; /* PUSH TO BOTTOM */
    padding-top: 8px; /* SPACE ABOVE META */
    border-top: 1px solid #eee; /* SEPARATOR LINE */
    flex-wrap: nowrap !important; /* FORCE SINGLE LINE */
    gap: 8px;
    background: none !important; /* NO BACKGROUND */
}

/* ==========================================
   PRODUCT PRICE
   NO BACKGROUND DIV - Clean display
   ========================================== */
.product-price {
    font-size: 16px; /* PRICE FONT SIZE */
    font-weight: 700;
    color: #1e5ba8; /* PRICE COLOR */
    white-space: nowrap;
    flex-shrink: 0;
    background: none !important; /* NO BACKGROUND */
    padding: 0 !important; /* NO PADDING */
    border: none !important; /* NO BORDER */
}

.product-price small {
    font-size: 12px;
    font-weight: 400;
}

.product-price.contact {
    font-size: 14px;
    color: #228b22;
}

/* ==========================================
   PRODUCT VIEWS
   ========================================== */
.product-views {
    font-size: 12px;
    color: #999;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    flex-shrink: 0;
}

.product-views i {
    font-size: 11px;
}

/* ==========================================
   PAGINATION
   ========================================== */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 20px;
}

.pagination-btn,
.pagination-number {
    padding: 8px 14px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    text-decoration: none;
    color: #333;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.pagination-btn:hover,
.pagination-number:hover {
    background: #1e5ba8;
    color: white;
    border-color: #1e5ba8;
}

.pagination-number.active {
    background: #1e5ba8;
    color: white;
    border-color: #1e5ba8;
    font-weight: 700;
}

.pagination-dots {
    color: #999;
    padding: 0 5px;
}

/* ==========================================
   NO PRODUCTS FOUND
   ========================================== */
.no-products-found {
    text-align: center;
    padding: 60px 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.no-products-found i {
    font-size: 60px;
    color: #ddd;
    margin-bottom: 20px;
    display: block;
}

.no-products-found h3 {
    font-size: 22px;
    color: #333;
    margin: 0 0 12px 0;
    font-weight: 700;
}

.no-products-found p {
    font-size: 14px;
    color: #666;
    margin: 0 0 24px 0;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: #1e5ba8;
    color: white;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s;
}

.btn-primary:hover {
    background: #164a8a;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(30,91,168,0.3);
}

/* ==========================================
   CATEGORIES SECTION
   ========================================== */
.other-categories {
    margin-top: 50px;
    margin-bottom: 40px;
}

.section-title {
    text-align: center;
    font-size: 26px;
    color: #1e5ba8;
    margin-bottom: 30px;
    font-weight: 700;
    position: relative;
    padding-bottom: 12px;
}

.section-title::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 3px;
    background: #1e5ba8;
    border-radius: 2px;
}

.categories-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.category-card {
    background: white;
    border-radius: 10px;
    padding: 30px 20px;
    text-align: center;
    text-decoration: none;
    transition: all 0.3s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    min-height: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.category-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--category-color, #1e5ba8);
    transform: scaleX(0);
    transition: transform 0.3s;
}

.category-card:hover::before {
    transform: scaleX(1);
}

.category-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.12);
}

.category-content h3 {
    font-size: 22px;
    color: #333;
    margin: 0 0 10px 0;
    font-weight: 700;
}

.category-content p {
    font-size: 14px;
    color: #666;
    margin: 0 0 12px 0;
}

.category-content .product-count {
    font-size: 13px;
    color: var(--category-color, #1e5ba8);
    font-weight: 600;
}

/* ==========================================
   RESPONSIVE - TABLET (1024px)
   ========================================== */
@media (max-width: 1024px) {
    .products-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }

    .filter-form {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .filter-search {
        grid-column: 1 / -1;
    }

    .clear-filter-btn {
        grid-column: 1 / -1;
    }

    .categories-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }

    .category-card {
        min-height: 130px;
        padding: 25px 15px;
    }

    .category-content h3 {
        font-size: 20px;
    }

    .category-content p {
        font-size: 13px;
    }
}

/* ==========================================
   RESPONSIVE - MOBILE (768px)
   ========================================== */
@media (max-width: 768px) {
    .products-page {
        padding: 15px 0 30px;
    }

    .products-page .container {
        padding: 0 5px !important; /* Giảm để tận dụng không gian */
        max-width: 100% !important;
    }

    .page-header {
        margin-bottom: 15px;
        padding: 0 5px;
    }

    .page-header h1 {
        font-size: 22px;
    }

    .page-header p {
        font-size: 13px;
    }

    .products-filter-section {
        padding: 12px 10px;
        margin-bottom: 15px;
    }

    .filter-form {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .filter-search {
        grid-column: 1;
    }

    .search-input {
        font-size: 13px;
        padding: 9px 10px;
    }

    .search-btn {
        padding: 9px 16px;
        font-size: 13px;
    }

    .filter-group label {
        font-size: 11px;
    }

    .filter-group select {
        font-size: 13px;
        padding: 9px 10px;
    }

    .results-info p {
        font-size: 12px;
    }

    /* MOBILE: 2 COLUMNS */
    .products-page .products-grid,
    .products-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 5px !important; /* Giảm gap để ô to hơn */
        width: 100% !important; /* Full width để tận dụng không gian */
    }

    .product-image {
        height: 165px !important; /* Tăng để nhìn rõ hơn */
        padding: 6px !important; /* ✅ Giảm padding trên mobile */
    }

    .product-category-badge {
        top: 6px;
        left: 6px;
        padding: 4px 10px;
        font-size: 7px !important; /* FORCE 7px trên mobile */
        border-radius: 10px;
    }

    .out-of-stock-badge {
        /* Giữ nguyên vị trí center, chỉ điều chỉnh size */
        padding: 6px 14px;
        font-size: 11px;
    }

    .product-info {
        padding: 8px;
        gap: 2px; /* MOBILE: Minimal gap */
    }

    .product-name {
        font-size: 13px;
        line-height: 1.3;
        min-height: 34px;
        margin: 0 0 2px 0; /* MOBILE: Minimal margin */
    }

    .product-description {
        font-size: 11px;
        line-height: 1.4;
        margin: 0 !important;
        padding: 0 !important;
    }

    .product-meta {
        padding-top: 6px;
        flex-wrap: nowrap !important;
        background: none !important;
    }

    .product-price {
        font-size: 14px;
        background: none !important;
        padding: 0 !important;
        border: none !important;
    }

    .product-price small {
        font-size: 10px;
    }

    .product-price.contact {
        font-size: 13px;
    }

    .product-views {
        font-size: 11px;
    }

    .product-views i {
        font-size: 10px;
    }

    .pagination {
        gap: 5px;
        flex-wrap: wrap;
    }

    .pagination-btn,
    .pagination-number {
        padding: 6px 10px;
        font-size: 13px;
    }

    .no-products-found {
        padding: 40px 15px;
    }

    .no-products-found i {
        font-size: 50px;
    }

    .no-products-found h3 {
        font-size: 18px;
    }

    .no-products-found p {
        font-size: 13px;
    }

    .other-categories {
        margin-top: 40px;
        margin-bottom: 30px;
    }

    .other-categories .section-title {
        font-size: 22px;
        margin-bottom: 20px;
    }

    .categories-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .category-card {
        min-height: 110px;
        padding: 20px 15px;
    }

    .category-content h3 {
        font-size: 18px;
    }

    .category-content p {
        font-size: 13px;
    }
}

/* ==========================================
   RESPONSIVE - SMALL MOBILE (480px)
   ========================================== */
@media (max-width: 480px) {
    .products-page .container {
        padding: 0 4px !important; /* Giảm để tận dụng không gian */
    }

    .page-header h1 {
        font-size: 20px;
    }

    .products-page .products-grid,
    .products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 4px !important; /* Giảm gap để ô to hơn */
    }

    .product-image {
        height: 150px !important; /* Tăng để nhìn rõ hơn */
        padding: 4px !important; /* ✅ Padding nhỏ hơn cho màn hình nhỏ */
    }

    .product-info {
        padding: 6px;
        gap: 1px; /* SMALL MOBILE: Ultra compact */
    }

    .product-name {
        font-size: 12px;
        min-height: 32px;
        margin: 0 0 1px 0; /* SMALL MOBILE: Ultra minimal margin */
    }

    .product-description {
        font-size: 10px;
        margin: 0 !important;
        padding: 0 !important;
    }

    .product-meta {
        padding-top: 4px;
    }

    .product-price {
        font-size: 13px;
    }

    .product-price small {
        font-size: 9px;
    }

    .product-views {
        font-size: 10px;
    }

    .product-views i {
        font-size: 9px;
    }

    .category-card {
        min-height: 100px;
        padding: 18px 12px;
    }

    .category-content h3 {
        font-size: 16px;
    }

    .category-content p {
        font-size: 12px;
    }
}

/* ==========================================
   FORCE OVERRIDES - PREVENT CSS CONFLICTS
   ========================================== */

/* FORCE: Grid columns */
.products-page .products-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 12px !important;
}

@media (max-width: 1024px) {
    .products-page .products-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 10px !important;
    }
}

@media (max-width: 768px) {
    .products-page .products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
}

@media (max-width: 480px) {
    .products-page .products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 6px !important;
    }
}

/* FORCE: Padding on images - ✅ Đảm bảo ảnh có padding */
.products-page .product-image {
    padding: 8px !important;
}

@media (max-width: 768px) {
    .products-page .product-image {
        padding: 6px !important;
    }
}

@media (max-width: 480px) {
    .products-page .product-image {
        padding: 4px !important;
    }
}

.products-page .product-image img {
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    object-fit: contain !important; /* ✅ FORCE: Hiển thị đầy đủ ảnh */
}

/* FORCE: Single line meta, no backgrounds */
.products-page .product-meta {
    flex-wrap: nowrap !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    background: none !important;
}

.products-page .product-price {
    background: none !important;
    padding: 0 !important;
    border: none !important;
}

/* FORCE: Compact spacing */
.products-page .product-info {
    gap: 2px !important;
}

.products-page .product-name {
    margin: 0 0 2px 0 !important;
}

.products-page .product-description {
    margin: 0 !important;
    padding: 0 !important;
}

/* ✅ CRITICAL OVERRIDE: Badge "Tạm hết hàng" PHẢI Ở GIỮA */
.products-page .out-of-stock-badge,
.product-card .out-of-stock-badge {
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    transform: translate(-50%, -50%) !important;
    z-index: 10 !important;
}
/* ==========================================
   FORCE RESPONSIVE IMPROVEMENTS
   ========================================== */
@media (max-width: 768px) {
    .products-filter-section {
        padding: 10px 12px;
    }
    
    .filter-form {
        gap: 8px;
    }
    
    .search-input {
        padding: 8px 10px;
        font-size: 13px;
    }
    
    .search-btn {
        padding: 8px 14px;
        font-size: 13px;
    }
    
    .filter-group select {
        padding: 8px 10px;
        font-size: 13px;
    }
    
    .clear-filter-btn {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    /* FORCE badge 7px trên mobile */
    .product-category-badge {
        font-size: 7px !important;
    }
}

@media (max-width: 480px) {
    .products-filter-section {
        padding: 8px 10px;
    }
    
    .filter-form {
        gap: 6px;
    }
    
    .search-input {
        padding: 6px 8px;
        font-size: 12px;
    }
    
    .search-btn {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .filter-group label {
        font-size: 10px;
    }
    
    .filter-group select {
        padding: 6px 8px;
        font-size: 12px;
    }
    
    .clear-filter-btn {
        padding: 6px 10px;
        font-size: 11px;
    }
    
    /* FORCE badge 7px trên mobile */
    .product-category-badge {
        font-size: 7px !important;
    }
}