/* --- HOSLI LOADERS LIBRARY --- */
/* Utilizza le variabili del tema: --text-main e --wine-liquid */

/* 1. Pulse (Cerchio pulsante) */
.loader-pulse {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--text-main);
  animation: pulse 1s linear infinite alternate;
}
@keyframes pulse {
  0% { transform: scale(0.8); opacity: 0.5; }
  100% { transform: scale(1.2); opacity: 1; }
}

/* 2. Bars (Equalizzatore) */
.loader-bars {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
}
.loader-bars div {
  width: 6px;
  background: var(--text-main);
  animation: bars 1s ease-in-out infinite;
}
.loader-bars div:nth-child(1) { animation-delay: 0.0s; height: 20px; }
.loader-bars div:nth-child(2) { animation-delay: 0.1s; height: 30px; }
.loader-bars div:nth-child(3) { animation-delay: 0.2s; height: 40px; }
.loader-bars div:nth-child(4) { animation-delay: 0.1s; height: 30px; }
.loader-bars div:nth-child(5) { animation-delay: 0.0s; height: 20px; }
@keyframes bars {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(1.5); }
}

/* 3. Ring (Doppio anello rotante) */
.loader-ring {
  display: inline-block;
  width: 60px;
  height: 60px;
}
.loader-ring:after {
  content: " ";
  display: block;
  width: 44px;
  height: 44px;
  margin: 8px;
  border-radius: 50%;
  border: 5px solid var(--text-main);
  border-color: var(--text-main) transparent var(--text-main) transparent;
  animation: ring 1.2s linear infinite;
}
@keyframes ring {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 4. Roller (Palline che ruotano) */
.loader-roller {
  display: inline-block;
  position: relative;
  width: 80px;
  height: 80px;
}
.loader-roller div {
  animation: roller 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
  transform-origin: 40px 40px;
}
.loader-roller div:after {
  content: " ";
  display: block;
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-main);
  margin: -4px 0 0 -4px;
}
.loader-roller div:nth-child(1) { animation-delay: -0.036s; }
.loader-roller div:nth-child(1):after { top: 63px; left: 63px; }
.loader-roller div:nth-child(2) { animation-delay: -0.072s; }
.loader-roller div:nth-child(2):after { top: 68px; left: 56px; }
.loader-roller div:nth-child(3) { animation-delay: -0.108s; }
.loader-roller div:nth-child(3):after { top: 71px; left: 48px; }
.loader-roller div:nth-child(4) { animation-delay: -0.144s; }
.loader-roller div:nth-child(4):after { top: 72px; left: 40px; }
.loader-roller div:nth-child(5) { animation-delay: -0.18s; }
.loader-roller div:nth-child(5):after { top: 71px; left: 32px; }
.loader-roller div:nth-child(6) { animation-delay: -0.216s; }
.loader-roller div:nth-child(6):after { top: 68px; left: 24px; }
.loader-roller div:nth-child(7) { animation-delay: -0.252s; }
.loader-roller div:nth-child(7):after { top: 63px; left: 17px; }
.loader-roller div:nth-child(8) { animation-delay: -0.288s; }
.loader-roller div:nth-child(8):after { top: 56px; left: 12px; }
@keyframes roller {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 5. Heart (Cuore pulsante - usa il colore del vino) */
.loader-heart {
  display: inline-block;
  position: relative;
  width: 80px;
  height: 80px;
  transform: rotate(45deg);
  transform-origin: 40px 40px;
}
.loader-heart div {
  top: 32px;
  left: 32px;
  position: absolute;
  width: 32px;
  height: 32px;
  background: var(--wine-liquid);
  animation: heart 1.2s infinite cubic-bezier(0.215, 0.61, 0.355, 1);
}
.loader-heart div:after,
.loader-heart div:before {
  content: " ";
  position: absolute;
  display: block;
  width: 32px;
  height: 32px;
  background: var(--wine-liquid);
}
.loader-heart div:before {
  left: -24px;
  border-radius: 50% 0 0 50%;
}
.loader-heart div:after {
  top: -24px;
  border-radius: 50% 50% 0 0;
}
@keyframes heart {
  0% { transform: scale(0.95); }
  5% { transform: scale(1.1); }
  39% { transform: scale(0.85); }
  45% { transform: scale(1); }
  60% { transform: scale(0.95); }
  100% { transform: scale(0.9); }
}

/* 6. Grid (Griglia 3x3) */
.loader-grid {
  display: inline-block;
  position: relative;
  width: 80px;
  height: 80px;
}
.loader-grid div {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-main);
  animation: grid 1.2s linear infinite;
}
.loader-grid div:nth-child(1) { top: 8px; left: 8px; animation-delay: 0s; }
.loader-grid div:nth-child(2) { top: 8px; left: 32px; animation-delay: -0.4s; }
.loader-grid div:nth-child(3) { top: 8px; left: 56px; animation-delay: -0.8s; }
.loader-grid div:nth-child(4) { top: 32px; left: 8px; animation-delay: -0.4s; }
.loader-grid div:nth-child(5) { top: 32px; left: 32px; animation-delay: -0.8s; }
.loader-grid div:nth-child(6) { top: 32px; left: 56px; animation-delay: -1.2s; }
.loader-grid div:nth-child(7) { top: 56px; left: 8px; animation-delay: -0.8s; }
.loader-grid div:nth-child(8) { top: 56px; left: 32px; animation-delay: -1.2s; }
.loader-grid div:nth-child(9) { top: 56px; left: 56px; animation-delay: -1.6s; }
@keyframes grid {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* 7. Hourglass (Clessidra) */
.loader-hourglass {
  display: inline-block;
  position: relative;
  width: 80px;
  height: 80px;
}
.loader-hourglass:after {
  content: " ";
  display: block;
  border-radius: 50%;
  width: 0;
  height: 0;
  margin: 8px;
  box-sizing: border-box;
  border: 32px solid var(--text-main);
  border-color: var(--text-main) transparent var(--text-main) transparent;
  animation: hourglass 1.2s infinite;
}
@keyframes hourglass {
  0% { transform: rotate(0); animation-timing-function: cubic-bezier(0.55, 0.055, 0.675, 0.19); }
  50% { transform: rotate(900deg); animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1); }
  100% { transform: rotate(1800deg); }
}

