/* ═══════════════════════════════════════════════════════
   AFRO-BIM MICROINTERACTION LIBRARY
   Ripple · Skeleton · Toast · Loaders · Modals ·
   Contextual toolbars · Guided walkthrough overlays
═══════════════════════════════════════════════════════ */

/* ══════════════════════════════════════════
   1. RIPPLE EFFECT
   Add class .btn-ripple to any button
══════════════════════════════════════════ */
.btn-ripple {
  position: relative;
  overflow: hidden;
}
.btn-ripple .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,0.22);
  transform: scale(0);
  animation: ripple-expand 0.55s linear;
  pointer-events: none;
}
@keyframes ripple-expand {
  to { transform: scale(4); opacity: 0; }
}

/* ══════════════════════════════════════════
   2. SKELETON LOADERS
══════════════════════════════════════════ */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--indigo-700) 25%,
    var(--indigo-600) 50%,
    var(--indigo-700) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-wave 1.5s infinite;
  border-radius: var(--r-sm);
}
@keyframes skeleton-wave {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text  { height: 14px; border-radius: 7px; margin-bottom: 8px; }
.skeleton-title { height: 28px; border-radius: 6px; margin-bottom: 12px; width: 60%; }
.skeleton-img   { height: 180px; border-radius: var(--r-lg); margin-bottom: 16px; }
.skeleton-kpi   { height: 90px; border-radius: var(--r-lg); }
.skeleton-sm    { height: 10px; width: 40%; border-radius: 5px; }

/* Skeleton card (full placeholder card) */
.skeleton-card {
  background: var(--indigo-700);
  border: 1px solid rgba(255,255,255,0.04);
  border-radius: var(--r-lg);
  padding: 20px;
  overflow: hidden;
}

/* Progressive LOD reveal: model viewer skeleton */
.skeleton-viewer {
  width: 100%;
  height: 100%;
  border-radius: var(--r-lg);
  position: relative;
  overflow: hidden;
  background: var(--indigo-800);
}
.skeleton-viewer::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 20%,
    rgba(15,181,174,0.04) 50%,
    transparent 80%
  );
  background-size: 200% 100%;
  animation: skeleton-wave 2s infinite;
}
.skeleton-viewer-icon {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  font-size: 3rem;
  opacity: 0.12;
  animation: pulse 2s ease-in-out infinite;
}

/* ══════════════════════════════════════════
   3. TOAST NOTIFICATIONS
══════════════════════════════════════════ */
#toast-container {
  position: fixed;
  bottom: 80px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9500;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: rgba(18,18,46,0.97);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.1);
  border-left: 3px solid var(--teal);
  border-radius: var(--r-md);
  box-shadow: 0 8px 32px rgba(0,0,20,0.65);
  font-size: 0.82rem;
  color: var(--light);
  min-width: 280px;
  max-width: 360px;
  pointer-events: all;
  animation: toast-in 0.35s var(--ease-spring) forwards;
  position: relative;
  overflow: hidden;
}
.toast.exiting { animation: toast-out 0.25s var(--ease-smooth) forwards; }
.toast-icon { font-size: 1.1rem; flex-shrink: 0; }
.toast-body { flex: 1; }
.toast-title { font-weight: 600; font-size: 0.85rem; margin-bottom: 2px; color: var(--white); }
.toast-msg { font-size: 0.78rem; color: var(--grey); }
.toast-close { font-size: 1rem; color: var(--muted); cursor: pointer; flex-shrink: 0; transition: color var(--dur-fast); padding: 2px 4px; }
.toast-close:hover { color: var(--white); }

/* Progress bar that auto-closes toast */
.toast-progress {
  position: absolute;
  bottom: 0; left: 0;
  height: 2px;
  background: var(--teal);
  border-radius: 0 0 0 var(--r-md);
  animation: toast-progress 4s linear forwards;
}

.toast.success { border-left-color: var(--green); }
.toast.success .toast-progress { background: var(--green); }
.toast.warning { border-left-color: var(--ochre); }
.toast.warning .toast-progress { background: var(--ochre); }
.toast.error   { border-left-color: var(--red); }
.toast.error .toast-progress { background: var(--red); }

@keyframes toast-in  { from{transform:translateX(120%);opacity:0}to{transform:translateX(0);opacity:1} }
@keyframes toast-out { from{transform:translateX(0);opacity:1}to{transform:translateX(120%);opacity:0} }
@keyframes toast-progress { from{width:100%}to{width:0} }

