/* --- Global Styles & Variables --- */
:root {
    --primary-color: #007bff;
    --secondary-color: #6c757d;
    --bg-color: #f8f9fa;
    --text-color: #212529;
    --light-gray: #e9ecef;
    --white: #fff;
    --border-radius: 8px;
    --box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* --- Header --- */
header {
    background-color: var(--white);
    box-shadow: var(--box-shadow);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
    text-decoration: none;
}

.search-bar { flex-grow: 1; margin: 0 1.5rem; }
.search-bar input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--light-gray);
    border-radius: var(--border-radius);
}

.cart-icon {
    position: relative;
    cursor: pointer;
    font-size: 1.5rem;
}
.cart-badge {
    position: absolute;
    top: -5px;
    right: -10px;
    background-color: red;
    color: var(--white);
    border-radius: 50%;
    padding: 0.15em 0.4em;
    font-size: 0.75rem;
    font-weight: bold;
    display: none; /* Hidden by default */
}
.cart-badge.visible {
    display: block;
}

/* --- Main Page Layout (Home) --- */
.page-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    margin-top: 2rem;
}

/* --- Sidebar / Filters --- */
#filters details {
    border: 1px solid var(--light-gray);
    border-radius: var(--border-radius);
    padding: 1rem;
    background: var(--white);
}
#filters summary {
    font-weight: bold;
    cursor: pointer;
    list-style: none; /* Remove default marker */
}
#filters summary::-webkit-details-marker { display: none; } /* Chrome/Safari */
#filters summary::before { content: '▶ '; }
#filters[open] summary::before { content: '▼ '; }
#category-filters { margin-top: 1rem; }
#category-filters label {
    display: block;
    margin-bottom: 0.5rem;
    cursor: pointer;
}

/* --- Product Grid --- */
#product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1.5rem;
    
}
.product-card {
    background-color: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.product-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 12px rgba(0,0,0,0.15);
}
.product-card a {
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}
.product-card img {
    object-fit: cover;
    aspect-ratio: 0/1;
}
.product-info {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}
.product-title {
    font-size: 1.1rem;
    font-weight: 600;
    flex-grow: 1;
}
.product-price {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--primary-color);
    margin: 0.5rem 0;
}
.button {
    cursor: pointer;
    border: none;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
    font-weight: bold;
    text-align: center;
    text-decoration: none;
    display: inline-block;
}
.button.primary {
    background-color: var(--primary-color);
    color: var(--white);
}
.button.primary:hover { background-color: #0056b3; }
.button.secondary {
    background-color: var(--secondary-color);
    color: var(--white);
}
.button.secondary:hover { background-color: #5a6268; }

.add-to-cart-btn { width: 100%; margin-top: auto; }

/* --- Product Details Page --- */
.back-link {
    display: inline-block;
    margin: 2rem 0 1rem;
    color: var(--primary-color);
    text-decoration: none;
}
#product-details-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    background-color: var(--white);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}
.product-details-img {
    width: 100%;
    max-width: 400px;
    border-radius: var(--border-radius);
    justify-self: center;
}
.product-details-info .product-price { font-size: 1.8rem; margin: 1rem 0; }
.product-description { margin: 1rem 0; }
.category-chip {
    display: inline-block;
    background-color: var(--light-gray);
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.9rem;
}
.product-details-info .add-to-cart-btn { max-width: 200px; margin-top: 1rem; }

/* --- Cart Modal --- */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    animation: fadeIn 0.3s;
}
.modal.is-open { display: flex; }
.modal-content {
    background-color: var(--white);
    margin: auto;
    width: 90%;
    max-width: 500px;
    border-radius: var(--border-radius);
    display: flex;
    flex-direction: column;
    max-height: 80vh;
    animation: slideIn 0.3s;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--light-gray);
}
.close-button {
    border: none;
    background: none;
    font-size: 1.5rem;
    cursor: pointer;
}
#cart-items {
    padding: 1rem;
    overflow-y: auto;
    flex-grow: 1;
}
.cart-item {
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
    gap: 1rem;
}
.cart-item img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: var(--border-radius);
}
.cart-item-info { flex-grow: 1; }
.cart-item-title { font-weight: bold; }
.quantity-controls { display: flex; align-items: center; gap: 0.5rem; }
.quantity-btn {
    border: 1px solid var(--light-gray);
    background-color: var(--bg-color);
    width: 25px;
    height: 25px;
    border-radius: 50%;
    cursor: pointer;
}
.delete-item-btn {
    background: none;
    border: none;
    color: red;
    font-size: 1.2rem;
    cursor: pointer;
}
.cart-footer {
    padding: 1rem;
    border-top: 1px solid var(--light-gray);
}
.subtotal {
    display: flex;
    justify-content: space-between;
    font-size: 1.2rem;
    margin-bottom: 1rem;
}
.cart-actions { display: flex; justify-content: space-between; gap: 1rem; }
.cart-actions .button { flex-grow: 1; }
.empty-cart-message { text-align: center; color: var(--secondary-color); padding: 2rem 0; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { transform: translateY(-30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* --- Responsive Design (Tablet & Desktop) --- */
@media (min-width: 768px) {
    .page-layout {
        grid-template-columns: 250px 1fr;
    }
    #product-details-container {
        grid-template-columns: 1fr 1fr;
        align-items: start;
    }
}

/* --- Make Category Filters Sticky on Large Screens --- */
@media (min-width: 768px) {
  
    /* The .page-layout is the grid container. We need to ensure
       the grid item (#filters) doesn't stretch, which would
       prevent sticky positioning from working. */
    .page-layout {
        align-items: start; /* Aligns grid items to the top */
    }

    #filters {
        position: sticky;
        
        /* Sets the distance from the top of the viewport where the element
           will "stick". We add a little space below the header. 
           Adjust '95px' to match your header's height + desired margin. */
        top: 95px; 
      
        /* This is crucial for long filter lists. It prevents the sidebar
           from being taller than the screen, making all options accessible. */
        max-height: calc(100vh - 120px); /* 100% viewport height minus top offset & some padding */
        overflow-y: auto; /* Adds a scrollbar ONLY if the content overflows */
    }
}