/* Botón oculto para vaciar inputs/textareas — animación de disolución */
.input-clear-wrap,
.input-clear-host {
    position: relative;
}

.input-clear-wrap > textarea,
.input-clear-wrap > input[type="text"],
.input-clear-wrap > input[type="search"],
.input-clear-wrap > input:not([type]),
.input-clear-host > .search-input,
.input-clear-host > input[type="text"],
.input-clear-host > input[type="search"],
.input-clear-host > input:not([type]) {
    padding-right: 2.35rem;
    transition: box-shadow 0.35s ease, border-color 0.35s ease;
}

/* Zona fija: captura el ratón aunque el botón esté invisible (evita fall-through al textarea) */
.input-clear-slot {
    position: absolute;
    top: 0.35rem;
    right: 0.2rem;
    z-index: 5;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

.input-clear-host .input-clear-slot {
    top: 50%;
    margin-top: -1rem;
}

.input-clear-wrap.has-value .input-clear-slot,
.input-clear-host.has-value .input-clear-slot {
    pointer-events: auto;
}

/* —— Botón clear —— */
.input-clear-btn {
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.07);
    color: var(--neo-muted, rgba(230, 233, 242, 0.5));
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.62rem;
    line-height: 1;
    opacity: 0;
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
    transition:
        opacity 0.18s ease,
        background 0.15s ease,
        color 0.15s ease,
        box-shadow 0.15s ease;
    box-shadow: none;
}

/* Mostrar: ratón en campo, foco en input, o ratón en la zona del botón */
.input-clear-wrap.has-value:hover .input-clear-btn,
.input-clear-wrap.has-value:focus-within .input-clear-btn,
.input-clear-host.has-value:hover .input-clear-btn,
.input-clear-host.has-value:focus-within .input-clear-btn,
.input-clear-wrap.has-value .input-clear-slot:hover .input-clear-btn,
.input-clear-host.has-value .input-clear-slot:hover .input-clear-btn,
.input-clear-btn:focus-visible {
    opacity: 1;
}

.input-clear-btn:hover {
    background: rgba(239, 68, 68, 0.22);
    color: #fca5a5;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.14);
}