/* 8. Ripple (Onda) */
.loader-ripple {
  display: inline-block;
  position: relative;
  width: 80px;
  height: 80px;
}
.loader-ripple div {
  position: absolute;
  border: 4px solid var(--text-main);
  opacity: 1;
  border-radius: 50%;
  animation: ripple 1s cubic-bezier(0, 0.2, 0.8, 1) infinite;
}
.loader-ripple div:nth-child(2) {
  animation-delay: -0.5s;
}
@keyframes ripple {
  0% { top: 36px; left: 36px; width: 0; height: 0; opacity: 0; }
  4.9% { top: 36px; left: 36px; width: 0; height: 0; opacity: 0; }
  5% { top: 36px; left: 36px; width: 0; height: 0; opacity: 1; }
  100% { top: 0px; left: 0px; width: 72px; height: 72px; opacity: 0; }
}

/* 9. Fade Circle (Cerchio che svanisce) */
.loader-fade-circle {
  width: 40px;
  height: 40px;
  background-color: var(--text-main);
  border-radius: 100%;  
  animation: fade-circle 1.0s infinite ease-in-out;
}
@keyframes fade-circle {
  0% { transform: scale(0); }
  100% { transform: scale(1.0); opacity: 0; }
}

/* 10. Ellipsis (Tre puntini scorrevoli) */
.loader-ellipsis {
  display: inline-block;
  position: relative;
  width: 80px;
  height: 80px;
}
.loader-ellipsis div {
  position: absolute;
  top: 33px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--text-main);
  animation-timing-function: cubic-bezier(0, 1, 1, 0);
}
.loader-ellipsis div:nth-child(1) { left: 8px; animation: ellipsis1 0.6s infinite; }
.loader-ellipsis div:nth-child(2) { left: 8px; animation: ellipsis2 0.6s infinite; }
.loader-ellipsis div:nth-child(3) { left: 32px; animation: ellipsis2 0.6s infinite; }
.loader-ellipsis div:nth-child(4) { left: 56px; animation: ellipsis3 0.6s infinite; }
@keyframes ellipsis1 {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}
@keyframes ellipsis3 {
  0% { transform: scale(1); }
  100% { transform: scale(0); }
}
@keyframes ellipsis2 {
  0% { transform: translate(0, 0); }
  100% { transform: translate(24px, 0); }
}

/* 11. Pill Wave (Onda di pillole) */
.loader-pill-wave {
  height: 40px;
  aspect-ratio: 1.5;
  display: grid;
}
.loader-pill-wave:before,
.loader-pill-wave:after {
  content: "";
  background: var(--text-main);
  border-radius: 80px 80px 0 0;
  animation: l10 1s infinite alternate both;
}
.loader-pill-wave:after {
  transform: scale(-1);
  animation-delay: 0.2s;
}
@keyframes l10 {
  0%,
  10% {margin-inline:0 33%}
  50% {margin-inline:0 0}
  90%,
  100%{margin-inline:33% 0}
}

