/* Base Styles */
:root { 
    --primary-color: #28a745; 
    --secondary-color: #007bff; 
    --light-gray: #f8f9fa; 
    --danger-color: #dc3545;
    --text-color: #333;
    --border-color: #dee2e6;
    --background-color: #f0f2f5;
}
body { 
    font-family: 'Sarabun', Arial, sans-serif; 
    margin: 0; 
    background-color: var(--background-color); 
    font-size: 16px; 
    color: var(--text-color); 
    line-height: 1.6;
}
.page-container { 
    max-width: 1400px;
    margin: 0 auto; 
    padding: 20px; 
}
h1, h2, h3, h4 { color: var(--primary-color); }

/* User Bar */
.user-bar { 
    padding: 10px 20px;
    background-color: #e9ecef; 
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9em;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 15px;
}
.user-bar a {
    color: var(--secondary-color);
    text-decoration: none;
    padding: 5px 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}
.user-bar a:hover {
    background-color: rgba(0, 123, 255, 0.1);
}

/* Cart Section */
.cart { 
    background-color: #fff; 
    border-radius: 8px; 
    box-shadow: 0 4px 8px rgba(0,0,0,0.05); 
    padding: 20px; 
    margin-bottom: 20px; 
}
details > summary {
    font-size: 1.2em;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
}
details > summary::-webkit-details-marker {
    display: none;
}
.cart h4 { margin-top: 0; display: flex; align-items: center; gap: 8px; }
.cart table { 
    width: 100%; 
    border-collapse: collapse; 
    margin-top: 15px; 
    font-size: 0.9em;
}
.cart th, .cart td { 
    padding: 10px 8px; 
    border-bottom: 1px solid var(--border-color); 
    text-align: left; 
    vertical-align: middle;
}
.cart th { 
    font-weight: 600; 
    color: #495057; 
    background-color: var(--light-gray); 
}
.cart-item-info { 
    display: flex; 
    align-items: center; 
    gap: 10px; 
}
.cart-item-info .thumb,
.cart-item-info img { 
    width: 50px; 
    height: 50px; 
    object-fit: contain; 
    border-radius: 4px; 
    background-color: #f8f8f8; 
}
.cart-item-info .name { font-weight: 600; }
.price-breakdown { font-size: 0.8em; color: #6c757d; line-height: 1.5; }
.cart-quantity-input { 
    width: 60px; 
    padding: 5px; 
    border: 1px solid #ccc; 
    border-radius: 4px; 
    text-align: center;
}
.cart-actions { 
    display: flex; 
    justify-content: flex-end; 
    align-items: center; 
    gap: 10px; 
    padding-top: 15px; 
    flex-wrap: wrap;
}
.update-cart-btn, .clear-cart, .checkout { 
    padding: 8px 16px; 
    margin-left: 8px;
    text-decoration: none; 
    color: white; 
    border-radius: 5px; 
    border: none;
    cursor: pointer;
    font-weight: bold;
    transition: opacity 0.2s;
}
.update-cart-btn:hover, .clear-cart:hover, .checkout:hover { opacity: 0.9; }
.update-cart-btn { background-color: var(--secondary-color); }
.clear-cart { background-color: #6c757d; }
.checkout { background-color: var(--primary-color); }

/* --- Sidebar Layout --- */
.main-layout {
    display: flex;
    flex-wrap: wrap; 
    gap: 20px;
    margin-top: 20px;
}
.sidebar-nav {
    flex: 0 0 240px; 
    background-color: #ffffff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.05);
    height: fit-content;
}
.product-display {
    flex: 1; 
    min-width: 0;
}

/* --- NEW: Sidebar Filter Form --- */
.sidebar-nav .form-group {
    margin-bottom: 20px;
}
.sidebar-nav .form-group:last-child {
    margin-bottom: 0;
}
.sidebar-nav h3 {
    margin-top: 0;
    margin-bottom: 10px;
    padding-bottom: 10px;
    font-size: 1.1em;
    border-bottom: 2px solid var(--primary-color);
}
.sidebar-nav label {
    font-weight: normal;
    display: flex;
    align-items: center;
    cursor: pointer;
}
.sidebar-nav input[type="checkbox"] {
    margin-right: 8px;
    width: 16px;
    height: 16px;
}
.sidebar-nav select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: white;
    font-size: 1em;
    cursor: pointer;
}
.sidebar-nav select:hover {
    border-color: #999;
}


/* Section Header & Search */
.section-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 15px; 
    flex-wrap: wrap;
    gap: 10px;
}
.section-header h2 { margin: 0; color: var(--text-color); font-size: 1.4rem; }
.search-form { display: flex; }
.search-form input[type="text"] { 
    border: 1px solid #ccc; 
    border-right: none; 
    padding: 8px; 
    border-radius: 20px 0 0 20px; 
    font-size: 0.9em;
}
.search-form button { 
    border: 1px solid #ccc; 
    background: #f0f0f0; 
    padding: 8px 12px; 
    border-radius: 0 20px 20px 0; 
    cursor: pointer; 
    font-size: 1rem; 
    line-height: 1; 
    color: var(--text-color);
}

