/* ============================================
   LOADER ANIMADO PADRONIZADO
   ============================================ */

/* Loader SVG animado */
.btn-loader,
button .loader,
.loader {
    width: 20px;
    height: 20px;
    overflow: visible;
    transform: rotate(-90deg);
    transform-origin: center;
    --active: currentColor;
    --track: rgba(255, 255, 255, 0.3);
    --duration: 2s;
    animation: spin-loader 2s linear infinite;
    display: inline-block;
    vertical-align: middle;
    margin-right: 8px;
}

/* Loader em botões escuros */
.btn-primary .loader,
.btn-salvar .loader,
.btn-buscar-cep .loader {
    --active: #1a1a1a;
    --track: rgba(26, 26, 26, 0.2);
}

/* Loader em botões claros/brancos */
.btn-secondary .loader,
.btn-cancelar .loader {
    --active: #666;
    --track: rgba(102, 102, 102, 0.2);
}

/* Animação de rotação */
@keyframes spin-loader {
    0% {
        rotate: 0deg;
    }
    100% {
        rotate: 360deg;
    }
}

/* Círculo ativo (animado) */
.loader .active {
    stroke: var(--active);
    stroke-linecap: round;
    stroke-dashoffset: 360;
    animation: active-animation var(--duration) ease-in-out infinite;
}

/* Animação do círculo ativo */
@keyframes active-animation {
    0% {
        stroke-dasharray: 0 0 0 360 0 360;
    }
    12.5% {
        stroke-dasharray: 0 0 270 90 270 90;
    }
    25% {
        stroke-dasharray: 0 270 0 360 0 360;
    }
    37.5% {
        stroke-dasharray: 0 270 270 90 270 90;
    }
    50% {
        stroke-dasharray: 0 540 0 360 0 360;
    }
    50.001% {
        stroke-dasharray: 0 180 0 360 0 360;
    }
    62.5% {
        stroke-dasharray: 0 180 270 90 270 90;
    }
    75% {
        stroke-dasharray: 0 450 0 360 0 360;
    }
    87.5% {
        stroke-dasharray: 0 450 270 90 270 90;
    }
    87.501% {
        stroke-dasharray: 0 90 270 90 270 90;
    }
    100% {
        stroke-dasharray: 0 360 1 360 0 360;
    }
}

/* Círculo de fundo (track) */
.loader .track {
    stroke: var(--track);
    stroke-linecap: round;
    stroke-dashoffset: 360;
    animation: track-animation var(--duration) ease-in-out infinite;
}

/* Animação do círculo de fundo */
@keyframes track-animation {
    0% {
        stroke-dasharray: 0 0 0 360 0 360;
    }
    12.5% {
        stroke-dasharray: 0 0 270 90 270 90;
    }
    25% {
        stroke-dasharray: 0 270 0 360 0 360;
    }
    37.5% {
        stroke-dasharray: 0 270 270 90 270 90;
    }
    50% {
        stroke-dasharray: 0 540 0 360 0 360;
    }
    50.001% {
        stroke-dasharray: 0 180 0 360 0 360;
    }
    62.5% {
        stroke-dasharray: 0 180 270 90 270 90;
    }
    75% {
        stroke-dasharray: 0 450 0 360 0 360;
    }
    87.5% {
        stroke-dasharray: 0 450 270 90 270 90;
    }
    87.501% {
        stroke-dasharray: 0 90 270 90 270 90;
    }
    100% {
        stroke-dasharray: 0 360 1 360 0 360;
    }
}

/* Botões com loader - garantir alinhamento */
button:disabled .loader,
.btn-loading .loader {
    display: inline-block;
}

/* Texto ao lado do loader */
button .loader + span,
.loader + span {
    vertical-align: middle;
}
