/* ============================================
   FuseIoT — Products Section
   Phase A: Product hero cards (Iris + Retina)
   Phase B: Capabilities grid (6 sensor types)
   Ref: 03-showreel-section.md, 04-featured-work-grid.md
   ============================================ */

/* --- Section --- */
.products {
  padding: var(--section-gap-large) 0;
  position: relative;
  background: var(--bg-primary);
}

/* ============================================
   PHASE A — Product Hero Cards
   ============================================ */

.products__heroes {
  margin-bottom: var(--section-gap-medium);
}

.products__heroes-header {
  margin-bottom: 40px;
}

.products__heroes-title {
  font-size: clamp(56px, 7vw, 110px);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--text-primary);
}

.products__heroes-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3vw;
  width: 90vw;
  max-width: var(--container-max);
  margin: 0 auto;
}

/* --- Product Hero Card --- */
.products__hero-card {
  border-radius: var(--radius-container);
  overflow: hidden;
  aspect-ratio: 16 / 10;
  position: relative;
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  cursor: pointer;
  /* GSAP handles entrance animation */
}

/* Animated visible state (triggered by GSAP) */
.products__hero-card[style*="opacity: 1"],
.products__hero-card[style*="scale(1)"] {
  /* Allow GSAP inline styles to take precedence */
}

/* --- Card Gradients --- */
.products__hero-card--iris {
  background: linear-gradient(135deg, #3436B1, #CF2A2E);
}

.products__hero-card--retina {
  background: linear-gradient(135deg, #CF2A2E, #F47D4E);
}

/* --- Card Background (live mounted layer) ---
   Oversized by 8px on all sides so the hover translate animation never
   reveals the card's underlying gradient as ugly edges. The card itself
   has `overflow: hidden` + border-radius, so the extra 8px is clipped. */
.products__hero-card-bg {
  position: absolute;
  inset: -8px;
  z-index: 0;
  overflow: hidden;
  transition: filter 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

.products__hero-card-bg-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  display: block;
}

/* Scanline overlay — flashes briefly during the glitch animation,
   sits ABOVE the live content but BELOW the gray text gradient. */
.products__hero-card-bg::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.05) 0px,
      rgba(255, 255, 255, 0.05) 1px,
      transparent 1px,
      transparent 3px
    );
  mix-blend-mode: overlay;
  opacity: 0;
  pointer-events: none;
  z-index: 2;
}

/* --- Card overlay (neutral gray) for text readability ---
   On hover the overlay partially fades so the live bg becomes more visible
   during the TV-tuning glitch — like the channel tuning in. */
.products__hero-card::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80%;
  background: linear-gradient(
    to top,
    rgba(35, 35, 38, 0.88) 0%,
    rgba(35, 35, 38, 0.78) 35%,
    rgba(35, 35, 38, 0.45) 65%,
    rgba(35, 35, 38, 0) 100%
  );
  pointer-events: none;
  z-index: 1;
  transition: opacity 0.55s cubic-bezier(0.16, 1, 0.3, 1);
}

.products__hero-card:hover::after,
.products__hero-card:focus-visible::after {
  opacity: 0.45;
}

/* --- Card Content --- */
.products__hero-card-content {
  position: relative;
  z-index: 2;
}

/* ============================================
   Card backgrounds — fill 100%, fully visible.
   Default state is crisp and prominent.
   ============================================ */
.products__hero-card-bg {
  transition: filter 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

.products__hero-card-bg-layer {
  width: 100%;
  height: 100%;
  opacity: 0.92;
  transition: opacity 0.45s ease;
}

/* Cursor + focus affordance */
.products__hero-card[data-card] {
  cursor: pointer;
  outline: none;
}

.products__hero-card[data-card]:focus-visible {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.4);
}

/* ============================================
   HOVER — TV channel tuning failure.
   Two beats of disruption inside ~1s, then signal
   stabilizes. Sub-effects:
   - Horizontal slice/translate jumps (signal tear)
   - Brief blur + saturate spikes
   - Hue-rotate flickers (color bleed, no drop-shadow)
   - Scanline overlay flashes
   - Vertical scale stretch on the worst frames
   ============================================ */

