:root {
    --primary: #1e293b;
    --accent: #4f46e5;
    --success: #22c55e;
    --danger: #ef4444;
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; outline: none; }
body { font-family: 'Segoe UI', system-ui, sans-serif; margin: 0; background: var(--bg); color: var(--text); overflow-x: hidden; }

/* Loader */
#loader { position: fixed; inset: 0; background: var(--primary); z-index: 9999; display: flex; flex-direction: column; align-items: center; justify-content: center; color: white; transition: opacity 0.5s; }
.spinner { width: 40px; height: 40px; border: 4px solid rgba(255,255,255,0.1); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Layout */
header { background: var(--primary); color: white; padding: 1.5rem 1rem; text-align: center; position: relative; z-index: 1000; box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.logo-container { width: 80px; height: 80px; margin: 0 auto 0.5rem; display: flex; align-items: center; justify-content: center; background: white; border-radius: 15px; overflow: hidden; }
.logo-container img { width: 100%; height: 100%; object-fit: contain; }
.header-title { font-size: 1.1rem; font-weight: 900; letter-spacing: 1.5px; text-transform: uppercase; }

.nav-sticky { position: sticky; top: 0; background: white; z-index: 900; padding: 12px; border-bottom: 1px solid #e2e8f0; box-shadow: 0 2px 10px rgba(0,0,0,0.05); }
@media (max-width: 600px) { .nav-sticky { top: 0; } }

.search-container { position: relative; max-width: 600px; margin: 0 auto; }
.search-input { width: 100%; padding: 12px 12px 12px 42px; border-radius: 100px; border: 1px solid #cbd5e0; font-size: 1rem; background: #f8fafc; transition: all 0.3s; }
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1); background: white; }
.search-container i { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }

.tabs { display: flex; justify-content: center; gap: 12px; padding: 12px 0 4px; }
.tab-btn { padding: 8px 24px; border-radius: 100px; border: 1px solid #e2e8f0; background: white; white-space: nowrap; font-weight: 700; cursor: pointer; transition: all 0.3s; color: var(--text-muted); }
.tab-btn.active { background: var(--accent); color: white; border-color: var(--accent); box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3); }

/* Grid */
main { max-width: 1200px; margin: 0 auto; padding: 1rem 1rem 120px; }
.category-block { margin-bottom: 2.5rem; }
.category-title { font-size: 1.3rem; font-weight: 800; border-left: 5px solid var(--accent); padding-left: 12px; margin-bottom: 1.25rem; display: flex; align-items: center; gap: 10px; color: var(--primary); }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 1rem; }

@media (max-width: 400px) {
    .product-grid { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
    .card-body { padding: 0.75rem; }
    .p-name { font-size: 0.85rem; height: 2.4rem; }
    .p-price { font-size: 1.1rem; }
}

.card { background: white; border-radius: 20px; overflow: hidden; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); display: flex; flex-direction: column; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); position: relative; border: 1px solid #f1f5f9; }
.card:hover { transform: translateY(-5px); box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); }

