/**
 * Tile Vitality CSS — Living Dashboard Animation System
 *
 * 5 urgency-level animations for dashboard tiles:
 *   tile-healthy   — Gentle 6s breathing (subtle scale pulse)
 *   tile-attention — 4s warm amber glow (soft gold border pulse)
 *   tile-warning   — 3s amber pulse + badge (orange glow)
 *   tile-critical  — 2s red pulse + badge (red pulsing glow, slight shake)
 *   tile-urgent    — 1.2s red strobe + badge (intense strobe, thick border)
 *
 * Performance: GPU-accelerated transform + box-shadow only (no layout thrash).
 * Accessibility: prefers-reduced-motion kills all animations.
 */

/* ============================================================================
   Keyframe Animations
   ============================================================================ */

/* Healthy — gentle breathing */
@keyframes tile-breathe {
  0%, 100% {
    transform: translateY(0) scale(1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  }
  50% {
    transform: translateY(-1px) scale(1.003);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
}

/* Attention — warm amber glow */
@keyframes tile-glow-amber {
  0%, 100% {
    box-shadow: 0 2px 8px rgba(217, 119, 6, 0.1), inset 0 0 0 0 rgba(217, 119, 6, 0);
  }
  50% {
    box-shadow: 0 4px 16px rgba(217, 119, 6, 0.2), inset 0 0 0 1px rgba(217, 119, 6, 0.12);
  }
}

/* Warning — amber pulse */
@keyframes tile-pulse-amber {
  0%, 100% {
    box-shadow: 0 2px 10px rgba(245, 158, 11, 0.15);
    border-left-color: #F59E0B;
  }
  50% {
    box-shadow: 0 4px 20px rgba(245, 158, 11, 0.35), 0 0 0 2px rgba(245, 158, 11, 0.1);
    border-left-color: #D97706;
  }
}

/* Critical — red pulse with subtle shake */
@keyframes tile-pulse-red {
  0%, 100% {
    transform: translateX(0);
    box-shadow: 0 2px 10px rgba(239, 68, 68, 0.2);
    border-left-color: #EF4444;
  }
  25% {
    transform: translateX(-1px);
  }
  50% {
    transform: translateX(0);
    box-shadow: 0 4px 24px rgba(239, 68, 68, 0.4), 0 0 0 2px rgba(239, 68, 68, 0.15);
    border-left-color: #DC2626;
  }
  75% {
    transform: translateX(1px);
  }
}

/* Urgent — intense red strobe */
@keyframes tile-strobe-red {
  0%, 100% {
    box-shadow: 0 2px 10px rgba(220, 38, 38, 0.25);
    border-left-color: #DC2626;
    border-left-width: 4px;
  }
  50% {
    box-shadow: 0 4px 30px rgba(220, 38, 38, 0.55), 0 0 0 3px rgba(220, 38, 38, 0.2);
    border-left-color: #B91C1C;
    border-left-width: 6px;
  }
}

/* Badge pulse */
@keyframes badge-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* Profit-up green glow (for tiles with positive/healthy indicators) */
@keyframes tile-glow-green {
  0%, 100% {
    box-shadow: 0 2px 8px rgba(22, 163, 74, 0.08);
  }
  50% {
    box-shadow: 0 4px 14px rgba(22, 163, 74, 0.18);
  }
}

/* ============================================================================
   Tile Urgency Classes
   ============================================================================ */

/* Healthy — gentle breathing */
.dashboard-card.tile-healthy {
  will-change: transform, box-shadow;
  animation: tile-breathe 6s ease-in-out infinite;
}

/* Attention — warm amber glow */
.dashboard-card.tile-attention {
  will-change: box-shadow;
  animation: tile-glow-amber 4s ease-in-out infinite;
  border-left-color: #D97706 !important;
}

/* Warning — amber pulse + badge visible */
.dashboard-card.tile-warning {
  will-change: box-shadow, border-left-color;
  animation: tile-pulse-amber 3s ease-in-out infinite;
}

/* Critical — red pulse + shake + badge visible */
.dashboard-card.tile-critical {
  will-change: transform, box-shadow, border-left-color;
  animation: tile-pulse-red 2s ease-in-out infinite;
}

/* Urgent — intense red strobe + thick border + badge visible */
.dashboard-card.tile-urgent {
  will-change: box-shadow, border-left-color, border-left-width;
  animation: tile-strobe-red 1.2s ease-in-out infinite;
}

/* Profit-up green glow modifier */
.dashboard-card.tile-profit-up {
  animation: tile-glow-green 5s ease-in-out infinite;
  border-left-color: #16A34A !important;
}

/* ============================================================================
   Urgency Badge (top-right corner of card)
   ============================================================================ */

.tile-urgency-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
  color: #fff;
  z-index: 5;
  pointer-events: none;
  animation: badge-pulse 2s ease-in-out infinite;
}

/* Badge colors by urgency */
.tile-warning .tile-urgency-badge {
  background: #F59E0B;
}
.tile-critical .tile-urgency-badge {
  background: #EF4444;
}
.tile-urgent .tile-urgency-badge {
  background: #DC2626;
  animation: badge-pulse 1s ease-in-out infinite;
}

/* ============================================================================
   Reason Tooltip (appears on hover)
   ============================================================================ */

.tile-reasons-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #1F2937;
  color: #F3F4F6;
  font-size: 0.75rem;
  line-height: 1.4;
  padding: 8px 12px;
  border-radius: 6px;
  white-space: nowrap;
  max-width: 300px;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  margin-bottom: 8px;
}

/* Arrow */
.tile-reasons-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #1F2937;
}

/* Show on hover */
.dashboard-card:hover .tile-reasons-tooltip {
  opacity: 1;
}

/* Tooltip text wrapping for long reasons */
.tile-reasons-tooltip span {
  display: block;
  white-space: normal;
  max-width: 280px;
}

/* ============================================================================
   Card position: relative (for badge + tooltip positioning)
   ============================================================================ */

.dashboard-card[data-tile-id] {
  position: relative;
}

/* ============================================================================
   Accessibility: Reduced Motion
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
  .dashboard-card.tile-healthy,
  .dashboard-card.tile-attention,
  .dashboard-card.tile-warning,
  .dashboard-card.tile-critical,
  .dashboard-card.tile-urgent,
  .dashboard-card.tile-profit-up {
    animation: none !important;
    will-change: auto !important;
  }

  .tile-urgency-badge {
    animation: none !important;
  }

  /* Instead of animations, use static visual cues */
  .dashboard-card.tile-attention {
    border-left-color: #D97706 !important;
    box-shadow: 0 2px 10px rgba(217, 119, 6, 0.2);
  }
  .dashboard-card.tile-warning {
    border-left-color: #F59E0B !important;
    box-shadow: 0 2px 12px rgba(245, 158, 11, 0.25);
  }
  .dashboard-card.tile-critical {
    border-left-color: #EF4444 !important;
    box-shadow: 0 2px 12px rgba(239, 68, 68, 0.3);
  }
  .dashboard-card.tile-urgent {
    border-left-color: #DC2626 !important;
    border-left-width: 6px;
    box-shadow: 0 2px 14px rgba(220, 38, 38, 0.35);
  }
}

/* ============================================================================
   Tile hidden (not relevant to current role — optional)
   ============================================================================ */

.dashboard-card.tile-hidden {
  display: none;
}