/* 12. Morph Shapes (Forme che cambiano) */
.loader-morph-shapes {
  width: 75px;
  aspect-ratio: 1;
  display: grid;
}
.loader-morph-shapes:before,
.loader-morph-shapes:after {
  content: "";
  grid-area: 1/1;
  width: 35px;
  aspect-ratio: 1;
  box-shadow: 0 0 0 3px var(--text-main) inset;
  filter: drop-shadow(40px 40px 0 var(--text-main));
  animation: l8 2s infinite alternate;
}
.loader-morph-shapes:after {
  margin: 0 0 0 auto;
  filter: drop-shadow(-40px 40px 0 var(--text-main));
  animation-delay: -1s;
}
@keyframes l8 {
  0%,10%   {border-radius:0}
  30%,40%  {border-radius:50% 0}
  60%,70%  {border-radius:50%}
  90%,100% {border-radius:0 50%}
}

/* 13. Liquid DNA (Elica liquida) */
.loader-liquid-dna {
  display: inline-grid;
  padding: 5px;
  background: transparent;
  filter: blur(4px) contrast(12);
}
.loader-liquid-dna:before,
.loader-liquid-dna:after {
  content: "";
  grid-area: 1/1;
  height: 40px;
  aspect-ratio: 3;
  --c: #0000 64%,var(--text-main) 66% 98%,#0000 101%;
  background:
    radial-gradient(35% 146% at 50% 159%,var(--c)) 0 0,
    radial-gradient(35% 146% at 50% -59%,var(--c)) 100% 100%;
  background-size: calc(200%/3) 50%;
  background-repeat: repeat-x;
  clip-path: inset(0 100% 0 0);
  animation: l15 1.5s infinite linear;
}
.loader-liquid-dna:after {
  scale: -1 1;
}
@keyframes l15{
  50% {clip-path: inset(0)}
  to {clip-path: inset(0 0 0 100%)}
}

/* --- NUOVO: Loader con Calici di Vino --- */
#loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--primary-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999; /* Assicura che sia sopra tutto */
    transition: opacity 0.5s ease-out; /* Transizione per la scomparsa */
}

#loader-overlay.hidden {
    opacity: 0;
    visibility: hidden; /* Nasconde completamente l'elemento dopo la transizione */
}

/* --- Loader Generico (Spinner) --- */
.spinner {
    height: 50px;
    width: 50px;
    border: 4px solid var(--text-secondary);
    border-top: 4px solid var(--text-main);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Loader Calici (Wine) --- */
.wine-loader-container {
    width: 150px;
    height: 150px;
    position: relative;
    transform: scale(1.5);
}
.wineglass {
    height: 50px;
    width: 30px;
    border: 3px solid var(--glass-border);
    border-top: 0;
    border-radius: 50%;
    position: absolute;
    bottom: 0;
}
.wineglass::before {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: -10px;
    width: 3px;
    height: 10px;
    background-color: var(--glass-border);
}
.wineglass::after {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: -15px;
    width: 20px;
    height: 3px;
    background-color: var(--glass-border);
}
.wineglass.left {
    left: 30px;
    animation: tilting 1.5s 0.5s ease-in-out infinite;
}
.wineglass.right {
    right: 30px;
    animation: tilting 1.5s ease-in-out infinite;
}
.wineglass .top {
    background-color: var(--wine-liquid);
    width: 100%;
    height: 0;
    position: absolute;
    bottom: 0;
    border-radius: 50%;
    animation: pouring 1.5s 0.5s ease-in-out infinite;
}
.wineglass.right .top {
    animation-delay: 0s;
}
@keyframes tilting {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(25deg); }
    75% { transform: rotate(-15deg); }
}
@keyframes pouring {
    0%, 100% { height: 0; }
    50% { height: 100%; }
    90% { height: 90%; }
}

/* --- Loader Dots (Pallini) --- */
.dots-loader {
    display: flex;
    justify-content: center;
    align-items: center;
}
.dots-loader div {
    width: 15px;
    height: 15px;
    margin: 0 5px;
    background-color: var(--text-main);
    border-radius: 50%;
    animation: dots 0.6s infinite alternate;
}
.dots-loader div:nth-child(2) { animation-delay: 0.2s; }
.dots-loader div:nth-child(3) { animation-delay: 0.4s; }
@keyframes dots {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0.3; transform: scale(0.7); }
}