/* Product Grid */
.product-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 15px; 
    margin-top: 10px; 
}
.product-item { 
    display: flex; 
    flex-direction: column; 
    background-color: #fff; 
    border-radius: 8px; 
    box-shadow: 0 4px 8px rgba(0,0,0,0.05); 
    overflow: hidden; 
    transition: transform 0.2s, box-shadow 0.2s; 
    position: relative; 
}
.product-item:hover { transform: translateY(-5px); box-shadow: 0 8px 16px rgba(0,0,0,0.1); }
.product-image-container { 
    position: relative; /* เพิ่มเพื่อให้ stock-badge อ้างอิงได้ */
    width: 100%; 
    aspect-ratio: 1 / 1;
    padding: 10px; 
    background-color: #fff; 
    box-sizing: border-box; 
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}
.product-image-container img { 
    max-width: 100%; 
    max-height: 100%;
    object-fit: contain;
    display: block;
}
.stock-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background-color: var(--secondary-color);
    color: white;
    padding: 5px 8px;
    border-radius: 5px;
    font-size: 0.85em;
    font-weight: bold;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    text-align: center;
    min-width: 60px;
}
.stock-badge.out-of-stock {
    background-color: var(--danger-color);
}
.product-details { 
    padding: 0 15px 15px 15px; 
    flex-grow: 1; 
}
.product-details h3 {
    margin-top: 10px;
    margin-bottom: 10px;
    font-size: 1em;
    height: 3.2em;
    line-height: 1.6em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}
.price-display {
    font-size: 1.1em;
    font-weight: bold;
    color: var(--primary-color);
    text-align: center;
    margin-bottom: 10px;
}
.price-tiers { 
    font-size: 0.85em; 
    text-align: left; 
    padding: 0 5px; 
    line-height: 1.5;
}
.price-tiers p { margin: 5px 0; }
.product-actions form { 
    display: flex; 
    gap: 10px; 
    padding: 15px; 
    background-color: var(--light-gray); 
}
.product-actions input[type="number"] { 
    width: 60px; 
    padding: 8px; 
    text-align: center; 
    border: 1px solid #ccc; 
    border-radius: 4px; 
    font-size: 0.9em;
}
.product-actions button { 
    flex-grow: 1; 
    padding: 8px; 
    background-color: var(--secondary-color); 
    color: white; 
    border: none; 
    border-radius: 4px; 
    cursor: pointer; 
    font-weight: bold; 
    transition: background-color 0.2s;
}
.product-actions button:hover { background-color: #0069d9; }
.product-actions button:disabled { background-color: #ccc; cursor: not-allowed; }

/* Status Message */
.status-message { 
    padding: 15px; 
    border-radius: 4px; 
    margin: 0 0 20px 0; 
    text-align: center; 
    font-weight: 500;
}
.status-message.error { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb;}
.status-message.success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; }

/* Pagination Controls */
.pagination {
    display: flex;
    justify-content: center;
    margin-top: 30px;
    gap: 5px;
    flex-wrap: wrap; 
}
.pagination a, .pagination span {
    padding: 8px 15px;
    border: 1px solid #ccc;
    border-radius: 5px;
    text-decoration: none;
    color: var(--primary-color);
    background-color: #fff;
    transition: background-color 0.3s, color 0.3s;
    font-size: 0.9em;
}
.pagination a:hover {
    background-color: #e9ecef;
}
.pagination .current-page {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    font-weight: bold;
}
.pagination .disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #f8f9fa;
}


