/**
 * SP Post Grid Styles
 */

/* Main container */
.sp-post-grid-container {
    width: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    position: relative;
    margin: 0;
    padding-bottom: 50px;
    min-height: 780px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Filter overlay */
.sp-post-grid-overlay {
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sp-post-grid-overlay.active {
    display: block;
    opacity: 1;
}

/* Prevent body scroll when filter is open */
body.sp-filter-open-no-scroll {
    overflow: hidden;
}

/* Spring animation for filter dropdown using height instead of scale */
@keyframes spring-down {
    0% { height: 0; }
    60% { height: 711px; } /* Overshoot */
    80% { height: 661px; }  /* Bounce back */
    100% { height: 681px; } /* Final position */
}

/* Spring animation for filter dropdown closing */
@keyframes spring-up {
    0% { height: 641px; }
    60% { height: 100px; } /* Undershoot */
    80% { height: 50px; }  /* Bounce back */
    100% { height: 0; } /* Final position */
}

/* New keyframes for mobile filter sliding from bottom */
@keyframes slide-up-mobile {
    0% {
        bottom: -100vh;
        opacity: 0.8;
    }
    60% {
        bottom: 5vh; /* Spring effect: overshoot */
        opacity: 1;
    }
    80% {
        bottom: -2vh; /* Spring effect: bounce back */
        opacity: 1;
    }
    100% {
        bottom: 0;
        opacity: 1;
    }
}

@keyframes slide-down-mobile {
    0% {
        bottom: 0;
        opacity: 1;
    }
    100% {
        bottom: -100vh;
        opacity: 0;
    }
}

/* Sticky Header */
.sp-post-grid-header {
    position: sticky;
    top: 0;
    background-color: #fff;
    z-index: 10;
    width: 100%;
    transition: top 0.3s ease;
    padding-bottom: 15px;
    padding-top: 100px;
}


.sp-post-grid-header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 55px 0 0 0;
    max-width: 1200px;
    margin: 0 20px;
}

/* Filter section */
.sp-post-grid-filters {
    position: relative;
}

.sp-post-grid-filter-trigger {
    display: flex;
    align-items: center;
    background: none !important;
    border: none !important;
    padding: 10px 0px;
    font-size: 14px;
    font-weight: 600;
    color: black !important;
}

.sp-post-grid-filter-trigger:hover {
    background-color: #e1e1e1;
}

.sp-post-grid-filter-trigger .icon {
    width: 30px;
    height: 30px;
    margin-right: 15px;
    vertical-align: middle;
}

.sp-post-grid-filter-content {
    position: absolute;
    top: 100px;
    left: 0;
    width: 100%;
    z-index: 10;
    background-color: #fff;
    overflow: hidden;
}

.sp-post-grid-filter-content-inner {
    overflow: hidden;
}

.sp-post-grid-filter-content.opening {
    animation: spring-down 0.5s forwards;
    overflow-y: hidden;
}

.sp-post-grid-filter-content.closing {
    animation: spring-up 0.5s forwards;
    overflow-y: hidden;
}

.sp-post-grid-filter-inner {
    max-width: 1200px;
    margin: auto;
    height: 100%;
}

.sp-post-grid-filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 55px 0px;
}

.sp-post-grid-filter-groups {
    display: flex;
    justify-content: space-between;
    margin-bottom: 35px;
}

.sp-post-grid-filter-groups-news {
    display: flex;
    justify-content: left;
    gap: 125px;
    margin-bottom: 35px;
}

.sp-post-grid-filter-group {
    min-width: 140px;
}

.sp-post-grid-filter-group .double {
    display: grid;
    grid-template-columns: repeat(2, 250px);
    gap: 15px 100px;
}

.sp-post-grid-filter-label {
    font-size: 15px;
    margin-bottom: 10px;
    color: #222;
}

.sp-post-grid-filter-options {
    display: flex;
    flex-direction: column;
    gap: 17px;
    padding: 0;
    margin: 0;
    transition: height 0.3s ease;
}

