/* =====================================================================
   DataMagic WMS — "Élő tárhely-rács" (Living Bin Grid)
   Scroll-driven digital-twin background, Lenis + GSAP ScrollTrigger.
   Loaded ONLY on /wms, /en/wms, /de/wms. Activates under body.wms-grid
   (the class is added by js/wms-grid.js only after a successful init →
   no-JS / failed-load leaves the page exactly as before).
   ===================================================================== */

/* ---- Lenis baseline ---- */
html.lenis, html.lenis body { height: auto; }
.lenis.lenis-smooth { scroll-behavior: auto !important; }
.lenis.lenis-smooth [data-lenis-prevent] { overscroll-behavior: contain; }
.lenis.lenis-stopped { overflow: hidden; }
.lenis.lenis-smooth iframe { pointer-events: none; }

/* ---- Layering: content floats above the fixed floor ----
   NOTE: do NOT touch the header — it keeps its native sticky z-index:100
   so the nav dropdowns + language menu stay above the sections. */
body.wms-grid > section,
body.wms-grid > footer { position: relative; z-index: 1; }

/* Glassy panels so the living grid breathes through without hurting text */
body.wms-grid section.alt {
  background: rgba(11, 11, 33, 0.58);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
body.wms-grid section:not(.alt):not(.cta-strip):not(.page-header) {
  background: transparent;
}
body.wms-grid .page-header { background: transparent; }

/* =====================================================================
   3D warehouse hero scene (js/wms-warehouse.js) — above the grid floor,
   below content. Opacity is JS-driven (scroll-dissolve into the grid).
   ===================================================================== */
#wms-scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.3s ease;
  background: radial-gradient(72% 60% at 50% 36%, rgba(20, 18, 58, 0.32) 0%, rgba(9, 9, 30, 0.55) 55%, rgba(7, 7, 26, 0.85) 100%);
}
/* persistent, faint backdrop so text + cards stay clearly readable */
#wms-scene.on { opacity: 0.42; }

/* when the 3D warehouse is running, it replaces the bin-grid floor
   (the grid stays as the graceful no-WebGL / reduced-motion fallback) */
body.wms-scene-on #wms-floor { display: none; }
#wms-scene canvas { display: block; width: 100%; height: 100%; }
#wms-scene .scene-scrim {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(56% 40% at 50% 46%, rgba(7, 7, 26, 0.5) 0%, rgba(7, 7, 26, 0) 70%),
    linear-gradient(180deg, rgba(7, 7, 26, 0.32) 0%, rgba(7, 7, 26, 0) 28%, rgba(7, 7, 26, 0.55) 100%);
}

/* =====================================================================
   The fixed floor
   ===================================================================== */
#wms-floor {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  opacity: 0;
  transition: opacity 1s ease;
  --tilt: 0deg;
  --depth: 0px;
  --vel: 0;
  contain: layout paint style;
}
body.wms-grid.floor-ready #wms-floor { opacity: 1; }

/* Ambient backlight */
#wms-floor .floor-glow {
  position: absolute;
  left: 50%; top: 46%;
  width: 120vw; height: 120vh;
  transform: translate(-50%, -50%);
  background:
    radial-gradient(40% 38% at 50% 42%, rgba(73, 63, 219, 0.20) 0%, rgba(7, 7, 26, 0) 70%),
    radial-gradient(60% 50% at 50% 60%, rgba(139, 121, 250, 0.10) 0%, rgba(7, 7, 26, 0) 72%);
  transition: opacity 1s ease, background 1.2s ease;
}

/* The grid panel fills the whole viewport (full-bleed) */
#wms-floor .floor-panel {
  position: absolute;
  inset: 0;
  transform: perspective(1700px)
             rotateX(calc(var(--tilt, 0) * 1deg))
             scale(calc(1 + (var(--tilt, 0) * 0.014)));
  transform-origin: 50% 46%;
  will-change: transform;
}

#wms-floor .floor-grid {
  position: absolute;
  inset: -6% -3%;                 /* slight bleed so tilt never reveals edges */
  display: grid;
  grid-template-columns: repeat(var(--cols, 16), 1fr);
  grid-auto-rows: 1fr;
  gap: clamp(5px, 0.55vw, 11px);
}

