/* ========================================
   Smart Intake Form — Mobile-First CSS
   ======================================== */

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --error: #dc2626;
    --error-light: #fee2e2;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --prefill-bg: #eff6ff;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--gray-800);
    background: var(--gray-100);
    line-height: 1.5;
    min-height: 100vh;
    padding: 0;
}

/* ========================================
   Progress Bar
   ======================================== */
.progress-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 16px 20px;
    background: white;
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 100;
}

.progress-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.step-number {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--gray-200);
    color: var(--gray-500);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.3s ease;
}

.progress-step.active .step-number {
    background: var(--primary);
    color: white;
}

.progress-step.completed .step-number {
    background: var(--success);
    color: white;
}

.step-label {
    font-size: 11px;
    color: var(--gray-400);
    font-weight: 500;
    transition: color 0.3s ease;
}

.progress-step.active .step-label {
    color: var(--primary);
}

.progress-step.completed .step-label {
    color: var(--success);
}

.progress-connector {
    width: 40px;
    height: 2px;
    background: var(--gray-200);
    margin: 0 8px;
    margin-bottom: 18px;
    transition: background 0.3s ease;
}

.progress-connector.active {
    background: var(--primary);
}

/* ========================================
   Form Container
   ======================================== */
#form-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
}

.form-header {
    text-align: center;
    padding: 20px 0 8px;
}

.form-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--gray-900);
}

.form-header .subtitle {
    color: var(--gray-500);
    font-size: 14px;
    margin-top: 4px;
}

/* ========================================
   Stage Cards
   ======================================== */
.stage-card {
    background: white;
    border-radius: var(--radius);
    padding: 24px 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.stage-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 4px;
}

.stage-subtitle {
    color: var(--gray-500);
    font-size: 14px;
    margin-bottom: 16px;
}

/* ========================================
   Form Fields
   ======================================== */
.field-group {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.field label {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-700);
}

.req {
    color: var(--error);
}

.sublabel {
    font-weight: 400;
    color: var(--gray-400);
    font-size: 13px;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="date"],
textarea,
select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 16px; /* Prevents iOS zoom */
    font-family: inherit;
    color: var(--gray-800);
    background: white;
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

input.error, textarea.error, select.error {
    border-color: var(--error);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

input.prefilled {
    background: var(--prefill-bg);
}

textarea {
    resize: vertical;
    min-height: 120px;
}

select {
    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 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* Field layout helpers */
.field-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.field-row-3 {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 12px;
}

/* ========================================
   Radio Buttons
   ======================================== */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 400 !important;
}

.radio-label:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-light);
}

.radio-label input[type="radio"] {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
}

.radio-text {
    font-size: 15px;
    color: var(--gray-700);
}

/* ========================================
   Checkbox
   ======================================== */
.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-weight: 400 !important;
    cursor: pointer;
    line-height: 1.4;
}

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

/* ========================================
   Pain Slider
   ======================================== */
.pain-slider-field {
    padding: 16px 0;
}

.pain-slider-wrap {
    text-align: center;
}

.pain-display {
    font-size: 56px;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
    margin-bottom: 8px;
    transition: color 0.3s;
}

.pain-display.pain-low { color: #16a34a; }
.pain-display.pain-mid { color: #ca8a04; }
.pain-display.pain-high { color: #dc2626; }

.pain-scale-labels {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--gray-400);
    margin-bottom: 4px;
}

.pain-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--gray-200);
    outline: none;
    border: none;
    padding: 0;
}

.pain-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.pain-slider::-moz-range-thumb {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* ========================================
   Detail Modal / Bottom Sheet
   ======================================== */
.detail-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.detail-modal-overlay.visible {
    opacity: 1;
}

.detail-modal {
    background: white;
    width: 100%;
    max-height: 85vh;
    border-radius: 16px 16px 0 0;
    padding: 20px 20px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
}

.detail-modal-overlay.visible .detail-modal {
    transform: translateY(0);
}

.detail-modal-header {
    text-align: center;
    margin-bottom: 12px;
}

.detail-modal-header h3 {
    font-size: 20px;
    font-weight: 700;
    color: var(--gray-900);
}

/* Drag handle visual cue */
.detail-modal-header::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--gray-300);
    border-radius: 2px;
    margin: 0 auto 16px;
}

.detail-modal-body {
    margin-bottom: 20px;
    flex: 1;
    min-height: 0;
}

.detail-modal-body p {
    font-size: 15px;
    line-height: 1.5;
    color: var(--gray-600);
    margin-bottom: 16px;
}

.detail-modal-body textarea {
    min-height: 120px;
    flex: 1;
}

.modal-hints {
    list-style: none;
    padding: 0;
    margin: 8px 0 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
}

.modal-hints li {
    font-size: 14px;
    color: var(--gray-500);
    line-height: 1.5;
}

.modal-hints li::before {
    content: '\2022';
    margin-right: 6px;
    color: var(--gray-400);
}

.detail-modal-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.detail-modal-footer .btn-link {
    font-size: 15px;
    color: var(--gray-500);
}

