/* ============================================
   Animations — Keyframes
   ============================================ */

@keyframes shimmer {
  0%   { background-position: -600px 0; }
  100% { background-position:  600px 0; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes spinnerStroke {
  0%   { stroke-dashoffset: 150; }
  50%  { stroke-dashoffset: 40;  }
  100% { stroke-dashoffset: 150; transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1);    opacity: 1;    }
  50%       { transform: scale(1.12); opacity: 0.85; }
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1);   opacity: 1;   }
  50%       { transform: scale(1.4); opacity: 0.6; }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0);    }
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-16px); }
  to   { opacity: 1; transform: translateX(0);     }
}

@keyframes slideInUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0);    }
}

@keyframes cardReveal {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

@keyframes progressSlide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%);  }
}

@keyframes navPop {
  0%   { transform: scale(1);    }
  35%  { transform: scale(0.82); }
  70%  { transform: scale(1.15); }
  100% { transform: scale(1);    }
}

@keyframes rippleExpand {
  to { transform: scale(4); opacity: 0; }
}

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0);   }
  30%           { transform: translateY(-6px); }
}

@keyframes starBurst {
  0%   { transform: scale(1) rotate(0deg);     }
  30%  { transform: scale(1.45) rotate(-15deg); }
  60%  { transform: scale(0.9) rotate(10deg);  }
  100% { transform: scale(1) rotate(0deg);     }
}

@keyframes unreadPulse {
  0%, 100% { box-shadow: 0 0 0 0   rgba(244, 197, 66, 0.6); }
  50%      { box-shadow: 0 0 0 5px rgba(244, 197, 66, 0);   }
}

@keyframes borderGlow {
  0%, 100% { box-shadow: 0 0 0 3px rgba(244, 197, 66, 0.07); }
  50%      { box-shadow: 0 0 0 3px rgba(244, 197, 66, 0.14), 0 0 16px rgba(244, 197, 66, 0.08); }
}

/* Modal scale-in from slight below */
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.93) translateY(12px); }
  to   { opacity: 1; transform: scale(1)    translateY(0);     }
}

/* Gentle float up for badges/chips */
@keyframes floatUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Gold accent glow pulse */
@keyframes glowPulse {
  0%, 100% { filter: drop-shadow(0 0 4px rgba(244, 197, 66, 0.3)); }
  50%       { filter: drop-shadow(0 0 10px rgba(244, 197, 66, 0.65)); }
}

/* Pop in from scale(0) */
@keyframes popIn {
  0%   { opacity: 0; transform: scale(0.6);   }
  70%  { opacity: 1; transform: scale(1.08);  }
  100% { opacity: 1; transform: scale(1);     }
}

/* Slide down (notifications) */
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)     scale(1);     }
}

/* ============================================
   Page-Level Progress Bar
   ============================================ */
#page-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 9999;
  background: transparent;
  pointer-events: none;
  overflow: hidden;
}

#page-progress::after {
  content: '';
  display: block;
  height: 100%;
  background: linear-gradient(90deg, transparent, var(--color-accent), #ffe48a, var(--color-accent), transparent);
  animation: progressSlide 1.1s ease-in-out infinite;
}

#page-progress.hidden {
  display: none;
}

/* ============================================
   Spinner (circular)
   ============================================ */
.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid rgba(244, 197, 66, 0.15);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}

.spinner-sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

.spinner-lg {
  width: 36px;
  height: 36px;
  border-width: 2.5px;
}

.loading-center {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px 0;
  gap: 10px;
  color: var(--color-text-tertiary);
  font-size: 13px;
  font-family: "Plus Jakarta Sans", sans-serif;
}

/* ============================================
   Skeleton Loading Cards
   ============================================ */
.skeleton-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--color-border, rgba(255,255,255,0.08));
  border-radius: var(--radius, 16px);
  padding: 16px;
  margin-bottom: 10px;
  overflow: hidden;
}