/* ---- A single bin ---- */
#wms-floor .bin {
  position: relative;
  border: 1px solid rgba(155, 152, 212, 0.16);
  border-radius: 6px;
  background: rgba(139, 121, 250, 0.018);
  opacity: 0.5;
  transition:
    background 0.7s ease,
    border-color 0.7s ease,
    box-shadow 0.7s ease,
    opacity 0.7s ease,
    transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
#wms-floor .bin::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 4px;
  background: currentColor;
  opacity: 0;
  transition: opacity 0.7s ease;
}

/* Location-code labels on a few bins (mono telemetry) */
#wms-floor .bin.lbl::before {
  content: attr(data-code);
  position: absolute;
  left: 5px; bottom: 3px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: clamp(6px, 0.62vw, 9px);
  letter-spacing: 0.02em;
  color: rgba(155, 152, 212, 0.45);
  opacity: 0;
  transition: opacity 0.7s ease;
  white-space: nowrap;
}
#wms-floor.p-hero .bin.lbl::before,
#wms-floor.p-show .bin.lbl::before { opacity: 1; }

/* =====================================================================
   Phases — driven by classes on #wms-floor
   ===================================================================== */

/* HERO + SHOW: empty wireframe coming online */
#wms-floor.p-hero .bin,
#wms-floor.p-show .bin { opacity: 0.55; }

/* BROKEN: fault cells flare burgundy (matches .challenges-grid wine theme) */
#wms-floor.p-broken .bin { opacity: 0.4; }
#wms-floor.p-broken .bin.s-fault {
  color: transparent;
  opacity: 1;
  border-color: rgba(200, 70, 100, 0.55);
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(180, 60, 90, 0.30) 0%, rgba(35, 8, 18, 0) 65%),
    linear-gradient(160deg, #2a0e18 0%, #1a060f 100%);
  box-shadow: 0 0 16px -4px rgba(180, 60, 90, 0.5),
              0 0 0 1px rgba(180, 60, 90, 0.18) inset;
  animation: bin-fault 2.4s ease-in-out infinite;
}
#wms-floor.p-broken .bin.s-unknown {
  opacity: 0.85;
  border-color: rgba(200, 70, 100, 0.3);
  color: rgba(232, 120, 140, 0.9);
}
#wms-floor.p-broken .bin.s-unknown::after { opacity: 0; }
#wms-floor .bin .q {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  color: rgba(232, 120, 140, 0.85);
  opacity: 0;
  transition: opacity 0.6s ease;
}
#wms-floor.p-broken .bin.s-unknown .q { opacity: 1; }
@keyframes bin-fault {
  0%, 100% { box-shadow: 0 0 16px -6px rgba(180, 60, 90, 0.45), 0 0 0 1px rgba(180, 60, 90, 0.16) inset; }
  50%      { box-shadow: 0 0 24px -4px rgba(220, 90, 120, 0.7),  0 0 0 1px rgba(220, 90, 120, 0.28) inset; }
}

/* HEAL: a mint commit-wave sweeps; faults resolve to healthy purple */
#wms-floor.p-heal .bin { opacity: 0.6; }
#wms-floor.p-heal .bin.s-fault {
  color: var(--primary);
  border-color: var(--primary-line);
  background: rgba(139, 121, 250, 0.10);
  box-shadow: none;
  animation: none;
}
#wms-floor.p-heal .bin.s-fault::after { opacity: 0.16; }

/* LIVE: full color-coded warehouse map */
#wms-floor.p-live .bin,
#wms-floor.p-zones .bin,
#wms-floor.p-connected .bin { opacity: 0.92; }
#wms-floor.p-live .bin.s-ok,
#wms-floor.p-zones .bin.s-ok,
#wms-floor.p-connected .bin.s-ok {
  color: var(--primary);
  border-color: rgba(139, 121, 250, 0.45);
}
#wms-floor.p-live .bin.s-ok::after,
#wms-floor.p-zones .bin.s-ok::after { opacity: 0.16; }

#wms-floor.p-live .bin.s-warn,
#wms-floor.p-zones .bin.s-warn {
  color: rgba(255, 176, 0, 1);
  border-color: rgba(255, 176, 0, 0.45);
}
#wms-floor.p-live .bin.s-warn::after,
#wms-floor.p-zones .bin.s-warn::after { opacity: 0.14; }