/* ══════════════════════════════════════════
   4. PAGE LOADER (initial load)
══════════════════════════════════════════ */
#page-loader {
  position: fixed;
  inset: 0;
  background: var(--space);
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  transition: opacity 0.4s, visibility 0.4s;
}
#page-loader.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-logo { font-family: 'Syne', sans-serif; font-weight: 800; font-size: 2rem; color: var(--ochre); letter-spacing: -0.03em; }
.loader-logo span { color: var(--teal); }
.loader-bar {
  width: 200px;
  height: 2px;
  background: rgba(255,255,255,0.06);
  border-radius: 1px;
  overflow: hidden;
}
.loader-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--ochre), var(--teal));
  border-radius: 1px;
  animation: loader-fill 1.2s var(--ease-smooth) forwards;
}
@keyframes loader-fill { from{width:0}to{width:100%} }
.loader-text {
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

/* ══════════════════════════════════════════
   5. SPINNER / INLINE LOADER
══════════════════════════════════════════ */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,0.1);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}
.spinner-lg {
  width: 40px; height: 40px;
  border-width: 3px;
}
.spinner-ochre { border-top-color: var(--ochre); }

/* BIM model loading spinner with datum grid */
.model-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 100%;
  padding: 40px;
}
.model-loader-ring {
  position: relative;
  width: 60px; height: 60px;
}
.model-loader-ring::before,
.model-loader-ring::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  border: 2px solid transparent;
}
.model-loader-ring::before {
  inset: 0;
  border-top-color: var(--teal);
  animation: spin 1s linear infinite;
}
.model-loader-ring::after {
  inset: 8px;
  border-top-color: var(--ochre);
  animation: spin 0.7s linear infinite reverse;
}
.model-loader-text {
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  animation: blink 1.5s ease-in-out infinite;
}

/* ══════════════════════════════════════════
   6. CONTEXTUAL TOOLBAR
   Appears when a BIM element is selected
══════════════════════════════════════════ */
.contextual-toolbar {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: rgba(14,14,40,0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(15,181,174,0.25);
  border-radius: var(--r-md);
  box-shadow: 0 8px 30px rgba(0,0,20,0.7);
  z-index: 300;
  animation: slideUp 0.22s var(--ease-spring) forwards;
  pointer-events: all;
}
.ctx-btn {
  width: 34px; height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: var(--grey);
  font-size: 1rem;
  cursor: pointer;
  transition: all var(--dur-fast);
  position: relative;
}
.ctx-btn:hover { background: rgba(15,181,174,0.1); color: var(--teal); }
.ctx-btn.active { background: var(--teal-muted); color: var(--teal); }
.ctx-divider { width: 1px; height: 22px; background: rgba(255,255,255,0.08); margin: 0 2px; }

/* Tooltip on hover */
.ctx-btn::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10,10,28,0.96);
  color: var(--white);
  font-family: 'Space Mono', monospace;
  font-size: 0.6rem;
  padding: 4px 8px;
  border-radius: var(--r-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast);
  border: 1px solid rgba(255,255,255,0.08);
}
.ctx-btn:hover::after { opacity: 1; }

/* ══════════════════════════════════════════
   7. GUIDED WALKTHROUGH OVERLAY
══════════════════════════════════════════ */
.walkthrough-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8,8,26,0.75);
  z-index: 8900;
  pointer-events: none;
}
.walkthrough-spotlight {
  position: fixed;
  border-radius: var(--r-md);
  box-shadow: 0 0 0 9999px rgba(8,8,26,0.75);
  z-index: 8901;
  transition: all 0.4s var(--ease-smooth);
  pointer-events: none;
}
.walkthrough-bubble {
  position: fixed;
  background: rgba(18,18,46,0.98);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(15,181,174,0.3);
  border-radius: var(--r-lg);
  padding: 20px 22px;
  max-width: 320px;
  z-index: 8902;
  box-shadow: 0 16px 48px rgba(0,0,20,0.75);
  animation: slideUp 0.3s var(--ease-spring) forwards;
}
.walkthrough-step {
  font-family: 'Space Mono', monospace;
  font-size: 0.6rem;
  color: var(--teal);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.walkthrough-title {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 8px;
  color: var(--white);
}
.walkthrough-text {
  font-size: 0.82rem;
  color: var(--grey);
  line-height: 1.65;
  margin-bottom: 18px;
}
.walkthrough-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.walkthrough-dots {
  display: flex;
  gap: 5px;
}
.walkthrough-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  transition: background var(--dur-base), width var(--dur-base);
}
.walkthrough-dot.active { background: var(--teal); width: 18px; border-radius: 3px; }
.walkthrough-close {
  position: absolute;
  top: 12px; right: 12px;
  font-size: 1rem;
  color: var(--muted);
  cursor: pointer;
  transition: color var(--dur-fast);
  background: none;
  border: none;
}
.walkthrough-close:hover { color: var(--white); }

