/* Service Cards Block Styles */
.service-cards-block .services-container {
    width: 95vw;
    margin-left: calc((95vw - 100%) / -2);
    min-height: 600px;
    height: auto;
    position: relative;
    display: flex;
    flex-direction: column;
}

.service-cards-block .service-cards {
    display: grid;
    grid-column-gap: 50px;
    grid-row-gap: 50px;
    min-height: 540px;
    flex: 1;
}

/* Dynamic grid layouts based on card count */
.service-cards-block[data-card-count="1"] .service-cards {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}

.service-cards-block[data-card-count="2"] .service-cards {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
}

.service-cards-block[data-card-count="3"] .service-cards {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr;
}

.service-cards-block[data-card-count="4"] .service-cards {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.service-cards-block[data-card-count="5"] .service-cards {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

.service-cards-block[data-card-count="5"] .service-card:nth-child(1) { grid-column: 1 / 3; }
.service-cards-block[data-card-count="5"] .service-card:nth-child(2) { grid-column: 3; }
.service-cards-block[data-card-count="5"] .service-card:nth-child(3) { grid-column: 1; }
.service-cards-block[data-card-count="5"] .service-card:nth-child(4) { grid-column: 2; }
.service-cards-block[data-card-count="5"] .service-card:nth-child(5) { grid-column: 3; }

.service-cards-block[data-card-count="6"] .service-cards {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

.service-cards-block[data-card-count="7"] .service-cards {
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(6, 1fr);
}

.service-cards-block[data-card-count="7"] .service-card:nth-child(1) { grid-area: 1 / 1 / 4 / 3; }
.service-cards-block[data-card-count="7"] .service-card:nth-child(2) { grid-area: 1 / 3 / 4 / 4; }
.service-cards-block[data-card-count="7"] .service-card:nth-child(3) { grid-area: 4 / 1 / 7 / 4; }
.service-cards-block[data-card-count="7"] .service-card:nth-child(4) { grid-area: 1 / 4 / 3 / 5; }
.service-cards-block[data-card-count="7"] .service-card:nth-child(5) { grid-area: 3 / 4 / 7 / 5; }
.service-cards-block[data-card-count="7"] .service-card:nth-child(6) { grid-area: 1 / 5 / 4 / 7; }
.service-cards-block[data-card-count="7"] .service-card:nth-child(7) { grid-area: 4 / 5 / 7 / 7; }

.service-cards-block[data-card-count="8"] .service-cards {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

.service-cards-block[data-card-count="9"] .service-cards {
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(8, 1fr);
}

/* Original 9-card layout (from homepage) */
.service-cards-block[data-card-count="9"] .service-card:nth-child(1) { grid-area: 1 / 1 / 5 / 4; }
.service-cards-block[data-card-count="9"] .service-card:nth-child(2) { grid-area: 5 / 1 / 9 / 4; }
.service-cards-block[data-card-count="9"] .service-card:nth-child(3) { grid-area: 1 / 4 / 3 / 6; }
.service-cards-block[data-card-count="9"] .service-card:nth-child(4) { grid-area: 3 / 4 / 7 / 6; }
.service-cards-block[data-card-count="9"] .service-card:nth-child(5) { grid-area: 7 / 4 / 9 / 6; }
.service-cards-block[data-card-count="9"] .service-card:nth-child(6) { grid-area: 1 / 6 / 5 / 9; }
.service-cards-block[data-card-count="9"] .service-card:nth-child(7) { grid-area: 1 / 9 / 3 / 11; }
.service-cards-block[data-card-count="9"] .service-card:nth-child(8) { grid-area: 3 / 9 / 5 / 11; }
.service-cards-block[data-card-count="9"] .service-card:nth-child(9) { grid-area: 5 / 6 / 9 / 11; }

/* For 10+ cards, use a flexible auto-fit grid */
.service-cards-block[data-card-count]:not([data-card-count="1"]):not([data-card-count="2"]):not([data-card-count="3"]):not([data-card-count="4"]):not([data-card-count="5"]):not([data-card-count="6"]):not([data-card-count="7"]):not([data-card-count="8"]):not([data-card-count="9"]) .service-cards {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    grid-template-rows: auto;
    gap: 30px;
}

/* Card link wrapper */
.service-cards-block .service-card-link {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    text-decoration: none;
    border-radius: 10px;
}

.service-cards-block .service-card {
    border-radius: 10px;
    box-shadow: 0px 5px 20px rgba(0, 0, 0, 0.2);
    padding: 20px;
    text-align: left;
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    min-height: 200px;
    position: relative;
    display: flex;
    align-items: flex-start;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    /* Debug: Add a background color to see if cards are rendering */
    background-color: #f0f0f0;
    cursor: pointer;
    overflow: hidden;
}

/* Video background styles */
.service-cards-block .service-card .service-card-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
    pointer-events: none;
}

.service-cards-block .service-card.has-video {
    background-color: #000;
}

.service-cards-block .service-card:hover {
    transform: translateY(-5px);
    box-shadow: 0px 8px 25px rgba(0, 0, 0, 0.3);
}

/* Debug: Show when background image is applied */
.service-cards-block .service-card[style*="background-image"] {
    background-color: transparent;
}

/* Ensure card title is above the link and video */
.service-cards-block .service-card .card-title {
    position: relative;
    z-index: 2;
    pointer-events: none;
}

/* Ensure link is above video but below title */
.service-cards-block .service-card .service-card-link {
    z-index: 1;
}

.service-cards-block .service-card .card-title {
    background-color: #fff;
    border-radius: 110px;
    padding: 10px 25px;
    display: inline-block;
}

.service-cards-block .service-card p {
    font-family: 'Titillium Web', sans-serif;
    font-size: 14px;
    color: #000;
    font-weight: 400;
}

/* Category-based styling for card titles */
.service-cards-block .service-card .card-title.utilities {
    background-color: var(--gold) !important;
}

.service-cards-block .service-card .card-title.industrial {
    background-color: var(--navy) !important;
}

.service-cards-block .service-card .card-title.industrial p {
    color: #fff;
}

@media screen and (max-width: 1279px) and (min-width: 992px) {
    .service-cards-block .service-cards {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

@media screen and (max-width: 1115px){
    .service-cards-block .service-card:nth-child(n) {
        grid-area: unset !important;
    }
}

/* Mobile responsiveness */
@media (max-width: 991px) {
    .service-cards-block .services-container {
        width: 95vw;
        margin-left: calc((95vw - 100%) / -2);
        height: auto;
    }
    
    .service-cards-block .service-cards {
        display: flex;
        flex-direction: column;
        gap: 20px;
        margin-top: 30px;
    }
    
    .service-cards-block .service-card {
        height: 200px;
        margin: 0;
    }

}

/* Very small screens - reduce to 100% to avoid horizontal scroll */
@media (max-width: 480px) {
    .service-cards-block .services-container {
        width: 100%;
        margin-left: 0;
    }
}
