/**
 * FKI Traders Sdn. Bhd. - Animated SVG Icon System
 * Light Theme System, Pure CSS Transform & Opacity Animations, Accessible & Reduced-Motion Compliant
 * Continuous Autonomous Looping System (No Hover Required)
 */

/* ==========================================================================
   1. Icon Color Tokens & Base SVG Setup
   ========================================================================== */
.icon {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.icon .i-main {
  stroke: var(--brand-blue);
  transition: stroke var(--transition-normal);
}

.icon .i-soft {
  stroke: var(--brand-blue-2);
  opacity: 0.55;
  transition: stroke var(--transition-normal), opacity var(--transition-normal);
}

.icon .i-accent {
  stroke: var(--brand-gold);
  fill: rgba(212, 175, 55, 0.18);
  transition: stroke var(--transition-normal), fill var(--transition-normal);
}

.icon .i-dot {
  fill: var(--brand-gold);
  stroke: none;
}

.icon .i-fill {
  fill: rgba(212, 175, 55, 0.18);
}

.icon .i-move {
  will-change: transform;
}

/* ==========================================================================
   2. Badge Container & Placement System
   ========================================================================== */
.icon-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #FFFFFF;
  border: 1px solid var(--line);
  box-shadow: 0 0 0 4px #FFFFFF, var(--shadow-sm);
  flex-shrink: 0;
  transition: background var(--transition-normal),
              transform var(--transition-normal),
              box-shadow var(--transition-normal);
  position: relative;
  z-index: 3;
}

/* Business Areas & Featured Chemical Cards: Clean top icon badge */
.card .icon-badge {
  width: 64px;
  height: 64px;
  margin-top: 0;
  margin-bottom: 1.5rem;
  margin-left: 0;
  box-shadow: 0 4px 14px rgba(11, 61, 145, 0.08);
  border: 1.5px solid var(--line);
}

.card .icon-badge .icon {
  width: 34px;
  height: 34px;
}

/* Capabilities Rows: Beside Header on Desktop / Above on Mobile */
.card__cap-head {
  display: flex;
  align-items: center;
  gap: 1.15rem;
  margin-bottom: 1rem;
}

.card__cap-head .icon-badge {
  width: 64px;
  height: 64px;
  margin: 0;
}

.card__cap-head .icon-badge .icon {
  width: 34px;
  height: 34px;
}

.card__cap-head .card__title {
  margin-bottom: 0;
  flex: 1;
}

/* Mobile Responsive Badge Scaling */
@media (max-width: 480px) {
  .card .icon-badge {
    width: 56px;
    height: 56px;
    margin-top: 0;
    margin-bottom: 1.15rem;
  }

  .card .icon-badge .icon,
  .card__cap-head .icon-badge .icon {
    width: 30px;
    height: 30px;
  }

  .card__cap-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.85rem;
  }

  .card__cap-head .icon-badge {
    width: 56px;
    height: 56px;
  }
}

/* ==========================================================================
   3. Card Hover & Focus States (Lift & Color Shift ONLY - Icons Keep Looping)
   ========================================================================== */
.card:hover .icon-badge,
.card:focus-within .icon-badge {
  background: var(--grad-blue);
  transform: translateY(-3px);
  box-shadow: 0 0 0 4px #FFFFFF, 0 0 0 7px rgba(212, 175, 55, 0.35), var(--shadow-md);
}

.card:hover .icon .i-main,
.card:focus-within .icon .i-main {
  stroke: #FFFFFF;
}

.card:hover .icon .i-soft,
.card:focus-within .icon .i-soft {
  stroke: rgba(255, 255, 255, 0.75);
}

.card:hover .icon .i-accent,
.card:focus-within .icon .i-accent {
  stroke: #D4AF37;
  fill: rgba(246, 227, 154, 0.35);
}

.qc-card, .card, .icon-host {
  transition: transform .35s cubic-bezier(.22,.61,.36,1), box-shadow .35s ease;
}

