/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Design System Colors */
    --primary: #667eea;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --text: #1f2937;
    --light-gray: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --border-color: #e2e8f0;
    
    /* Spacing (8px base unit) */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    --spacing-2xl: 40px;
    --spacing-3xl: 48px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text);
    background: linear-gradient(to bottom, var(--light-gray), var(--gray-200));
    min-height: 100vh;
    padding: var(--spacing-2xl) var(--spacing-md);
}

/* Container */
.container {
    max-width: 700px;
    margin: 0 auto;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05), 0 10px 20px rgba(0, 0, 0, 0.08);
    padding: var(--spacing-2xl);
}

/* Header */
header {
    text-align: center;
    margin-bottom: var(--spacing-2xl);
}

h1 {
    font-size: 32px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: var(--spacing-sm);
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: 16px;
    color: var(--gray-600);
    font-weight: 400;
    line-height: 1.5;
}

/* Progress Bar */
.progress-bar {
    width: 100%;
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    margin: 30px 0;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 11%; /* Start at question 1 of 9 */
}

.progress-text {
    position: absolute;
    top: -25px;
    right: 0;
    font-size: 14px;
    color: #6b7280;
    font-weight: 500;
}

/* Form Sections */
.form-section {
    margin-bottom: var(--spacing-3xl);
}

.form-section h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: var(--spacing-2xl);
    padding-bottom: var(--spacing-md);
    border-bottom: 2px solid var(--light-gray);
}

/* Question Groups */
.question-group {
    margin-bottom: 40px;
}

.question-label {
    display: block;
    font-size: 18px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 20px;
    line-height: 1.5;
}

.question-number {
    display: inline-block;
    width: 32px;
    height: 32px;
    background: #667eea;
    color: white;
    border-radius: 50%;
    text-align: center;
    line-height: 32px;
    margin-right: 12px;
    font-size: 16px;
    font-weight: 600;
    vertical-align: middle;
}

.helper-text {
    font-size: 14px;
    color: #6b7280;
    margin-top: 8px;
    font-style: italic;
}

/* Radio Groups */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.radio-option {
    display: block;
    padding: 16px 20px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px; /* Touch target */
    display: flex;
    align-items: flex-start;
}

.radio-option:hover {
    border-color: #667eea;
    background: #f9fafb;
}

.radio-option input[type="radio"] {
    margin-right: 12px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    margin-top: 2px;
    accent-color: #667eea;
    flex-shrink: 0;
}

.radio-option input[type="radio"]:checked + span {
    font-weight: 600;
    color: #667eea;
}

.radio-option:has(input:checked) {
    border-color: #667eea;
    background: #eff6ff;
}

.radio-option span {
    flex: 1;
    line-height: 1.5;
    color: var(--gray-700);
}

/* Checkbox Groups */
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.checkbox-option {
    display: flex;
    align-items: flex-start;
    padding: var(--spacing-md);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px;
    background-color: #ffffff;
}

.checkbox-option:hover {
    border-color: var(--primary);
    background-color: rgba(102, 126, 234, 0.02);
}

.checkbox-option input[type="checkbox"] {
    margin-right: var(--spacing-md);
    margin-top: 2px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--primary);
    flex-shrink: 0;
}

.checkbox-option input[type="checkbox"]:checked + span {
    color: var(--text);
    font-weight: 500;
}

.checkbox-option:has(input[type="checkbox"]:checked) {
    border-color: var(--primary);
    background-color: rgba(102, 126, 234, 0.05);
}

.checkbox-option span {
    flex: 1;
    line-height: 1.5;
    color: var(--gray-700);
}

/* Input Groups */
.input-group {
    margin-bottom: var(--spacing-md);
}

.input-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: var(--spacing-sm);
}

.input-group input,
.input-group select,
.input-group textarea {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    font-family: inherit;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.2s ease;
    background-color: #ffffff;
    color: var(--text);
    line-height: 1.5;
}

.input-group textarea {
    resize: vertical;
    min-height: 100px;
}

.input-group input::placeholder {
    color: var(--gray-400);
}