/* Class added during transitions for smoother container adjustments */
.sp-post-grid-filter-options.transitioning {
    overflow: hidden;
}

.sp-post-grid-checkbox {
    display: flex;
    align-items: center;
    padding: 0;
    border-style: solid;
    border-radius: 3px;
    border-width: 1px;
    border-color: black;
    width: fit-content;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.sp-post-grid-checkbox label {
    padding: 0 15px;
    font-size: 12px;
    text-transform: uppercase;
    line-height: 1.7;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
}

/* Hide the native checkbox visually while keeping it accessible */
.sp-post-grid-filter-checkbox {
    display: none;
}

/* Style for when the real checkbox is checked */
.sp-post-grid-checkbox .sp-post-grid-filter-checkbox:checked + .sp-post-grid-filter-checkbox-label {
    background-color: black;
    color: white;
    padding-right: 35px; /* Make room for the X icon */
}

/* Add X icon for checked items */
.sp-post-grid-checkbox .sp-post-grid-filter-checkbox:checked + .sp-post-grid-filter-checkbox-label::after {
    content: "×";
    position: absolute;
    right: 12px;
    font-size: 18px;
    font-weight: bold;
    color: white;
    transition: all 0.3s ease;
}

/* Style for hover state */
.sp-post-grid-filter-checkbox:hover + .sp-post-grid-filter-checkbox-label {
    background-color: #f0f0f0;
}

/* Style for focus state for accessibility */
.sp-post-grid-filter-checkbox:focus + .sp-post-grid-filter-checkbox-label {
    outline: none;
}

.sp-post-grid-filter-buttons {
    display: flex;
    justify-content: right;
    gap: 10px;
    margin-top: 20px;
    border-top: 2px solid black;
}

.sp-post-grid-apply-button, 
.sp-post-grid-clear-button {
    padding: 12px 35px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 30px;
    margin-bottom: 30px;
}

.sp-post-grid-apply-button svg {
    width: 15px;
    height: 15px;
    margin-left: 40px;
}

.sp-post-grid-apply-button {
    color: #343434 !important;
    background-color: white;
    transition: all 0.3s ease;
}

.sp-post-grid-clear-button {
    color: white !important;
    background-color: #343434 !important;
    transition: all 0.3s ease;
}

.sp-post-grid-apply-button:hover {
    background-color: #343434 !important;
    color: #fff !important;
    border-color: #343434 !important;
}

.sp-post-grid-clear-button:hover {
    color: #343434 !important;
    background-color: white !important;
    transition: all 0.3s ease;
}

/* Search section */
.sp-post-grid-search {
    flex: 0 0 340px; /* Reduced from 250px to make it thinner */
    position: relative;
    color: #333;
}

.sp-post-grid-search:before {
    content: "";
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: contain;
    z-index: 1;
}

.sp-post-grid-search input {
    width: 100%;
    padding: 7px 15px 7px 38px !important; /* Added left padding for icon */
    border-radius: 50px !important; /* Fully rounded borders */
    font-size: 14px;
    outline: none;
    background-color: #f2f2f2 !important; /* Grey background */
}

.sp-post-grid-search input::placeholder {
    font-style: italic; /* Italic placeholder text */
    color: #545454;
}

.sp-post-grid-search input:focus {
    border-color: #1890ff;
    box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}

/* Posts grid container */
.sp-post-grid-posts {
    display: grid;
    grid-template-columns: repeat(auto-fill, 380px);
    gap: 25px;
    margin-bottom: 30px;
    width: auto;
    max-width: 86%;
    margin: 0 auto;
    margin-top: 40px;
}

@media screen and (min-width: 1240px) {
    .sp-post-grid-posts {
        max-width: 1200px;
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
        gap: 20px;
    }
    
    .sp-post-grid-header-inner {
        margin: auto;
    }
}

/* Individual post item */
.sp-post-grid-item {
    display: flex;
    flex-direction: column;
    background-color: #fff;
    border-radius: 8px;
}

.sp-post-grid-thumbnail {
    height: 300px;
    overflow: hidden;
    background-color: #f5f5f5;
    border-radius: 5px;
}

.sp-post-grid-thumbnail img {
    width: 100%;
    height: 100% !important;
    object-fit: cover;
    transition: transform 0.3s;
}

.sp-post-grid-item:hover .sp-post-grid-thumbnail img {
    transform: scale(1.05);
}

.sp-post-grid-content {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 200px;
    padding: 0;
    margin-top: 20px;
}

.sp-post-grid-main {
    display: flex;
    flex-direction: column;
}

.sp-post-grid-title {
    margin: 0 0 10px;
    font-size: 18px;
    font-weight: 400;
    color: black;
}

.sp-post-grid-excerpt {
    margin-bottom: 15px;
    font-size: 15px;
    color: black;
    line-height: 1.5;
}

.sp-post-grid-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: #999;
}