.qc-card:hover .qc-icon__fill,
.qc-card:focus-within .qc-icon__fill {
  opacity: 1;
}

.qc-card:hover .icon .i-main,
.qc-card:focus-within .icon .i-main {
  stroke: #fff;
}

.qc-card:hover .icon .i-soft,
.qc-card:focus-within .icon .i-soft {
  stroke: #fff;
}

/* ==========================================================================
   4. Scroll Draw-In & Pop Transitions
   ========================================================================== */
.icon .i-draw {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0;
  transition: stroke-dashoffset .9s cubic-bezier(.22,.61,.36,1) var(--d, 0s),
              opacity .01s linear var(--d, 0s);
}

.icon.is-drawn .i-draw,
.is-drawn .icon .i-draw,
.qc-card.is-drawn .icon .i-draw,
.card.is-drawn .icon .i-draw {
  stroke-dashoffset: 0;
  opacity: 1;
}

.icon .i-pop {
  opacity: 0;
  transform: scale(0.3);
  transform-box: fill-box;
  transform-origin: center;
  transition: opacity .35s ease .8s, transform .45s cubic-bezier(.34,1.56,.64,1) .8s;
}

.icon.is-drawn .i-pop,
.is-drawn .icon .i-pop,
.qc-card.is-drawn .icon .i-pop,
.card.is-drawn .icon .i-pop {
  opacity: 1;
  transform: scale(1);
}

/* Delay tokens for draw-in paths */
.d1 { --d: 0s; --i: 1; }
.d2 { --d: .09s; --i: 2; }
.d3 { --d: .18s; --i: 3; }
.d4 { --d: .27s; --i: 4; }
.d5 { --d: .7s; --i: 5; }
.d6 { --d: .8s; --i: 6; }
.d7 { --d: .9s; --i: 7; }

/* ==========================================================================
   5. Continuous Autonomous Loop Engine (Section 3 Spec)
   ========================================================================== */
.icon .loop {
  animation-duration: var(--dur, 4s);
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-fill-mode: backwards;               /* shows the 0% pose during the start delay */
  animation-delay: calc(1.3s + var(--card-ld, 0s) + var(--ld, 0s));
  animation-play-state: paused;                 /* running only when visible (see JS) */
  transform-box: fill-box;                      /* default pivot: center of the part itself */
  transform-origin: 50% 50%;
}

.icon.is-live.is-drawn .loop,
.is-live.is-drawn .icon .loop {
  animation-play-state: running;
}

.tab-hidden .icon .loop,
.tab-hidden .qc-icon__ring {
  animation-play-state: paused !important;
}

/* Pivot helpers (use ONLY on .loop wrappers) */
.icon .pv-top    { transform-origin: 50% 0; }
.icon .pv-bottom { transform-origin: 50% 100%; }
.icon .pv-c      { transform-box: view-box; transform-origin: 32px 32px; }   /* exact icon center */
.icon .pv-flap   { transform-box: view-box; transform-origin: 32px 20px; }   /* mail flap hinge */

/* Durations and stagger delays */
.dur-2 { --dur: 2s; }
.dur-3 { --dur: 3s; }
.dur-4 { --dur: 4s; }
.dur-5 { --dur: 5s; }
.dur-6 { --dur: 6s; }
.dur-8 { --dur: 8s; }
.dur-10 { --dur: 10s; }
.dur-30 { --dur: 30s; }
.dur-120 { --dur: 120s; }

.ld1 { --ld: .15s; }
.ld2 { --ld: .3s; }
.ld3 { --ld: .45s; }
.ld4 { --ld: .6s; }
.ld5 { --ld: .75s; }
.ld6 { --ld: .9s; }
.ld7 { --ld: 1.05s; }
.ld8 { --ld: 1.2s; }