.img-container { padding-top: 100%; background: #f1f5f9; position: relative; overflow: hidden; }
.img-container img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: transform 0.5s; }
.card:hover .img-container img { transform: scale(1.1); }
.img-fallback { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #cbd5e1; background: #f8fafc; }

.discount-badge { position: absolute; top: 12px; right: -30px; background: var(--danger); color: white; padding: 6px 35px; transform: rotate(45deg); font-size: 0.75rem; font-weight: 900; z-index: 2; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }

.card-body { padding: 1rem; flex: 1; display: flex; flex-direction: column; }
.p-name { font-weight: 700; font-size: 0.95rem; margin-bottom: 6px; color: var(--text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; height: 2.7rem; line-height: 1.4; }
.p-price { color: var(--success); font-weight: 800; font-size: 1.2rem; margin-bottom: 2px; }
.p-unit { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 1rem; font-weight: 600; }

.btn-add { width: 100%; padding: 10px; background: var(--primary); color: white; border: none; border-radius: 10px; font-weight: 800; cursor: pointer; margin-top: auto; transition: all 0.2s; }
.btn-add:hover { background: var(--accent); }
.btn-add:active { transform: scale(0.95); }

.qty-controls { display: flex; align-items: center; justify-content: space-between; background: #f1f5f9; border-radius: 10px; padding: 5px; margin-top: auto; }
.qty-btn { width: 32px; height: 32px; border: none; background: white; border-radius: 8px; font-weight: 900; cursor: pointer; color: var(--primary); box-shadow: 0 2px 4px rgba(0,0,0,0.05); }

/* Floating Nav */
.bottom-bar { position: fixed; bottom: 1.5rem; left: 1rem; right: 1rem; max-width: 500px; margin: 0 auto; background: var(--primary); color: white; border-radius: 25px; padding: 12px 24px; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.3); z-index: 1100; border: 1px solid rgba(255,255,255,0.1); }
.total-info { cursor: pointer; }
.total-info .label { font-size: 0.6rem; text-transform: uppercase; opacity: 0.7; font-weight: 800; letter-spacing: 0.5px; }
.total-info .val { font-size: 1.3rem; font-weight: 900; }
.action-icons { display: flex; gap: 12px; }
.action-btn { position: relative; width: 44px; height: 44px; border-radius: 14px; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,0.1); cursor: pointer; transition: all 0.2s; font-size: 1.1rem; }
.action-btn:hover { background: rgba(255,255,255,0.2); }
.badge { position: absolute; top: -6px; right: -6px; background: var(--danger); min-width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.7rem; font-weight: 900; border: 2px solid var(--primary); }

/* Drawers - IMPROVED ANIMATIONS */
.overlay { 
    position: fixed; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); z-index: 2000; 
    display: none; opacity: 0; transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1); 
}
.drawer { 
    position: fixed; bottom: 0; left: 0; right: 0; background: white; z-index: 2100; 
    border-radius: 32px 32px 0 0; max-height: 85vh; transform: translateY(110%); 
    transition: transform 0.5s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.3s, visibility 0.5s; 
    display: flex; flex-direction: column; opacity: 0; visibility: hidden; pointer-events: none;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.1);
}
.drawer.active { transform: translateY(0); opacity: 1; visibility: visible; pointer-events: auto; }

.drawer-header { padding: 20px 24px; border-bottom: 1px solid #f1f5f9; display: flex; justify-content: space-between; align-items: center; }
.drawer-header h3 { margin: 0; font-size: 1.25rem; font-weight: 800; color: var(--primary); }
.drawer-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.drawer-footer { padding: 24px; border-top: 1px solid #f1f5f9; background: #f8fafc; }

/* Desktop Right Drawer */
@media (min-width: 768px) {
    .drawer { 
        left: auto; right: 0; top: 0; bottom: 0; width: 450px; 
        max-height: 100vh; border-radius: 32px 0 0 32px; 
        transform: translateX(110%); 
    }
    .drawer.active { transform: translateX(0); }
}

/* Cart Item Styling */
.cart-item-row { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; padding: 12px; background: #f8fafc; border-radius: 16px; border: 1px solid #f1f5f9; }
.cart-item-img { width: 50px; height: 50px; border-radius: 10px; object-fit: cover; background: white; border: 1px solid #eee; }
.cart-item-details { flex: 1; }
.cart-item-name { font-weight: 700; font-size: 0.9rem; color: var(--primary); }
.cart-item-price { font-size: 0.8rem; color: var(--success); font-weight: 700; }

.input-group { margin-bottom: 1rem; }
.input-group label { display: block; font-size: 0.8rem; font-weight: 800; margin-bottom: 6px; color: var(--text-muted); text-transform: uppercase; }
.input-box { width: 100%; padding: 12px; border: 2px solid #e2e8f0; border-radius: 12px; font-size: 1rem; font-weight: 600; }
.input-box:focus { border-color: var(--accent); outline: none; }

/* Success State */
.success-msg { text-align: center; padding: 2rem; }
.success-msg i { color: var(--success); margin-bottom: 1rem; }
