/* ============================================================
   ANIMATIONS & MOTION
   ============================================================ */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  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 pulseRing {
  0% { box-shadow: 0 0 0 0 rgba(167, 139, 250, 0.4); }
  70% { box-shadow: 0 0 0 12px rgba(167, 139, 250, 0); }
  100% { box-shadow: 0 0 0 0 rgba(167, 139, 250, 0); }
}

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

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

@keyframes glow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.15); }
}

@keyframes countUp {
  from { opacity: 0.4; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Page entry — every page transition */
.page, .app main > * {
  animation: fadeIn 0.2s ease-out;
}
.page > * {
  animation: slideUp 0.3s ease-out backwards;
}
.page > *:nth-child(1) { animation-delay: 0.02s; }
.page > *:nth-child(2) { animation-delay: 0.06s; }
.page > *:nth-child(3) { animation-delay: 0.10s; }
.page > *:nth-child(4) { animation-delay: 0.14s; }
.page > *:nth-child(5) { animation-delay: 0.18s; }
.page > *:nth-child(6) { animation-delay: 0.22s; }
.page > *:nth-child(7) { animation-delay: 0.26s; }
.page > *:nth-child(8) { animation-delay: 0.30s; }

/* Card hover lift */
.card {
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.4);
  border-color: var(--accent-2);
}

/* Button micro-interactions */
.btn {
  transition: all 0.15s ease;
  position: relative;
}
.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.1);
}
.btn:active {
  transform: translateY(0);
  filter: brightness(0.95);
}

/* KPI cards — value pulses on mount */
.kpi-card .kpi-value {
  animation: countUp 0.4s ease-out backwards;
}

/* Sidebar nav items */
.sidebar a, .nav-link {
  transition: all 0.15s ease;
  position: relative;
}
.sidebar a:hover, .nav-link:hover {
  transform: translateX(2px);
}
.sidebar a.active::before, .nav-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
  animation: scaleIn 0.2s ease;
}

/* Live indicator dot */
.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success, #22c55e);
  animation: pulse 1.5s infinite;
}
.live-dot.urgent {
  background: var(--danger, #ef4444);
  animation: pulseRing 1.5s infinite;
}

/* Badge pulse for alerts */
.badge.badge-pulse {
  animation: pulse 2s infinite;
}

/* Status dot in tables */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}
.status-dot.success { background: #22c55e; box-shadow: 0 0 6px #22c55e80; }
.status-dot.warn { background: #f59e0b; box-shadow: 0 0 6px #f59e0b80; }
.status-dot.danger { background: #ef4444; box-shadow: 0 0 6px #ef444480; animation: pulse 2s infinite; }
.status-dot.info { background: #3b82f6; box-shadow: 0 0 6px #3b82f680; }

/* Shimmer skeleton loader */
.skeleton {
  background: linear-gradient(90deg,
    var(--bg-2) 25%,
    var(--bg-3) 50%,
    var(--bg-2) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

/* Toast pop-in */
.toast {
  animation: slideInRight 0.3s ease-out;
}

/* Modal pop-in */
.modal-content {
  animation: scaleIn 0.2s ease-out;
}

/* Heatmap cell hover */
.heatmap-cell {
  transition: all 0.12s ease;
}
.heatmap-cell:hover {
  filter: brightness(1.4);
  stroke: white;
  stroke-width: 1.5;
}

/* Chart bar/line points */
.chart-bar, .chart-line {
  transition: all 0.2s ease;
}
.chart-bar:hover, .chart-line:hover {
  filter: brightness(1.2);
}

/* SVG animation — bar grow from 0 */
.chart-bar {
  transform-origin: bottom;
  animation: barGrow 0.5s ease-out backwards;
}
@keyframes barGrow {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}

/* Donut grow */
.donut-arc {
  animation: scaleIn 0.5s ease-out;
  transform-origin: center;
}

.donut-legend {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.donut-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border-faint);
}
.donut-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}
.donut-legend-label {
  flex: 1;
  color: var(--text);
}
.donut-legend-value {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.donut-container {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}
.donut-container > svg {
  flex-shrink: 0;
}

/* Sparkline draw */
.sparkline-path {
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  animation: drawLine 1.2s ease-out forwards;
}
@keyframes drawLine {
  to { stroke-dashoffset: 0; }
}

/* Toggle button micro */
.toggle-btn {
  transition: all 0.15s ease;
}
.toggle-btn:hover {
  background: var(--bg-3);
}

/* Sidebar group header */
.sidebar .group-header {
  cursor: pointer;
  transition: color 0.15s ease;
}
.sidebar .group-header:hover {
  color: var(--accent);
}

/* Mobile responsive */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); animation: slideInRight 0.2s ease; }
  .mobile-menu-btn { display: block !important; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-actions { width: 100%; justify-content: flex-start; }
}

/* Smooth scroll */
.main { scroll-behavior: smooth; }

/* Progress bar fill animation */
.progress-fill {
  animation: barGrow 0.8s ease-out;
  transform-origin: left;
}

/* Avatar pulse for active users */
.avatar.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid var(--bg-1);
  animation: pulse 2s infinite;
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus ring */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Selection */
::selection {
  background: var(--accent);
  color: white;
}