/* Auto-stagger across sibling cards so icons never move in sync */
.icon-host:nth-child(4n+2) { --card-ld: .35s; }
.icon-host:nth-child(4n+3) { --card-ld: .7s; }
.icon-host:nth-child(4n+4) { --card-ld: 1.05s; }

/* Loop classes -> keyframes */
.loop-float  { animation-name: lp-float; }
.loop-bob    { animation-name: lp-bob; }
.loop-swing  { animation-name: lp-swing; }
.loop-rock   { animation-name: lp-rock; }
.loop-ring   { animation-name: lp-ring; }
.loop-pulse  { animation-name: lp-pulse; }
.loop-pop    { animation-name: lp-pop; }
.loop-wave   { animation-name: lp-wave; }
.loop-blink  { animation-name: lp-blink; }
.loop-rise   { animation-name: lp-rise; }
.loop-slide  { animation-name: lp-slide; }
.loop-orbit  { animation-name: lp-orbit; }
.loop-hop    { animation-name: lp-hop; }
.loop-ripple { animation-name: lp-ripple; }
.loop-flap   { animation-name: lp-flap; }
.loop-letter { animation-name: lp-letter; }
.loop-spin   { animation-name: lp-spin; animation-timing-function: linear; }
.loop-dash   { animation-name: lp-dash; animation-timing-function: linear; stroke-dasharray: 4 4; }
.loop-redraw { animation-name: lp-redraw; stroke-dasharray: 1; stroke-dashoffset: 0; }

/* Keyframes: every one starts and ends in the same pose */
@keyframes lp-float  {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

@keyframes lp-bob    {
  0%, 60%, 100% { transform: translateY(0); }
  15% { transform: translateY(-4px); }
  30% { transform: translateY(0); }
  42% { transform: translateY(-2px); }
  52% { transform: translateY(0); }
}

@keyframes lp-swing  {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(7deg); }
  75% { transform: rotate(-7deg); }
}

@keyframes lp-rock   {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(4deg); }
  75% { transform: rotate(-4deg); }
}

@keyframes lp-ring   {
  0%, 40%, 100% { transform: rotate(0); }
  5% { transform: rotate(-12deg); }
  10% { transform: rotate(12deg); }
  15% { transform: rotate(-10deg); }
  20% { transform: rotate(10deg); }
  25% { transform: rotate(-6deg); }
  30% { transform: rotate(6deg); }
}

@keyframes lp-pulse  {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}

@keyframes lp-pop    {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.25); }
}

@keyframes lp-wave   {
  0%, 100% { opacity: 1; }
  8% { opacity: .2; }
  16% { opacity: 1; }
  24% { opacity: .2; }
  32% { opacity: 1; }
}

@keyframes lp-blink  {
  0%, 100% { opacity: .25; }
  20%, 60% { opacity: 1; }
}

@keyframes lp-rise   {
  0% { transform: translateY(0); opacity: 0; }
  15% { opacity: 1; }
  70% { opacity: .8; }
  100% { transform: translateY(-14px); opacity: 0; }
}

@keyframes lp-slide  {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

@keyframes lp-orbit  {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(3px, -3px); }
  50% { transform: translate(6px, 0); }
  75% { transform: translate(3px, 3px); }
}

@keyframes lp-hop    {
  0%, 45%, 100% { transform: translateY(0) scale(1, 1); }
  12% { transform: translateY(-8px) scale(.96, 1.05); }
  24% { transform: translateY(0) scale(1.06, .92); }
  32% { transform: translateY(-3px) scale(1, 1); }
  40% { transform: translateY(0) scale(1, 1); }
}

@keyframes lp-ripple {
  0% { transform: scale(.4); opacity: .9; }
  70%, 100% { transform: scale(1.3); opacity: 0; }
}

@keyframes lp-flap   {
  0%, 18%, 76%, 100% { transform: scaleY(1); }
  32%, 62% { transform: scaleY(-1); }
}

