/**
 * Error Handling & User Feedback Styles
 * Provides consistent styling for loading states, success animations, and error messages
 * Includes testability attributes and state classes for automation
 */

/* Form State Classes - For Testability */
.tswc-state-idle {
    /* Default state */
}

.tswc-state-loading {
    pointer-events: none;
    opacity: 0.8;
}

.tswc-state-loading button,
.tswc-state-loading input[type="submit"] {
    cursor: wait;
}

.tswc-state-success {
    /* Success state styling */
}

.tswc-state-error {
    /* Error state styling */
}

.tswc-state-error input,
.tswc-state-error textarea,
.tswc-state-error select {
    border-color: #dc3545;
}

/* Container State Classes */
.tswc-container-loading {
    position: relative;
}

.tswc-container-success {
    /* Success container styling */
}

.tswc-container-error {
    /* Error container styling */
}

/* Testability Attributes - Visible States */
[data-tswc-visible="true"] {
    display: block;
}

[data-tswc-visible="false"] {
    display: none;
}

/* Testable Elements */
[data-tswc-testable="true"] {
    /* Elements marked for testing */
}

/* Loading Spinner */
.tswc-loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    text-align: center;
}

.tswc-spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #1F6066;
    border-radius: 50%;
    animation: tswc-spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes tswc-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.tswc-loading-text {
    margin-top: 15px;
    color: #666;
    font-size: 14px;
}

/* Success Animation */
.tswc-success-animation {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    text-align: center;
}

.tswc-checkmark {
    width: 60px;
    height: 60px;
    margin: 0 auto 15px;
}

.tswc-checkmark-svg {
    width: 100%;
    height: 100%;
}

.tswc-checkmark-circle {
    stroke: #1F6066;
    stroke-width: 2;
    stroke-dasharray: 166;
    stroke-dashoffset: 166;
    animation: tswc-stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.tswc-checkmark-check {
    stroke: #1F6066;
    stroke-width: 3;
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
    animation: tswc-stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}

@keyframes tswc-stroke {
    100% {
        stroke-dashoffset: 0;
    }
}

.tswc-success-message {
    color: #28a745;
    font-weight: 600;
    font-size: 16px;
    margin: 0;
}

/* Error Message */
.tswc-error-message {
    display: flex;
    align-items: flex-start;
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    border-left: 4px solid #dc3545;
    color: #721c24;
    padding: 15px;
    border-radius: 5px;
    margin: 15px 0;
}

.tswc-error-icon {
    font-size: 20px;
    margin-right: 10px;
    flex-shrink: 0;
}

.tswc-error-content {
    flex: 1;
}

.tswc-error-text {
    margin: 0 0 10px 0;
    line-height: 1.5;
}

.tswc-retry-button {
    background: #dc3545;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
}

.tswc-retry-button:hover {
    background: #c82333;
}

.tswc-retry-icon {
    display: inline-block;
    animation: tswc-rotate 2s linear infinite;
}

@keyframes tswc-rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Validation Feedback */
.tswc-validation-feedback {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 5px;
    font-size: 13px;
}

.tswc-validation-success {
    color: #28a745;
}

.tswc-validation-error {
    color: #dc3545;
}

.tswc-validation-icon {
    font-weight: bold;
}

.tswc-validation-message {
    line-height: 1.4;
}

/* Inline field validation */
.tswc-form-group {
    position: relative;
}

.tswc-form-group input:invalid,
.tswc-form-group textarea:invalid,
.tswc-form-group select:invalid {
    border-color: #dc3545;
}

.tswc-form-group input:valid:not(:placeholder-shown),
.tswc-form-group textarea:valid:not(:placeholder-shown),
.tswc-form-group select:valid {
    border-color: #28a745;
}

/* Offline Notice */
.tswc-offline-notice {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #ffc107;
    color: #856404;
    padding: 12px 20px;
    text-align: center;
    font-weight: 600;
    z-index: 9999;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Progress Bar */
.tswc-progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
    margin: 15px 0;
}

.tswc-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #1F6066 0%, #2a7a80 100%);
    border-radius: 4px;
    transition: width 0.3s ease;
    animation: tswc-progress-pulse 2s ease-in-out infinite;
}

@keyframes tswc-progress-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Button Loading State */
.tswc-button-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.tswc-button-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid #ffffff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: tswc-spin 0.6s linear infinite;
}

/* Success Confetti (optional) */
.tswc-confetti {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9998;
}

.tswc-confetti-piece {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #1F6066;
    animation: tswc-confetti-fall 3s ease-in forwards;
}

@keyframes tswc-confetti-fall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .tswc-error-message {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .tswc-error-icon {
        margin-bottom: 8px;
    }
    
    .tswc-retry-button {
        width: 100%;
        justify-content: center;
        margin-top: 10px;
    }
}

