/* Base styles */
.worksheets-filter-wrapper { /* Renamed class */
    display: flex;
    gap: 20px;
    margin: 0px;
    flex-wrap: wrap;
}

.filter-sidebar {
    width: 250px;
    flex-shrink: 0;
}

/* NEW: Clear All Button Style */
#clear-all-filters {
    background-color: #ff7b25;
    color: white;
    border: none;
    padding: 8px 15px;
    text-align: center;
    text-decoration: none;
    display: inline-block; 
    font-size: 14px;
    margin: 10px 0 20px;
    cursor: pointer;
    border-radius: 5px;
    font-weight: bold;
    width: 100%; 
    transition: background-color 0.2s;
    z-index: 100;
    position: relative;
    touch-action: manipulation;
}

#clear-all-filters:hover {
    background-color: #e56c1d;
}

/* NEW: Active Filters Container */
.active-filters-container {
    margin: 0 0 20px 0;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background-color: #f7f7f7;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

.active-filters-title {
    font-weight: bold;
    color: #333;
    margin-right: 10px;
    font-size: 14px;
    flex-shrink: 0;
}

.active-filters-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Individual Active Filter Item */
.active-filter-item {
    display: inline-flex;
    align-items: center;
    background-color: #586D96; /* Dark blue color */
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: background-color 0.2s;
    line-height: 1; /* Ensure clean alignment */
}

.active-filter-item:hover {
    background-color: #435474;
}

/* Removal Button */
.filter-remove-btn {
    margin-left: 8px;
    font-weight: bold;
    font-size: 16px;
    cursor: pointer;
    line-height: 1;
}

/* Responsive adjustment for Active Filters */
@media (max-width: 480px) {
    .active-filters-container {
        flex-direction: column;
        align-items: flex-start;
    }
    .active-filters-title {
        margin-bottom: 5px;
    }
}
/* END NEW STYLES */

.worksheets-grid { /* Renamed class */
    flex: 1;
}

/* The grid template is now set inline in PHP to force 3 columns. */
.worksheet-cards-grid {
    /* Only using gap here as the main grid display properties are now inline in PHP */
    gap: 16px;
}

/* 櫨 USE FLEXBOX ON GRID ITEM TO ALIGN CONTENT VERTICALLY */
.grid-item-worksheet {
    background: #fff;
    /* Border color set to #efefef (Confirmed) */
    border: 1px solid #efefef!important;
    padding: 0px;
    border-radius: 6px;
    text-align: center;
    font-size:15px;
    /* ADDED: Smooth transition for border color change */
    transition: border-color 0.2s ease-in-out; 
    
    /* 泊 Flexbox setup for internal content alignment and pushing button down */
    display: flex;
    flex-direction: column; 
    justify-content: space-between; 
}

/* NEW FIX: Explicitly set border color on hover to prevent "orange" override from external CSS */
.grid-item-worksheet:hover {
    /* Subtle change to a light gray for feedback, ensuring it's NOT orange. */
    border-color: #ccc; 
}

.grid-item-worksheet h4 {
    font-size: 18px;
    /* CHANGE: Reduced margin for tighter gap */
    margin-top: 5px; 
    margin-bottom: 5px; 
    margin-left:10px;
    margin-right:10px;
    font-family:Avenir Next Demi Bold !important;
    flex-shrink: 0; 
}

/* 泊 Image container allows it to stretch and maximize vertical space */
.grid-item-worksheet a.thumb {
    flex-grow: 1; 
    display: block; 
    /* CHANGE: Reduced margin for tighter gap */
    margin-bottom: 5px; 
    overflow: hidden; 
}

.grid-item-worksheet img {
    display: block;
    width: 100%;
    /* 泊 Make the image fill the available container height */
    height: 100%; 
    object-fit: cover; 
    border-radius: 0;
}


.grid-item-worksheet p {
    font-size: 16px;
    color: #586D96;
    padding:0px 5px 0px 5px !important;
    max-height: none;
    overflow: visible;
    position: static;
    margin-bottom: 10px; 
    line-height: 1.4; 
    flex-shrink: 0; 
}

.grid-item-worksheet p::after {
    content: none;
}

.worksheet-label { /* Renamed class */
    font-size: 16px;
    display: block;
    margin: -5px 0;
}

/* NEW: Download Button Style (based on image) */
.grid-item-worksheet a.worksheet-view-button {
    /* Blue Background */
    background-color: #0e76bc; 
    /* White Text */
    color: white !important; 
    border: none;
    padding: 10px 20px;
    margin: 0 auto 15px; 
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    /* Rounded Corners */
    border-radius: 15px; 
    /* Display as inline-flex to match image and include icon */
    display: inline-flex; 
    align-items: center;
    text-decoration: none;
    transition: background-color 0.2s;
    
    /* 泊 Ensure button stays at the bottom and is not stretched */
    margin-top: auto; 
    flex-shrink: 0;
}

.grid-item-worksheet a.worksheet-view-button:hover {
    /* Slightly darker blue on hover */
    background-color: #f0564f; 
}

/* Responsive Styles */

/* <= 768px: Sidebar on top, and Tablet/Mid-size screen layout (2 columns) */
@media (max-width: 768px) {
    .worksheets-filter-wrapper { /* Renamed class */
        flex-direction: column;
    }

    .filter-sidebar {
        width: 100%;
        margin-bottom: 0px;
    }
    
    #clear-all-filters {
        display: none !important; 
    }

    /* Force 2 columns for tablet/small screens */
    .worksheet-cards-grid { 
        display: grid !important; /* Re-declare for media query priority */
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 16px; /* Ensure gap is applied */
    }

    /* === EXCERPT LOGIC FIXED === */
    .grid-item-worksheet p {
        max-height: 75px;
        overflow: hidden;
        position: relative;
        padding-right: 1em; 
    }

    /* Create the ellipsis effect */
    .grid-item-worksheet p::after {
        content: "...";
        position: absolute;
        bottom: 0;
        right: 0;
        padding: 0 5px 0 10px;
        background: #f9f9f9; 
    }
}