/* Responsive Adjustments */
@media (max-width: 992px) {
    .main-layout {
        flex-direction: column;
    }
    .sidebar-nav {
        flex: 0 0 auto; 
        width: 100%;
        box-sizing: border-box;
    }
}
@media (max-width: 768px) {
    body { font-size: 15px; }
    .page-container { padding: 10px; }
    .user-bar { 
        padding: 10px; 
        justify-content: center;
        font-size: 0.85em;
    }
    .cart, .product-section { padding: 15px; }
    .cart th, .cart td { padding: 8px 5px; }
    .cart-item-info img { width: 40px; height: 40px; }
    .cart-item-info .name { font-size: 0.9em; }
    .cart-quantity-input { width: 45px; font-size: 0.85em; }
    .cart-actions { justify-content: center; }

    .section-header { 
        flex-direction: column; 
        align-items: stretch; 
        gap: 15px; 
    }
    .section-header h2 { text-align: center; }
    .search-form { width: 100%; }

    .product-grid { 
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
    .product-details h3 { font-size: 0.9em; height: 3.2em; }
    .price-tiers { font-size: 0.8em; padding: 0 5px; }
    .product-actions form { flex-direction: column; gap: 8px; }
    .product-actions input[type="number"] { width: 100%; box-sizing: border-box; }
    
    .pagination { gap: 3px; }
    .pagination a, .pagination span { padding: 6px 10px; font-size: 0.8em; }

    .cart-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .cart-table-wrapper table {
        min-width: 600px;
    }
}

/* --- UI Polishing Overrides (non-breaking) --- */
:root {
    --primary-color: #22c55e; /* fresh green */
    --secondary-color: #0ea5e9; /* sky blue */
    --light-gray: #f6f7fb;
    --danger-color: #ef4444;
    --text-color: #1f2937;
    --border-color: #e5e7eb;
    --background-color: #f4f6fb;
    --shadow-sm: 0 2px 6px rgba(0,0,0,0.06);
    --shadow-md: 0 6px 16px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 24px rgba(0,0,0,0.12);
}

/* Typography & base */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: radial-gradient(1200px 600px at 10% -10%, #ffffff 0%, transparent 40%),
                radial-gradient(1200px 800px at 110% 10%, #ffffff 0%, transparent 40%),
                var(--background-color);
}
.header, .sidebar-nav, .cart, .product-item {
    box-shadow: var(--shadow-sm);
}
.product-item:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-md);
}

/* Header polish */
.header-inner { gap: 20px; }
.logo { letter-spacing: 0.5px; }
.header-search input[type="text"] {
    background: #f3f4f6;
    transition: box-shadow 0.2s, background 0.2s;
}
.header-search input[type="text"]:focus {
    outline: none;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(14,165,233,0.15);
}
.header-search button {
    background: linear-gradient(180deg, var(--secondary-color), #0b8fc8);
    border-color: #0b8fc8;
}
.header-link { opacity: 0.9; }
.header-link:hover { opacity: 1; text-decoration: underline; }

/* Chips */
.chip { transition: transform 0.15s, background 0.2s, color 0.2s; }
.chip:hover { transform: translateY(-1px); }
.chip.active { box-shadow: 0 0 0 3px rgba(34,197,94,0.15); }

/* Hero */
.hero {
    background: linear-gradient(90deg, rgba(34,197,94,0.08) 0%, rgba(14,165,233,0.08) 100%);
}
.hero-content h1 { font-weight: 800; letter-spacing: 0.2px; }
.hero-cta { box-shadow: var(--shadow-sm); }
.hero-cta:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

/* Sidebar */
.sidebar-nav { border: 1px solid var(--border-color); }
.sidebar-nav select { transition: border-color 0.2s, box-shadow 0.2s; }
.sidebar-nav select:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(14,165,233,0.12);
}

