/* ==========================================================================
   Investama Workflow Component — Scoped Styles
   ========================================================================== */

.iwf-component {
  --iwf-bg-center: #f7f8f9;
  --iwf-bg-mid: #dedfe2;
  --iwf-bg-edge: #b4b6ba;
  --iwf-ink: #1e2024;
  --iwf-ink-muted: #383b42;
  --iwf-accent: #f3b528;
  --iwf-accent-deep: #b87300;
  --iwf-accent-glow: rgba(243, 181, 40, 0.38);
  --iwf-card-active-bg: rgba(255, 255, 255, 0.74);
  --iwf-badge-core: #c8cacf;
  --iwf-focus-ring: #b85d00;
  --iwf-radius: 16px;
  --iwf-font: "Plus Jakarta Sans", "Montserrat", "Segoe UI", system-ui, -apple-system, sans-serif;

  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  box-sizing: border-box;
  padding: clamp(0.85rem, 1.6vw, 1.35rem) clamp(0.85rem, 1.8vw, 1.5rem) clamp(0.85rem, 1.6vw, 1.25rem);
  font-family: var(--iwf-font);
  color: var(--iwf-ink);
  background: radial-gradient(circle at 50% 42%, var(--iwf-bg-center) 0%, var(--iwf-bg-mid) 52%, var(--iwf-bg-edge) 100%);
  border-radius: var(--iwf-radius);
  overflow: hidden;
  container-type: inline-size;
  container-name: iwf;
}

.iwf-component *,
.iwf-component *::before,
.iwf-component *::after {
  box-sizing: border-box;
}

/* Visually hidden utility (accessible, unclipped on focus) */
.iwf-visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

/* Focus indicators */
.iwf-component :where(button):focus-visible {
  outline: 3px solid var(--iwf-focus-ring);
  outline-offset: 2px;
}

/* Header */
.iwf-header {
  position: relative;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.45rem;
  margin-bottom: 0.65rem;
}

.iwf-title {
  margin: 0;
  font-size: clamp(1.25rem, 2.5vw, 2.15rem);
  font-weight: 800;
  line-height: 1.12;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--iwf-ink);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.iwf-title-sub {
  font-size: 0.92em;
  font-weight: 800;
}

.iwf-phase-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.85rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(30, 32, 36, 0.1);
  box-shadow: 0 3px 12px rgba(15, 23, 42, 0.06);
  font-size: 0.78rem;
  color: var(--iwf-ink-muted);
}

.iwf-phase-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--iwf-accent);
  box-shadow: 0 0 0 3px var(--iwf-accent-glow);
}

.iwf-phase-kicker {
  font-weight: 600;
  opacity: 0.82;
}

.iwf-phase-name {
  font-weight: 700;
  color: var(--iwf-ink);
}

.iwf-phase-counter {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--iwf-accent-deep);
  padding-left: 0.35rem;
  border-left: 1px solid rgba(30, 32, 36, 0.16);
}

/* Stage: Default mobile-first vertical flow */
.iwf-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  width: 100%;
}

.iwf-canvas-wrap {
  position: relative;
  width: 100%;
  height: 300px;
  border-radius: 12px;
  overflow: hidden;
}

.iwf-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: pan-y;
}

.iwf-canvas:active {
  cursor: grabbing;
}

.iwf-canvas.is-hovering-node {
  cursor: pointer;
}

.iwf-webgl-fallback,
.iwf-noscript {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  text-align: center;
  font-size: 0.9rem;
  color: var(--iwf-ink-muted);
  background: rgba(255, 255, 255, 0.55);
}

.iwf-webgl-fallback[hidden] {
  display: none;
}

/* Leader Lines SVG (desktop stage overlay) */
.iwf-leaders {
  display: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  overflow: visible;
}

.iwf-leader-line {
  stroke: rgba(255, 255, 255, 0.86);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke 260ms ease, stroke-width 260ms ease, opacity 260ms ease;
}

.iwf-leader-glow {
  stroke: var(--iwf-accent);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
  transition: opacity 260ms ease;
}

.iwf-leader-dot {
  fill: #ffffff;
  stroke: rgba(30, 32, 36, 0.25);
  stroke-width: 1;
  transition: fill 260ms ease, r 260ms ease;
}

.iwf-leader-pulse {
  fill: var(--iwf-accent);
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
}

.iwf-leader.is-completed .iwf-leader-line {
  stroke: rgba(255, 240, 196, 0.95);
}

