/**
 * Custom Post Grid Widget CSS
 * Version: 1.1.0
 */

/* Grid Container */
.custom-post-grid-container {
    width: 100%;
    padding: 32px;
    box-sizing: border-box;
}

.custom-post-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-gap: 24px;
    width: 100%;
}

/* Card */
.custom-post-card {
    background-color: #FFFFFF;
    border-radius: 24px;
    box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    padding-bottom: 24px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(0);
    will-change: transform, box-shadow;
}

/* FIX 1: Make cards visible by default on frontend */
.custom-post-card {
    opacity: 1 !important;
    transform: translateY(0) !important;
}

/* FIX 1: Add subtle entrance animation that doesn't hide content */
body:not(.elementor-editor-active) .custom-post-card {
    animation: fadeInUp 0.6s ease-out forwards;
}

@keyframes fadeInUp {
    from {
        opacity: 0.8;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Keep editor performance optimizations */
body.elementor-editor-active .custom-post-card {
    animation: none !important;
    transition: none !important;
}

/* FIX 2: Card Hover Effects - Apply to entire card */
.custom-post-card:hover {
    transform: translateY(-8px);
    box-shadow: 0px 12px 40px rgba(0, 0, 0, 0.15);
}

.custom-post-card.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* Image Section */
.custom-post-image-wrapper {
    position: relative;
    width: 100%;
    overflow: hidden; /* FIX 2: Keep images contained within card */
}

.custom-post-main-image {
    width: 100%;
    height: auto;
    aspect-ratio: 16/9;
    object-fit: cover;
    display: block;
    border-radius: 24px 24px 0 0;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* FIX 2: Remove individual image hover effects */
.custom-post-card:hover .custom-post-main-image {
    transform: scale(1.05);
}

/* Image Overlay */
.custom-post-image-wrapper::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: transparent;
    pointer-events: none;
    z-index: 1;
    transition: background-color 0.3s ease;
}

.custom-post-image-wrapper.has-overlay::after {
    background-color: rgba(0, 0, 0, 0.2);
}

.custom-post-card:hover .custom-post-image-wrapper.has-overlay::after {
    background-color: rgba(0, 0, 0, 0.4);
}

/* Square Image - Updated positioning */
.custom-post-square-image-wrapper {
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 4px solid #FFFFFF;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.4s ease;
}

/* FIX 2: Square image hover effect coordinated with card */
.custom-post-card:hover .custom-post-square-image-wrapper {
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
    transform: scale(1.05);
}

/* Position classes for square image */
.custom-post-square-image-wrapper.position-bottom-right {
    right: 20px;
    bottom: -60px;
}

.custom-post-square-image-wrapper.position-bottom-left {
    left: 20px;
    bottom: -60px;
}

.custom-post-square-image-wrapper.position-top-right {
    right: 20px;
    top: 20px;
}

.custom-post-square-image-wrapper.position-top-left {
    left: 20px;
    top: 20px;
}

/* FIX 3: Add center positioning classes */
.custom-post-square-image-wrapper.position-center-right {
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
}

.custom-post-square-image-wrapper.position-center-left {
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
}

/* FIX 3: Maintain transform on hover for center positioned images */
.custom-post-card:hover .custom-post-square-image-wrapper.position-center-right,
.custom-post-card:hover .custom-post-square-image-wrapper.position-center-left {
    transform: translateY(-50%) scale(1.05);
}

.custom-post-square-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* FIX 2: Remove individual square image scale on hover */
.custom-post-card:hover .custom-post-square-image {
    transform: none;
}

/* Tags Section */
.custom-post-tags-wrapper {
    display: flex;
    flex-wrap: wrap;
    padding: 20px;
    padding-bottom: 0;
}

.custom-post-tag {
    display: inline-flex;
    align-items: center;
    background-color: #F2F2F2;
    color: #000000;
    font-size: 14px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 8px;
    margin-right: 8px;
    margin-bottom: 10px;
    font-family: "Inter", sans-serif;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: default;
}

.custom-post-tag:hover {
    background-color: #E0E0E0;
    transform: translateY(-2px);
}

.custom-post-tag i, 
.custom-post-tag svg {
    margin-right: 6px;
    width: 18px;
    height: 18px;
    transition: transform 0.3s ease;
}

.custom-post-tag:hover i,
.custom-post-tag:hover svg {
    transform: scale(1.2);
}

/* Title */
.custom-post-title {
    width: 100%;
    background-color: #C92A2A;
    color: #FFFFFF;
    font-size: 24px;
    font-weight: 700;
    font-family: "Inter", sans-serif;
    line-height: 1.4;
    padding: 20px;
    margin: 0;
    border-radius: 0;
    box-sizing: border-box;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.custom-post-card:hover .custom-post-title {
    background-color: #A52121;
}

/* Button */
.custom-post-button-wrapper {
    padding: 0 20px;
    margin-top: 16px;
}

.custom-post-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: #E6E6E6;
    color: #000000;
    font-size: 16px;
    font-weight: 600;
    font-family: "Inter", sans-serif;
    padding: 12px 20px;
    border-radius: 12px;
    text-decoration: none;
    text-align: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

.custom-post-button:hover {
    background-color: #D0D0D0;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Button Icon */
.custom-post-button .button-icon-before,
.custom-post-button .button-icon-after {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: transform 0.3s ease;
}

.custom-post-button .button-icon-before {
    margin-right: 8px;
}

.custom-post-button .button-icon-after {
    margin-left: 8px;
}

.custom-post-button:hover .button-icon-before,
.custom-post-button:hover .button-icon-after {
    transform: scale(1.1);
}

.custom-post-button i, 
.custom-post-button svg {
    width: 1em;
    height: 1em;
    vertical-align: middle;
}

/* Search Widget Styles */
.post-grid-search-wrapper {
    position: relative;
    width: 100%;
}

.post-grid-search-form {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
}

.post-grid-search-form.inline-layout {
    flex-direction: row;
}

.post-grid-search-form.stacked-layout {
    flex-direction: column;
}

.post-grid-search-form.minimal-layout .search-filters {
    display: none;
}

.search-field-wrapper {
    position: relative;
    flex: 1;
    min-width: 250px;
}

.search-input {
    width: 100%;
    font-size: 16px;
    transition: all 0.3s ease;
}

.search-input:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(201, 42, 42, 0.1);
}

/* Search icon size constraint */
.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.search-icon i,
.search-icon svg {
    width: 18px !important;
    height: 18px !important;
    max-width: 18px !important;
    max-height: 18px !important;
}

/* Clear button styling */
.clear-search {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
}

.clear-search i,
.clear-search svg {
    width: 16px !important;
    height: 16px !important;
    max-width: 16px !important;
    max-height: 16px !important;
}

.search-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
}

.search-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Filters */
.search-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    width: 100%;
}

.filter-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-width: 150px;
}

