/**
 * Quote Builder Phase 3 CSS
 * Advanced features: validation, loading, toasts, mobile, accessibility
 */

/* =================================
   VALIDATION STYLES
   ================================= */

/* Input validation states */
.form-control.is-invalid {
    border-color: #dc3545;
    padding-right: calc(1.5em + 0.75rem);
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.form-control.is-valid {
    border-color: #28a745;
    padding-right: calc(1.5em + 0.75rem);
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

/* Validation icons */
.validation-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    z-index: 10;
}

.validation-icon-valid {
    color: #28a745;
}

.validation-icon-invalid {
    color: #dc3545;
}

/* Error feedback messages */
.invalid-feedback {
    display: none;
    width: 100%;
    margin-top: 0.25rem;
    font-size: 0.875em;
    color: #dc3545;
}

.form-control.is-invalid ~ .invalid-feedback {
    display: block;
}

/* Inline error/success messages */
.inline-error, .inline-success {
    margin-top: 5px;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: slideIn 0.3s ease;
}

.inline-error {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

.inline-success {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

/* =================================
   LOADING OVERLAY
   ================================= */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(3px);
}

.loading-content {
    text-align: center;
    color: white;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    font-size: 18px;
    margin-bottom: 20px;
    font-weight: 500;
}

/* Progress bar */
.loading-progress {
    width: 200px;
    margin: 0 auto;
}

.progress-bar {
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-fill {
    height: 100%;
    background: #4169E1;
    width: 0;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 14px;
    opacity: 0.8;
}

/* =================================
   TOAST NOTIFICATIONS
   ================================= */

.toast-container {
    position: fixed;
    z-index: 10000;
    pointer-events: none;
}

.toast-container.toast-bottom-right {
    bottom: 20px;
    right: 20px;
}

.toast-container.toast-top-right {
    top: 80px;
    right: 20px;
}

.toast-container.toast-bottom-left {
    bottom: 20px;
    left: 20px;
}

.toast {
    background: #333;
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateX(400px);
    transition: transform 0.3s ease;
    max-width: 350px;
    pointer-events: auto;
}

.toast.show {
    transform: translateX(0);
}

.toast-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toast-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
    font-size: 14px;
    line-height: 1.4;
}

.toast-close {
    background: none;
    border: none;
    color: white;
    opacity: 0.7;
    cursor: pointer;
    padding: 0;
    margin-left: 12px;
    font-size: 16px;
}

.toast-close:hover {
    opacity: 1;
}

/* Toast types */
.toast-success {
    background: #28a745;
}

.toast-error {
    background: #dc3545;
}

.toast-warning {
    background: #ffc107;
    color: #333;
}

.toast-warning .toast-close {
    color: #333;
}

.toast-info {
    background: #17a2b8;
}

/* =================================
   UNSAVED INDICATOR
   ================================= */

.unsaved-indicator {
    position: fixed;
    top: 70px;
    right: 20px;
    background: #ffc107;
    color: #333;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    display: none;
    align-items: center;
    gap: 8px;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.unsaved-indicator.show {
    display: flex;
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background: #dc3545;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(1.2);
    }
}

/* =================================
   CONFIRMATION MODAL
   ================================= */

.confirm-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10001;
    animation: fadeIn 0.2s ease;
}

.confirm-modal {
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    max-width: 400px;
    width: 90%;
    animation: slideUp 0.3s ease;
}

.confirm-header {
    padding: 20px;
    border-bottom: 1px solid #e9ecef;
}

.confirm-header h3 {
    margin: 0;
    font-size: 20px;
    color: #333;
}

.confirm-body {
    padding: 20px;
}

.confirm-body p {
    margin: 0;
    color: #666;
    line-height: 1.5;
}

.confirm-footer {
    padding: 15px 20px;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* =================================
   PROGRESS STEPS
   ================================= */

.progress-steps {
    display: flex;
    justify-content: space-between;
    margin: 30px 0;
    padding: 0 20px;
    position: relative;
}

.progress-steps::before {
    content: '';
    position: absolute;
    top: 20px;
    left: 10%;
    right: 10%;
    height: 2px;
    background: #e9ecef;
    z-index: -1;
}

.progress-step {
    text-align: center;
    flex: 1;
    position: relative;
}

.step-number {
    width: 40px;
    height: 40px;
    background: #e9ecef;
    color: #999;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 8px;
    font-weight: bold;
    transition: all 0.3s ease;
}

.step-label {
    font-size: 13px;
    color: #999;
}

.progress-step.active .step-number {
    background: #4169E1;
    color: white;
    transform: scale(1.1);
}

.progress-step.active .step-label {
    color: #4169E1;
    font-weight: 600;
}

.progress-step.completed .step-number {
    background: #28a745;
    color: white;
}

.progress-step.completed .step-label {
    color: #28a745;
}

/* =================================
   MOBILE RESPONSIVE
   ================================= */

@media (max-width: 768px) {
    /* Form adjustments */
    .form-row {
        flex-direction: column;
    }
    
    .form-group.col-md-4,
    .form-group.col-md-6,
    .form-group.col-md-8 {
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
    }
    
    /* Larger touch targets */
    .btn {
        min-height: 44px;
        padding: 12px 20px;
        font-size: 16px;
        width: 100%;
        margin-bottom: 10px;
    }
    
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 44px;
        padding: 10px 12px;
    }
    
    /* Table responsiveness */
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        min-width: 600px;
    }
    
    /* Modal adjustments */
    .modal-dialog {
        margin: 10px;
        max-width: calc(100% - 20px);
    }
    
    .modal-footer {
        flex-direction: column;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 5px 0;
    }
    
    /* Toast adjustments */
    .toast-container {
        left: 10px;
        right: 10px;
    }
    
    .toast {
        max-width: 100%;
        margin: 0 10px 10px;
    }
    
    /* Progress steps mobile */
    .progress-steps {
        padding: 0 10px;
    }
    
    .step-label {
        font-size: 11px;
    }
    
    .step-number {
        width: 35px;
        height: 35px;
        font-size: 14px;
    }
    
    /* Loading overlay mobile */
    .loading-spinner {
        width: 50px;
        height: 50px;
    }
    
    .loading-text {
        font-size: 16px;
    }
    
    /* Unsaved indicator mobile */
    .unsaved-indicator {
        top: auto;
        bottom: 20px;
        right: 10px;
        left: 10px;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    /* Even smaller screens */
    h1 { font-size: 24px; }
    h2 { font-size: 20px; }
    h3 { font-size: 18px; }
    
    .container {
        padding: 10px;
    }
    
    /* Stack everything vertically */
    .row {
        margin: 0;
    }
    
    .col, [class*="col-"] {
        padding: 0;
    }
    
    /* Progress steps very small screens */
    .progress-steps {
        flex-direction: column;
        align-items: center;
    }
    
    .progress-steps::before {
        display: none;
    }
    
    .progress-step {
        margin-bottom: 20px;
    }
}

/* =================================
   ACCESSIBILITY
   ================================= */

/* Skip to content link */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: #003f7f;
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 100;
    border-radius: 0 0 4px 0;
}