/* Desktop: centered dialog instead of bottom sheet */
@media (min-width: 640px) {
    .detail-modal-overlay {
        align-items: center;
    }

    .detail-modal {
        max-width: 520px;
        border-radius: var(--radius);
        transform: translateY(20px);
    }

    .detail-modal-overlay.visible .detail-modal {
        transform: translateY(0);
    }

    .detail-modal-header::before {
        display: none;
    }
}

/* ========================================
   DOB Dropdowns
   ======================================== */
.dob-dropdowns {
    display: grid;
    grid-template-columns: 2fr 1fr 1.2fr;
    gap: 8px;
}

.dob-dropdowns select {
    font-size: 15px;
}

/* ========================================
   Emergency Contact Row
   ======================================== */
.ec-row {
    grid-template-columns: 1fr 1fr 1fr;
}

.sublabel-only {
    font-size: 12px !important;
    font-weight: 500 !important;
    color: var(--gray-400) !important;
}

/* ========================================
   Buttons
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    padding: 14px 24px;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
}

.btn-primary:disabled {
    background: var(--gray-300);
    cursor: not-allowed;
}

.btn-full {
    width: 100%;
}

.btn-outline {
    background: white;
    color: var(--gray-600);
    border: 1px solid var(--gray-300);
}

.btn-outline:hover {
    background: var(--gray-50);
}

.btn-small {
    padding: 6px 14px;
    font-size: 13px;
}

.btn-link {
    background: none;
    border: none;
    color: var(--primary);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    padding: 4px;
    font-family: inherit;
}

.btn-link:hover {
    text-decoration: underline;
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
}

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

.btn-loading {
    font-weight: 400;
    font-size: 15px;
}

/* ========================================
   Prefill Banner
   ======================================== */
.prefill-banner {
    background: var(--prefill-bg);
    border: 1px solid #93c5fd;
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 16px;
}

.prefill-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.prefill-icon {
    width: 36px;
    height: 36px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    flex-shrink: 0;
}

.prefill-text {
    flex: 1;
    font-size: 14px;
    color: var(--gray-700);
}

.prefill-text strong {
    font-size: 16px;
    color: var(--gray-900);
}

/* ========================================
   Follow-up Question Cards
   ======================================== */
.followup-card {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 12px;
    animation: slideIn 0.3s ease forwards;
    opacity: 0;
    transform: translateY(10px);
}

@keyframes slideIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.followup-card .question-text {
    font-size: 15px;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 10px;
}

.followup-card textarea {
    min-height: 60px;
    font-size: 15px;
}

.followup-card .detail-field {
    margin-top: 8px;
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.3s ease, opacity 0.3s ease, margin-top 0.3s ease;
}

.followup-card .detail-field.open {
    max-height: 200px;
    opacity: 1;
    margin-top: 10px;
}

/* Toggle Switch */
.toggle-wrap {
    display: flex;
    gap: 8px;
}

.toggle-btn {
    flex: 1;
    padding: 10px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-sm);
    background: white;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--gray-500);
    text-align: center;
}

.toggle-btn:hover {
    border-color: var(--gray-300);
}

.toggle-btn.selected-yes {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
}

.toggle-btn.selected-no {
    border-color: var(--gray-400);
    background: var(--gray-100);
    color: var(--gray-700);
}

/* Select dropdown inside followup card */
.followup-card select {
    font-size: 15px;
}

/* ========================================
   Fee Notice
   ======================================== */
.fee-notice {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 16px;
    font-size: 15px;
    line-height: 1.5;
    color: var(--gray-700);
}

/* ========================================
   Signature Pad
   ======================================== */
.signature-wrap {
    position: relative;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: white;
    touch-action: none;
}

.signature-wrap canvas {
    display: block;
    width: 100%;
    min-height: 150px;
    cursor: crosshair;
}

.signature-wrap .btn {
    position: absolute;
    top: 8px;
    right: 8px;
}

/* ========================================
   Error Message
   ======================================== */
.error-message {
    background: var(--error-light);
    color: var(--error);
    border: 1px solid #fca5a5;
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-size: 14px;
    margin-bottom: 12px;
}

/* ========================================
   Confirmation
   ======================================== */
.confirmation {
    max-width: 500px;
    margin: 80px auto;
    text-align: center;
    padding: 40px 24px;
}

.confirmation-icon {
    width: 72px;
    height: 72px;
    background: var(--success-light);
    color: var(--success);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    font-weight: 700;
    margin: 0 auto 20px;
}

.confirmation h2 {
    font-size: 28px;
    color: var(--gray-900);
    margin-bottom: 8px;
}

.confirmation p {
    color: var(--gray-500);
    font-size: 16px;
}

/* ========================================
   Desktop Breakpoint
   ======================================== */
@media (min-width: 640px) {
    body {
        padding: 20px;
    }

    #form-container {
        padding: 0;
    }

    .stage-card {
        padding: 32px;
    }

    .form-header h1 {
        font-size: 28px;
    }

    .progress-connector {
        width: 60px;
    }

    .radio-group {
        flex-direction: row;
    }

    .radio-label {
        flex: 1;
    }
}
