/* Loading screen: logo fill then empty animation */

/* Keep nav above the loader overlay only after first visit (body class set by loader.js) */
body.loader-nav-visible .sidebar,
body.loader-nav-visible .mobile-header,
body.loader-nav-visible .mobile-nav {
  z-index: 10000;
}

.loader-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-primary, #1E1E1E);
  opacity: 1;
  visibility: visible;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.loader-overlay.loader-hiding {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-overlay.loader-hidden {
  display: none;
}

.loader-logo-wrap {
  position: relative;
  width: 140px;
  height: 140px;
}

/* Outline/empty logo (base layer) */
.loader-logo-outline {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.35;
}

/* Fill layer: same logo used as mask, clip-path animates fill from bottom */
.loader-logo-fill {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background-color: var(--color-heading, #ffffff);
  mask-image: url('../images/Logo-light.png');
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
  -webkit-mask-image: url('../images/Logo-light.png');
  -webkit-mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
  clip-path: inset(0 0 100% 0);
}

/* Phase 1: fill only (empty → full) – default = subsequent page loads */
.loader-logo-fill.loader-fill-phase {
  animation: loader-fill-only 0.5s ease-in-out forwards;
}

/* Phase 2: if still loading, run empty (full → empty) */
.loader-logo-fill.loader-empty-phase {
  clip-path: inset(0 0 0% 0);
  animation: loader-empty-only 0.5s ease-in-out forwards;
}

/* First visit only: slower animation */
.loader-overlay.loader-first-visit .loader-logo-fill.loader-fill-phase {
  animation-duration: 1s;
}
.loader-overlay.loader-first-visit .loader-logo-fill.loader-empty-phase {
  animation-duration: 1s;
}

/* Supabase/content loading: super short animation */
.loader-overlay.loader-short .loader-logo-fill.loader-fill-phase {
  animation-duration: 0.125s;
}
.loader-overlay.loader-short .loader-logo-fill.loader-empty-phase {
  animation-duration: 0.125s;
}

/* When overlay is hiding, stop animation and show empty logo */
.loader-overlay.loader-hiding .loader-logo-fill {
  animation: none;
  clip-path: inset(0 0 100% 0);
}

@keyframes loader-fill-only {
  from {
    clip-path: inset(0 0 100% 0);
  }
  to {
    clip-path: inset(0 0 0% 0);
  }
}

@keyframes loader-empty-only {
  from {
    clip-path: inset(0 0 0% 0);
  }
  to {
    clip-path: inset(0 0 100% 0);
  }
}

/* Light mode overlay: use dark logo for fill mask */
body.light-mode .loader-logo-outline {
  opacity: 0.4;
}

body.light-mode .loader-logo-fill {
  background-color: var(--color-heading-light, #1a1a1a);
  mask-image: url('../images/Logo-dark.png');
  -webkit-mask-image: url('../images/Logo-dark.png');
}

body.light-mode .loader-overlay {
  background-color: var(--bg-primary-light, #f5f5f5);
}