/* Outer bg — translate, scale, blur (the "tear" + signal noise) */
@keyframes cardTvGlitch {
  0%   { transform: translate(0, 0)        scale(1);                 filter: none; }
  /* first burst of disruption */
  4%   { transform: translate(-5px, 1px)   scale(1.005, 1.025);      filter: blur(0.6px) saturate(1.35) contrast(1.10); }
  7%   { transform: translate(4px, -1px)   scale(0.995, 1.015);      filter: blur(0.4px) saturate(1.40) hue-rotate(-12deg) contrast(1.12); }
  10%  { transform: translate(-3px, 2px)   scale(1.01, 0.98);        filter: blur(0.7px) hue-rotate(8deg); }
  13%  { transform: translate(2px, -2px)   scale(1, 1.02);            filter: blur(0.3px) saturate(1.25) contrast(1.08); }
  18%  { transform: translate(0, 0)        scale(1);                 filter: blur(0.2px); }
  /* short calm */
  22%  { transform: translate(0, 0)        scale(1);                 filter: none; }
  /* second smaller burst */
  46%  { transform: translate(3px, 0)      scale(1.004, 1.012);      filter: blur(0.4px) hue-rotate(-6deg) saturate(1.20); }
  50%  { transform: translate(-4px, 1px)   scale(1, 0.99);            filter: blur(0.3px) saturate(1.18); }
  54%  { transform: translate(2px, -1px)   scale(1);                 filter: blur(0.2px); }
  60%  { transform: translate(0, 0)        scale(1);                 filter: none; }
  100% { transform: translate(0, 0)        scale(1);                 filter: none; }
}

/* Scanline overlay flash — separate animation for the ::before */
@keyframes cardScanlineFlash {
  0%   { opacity: 0; }
  4%   { opacity: 0.9; }
  7%   { opacity: 0.4; }
  10%  { opacity: 0.85; }
  13%  { opacity: 0.5; }
  18%  { opacity: 0.7; }
  22%  { opacity: 0; }
  46%  { opacity: 0.6; }
  50%  { opacity: 0.3; }
  54%  { opacity: 0.5; }
  60%  { opacity: 0; }
  100% { opacity: 0; }
}

.products__hero-card:hover .products__hero-card-bg,
.products__hero-card:focus-visible .products__hero-card-bg {
  animation: cardTvGlitch 1s steps(60) 1;
}

.products__hero-card:hover .products__hero-card-bg::before,
.products__hero-card:focus-visible .products__hero-card-bg::before {
  animation: cardScanlineFlash 1s steps(60) 1;
}

/* Mobile: disable live backgrounds for perf */
@media (max-width: 768px) {
  .products__hero-card-bg-layer {
    display: none;
  }
}

.products__hero-card-label {
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 12px;
  display: block;
}

.products__hero-card-title {
  font-size: clamp(4rem, 8vw, 8rem);
  font-weight: 400;
  letter-spacing: -0.02em;
  color: #FFF;
  line-height: 0.95;
  margin-bottom: 12px;
}

.products__hero-card-subtitle {
  font-size: 18px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 24px;
  line-height: 1.4;
}

/* --- Feature Pills --- */
.products__hero-card-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.products__hero-card-pills .pill {
  padding: 8px 16px;
  font-size: 11px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: transparent;
  color: #FFF;
}

.products__hero-card-pills .pill:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.5);
}

/* ============================================
   PHASE B — Capabilities Grid
   ============================================ */

.products__capabilities {
  padding-top: var(--section-gap-medium);
}

/* --- Heading --- */
.products__capabilities-header {
  margin-bottom: 40px;
}

.products__capabilities-title {
  font-size: clamp(56px, 7vw, 110px);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--text-primary);
}

/* --- Grid --- */
.products__capabilities-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  column-gap: 3vw;
  row-gap: 60px;
}

/* --- Capability Card ---
   The card is a real live product preview: the bg shows a mini chart,
   and the text (tags + headline) stays BELOW in normal flow. A small
   overlay label sits in the top-left of the bg. Expanding grows the bg
   to a wider aspect ratio and reveals the full mini-dashboard. */
