/**
 * Icon & Text Box Grid Block Styles
 *
 * Grid layout for content boxes with icons, titles, descriptions, and hover effects.
 * Uses CSS Grid for responsive layout with optional CTA buttons or clickable boxes.
 *
 * @package TMW_Blocks
 * @since 1.0.0
 */

.row.icon-text-box-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: stretch;
    gap: var(--row-gap);
}

/* Override column classes to work with flexbox - desktop/tablet only */
@media (width >=768px) {
    .row.icon-text-box-grid .col-3 {
        /* 4 items = 3 gaps total = 3/4 gap per item */
        flex: 0 0 calc(25% - (var(--row-gap) * 3 / 4));
        max-width: calc(25% - (var(--row-gap) * 3 / 4));
    }

    .row.icon-text-box-grid .col-4 {
        /* 3 items = 2 gaps total = 2/3 gap per item */
        flex: 0 0 calc(33.333% - (var(--row-gap) * 2 / 3));
        max-width: calc(33.333% - (var(--row-gap) * 2 / 3));
    }
}

/* Full width for section headers at all screen sizes */
.row.icon-text-box-grid .col-12 {
    flex: 0 0 100%;
    max-width: 100%;
}

/* Section header spans full width via .col-12 class */
.icon-text-box-grid .section-header {
    text-align: center;
    margin-bottom: var(--space-md);
}

/* Header CTA button spacing */
.icon-text-box-grid .section-header-cta {
    margin-top: var(--space-md);
}

.icon-text-box-grid .box-item {
    background: var(--color-white);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-default);
    padding: var(--space-lg);
    text-decoration: none;
    display: block;
    position: relative;
    overflow: hidden;
    transition: transform var(--transition-base), box-shadow var(--transition-base), background-color var(--transition-base);
}

/* GPU acceleration optimizations - desktop only to prevent iOS border rendering issues */
@media (width > 768px) and (hover: hover) and (pointer: fine) {
    .icon-text-box-grid .box-item {
        will-change: transform;
        backface-visibility: hidden;
        transform: translateZ(0);
        -webkit-font-smoothing: subpixel-antialiased;
    }
}

/* Boxes with CTA buttons need flex layout to push button to bottom */
.icon-text-box-grid .box-item.flex-col {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Clickable card links - no transform transition to preserve stagger animation timing */
.icon-text-box-grid a.box-item {
    cursor: pointer;
}

/* Hover effects only for clickable card links */
.icon-text-box-grid a.box-item:hover {
    background-color: rgb(255 255 255 / 96%);
    transform: translate3d(0, var(--transform-offset-md), 0);
    box-shadow: var(--shadow-lg);
    border-color: var(--color-primary);

    /* Fast transition on hover-in only - ease-out inherits stagger timing */
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), background-color var(--transition-fast);
}

/* Icon scale on hover for clickable cards */
.icon-text-box-grid a.box-item .box-icon {
    transition: transform var(--transition-fast);
}

.icon-text-box-grid a.box-item:hover .box-icon {
    transform: scale(1.1);
}

.icon-text-box-grid a.box-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--wp--preset--gradient--gradient-1);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform var(--transition-base);
}

.icon-text-box-grid a.box-item:hover::before {
    transform: scaleX(1);
}

.icon-text-box-grid .box-icon {
    height: auto;

    /* flex-center utility class provides: display: flex; align-items: center; justify-content: center */
    margin-bottom: var(--space-sm);
    width: fit-content;

    /* Force pixel alignment to prevent sub-pixel blur */
    transform: translate3d(0, 0, 0);
}

.icon-text-box-grid .box-icon img {
    object-fit: contain;
    max-width: var(--dimension-icon-xs);
    max-height: var(--dimension-icon-xs);
    width: var(--dimension-icon-xs);
    height: auto;

    /* GPU layer for pixel alignment */
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* SVG-specific sharpness - crisp-edges works for vectors but blurs raster images */
.icon-text-box-grid .box-icon img[src$=".svg"] {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* SVG-specific styling */
.icon-text-box-grid .box-icon-img--svg {
    display: block;
    fill: currentcolor;
}

.icon-text-box-grid .box-description,
.icon-text-box-grid a .box-description {
    margin-bottom: var(--space-md);
    color: var(--color-text-primary);
}

.icon-text-box-grid .box-description ul,
.icon-text-box-grid .box-description ol {
    text-align: left;
    margin-bottom: 0 !important;
    margin-left: 0;
}

.icon-text-box-grid .box-item .box-title {
    color: var(--color-heading);
}

/* Override global .has-text-color inheritance for box grid - reset at card level */
.has-text-color .icon-text-box-grid .box-item {
    color: var(--color-text-primary);
}

/* Protect links inside cards from inheriting white text color */
.has-text-color .icon-text-box-grid .box-description a {
    color: var(--color-link);
}

.has-text-color .icon-text-box-grid .box-description a:hover {
    color: var(--color-link-hover);
}

/* Protect arrow-style CTA buttons from inheriting section's light text color */
.has-text-color .icon-text-box-grid .box-cta.btn-arrow {
    color: var(--color-link);
}

.has-text-color .icon-text-box-grid .box-cta.btn-arrow:hover {
    color: var(--color-link-hover);
}

/* ==========================================================================
   Card Background Text Adaptation
   Dark bg styles handled globally by theme dark-bg-adaptation.css
   Light cards on dark sections use .has-nested-bg for color reset
   ========================================================================== */

/* CTA Button inside boxes (for external URL links) */
.icon-text-box-grid .box-cta {
    margin-top: auto;
    display: inline-block;
    align-self: flex-start;
}

/* Boxes with buttons need flex layout to push button to bottom */

/* flex-col utility class applied via PHP when appropriate */

/* margin-top: auto pushes button to bottom of flex container */

/* Responsive adjustments (grid system handles mobile stacking via .col-sm-12) */
@media (width <=1024px) {
    .row.icon-text-box-grid {
        --row-gap: var(--space-md);
    }
}