/* <= 480px: Small mobile layout (1 column) */
@media (max-width: 480px) {
    /* Force 1 column for small phones */
    .worksheet-cards-grid { 
        display: grid !important; /* Re-declare for media query priority */
        grid-template-columns: 1fr !important;
        gap: 16px;
    }
    
    .grid-item-worksheet {
        background: #f9f9f9;
        padding: 0px;
        /* Border color set to #efefef (Confirmed and kept) */
        border: 1px solid #efefef; 
        text-align: center;
    }

    .grid-item-worksheet h4 {
        font-size: 16px!important;
    }

    .grid-item-worksheet p {
        font-size: 13px;
        padding: 05px;
        color: #586D96;
        margin-top:-15px!important;
    }

    .worksheet-label { /* Renamed class */
        font-size: 12px;
        display: block;
        margin: -5px 0;
    }
}

/* Pagination container */
.worksheets-pagination { /* Renamed class */
    display: flex;
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
}

/* Pagination links */
.worksheets-pagination a, /* Renamed class */
.worksheets-pagination span { /* Renamed class */
    display: inline-block;
    padding: 8px 14px;
    margin: 2px;
    font-size: 15px;
    color: #333;
    border: 1px solid #ddd;
    border-radius: 5px;
    background: #fff;
    text-decoration: none;
    transition: all 0.2s ease-in-out;
}

/* Hover effect */
.worksheets-pagination a:hover { /* Renamed class */
    background: #f0f0f0;
    border-color: #ccc;
}

/* Active page */
.worksheets-pagination .current { /* Renamed class */
    background: #4CAF50;
    color: #fff !important;
    border-color: #4CAF50;
    font-weight: bold;
}

/* Next/Prev arrows */
.worksheets-pagination .prev, /* Renamed class */
.worksheets-pagination .next { /* Renamed class */
    font-weight: bold;
}

/* Disabled state for prev/next if needed */
.worksheets-pagination .disabled { /* Renamed class */
    opacity: 0.5;
    pointer-events: none;
}

/* Loader overlay for grid only */
.worksheets-loader { /* Renamed class */
    display: none;
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(255,255,255,0.7);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.worksheets-loader.active { /* Renamed class */
    display: flex;
    opacity: 1;
}

.worksheets-loader::after { /* Renamed class */
    content: "";
    width: 40px;
    height: 40px;
    border: 4px solid #ff7b25;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Make grid items fill columns neatly */
.grid-item-worksheet {
    background: #fff;
    border: 1px solid #efefef; 
    padding: 0px;
    border-radius: 6px;
    text-align: center;
    font-size:15px;
}

.total-worksheets-count { /* Renamed class */
    font-size: 18px;
    font-weight: bold;
    color: #19306C; 
    text-align: center;
    margin: 10px 0px 20px;
    font-family: Avenir Next Demi Bold;
    letter-spacing: 1px;
    text-transform: uppercase;
}