.iwf-leader.is-active .iwf-leader-line {
  stroke: #ffffff;
  stroke-width: 2;
}

.iwf-leader.is-active .iwf-leader-glow {
  opacity: 0.72;
}

.iwf-leader.is-active .iwf-leader-dot {
  fill: var(--iwf-accent);
  stroke: #ffffff;
  stroke-width: 1.5;
}

.iwf-leader.is-active .iwf-leader-pulse {
  opacity: 0.45;
}

@media (prefers-reduced-motion: no-preference) {
  .iwf-leader.is-active .iwf-leader-pulse {
    animation: iwf-pulse-dot 1.8s ease-out infinite;
  }
}

/* Cards list: mobile-first 1 column */
.iwf-cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
}

.iwf-card-slot {
  display: block;
}

.iwf-card {
  appearance: none;
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.34);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 260ms ease, box-shadow 260ms ease, transform 260ms ease, border-color 260ms ease;
}

.iwf-card:hover {
  background: rgba(255, 255, 255, 0.56);
  border-color: rgba(255, 255, 255, 0.75);
}

.iwf-card.is-active {
  will-change: transform, opacity;
  background: var(--iwf-card-active-bg);
  border-color: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.09), 0 0 0 1px rgba(243, 181, 40, 0.25);
  transform: translateY(-2px);
}

.iwf-card.is-completed:not(.is-active) {
  background: rgba(255, 255, 255, 0.45);
}

/* Badge Ring + Number */
.iwf-badge {
  position: relative;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  will-change: transform;
}

.iwf-badge-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.iwf-ring-ambient {
  transform-box: fill-box;
  transform-origin: center;
}

@media (prefers-reduced-motion: no-preference) {
  .iwf-ring-ambient {
    animation: iwf-spin-slow 24s linear infinite;
  }
  .iwf-card.is-active .iwf-ring-ambient {
    animation-duration: 9s;
  }
}

.iwf-ring-brush-outer {
  fill: none;
  stroke: var(--iwf-accent);
  stroke-width: 4.4;
  stroke-linecap: round;
  stroke-dasharray: 28 10 18 9 36 12;
  opacity: 0.78;
}

.iwf-ring-brush-inner {
  fill: var(--iwf-badge-core);
  stroke: #f6c94d;
  stroke-width: 2.2;
  stroke-dasharray: 22 8 14 10;
}

.iwf-ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.4);
  stroke-width: 2.6;
}

.iwf-ring-progress {
  fill: none;
  stroke: var(--iwf-accent-deep);
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-dasharray: 150.8;
  stroke-dashoffset: 150.8;
  transform: rotate(-90deg);
  transform-origin: 32px 32px;
  opacity: 0;
  transition: opacity 200ms ease;
}

.iwf-card.is-active .iwf-ring-progress {
  opacity: 1;
}

.iwf-card.is-completed:not(.is-active) .iwf-ring-progress {
  opacity: 0.65;
  stroke-dashoffset: 0;
}

.iwf-badge-num {
  position: relative;
  z-index: 1;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #2b2e33;
  font-variant-numeric: tabular-nums;
}

/* Card text */
.iwf-card-body {
  display: flex;
  flex-direction: column;
  gap: 0.16rem;
  min-width: 0;
}

.iwf-card-title {
  font-size: 0.88rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.2;
  color: var(--iwf-ink);
  text-transform: uppercase;
}

.iwf-card-desc {
  font-size: 0.75rem;
  line-height: 1.36;
  color: var(--iwf-ink-muted);
}

/* ==========================================================================
   Size-Aware Responsive Layouts (Fallback @media + @container queries)
   ========================================================================== */

/* Fallback media queries for browsers without container query support */
@media (min-width: 680px) {
  .iwf-canvas-wrap {
    height: 390px;
  }
  .iwf-cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
  }
}

@media (min-width: 1020px) {
  .iwf-stage {
    display: block;
    aspect-ratio: 16 / 8.5;
    min-height: 540px;
    max-height: 750px;
  }
  .iwf-canvas-wrap {
    position: absolute;
    inset: 0;
    height: 100%;
    border-radius: 0;
  }
  .iwf-leaders {
    display: block;
  }
  .iwf-cards {
    position: absolute;
    inset: 0;
    display: block;
    pointer-events: none;
    z-index: 3;
  }
  .iwf-card-slot {
    position: absolute;
  }
}

