/* ==========================================================================
   Friendly Healthcare Map - Micro-interaction Animation System (Phase 2)
   ========================================================================== */

/* ---- Core keyframes ---- */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

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

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInLeft {
  from { opacity: 0; transform: translateX(-20px); }
  to   { opacity: 1; transform: translateX(0); }
}

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

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes slideInLeft {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}

@keyframes slideInRight {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

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

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

/* ---- Button ripple ---- */
@keyframes ripple {
  0%   { transform: scale(0); opacity: 0.5; }
  100% { transform: scale(4); opacity: 0; }
}

/* ---- Pulse (for voice search & live indicators) ---- */
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.08); opacity: 0.85; }
}

@keyframes pulseRing {
  0%   { transform: scale(0.8); opacity: 0.8; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* ---- Marker bounce ---- */
@keyframes markerBounce {
  0%, 100% { transform: translateY(0); }
  30%      { transform: translateY(-12px); }
  50%      { transform: translateY(-6px); }
  70%      { transform: translateY(-3px); }
}

/* ---- Float (for decorative elements) ---- */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}

/* ---- Spin (already defined in main.css, reference only) ---- */

/* ---- Notification slide ---- */
@keyframes notifySlideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

@keyframes notifySlideOut {
  from { transform: translateX(0); opacity: 1; }
  to   { transform: translateX(100%); opacity: 0; }
}

/* ---- Progress bar fill ---- */
@keyframes progressFill {
  from { width: 0; }
}

/* ---- Gentle shake (for errors / warnings) ---- */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 50%, 90% { transform: translateX(-4px); }
  30%, 70% { transform: translateX(4px); }
}

/* ==========================================================================
   Animation utility classes
   ========================================================================== */

/* Apply these classes to trigger animations */
.anim-fade-in       { animation: fadeIn 0.4s ease-out both; }
.anim-fade-in-up    { animation: fadeInUp 0.5s ease-out both; }
.anim-fade-in-down  { animation: fadeInDown 0.4s ease-out both; }
.anim-fade-in-left  { animation: fadeInLeft 0.5s ease-out both; }
.anim-fade-in-right { animation: fadeInRight 0.5s ease-out both; }
.anim-scale-in      { animation: scaleIn 0.35s ease-out both; }
.anim-shake         { animation: shake 0.5s ease-in-out; }

/* Stagger delays for lists / grids */
.anim-delay-1 { animation-delay: 0.05s; }
.anim-delay-2 { animation-delay: 0.10s; }
.anim-delay-3 { animation-delay: 0.15s; }
.anim-delay-4 { animation-delay: 0.20s; }
.anim-delay-5 { animation-delay: 0.25s; }
.anim-delay-6 { animation-delay: 0.30s; }
.anim-delay-7 { animation-delay: 0.35s; }
.anim-delay-8 { animation-delay: 0.40s; }

/* ==========================================================================
   Button ripple effect
   ========================================================================== */
.btn {
  position: relative;
  overflow: hidden;
}

.btn .ripple-circle {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  width: 24px;
  height: 24px;
  margin-top: -12px;
  margin-left: -12px;
  animation: ripple 0.6s ease-out forwards;
  pointer-events: none;
}

.btn-secondary .ripple-circle {
  background: rgba(14, 165, 160, 0.15);
}

/* ==========================================================================
   Card hover micro-interactions (enhanced)
   ========================================================================== */
.stat-card,
.facility-card,
.needs-card {
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              border-color 0.25s ease;
}

/* Facility card: subtle left-border accent on hover */
.facility-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 4px;
  height: 0;
  background: var(--color-primary);
  border-radius: 0 4px 4px 0;
  transition: height 0.3s ease, top 0.3s ease;
}

.facility-card {
  position: relative;
}

.facility-card:hover::before {
  height: 60%;
  top: 20%;
}

/* ==========================================================================
   Panel transitions (enhanced)
   ========================================================================== */
#search-panel {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#facility-detail-panel {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   Tab switch fade transition
   ========================================================================== */
.dashboard-tab-panel {
  animation: fadeIn 0.3s ease-out;
}

.dashboard-tab-panel[hidden] {
  display: none;
}

/* Tab underline slide effect */
.dashboard-tab {
  position: relative;
}

.dashboard-tab::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 50%;
  width: 0;
  height: 3px;
  background: var(--color-primary);
  border-radius: var(--border-radius-pill);
  transition: width 0.3s ease, left 0.3s ease;
}

.dashboard-tab.is-active::after {
  width: 100%;
  left: 0;
}

.dashboard-tab:hover::after {
  width: 60%;
  left: 20%;
}

/* ==========================================================================
   Skeleton loading screens
   ========================================================================== */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-bg-secondary) 25%,
    rgba(255, 255, 255, 0.6) 50%,
    var(--color-bg-secondary) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--border-radius-md);
}

.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
  border-radius: 4px;
}

.skeleton-text--short {
  width: 40%;
}

