/* ===== KEYFRAMES ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInLeft {
  from { opacity: 0; transform: translateX(-16px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  33%       { transform: translateY(-20px) rotate(5deg); }
  66%       { transform: translateY(10px) rotate(-3deg); }
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-8px); }
}
@keyframes countUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@keyframes toastSlideIn {
  from { transform: translateX(calc(100% + 20px)); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@keyframes toastSlideOut {
  from { transform: translateX(0); opacity: 1; }
  to   { transform: translateX(calc(100% + 20px)); opacity: 0; }
}
@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.94) translateY(-10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes overlayFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes progressFill {
  from { width: 0; }
}
@keyframes radarPulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50%       { opacity: 1; transform: scale(1.02); }
}
@keyframes badgeUnlock {
  0%  { transform: scale(0) rotate(-180deg); opacity: 0; }
  60% { transform: scale(1.2) rotate(10deg); }
  80% { transform: scale(0.9) rotate(-5deg); }
  100%{ transform: scale(1) rotate(0deg); opacity: 1; }
}
@keyframes confetti {
  0%   { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}
@keyframes timerPulse {
  0%, 100% { color: inherit; }
  50%       { color: var(--color-danger-500); transform: scale(1.05); }
}

/* ===== ANIMATION UTILITIES ===== */
.anim-fade-in       { animation: fadeIn 0.3s ease forwards; }
.anim-fade-in-up    { animation: fadeInUp 0.4s ease forwards; }
.anim-fade-in-down  { animation: fadeInDown 0.3s ease forwards; }
.anim-scale-in      { animation: scaleIn 0.3s ease forwards; }
.anim-spin          { animation: spin 1s linear infinite; }
.anim-pulse         { animation: pulse 2s ease-in-out infinite; }
.anim-bounce        { animation: bounce 1s ease-in-out infinite; }
.anim-float         { animation: float 6s ease-in-out infinite; }

/* Staggered children */
.stagger-children > *:nth-child(1) { animation-delay: 0ms; }
.stagger-children > *:nth-child(2) { animation-delay: 60ms; }
.stagger-children > *:nth-child(3) { animation-delay: 120ms; }
.stagger-children > *:nth-child(4) { animation-delay: 180ms; }
.stagger-children > *:nth-child(5) { animation-delay: 240ms; }
.stagger-children > *:nth-child(6) { animation-delay: 300ms; }
.stagger-children > *:nth-child(7) { animation-delay: 360ms; }
.stagger-children > *:nth-child(8) { animation-delay: 420ms; }

/* ===== SKELETON LOADER ===== */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-surface2) 25%,
    var(--border-color) 50%,
    var(--bg-surface2) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}
.skeleton-text { height: 14px; width: 100%; margin-bottom: var(--space-2); }
.skeleton-text.short { width: 60%; }
.skeleton-text.shorter { width: 40%; }
.skeleton-title { height: 22px; width: 70%; margin-bottom: var(--space-3); }
.skeleton-avatar { width: 40px; height: 40px; border-radius: var(--radius-full); flex-shrink: 0; }
.skeleton-card { height: 120px; border-radius: var(--radius-xl); }
.skeleton-chart { height: 300px; border-radius: var(--radius-xl); }
.skeleton-badge { height: 20px; width: 60px; border-radius: var(--radius-full); }

/* ===== TOAST ===== */
.toast-container {
  position: fixed;
  top: calc(var(--topbar-height) + var(--space-4));
  right: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  min-width: 300px;
  max-width: 420px;
  pointer-events: all;
  animation: toastSlideIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  border-left: 4px solid var(--color-primary-500);
}
.toast.leaving { animation: toastSlideOut 0.25s ease forwards; }
.toast.success { border-left-color: var(--color-success-500); }
.toast.error   { border-left-color: var(--color-danger-500); }
.toast.warning { border-left-color: var(--color-warning-500); }
.toast.info    { border-left-color: var(--color-info-500); }
.toast-icon {
  font-size: var(--text-lg);
  flex-shrink: 0;
  margin-top: 2px;
}
.toast.success .toast-icon { color: var(--color-success-500); }
.toast.error   .toast-icon { color: var(--color-danger-500); }
.toast.warning .toast-icon { color: var(--color-warning-500); }
.toast.info    .toast-icon { color: var(--color-info-500); }
.toast-body { flex: 1; }
.toast-title {
  font-size: var(--text-sm);
  font-weight: var(--font-semi);
  color: var(--text-primary);
  margin-bottom: 2px;
}
.toast-msg {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.4;
}
.toast-close {
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--text-xs);
  padding: 2px;
  background: none;
  border: none;
  font-family: var(--font-sans);
  transition: color var(--transition-fast);
  flex-shrink: 0;
}
.toast-close:hover { color: var(--text-primary); }