.sp-post-grid-readmore {
    display: inline-block;
    font-weight: bold;
    text-decoration: underline;
    font-size: 16px;
    color: black;
}

/* Pagination */
.sp-post-grid-pagination {
    display: flex;
    justify-content: center;
    margin-top: 40px;
    margin-bottom: 20px;
}

.sp-post-grid-pagination button {
    margin: 0 5px;
    padding: 8px 15px;
    background-color: #f1f1f1;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s;
}

.sp-post-grid-pagination .pagination-nav {
    display: flex;
    align-items: center;
    border: none;
    background: none;
    padding: 0;
    margin: 0 10px;
}

.sp-post-grid-pagination .pagination-nav:hover {
    border: none;
    background: none;
}

.sp-post-grid-pagination .pagination-nav:disabled {
    background: none;
    color: #999;
}

.sp-post-grid-pagination button .icon {
    width: 16px;
    height: 16px;
    vertical-align: middle;
}

.sp-post-grid-page-info {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 30px;
}

.sp-post-grid-page-info button {
    background-color: white;
    border-width: 1px !important;
    border-radius: 100% !important;
    padding: 7px 7px;
    margin: 0 5px;
    font-size: 15px;
    color: black;
    cursor: pointer;
}

.sp-post-grid-page-info div.number {
    width: 25px;
    height: 25px;
    padding-top: 1px;
}

.sp-post-grid-page-info button:hover {
    background-color: #e1e1e1;
    color: #333;
    border-color: black;
}

.sp-post-grid-page-info button.current {
    background-color: black;
    color: #fff;
    border-color: black;
}

.sp-post-grid-page-info button:disabled {
    color: #ccc;
    cursor: not-allowed;
}

.sp-post-grid-page-info button:disabled.current {
    border-color: black;
    cursor: not-allowed;
}

.sp-post-grid-page-first .icon,
.sp-post-grid-page-prev .icon {
    margin-right: 5px;
    transform: rotate(180deg);
}

.sp-post-grid-page-next .icon,
.sp-post-grid-page-last .icon {
    margin-left: 5px;
}

/* Loading state */
.sp-post-grid-loading {
    text-align: center;
    padding: 30px;
    grid-column: 1 / -1;
    color: #666;
}

.sp-post-grid-container.loading .sp-post-grid-posts {
    opacity: 0.6;
}

/* Utility classes */
.hidden {
    display: none !important;
}

