/* Phase 1B: CSS Variables - Lock down all dimensions */
:root {
    /* Card dimensions */
    --card-h-collapsed: 350px;
    --card-h-expanded: 400px;
    
    /* Image dimensions - FIXED SIZE (never changes) */
    --img-w-fixed: 263px; /* 3:4 aspect ratio, height = 350px */
    --img-h-fixed: 350px;
    --img-w-collapsed: auto;
    --img-w-expanded: 300px;
    
    /* Content dimensions */
    --content-h-collapsed: 120px;
    --content-h-expanded: 360px;
    
    /* Spacing */
    --content-pad: 24px;
    --gap: 20px;
    --min-card-w: 245px;
    
    /* Bio constraints */
    --bio-lines: 7; /* Lines that fit in expanded height */
}

.team-members-container {
    display: grid;
    /* Desktop/max column count is driven by --columns (set by the Elementor
       control / shortcode); the tablet & mobile media queries below cap it at
       3 / 1 regardless. Defaults to 4. */
    grid-template-columns: repeat(var(--effective-columns, var(--columns, 4)), 1fr);
    gap: var(--gap);
    align-content: start;
    width: 100%;
    padding: 20px 0;
    position: relative;
    --columns: 4;
    --animation-duration: 1s; /* Synced with JS SPEED_MULT */
    overflow-anchor: none;
    /* Confine the cards' z-index (expanded card = 1000) to this container's own
       stacking context so an expanded card can never paint OVER the site's sticky
       header — it scrolls behind it like the rest of the page content. */
    isolation: isolate;
}

/* Disable scroll anchoring globally during animations */
html, body {
    overflow-anchor: none;
}

/* Phase 1A: Basic state classes for validation */
.team-member-slot {
    position: relative;
    min-width: 0;
    grid-column: span 1; /* Default: single column */
}

/* Phase 1C: Expanded slot spans full width */
/* Note: For Phase 1C validation, manually add .is-expanded to slot too */
.team-member-slot.is-expanded {
    grid-column: 1 / -1; /* Full width when expanded */
}

/* Also remove grid-column from card (it's on slot now) */
.team-member.is-expanded {
    grid-column: unset; /* Remove grid-column from card */
}

.team-member {
    display: block;
    height: var(--card-h-collapsed); /* Phase 1B: Use CSS variable */
    cursor: pointer;
    box-sizing: border-box;
    margin: 0;
    position: relative;
    overflow: hidden;
    min-width: 0;
    width: 100%;
    grid-column: span 1; /* Default: single column */
}

/* Phase 1C: Expanded card spans full width */
.team-member.is-expanded {
    grid-column: 1 / -1 !important; /* Force full width span */
}

/* Phase 1B: State classes using CSS variables */
.team-member.is-collapsed {
    height: var(--card-h-collapsed);
}

.team-member.is-expanded {
    height: var(--card-h-expanded);
    grid-column: 1 / -1; /* Phase 1C: Expanded card spans full width */
    width: 100%; /* CRITICAL: Grid needs parent width to calculate 1fr */
    /* Phase 1C: Real layout now, no testing border needed */
}

/* Phase 1B: Ensure expanded state uses variables */
.team-member.is-expanded {
    height: var(--card-h-expanded);
}

/* Depth: lift the bottom-right corner. The shadow is cast by a pseudo-element
   on the SLOT, sitting behind the card; the card's own (page-coloured) opaque
   background masks its body, leaving a soft shadow peeking out only at that
   corner. (box-shadow can't isolate a corner on an element this large, hence
   the pseudo-element; it lives on the slot because the card is overflow:hidden.)
   The shadow fades in as the card settles and fades out on collapse. */