#wms-floor.p-live .bin.s-pick,
#wms-floor.p-zones .bin.s-pick {
  color: var(--accent);
  border-color: rgba(45, 220, 177, 0.5);
}
#wms-floor.p-live .bin.s-pick::after,
#wms-floor.p-zones .bin.s-pick::after { opacity: 0.2; }
#wms-floor.p-live .bin.s-pick {
  box-shadow: 0 0 18px -6px rgba(45, 220, 177, 0.55);
}

/* CONNECTED: calm down; pick cells keep a slow heartbeat */
#wms-floor.p-connected .bin { opacity: 0.72; }
#wms-floor.p-connected .bin.s-warn { color: var(--primary); border-color: rgba(139,121,250,.4); }
#wms-floor.p-connected .bin.s-pick {
  animation: bin-beat 3.2s ease-in-out infinite;
}
@keyframes bin-beat {
  0%, 100% { box-shadow: 0 0 10px -6px rgba(45, 220, 177, 0.4); }
  50%      { box-shadow: 0 0 22px -4px rgba(45, 220, 177, 0.7); }
}

/* =====================================================================
   The mint commit-wave overlay (heal phase)
   ===================================================================== */
#wms-floor .floor-sweep {
  position: absolute;
  inset: -10% -30%;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(115deg,
    rgba(45, 220, 177, 0) 38%,
    rgba(45, 220, 177, 0.55) 50%,
    rgba(45, 220, 177, 0) 62%);
  mix-blend-mode: screen;
  transform: translateX(-60%);
}
#wms-floor.p-heal .floor-sweep {
  animation: floor-sweep 1.5s cubic-bezier(0.4, 0, 0.2, 1) 1 forwards;
}
@keyframes floor-sweep {
  0%   { opacity: 0;    transform: translateX(-60%); }
  20%  { opacity: 0.9; }
  100% { opacity: 0;    transform: translateX(60%); }
}

/* =====================================================================
   Scan-line (idle "alive" sweep)
   ===================================================================== */
#wms-floor .floor-scan {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 14%;
  pointer-events: none;
  background: linear-gradient(180deg,
    rgba(139, 121, 250, 0) 0%,
    rgba(139, 121, 250, 0.12) 60%,
    rgba(139, 121, 250, 0.28) 100%);
  border-bottom: 1px solid rgba(139, 121, 250, 0.4);
  opacity: 0.5;
  animation: floor-scan 6.5s linear infinite;
}
#wms-floor.p-live .floor-scan,
#wms-floor.p-zones .floor-scan { opacity: 0.65; }
#wms-floor.p-connected .floor-scan { opacity: 0.25; }
@keyframes floor-scan {
  0%   { transform: translateY(-20%); opacity: 0; }
  10%  { opacity: 0.55; }
  90%  { opacity: 0.55; }
  100% { transform: translateY(740%); opacity: 0; }
}

/* =====================================================================
   Picking-route lines (process phase)
   ===================================================================== */
#wms-floor .floor-routes {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  overflow: visible;
}
#wms-floor .floor-routes path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
  filter: drop-shadow(0 0 6px rgba(45, 220, 177, 0.6));
  stroke-dasharray: var(--len, 1200);
  stroke-dashoffset: var(--len, 1200);
  transition: opacity 0.6s ease;
}
#wms-floor.p-live .floor-routes path { opacity: 0.9; }
#wms-floor .floor-routes path.r2 { stroke: var(--primary); }

/* =====================================================================
   Zone tints (industry phase) — 5 vertical bands
   ===================================================================== */
#wms-floor .floor-zones {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  opacity: 0;
  transition: opacity 0.9s ease;
}
#wms-floor.p-zones .floor-zones { opacity: 1; }
#wms-floor .floor-zones span {
  border-right: 1px dashed rgba(155, 152, 212, 0.14);
  transition: background 0.7s ease;
}
#wms-floor .floor-zones span:last-child { border-right: 0; }
#wms-floor.p-zones .floor-zones span.z-on:nth-child(1) { background: rgba(45, 220, 177, 0.05); }
#wms-floor.p-zones .floor-zones span.z-on:nth-child(2) { background: rgba(96, 165, 250, 0.07); }
#wms-floor.p-zones .floor-zones span.z-on:nth-child(3) { background: rgba(139, 121, 250, 0.06); }
#wms-floor.p-zones .floor-zones span.z-on:nth-child(4) { background: rgba(45, 220, 177, 0.05); }
#wms-floor.p-zones .floor-zones span.z-on:nth-child(5) { background: rgba(255, 176, 0, 0.06); }