/* Responsive styles */
@media (max-width: 768px) {
    .sp-post-grid-container {
        min-height: 300px;
    }

    .sp-post-grid-no-results {
        text-align: center;
    }

    .sp-post-grid-filter-groups {
        flex-direction: column;
        gap: 15px;
    }

    .sp-post-grid-filter-inner {
        overflow-y: scroll;
        /* Hide scrollbar */
        -ms-overflow-style: none;  /* IE and Edge */
        scrollbar-width: none;  /* Firefox */
    }

    .sp-post-grid-filter-groups::-webkit-scrollbar {
        display: none; /* Safari and Chrome */
    }

    .sp-post-grid-filter-groups .sp-post-grid-filter-options {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 10px 8px;
    }

    .sp-post-grid-filter-group {
        display: flex;
        flex-direction: column;
    }

    .sp-post-grid-filter-group .double {
        display: flex;
        flex-wrap: wrap;
        gap: 10px 8px;
    }

    .sp-post-grid-filter-buttons {
        display: flex;
        flex-direction: column;
        justify-content: center;
        margin-top: 20px;
        padding-top: 20px;
        border-top: 1px solid black;
    }
    .sp-post-grid-apply-button,
    .sp-post-grid-clear-button {
        width: 80%;
        padding: 12px 0;
        font-size: 18px;
        margin: auto;
    }

    .sp-post-grid-item {
        margin: 0 30px;
    }

    .sp-post-grid-header {
        padding-top: 10px;
        padding-bottom: 10px;
        top: 100px;
    }

    .sp-post-grid-header-inner {
        padding: 15px 0px;
        margin: 0px 20px 0px 30px;
        justify-content: space-between;
    }

    .sp-post-grid-filter-trigger .icon {
        width: 45px;
        height: 45px;
    }

    .sp-post-grid-search {
        flex: 0 0 75%;
    }

    .sp-post-grid-search input {
        padding: 8px 16px 8px 38px !important; /* Added left padding for icon */
        font-size: 16px;
    }

    .sp-post-grid-search:before {
        left: 12px;
    }

    .sp-post-grid-filter-inner {
        max-width: 100%;
        margin: 0 auto;
        padding: 20px;
    }

    .sp-post-grid-filter-header {
        padding-top: 100px;
        padding-bottom: 10px;
    }

    .sp-post-grid-filters {
        /* Hide the button content */
        width: 45px;
        overflow: hidden;
    }

    .sp-post-grid-posts {
        max-width: 100%;
        margin-top: 10px;
        position: relative;
    }

    .sp-post-grid-filter-content {
        position: fixed; /* Changed from absolute */
        top: unset;
        left: 0; /* Ensure full width */
        right: 0;
        width: 100%; /* Explicitly set width */
        height: 100vh; /* Full viewport height */
        z-index: 1000; /* Ensure it's on top */
    }

    .sp-post-grid-filter-content.opening {
        animation: slide-up-mobile 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; /* Apply new opening animation */
        /* overflow-y: auto; Ensure scrolling is enabled, remove hidden if previously set here */
    }

    .sp-post-grid-filter-content.closing {
        animation: slide-down-mobile 0.3s ease-out forwards; /* Apply new closing animation */
    }
}

@media (max-width: 480px) {
    .sp-post-grid-posts {
        grid-template-columns: 1fr;
    }
}

/* Post fade-in animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sp-post-grid-item {
    opacity: 0;
}

.sp-post-grid-item.animated {
    animation: fadeIn 0.5s ease forwards;
}

/* Staggered animation delay for grid items */
.sp-post-grid-item:nth-child(1) { animation-delay: 0.05s; }
.sp-post-grid-item:nth-child(2) { animation-delay: 0.1s; }
.sp-post-grid-item:nth-child(3) { animation-delay: 0.15s; }
.sp-post-grid-item:nth-child(4) { animation-delay: 0.2s; }
.sp-post-grid-item:nth-child(5) { animation-delay: 0.25s; }
.sp-post-grid-item:nth-child(6) { animation-delay: 0.3s; }
.sp-post-grid-item:nth-child(7) { animation-delay: 0.35s; }
.sp-post-grid-item:nth-child(8) { animation-delay: 0.4s; }
.sp-post-grid-item:nth-child(9) { animation-delay: 0.45s; }
.sp-post-grid-item:nth-child(10) { animation-delay: 0.5s; }
.sp-post-grid-item:nth-child(11) { animation-delay: 0.55s; }
.sp-post-grid-item:nth-child(12) { animation-delay: 0.6s; }