.skip-to-content:focus {
    top: 0;
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

/* Focus indicators */
*:focus {
    outline: 2px solid #4169E1;
    outline-offset: 2px;
}

button:focus,
a:focus {
    outline: 2px solid #4169E1;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn-primary {
        border: 2px solid currentColor;
    }
    
    .form-control {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .loading-overlay {
        background: rgba(0, 0, 0, 0.9);
    }
    
    .confirm-modal {
        background: #2d2d2d;
        color: #fff;
    }
    
    .confirm-header h3,
    .confirm-body p {
        color: #fff;
    }
    
    .confirm-header,
    .confirm-footer {
        border-color: #444;
    }
}

/* =================================
   ANIMATIONS
   ================================= */

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        transform: translateY(-10px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Attention pulse */
.pulse-attention {
    animation: pulseAttention 2s ease;
}

@keyframes pulseAttention {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(65, 105, 225, 0);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(65, 105, 225, 0.3);
    }
}

/* =================================
   UTILITY CLASSES
   ================================= */

.text-muted {
    color: #6c757d;
}

.text-danger {
    color: #dc3545;
}

.text-success {
    color: #28a745;
}

.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }

.d-none { display: none; }
.d-block { display: block; }
.d-flex { display: flex; }

.justify-content-center { justify-content: center; }
.align-items-center { align-items: center; }

.w-100 { width: 100%; }
.h-100 { height: 100%; }