/* ============================================================
   Case Study Portfolio – Styles
   Matches the ECF Blog Filter design system
   ============================================================ */

/* Main Wrapper */
.csp-blog-wrapper {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    box-sizing: border-box;
    overflow-x: hidden;
}

.csp-blog-wrapper *,
.csp-blog-wrapper *::before,
.csp-blog-wrapper *::after {
    box-sizing: border-box;
}

/* ─── Search & Filter Bar ───────────────────────────────────── */
.csp-blog-search-filter-wrapper {
    margin-bottom: 40px;
    background-color: #f5f5f5;
    padding: 20px;
    border-radius: 8px;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.csp-blog-search-form {
    width: 100%;
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
}

/* Search Box */
.csp-blog-search-box {
    flex: 1;
    min-width: 200px;
    position: relative;
    display: flex;
    align-items: center;
}

.csp-blog-search-icon {
    position: absolute;
    left: 15px;
    pointer-events: none;
    z-index: 1;
}

.csp-blog-search-field {
    width: 100%;
    padding: 12px 15px 12px 45px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease;
    background-color: #ffffff;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    box-sizing: border-box;
}

.csp-blog-search-field:focus {
    border-color: #0a4d8c;
}

/* Category Dropdown */
.csp-blog-category-menu-wrapper {
    min-width: 180px;
    position: relative;
}

.csp-blog-category-select {
    width: 100%;
    min-width: 180px;
    padding: 12px 35px 12px 15px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background-color: #ffffff;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s ease;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill='%23333' d='M7 8l6 6 6-6z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    box-sizing: border-box;
}

.csp-blog-category-select:focus {
    border-color: #0a4d8c;
}

.csp-blog-category-select option {
    padding: 10px;
}

/* ─── Posts Grid ────────────────────────────────────────────── */
.csp-post-grid {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 30px;
    width: 100%;
    box-sizing: border-box;
}

/* ─── Post Card ─────────────────────────────────────────────── */
.csp-post-item {
    background: #ffffff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
}

.csp-post-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Thumbnail */
.csp-post-thumb {
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    overflow: hidden;
    background-color: #f0f0f0;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

.csp-post-thumb img,
.csp-post-thumb img.csp-full-img,
.csp-post-thumb a img {
    width: 100% !important;
    height: auto !important;
    max-width: 100% !important;
    max-height: none !important;
    min-height: 0 !important;
    object-fit: contain !important;
    object-position: center !important;
    display: block !important;
    aspect-ratio: auto !important;
    transition: transform 0.2s ease;
}

.csp-post-item:hover .csp-post-thumb img {
    transform: scale(1.05);
}

.csp-post-thumb a {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    line-height: 0;
}

.csp-post-cats {
    position: absolute;
    top: 10px;
    left: 10px;
    background-color: rgba(10, 77, 140, 0.9);
    color: #ffffff;
    padding: 5px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    z-index: 1;
}

/* Content */
.csp-post-content {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.csp-post-title {
    margin: 0 0 10px 0;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.4;
}

.csp-post-title a {
    color: #111111;
    text-decoration: none;
    transition: color 0.2s ease;
}

.csp-post-title a:hover {
    color: #0a4d8c;
}

.csp-post-meta {
    margin-bottom: 12px;
    font-size: 12px;
    color: #666666;
}

.csp-post-date {
    font-size: 12px;
    color: #999999;
}

.csp-post-excerpt {
    margin-bottom: 15px;
    font-size: 14px;
    color: #555555;
    line-height: 1.5;
    flex: 1;
}

.csp-post-readmore {
    display: inline-block;
    padding: 8px 15px;
    background-color: #0a4d8c;
    color: #ffffff;
    text-decoration: none;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    transition: background-color 0.2s ease;
    align-self: flex-start;
}

.csp-post-readmore:hover {
    background-color: #083968;
    color: #ffffff;
}

/* No Posts */
.csp-no-posts {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px;
    font-size: 16px;
    color: #666666;
    width: 100%;
}

/* ─── Load More ─────────────────────────────────────────────── */
.csp-load-more-wrapper {
    text-align: right;
    margin-top: 30px;
    margin-bottom: 20px;
}

.csp-load-more-btn {
    display: inline-block !important;
    padding: 12px 30px !important;
    background-color: #006938 !important;
    color: #ffffff !important;
    border: none !important;
    border-radius: 6px !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    transition: background-color 0.2s ease, transform 0.2s ease !important;
    font-family: inherit !important;
    text-decoration: none !important;
}

.csp-load-more-btn:hover:not(:disabled) {
    background-color: #004d2a !important;
    transform: translateY(-2px) !important;
}

.csp-load-more-btn:active:not(:disabled) {
    transform: translateY(0);
}

.csp-load-more-btn:disabled {
    background-color: #94a3b8 !important;
    cursor: not-allowed !important;
    opacity: 0.7;
}

/* Loading spinner */
.csp-load-more-btn.csp-loading {
    pointer-events: none;
    opacity: 0.7;
}

.csp-load-more-btn.csp-loading::after {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-left: 8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: csp-spin 0.6s linear infinite;
    vertical-align: middle;
}

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

/* Grid fade-in for newly loaded cards */
.csp-post-item.csp-fade-in {
    animation: cspFadeUp 0.4s ease forwards;
}

@keyframes cspFadeUp {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Responsive ────────────────────────────────────────────── */

/* Tablet landscape / small desktop — 1024px */
@media (max-width: 1024px) {
    .csp-blog-wrapper {
        padding: 16px;
    }

    .csp-post-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 24px;
    }
}

/* Tablet portrait — 768px */
@media (max-width: 768px) {
    .csp-blog-wrapper {
        padding: 12px;
    }

    .csp-blog-search-filter-wrapper {
        padding: 16px;
        margin-bottom: 24px;
    }

    .csp-blog-search-form {
        flex-direction: column;
        gap: 12px;
    }

    .csp-blog-search-box {
        width: 100%;
        min-width: 0;
    }

    .csp-blog-category-menu-wrapper {
        width: 100%;
        min-width: 0;
    }

    .csp-blog-category-select {
        width: 100%;
        min-width: 0;
    }

    .csp-blog-search-field {
        font-size: 16px;   /* prevents iOS auto-zoom on focus */
        padding: 14px 15px 14px 45px;
    }

    .csp-blog-category-select {
        font-size: 16px;   /* prevents iOS auto-zoom on focus */
        padding: 14px 35px 14px 15px;
    }

    .csp-post-grid {
        grid-template-columns: 1fr !important;
        gap: 20px;
    }

    .csp-post-title {
        font-size: 17px;
    }

    .csp-post-content {
        padding: 16px;
    }

    .csp-post-readmore {
        padding: 10px 18px;
        font-size: 14px;
    }

    .csp-load-more-wrapper {
        text-align: left;
        margin-top: 24px;
    }

    .csp-load-more-btn {
        width: 100% !important;
        max-width: 320px !important;
        padding: 14px 24px !important;
        font-size: 15px !important;
    }

    .csp-no-posts {
        padding: 30px 16px;
        font-size: 15px;
    }
}

/* Large phones — 600px */
@media (max-width: 600px) {
    .csp-post-item:hover {
        transform: none;       /* disable hover lift on touch devices */
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    .csp-post-item:hover .csp-post-thumb img {
        transform: none;       /* disable hover zoom on touch */
    }

    .csp-post-cats {
        font-size: 11px;
        padding: 4px 10px;
    }

    .csp-post-meta {
        margin-bottom: 10px;
    }
}

/* Small phones — 480px */
@media (max-width: 480px) {
    .csp-blog-wrapper {
        padding: 8px;
    }

    .csp-blog-search-filter-wrapper {
        padding: 12px;
        margin-bottom: 20px;
        border-radius: 6px;
    }

    .csp-blog-search-field {
        padding: 12px 12px 12px 40px;
    }

    .csp-blog-search-icon {
        left: 12px;
    }

    .csp-blog-category-select {
        padding: 12px 30px 12px 12px;
    }

    .csp-post-grid {
        gap: 16px;
    }

    .csp-post-content {
        padding: 14px;
    }

    .csp-post-title {
        font-size: 16px;
        margin-bottom: 8px;
    }

    .csp-post-readmore {
        padding: 10px 16px;
        font-size: 13px;
        width: 100%;
        text-align: center;
        box-sizing: border-box;
    }

    .csp-load-more-btn {
        width: 100% !important;
        max-width: none !important;
        padding: 14px 20px !important;
    }

    .csp-no-posts {
        padding: 24px 12px;
        font-size: 14px;
    }
}

/* Very small phones — 360px */
@media (max-width: 360px) {
    .csp-blog-wrapper {
        padding: 6px;
    }

    .csp-blog-search-filter-wrapper {
        padding: 10px;
    }

    .csp-post-content {
        padding: 12px;
    }

    .csp-post-title {
        font-size: 15px;
    }

    .csp-post-cats {
        font-size: 10px;
        padding: 3px 8px;
        top: 8px;
        left: 8px;
    }
}

/* ─── Touch device enhancements ────────────────────────────── */
@media (hover: none) and (pointer: coarse) {
    .csp-post-item:hover {
        transform: none;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    .csp-post-item:hover .csp-post-thumb img {
        transform: none;
    }

    .csp-load-more-btn:hover:not(:disabled) {
        transform: none !important;
    }

    /* Ensure comfortable tap targets (min 44px) */
    .csp-blog-search-field,
    .csp-blog-category-select {
        min-height: 44px;
    }

    .csp-post-readmore {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .csp-load-more-btn {
        min-height: 48px !important;
    }
}
