/* Animated Submit Button - RetailReady
   Reusable button with loading spinner and success states

   Usage:
   1. Add class "animated-submit-btn" to your button
   2. Include the required HTML structure (see below)
   3. Include animated-button.js for form handling

   HTML Structure:
   <button type="submit" class="animated-submit-btn" id="your-btn-id">
       <span class="btn-text">Button Text</span>
       <span class="btn-spinner">
           <svg class="spinner-circle" viewBox="0 0 100 100">
               <circle cx="50" cy="50" r="45" fill="#6366f1"/>
           </svg>
           <svg class="spinner-check" viewBox="0 0 100 100">
               <path d="M25 52 L42 70 L75 32" stroke="white" stroke-width="8" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
           </svg>
       </span>
       <span class="btn-success">
           <svg class="success-circle" viewBox="0 0 100 100">
               <circle cx="50" cy="50" r="45" fill="#10b981"/>
           </svg>
           <svg class="success-check" viewBox="0 0 100 100">
               <path class="check-path" d="M25 52 L42 70 L75 32" stroke="white" stroke-width="10" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
           </svg>
       </span>
   </button>
*/

/* Base button styles */
.animated-submit-btn {
    height: 48px;
    width: 100%;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    background: #14b8a6;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
    box-shadow: 0 0 20px -5px rgba(20, 184, 166, 0.4);
}

.animated-submit-btn:hover:not(.loading):not(.success) {
    background: #0d9488;
    transform: translateY(-1px);
    box-shadow: 0 0 25px -3px rgba(20, 184, 166, 0.5);
}

.animated-submit-btn:active:not(.loading):not(.success) {
    transform: translateY(0);
}

.animated-submit-btn:focus {
    outline: 2px solid #14b8a6;
    outline-offset: 2px;
}

.animated-submit-btn:focus:not(:focus-visible) {
    outline: none;
}

