/* ============================================================
   ANIMATIONS & MICRO-INTERACTIONS
   Insightful Booking Design System
   ============================================================ */

/* ============================================================
   1. PAGE TRANSITIONS — Subtle fade-in on page load
   ============================================================ */

@keyframes ds-page-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-in,
.premium-hero,
.ds-card {
  animation: ds-page-fade-in 0.4s ease both;
}

.fade-in:nth-child(2),
.ds-card:nth-child(2) { animation-delay: 0.05s; }
.fade-in:nth-child(3),
.ds-card:nth-child(3) { animation-delay: 0.1s; }
.fade-in:nth-child(4),
.ds-card:nth-child(4) { animation-delay: 0.15s; }

/* ============================================================
   2. BUTTON PRESS — Scale down on active
   ============================================================ */

.btn,
.ds-btn,
.btn-custom {
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease, background-color 0.15s ease;
}

.btn:active:not(:disabled),
.ds-btn:active:not(:disabled),
.btn-custom:active:not(:disabled) {
  transform: scale(0.97);
}

/* ============================================================
   3. CARD HOVER — Lift effect (scoped to design-system cards only)
   ============================================================ */

.ds-card {
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

@media (hover: hover) {
  .ds-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  }

  [data-theme="dark"] .ds-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

/* ============================================================
   4. INPUT FOCUS — Ring animation
   ============================================================ */

input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]),
textarea,
select,
.form-control,
.form-select,
.ds-input {
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):focus,
textarea:focus,
select:focus,
.form-control:focus,
.form-select:focus,
.ds-input:focus {
  border-color: var(--color-primary, #FFD700) !important;
  box-shadow: 0 0 0 3px rgba(0, 131, 99, 0.15) !important;
  outline: none !important;
}

[data-theme="dark"] input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):focus,
[data-theme="dark"] textarea:focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus,
[data-theme="dark"] .ds-input:focus {
  box-shadow: 0 0 0 3px rgba(0, 131, 99, 0.25) !important;
}

/* ============================================================
   5. SCROLL REVEAL — Fade in on scroll (IntersectionObserver)
   ============================================================ */

.ds-scroll-reveal {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.ds-scroll-reveal.ds-revealed {
  opacity: 1;
  transform: translateY(0);
}

/* ============================================================
   6. SKELETON LOADERS
   ============================================================ */

@keyframes ds-skeleton-pulse {
  0%   { background-position: -200px 0; }
  100% { background-position: calc(200px + 100%) 0; }
}

.ds-skeleton {
  background: linear-gradient(
    90deg,
    var(--color-bg-secondary, #f3f4f6) 0%,
    var(--color-bg, #e5e7eb) 40%,
    var(--color-bg-secondary, #f3f4f6) 80%
  );
  background-size: 200px 100%;
  animation: ds-skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm, 6px);
}

[data-theme="dark"] .ds-skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(255, 255, 255, 0.1) 40%,
    rgba(255, 255, 255, 0.05) 80%
  );
  background-size: 200px 100%;
}

.ds-skeleton-text {
  height: 14px;
  width: 80%;
  margin-bottom: 8px;
}

.ds-skeleton-text:last-child {
  width: 60%;
}

.ds-skeleton-heading {
  height: 24px;
  width: 50%;
  margin-bottom: 16px;
}

.ds-skeleton-card {
  height: 120px;
  border-radius: var(--radius-lg, 12px);
}

.ds-skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.ds-skeleton-btn {
  height: 44px;
  width: 120px;
  border-radius: var(--radius-md, 8px);
}

/* ============================================================
   7. TOAST NOTIFICATIONS
   ============================================================ */

@keyframes ds-toast-slide-in {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

@keyframes ds-toast-slide-out {
  from { transform: translateX(0); opacity: 1; }
  to   { transform: translateX(100%); opacity: 0; }
}

.ds-toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 380px;
  width: calc(100% - 32px);
}

.ds-toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--color-bg, #ffffff);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius-lg, 12px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  animation: ds-toast-slide-in 0.35s ease;
  pointer-events: auto;
  font-family: var(--font-primary, 'Inter', sans-serif);
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--color-text, #1f2937);
}

