:root {
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --text-color: #212529;
    --border-color: #e9ecef;
    --primary-color: #0d6efd;
    --primary-hover: #0b5ed7;
    --danger-color: #dc3545;
    --success-color: #198754;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    max-width: 1300px; /* 🟢 Increased from 900px to allow side-by-side elements */
    margin: 40px auto;
    padding: 0 20px;
}


h1, h2 {
    color: #1a1a1a;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 8px;
}

.products-grid {
    display: grid;
    /* This automatically creates as many columns as fit, with a minimum width of 240px per card */
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;         /* Adds a nice clean breathing space between your product cards */
    width: 100%;       /* Spans across the entire available left-hand catalog column space */
}

/* 🎴 Clean Card Scoping */
.product-card {
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between; /* Keeps titles, prices, and buttons perfectly aligned at the bottom */
    height: 100%;                  /* Forces all product cards in a row to match heights beautifully */
}

.product-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.product-card h3 { 
    margin: 0 0 8px 0; 
    font-size: 1.2rem;
}

/* 🖼️ Constrains the placeholder images to their card frames */
.product-img-placeholder {
    width: 100%;
    height: 160px;
    background-color: #eaeef2;
    border-radius: 6px;
    margin-bottom: 12px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.product-img-placeholder img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 📝 Keeps the description clean, padded, and safely bounded */
.product-description {
    font-size: 0.9rem;
    color: #6c757d;
    margin: 0 0 16px 0 !important;
    line-height: 1.4;
    min-height: 40px;                 
    
    /* 🟢 Transitions handle the smooth expansion */
    display: block;
    overflow: hidden;                 /* Keep hidden during transition */
    transition: max-height 0.4s ease-in-out, opacity 0.3s ease;
    
    /* Set a max-height cap safely higher than your longest description text */
    max-height: 500px;                
    opacity: 1;
}

/* 🟢 When clamped, cleanly limit the height boundary and slightly fade */
.product-description.clamped {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    
    /* Set this to match your line-height cap (roughly 2 lines of text) */
    max-height: 44px;                 
    opacity: 0.9;
}

.toggle-link {
    color: #0066cc;
    font-size: 0.85rem;
    cursor: pointer;
    font-weight: bold;
    display: inline-block;
    margin-top: 4px;
}
.toggle-link:hover {
    text-decoration: underline;
}


/* 💵 Aligns price and button at the bottom of the card */
.card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
}

.product-price { 
    font-size: 1.1rem; 
    font-weight: bold; 
    margin: 0;
}

/* 🎛️ Standard Interactions */
button, .btn-add, .btn-qty, #checkout-action-button {
    cursor: pointer;
    font-weight: 600;
    border-radius: 6px;
    border: none;
    transition: background-color 0.2s;
}

.btn-add {
    padding: 8px 16px;
    background-color: var(--primary-color);
    color: white;
}
.btn-add:hover { background-color: var(--primary-hover); }

/* 🛒 Shopping Cart Display Table */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: 8px;
    margin: 20px 0;
}

th, td { padding: 12px 16px; }
th { background-color: #f1f3f5; font-weight: 600; }
td { border-bottom: 1px solid var(--border-color); }

.qty-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
}

.btn-qty { padding: 2px 8px; background-color: #e9ecef; }
.btn-qty:hover { background-color: #dee2e6; }

.cart-actions { display: flex; align-items: center; gap: 20px; margin-top: 20px; }

#empty-cart-btn {
    color: var(--danger-color);
    background: none;
    font-weight: 600;
    text-decoration: underline;
}

#checkout-action-button {
    padding: 10px 20px;
    background-color: var(--success-color);
    color: white;
}

.cart-item-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.cart-thumb {
    width: 45px;
    height: 45px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: #f1f3f5;
}

.cart-item-desc {
    font-size: 0.8rem;
    color: #6c757d;
    margin: 2px 0 0 0;
}
/* 🔐 Authentication Box Profile Styling */
.auth-box {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 30px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.auth-box h3 {
    margin-top: 0;
    margin-bottom: 12px;
}
.auth-input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}
.auth-input-group input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.95rem;
}
.auth-actions-row {
    display: flex;
    gap: 10px;
}
.auth-actions-row button {
    padding: 8px 16px;
}
#btn-login { background-color: var(--primary-color); color: white; }
#btn-login:hover { background-color: var(--primary-hover); }
#btn-register { background-color: #6c757d; color: white; }
#btn-register:hover { background-color: #5c636a; }
#btn-logout { background-color: var(--danger-color); color: white; }

.password-wrapper {
  position: relative;
  display: inline-block;
  width: 100%;
  max-width: 300px;
}

.password-wrapper input {
  width: 100%;
  padding-right: 40px; /* Make room so text doesn't hide under the button */
  box-sizing: border-box;
}

.password-wrapper button {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

/* Normal state */
#auth-username {
  border: 1px solid #ccc;
  background-color: #fff;
}

/* Error state applied by JavaScript */
#auth-username.is-invalid {
  border-color: red;
  background-color: #ffe6e6;
}


/* ==========================================
   🟢 CLEAR DESKTOP BASE STYLES (Screen widths > 768px)
   ========================================== */

