/* ==========================================================================
   EAB Flip Cards V2 — Styles
   Shared between frontend and editor.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Card Grid
   -------------------------------------------------------------------------- */
.eab-flip-cards-v2-grid {
    list-style: none;
    padding: 0;
}

/* --------------------------------------------------------------------------
   ACF InnerBlocks wrapper — make transparent to layout.
   ACF wraps <InnerBlocks> output in <div class="acf-innerblocks-container">
   on the frontend. display:contents removes it from the box tree so grid
   and absolute positioning work as if it weren't there.
   -------------------------------------------------------------------------- */
.eab-flip-cards-v2-grid>.acf-innerblocks-container,
.eab-flip-card-inner>.acf-innerblocks-container {
    display: contents;
}

/* --------------------------------------------------------------------------
   Flip Card — outer container (minimal; visual card is .eab-flip-card-inner)
   -------------------------------------------------------------------------- */
.eab-flip-card {
    width: 100%;
}

/* --------------------------------------------------------------------------
   Flip Card Inner — the visual card that animates.
   Uses scaleX driven by JS to simulate a flip — no CSS 3D transforms, so
   the animation works correctly in every browser including Firefox.
   Row 1 (1fr): both faces stack here via grid-area; tallest drives height.
   Row 2 (auto): toggle pinned to the bottom.
   transform-origin is centred so the scaleX fold looks symmetrical.
   -------------------------------------------------------------------------- */
.eab-flip-card-inner {
    position: relative;
    display: grid;
    grid-template-rows: 1fr;
    width: 100%;
    min-height: 400px;
    border-radius: 0.5rem;
    box-shadow:
        0 4px 6px -1px rgb(0 0 0 / 0.1),
        0 2px 4px -2px rgb(0 0 0 / 0.1);
    transform-origin: 50% 50%;
}

/* --------------------------------------------------------------------------
   Card Faces — both faces sit in grid row 1, stacked on top of each other.
   Visibility is swapped by JS at the exact midpoint of the scaleX animation
   (when the card is edge-on) so the wrong face is never visible in any browser.
   -------------------------------------------------------------------------- */
.eab-flip-card-face {
    position: relative;
    grid-area: 1 / 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    border-radius: 0.5rem;
    padding: 1.5rem;
    overflow: hidden;
}

/* Back face hidden by default; shown when .is-flipped is added by JS */
.eab-flip-card-face--back {
    visibility: hidden;
}

.eab-flip-card.is-flipped .eab-flip-card-face--back {
    visibility: visible;
}

.eab-flip-card.is-flipped .eab-flip-card-face--front {
    visibility: hidden;
}

/* --------------------------------------------------------------------------
   Card Color Themes
   Background on .eab-flip-card-inner (the rotating element) so it flips
   with the card. Color class is on the outer block wrapper.
   -------------------------------------------------------------------------- */
.eab-flip-card--prussian-blue .eab-flip-card-inner {
    background-color: #002746;
    color: #ffffff;
}

.eab-flip-card--congress-blue .eab-flip-card-inner {
    background-color: #004b87;
    color: #ffffff;
}

.eab-flip-card--medium-teal .eab-flip-card-inner {
    background-color: #7fcfcf;
    color: #002746;
}

.eab-flip-card--cool-gray .eab-flip-card-inner {
    background-color: #eaebec;
    color: #002746;
}

.eab-flip-card--white .eab-flip-card-inner {
    background-color: #ffffff;
    color: #002746;
}

/* --------------------------------------------------------------------------
   Toggle Button — inside .eab-flip-card-inner, auto-placed in the grid row
   below the stacked faces. Rotates with the card as part of the flip unit.
   justify-self:center keeps it horizontally centered in the grid column.
   -------------------------------------------------------------------------- */
.eab-flip-card-toggle {
    position: absolute;
    bottom: 0.75rem;
    left: 50%;
    transform: translate(-50%, 0);
    z-index: 10;
    border: none;
    border-radius: 50%;
    padding: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease;
    flex-shrink: 0;
}

.eab-flip-card-toggle:hover {
    opacity: 0.8;
}

.eab-flip-card-toggle:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.eab-flip-card-toggle svg {
    width: 18px;
    height: 18px;
}

/* Minimum 44×44px touch target (WCAG 2.5.8) */
.eab-flip-card-toggle {
    width: 44px;
    height: 44px;
}