[data-theme="dark"] .ds-toast {
  background: var(--color-bg-secondary, #1e293b);
  border-color: var(--color-border, #334155);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.ds-toast.ds-toast-removing {
  animation: ds-toast-slide-out 0.3s ease forwards;
}

.ds-toast-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
  margin-top: 1px;
}

.ds-toast-content {
  flex: 1;
}

.ds-toast-title {
  font-weight: 600;
  margin-bottom: 2px;
}

.ds-toast-message {
  color: var(--color-text-secondary, #6b7280);
}

.ds-toast-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-secondary, #6b7280);
  padding: 2px;
  font-size: 1rem;
  flex-shrink: 0;
  transition: color 0.15s;
}

.ds-toast-close:hover {
  color: var(--color-text, #1f2937);
}

/* Toast variants */
.ds-toast--success .ds-toast-icon { color: var(--color-success, #10b981); }
.ds-toast--error   .ds-toast-icon { color: var(--color-error, #ef4444); }
.ds-toast--warning .ds-toast-icon { color: var(--color-warning, #f59e0b); }
.ds-toast--info    .ds-toast-icon { color: var(--color-info, #3b82f6); }

.ds-toast--success { border-left: 3px solid var(--color-success, #10b981); }
.ds-toast--error   { border-left: 3px solid var(--color-error, #ef4444); }
.ds-toast--warning { border-left: 3px solid var(--color-warning, #f59e0b); }
.ds-toast--info    { border-left: 3px solid var(--color-info, #3b82f6); }

/* ============================================================
   8. LOADING SPINNER (for buttons on submit)
   ============================================================ */

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

.ds-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: ds-spin 0.6s linear infinite;
  vertical-align: middle;
}

.ds-spinner--sm { width: 14px; height: 14px; border-width: 1.5px; }
.ds-spinner--lg { width: 24px; height: 24px; border-width: 3px; }

/* Button loading state */
.btn.ds-loading,
.ds-btn.ds-loading {
  pointer-events: none;
  opacity: 0.7;
}

/* ============================================================
   9. EMPTY STATES
   ============================================================ */

.ds-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px;
  color: var(--color-text-secondary, #6b7280);
}

.ds-empty-state-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.4;
}

.ds-empty-state-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text, #1f2937);
  margin-bottom: 8px;
}

.ds-empty-state-text {
  font-size: 0.875rem;
  max-width: 360px;
  margin-bottom: 24px;
}

/* ============================================================
   10. SMOOTH THEME TRANSITION
   Only activates when .ds-theme-transitioning is on <html>.
   The theme-toggle.js adds/removes this class during switches.
   ============================================================ */

html.ds-theme-transitioning,
html.ds-theme-transitioning *,
html.ds-theme-transitioning *::before,
html.ds-theme-transitioning *::after {
  transition-property: background-color, color, border-color, box-shadow !important;
  transition-duration: 0.3s !important;
  transition-timing-function: ease !important;
}

/* Exclude elements that should NOT transition even during theme switch */
html.ds-theme-transitioning .ds-skeleton,
html.ds-theme-transitioning .ds-spinner,
html.ds-theme-transitioning canvas,
html.ds-theme-transitioning video,
html.ds-theme-transitioning img {
  transition-property: none !important;
}

/* ============================================================
   11. ALERT ANIMATIONS — Smooth dismiss
   ============================================================ */

.alert {
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.alert.fade:not(.show) {
  opacity: 0;
  transform: translateY(-8px);
}

/* ============================================================
   12. TABLE ROW HOVER
   ============================================================ */

@media (hover: hover) {
  .table tbody tr,
  .premium-table tbody tr,
  .tenant-table tbody tr {
    transition: background-color 0.15s ease;
  }
}

/* ============================================================
   13. BADGE PULSE — For notification indicators
   ============================================================ */

@keyframes ds-badge-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.15); }
}

.ds-badge-pulse {
  animation: ds-badge-pulse 2s ease-in-out infinite;
}

/* ============================================================
   14. PROGRESS BAR ANIMATION
   ============================================================ */

@keyframes ds-progress-fill {
  from { width: 0; }
}

.progress-bar,
.ds-progress-bar {
  animation: ds-progress-fill 0.8s ease;
}

/* ============================================================
   15. REDUCED MOTION — Respect user preference
   ============================================================ */

@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;
  }

  .ds-skeleton {
    animation: none !important;
    background: var(--color-bg-secondary, #f3f4f6) !important;
  }
}

/* ============================================================
   16. TRIAL TENANT — Disable all animations
   ============================================================ */

.trial-tenant *,
.trial-tenant *::before,
.trial-tenant *::after {
  animation-duration: 0ms !important;
  animation-delay: 0ms !important;
  transition-duration: 0ms !important;
}
