/* ===== Form Container ===== */
.qfld-form-container {
    max-width: 640px;
    margin: 20px auto;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    background: #fff;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    position: relative;
}

/* ===== Running Total Badge ===== */
.qfld-form-container .qfld-running-total {
    position: absolute;
    top: 10px;
    right: 12px;
    background: #4a6cf7;
    color: #fff;
    padding: 6px 12px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 13px;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(74, 108, 247, 0.3);
    line-height: 1.2;
    pointer-events: none;
    white-space: nowrap;
}
.qfld-form-container .qfld-running-total-label {
    opacity: 0.85;
    font-weight: 500;
    margin-right: 4px;
}
.qfld-form-container .qfld-running-total-value {
    font-weight: 700;
}

/* ===== AI Markdown Output ===== */
.qfld-form-container .qfld-ai-md { font-size: 14px; line-height: 1.5; }
.qfld-form-container .qfld-ai-md > *:first-child { margin-top: 0; }
.qfld-form-container .qfld-ai-md > *:last-child { margin-bottom: 0; }
.qfld-form-container .qfld-ai-md p { margin: 0 0 10px; }
.qfld-form-container .qfld-ai-md h1,
.qfld-form-container .qfld-ai-md h2,
.qfld-form-container .qfld-ai-md h3,
.qfld-form-container .qfld-ai-md h4,
.qfld-form-container .qfld-ai-md h5,
.qfld-form-container .qfld-ai-md h6 {
    margin: 14px 0 8px;
    font-weight: 700;
    line-height: 1.25;
}
.qfld-form-container .qfld-ai-md h1 { font-size: 1.35em; }
.qfld-form-container .qfld-ai-md h2 { font-size: 1.22em; }
.qfld-form-container .qfld-ai-md h3 { font-size: 1.12em; }
.qfld-form-container .qfld-ai-md ul,
.qfld-form-container .qfld-ai-md ol { margin: 6px 0 10px; padding-left: 22px; }
.qfld-form-container .qfld-ai-md li { margin: 3px 0; }
.qfld-form-container .qfld-ai-md a { color: #4a6cf7; text-decoration: underline; }
.qfld-form-container .qfld-ai-md strong { font-weight: 700; }
.qfld-form-container .qfld-ai-md em { font-style: italic; }
.qfld-form-container .qfld-ai-md code {
    background: rgba(0,0,0,0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.92em;
}
.qfld-form-container .qfld-ai-md pre {
    background: #1f2937;
    color: #f3f4f6;
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 0.88em;
}
.qfld-form-container .qfld-ai-md pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}
.qfld-form-container .qfld-ai-md blockquote {
    margin: 8px 0;
    padding: 4px 12px;
    border-left: 3px solid #cbd5e1;
    color: #4b5563;
    font-style: italic;
}
.qfld-form-container .qfld-ai-md hr { border: 0; border-top: 1px solid #e5e7eb; margin: 12px 0; }
.qfld-form-container .qfld-ai-md table.qfld-md-table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 0.93em;
    display: block;
    overflow-x: auto;
}
.qfld-form-container .qfld-ai-md table.qfld-md-table th,
.qfld-form-container .qfld-ai-md table.qfld-md-table td {
    border: 1px solid #e5e7eb;
    padding: 6px 10px;
    text-align: left;
    vertical-align: top;
}
.qfld-form-container .qfld-ai-md table.qfld-md-table thead th {
    background: #f3f4f6;
    font-weight: 700;
}
.qfld-form-container .qfld-ai-md table.qfld-md-table tbody tr:nth-child(even) {
    background: #fafafa;
}

/* ===== AI Action Elements (button / inline form) — Form Mode ===== */
.qfld-form-container .qfld-ai-action-wrap {
    background: #faf5ff !important;
    border-left: 3px solid #9333ea;
}
.qfld-form-container .qfld-ai-action-btn {
    display: inline-block;
    padding: 10px 18px;
    background: #9333ea;
    color: #fff !important;
    border-radius: 8px;
    text-decoration: none !important;
    font-weight: 600;
    font-size: 14px;
}
.qfld-form-container .qfld-ai-action-btn:hover { background: #7e22ce; }
.qfld-form-container .qfld-ai-action-form-title {
    font-weight: 700;
    margin-bottom: 10px;
    color: #4c1d95;
}
.qfld-form-container .qfld-ai-action-form { display: flex; flex-direction: column; gap: 8px; }
.qfld-form-container .qfld-ai-action-field { display: flex; flex-direction: column; gap: 3px; }
.qfld-form-container .qfld-ai-action-field label { font-size: 12px; font-weight: 600; color: #555; }
.qfld-form-container .qfld-ai-action-input {
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    width: 100%;
    box-sizing: border-box;
}
.qfld-form-container .qfld-ai-action-checkbox-label {
    display: flex; align-items: flex-start; gap: 8px; font-size: 13px;
}
.qfld-form-container .qfld-ai-action-submit {
    margin-top: 6px;
    padding: 9px 16px;
    background: #9333ea;
    color: #fff;
    border: 0;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
}
.qfld-form-container .qfld-ai-action-submit:disabled { background: #16a34a; cursor: default; }

/* ===== AI Vision — Modern Upload Zone (Form Mode) ===== */
.qfld-form-container .qfld-vision-dropzone {
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    padding: 32px 20px;
    background: #fafbff;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
    margin-top: 8px;
    position: relative;
}
.qfld-form-container .qfld-vision-dropzone:hover {
    border-color: #4a6cf7;
    background: #f0f4ff;
}
.qfld-form-container .qfld-vision-dropzone.qfld-vision-dragging {
    border-color: #4a6cf7;
    background: #e0e7ff;
    border-style: solid;
    transform: scale(1.01);
}
.qfld-form-container .qfld-vision-dz-icon {
    font-size: 44px;
    line-height: 1;
    margin-bottom: 10px;
    pointer-events: none;
}
.qfld-form-container .qfld-vision-dz-main {
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 4px;
    pointer-events: none;
}
.qfld-form-container .qfld-vision-dz-sub {
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 14px;
    pointer-events: none;
}
.qfld-form-container .qfld-vision-dz-browse {
    background: #fff;
    border: 1px solid #d1d5db;
    color: #4a6cf7;
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}
.qfld-form-container .qfld-vision-dz-browse:hover {
    background: #4a6cf7;
    color: #fff;
    border-color: #4a6cf7;
}
.qfld-form-container .qfld-vision-dz-hint {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 12px;
    pointer-events: none;
}
.qfld-form-container .qfld-vision-previews {
    margin-top: 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

/* ===== AI Chat (Form Mode) ===== */
.qfld-form-ai-wrap { display: flex; flex-direction: column; gap: 12px; }
.qfld-form-ai-chat {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 340px;
    overflow-y: auto;
    background: #fafafa;
    border: 1px solid #e5e5e5;
    border-radius: 10px;
    padding: 12px;
}
.qfld-form-ai-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
}
.qfld-form-ai-bot {
    background: #f3e8ff;
    color: #1e1e1e;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.qfld-form-ai-user {
    background: #4a6cf7;
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.qfld-form-ai-error {
    background: #fee2e2;
    color: #991b1b;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.qfld-form-ai-input-row {
    display: flex;
    gap: 8px;
}
.qfld-form-ai-input { flex: 1; }
.qfld-form-ai-continue {
    background: #9333ea !important;
    color: #fff !important;
    flex: 1;
}
.qfld-form-ai-continue:hover { background: #7e22ce !important; }
.qfld-form-ai-bottom-row {
    display: flex;
    gap: 8px;
    width: 100%;
}
.qfld-form-ai-clear {
    background: #f3f4f6 !important;
    color: #4b5563 !important;
    border: 1px solid #e5e7eb !important;
    flex: 0 0 auto;
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
}
.qfld-form-ai-clear:hover {
    background: #e5e7eb !important;
    color: #1f2937 !important;
}

/* ===== Progress Bar ===== */
.qfld-form-progress {
    padding: 24px 24px 0;
    background: #fafbfc;
    border-bottom: 1px solid #eee;
}

.qfld-form-steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: 16px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.qfld-form-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 60px;
    flex-shrink: 0;
}

.qfld-form-step-number {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    color: #999;
    background: #fff;
    transition: all 0.3s;
}

.qfld-form-step.active .qfld-form-step-number {
    border-color: #4a6cf7;
    background: #4a6cf7;
    color: #fff;
    box-shadow: 0 2px 8px rgba(74, 108, 247, 0.3);
}

.qfld-form-step.completed .qfld-form-step-number {
    border-color: #4CAF50;
    background: #4CAF50;
    color: #fff;
}

.qfld-form-step-label {
    font-size: 11px;
    color: #999;
    text-align: center;
    max-width: 80px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.qfld-form-step.active .qfld-form-step-label {
    color: #4a6cf7;
    font-weight: 600;
}

.qfld-form-step.completed .qfld-form-step-label {
    color: #4CAF50;
}

.qfld-form-step-connector {
    width: 32px;
    height: 2px;
    background: #ddd;
    flex-shrink: 0;
    margin-bottom: 22px;
    transition: background 0.3s;
}

.qfld-form-step-connector.completed {
    background: #4CAF50;
}

/* Progress bar */
.qfld-form-progress-bar {
    height: 4px;
    background: #eee;
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 0;
}

.qfld-form-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4a6cf7, #7c3aed);
    border-radius: 2px;
    transition: width 0.4s ease;
}

/* ===== Content Area ===== */
.qfld-form-content {
    padding: 32px 24px;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.qfld-form-fade-in {
    animation: qfldFormFadeIn 0.3s ease;
}

@keyframes qfldFormFadeIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

.qfld-form-step-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.qfld-form-question {
    font-size: 20px;
    font-weight: 600;
    color: #1a1a2e;
    margin: 0;
    line-height: 1.4;
}

.qfld-form-message {
    font-size: 16px;
    color: #444;
    line-height: 1.6;
}

/* ===== Form Fields ===== */
.qfld-form-field {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    outline: none;
    font-family: inherit;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fafbfc;
}

.qfld-form-field:focus {
    border-color: #4a6cf7;
    box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.1);
    background: #fff;
}

.qfld-form-field.qfld-form-error {
    border-color: #F44336;
    box-shadow: 0 0 0 3px rgba(244, 67, 54, 0.1);
    animation: qfldShake 0.4s ease;
}

textarea.qfld-form-field {
    resize: vertical;
}

select.qfld-form-field {
    appearance: auto;
}

.qfld-form-fields-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    width: 100%;
}

.qfld-form-field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 0 0 100%;
    min-width: 0;
    box-sizing: border-box;
}

.qfld-form-field-group.qfld-w-75 { flex: 0 0 calc(75% - 6px); }
.qfld-form-field-group.qfld-w-66 { flex: 0 0 calc(66.666% - 6px); }
.qfld-form-field-group.qfld-w-50 { flex: 0 0 calc(50% - 6px); }
.qfld-form-field-group.qfld-w-33 { flex: 0 0 calc(33.333% - 6px); }
.qfld-form-field-group.qfld-w-25 { flex: 0 0 calc(25% - 6px); }

.qfld-form-field-label {
    font-size: 14px;
    font-weight: 600;
    color: #333;
}

/* ===== Choice Buttons ===== */
.qfld-form-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.qfld-form-choice-btn {
    width: 100%;
    padding: 16px 20px;
    border: 2px solid #e0e0e0;
    background: #fff;
    border-radius: 10px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    text-align: left;
    transition: all 0.2s;
    color: #333;
}

.qfld-form-choice-btn:hover {
    border-color: #4a6cf7;
    background: #f8f9ff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74, 108, 247, 0.12);
}

.qfld-form-choice-btn.selected {
    border-color: #4a6cf7;
    background: #f0f4ff;
    color: #4a6cf7;
}

.qfld-form-hint {
    font-size: 13px;
    color: #888;
    margin: 0 0 8px 0;
    font-style: italic;
}

/* ===== Image ===== */
.qfld-form-image {
    max-width: 100%;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.qfld-form-caption {
    font-size: 14px;
    color: #888;
    margin: 0;
    text-align: center;
}

/* ===== Navigation ===== */
.qfld-form-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-top: 1px solid #eee;
    background: #fafbfc;
}

.qfld-form-btn {
    padding: 12px 28px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
}

.qfld-form-btn-back {
    background: transparent;
    color: #666;
    border: 1px solid #ddd;
}

.qfld-form-btn-back:hover {
    background: #f5f5f5;
    color: #333;
}

.qfld-form-btn-next {
    background: #4a6cf7;
    color: #fff;
    box-shadow: 0 2px 8px rgba(74, 108, 247, 0.3);
}

.qfld-form-btn-next:hover {
    background: #3a5ce5;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74, 108, 247, 0.4);
}

/* ===== End / Summary ===== */
.qfld-form-end {
    text-align: center;
    padding: 20px 0;
}

.qfld-form-end-message h3 {
    font-size: 22px;
    color: #1a1a2e;
    margin: 0 0 8px;
}

.qfld-form-summary {
    text-align: left;
    margin-top: 20px;
    background: #fafbfc;
    border-radius: 8px;
    padding: 16px;
    border: 1px solid #eee;
}

.qfld-form-summary h4 {
    margin: 0 0 12px;
    font-size: 14px;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.qfld-form-summary-table {
    width: 100%;
    border-collapse: collapse;
}

.qfld-form-summary-table td {
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    font-size: 14px;
}

.qfld-form-summary-table tr:last-child td {
    border-bottom: none;
}

.qfld-form-summary-label {
    color: #888;
    width: 40%;
}

.qfld-form-summary-value {
    color: #333;
    font-weight: 500;
}

.qfld-form-total {
    font-size: 18px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 2px solid #e0e0e0;
    color: #1a1a2e;
    text-align: right;
}

.qfld-form-email-sent {
    color: #4CAF50;
    font-style: italic;
    margin-top: 12px;
    font-size: 14px;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .qfld-form-container {
        margin: 10px;
        border-radius: 8px;
    }

    .qfld-form-progress {
        padding: 16px 16px 0;
    }

    .qfld-form-content {
        padding: 24px 16px;
    }

    .qfld-form-nav {
        padding: 12px 16px;
    }

    .qfld-form-question {
        font-size: 18px;
    }

    .qfld-form-step-label {
        display: none;
    }

    .qfld-form-step-number {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
}

/* ===== Header Text ===== */
.qfld-form-header-text {
    padding: 16px 24px 0;
    background: #fafbfc;
    font-size: 14px;
    color: #444;
    line-height: 1.5;
}
.qfld-form-header-text a {
    color: #4A6CF7;
    text-decoration: underline;
}

/* ===== Checkbox Fields ===== */
.qfld-form-checkbox-wrap {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1.5;
    padding: 4px 0;
}
.qfld-form-checkbox-input {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: #4A6CF7;
}
.qfld-form-checkbox-label {
    color: #333;
}
.qfld-form-checkbox-label a {
    color: #4A6CF7;
    text-decoration: underline;
}
.qfld-form-required {
    color: #F44336;
}
.qfld-form-field-group.qfld-form-error .qfld-form-checkbox-wrap {
    color: #F44336;
    padding: 8px 10px;
    border: 2px solid #F44336;
    border-radius: 8px;
    background: rgba(244, 67, 54, 0.04);
    animation: qfldShake 0.4s ease;
}
.qfld-form-field-group.qfld-form-error .qfld-form-checkbox-label a {
    color: #F44336;
}

@keyframes qfldShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

/* ===== File Upload ===== */
.qfld-form-file-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.qfld-form-file-input {
    padding: 10px;
    border: 2px dashed #d0d5dd;
    border-radius: 8px;
    background: #fafbfc;
    cursor: pointer;
    font-size: 14px;
}
.qfld-form-file-input:hover {
    border-color: #4a6cf7;
    background: #f0f4ff;
}
.qfld-form-field-group.qfld-form-error .qfld-form-file-input {
    border-color: #F44336;
}
.qfld-form-file-info {
    font-size: 12px;
    color: #888;
}
.qfld-form-file-status {
    font-size: 13px;
    color: #333;
}
.qfld-form-file-error {
    color: #F44336 !important;
    font-weight: 600;
}

/* ===== Date Field ===== */
.qfld-form-date-hidden {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    overflow: hidden;
    pointer-events: none;
}

.qfld-form-field[data-field-type="date"] {
    cursor: pointer;
    background: #fafbfc url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%23888" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="18" rx="2" ry="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg>') no-repeat right 12px center;
    padding-right: 36px;
}

/* Start screen (form mode) */
.qfld-form-start-screen {
    text-align: center;
    padding: 32px 16px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}

.qfld-form-start-message {
    font-size: 16px;
    line-height: 1.6;
    color: #1f2937;
    max-width: 560px;
}

.qfld-form-start-message h1,
.qfld-form-start-message h2,
.qfld-form-start-message h3 {
    margin: 0 0 10px;
    color: #111827;
}

.qfld-form-btn-start {
    min-width: 220px;
    font-size: 16px;
    font-weight: 600;
    padding: 14px 28px;
    border-radius: 999px;
}

.qfld-form-start-duration {
    font-size: 13px;
    color: #6b7280;
}
