/**
 * Quote Builder Common Styles
 * Shared styles for all NWCA quote builders
 * Includes: Loading states, toasts, validation, mobile responsive
 */

/* ============================================
   LOADING OVERLAY
   ============================================ */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(2px);
}

.loading-content {
    text-align: center;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    margin: 0 auto 20px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-top: 5px solid #003f7f;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    color: white;
    font-size: 18px;
    font-weight: 500;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */

.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    pointer-events: none;
}

.toast {
    min-width: 250px;
    max-width: 350px;
    padding: 15px 20px;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transform: translateX(400px);
    transition: transform 0.3s ease, opacity 0.3s ease;
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: all;
}

.toast.show {
    transform: translateX(0);
}

.toast-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
    line-height: 1.4;
}

.toast-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    opacity: 0.7;
    padding: 0;
    margin-left: 10px;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

.toast-close:hover {
    opacity: 1;
}

/* Toast Types */
.toast-success {
    background: linear-gradient(135deg, #28a745 0%, #20c24c 100%);
}

.toast-error {
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
}

.toast-info {
    background: linear-gradient(135deg, #17a2b8 0%, #138496 100%);
}

.toast-warning {
    background: linear-gradient(135deg, #ffc107 0%, #e0a800 100%);
    color: #333;
}

.toast-warning .toast-close {
    color: #333;
}

/* ============================================
   UNSAVED CHANGES INDICATOR
   ============================================ */

.unsaved-indicator {
    position: fixed;
    top: 70px;
    right: 20px;
    background: linear-gradient(135deg, #ffc107 0%, #ffb300 100%);
    color: #333;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    display: none;
    align-items: center;
    gap: 8px;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.unsaved-indicator.show {
    display: flex;
}

.unsaved-indicator::before {
    content: '●';
    animation: pulse 2s infinite;
    color: #d39e00;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ============================================
   FORM VALIDATION STYLES
   ============================================ */

.form-control.is-invalid {
    border-color: #dc3545 !important;
    padding-right: calc(1.5em + 0.75rem);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23dc3545' viewBox='0 0 12 12'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
    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);
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

.form-control.is-valid {
    border-color: #28a745 !important;
    padding-right: calc(1.5em + 0.75rem);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3e%3cpath fill='%2328a745' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e");
    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);
}

.invalid-feedback {
    display: none;
    width: 100%;
    margin-top: 0.25rem;
    font-size: 0.875em;
    color: #dc3545;
    animation: shake 0.3s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.form-control.is-invalid ~ .invalid-feedback {
    display: block;
}

/* Required field indicator */
label.required::after {
    content: ' *';
    color: #dc3545;
    font-weight: bold;
}

/* ============================================
   ERROR & SUCCESS MESSAGES
   ============================================ */

.error-message {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
    padding: 12px 16px;
    border-radius: 6px;
    margin: 10px 0;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideDown 0.3s ease;
}

.success-message {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
    padding: 12px 16px;
    border-radius: 6px;
    margin: 10px 0;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideDown 0.3s ease;
}

.warning-message {
    background: #fff3cd;
    border: 1px solid #ffeeba;
    color: #856404;
    padding: 12px 16px;
    border-radius: 6px;
    margin: 10px 0;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-10px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ============================================
   PROGRESS STEPS
   ============================================ */

.progress-steps {
    display: flex;
    justify-content: space-between;
    margin-bottom: 30px;
    padding: 0;
    list-style: none;
}

.progress-step {
    flex: 1;
    text-align: center;
    position: relative;
    padding: 10px;
    color: #6c757d;
    font-weight: 500;
}

.progress-step::before {
    content: attr(data-step);
    display: block;
    width: 30px;
    height: 30px;
    margin: 0 auto 10px;
    background: #e9ecef;
    border-radius: 50%;
    line-height: 30px;
    font-weight: bold;
}

.progress-step.active {
    color: #003f7f;
}

.progress-step.active::before {
    background: #003f7f;
    color: white;
}

.progress-step.completed {
    color: #28a745;
}

.progress-step.completed::before {
    background: #28a745;
    color: white;
    content: '✓';
}

/* Progress line connector */
.progress-step:not(:last-child)::after {
    content: '';
    position: absolute;
    top: 15px;
    left: 50%;
    width: 100%;
    height: 2px;
    background: #e9ecef;
    z-index: -1;
}

.progress-step.completed:not(:last-child)::after {
    background: #28a745;
}

/* ============================================
   ACCESSIBILITY HELPERS
   ============================================ */

/* 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;
}

/* 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;
}

/* Focus indicators */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
    outline: 2px solid #4169E1;
    outline-offset: 2px;
}

/* ============================================
   DISABLED STATES
   ============================================ */

.btn:disabled,
.form-control:disabled,
button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #e9ecef;
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    /* Make forms stack vertically */
    .form-row {
        flex-direction: column;
    }
    
    .form-group {
        width: 100%;
        margin-bottom: 15px;
    }
    
    .col-md-4,
    .col-md-6,
    .col-md-8 {
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
    }
    
    /* Responsive tables */
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .items-table {
        font-size: 14px;
        min-width: 600px;
    }
    
    .items-table td,
    .items-table th {
        padding: 8px 5px;
        font-size: 13px;
    }
    
    /* Larger touch targets */
    .btn {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 20px;
        font-size: 16px;
    }
    
    input,
    select,
    textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 44px;
        padding: 10px;
    }
    
    /* Stack modal buttons */
    .modal-footer {
        flex-direction: column;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 5px 0;
    }
    
    /* Adjust toast position */
    .toast-container {
        left: 10px;
        right: 10px;
        bottom: 10px;
    }
    
    .toast {
        max-width: 100%;
    }
    
    /* Adjust unsaved indicator */
    .unsaved-indicator {
        top: auto;
        bottom: 60px;
        right: 10px;
        font-size: 12px;
        padding: 6px 12px;
    }
    
    /* Progress steps mobile */
    .progress-steps {
        font-size: 12px;
    }
    
    .progress-step {
        padding: 5px;
    }
    
    .progress-step::before {
        width: 25px;
        height: 25px;
        line-height: 25px;
        font-size: 12px;
    }
    
    /* Hide less important columns on mobile */
    .hide-mobile {
        display: none;
    }
}

@media (max-width: 480px) {
    /* Even smaller screens */
    h1 { font-size: 24px; }
    h2 { font-size: 20px; }
    h3 { font-size: 18px; }
    
    .quote-header {
        flex-direction: column;
        text-align: center;
    }
    
    .company-logo {
        max-width: 150px;
        margin: 0 auto;
    }
    
    /* Stack everything vertically */
    .quote-meta {
        flex-direction: column;
    }
    
    /* Simplify tables on very small screens */
    .items-table {
        font-size: 12px;
    }
    
    .items-table td,
    .items-table th {
        padding: 5px 3px;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

/* Spacing */
.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: 0.25rem !important; }
.mt-2 { margin-top: 0.5rem !important; }
.mt-3 { margin-top: 1rem !important; }
.mt-4 { margin-top: 1.5rem !important; }
.mt-5 { margin-top: 3rem !important; }

.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 0.25rem !important; }
.mb-2 { margin-bottom: 0.5rem !important; }
.mb-3 { margin-bottom: 1rem !important; }
.mb-4 { margin-bottom: 1.5rem !important; }
.mb-5 { margin-bottom: 3rem !important; }

/* Text alignment */
.text-left { text-align: left !important; }
.text-center { text-align: center !important; }
.text-right { text-align: right !important; }

/* Display */
.d-none { display: none !important; }
.d-block { display: block !important; }
.d-inline { display: inline !important; }
.d-inline-block { display: inline-block !important; }
.d-flex { display: flex !important; }

/* Flexbox */
.justify-content-center { justify-content: center !important; }
.justify-content-between { justify-content: space-between !important; }
.align-items-center { align-items: center !important; }
.flex-column { flex-direction: column !important; }
.flex-wrap { flex-wrap: wrap !important; }

/* Colors */
.text-primary { color: #003f7f !important; }
.text-success { color: #28a745 !important; }
.text-danger { color: #dc3545 !important; }
.text-warning { color: #ffc107 !important; }
.text-info { color: #17a2b8 !important; }
.text-muted { color: #6c757d !important; }

.bg-primary { background-color: #003f7f !important; }
.bg-success { background-color: #28a745 !important; }
.bg-danger { background-color: #dc3545 !important; }
.bg-warning { background-color: #ffc107 !important; }
.bg-info { background-color: #17a2b8 !important; }
.bg-light { background-color: #f8f9fa !important; }
.bg-dark { background-color: #343a40 !important; }

/* Borders */
.border { border: 1px solid #dee2e6 !important; }
.border-0 { border: 0 !important; }
.border-top { border-top: 1px solid #dee2e6 !important; }
.border-bottom { border-bottom: 1px solid #dee2e6 !important; }
.border-primary { border-color: #003f7f !important; }
.border-success { border-color: #28a745 !important; }
.border-danger { border-color: #dc3545 !important; }

.rounded { border-radius: 0.25rem !important; }
.rounded-0 { border-radius: 0 !important; }

/* Shadows */
.shadow-sm { box-shadow: 0 0.125rem 0.25rem rgba(0,0,0,0.075) !important; }
.shadow { box-shadow: 0 0.5rem 1rem rgba(0,0,0,0.15) !important; }
.shadow-lg { box-shadow: 0 1rem 3rem rgba(0,0,0,0.175) !important; }

/* ============================================
   ANIMATIONS
   ============================================ */

.fade-in {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.slide-up {
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ============================================
   PRINT MEDIA QUERY
   ============================================ */

@media print {
    /* Hide UI elements during print */
    .no-print,
    .btn,
    .modal,
    .toast-container,
    .unsaved-indicator,
    .loading-overlay,
    .skip-to-content,
    .progress-steps,
    button,
    .header-nav,
    .footer {
        display: none !important;
    }
    
    /* Reset backgrounds */
    body {
        background: white;
    }
    
    /* Ensure text is black */
    * {
        color: black !important;
    }
    
    /* Show print-only elements */
    .print-only {
        display: block !important;
    }
}