/* 1. Wrap your entire application content below your Login area */
.store-layout-container {
    display: flex !important;
    flex-direction: row !important; /* Forces side-by-side on desktop */
    gap: 30px !important;
    max-width: 1300px !important;
    margin: 20px auto !important;
    padding: 0 20px !important;
    align-items: flex-start !important;
}

/* 2. Left side: The catalog scrolls independently */
.catalog-section {
    flex: 1 !important;
    min-width: 0 !important;
}

/* FORCE BREAKOUT GRID SYSTEM */
.products-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)) !important;
    gap: 25px !important;
    width: 100% !important;
    box-sizing: border-box !important;
    align-content: start !important;
    padding: 10px 0 !important;
}

/* FIX INDIVIDUAL DYNAMIC PRODUCT CARDS */
.product-card {
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    background: #ffffff !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 12px !important;
    padding: 16px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04) !important;
    height: auto !important;
    margin: 0 !important;
}

/* 3. Right side: The Cart is pinned to the view */
.cart-sidebar-section {
    width: 380px !important;       /* Explicit fixed width on desktop */
    position: sticky !important;    /* Floating follow scroll behavior */
    top: 20px !important;
    background: #ffffff !important;
    border: 1px solid #e0e0e0 !important;
    border-radius: 8px !important;
    padding: 20px !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05) !important;
    max-height: calc(100vh - 40px) !important;
    display: flex !important;
    flex-direction: column !important;
}

/* 4. Internal Scroll Box: The table scrolls inside the fixed cart box */
#cart-display-wrapper {
    overflow-y: auto !important;
    flex: 1 !important;
    margin-bottom: 15px !important;
}

#cart-display-wrapper table {
    width: 100% !important;
    border-collapse: collapse !important;
}


/* ==========================================
   📱 ISOLATED MOBILE RULES (Screen widths <= 768px only)
   ========================================== */
@media screen and (max-width: 768px) {
    .store-layout-container {
        flex-direction: column !important; /* Stack columns vertically on phones */
        padding: 0 10px !important;
        gap: 20px !important;
    }

    .catalog-section {
        width: 100% !important;
    }

    .products-grid {
        grid-template-columns: 1fr !important; /* Single card width on mobile phones */
    }

    .cart-sidebar-section {
        width: 100% !important;        /* Expand cart to full layout width */
        position: static !important;     /* Kill sticky overlap anchor */
        max-height: none !important;     /* Expand vertical container box naturally */
        margin-top: 20px !important;
    }


/* ==========================================
   📱 ISOLATED MOBILE RULES (Screen widths <= 768px only)
   ========================================== */
@media screen and (max-width: 768px) {
    
    /* ... Keep all your existing container/grid mobile overrides here ... */

    /* 🟢 NEW: Prevent the table from forcing a horizontal scroll */
    #cart-display-wrapper table {
        display: block !important;       /* Lets the table adjust fluidly like a block box */
        width: 100% !important;
        overflow-x: hidden !important;   /* Disables the awkward horizontal swipe behavior */
    }

    /* 🟢 NEW: Hide the "Total Column" text header cells to reclaim horizontal space */
    #cart-display-wrapper th:nth-child(4),
    #cart-display-wrapper td:nth-child(4) {
        display: none !important;        /* Hides the redundant individual item total cell on phones */
    }

    /* 🟢 NEW: Dynamically shrink descriptions so they stay on a single line inside the row */
    .cart-item-desc {
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important; /* Truncates long text strings with a clean "..." */
        max-width: 140px !important;       /* Keeps description from pushing the row wider */
    }

    /* 🟢 NEW: Make paddings tight so the columns sit inside the layout frame comfortably */
    #cart-display-wrapper th, 
    #cart-display-wrapper td {
        padding: 8px 4px !important;       /* Shaves off blank padding spaces */
        font-size: 0.85rem !important;     /* Slightly text-scales details for clean phone viewports */
    }

    /* 🟢 NEW: Keep item images extra tiny in the mobile grid list row */
    .cart-thumb {
        width: 32px !important;
        height: 32px !important;
    }
}

/* 🟢 Pinned Sticky Footer Configuration */
    #mobile-cart-bar {
        display: block; /* Managed by JS, but activated for mobile dimensions */
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100% !important;
        background: #1a1a1a !important; /* Dark theme contrast colors */
        color: #ffffff !important;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.15) !important;
        z-index: 9999 !important; /* Forces it to hover over all layout cards */
        padding: 12px 20px !important;
        box-sizing: border-box !important;
    }

    .mobile-bar-content {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        max-width: 100%;
    }

    #mobile-bar-count, #mobile-bar-total {
        font-weight: 600 !important;
        font-size: 0.95rem !important;
    }

    .mobile-bar-btn {
        background-color: var(--success-color) !important;
        color: white !important;
        padding: 8px 16px !important;
        border-radius: 6px !important;
        font-size: 0.9rem !important;
        font-weight: bold !important;
    }
    
    /* Ensure the actual cart section at the bottom has extra spacing so it isn't blocked by the bar */
    .cart-sidebar-section {
        margin-bottom: 80px !important;
    }
}


}


html {
    scroll-behavior: smooth;
}