.filter-item label {
    font-size: 14px;
    font-weight: 600;
    color: #333;
}

.filter-dropdown {
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: #fff;
    font-size: 14px;
    transition: all 0.3s ease;
}

.filter-dropdown:focus {
    outline: none;
    border-color: #C92A2A;
}

/* Search Results */
.search-results {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    right: 0;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    max-height: 500px;
    overflow-y: auto;
    z-index: 1000;
}

.results-loader {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #C92A2A;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.results-content {
    padding: 20px;
}

.results-count {
    font-size: 14px;
    color: #666;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid #eee;
}

.search-result-item {
    display: flex;
    gap: 16px;
    padding: 16px 0;
    border-bottom: 1px solid #eee;
    transition: all 0.3s ease;
}

.search-result-item:hover {
    background-color: #f8f8f8;
    margin: 0 -20px;
    padding: 16px 20px;
}

.result-thumbnail {
    flex-shrink: 0;
}

.result-thumbnail img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
}

.result-content {
    flex: 1;
}

.result-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 8px 0;
}

.result-title a {
    color: #333;
    text-decoration: none;
    transition: color 0.3s ease;
}

.result-title a:hover {
    color: #C92A2A;
}

.result-meta {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: #666;
    margin-bottom: 8px;
}

.result-excerpt {
    font-size: 14px;
    color: #666;
    line-height: 1.5;
}

.no-results {
    text-align: center;
    padding: 40px;
    color: #666;
}

.view-all-results {
    display: block;
    text-align: center;
    padding: 16px;
    background-color: #f8f8f8;
    color: #C92A2A;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
}

.view-all-results:hover {
    background-color: #C92A2A;
    color: #fff;
}

/* Loading State */
.custom-post-card.is-loading {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
    100% {
        opacity: 1;
    }
}

/* Search visibility states */
.custom-post-card.search-hidden {
    display: none !important;
}

.custom-post-card.search-visible {
    display: block !important;
}

/* Responsive Styles */
@media (max-width: 1024px) {
    .custom-post-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .custom-post-title {
        font-size: 22px;
    }
    
    .custom-post-square-image-wrapper {
        width: 100px;
        height: 100px;
    }
    
    .custom-post-square-image-wrapper.position-bottom-right,
    .custom-post-square-image-wrapper.position-bottom-left {
        bottom: -50px;
    }
    
    .custom-post-button {
        font-size: 15px;
        padding: 10px 18px;
    }
}

@media (max-width: 767px) {
    .custom-post-grid-container {
        padding: 20px;
    }
    
    .custom-post-grid {
        grid-template-columns: 1fr;
    }
    
    .custom-post-card {
        max-width: 100%;
    }
    
    .custom-post-title {
        font-size: 20px;
        text-align: center;
    }
    
    .custom-post-tags-wrapper {
        justify-content: center;
    }
    
    .custom-post-button-wrapper {
        text-align: center;
    }
    
    .custom-post-square-image-wrapper {
        width: 90px;
        height: 90px;
    }
    
    /* Search Widget Mobile */
    .post-grid-search-form {
        flex-direction: column;
    }
    
    .search-field-wrapper {
        width: 100%;
        min-width: auto;
    }
    
    .search-filters {
        flex-direction: column;
    }
    
    .filter-item {
        width: 100%;
    }
    
    .search-result-item {
        flex-direction: column;
    }
    
    .result-thumbnail img {
        width: 100%;
        height: 200px;
    }
}