.skeleton-text--medium {
  width: 70%;
}

.skeleton-text--long {
  width: 100%;
}

.skeleton-title {
  height: 20px;
  width: 60%;
  margin-bottom: 12px;
}

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

.skeleton-card {
  padding: var(--space-md);
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-bg-white);
}

.skeleton-card__row {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
  margin-bottom: var(--space-sm);
}

.skeleton-card__row:last-child {
  margin-bottom: 0;
}

/* Skeleton stat card */
.skeleton-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-lg) var(--space-md);
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-bg-white);
}

.skeleton-stat__grade {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

.skeleton-stat__label {
  width: 60px;
  height: 12px;
}

.skeleton-stat__count {
  width: 40px;
  height: 24px;
}

/* Skeleton needs card */
.skeleton-needs {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xl) var(--space-lg);
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-bg-white);
}

.skeleton-needs__icon {
  width: 56px;
  height: 56px;
  border-radius: var(--border-radius-lg);
}

.skeleton-needs__title {
  width: 80px;
  height: 16px;
}

.skeleton-needs__count {
  width: 50px;
  height: 12px;
}

/* ==========================================================================
   Map marker animations
   ========================================================================== */
.leaflet-marker-icon.marker-bounce {
  animation: markerBounce 0.6s ease-out;
}

.leaflet-marker-icon.marker-pulse::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid var(--color-primary);
  transform: translate(-50%, -50%);
  animation: pulseRing 1.5s ease-out infinite;
  pointer-events: none;
}

/* ==========================================================================
   Voice search pulse animation
   ========================================================================== */
#voice-search-btn[aria-pressed="true"] {
  animation: pulse 1.2s ease-in-out infinite;
  color: var(--color-danger);
}

#voice-search-btn[aria-pressed="true"]::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid var(--color-danger);
  transform: translate(-50%, -50%);
  animation: pulseRing 1.5s ease-out infinite;
  pointer-events: none;
}

/* ==========================================================================
   Notification toast animations
   ========================================================================== */
.notification-toast {
  animation: notifySlideIn 0.35s cubic-bezier(0.4, 0, 0.2, 1) both;
}

.notification-toast.is-exiting {
  animation: notifySlideOut 0.3s ease-in both;
}

/* ==========================================================================
   Match bar fill animation
   ========================================================================== */
.match-bar__fill {
  animation: progressFill 0.8s cubic-bezier(0.4, 0, 0.2, 1) both;
}

/* ==========================================================================
   Form input focus glow animation
   ========================================================================== */
.form-input:focus,
.form-select:focus {
  transition: border-color 0.2s ease,
              box-shadow 0.3s ease;
}

/* Checkbox check animation */
.form-checkbox input[type="checkbox"] {
  transition: transform 0.15s ease;
}

.form-checkbox input[type="checkbox"]:checked {
  transform: scale(1.1);
}

.form-checkbox input[type="checkbox"]:active {
  transform: scale(0.9);
}

/* ==========================================================================
   Dashboard hero decorative floating elements
   ========================================================================== */
.dashboard-hero__float-1,
.dashboard-hero__float-2 {
  position: absolute;
  border-radius: 50%;
  opacity: 0.08;
  pointer-events: none;
}

.dashboard-hero__float-1 {
  width: 200px;
  height: 200px;
  background: #fff;
  top: -40px;
  right: -30px;
  animation: float 6s ease-in-out infinite;
}

.dashboard-hero__float-2 {
  width: 140px;
  height: 140px;
  background: #fff;
  bottom: 30px;
  left: -20px;
  animation: float 8s ease-in-out infinite 1s;
}

/* ==========================================================================
   Grade badge pop on appear
   ========================================================================== */
.grade-badge {
  transition: transform 0.15s ease;
}

.grade-badge:hover {
  transform: scale(1.15);
}

/* ==========================================================================
   Search toggle button spin on hover
   ========================================================================== */
#search-toggle-btn {
  transition: transform 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
}

#search-toggle-btn:hover {
  transform: scale(1.08) rotate(8deg);
}

#search-toggle-btn:active {
  transform: scale(0.95);
}

/* ==========================================================================
   Tooltip animation
   ========================================================================== */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  padding: 4px 10px;
  background: var(--color-text);
  color: var(--color-text-inverse);
  font-size: var(--font-size-xs);
  border-radius: var(--border-radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Map control buttons use JS tooltip (.map-ctrl-tooltip), disable CSS tooltip */
.leaflet-control [data-tooltip]::after,
.leaflet-control [data-tooltip]:hover::after,
.leaflet-control [data-tooltip]:focus::after {
  display: none !important;
}

/* ==========================================================================
   Reduced motion: respect user preferences
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .skeleton {
    animation: none;
    background: var(--color-bg-secondary);
  }

  .btn .ripple-circle {
    display: none;
  }

  .notification-toast {
    animation: none;
  }

  #voice-search-btn[aria-pressed="true"] {
    animation: none;
  }
}