/* Section header tools */
.section-header { border-bottom: 1px dashed #eaecef; padding-bottom: 12px; }
.sort-bar select { background: #fff; }

/* Product card details */
.product-details h3 { color: #111827; }
.price-display { color: #16a34a; }
.price-highlight { color: #16a34a; font-weight: 700; }
.price-wholesale { color: #0ea5e9; font-weight: 600; }

/* Add subtle divider on product info */
.product-details { position: relative; }
.product-details::after {
    content: "";
    position: absolute;
    left: 15px; right: 15px; bottom: 0;
    height: 1px; background: #f1f5f9;
}

/* Product actions */
.product-actions form { background: #f8fafc; }
.product-actions button {
    background: linear-gradient(180deg, var(--secondary-color), #0b8fc8);
    box-shadow: var(--shadow-sm);
}
.product-actions button:hover { filter: brightness(1.05); }

/* Badges & ribbons */
.stock-badge { background-color: var(--secondary-color); }
.stock-badge.out-of-stock { background-color: var(--danger-color); }
.ribbon { box-shadow: var(--shadow-sm); }

/* Cart polish */
.cart table thead th { background: #f3f4f6; }
.cart-actions .checkout { box-shadow: var(--shadow-sm); }

/* Pagination */
.pagination a, .pagination span { box-shadow: 0 1px 0 rgba(0,0,0,0.03); }
.pagination a:hover { transform: translateY(-1px); }

/* Subtle card borders */
.product-item, .cart, .sidebar-nav, .header {
    border: 1px solid var(--border-color);
    border-radius: 10px;
}

/* Scrollbar (WebKit) */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #d1d5db, #cbd5e1);
    border-radius: 8px;
}
*::-webkit-scrollbar-track { background: #f8fafc; }

/* Micro-interactions */
.update-cart-btn, .clear-cart, .checkout { transition: transform 0.12s ease, opacity 0.2s; }
.update-cart-btn:hover, .clear-cart:hover, .checkout:hover { transform: translateY(-1px); }

/* Responsive tweaks */
@media (max-width: 768px) {
    .header-inner { gap: 12px; }
    .brand { width: 100%; justify-content: center; }
    .header-actions { width: 100%; justify-content: center; }
    .category-chips { justify-content: center; }
}

/* --- E-commerce Feature Styles (Lazada/Shopee-like) --- */
.flash-sale {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    padding: 10px 14px;
    background: linear-gradient(90deg, rgba(239,68,68,0.08), rgba(234,179,8,0.08));
    border: 1px solid var(--border-color);
    border-radius: 10px;
}
.flash-title { font-weight: 800; color: #ef4444; margin-right: 10px; }
.flash-countdown {
    font-family: monospace;
    padding: 4px 8px;
    border-radius: 6px;
    background: #111827;
    color: #fff;
    letter-spacing: 1px;
}
.flash-link { color: #ef4444; text-decoration: none; font-weight: 700; }
.flash-link:hover { text-decoration: underline; }

/* Price block */
.price-block { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.price-now { font-size: 1.2rem; font-weight: 800; color: #111827; }
.price-old { font-size: 0.95rem; color: #9ca3af; text-decoration: line-through; }
.price-badge {
    background: #ef4444; color: #fff; font-weight: 700; font-size: 0.75rem;
    padding: 2px 6px; border-radius: 4px;
}

/* Meta tags under product */
.meta-tags { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.tag {
    padding: 2px 6px; font-size: 0.75rem; border-radius: 4px; border: 1px dashed #e5e7eb; color: #475569;
    background: #f8fafc;
}
.tag.shipping { border-color: #22c55e; color: #16a34a; }
.tag.return { border-color: #0ea5e9; color: #0284c7; }

/* Bottom mobile nav */
.bottom-nav {
    position: fixed;
    left: 0; bottom: 0; right: 0;
    background: #ffffff;
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -4px 10px rgba(0,0,0,0.04);
    display: none;
    z-index: 1000;
}
.bn-item {
    flex: 1; text-align: center; padding: 8px 6px; color: #334155; text-decoration: none;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.bn-item small { font-size: 0.7rem; }

@media (max-width: 768px) {
    .bottom-nav { display: flex; }
    body { padding-bottom: 56px; }
}

/* ===== Brand / Logo polish ===== */
.header { position: relative; overflow: hidden; }
.header::before {
    content: "";
    position: absolute; inset: 0;
    background: radial-gradient(600px 200px at -10% -20%, rgba(14,165,233,0.08), transparent 50%),
                radial-gradient(600px 200px at 110% -10%, rgba(34,197,94,0.08), transparent 50%);
    pointer-events: none;
}
.brand .logo {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 10px;
    background: linear-gradient(180deg, #22c55e, #16a34a);
    color: #fff;
    text-shadow: 0 1px 0 rgba(0,0,0,0.15);
}
.brand .tagline {
    background: #f0fdf4;
    color: #166534;
    padding: 3px 8px;
    border-radius: 999px;
    border: 1px solid #bbf7d0;
}

/* ===== Header Search - enhanced ===== */
.header-search {
    position: relative;
    border-radius: 999px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    background: #ffffff;
}
.header-search input[type="text"] {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-right: none;
}
.header-search input[type="text"]::placeholder {
    color: #9ca3af;
}
.header-search:focus-within {
    box-shadow: 0 0 0 4px rgba(14,165,233,0.12), var(--shadow-md);
}
.header-search button {
    background: linear-gradient(180deg, var(--secondary-color), #0b8fc8);
    border-color: #0b8fc8;
    position: relative;
}
.header-search button::before {
    content: "\1F50D"; /* 🔍 */
    position: absolute; left: 10px;
}
.header-search button { padding-left: 30px; }

/* ===== Section search (product list) match header style ===== */
.section-header .search-form {
    border-radius: 999px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    background: #fff;
}
.section-header .search-form input[type="text"] {
    border: 1px solid #e5e7eb; border-right: none; background: #fff;
}
.section-header .search-form input[type="text"]:focus { outline: none; box-shadow: inset 0 0 0 2px rgba(14,165,233,0.08); }
.section-header .search-form button { background: #f3f4f6; border: 1px solid #e5e7eb; }
.section-header .search-form button:hover { background: #e5e7eb; }

/* ===== Search suggestions (future-ready) ===== */
.search-suggest {
    position: absolute; top: 100%; left: 0; right: 0;
    background: #fff; border: 1px solid #e5e7eb; border-top: none;
    border-radius: 0 0 12px 12px; box-shadow: var(--shadow-md);
    z-index: 20; display: none;
}
.search-suggest .item { padding: 10px 14px; cursor: pointer; }
.search-suggest .item:hover { background: #f8fafc; }

/* ===== Minor spacing tweaks for harmony ===== */
.header-inner { padding-bottom: 4px; }
.category-chips { margin-top: 8px; }

/* ===== Wishlist Button Styles ===== */
.wish-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 35px;
    height: 35px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    color: #ccc;
    font-size: 18px;
    cursor: pointer;
    z-index: 10;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.wish-btn:hover {
    background: rgba(255, 255, 255, 1);
    color: #ff6b6b;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
}

.wish-btn.active {
    color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
}

.wish-btn.active:hover {
    background: rgba(255, 107, 107, 0.2);
}

/* Wishlist notification */
.wishlist-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #28a745;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    transform: translateX(400px);
    transition: transform 0.3s ease;
}

.wishlist-notification.show {
    transform: translateX(0);
}

.wishlist-notification.error {
    background: #dc3545;
}