.skeleton-line {
  border-radius: 8px;
  background: linear-gradient(
    90deg,
    rgba(255,255,255,0.04) 0%,
    rgba(255,255,255,0.09) 35%,
    rgba(255,255,255,0.04) 70%
  );
  background-size: 600px 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-card .skeleton-line:first-child {
  height: 15px;
  width: 62%;
  margin-bottom: 10px;
}

.skeleton-card .skeleton-line:last-child {
  height: 13px;
  width: 42%;
}

:root.light-mode .skeleton-line {
  background: linear-gradient(
    90deg,
    #ebebeb 0%,
    #f5f5f5 35%,
    #ebebeb 70%
  );
  background-size: 600px 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-chat {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border, rgba(255,255,255,0.08));
}

.skeleton-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  flex-shrink: 0;
  background: linear-gradient(
    90deg,
    rgba(255,255,255,0.04) 0%,
    rgba(255,255,255,0.09) 35%,
    rgba(255,255,255,0.04) 70%
  );
  background-size: 600px 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-chat-lines {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ============================================
   Card Stagger Entrance
   ============================================ */
.listing-card {
  animation: cardReveal 380ms var(--ease-spring, cubic-bezier(0.16, 1, 0.3, 1)) both;
  animation-delay: calc(var(--card-i, 0) * 55ms);
}

/* ============================================
   Chat Message Entrance
   ============================================ */
.message.own   { animation: slideInRight 240ms var(--ease-spring, cubic-bezier(0.16, 1, 0.3, 1)) both; }
.message.other { animation: slideInLeft  240ms var(--ease-spring, cubic-bezier(0.16, 1, 0.3, 1)) both; }

/* ============================================
   Nav Active Pop — gold icon glow
   ============================================ */
.nav-item.active i {
  animation: navPop 320ms var(--ease-spring, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

/* ============================================
   Unread Badge Pulse
   ============================================ */
.chat-unread-badge {
  animation: unreadPulse 2s ease-in-out infinite;
}

/* ============================================
   Button Loading State
   ============================================ */
.btn-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.8;
}

.btn-loading .btn-label { visibility: hidden; }

.btn-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-top-color: var(--color-primary, #111);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

/* ============================================
   Ripple on Buttons
   ============================================ */
.btn-ripple {
  position: relative;
  overflow: hidden;
}

.ripple-circle {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  transform: scale(0);
  animation: rippleExpand 550ms ease-out forwards;
  pointer-events: none;
}

/* ============================================
   Typing Indicator
   ============================================ */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--color-border, rgba(255,255,255,0.08));
  border-radius: 18px 18px 18px 4px;
  margin-bottom: 8px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-text-tertiary);
  animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.30s; }

/* ============================================
   Favorite / Star Burst
   ============================================ */
.btn-star.burst i {
  animation: starBurst 400ms cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

/* ============================================
   Input Focus Glow
   ============================================ */
.listing-input:focus,
.filter-input:focus,
.search-input:focus {
  animation: borderGlow 2s ease-in-out infinite;
}

/* ============================================
   Modal Entrance
   ============================================ */
.settings-modal.open .modal-content,
.listing-detail-modal.open .modal-content,
.auth-modal .modal-content {
  animation: scaleIn 320ms var(--ease-spring, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

/* Notification dropdown */
.notif-dropdown:not([hidden]) {
  animation: slideDown 260ms var(--ease-spring, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

/* ============================================
   Notification badge pop
   ============================================ */
.notif-badge {
  animation: popIn 350ms var(--ease-spring, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

/* ============================================
   Section h1 underline reveal
   ============================================ */
section h1::after {
  animation: floatUp 500ms var(--ease-spring, cubic-bezier(0.16, 1, 0.3, 1)) both;
  animation-delay: 100ms;
}

/* ============================================
   Maintenance Overlay
   ============================================ */
@keyframes maintenancePulse {
  0%, 100% { transform: rotate(-8deg) scale(1); }
  50%       { transform: rotate(-8deg) scale(1.12); }
}

@keyframes maintenanceDotBounce {
  0%, 100% { opacity: 0.3; transform: translateY(0); }
  50%       { opacity: 1;   transform: translateY(-5px); }
}

.maintenance-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--color-primary, #0e0e0e);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.maintenance-overlay[hidden] {
  display: none !important;
}

.maintenance-card {
  text-align: center;
  max-width: 340px;
}

.maintenance-icon {
  display: block;
  font-size: 56px;
  color: var(--color-accent, #f4c542);
  margin-bottom: 28px;
  animation: maintenancePulse 2.4s ease-in-out infinite;
  transform-origin: center;
}

.maintenance-card h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text, #f0f0f0);
}

.maintenance-card p {
  font-size: 1rem;
  line-height: 1.6;
  color: var(--color-text-secondary, #a0a0a0);
  margin-bottom: 32px;
}

.maintenance-dots {
  display: inline-flex;
  gap: 8px;
}

.maintenance-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-accent, #f4c542);
  animation: maintenanceDotBounce 1.2s ease-in-out infinite;
}

.maintenance-dots span:nth-child(2) { animation-delay: 0.2s; }
.maintenance-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ============================================
   Initial App Loader
   ============================================ */
.app-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg, #0d0d14);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.35s ease;
}

.app-loader.fade-out {
  opacity: 0;
  pointer-events: none;
}

.app-loader-ring {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(244, 197, 66, 0.2);
  border-top-color: var(--color-accent, #f4c542);
  border-radius: 50%;
  animation: loaderSpin 0.8s linear infinite;
}

@keyframes loaderSpin {
  to { transform: rotate(360deg); }
}

/* ============================================
   Back to Top Button
   ============================================ */
.back-to-top-btn {
  position: fixed;
  bottom: 28px;
  right: 24px;
  z-index: 400;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--color-accent, #f4c542);
  color: #000;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s ease, transform 0.25s ease, background 0.2s ease;
  pointer-events: none;
}

.back-to-top-btn:not([hidden]) {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

@media (hover: hover) {
  .back-to-top-btn:hover {
    background: var(--color-accent-hover, #ffd45e);
    transform: translateY(-2px);
  }
}

/* ============================================
   Reduced Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