.input-clear-btn:focus-visible {
    outline: 2px solid var(--neo-primary, #7c3aed);
    outline-offset: 2px;
    opacity: 1;
}

.input-clear-btn.is-activating {
    pointer-events: none;
    animation: inputClearBtnFadeOut 0.52s ease forwards;
}

.input-clear-btn.is-activating i {
    animation: inputClearBtnIconSpin 0.52s cubic-bezier(0.34, 1.25, 0.64, 1) forwards;
}

@keyframes inputClearBtnFadeOut {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes inputClearBtnIconSpin {
    0% { transform: rotate(0deg) scale(1); }
    40% { transform: rotate(-120deg) scale(0.9); }
    100% { transform: rotate(-200deg) scale(0); }
}

/* —— Capa de efectos sobre el input —— */
.input-clear-fx {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    pointer-events: none;
    border-radius: inherit;
    overflow: hidden;
    opacity: 0;
}

.input-clear-wrap.is-clearing .input-clear-fx,
.input-clear-host.is-clearing .input-clear-fx {
    opacity: 1;
    display: block;
}

.input-clear-wrap:not(.is-clearing) .input-clear-fx,
.input-clear-host:not(.is-clearing) .input-clear-fx {
    display: none;
}

.input-clear-fx::before {
    content: '';
    position: absolute;
    inset: -20% -40%;
    background: linear-gradient(
        105deg,
        transparent 0%,
        transparent 38%,
        rgba(124, 58, 237, 0.08) 44%,
        rgba(255, 255, 255, 0.22) 50%,
        rgba(34, 211, 238, 0.1) 56%,
        transparent 62%,
        transparent 100%
    );
    transform: translateX(-120%) skewX(-12deg);
    animation: inputClearSweep 0.48s cubic-bezier(0.4, 0, 0.15, 1) forwards;
}

.input-clear-fx::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    border: 1px solid rgba(124, 58, 237, 0.45);
    box-shadow:
        inset 0 0 18px rgba(124, 58, 237, 0.12),
        0 0 0 0 rgba(124, 58, 237, 0.35);
    opacity: 0;
    animation: inputClearRing 0.52s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    animation-delay: 0.08s;
}

@keyframes inputClearSweep {
    0% { transform: translateX(-120%) skewX(-12deg); }
    100% { transform: translateX(120%) skewX(-12deg); }
}

@keyframes inputClearRing {
    0% {
        opacity: 0;
        box-shadow: inset 0 0 0 rgba(124, 58, 237, 0), 0 0 0 0 rgba(124, 58, 237, 0.4);
    }
    30% {
        opacity: 1;
        box-shadow: inset 0 0 24px rgba(124, 58, 237, 0.15), 0 0 0 4px rgba(124, 58, 237, 0.25);
    }
    100% {
        opacity: 0;
        box-shadow: inset 0 0 0 rgba(124, 58, 237, 0), 0 0 0 10px rgba(124, 58, 237, 0);
    }
}

/* Disolución del texto */
.input-clear-wrap.is-clearing > textarea,
.input-clear-wrap.is-clearing > input,
.input-clear-host.is-clearing > .search-input,
.input-clear-host.is-clearing > input[type="text"],
.input-clear-host.is-clearing > input[type="search"],
.input-clear-host.is-clearing > input:not([type]) {
    animation: inputClearDissolve 0.48s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    pointer-events: none;
}

@keyframes inputClearDissolve {
    0% {
        opacity: 1;
        filter: blur(0) brightness(1);
        transform: translateY(0) scale(1);
        letter-spacing: normal;
    }
    25% {
        opacity: 0.85;
        filter: blur(1px) brightness(1.08);
        transform: translateY(-2px) scale(1.002);
    }
    55% {
        opacity: 0.35;
        filter: blur(4px) brightness(1.15);
        transform: translateY(-6px) scale(0.985);
        letter-spacing: 0.04em;
    }
    100% {
        opacity: 0;
        filter: blur(10px) brightness(1.3);
        transform: translateY(-10px) scale(0.97);
        letter-spacing: 0.08em;
    }
}

.input-clear-settled {
    animation: inputClearSettled 0.55s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes inputClearSettled {
    0% {
        box-shadow: 0 0 0 0 rgba(124, 58, 237, 0.35);
        border-color: rgba(124, 58, 237, 0.5);
    }
    40% {
        box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.12);
        border-color: rgba(124, 58, 237, 0.35);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(124, 58, 237, 0);
        border-color: inherit;
    }
}

/* Partículas */
.input-clear-particles {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    pointer-events: none;
}

.input-clear-particles span {
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 4px;
    margin: -2px 0 0 -2px;
    border-radius: 50%;
    opacity: 0;
    background: var(--neo-primary, #7c3aed);
    box-shadow: 0 0 6px rgba(124, 58, 237, 0.6);
}

.input-clear-particles.is-active span {
    animation: inputClearParticle 0.55s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.input-clear-particles span:nth-child(1) { animation-delay: 0.02s; background: #7c3aed; --input-clear-angle: -70deg; --input-clear-dist: 22px; }
.input-clear-particles span:nth-child(2) { animation-delay: 0.05s; background: #22d3ee; box-shadow: 0 0 6px rgba(34, 211, 238, 0.6); --input-clear-angle: -20deg; --input-clear-dist: 28px; }
.input-clear-particles span:nth-child(3) { animation-delay: 0.08s; background: #fca5a5; box-shadow: 0 0 6px rgba(248, 113, 113, 0.6); --input-clear-angle: 30deg; --input-clear-dist: 24px; }
.input-clear-particles span:nth-child(4) { animation-delay: 0.04s; background: #a78bfa; --input-clear-angle: 80deg; --input-clear-dist: 20px; }
.input-clear-particles span:nth-child(5) { animation-delay: 0.1s; background: #22d3ee; --input-clear-angle: 130deg; --input-clear-dist: 26px; }
.input-clear-particles span:nth-child(6) { animation-delay: 0.06s; background: #7c3aed; --input-clear-angle: 200deg; --input-clear-dist: 22px; }

@keyframes inputClearParticle {
    0% {
        opacity: 1;
        transform: rotate(var(--input-clear-angle, 0deg)) translateX(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: rotate(var(--input-clear-angle, 0deg)) translateX(var(--input-clear-dist, 20px)) scale(0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .input-clear-btn {
        transition: opacity 0.12s ease;
    }

    .input-clear-btn.is-activating,
    .input-clear-btn.is-activating i {
        animation: none;
        opacity: 0;
    }

    .input-clear-wrap.is-clearing > textarea,
    .input-clear-wrap.is-clearing > input,
    .input-clear-host.is-clearing > .search-input,
    .input-clear-host.is-clearing > input {
        animation: inputClearDissolveReduced 0.12s ease forwards;
    }

    @keyframes inputClearDissolveReduced {
        to { opacity: 0; }
    }

    .input-clear-fx::before,
    .input-clear-fx::after {
        animation: none;
        display: none;
    }

    .input-clear-particles {
        display: none;
    }

    .input-clear-settled {
        animation: none;
    }
}
