/* “Stat cards” Elementor widget. Variables set by the widget controls. */

.jits-stat-cards {
    --jits-stat-columns: 2;
    --jits-stat-gap: 48px;
    --jits-stat-rows: 2;
    --jits-stat-min-height: 240px;
    /* Height shared by --jits-stat-rows rows: window height minus the WP admin bar
       (logged-in users), the scrolled header (theme variable) and 40px. */
    --jits-stat-screen: calc(100vh - var(--wp-admin--admin-bar--height, 0px) - var(--header-height-scrolled, 88px) - 40px);
    --jits-stat-radius: 8px;
    --jits-stat-card-overlay: rgba(13, 29, 87, 0.35);
    --jits-stat-panel-overlay: rgba(22, 60, 219, 0.85);
    --jits-stat-text: #ffffff;

    color: var(--jits-stat-text);
}

/* Mobile browsers: height without the collapsible address bar. */
@supports (height: 100svh) {
    .jits-stat-cards {
        --jits-stat-screen: calc(100svh - var(--wp-admin--admin-bar--height, 0px) - var(--header-height-scrolled, 88px) - 40px);
    }
}

.jits-stat-cards__grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--jits-stat-columns), minmax(0, 1fr));
    gap: var(--jits-stat-gap);
}

/* Card (closed state). */
.jits-stat-card {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-height: max(
        var(--jits-stat-min-height),
        (var(--jits-stat-screen) - (var(--jits-stat-rows) - 1) * var(--jits-stat-gap)) / var(--jits-stat-rows)
    );
    margin: 0;
    padding: 2.5rem;
    border: 0;
    border-radius: var(--jits-stat-radius);
    background: #0d1d57;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.jits-stat-card::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--jits-stat-card-overlay);
}

.jits-stat-card__media,
.jits-stat-cards__panel-media {
    position: absolute;
    inset: 0;
    z-index: -2;
}

.jits-stat-card__media img,
.jits-stat-cards__panel-media img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: cover;
}

/* Scaled from the card to the full panel by script during the animation. */
.jits-stat-cards__panel-media {
    transform-origin: 0 0;
}

.jits-stat-card__media img {
    transition: transform 600ms ease;
}

.jits-stat-card:hover .jits-stat-card__media img,
.jits-stat-card:focus-visible:not(.is-restored-focus) .jits-stat-card__media img {
    transform: scale(1.04);
}

/* Focus given back by script after closing the panel: no focus ring. */
.jits-stat-card.is-restored-focus {
    outline: none;
}

.jits-stat-card:focus-visible:not(.is-restored-focus) {
    outline: 3px solid var(--jits-stat-text);
    outline-offset: 3px;
}

.jits-stat-cards__number {
    display: block;
    margin: 0;
    font-size: clamp(3rem, 2.2rem + 2.5vw, 4.5rem);
    font-weight: 600;
    line-height: 1;
}

.jits-stat-cards__label {
    display: block;
    margin: 0.5rem 0 0;
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.2;
}

/* Expanded panel, over the whole grid. */
.jits-stat-cards__panel {
    position: absolute;
    inset: 0;
    z-index: 2;
    isolation: isolate;
    overflow-y: auto;
    border-radius: var(--jits-stat-radius);
    background: #0d1d57;
    /* Scrolled into view on opening: below the WP admin bar and the scrolled header,
       with half of the 40px kept by the card height above (and so below) it. */
    scroll-margin-top: calc(var(--wp-admin--admin-bar--height, 0px) + var(--header-height-scrolled, 88px) + 20px);
}

.jits-stat-cards__panel[hidden] {
    display: none;
}

.jits-stat-cards__panel::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: linear-gradient(
        90deg,
        var(--jits-stat-panel-overlay) 0%,
        color-mix(in srgb, var(--jits-stat-panel-overlay) 55%, transparent) 40%,
        transparent 75%
    );
}

.jits-stat-cards__panel-content {
    position: relative;
    max-width: 34rem;
    padding: 2.5rem;
    opacity: 0;
    transform: translateY(1rem);
    transition: opacity 350ms ease, transform 350ms ease;
}

.jits-stat-cards__panel.is-content-visible .jits-stat-cards__panel-content {
    opacity: 1;
    transform: none;
}

.jits-stat-cards__title {
    margin: 4rem 0 1.25rem;
    color: inherit;
    font-size: clamp(1.5rem, 1.2rem + 1vw, 2rem);
    font-weight: 700;
    line-height: 1.2;
}

/* Focused by script when the panel opens (tabindex="-1"). */
.jits-stat-cards__title:focus {
    outline: none;
}

.jits-stat-cards__text {
    font-size: 1.125rem;
    line-height: 1.5;
}

.jits-stat-cards__text p {
    margin: 0 0 1em;
}

.jits-stat-cards__close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3.5rem;
    height: 3.5rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--button-primary-bg, #163cdb);
    color: #ffffff;
    cursor: pointer;
    opacity: 0;
    transition: opacity 350ms ease, transform 200ms ease;
}

.jits-stat-cards__panel.is-content-visible .jits-stat-cards__close {
    opacity: 1;
}

.jits-stat-cards__close:hover {
    transform: scale(1.06);
}

.jits-stat-cards__close:focus-visible {
    outline: 3px solid #ffffff;
    outline-offset: 3px;
}

.jits-stat-cards__close svg {
    width: 1.75rem;
    height: 1.75rem;
}

@media (max-width: 767px) {
    .jits-stat-card,
    .jits-stat-cards__panel-content {
        padding: 1.5rem;
    }

    .jits-stat-cards__panel-content {
        padding-right: 5.5rem;
    }

    .jits-stat-cards__title {
        margin-top: 2rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .jits-stat-card__media img,
    .jits-stat-cards__panel-content,
    .jits-stat-cards__close {
        transition: none;
    }
}