@media (max-width: 480px) {
  .toast-container { right: var(--space-3); left: var(--space-3); }
  .toast { min-width: unset; max-width: unset; }
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  animation: overlayFadeIn 0.2s ease forwards;
}
.modal {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: modalFadeIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  overflow: hidden;
}
.modal-sm  { max-width: 400px; }
.modal-md  { max-width: 560px; }
.modal-lg  { max-width: 760px; }
.modal-xl  { max-width: 1000px; }
.modal-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4);
  flex-shrink: 0;
}
.modal-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semi);
  color: var(--text-primary);
  display: flex; align-items: center; gap: var(--space-3);
}
.modal-close {
  width: 32px; height: 32px;
  border-radius: var(--radius-lg);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition-fast);
  font-size: var(--text-base);
  font-family: var(--font-sans);
}
.modal-close:hover { background: var(--bg-surface2); color: var(--text-primary); }
.modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface2);
  display: flex; gap: var(--space-3); justify-content: flex-end;
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-overlay);
  flex-direction: column;
  gap: var(--space-4);
}
.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--border-color);
  border-top-color: var(--color-primary-500);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}
.spinner-sm {
  width: 20px; height: 20px;
  border-width: 2px;
}

/* ===== PAGE TRANSITIONS ===== */
.page-enter {
  animation: fadeInUp 0.3s ease forwards;
}

/* ===== QUIZ TIMER ===== */
.timer-bar {
  height: 4px;
  background: var(--progress-track);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: var(--space-4);
}
.timer-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 1s linear, background 0.3s ease;
  background: var(--color-success-500);
}
.timer-fill.warning { background: var(--color-warning-500); }
.timer-fill.critical {
  background: var(--color-danger-500);
  animation: timerPulse 0.5s ease-in-out infinite;
}

/* ===== SCORE COUNTER ANIMATION ===== */
.score-counter {
  font-size: var(--text-5xl);
  font-weight: var(--font-bold);
  text-align: center;
  overflow: hidden;
}
.score-counter span {
  display: inline-block;
  animation: countUp 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* ===== GANTT TIMELINE ===== */
.gantt-wrap {
  overflow-x: auto;
  padding-bottom: var(--space-2);
}
.gantt-track {
  height: 32px;
  background: var(--progress-track);
  border-radius: var(--radius-full);
  position: relative;
  overflow: hidden;
  margin-bottom: var(--space-2);
}
.gantt-bar {
  position: absolute;
  height: 100%;
  border-radius: var(--radius-full);
  display: flex; align-items: center; padding: 0 var(--space-3);
  font-size: var(--text-xs);
  color: #fff;
  font-weight: var(--font-medium);
  transition: all var(--transition-base);
  white-space: nowrap;
  overflow: hidden;
}

/* ===== CONFETTI PARTICLE ===== */
.confetti-piece {
  position: fixed;
  width: 8px; height: 8px;
  pointer-events: none;
  z-index: var(--z-toast);
  animation: confetti 2s ease-in forwards;
  border-radius: 2px;
}

/* ===== PRINT ===== */
@media print {
  .sidebar, .topbar, .btn, .tab-item,
  .toast-container, .modal-overlay,
  .page-header .d-flex { display: none !important; }

  .main-wrap { margin-left: 0 !important; }
  body { background: #fff !important; color: #000 !important; }
  .card, .chart-card { box-shadow: none !important; border: 1px solid #ddd !important; }
  .page-content { padding: 0 !important; }

  .print-header {
    display: flex !important;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid #1a0533;
  }
  .print-only { display: block !important; }
}
.print-only { display: none; }

/* ===== TRANSITION HELPERS ===== */
.transition-all    { transition: all var(--transition-base); }
.transition-colors { transition: color var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast); }
.transition-shadow { transition: box-shadow var(--transition-base); }
.transition-transform { transition: transform var(--transition-base); }

/* ===== HOVER EFFECTS ===== */
.hover-lift:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.hover-scale:hover { transform: scale(1.02); }
.hover-glow:hover { box-shadow: var(--shadow-glow); }