/* =====================================================================
   HUD chip (top-left telemetry)
   ===================================================================== */
#wms-floor .floor-hud {
  position: absolute;
  left: clamp(12px, 4vw, 48px);
  top: calc(var(--wms-header-h, 64px) + 18px);
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(155, 152, 212, 0.7);
  opacity: 0;
  transition: opacity 0.8s ease, color 0.8s ease;
}
body.wms-grid.floor-ready #wms-floor .floor-hud { opacity: 1; }
#wms-floor .floor-hud .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(45, 220, 177, 0.16), 0 0 10px rgba(45, 220, 177, 0.65);
  animation: bin-beat 2.4s ease-in-out infinite;
}
#wms-floor.p-broken .floor-hud { color: rgba(232, 120, 140, 0.85); }
#wms-floor.p-broken .floor-hud .dot {
  background: rgba(220, 90, 120, 1);
  box-shadow: 0 0 0 3px rgba(220, 90, 120, 0.16), 0 0 10px rgba(220, 90, 120, 0.7);
}

/* =====================================================================
   Converge / FLIP-ish moment (Live Platform) — handled with JS adding
   .is-converging; floor scales toward the real wms-2d screenshot + fades.
   ===================================================================== */
#wms-floor.is-converging .floor-scan,
#wms-floor.is-converging .floor-hud { opacity: 0; }

/* The real screenshots get a scan-in highlight when they take over */
body.wms-grid [data-floor="live"] .tms-mockup { will-change: transform, opacity; }
body.wms-grid .floor-handoff {
  box-shadow:
    0 30px 70px -24px rgba(0, 0, 0, 0.8),
    0 0 60px -10px rgba(45, 220, 177, 0.4),
    0 0 0 1px rgba(45, 220, 177, 0.3) inset !important;
}

/* =====================================================================
   Reveal hooks — JS animates [data-reveal] items in. Initial hidden
   state is set by GSAP (.from), so without JS nothing is hidden.
   ===================================================================== */
body.wms-grid [data-reveal] { will-change: transform, opacity; }

/* Let GSAP own `transform` during the 3D reveals — keep the CSS hover
   transitions only on colour/shadow so they don't fight the animation. */
body.wms-grid .why-item,
body.wms-grid .challenges-grid .why-item { transition-property: border-color, background, box-shadow; }
body.wms-grid .tms-mockup { transition-property: border-color, box-shadow; }

/* =====================================================================
   Reduced motion / mobile tuning
   ===================================================================== */
@media (max-width: 860px) {
  #wms-floor .floor-panel { width: 96vw; }
  #wms-floor .floor-hud { font-size: 0.62rem; }
}

@media (prefers-reduced-motion: reduce) {
  /* JS won't init the experience, but guard the CSS animations too */
  #wms-floor .bin,
  #wms-floor .floor-scan,
  #wms-floor .floor-sweep,
  #wms-floor .floor-hud .dot { animation: none !important; }
}

/* =====================================================================
   Pick-a-Bin — live WMS bin-card (js/wms-warehouse.js): tap a pallet and
   its real-shaped stock record snaps out on a leader line.
   ===================================================================== */