/* ══════════════════════════════════════════
   8. HOVER MICRO-STATES
══════════════════════════════════════════ */

/* Teal underline on text links */
.link-teal {
  color: var(--teal);
  position: relative;
  display: inline-block;
}
.link-teal::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0;
  width: 100%; height: 1px;
  background: var(--teal);
  transform: scaleX(0);
  transform-origin: right;
  transition: transform var(--dur-base) var(--ease-smooth);
}
.link-teal:hover::after { transform: scaleX(1); transform-origin: left; }

/* Ochre underline */
.link-ochre {
  color: var(--ochre);
  position: relative;
  display: inline-block;
}
.link-ochre::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0;
  width: 100%; height: 1px;
  background: var(--ochre);
  transform: scaleX(0);
  transform-origin: right;
  transition: transform var(--dur-base) var(--ease-smooth);
}
.link-ochre:hover::after { transform: scaleX(1); transform-origin: left; }

/* Tactile press effect for critical actions */
.btn-tactile {
  transition: transform var(--dur-fast), box-shadow var(--dur-fast);
}
.btn-tactile:hover  { transform: translateY(-2px); }
.btn-tactile:active { transform: translateY(1px); box-shadow: none !important; }

/* Glow pulse on critical action buttons */
.btn-critical {
  animation: glow-ochre 2.5s ease-in-out infinite;
}

/* ══════════════════════════════════════════
   9. FOCUS INDICATOR UPGRADE
══════════════════════════════════════════ */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 3px;
}

/* ══════════════════════════════════════════
   10. ELEMENT SELECTION HIGHLIGHT (BIM)
══════════════════════════════════════════ */
.bim-element-selected {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(15,181,174,0.15);
  animation: element-pulse 1.5s ease-in-out infinite;
}
@keyframes element-pulse {
  0%,100% { box-shadow: 0 0 0 4px rgba(15,181,174,0.15); }
  50%      { box-shadow: 0 0 0 8px rgba(15,181,174,0.05); }
}

/* Clash highlight */
.bim-element-clash {
  outline: 2px solid var(--red);
  box-shadow: 0 0 0 4px rgba(192,57,43,0.15);
  animation: clash-highlight 1s ease-in-out infinite;
}
@keyframes clash-highlight {
  0%,100% { box-shadow: 0 0 0 4px rgba(192,57,43,0.15); }
  50%      { box-shadow: 0 0 0 8px rgba(192,57,43,0.30); }
}

/* ══════════════════════════════════════════
   SCROLL-TRIGGERED STAGGER
   Children get sequential delay via CSS
══════════════════════════════════════════ */
.stagger-children > *:nth-child(1)  { transition-delay: 0ms; }
.stagger-children > *:nth-child(2)  { transition-delay: 80ms; }
.stagger-children > *:nth-child(3)  { transition-delay: 160ms; }
.stagger-children > *:nth-child(4)  { transition-delay: 240ms; }
.stagger-children > *:nth-child(5)  { transition-delay: 320ms; }
.stagger-children > *:nth-child(6)  { transition-delay: 400ms; }
.stagger-children > *:nth-child(7)  { transition-delay: 480ms; }
.stagger-children > *:nth-child(8)  { transition-delay: 560ms; }
.stagger-children > *:nth-child(9)  { transition-delay: 640ms; }
.stagger-children > *:nth-child(10) { transition-delay: 720ms; }
.stagger-children > *:nth-child(11) { transition-delay: 800ms; }
.stagger-children > *:nth-child(12) { transition-delay: 880ms; }

@media (prefers-reduced-motion: reduce) {
  .stagger-children > * { transition-delay: 0ms !important; }
  .btn-ripple .ripple   { display: none; }
  #page-loader          { display: none !important; }
}