/* Toggle colors — dark card backgrounds get a white button */
.eab-flip-card--prussian-blue .eab-flip-card-toggle,
.eab-flip-card--congress-blue .eab-flip-card-toggle {
    background-color: #ffffff;
    color: #0072ce;
}

/* Medium teal needs darker icon for contrast (WCAG 1.4.3 — 4.5:1) */
.eab-flip-card--medium-teal .eab-flip-card-toggle {
    background-color: #ffffff;
    color: #004b87;
}

/* Light card backgrounds get a blue button */
.eab-flip-card--cool-gray .eab-flip-card-toggle,
.eab-flip-card--white .eab-flip-card-toggle {
    background-color: #0072ce;
    color: #ffffff;
}

/* --------------------------------------------------------------------------
   Reduced Motion (WCAG 2.3.3)
   The flip animation itself is skipped by JS when prefers-reduced-motion is
   set. This rule covers the toggle button's opacity hover transition.
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .eab-flip-card-toggle {
        transition: none;
    }
}

/* --------------------------------------------------------------------------
   Pattern background section variant
   -------------------------------------------------------------------------- */
.eab-flip-cards-v2.pattern-bg {
    padding-bottom: 40px;
}

/* --------------------------------------------------------------------------
   Images inside card faces — inline display
   -------------------------------------------------------------------------- */
.eab-flip-card-face p img {
    display: inline;
}

/* ==========================================================================
   Editor-only Styles
   Show one face at a time with a toggle button. No 3D transforms in editor
   because they break block editing interactions.
   ========================================================================== */

/* Disable JS-driven transform in editor so dragging/resizing blocks works */
.wp-admin .eab-flip-card-inner {
    transform: none !important;
    transition: none !important;
}

/* Both faces always visible in editor for content editing */
.wp-admin .eab-flip-card-face {
    visibility: visible !important;
}

/* Default: show front, hide back */
.wp-admin .eab-flip-card-inner .block-editor-block-list__layout>.wp-block:not(.eab-flip-card-face *):last-child {
    opacity: 0;
    pointer-events: none;
    z-index: 0;
}

.wp-admin .eab-flip-card-inner .block-editor-block-list__layout>.wp-block:not(.eab-flip-card-face *):first-child {
    opacity: 1;
    pointer-events: auto;
    z-index: 1;
}

/* Flipped: show back, hide front */
.wp-admin .eab-flip-card.is-flipped .block-editor-block-list__layout>.wp-block:not(.eab-flip-card-face *):first-child {
    opacity: 0;
    pointer-events: none;
    z-index: 0;
}

.wp-admin .eab-flip-card.is-flipped .block-editor-block-list__layout>.wp-block:not(.eab-flip-card-face *):last-child {
    opacity: 1;
    pointer-events: auto;
    z-index: 1;
}

/* If a hidden face gets selected via list view, reveal it */
.wp-admin .eab-flip-card-inner .block-editor-block-list__layout>.wp-block:not(.eab-flip-card-face *).is-selected,
.wp-admin .eab-flip-card-inner .block-editor-block-list__layout>.wp-block:not(.eab-flip-card-face *).has-child-selected {
    opacity: 1 !important;
    pointer-events: auto !important;
    z-index: 2 !important;
}

/* Face label badges */
.wp-admin .eab-flip-card-face::before {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 5;
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 4px 10px;
    border-radius: 0 0 0.25rem 0;
    pointer-events: none;
}

.wp-admin .eab-flip-card-face--front::before,
.wp-admin .eab-flip-card-face--back::before {
    background-color: #000000;
    color: #ffffff;
}


.wp-admin .eab-flip-card-face--front::before {
    content: 'Front';
}

.wp-admin .eab-flip-card-face--back::before {
    content: 'Back';
}

/* Show the toggle button in the editor */
.wp-admin .eab-flip-card-toggle {
    display: flex;
    z-index: 20;
    /* transform: none; */
}

/* Active face indicator on the toggle */
.wp-admin .eab-flip-card-toggle::after {
    content: 'Show Back';
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    font-size: 11px;
    font-weight: 600;
    color: #1e1e1e;
    background: #ffffff;
    padding: 2px 8px;
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.wp-admin .eab-flip-card.is-flipped .eab-flip-card-toggle::after {
    content: 'Show Front';
}

.wp-admin .eab-flip-card-toggle:hover::after {
    opacity: 1;
}

.wp-admin .wp-block-acf-eab-flip-cards-v2 .eab-flip-card-face>.block-editor-block-list__block {
    width: 100%;
}