.team-member.is-expanded {
    /* Surface stays TRANSPARENT during the expand so the row-mates animating out
       from underneath remain visible (no jarring instant white-out). It fades in
       once the card settles — same .corner-shadow trigger as the shadow + project
       image — and in the rested state masks the corner caster. On collapse the
       class is removed first, so it fades back out before the card snaps. */
    background-color: transparent;
    transition: background-color 0.45s ease;
}
.team-member-slot.corner-shadow .team-member.is-expanded {
    /* Opaque surface in the page's own colour (set --tmoc-surface to the section
       background; defaults to white). */
    background-color: var(--tmoc-surface, #ffffff);
}

/* ===== OPTION 1 (default) — CAD line-drawing treatment =====
   Faint project drawing on a pseudo-element behind the card content, anchored to
   the bottom-right corner, skewed, multiply-blended (drops the white bg), fading
   up-left. Per member, set --tmoc-project-img to the tagged project's image
   (output by WP); a placeholder is used until then.
   Option 2 (photo) overrides this when .bg-photo is on the container. */
.team-member.is-expanded::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: var(--tmoc-project-img, url('cad-floor-plan.jpeg'));
    /* Smaller drawing so more of the linework/detail shows in the band */
    background-size: 100%;
    background-position: calc(42% + var(--tmoc-bg-jx, 0%)) calc(60% + var(--tmoc-bg-jy, 0%));
    background-repeat: no-repeat;
    opacity: 0; /* fades in once the card settles (driven by .corner-shadow) */
    transition: opacity 0.9s ease; /* slow fade-in */
    mix-blend-mode: multiply; /* drops the drawing's white bg, leaving only the linework */
    /* Dramatic skew so it reads as a dynamic placement, anchored to the corner */
    transform: skewX(-24deg) scale(1.42);
    transform-origin: bottom right;
    /* Tight visible band hugging the bottom-right, fading up-left */
    -webkit-mask-image: linear-gradient(to top left, #000 0%, rgba(0, 0, 0, 0) 32%);
    mask-image: linear-gradient(to top left, #000 0%, rgba(0, 0, 0, 0) 32%);
    pointer-events: none;
}

/* Fade the project image in once the card has settled (same trigger as the
   corner shadow), so it eases in slowly instead of popping with the layout. */
.team-member-slot.corner-shadow .team-member.is-expanded::before {
    opacity: 0.18;
}

/* ===== OPTION 2 — project PHOTO treatment =====
   Activate by adding `bg-photo` to .team-members-container (default = Option 1).
   Same corner placement + slow fade-in, but a real photo: cover-filled, normal
   blend (no multiply), gentler skew, and a touch fainter. */
.team-members-container.bg-photo .team-member.is-expanded::before {
    /* No project image -> show nothing (the demo rotation sets one per expand) */
    background-image: var(--tmoc-project-img, none);
    background-size: 100%;
    background-position: calc(42% + var(--tmoc-bg-jx, 0%)) calc(60% + var(--tmoc-bg-jy, 0%));
    background-repeat: no-repeat;
    mix-blend-mode: normal;
    transform: skewX(-0deg) scale(1.2);
}

.team-members-container.bg-photo .team-member-slot.corner-shadow .team-member.is-expanded::before {
    opacity: 0.33; /* photos read stronger than line art - keep fainter */
}

.team-member-slot::after {
    content: "";
    position: absolute;
    z-index: 999; /* above neighbouring cards, below the expanded card (z 1000) */
    bottom: 0;
    right: 0;
    width: 40%;
    height: 48%;
    box-shadow: 12px 12px 34px -2px rgba(18, 32, 58, 0.10); /* bottom-right corner */
    pointer-events: none;
    opacity: 0;
    /* Fast fade-out, triggered (via JS removing .corner-shadow) BEFORE the slot
       snaps on collapse, so the snap/resize is never visible. */
    transition: opacity 0.22s ease;
}

/* .corner-shadow is toggled by JS, not by .is-expanded, so the shadow's fade is
   decoupled from the layout snap: it fades in only once the card has settled. */
.team-member-slot.corner-shadow::after {
    opacity: 1;
    transition: opacity 0.5s ease;
}

/* Phase 1C: Inner wrapper - controls layout mode */
.team-member-inner {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: visible;
}

/* Collapsed: block layout */
.team-member.is-collapsed .team-member-inner {
    display: block;
    position: relative;
    height: 100%;
}

/* Expanded: grid layout (2 columns) */
.team-member.is-expanded .team-member-inner {
    display: grid !important; /* Ensure grid is applied */
    grid-template-columns: var(--img-w-expanded) minmax(0, 1fr); /* minmax prevents collapse */
    width: 100%; /* CRITICAL: Grid needs explicit width to calculate 1fr */
    height: 100%;
}

/* Phase 1B: Content wrapper - CRITICAL: Fixed height for absolute children */
.team-member-content {
    position: relative;
    height: 100%; /* CRITICAL: Fixed height for absolute children */
    width: 100%;
}

/* Phase 1C: Content wrapper in expanded state - grid column 2 */
.team-member.is-expanded .team-member-content {
    position: relative;
    grid-column: 2;
    grid-row: 1;
    height: 100%; /* CRITICAL */
    min-width: 0; /* Prevent grid column from shrinking */
    width: 100%; /* Ensure it takes full grid column width */
}

/* Phase 1C: Image positioning - FIXED SIZE and ABSOLUTE in both states */
/* Keep the portrait on its own compositing layer so the card's FLIP
   transform just repositions it, instead of repainting and re-sampling the
   background-size:cover image (which caused a few-px size/crop jump at the
   start of the collapse). */
.team-member-image {
    transform: translateZ(0);
    backface-visibility: hidden;
    /* Keep the layer's cached texture across repaints so the card's width
       snap during collapse doesn't re-rasterize (and sub-pixel-resize) the
       cover image on HiDPI displays. */
    will-change: transform;
}

/* Collapsed: absolute, layered behind content */
.team-member.is-collapsed .team-member-image {
    position: absolute;
    top: 0;
    left: 0;
    width: min(var(--img-w-fixed), 100%);
    height: var(--img-h-fixed);
    object-fit: cover; /* Deterministic crop */
    z-index: 1;
}

/* Expanded: ALSO absolute - SAME FIXED SIZE, SAME POSITIONING */
.team-member.is-expanded .team-member-image {
    position: absolute; /* Never changes from absolute */
    top: 0;
    left: 0;
    width: var(--img-w-fixed);
    height: var(--img-h-fixed);
    object-fit: cover; /* Deterministic crop */
    z-index: 1;
}

/* Phase 1C: Text wrapper - absolute in both states */
/* Collapsed: label block coincides with the blue field so the name pins to
   the top-left and the role pins to the bottom-right corner. */
.team-member.is-collapsed .team-member-text-wrapper {
    position: absolute;
    left: 0;
    /* Cap at the card width so it never overflows + gets clipped on narrower
       columns (the role label was cutting off on the right). */
    width: min(calc(var(--img-w-fixed) * 1.05), 100%);
    right: auto;
    bottom: 17px;              /* match blue field bottom edge */
    top: auto;
    height: calc(var(--card-h-collapsed) * 0.30); /* coincide with the blue field */
    box-sizing: border-box;    /* keep padding inside the field height */
    display: flex;
    flex-direction: column;
    justify-content: space-between; /* name (after top pad) mid, role at bottom */
    align-items: flex-start;
    padding: 20px 0 6px 0;     /* top pad drops the name plate partway down the field */
    z-index: 10; /* Above blue box (z-index 1) */
}

/* Expanded: label block spans the blue field; name top, role bottom-right */
.team-member.is-expanded .team-member-text-wrapper {
    position: absolute;
    top: 24px; /* align with the blue field top (scooted up) */
    left: calc(var(--content-pad) - 24px); /* scooted further left (to content edge) */
    right: var(--content-pad); /* match blue field right edge */
    bottom: auto;
    height: calc(var(--card-h-expanded) * 0.33); /* coincide with the blue field */
    box-sizing: border-box;    /* keep padding inside the field height */
    display: flex;
    flex-direction: column;
    justify-content: space-between; /* name (after top pad) upper third, role at bottom */
    align-items: flex-start;
    padding: 26px 0 8px 0;     /* name sits ~upper third (a little higher), role at bottom */
    z-index: 10; /* Above blue box (z-index 1) */
}

/* Phase 1C: Blue box - absolute in both states */
/* Textured blue field echoing the glass-curtain-wall banner:
   diagonal light->dark sheen ("burn") + faint window grid over brand blue. */
.team-member-blue-box {
    background:
        linear-gradient(225deg, rgba(255,255,255,0.14) 0%, rgba(255,255,255,0) 42%, rgba(0,0,0,0.24) 100%),
        repeating-linear-gradient(0deg, rgba(255,255,255,0.05) 0 1px, transparent 1px 14px),
        repeating-linear-gradient(90deg, rgba(255,255,255,0.045) 0 1px, transparent 1px 14px),
        var(--e-global-color-bwa-blue, #035399);
}

/* Collapsed: behind text-wrapper */
.team-member.is-collapsed .team-member-blue-box {
    position: absolute;
    bottom: 17px; /* Moved up 10px from 7px */
    left: 0; /* Flush left so the label block covers the photo on the left */
    width: min(calc(var(--img-w-fixed) * 1.05), 100%); /* ~5% past the photo, capped to the card */
    right: auto;
    top: auto;
    height: calc(var(--card-h-collapsed) * 0.30); /* taller field to fit lower plate + corner role */
    z-index: 1;
}

/* Expanded: positioned below text wrapper at top of column */
.team-member.is-expanded .team-member-blue-box {
    position: absolute;
    top: 24px; /* scooted up a tad */
    left: calc(var(--content-pad) - 24px); /* scooted further left (to content edge) */
    right: var(--content-pad);
    bottom: auto;
    height: calc(var(--card-h-expanded) * 0.33); /* 33% of expanded height = ~132px */
    z-index: 1;
}

/* NAME - Inside wrapper, positioned by its padding
   Properties that affect layout and position */
.team-member-name {
    /* White name-plate with dark-blue text, overlaying the blue field
       (mirrors the "About Us" box on the banner). */
    color: var(--e-global-color-bwa-blue, #035399) !important;
    background: #ffffff;
    font-family: 'Poppins', sans-serif;
    font-size: 17px;            /* Text size (collapsed) - reduced ~15% */
    font-weight: 600;           /* Semibold: let whitespace carry authority, not weight */
    line-height: 1.2;
    position: relative;
    z-index: 1; /* Relative to wrapper (wrapper is already z-index 10) */
    display: inline-block;      /* Hug the text so it reads as a plate, not a bar */
    margin: 0 0 6px 0;          /* Flush to the card's left edge (covers photo behind) */
    padding: 7px 14px;
    letter-spacing: 0.3px;      /* Very slight tracking for a more refined feel */
    box-sizing: border-box;
    max-width: 100%;
    overflow-wrap: break-word;
}

/* TITLE (grey box) - Below name
   Properties that affect layout and position */
.team-member-title {
    /* Role: white text directly on the blue field (no grey bar). */
    background: transparent;
    color: #ffffff;
    font-size: 13px;            /* Text size (collapsed) - slightly smaller */
    font-weight: 600;
    border-radius: 0;
    display: inline-block;
    position: relative;
    margin: 0 0 0 12px;         /* Align under the name plate */
    padding: 0;
    z-index: 1; /* Relative to wrapper (wrapper is already z-index 10) */
    line-height: 1.4;
    text-transform: uppercase;  /* Spaced-caps role label */
    letter-spacing: 0.7px;      /* Caps need a bit more tracking */
    box-sizing: border-box;
    max-width: calc(100% - 12px);
    overflow-wrap: break-word;
    /* Balance the wrap so multi-part roles break at the sensible point and keep
       phrases together, e.g. "Associate Partner," / "Assistant Studio Head" and
       "Director of" / "Administrative Services". */
    text-wrap: balance;
}

/* Phase 1C: Name and Title - expanded state styles */
/* Expanded name: larger font, moved up */
.team-member.is-expanded .team-member-name {
    font-size: 20px;            /* reduced from 24px (~17%) */
    padding: 8px 16px;          /* Plate padding (slightly larger when expanded) */
    margin: 0 0 6px 0;
}

/* Role pinned to the blue field's bottom-right corner (both states) */
.team-member.is-collapsed .team-member-title,
.team-member.is-expanded .team-member-title {
    align-self: flex-end;
    text-align: right;
    margin: 0 6px 0 0;          /* small nudge in from the field's right edge */
    padding: 0;
}

.team-member.is-expanded .team-member-title {
    font-size: 14px;
    margin-right: 12px; /* a touch more inset from the field's right edge */
}

/* Phase 1C: Bio - absolute in both states */
/* Collapsed: hidden */
.team-member.is-collapsed .team-member-bio {
    position: absolute;
    opacity: 0;
    visibility: hidden;
    height: 0;
    overflow: hidden;
}

/* Phase 1D: Bio line clamp - prevents layout changes */
.team-member-bio {
    display: -webkit-box;
    -webkit-line-clamp: var(--bio-lines);
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.7;
    /* Bio cannot change layout height */
}

/* Subtitle (the leading <em>) sits on its own line above the bio text.
   width:100% forces a full line inside the bio's -webkit-box so the body
   never collapses up onto the subtitle's line. */
.team-member-bio em {
    display: block;
    width: 100%;
    margin-bottom: 6px;
}

/* Expanded: visible, below blue box */
.team-member.is-expanded .team-member-bio {
    position: absolute;
    top: 168px; /* Below blue box + bottom-corner role (tighter gap) */
    left: var(--content-pad);
    right: var(--content-pad);
    bottom: 60px; /* Above read-more */
    padding-top: 20px; /* More top padding */
    opacity: 1;
    visibility: visible;
    font-size: 14px;
    color: #333;
    /* Line-clamp already set above - no overflow-y needed */
}

/* Phase 1C: Read more link - absolute positioning */
.team-member.is-collapsed .team-member-readmore {
    display: none; /* Hidden in collapsed */
}

.team-member.is-expanded .team-member-readmore {
    position: absolute;
    bottom: var(--content-pad);
    right: var(--content-pad);
    color: var(--e-global-color-bwa-blue, #035399);
    font-weight: 600;
    text-decoration: none;
    z-index: 10;
    display:none; /* just hidden */
}

.team-member.is-expanded .team-member-readmore:hover {
    text-decoration: underline;
}

/* TEMPORARILY DISABLED: the team_member single pages aren't built yet, so "Read
   more" points at dead links. This hides it in every state/breakpoint (incl. the
   mobile rule below). Re-enable by removing this rule once the single-member
   template exists. */
.team-member-readmore {
    display: none !important;
}

@media (min-width: 1201px) {
    .team-members-container {
        /* Honour the configured max column count on desktop (don't hardcode 4). */
        grid-template-columns: repeat(var(--effective-columns, var(--columns, 4)), 1fr);
    }
}

@media (min-width: 768px) and (max-width: 1200px) {
    .team-members-container {
        --columns: 3;
        grid-template-columns: repeat(var(--effective-columns, var(--columns, 3)), 1fr);
    }

    .team-member-name {
        font-size: 17px;
    }

    .team-member-title {
        font-size: 14px;
    }
}

@media (min-width: 481px) and (max-width: 767px) {
    .team-members-container {
        grid-template-columns: 1fr;
        --columns: 1;
    }
    
    .team-member-blue-box {
        left: 0;
        width: 80%;
    }
    
    .team-member-title {
        width: 76%;
        margin-left: 0;
        margin-right: 0;
        padding-left: 15px;
    }

    .team-member-name {
        font-size: 17px;
    }

    .team-member-title {
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .team-members-container {
        grid-template-columns: 1fr;
        --columns: 1;
    }
    
    .team-member-blue-box {
        left: 0;
        width: 80%;
    }
    
    .team-member-title {
        width: 76%;
        margin-left: 0;
        margin-right: 0;
        padding-left: 12px;
        padding-right: 12px;
    }
    
    .team-member-name {
        font-size: 15px;
        padding-top: 8px;
    }

    .team-member-title {
        font-size: 13px;
        padding: 6px 12px;
    }
    
    .team-member.no-expand::after {
        content: '→';
        position: absolute;
        top: 15px;
        right: 15px;
        color: white;
        font-size: 24px;
        z-index: 10;
        opacity: 0.8;
    }
}

/* ===== Mobile / small single-column expanded layout =====
   Keep the collapsed look up top (photo with name-plate + role overlaid at the
   photo's bottom), then flow the full bio and read-more BELOW the photo so the
   card grows to fit. Everything here is scoped to <=767px, so the desktop and
   3-col tablet expanded layouts are untouched. */
@media (max-width: 767px) {
    .team-member.is-expanded {
        height: auto; /* grow to fit the bio */
    }

    .team-member.is-expanded .team-member-inner {
        display: block !important; /* override desktop `grid !important`; stack vertically */
        height: auto;
    }

    /* Reserve the photo's height up top; bio/read-more flow after it. */
    .team-member.is-expanded .team-member-content {
        position: relative;
        height: auto;
        padding-top: var(--img-h-fixed);
    }

    /* Name plate + blue field overlay the photo's bottom (anchored to the
       photo via top, not the now-taller card), matching the collapsed look. */
    .team-member.is-expanded .team-member-text-wrapper,
    .team-member.is-expanded .team-member-blue-box {
        left: 0;
        right: auto;
        width: min(calc(var(--img-w-fixed) * 1.05), 100%);
        top: calc(var(--img-h-fixed) - (var(--card-h-collapsed) * 0.30) - 17px);
        bottom: auto;
        height: calc(var(--card-h-collapsed) * 0.30);
    }

    .team-member.is-expanded .team-member-text-wrapper {
        padding: 20px 0 6px 0;
    }

    /* Name/role back to the collapsed scale */
    .team-member.is-expanded .team-member-name {
        font-size: 17px;
        padding: 7px 14px;
    }

    .team-member.is-expanded .team-member-title {
        font-size: 13px;
    }

    /* Full bio flows below the photo (no clamp - the card grows). */
    .team-member.is-expanded .team-member-bio {
        position: static;
        top: auto;
        left: auto;
        right: auto;
        bottom: auto;
        margin: 0;
        padding: 16px 18px 0 18px;
        display: block;
        -webkit-line-clamp: initial;
        line-clamp: initial;
        font-size: 14px;
        color: #333;
    }

    /* Read more below the bio. */
    .team-member.is-expanded .team-member-readmore {
        position: static;
        display: inline-block;
        margin: 10px 18px 18px 18px;
    }
}