/* Button content layers */
.animated-submit-btn .btn-text,
.animated-submit-btn .btn-spinner,
.animated-submit-btn .btn-success {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.animated-submit-btn .btn-text {
    opacity: 1;
}

.animated-submit-btn .btn-spinner,
.animated-submit-btn .btn-success {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    width: 32px;
    height: 32px;
}

.animated-submit-btn .btn-spinner svg,
.animated-submit-btn .btn-success svg {
    width: 100%;
    height: 100%;
}

.animated-submit-btn .btn-spinner .spinner-circle,
.animated-submit-btn .btn-spinner .spinner-check {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* 3D perspective for spinner */
.animated-submit-btn .btn-spinner {
    perspective: 200px;
}

.animated-submit-btn .btn-spinner svg {
    transform-style: preserve-3d;
}

/* Loading state */
.animated-submit-btn.loading {
    background: #14b8a6;
    cursor: wait;
    pointer-events: none;
}

.animated-submit-btn.loading .btn-text {
    opacity: 0;
}

.animated-submit-btn.loading .btn-spinner {
    opacity: 1;
}

.animated-submit-btn.loading .spinner-circle {
    animation: animated-btn-spin-cw 2s linear infinite;
}

.animated-submit-btn.loading .spinner-check {
    animation: animated-btn-spin-ccw 1s linear infinite;
}

/* Success state */
.animated-submit-btn.success {
    background: #10b981;
    cursor: default;
    pointer-events: none;
    box-shadow: 0 0 30px 0 rgba(16, 185, 129, 0.6);
    animation: animated-btn-success-glow 1s ease-in-out;
}

.animated-submit-btn.success .btn-text,
.animated-submit-btn.success .btn-spinner {
    opacity: 0;
}

.animated-submit-btn.success .btn-success {
    opacity: 1;
    width: 40px;
    height: 40px;
    animation: animated-btn-success-pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.animated-submit-btn.success .btn-success .success-circle,
.animated-submit-btn.success .btn-success .success-check {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.animated-submit-btn.success .btn-success .success-circle {
    animation: animated-btn-circle-pop 0.4s ease-out forwards;
}

.animated-submit-btn.success .btn-success .check-path {
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    animation: animated-btn-draw-check 0.4s ease-out 0.2s forwards;
}

/* Error state */
.animated-submit-btn.error {
    background: #ef4444;
    animation: animated-btn-shake 0.5s ease-in-out;
}

/* Keyframe animations */
@keyframes animated-btn-spin-cw {
    from { transform: rotateY(0deg); }
    to { transform: rotateY(360deg); }
}

@keyframes animated-btn-spin-ccw {
    from { transform: rotateY(0deg); }
    to { transform: rotateY(-360deg); }
}

@keyframes animated-btn-success-pop {
    0% { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
    50% { transform: translate(-50%, -50%) scale(1.15); }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@keyframes animated-btn-circle-pop {
    0% { transform: scale(0.5); opacity: 0; }
    60% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes animated-btn-draw-check {
    to { stroke-dashoffset: 0; }
}

@keyframes animated-btn-success-glow {
    0% { box-shadow: 0 0 20px 0 rgba(16, 185, 129, 0.4); }
    50% { box-shadow: 0 0 40px 5px rgba(16, 185, 129, 0.7); }
    100% { box-shadow: 0 0 30px 0 rgba(16, 185, 129, 0.5); }
}

@keyframes animated-btn-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

/* Auto width variant (for inline/flex contexts) */
.animated-submit-btn.btn-auto {
    width: auto;
    padding: 0 24px;
}

/* Size variants */
.animated-submit-btn.btn-sm {
    height: 40px;
    font-size: 0.875rem;
}

.animated-submit-btn.btn-sm .btn-spinner,
.animated-submit-btn.btn-sm .btn-success {
    width: 24px;
    height: 24px;
}

.animated-submit-btn.btn-sm.success .btn-success {
    width: 30px;
    height: 30px;
}

.animated-submit-btn.btn-lg {
    height: 56px;
    font-size: 1.125rem;
}

.animated-submit-btn.btn-lg .btn-spinner,
.animated-submit-btn.btn-lg .btn-success {
    width: 36px;
    height: 36px;
}

.animated-submit-btn.btn-lg.success .btn-success {
    width: 44px;
    height: 44px;
}

/* Color variants */
.animated-submit-btn.btn-secondary {
    background: #8b5cf6;
    box-shadow: 0 0 20px -5px rgba(139, 92, 246, 0.4);
}

.animated-submit-btn.btn-secondary:hover:not(.loading):not(.success) {
    background: #7c3aed;
    box-shadow: 0 0 25px -3px rgba(139, 92, 246, 0.5);
}

.animated-submit-btn.btn-secondary:focus {
    outline-color: #8b5cf6;
}

.animated-submit-btn.btn-danger {
    background: #ef4444;
    box-shadow: 0 0 20px -5px rgba(239, 68, 68, 0.4);
}

.animated-submit-btn.btn-danger:hover:not(.loading):not(.success) {
    background: #dc2626;
    box-shadow: 0 0 25px -3px rgba(239, 68, 68, 0.5);
}

.animated-submit-btn.btn-danger:focus {
    outline-color: #ef4444;
}

/* Next step variant - arrow instead of checkmark for multi-step flows */
.animated-submit-btn.btn-next.success {
    background: #14b8a6; /* Keep teal instead of green */
    box-shadow: 0 0 30px 0 rgba(20, 184, 166, 0.6);
    animation: animated-btn-next-glow 0.8s ease-in-out;
}

.animated-submit-btn.btn-next.success .btn-success .success-circle {
    fill: #14b8a6;
}

.animated-submit-btn.btn-next.success .btn-success .arrow-path {
    stroke-dasharray: 60;
    stroke-dashoffset: 60;
    animation: animated-btn-draw-arrow 0.3s ease-out 0.15s forwards;
}

@keyframes animated-btn-next-glow {
    0% { box-shadow: 0 0 20px 0 rgba(20, 184, 166, 0.4); }
    50% { box-shadow: 0 0 40px 5px rgba(20, 184, 166, 0.7); }
    100% { box-shadow: 0 0 30px 0 rgba(20, 184, 166, 0.5); }
}

@keyframes animated-btn-draw-arrow {
    to { stroke-dashoffset: 0; }
}