#wms-binleader {
  position: fixed; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 59; overflow: visible;
}
#wms-binleader line {
  stroke: rgba(45, 220, 177, 0.85); stroke-width: 1.5; stroke-dasharray: 3 3;
}
#wms-bincard {
  position: fixed; z-index: 60; width: min(266px, 84vw);
  max-height: calc(100vh - 24px); overflow-y: auto; overscroll-behavior: contain;
  pointer-events: auto; padding: 14px 14px 10px; border-radius: 14px;
  background: linear-gradient(180deg, rgba(20, 18, 48, 0.92), rgba(11, 11, 30, 0.95));
  border: 1px solid rgba(45, 220, 177, 0.32);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.85),
              0 0 0 1px rgba(139, 121, 250, 0.12) inset,
              0 0 30px -8px rgba(45, 220, 177, 0.35);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  color: #e9e7ff; font-size: 13px; line-height: 1.35;
  opacity: 0; transform: translateY(6px) scale(0.97); transform-origin: left center;
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
@media (max-width: 860px) { #wms-bincard { backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); } }
#wms-bincard.on { opacity: 1; transform: translateY(0) scale(1); }
#wms-bincard .bc-x {
  position: absolute; top: 8px; right: 8px; width: 22px; height: 22px;
  border: 0; border-radius: 7px; background: rgba(255, 255, 255, 0.06);
  color: rgba(233, 231, 255, 0.7); font-size: 15px; line-height: 1; cursor: pointer;
}
#wms-bincard .bc-x:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
#wms-bincard .bc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; padding-right: 24px; }
#wms-bincard .bc-code {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 18px; font-weight: 700; letter-spacing: 0.04em; color: #fff;
}
#wms-bincard .bc-badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 3px 7px; border-radius: 999px; white-space: nowrap;
}
#wms-bincard .bc-badge.ok { background: rgba(45, 220, 177, 0.16); color: #58e6c0; }
#wms-bincard .bc-badge.amber { background: rgba(255, 176, 0, 0.16); color: #ffce6a; }
#wms-bincard .bc-badge.warn { background: rgba(232, 90, 120, 0.18); color: #ff8aa0; }
#wms-bincard .bc-badge.purple { background: rgba(139, 121, 250, 0.18); color: #b9acff; }
#wms-bincard .bc-art {
  font-size: 13.5px; font-weight: 600; color: #fff;
  margin-bottom: 9px; padding-bottom: 9px; border-bottom: 1px solid rgba(155, 152, 212, 0.16);
}
#wms-bincard .bc-row { display: flex; justify-content: space-between; gap: 12px; padding: 2.5px 0; }
#wms-bincard .bc-row .bc-l { color: rgba(155, 152, 212, 0.85); }
#wms-bincard .bc-row .bc-v {
  font-family: "JetBrains Mono", ui-monospace, monospace; color: #e9e7ff; text-align: right;
}
#wms-bincard .bc-row.val .bc-v { color: #58e6c0; font-weight: 700; }
#wms-bincard .bc-row.amber .bc-v { color: #ffce6a; }
#wms-bincard .bc-row.warn .bc-v { color: #ff8aa0; }
#wms-bincard .bc-foot {
  display: flex; align-items: center; gap: 6px; margin-top: 9px; padding-top: 8px;
  border-top: 1px solid rgba(155, 152, 212, 0.16);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: rgba(155, 152, 212, 0.65);
}
#wms-bincard .bc-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent, #2ddcb1);
  box-shadow: 0 0 8px rgba(45, 220, 177, 0.8); animation: bin-beat 2.4s ease-in-out infinite;
}
#wms-bincard .bc-fill { margin-top: 9px; }
#wms-bincard .bc-fill-l { display: flex; justify-content: space-between; font-size: 11px; color: rgba(155, 152, 212, 0.85); margin-bottom: 4px; }
#wms-bincard .bc-fill-l span:last-child { font-family: "JetBrains Mono", ui-monospace, monospace; color: #e9e7ff; }
#wms-bincard .bc-fill-bar { height: 6px; border-radius: 999px; background: rgba(155, 152, 212, 0.16); overflow: hidden; }
#wms-bincard .bc-fill-bar i { display: block; height: 100%; border-radius: 999px; transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1); }
#wms-bincard .bc-fill-bar i.ok { background: linear-gradient(90deg, #2ddcb1, #58e6c0); }
#wms-bincard .bc-fill-bar i.amber { background: linear-gradient(90deg, #ffb22e, #ffce6a); }
#wms-bincard .bc-fill-bar i.warn { background: linear-gradient(90deg, #e85a78, #ff8aa0); }

@media (prefers-reduced-motion: reduce) {
  #wms-bincard { transition: none; }
  #wms-bincard .bc-dot { animation: none; }
  #wms-bincard .bc-fill-bar i { transition: none; }
}