.products__capability-card {
  position: relative;
  cursor: pointer;
  outline: none;
}



/* Hint label — visible only on hover, hides when expanded */
.products__capability-card-hint {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 4;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(0, 0, 0, 0.45);
  /* backdrop-filter removed for performance — using solid bg instead */
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.products__capability-card:hover .products__capability-card-hint,
.products__capability-card:focus-visible .products__capability-card-hint {
  opacity: 1;
  transform: translateY(0);
}


/* --- Card Background — the live preview area ---
   Normal flow sibling: aspect-ratio 16/10 in the regular grid, 21/9 when
   the card is expanded. The actual viz fills this area; the text content
   flows BELOW the bg in the document. */
.products__capability-card-bg {
  position: relative;
  border-radius: var(--radius-card);
  overflow: hidden;
  aspect-ratio: 16 / 10;
  isolation: isolate;
  background: #0e0e14;
  transition: aspect-ratio 0.6s cubic-bezier(0.16, 1, 0.3, 1),
              filter 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

/* When WebGL is rendering the card preview, hide the DOM bg */
.products__capability-card-bg.webgl-active {
  opacity: 0 !important;
}

/* Colored gradient — VERY transparent, just a subtle tint behind the viz.
   Float animation + TV glitch on hover. Fades completely on expand. */
.products__capability-card-bg::before {
  content: '';
  position: absolute;
  inset: -8px;
  background: var(--cap-bg, linear-gradient(135deg, #3436B1, #CF2A2E));
  z-index: 0;
  opacity: 0.22;
  animation: capCardFloat 18s ease-in-out infinite;
  transition: opacity 0.55s cubic-bezier(0.16, 1, 0.3, 1);
}


/* Scanline flash — sits above the viz as a screen-tune artifact on hover */
.products__capability-card-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.05) 0px,
    rgba(255, 255, 255, 0.05) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: overlay;
  opacity: 0;
  pointer-events: none;
  z-index: 3;
}

/* Per-sensor gradients applied as a CSS variable so the ::before inherits. */
/* Per-sensor gradients — set on card-bg AND inherited by card ::after mask */
.products__capability-card-bg--energia       { --cap-bg: linear-gradient(135deg, #F47D4E 0%, #CF2A2E 100%); }
.products__capability-card-bg--temperatura   { --cap-bg: linear-gradient(135deg, #CF2A2E 0%, #3436B1 100%); }
.products__capability-card-bg--agua          { --cap-bg: linear-gradient(135deg, #3436B1 0%, #61B65D 100%); }
.products__capability-card-bg--vibracao      { --cap-bg: linear-gradient(135deg, #F47D4E 0%, #3436B1 100%); }
.products__capability-card-bg--pressao       { --cap-bg: linear-gradient(135deg, #3436B1 0%, #CF2A2E 50%, #F47D4E 100%); }
.products__capability-card-bg--rastreamento  { --cap-bg: linear-gradient(135deg, #61B65D 0%, #3436B1 100%); }


/* Stagger the floating animation per card so they don't move in lockstep */
.products__capabilities-grid > :nth-child(1) .products__capability-card-bg::before { animation-delay: 0s; }
.products__capabilities-grid > :nth-child(2) .products__capability-card-bg::before { animation-delay: -3s; }
.products__capabilities-grid > :nth-child(3) .products__capability-card-bg::before { animation-delay: -6s; }
.products__capabilities-grid > :nth-child(4) .products__capability-card-bg::before { animation-delay: -9s; }
.products__capabilities-grid > :nth-child(5) .products__capability-card-bg::before { animation-delay: -12s; }
.products__capabilities-grid > :nth-child(6) .products__capability-card-bg::before { animation-delay: -15s; }

@keyframes capCardFloat {
  0%, 100% { transform: scale(1.04) translate(-1%, -1%); }
  33%      { transform: scale(1.06) translate(1.5%, 0.5%); }
  66%      { transform: scale(1.05) translate(-0.5%, 1.5%); }
}

/* Pause infinite animations when card is off-screen (set by JS IntersectionObserver) */
.products__capability-card:not(.in-viewport) .products__capability-card-bg::before {
  animation-play-state: paused;
}
.products__capability-card:not(.in-viewport) .products__capability-card-overlay::before {
  animation-play-state: paused;
}

/* Mount target for the live ECharts viz — fills the bg, above the
   colored gradient, below the scanline flash. */
.products__capability-card-viz {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

/* Block ALL interaction inside card bg — charts are preview-only.
   The gradient mask (WebGL) is the only clickable surface. */
.products__capability-card-bg,
.products__capability-card-bg * {
  pointer-events: none !important;
  cursor: pointer;
}


/* Small overlay label inside the card (top-left) — a live-metric tag
   that's DIFFERENT from the H4 headline below. Fades out when expanded. */
.products__capability-card-overlay {
  position: absolute;
  top: 16px;
  left: 18px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.products__capability-card-overlay::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.22);
  animation: capOverlayPulse 2s ease-in-out infinite;
}


@keyframes capOverlayPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.55; transform: scale(0.82); }
}

/* Hover: TV glitch on the colored gradient + scanline flash on the bg */
.products__capability-card:hover .products__capability-card-bg::before,
.products__capability-card:focus-visible .products__capability-card-bg::before {
  animation: cardTvGlitch 1s steps(60) 1, capCardFloat 18s ease-in-out infinite;
}

.products__capability-card:hover .products__capability-card-bg::after,
.products__capability-card:focus-visible .products__capability-card-bg::after {
  animation: cardScanlineFlash 1s steps(60) 1;
}

.products__capability-card:hover .products__capability-card-bg,
.products__capability-card:focus-visible .products__capability-card-bg {
  filter: saturate(1.10) contrast(1.05);
}

.products__capability-card:focus-visible .products__capability-card-bg {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.4);
}

/* --- Card Content (text BELOW the card) --- */
.products__capability-card-content {
  padding-top: 20px;
}

/* --- Tags --- */
.products__capability-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.products__capability-card-tags .label + .label::before {
  content: '\00B7';
  margin-right: 8px;
  color: var(--text-muted);
}

/* --- Title with arrow --- */
.products__capability-card-title {
  font-size: clamp(22px, 2.5vw, 34px);
  font-weight: 400;
  color: var(--text-primary);
  line-height: 1.2;
}

/* --- Slot machine text animation support ---
   .title-clip wraps the text area. Its height is set by JS to match
   the original text height BEFORE char splitting. This lets overflow:hidden
   clip the 4 stacked copies above/below the visible character. */
/* --- Slot machine text animation support --- */
.title-clip {
  display: inline;
}

.title-inner {
  display: inline;
}

/* Character spans — entry animation sets inline styles via JS (RAF),
   then JS adds a CSS transition and stops. Hover is 100% CSS. */
.char-col {
  display: inline-block;
}

/* Hover shift — triggered by .is-hovered class on .title-inner.
   CSS transition is added by JS after entry completes, so this
   runs at native browser 60fps with zero JS per frame. */
.title-inner.is-hovered .char-col {
  transform: translateX(0.25em) !important;
}

/* --- Arrow — hidden by default, slides in on hover.
   Negative margin collapses its space when hidden;
   margin returns to 0 on hover, pushing the text right. --- */
.products__capability-card-arrow {
  display: inline-block;
  font-size: 0.8em;
  width: 1em;
  margin-right: 0.35em;
  margin-left: -1.35em; /* = -(width + margin-right) → net 0 space */
  opacity: 0;
  vertical-align: baseline;
  transition: margin-left 0.45s cubic-bezier(0.35, 0, 0, 1),
              opacity 0.35s cubic-bezier(0.35, 0, 0, 1);
  transition-delay: 0.1s;
}

/* Arrow appears on TEXT hover, not card hover */
.products__capability-card-content:hover .products__capability-card-arrow {
  margin-left: 0;
  opacity: 1;
}

/* --- Hero card pill hover shift (Lusion-inspired) --- */
.products__hero-card-pills .pill {
  transition: transform 0.4s cubic-bezier(0.35, 0, 0, 1),
              background 0.3s ease,
              border-color 0.3s ease;
}

.products__hero-card:hover .products__hero-card-pills .pill {
  transform: translateX(0.3em);
}

.products__hero-card:hover .products__hero-card-pills .pill:nth-child(2) { transition-delay: 0.04s; }
.products__hero-card:hover .products__hero-card-pills .pill:nth-child(3) { transition-delay: 0.08s; }
.products__hero-card:hover .products__hero-card-pills .pill:nth-child(4) { transition-delay: 0.12s; }

/* ============================================
   ZOOM — Cinematic card expansion
   ============================================ */

/* Blackout is handled 100% in WebGL shader (u_blackout uniform).
   CSS only hides the hint label. */
.products__capability-card.cap-card--blacking-out .products__capability-card-hint {
  opacity: 0;
  transition: opacity 0.3s ease;
}

/* Zoom wrapper — no styles by default, transform applied by JS */
#site-zoom-wrapper {
  /* empty — JS sets transform, transform-origin, transition */
}

/* ============================================
   EXPANDED OVERLAY — fullscreen dashboard
   ============================================ */
.cap-expanded-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #0e0e14;
  padding-top: 110px;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.cap-expanded-overlay[hidden] {
  display: none;
}

.cap-expanded-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
}

/* --- Topbar --- */
.cap-expanded-overlay__topbar {
  display: flex;
  justify-content: center;
  padding: 16px 24px;
  flex-shrink: 0;
}

/* --- VOLTAR button with Lusion hover animation --- */
.cap-expanded-overlay__back {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 34px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  cursor: pointer;
  overflow: hidden;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  transition: background 0.3s ease, border-color 0.3s ease;
}

.cap-expanded-overlay__back:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
}

/* Chevron arrows — large, pointy ‹, vertically centered with text */
.cap-expanded-overlay__back-arrow-left,
.cap-expanded-overlay__back-arrow-right {
  font-size: 1.6em;
  line-height: 0;
  font-weight: 300;
  display: flex;
  align-items: center;
  margin-top: -0.05em;
}

/* Arrow left ‹ : visible by default, slides left fast + fades on hover */
.cap-expanded-overlay__back-arrow-left {
  transition: transform 0.25s cubic-bezier(0.35, 0, 0, 1),
              opacity 0.2s cubic-bezier(0.35, 0, 0, 1);
}

.cap-expanded-overlay__back:hover .cap-expanded-overlay__back-arrow-left,
.cap-expanded-overlay__back.is-frozen .cap-expanded-overlay__back-arrow-left {
  transform: translateX(-1.2em);
  opacity: 0;
}

/* Text: slides left on hover (pushed by right arrow arriving) */
.cap-expanded-overlay__back-text {
  transition: transform 0.4s cubic-bezier(0.35, 0, 0, 1);
}

.cap-expanded-overlay__back:hover .cap-expanded-overlay__back-text,
.cap-expanded-overlay__back.is-frozen .cap-expanded-overlay__back-text {
  transform: translateX(-0.9em);
}

/* Arrow right ‹ : hidden, slides in from the RIGHT side, pushing text left */
.cap-expanded-overlay__back-arrow-right {
  opacity: 0;
  transform: translateX(0.6em);
  margin-left: -0.3em;
  transition: transform 0.4s cubic-bezier(0.35, 0, 0, 1) 0.08s,
              opacity 0.25s cubic-bezier(0.35, 0, 0, 1) 0.08s;
}

.cap-expanded-overlay__back:hover .cap-expanded-overlay__back-arrow-right,
.cap-expanded-overlay__back.is-frozen .cap-expanded-overlay__back-arrow-right {
  opacity: 1;
  transform: translateX(0);
}

/* --- Content area (dashboard mount) --- */
.cap-expanded-overlay__content {
  flex: 1;
  padding: 0 clamp(24px, 4vw, 80px) 24px;
  min-height: 0;
  overflow-y: auto;
}