/* Overwrite cleanly with container queries where supported */
@supports (container-type: inline-size) {
  @media (min-width: 680px) {
    .iwf-canvas-wrap {
      height: 300px;
    }
    .iwf-cards {
      grid-template-columns: 1fr;
    }
  }
  @media (min-width: 1020px) {
    .iwf-stage {
      display: flex;
      aspect-ratio: auto;
      min-height: 0;
      max-height: none;
    }
    .iwf-canvas-wrap {
      position: relative;
      height: 300px;
      border-radius: 12px;
    }
    .iwf-leaders {
      display: none;
    }
    .iwf-cards {
      position: static;
      display: grid;
      pointer-events: auto;
    }
    .iwf-card-slot {
      position: static;
    }
  }

  /* Medium container: prominent diorama + 3x3 card grid */
  @container iwf (min-width: 680px) and (max-width: 1019px) {
    .iwf-canvas-wrap {
      height: clamp(350px, 44cqi, 440px);
    }
    .iwf-cards {
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 0.7rem;
    }
  }

/* Wide container: faithful horseshoe 3D stage matching values_investama.mp4 */
  @container iwf (min-width: 1020px) {
    .iwf-header {
      margin-bottom: 0.2rem;
    }

    .iwf-stage {
      display: block;
      position: relative;
      aspect-ratio: 16 / 7.5;
      min-height: 500px;
      max-height: 645px;
    }

    .iwf-canvas-wrap {
      position: absolute;
      inset: 0;
      height: 100%;
      border-radius: 0;
    }

    .iwf-leaders {
      display: block;
    }

    .iwf-cards {
      position: absolute;
      inset: 0;
      display: block;
      pointer-events: none;
      z-index: 3;
    }

    .iwf-card-slot {
      position: absolute;
    }

    /* Horseshoe placement matching reference video with generous slab clearance */
    .iwf-card-slot[data-slot="tl"]      { top: 1%;    left: 7.5%;  width: 22.5%; }
    .iwf-card-slot[data-slot="ml-high"] { top: 23%;   left: 1.8%;  width: 22.8%; }
    .iwf-card-slot[data-slot="ml-low"]  { top: 44%;   left: 1.8%;  width: 22.8%; }
    .iwf-card-slot[data-slot="bl"]      { top: 65%;   left: 1.8%;  width: 22.5%; }

    .iwf-card-slot[data-slot="tc"]      { top: 1%;    left: 37%;   width: 26%; }

    .iwf-card-slot[data-slot="tr"]      { top: 1%;    right: 7.5%; width: 24.5%; }
    .iwf-card-slot[data-slot="mr-high"] { top: 23.5%; right: 1.8%; width: 22.8%; }
    .iwf-card-slot[data-slot="mr-low"]  { top: 46.5%; right: 1.8%; width: 22.8%; }
    .iwf-card-slot[data-slot="br"]      { top: 69.5%; right: 1.8%; width: 22.5%; }

    .iwf-card,
    .iwf-card.is-completed:not(.is-active) {
      pointer-events: auto;
      background: transparent;
      border-color: transparent;
      padding: clamp(0.28rem, 0.5cqi, 0.48rem) clamp(0.42rem, 0.65cqi, 0.65rem);
      gap: clamp(0.42rem, 0.65cqi, 0.68rem);
      border-radius: 12px;
    }

    .iwf-card:hover {
      background: rgba(255, 255, 255, 0.45);
      border-color: rgba(255, 255, 255, 0.68);
    }

    .iwf-card.is-active {
      background: var(--iwf-card-active-bg);
      backdrop-filter: blur(8px);
      border-color: rgba(255, 255, 255, 0.94);
    }

    .iwf-card--align-right {
      flex-direction: row-reverse;
      text-align: right;
    }

    .iwf-badge {
      width: clamp(40px, 3.6cqi, 52px);
      height: clamp(40px, 3.6cqi, 52px);
    }

    .iwf-badge-num {
      font-size: clamp(0.92rem, 1.3cqi, 1.24rem);
    }

    .iwf-card-title {
      font-size: clamp(0.73rem, 0.9cqi, 0.94rem);
    }

    .iwf-card-desc {
      font-size: clamp(0.61rem, 0.7cqi, 0.73rem);
      line-height: 1.26;
    }
  }
}

@keyframes iwf-spin-slow {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

@keyframes iwf-pulse-dot {
  0%   { transform: scale(0.8); opacity: 0.75; }
  100% { transform: scale(2.3); opacity: 0; }
}
