/* Basic styling for the Families page layout */
.families-page-wrapper {
    /* Removed redundant padding. The parent <main class="container"> in base.html already handles global padding and max-width. */
    box-sizing: border-box;
    width: 100%; /* Ensure it explicitly takes 100% of the parent's content area */
}

/* Ensure all images stay within their containers and reset any external defaults */
img {
    max-width: 100%;
    height: auto;
    display: block; /* Helps remove extra space below images */
}

.families-page-content {
    display: grid;
    grid-template-columns: 1fr; /* Default to single column on small screens */
    gap: 2rem; /* Gap between main content and sidebar */
    padding-top: 2rem;
    padding-bottom: 2rem;

    /* Removed `overflow: hidden` from here. We'll control overflow at a higher level (html/body)
       to avoid potentially hiding legitimate content, and rely on `min-width: 0` for grid items. */
    width: 100%; /* Ensures the grid respects the width of its parent (families-page-wrapper) */
}

@media (min-width: 768px) {
    .families-page-content {
        /* This is the key for products on left (main-content), filters on right (sidebar) */
        /* minmax(0, 1fr) allows the main content area to shrink as needed, preventing overflow */
        grid-template-columns: minmax(0, 1fr) 250px;
    }
}

.main-content {
    /* Critical for ensuring content inside a grid cell doesn't force the cell to be wider than its allocated space */
    min-width: 0;
    /* Explicitly fill its grid column space */
    width: 100%;
    /* Removed `overflow-x: hidden` from here. If there's an internal overflow problem, we want to see it,
       and general page overflow is handled by `html, body`. */
}

/* The families-breadcrumbs and families-header are within main-content, so they'll be on the left */
.families-breadcrumbs {
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    color: #6c757d;
    padding: 1rem 1.5rem;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    border: 1px solid rgba(255,255,255,0.3);
}

.families-breadcrumbs a {
    color: #667eea;
    text-decoration: none;
    transition: color 0.3s ease;
}

.families-breadcrumbs a:hover {
    text-decoration: underline;
}

.families-breadcrumbs .current-page {
    font-weight: bold;
    color: #333;
}

/* Styling for the sidebar, which is correctly placed on the right by families-page-content grid */
.sidebar {
    padding: 1rem;
    background-color: #f8f9fa;
    border-radius: 8px;
    /* Ensure sidebar also respects its own width and doesn't overflow */
    min-width: 0;
    /* Removed `overflow-x: hidden` from here for similar reasons as main-content. */
}

.sidebar h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: #333;
    display: none; /* Hide this title as it's not in the screenshot */
}

/* New search box for filters */
.filter-search-box {
    display: flex;
    margin-bottom: 1.5rem;
    border: 1px solid #ced4da;
    /* Apply rounded corners to the search box container */
    border-radius: 9999px; /* This makes it pill-shaped */
    overflow: hidden; /* Ensures child input/button respect the border-radius */
}

.filter-search-input {
    flex-grow: 1;
    padding: 0.5rem 0.75rem;
    border: none; /* Remove individual border */
    outline: none;
    font-size: 1rem;
    /* Match background of parent filter-search-box for seamless look */
    background-color: #fff;
}

.filter-search-btn {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.15s ease-in-out;
}

.filter-search-btn:hover {
    background-color: #0056b3;
}


.filter-section {
    margin-bottom: 1.5rem;
}

.filter-section h3 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    color: #555;
}

.filter-dropdown, .sort-dropdown {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ced4da;
    /* NEW: Make it pill-shaped for rounded corners */
    border-radius: 9999px; /* This makes it pill-shaped */
    background-color: #fff;
    font-size: 1rem;
    cursor: pointer;
    appearance: none; /* Remove default dropdown arrow */
    -webkit-appearance: none;
    -moz-appearance: none;
    /* Custom arrow for appearance */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%236c757d'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 16px 12px;
}

.families-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
    width: 100%; /* Ensure header takes full width of main-content */
}

.families-header .results-info {
    font-size: 0.9rem;
    color: #6c757d;
}

/* Remove the H1 from families-header as it's not in the screenshot */
.families-header h1 {
    display: none;
}

.sort-options {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0;
}

/* Product Grid (4 columns) */
.product-grid {
    display: grid;
    /* To fit 4 columns: 4 * (card_width) + 3 * (gap) <= available_width */
    /* With ~886px available for main-content, 4 columns of 200px + 3 gaps (24px each) = 800 + 72 = 872px. */
    /* This should comfortably fit 4 columns. If still 2, reduce minmax(180px, 1fr) */
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;

    min-width: 0; /* Crucial for grid items to shrink */
    width: 100%; /* Ensure grid takes full width of main-content */
}

.product-card {
    background-color: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px; /* Maintain existing card corner radius */
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s ease-in-out;

    min-width: 0; /* Ensures card content respects its boundaries */
    word-wrap: break-word; /* Important for long product names/descriptions */

    /* Make sure the card takes full height in the grid */
    height: 100%;
}

.product-card:hover {
    transform: translateY(-5px);
}

.product-image {
    max-width: 100%;
    height: 150px; /* Fixed height for consistency */
    object-fit: contain; /* Ensure image fits without cropping */
    margin-bottom: 1rem;
    border-radius: 4px;
}

.product-title {
    font-size: 1.2rem;
    color: #007bff; /* Primary color */
    margin-bottom: 0.5rem;
}

.product-description {
    font-size: 0.9rem;
    color: #6c757d;
    margin-bottom: 1rem;
    flex-grow: 1; /* Allows descriptions of different lengths to push button to bottom */
}

.product-price {
    font-size: 1.3rem;
    font-weight: bold;
    color: #28a745; /* Success color */
    margin-bottom: auto; /* This pushes the button to the bottom */
}

.btn {
    display: inline-block;
    padding: 0.75rem 1.25rem;
    border-radius: 0.3rem;
    text-decoration: none;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.15s ease-in-out;
    border: none;
    outline: none;

    /* Stick to bottom with margin */
    margin-top: auto;
    margin-bottom: 10px;
}

.btn-primary {
    color: #fff;
    background-color: #007bff;
    border-color: #007bff;
}

.btn-primary:hover {
    background-color: #0056b3;
    border-color: #0056b3;
    transform: translateY(-1px);
}

/* Google Ad Placeholders */
.google-ad-unit {
    background-color: #e9ecef;
    border: 1px dashed #adb5bd;
    padding: 1rem;
    text-align: center;
    color: #6c757d;
    font-style: italic;
    margin-top: 1.5rem;
    min-height: 100px; /* Minimum height for ad units */
    display: flex;
    align-items: center;
    justify-content: center;
}

.google-ad-bottom {
    margin-top: 2rem;
    text-align: center;
}

/* Responsive adjustments for header */
@media (max-width: 576px) {
    .families-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 2rem;
    gap: 0.5rem;
}

.pagination a, .pagination span {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 35px;
    height: 35px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    text-decoration: none;
    color: #007bff;
    background-color: #fff;
    transition: all 0.2s ease;
}

.pagination a:hover {
    background-color: #e9ecef;
    border-color: #007bff;
}

.pagination .current-page {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
    font-weight: bold;
}

.pagination .disabled {
    pointer-events: none;
    opacity: 0.6;
    background-color: #e9ecef;
    color: #6c757d;
}