@keyframes lp-letter {
  0%, 22%, 72%, 100% { transform: translateY(12px); }
  40%, 56% { transform: translateY(0); }
}

@keyframes lp-spin   {
  from { transform: rotate(var(--from, 0deg)); }
  to { transform: rotate(calc(var(--from, 0deg) + 360deg)); }
}

@keyframes lp-dash   {
  to { stroke-dashoffset: -8; }
}

@keyframes lp-redraw {
  0% { stroke-dashoffset: 1; opacity: 0; }
  1% { opacity: 1; }
  40%, 85% { stroke-dashoffset: 0; opacity: 1; }
  95%, 100% { stroke-dashoffset: 1; opacity: 0; }
}

/* Static starting poses (also what reduced-motion users see) */
.icon .from-120 {
  --from: 120deg;
  transform: rotate(120deg);
}

.icon--mail .i-letter {
  transform: translateY(12px);
}

/* UI micro-icons do not loop */
.icon--ui .loop {
  animation: none !important;
}

/* ==========================================================================
   6. Contact Page Quick-Contact Cards & Spinning Ring System
   ========================================================================== */
.qc-card {
  background: #FFFFFF;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 2.25rem 1.5rem;
  text-align: center;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform .35s cubic-bezier(.22,.61,.36,1), box-shadow .35s ease, border-color .35s ease;
}

.qc-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--grad-gold);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--transition-normal);
}

.qc-card:hover, .qc-card:focus-within {
  transform: translateY(-6px);
  box-shadow: var(--shadow-lg);
  border-color: rgba(212, 175, 55, 0.45);
}

.qc-card:hover::before, .qc-card:focus-within::before {
  transform: scaleX(1);
}

.qc-card h3 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-900);
  margin-bottom: 0.65rem;
}

.qc-card p {
  color: var(--text-500);
  font-size: 0.92rem;
  line-height: 1.6;
  margin-bottom: 1.25rem;
  flex: 1;
}

.qc-card p a {
  font-weight: 700;
  color: var(--brand-blue);
  transition: color var(--transition-fast);
}

.qc-card p a:hover {
  color: var(--brand-blue-2);
}

.qc-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--brand-blue);
  transition: color var(--transition-fast), transform var(--transition-fast);
}

.qc-link:hover {
  color: var(--brand-blue-2);
  transform: translateX(3px);
}

.qc-icon {
  position: relative;
  width: 128px;
  height: 128px;
  margin: 0 auto 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 8px var(--bg-1);
}

.qc-icon__ring {                       /* spinning dashed gold ring: its own element */
  position: absolute; inset: -8px;
  border: 2px dashed rgba(212,175,55,.65);
  border-radius: 50%;
  animation: qc-ring-spin 30s linear infinite;
  animation-play-state: paused;
  backface-visibility: hidden; will-change: transform;
  pointer-events: none;
}

.qc-icon.is-live .qc-icon__ring,
.is-live .qc-icon__ring {
  animation-play-state: running;
}

.qc-icon__fill {                       /* blue overlay that fades in on hover */
  position: absolute; inset: 0; border-radius: 50%;
  background: var(--grad-blue);
  opacity: 0; transition: opacity .3s ease;
}

.qc-icon .icon {
  position: relative;
  z-index: 1;
  width: 88px;
  height: 88px;
  overflow: visible;
}

@keyframes qc-ring-spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 479px) {
  .qc-icon { width: 104px; height: 104px; }
  .qc-icon .icon { width: 72px; height: 72px; }
}

/* ==========================================================================
   7. Accessibility & Reduced Motion (No loops, fully drawn, rest pose)
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .icon .loop,
  .qc-icon__ring {
    animation: none !important;
  }

  .icon .i-draw {
    stroke-dashoffset: 0 !important;
    opacity: 1 !important;
    transition: none !important;
  }

  .icon .i-pop {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }

  .icon *,
  .qc-card {
    transition: none !important;
  }
}
