/* ========================================
   Animations & Transitions
   ========================================= */

/* === Base Transitions === */

.card,
.btn,
.input,
.preset-btn,
.result-card,
.filter-btn,
.position-card,
.stat-card,
.compound-card {
  transition:
    background-color var(--transition-fast),
    border-color var(--transition-fast),
    color var(--transition-fast),
    box-shadow var(--transition-fast),
    opacity var(--transition-fast);
}

/* === Core Keyframes === */

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

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

@keyframes scaleInSoft {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pulseSoft {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.82;
  }
}

@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

@keyframes valueFlash {
  0% {
    color: var(--text-primary);
  }
  50% {
    color: var(--primary);
  }
  100% {
    color: var(--text-primary);
  }
}

@keyframes successFlash {
  0% {
    background-color: rgba(158, 123, 59, 0.10);
  }
  100% {
    background-color: transparent;
  }
}

/* === Utility Animation Classes === */

.animate-fade-in {
  animation: fadeIn 0.2s ease-out;
}

.animate-fade-in-up {
  animation: fadeInSoft 0.24s ease-out;
}

.animate-scale-in {
  animation: scaleInSoft 0.2s ease-out;
}

.animate-pulse {
  animation: pulseSoft 1.8s ease-in-out infinite;
}

.animate-shake {
  animation: shake 0.35s ease-in-out;
}

/* === Staggered Animations === */

.stagger-1 { animation-delay: 40ms; }
.stagger-2 { animation-delay: 80ms; }
.stagger-3 { animation-delay: 120ms; }
.stagger-4 { animation-delay: 160ms; }
.stagger-5 { animation-delay: 200ms; }
.stagger-6 { animation-delay: 240ms; }

/* === Page Load Animation === */

.dashboard-header {
  animation: fadeInSoft 0.24s ease-out backwards;
  animation-delay: 0ms;
}

.panel {
  animation: fadeInSoft 0.24s ease-out backwards;
}

.panel--input { animation-delay: 40ms; }
.panel--results { animation-delay: 80ms; }
.panel--journal { animation-delay: 120ms; }

/* === Result Card Updates === */

.result-card.updated {
  animation: fadeIn 0.18s ease-out;
}

.result-card.updated .result-card__value {
  animation: valueFlash 0.3s ease-out;
}

/* === Collapsible Card Animation === */

.card__body--collapsible {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition:
    max-height 0.24s ease-out,
    opacity 0.18s ease-out,
    padding 0.24s ease-out;
  padding-top: 0;
  padding-bottom: 0;
}

.card--collapsible.open .card__body--collapsible {
  max-height: 500px;
  opacity: 1;
  overflow: visible;
  padding-top: var(--space-5);
  padding-bottom: var(--space-5);
}

/* Settings card */
.card--settings .card__body--collapsible {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  transition:
    max-height 0.24s ease-out,
    opacity 0.18s ease-out,
    padding 0.24s ease-out;
}

.card--settings.open .card__body--collapsible {
  max-height: 400px;
  opacity: 1;
  overflow: visible;
  padding-top: var(--space-4);
  padding-bottom: var(--space-4);
}

/* === Scenarios Expand Animation === */

.scenarios-content {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition:
    max-height 0.24s ease-out,
    opacity 0.18s ease-out,
    margin 0.24s ease-out,
    padding 0.24s ease-out;
  margin-top: 0;
  padding: 0;
}

.scenarios-content.open {
  max-height: 400px;
  opacity: 1;
  margin-top: var(--space-3);
  padding: var(--space-4);
}

/* === Button Press === */

.btn:active,
.preset-btn:active,
.icon-btn:active {
  transform: scale(0.985);
}

/* === Error State === */

.input.error {
  animation: shake 0.35s ease-in-out;
  border-color: var(--danger);
}

/* === Success Flash === */

.flash-success {
  animation: successFlash 0.8s ease-out;
}

/* === Loading State === */

.loading {
  position: relative;
  pointer-events: none;
}

.loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--bg-surface);
  opacity: 0.65;
  animation: pulseSoft 1.2s ease-in-out infinite;
}

/* === Toast Animations === */

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

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

.toast {
  animation: toastIn 0.2s ease-out;
}

.toast.removing {
  animation: toastOut 0.18s ease-in forwards;
}

/* === Trade Card === */

.trade-card {
  animation: fadeInSoft 0.22s ease-out;
}

.trade-card.removing {
  animation: fadeIn 0.16s ease-out reverse forwards;
}

/* === Header Account Update === */

.header__account-value.updated {
  animation: valueFlash 0.35s ease-out;
}

/* === Insight Animation === */

.insight {
  animation: fadeInSoft 0.22s ease-out;
}

.insights .insight:nth-child(1) { animation-delay: 0ms; }
.insights .insight:nth-child(2) { animation-delay: 40ms; }
.insights .insight:nth-child(3) { animation-delay: 80ms; }

/* === Preset Button Active State === */

.preset-btn.active {
  transition:
    background-color 0.15s ease-out,
    border-color 0.15s ease-out,
    color 0.15s ease-out;
}

/* === Modal Overlay === */

.modal-overlay,
.settings-overlay {
  transition: opacity 0.2s ease-out, backdrop-filter 0.2s ease-out;
}

.modal-overlay.open,
.settings-overlay.open {
  backdrop-filter: blur(3px);
}

/* === Input Valid State === */

.input.valid {
  border-color: var(--primary);
  animation: none;
}

/* === Risk Summary Indicator === */

.risk-summary__indicator {
  transition:
    background-color 0.24s ease-out,
    color 0.24s ease-out,
    border-color 0.24s ease-out;
}

/* === Smooth Number Transitions === */

.result-card__value,
.header__account-value,
.risk-summary__value {
  transition: color 0.2s ease-out;
}

/* === Hero Card Hover === */

.card--hero {
  transition: border-color 0.24s ease-out, box-shadow 0.24s ease-out;
}

.card--hero:hover {
  box-shadow: var(--shadow-sm);
}

/* === Input Focus === */

.input:focus {
  transition: border-color 0.15s ease-out, box-shadow 0.15s ease-out;
}

/* === Button Hover === */

.btn--primary:hover,
.btn--success:hover,
.btn--secondary:hover {
  box-shadow: var(--shadow-sm);
}

/* === Skeleton Loading === */

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-elevated) 25%,
    var(--bg-hover) 50%,
    var(--bg-elevated) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--border-radius-sm);
}

/* === Mobile Animation Fixes === */

@media (max-width: 900px) {
  .panel {
    animation: fadeIn 0.22s ease-out backwards;
  }

  .panel--input,
  .panel--results,
  .panel--journal {
    animation-delay: 0ms;
  }
}

@media (max-width: 600px) {
  .panel {
    animation: fadeIn 0.2s ease-out;
    will-change: auto;
  }

  .panel--input,
  .panel--results,
  .panel--journal {
    animation-delay: 0ms;
    transform: none !important;
  }

  .result-card.updated {
    animation: fadeIn 0.15s ease-out;
  }

  .trade-card {
    animation: fadeIn 0.18s ease-out;
  }
}

/* === Theme Transition === */

html.theme-transitioning *,
html.theme-transitioning *::before,
html.theme-transitioning *::after {
  transition:
    background-color 0.3s ease-out,
    color 0.3s ease-out,
    border-color 0.3s ease-out,
    box-shadow 0.3s ease-out,
    fill 0.3s ease-out,
    stroke 0.3s ease-out !important;
}

/* === View Swap Transitions === */

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

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

.view--hiding {
  animation: viewFadeOut 0.14s ease-out forwards;
  pointer-events: none;
}

.view--entering {
  animation: viewFadeIn 0.18s ease-out forwards;
}

@media (max-width: 768px) {
  .view--hiding {
    animation: viewFadeOut 0.12s ease-out forwards;
  }

  .view--entering {
    animation: viewFadeIn 0.16s ease-out forwards;
  }
}

/* === Reduced Motion === */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}