.input-group input:focus,
.input-group select:focus,
.input-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.input-group input:invalid:not(:placeholder-shown):not(:focus) {
    border-color: var(--danger);
}

.input-group select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
}

.inline-input {
    margin-left: var(--spacing-sm);
    padding: 8px;
    font-size: 14px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    width: auto;
    min-width: 200px;
}

/* Submit Button */
.submit-btn {
    width: 100%;
    padding: 14px var(--spacing-lg);
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    color: #ffffff;
    background: var(--primary);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: var(--spacing-xl);
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.submit-btn:hover {
    background: #5568d3;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.submit-btn:active {
    transform: translateY(0);
}

.submit-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}

.submit-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: var(--gray-400);
    transform: none;
}

/* Error States */
.error-message {
    display: block;
    color: var(--danger);
    font-size: 13px;
    margin-top: var(--spacing-xs);
    min-height: 20px;
    line-height: 1.4;
}

input.error,
select.error {
    border-color: var(--danger);
}

input.error:focus,
select.error:focus {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* Hidden State */
.hidden {
    display: none !important;
}

/* Loading State */
#loadingState {
    text-align: center;
    padding: 60px 20px;
    animation: fadeIn 0.4s ease-in;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #e5e7eb;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#loadingState h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: var(--spacing-sm);
}

#loadingState p {
    font-size: 16px;
    color: var(--gray-700);
    font-weight: 500;
    margin-bottom: var(--spacing-sm);
}

.loading-detail {
    font-size: 14px;
    color: var(--gray-500);
    font-weight: 400;
    margin-bottom: var(--spacing-lg);
}

.loading-progress-bar {
    width: 100%;
    max-width: 400px;
    height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    margin: 20px auto 0;
}

.loading-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    border-radius: 2px;
    width: 0%;
    animation: loadingProgress 30s linear forwards;
}

@keyframes loadingProgress {
    to { width: 100%; }
}

/* Success State */
#successState {
    text-align: center;
    padding: 60px 20px;
    animation: fadeIn 0.4s ease-in;
}

.success-icon {
    width: 80px;
    height: 80px;
    background: #10b981;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    margin: 0 auto 20px;
    font-weight: 700;
    animation: scaleIn 0.4s ease-out;
}

@keyframes scaleIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

#successState h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: var(--spacing-sm);
}

#successState p {
    font-size: 16px;
    color: var(--gray-600);
    line-height: 1.5;
    margin-bottom: var(--spacing-xl);
}

.success-buttons {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    margin-top: var(--spacing-xl);
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

.success-buttons .submit-btn {
    width: 100%;
    margin-top: 0;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: var(--spacing-md);
    }

    .container {
        padding: var(--spacing-lg);
        border-radius: 8px;
    }

    h1 {
        font-size: 28px;
    }

    .subtitle {
        font-size: 15px;
    }

    .form-section h2 {
        font-size: 18px;
    }

    .question-group {
        margin-bottom: var(--spacing-xl);
    }

    .input-group input,
    .input-group select {
        font-size: 16px; /* Prevents zoom on iOS */
    }

    .inline-input {
        width: 100%;
        margin-left: 0;
        margin-top: var(--spacing-sm);
    }
}

@media (max-width: 480px) {
    .container {
        padding: var(--spacing-md);
    }

    h1 {
        font-size: 24px;
    }

    .radio-option,
    .checkbox-option {
        padding: var(--spacing-sm);
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .radio-option,
    .checkbox-option,
    .input-group input,
    .input-group select {
        border-width: 3px;
    }

    .submit-btn {
        border: 2px solid #ffffff;
    }
}

/* Dynamic Insights */
.dynamic-insight {
    background: #eff6ff;
    border-left: 4px solid #667eea;
    padding: 16px;
    margin-top: 16px;
    border-radius: 4px;
    font-size: 14px;
    color: #1f2937;
}

.dynamic-insight strong {
    color: #667eea;
}

.dynamic-insight p {
    margin: 0;
    line-height: 1.5;
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

