/**
 * VSM Element AI Generator Styles
 *
 * Styles for the AI content generation modal and related UI elements.
 * Supports both light and dark mode in Contao 5.x backend.
 */

/* ============================================================================
   CSS Variables (with dark mode support)
   ============================================================================ */
:root {
    --vsm-ai-primary: #0066cc;
    --vsm-ai-primary-hover: #0052a3;
    --vsm-ai-success: #28a745;
    --vsm-ai-warning: #ffc107;
    --vsm-ai-error: #dc3545;
    --vsm-ai-bg: #ffffff;
    --vsm-ai-bg-secondary: #f8f9fa;
    --vsm-ai-border: #dee2e6;
    --vsm-ai-text: #212529;
    --vsm-ai-text-muted: #6c757d;
    --vsm-ai-overlay: rgba(0, 0, 0, 0.5);
    --vsm-ai-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    --vsm-ai-code-bg: #f4f4f4;
}

[data-color-scheme="dark"] {
    --vsm-ai-primary: #4da6ff;
    --vsm-ai-primary-hover: #66b3ff;
    --vsm-ai-success: #48c774;
    --vsm-ai-warning: #ffdd57;
    --vsm-ai-error: #f14668;
    --vsm-ai-bg: #2d2d2d;
    --vsm-ai-bg-secondary: #3a3a3a;
    --vsm-ai-border: #4a4a4a;
    --vsm-ai-text: #e0e0e0;
    --vsm-ai-text-muted: #a0a0a0;
    --vsm-ai-overlay: rgba(0, 0, 0, 0.7);
    --vsm-ai-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --vsm-ai-code-bg: #1e1e1e;
}

/* ============================================================================
   Modal Overlay
   ============================================================================ */
.vsm-ai-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--vsm-ai-overlay);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal-backdrop, 6000);
    animation: vsm-ai-fade-in 0.2s ease-out;
}

@keyframes vsm-ai-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ============================================================================
   Modal Container
   ============================================================================ */
.vsm-ai-modal {
    background: var(--vsm-ai-bg);
    border-radius: 8px;
    box-shadow: var(--vsm-ai-shadow);
    max-width: 860px;
    width: min(96vw, 860px);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    animation: vsm-ai-slide-up 0.3s ease-out;
    border: 1px solid var(--vsm-ai-border);
}

@keyframes vsm-ai-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================================================
   Modal Header
   ============================================================================ */
.vsm-ai-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--vsm-ai-border);
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--vsm-ai-bg);
}

.vsm-ai-modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--vsm-ai-text);
}

.vsm-ai-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--vsm-ai-text-muted);
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

.vsm-ai-modal-close:hover {
    color: var(--vsm-ai-error);
}

/* ============================================================================
   Modal Content
   ============================================================================ */
.vsm-ai-modal-content {
    padding: 20px;
    overflow-y: auto;
    overscroll-behavior: contain;
    flex: 1;
    scrollbar-gutter: stable both-edges;
}

/* ============================================================================
   Loading State
   ============================================================================ */
.vsm-ai-loading {
    text-align: center;
    padding: 40px 20px;
}

.vsm-ai-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--vsm-ai-border);
    border-top-color: var(--vsm-ai-primary);
    border-radius: 50%;
    margin: 0 auto 16px;
    animation: vsm-ai-spin 0.8s linear infinite;
}

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

/* ============================================================================
   Form Styles
   ============================================================================ */
.vsm-ai-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.vsm-ai-section {
    border-bottom: 1px solid var(--vsm-ai-border);
    padding-bottom: 16px;
}

.vsm-ai-section:last-of-type {
    border-bottom: none;
}

.vsm-ai-section h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--vsm-ai-text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.vsm-ai-info-box {
    background: var(--vsm-ai-bg-secondary);
    border-radius: 6px;
    padding: 12px 16px;
}

.vsm-ai-info-box p {
    margin: 0 0 8px 0;
    font-size: 13px;
    color: var(--vsm-ai-text);
    line-height: 1.5;
}

.vsm-ai-info-box p:last-child {
    margin-bottom: 0;
}

.vsm-ai-info-box code {
    background: var(--vsm-ai-code-bg);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 12px;
}

/* ============================================================================
   Form Fields
   ============================================================================ */
.vsm-ai-field {
    margin-bottom: 16px;
}

.vsm-ai-field:last-child {
    margin-bottom: 0;
}

.vsm-ai-field label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--vsm-ai-text);
    margin-bottom: 6px;
}

.vsm-ai-field select,
.vsm-ai-field textarea,
.vsm-ai-field input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--vsm-ai-border);
    border-radius: 6px;
    background: var(--vsm-ai-bg);
    color: var(--vsm-ai-text);
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.vsm-ai-field select:focus-visible,
.vsm-ai-field textarea:focus-visible,
.vsm-ai-field input[type="text"]:focus-visible {
    outline: 2px solid var(--vsm-ai-primary);
    outline-offset: -1px;
    border-color: var(--vsm-ai-primary);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.15);
}

.vsm-ai-field textarea {
    resize: vertical;
    font-family: inherit;
}

.vsm-ai-checkbox label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.vsm-ai-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Image Settings (conditional section) */
.vsm-ai-image-settings {
    margin-top: 12px;
    padding: 16px;
    background: var(--vsm-ai-bg-secondary);
    border-radius: 6px;
    border-left: 3px solid var(--vsm-ai-primary);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.vsm-ai-image-settings .vsm-ai-field {
    margin-bottom: 0;
}

/* Folder Selector (conditional field) */
.vsm-ai-folder-selector {
    margin-top: 12px;
    padding: 12px;
    background: var(--vsm-ai-bg-secondary);
    border-radius: 6px;
    border-left: 3px solid var(--vsm-ai-primary);
}

.vsm-ai-field-hint {
    margin: 8px 0 0 0;
    font-size: 12px;
    color: var(--vsm-ai-text-muted);
    line-height: 1.4;
}

.vsm-ai-field-hint.vsm-ai-hint-warning {
    color: var(--vsm-ai-warning);
}

/* Folder Picker Tree */
.vsm-ai-folder-picker {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.vsm-ai-folder-search {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--vsm-ai-border);
    border-radius: 4px;
    background: var(--vsm-ai-bg);
    color: var(--vsm-ai-text);
    font-size: 13px;
}

.vsm-ai-folder-search:focus-visible {
    outline: 2px solid var(--vsm-ai-primary);
    outline-offset: -1px;
    border-color: var(--vsm-ai-primary);
}

.vsm-ai-folder-tree {
    max-height: 240px;
    overflow-y: auto;
    border: 1px solid var(--vsm-ai-border);
    border-radius: 4px;
    background: var(--vsm-ai-bg);
}

.vsm-ai-folder-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--vsm-ai-text);
    border-bottom: 1px solid var(--vsm-ai-border);
    user-select: none;
}

.vsm-ai-folder-row:last-child > .vsm-ai-folder-item {
    border-bottom: none;
}

.vsm-ai-folder-item.vsm-ai-has-children {
    cursor: pointer;
}

.vsm-ai-folder-item.vsm-ai-has-children:hover {
    background: var(--vsm-ai-bg-secondary);
}

.vsm-ai-folder-item.vsm-ai-has-children .vsm-ai-folder-name::before {
    content: '▸ ';
    color: var(--vsm-ai-text-muted);
    font-size: 10px;
}

.vsm-ai-folder-item.vsm-ai-has-children.vsm-ai-expanded .vsm-ai-folder-name::before {
    content: '▾ ';
}

.vsm-ai-folder-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.vsm-ai-folder-select {
    font-size: 11px;
    color: var(--vsm-ai-primary);
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 3px;
    opacity: 0;
    transition: opacity 0.15s;
}

.vsm-ai-folder-item:hover .vsm-ai-folder-select,
.vsm-ai-folder-item:focus-within .vsm-ai-folder-select {
    opacity: 1;
}

.vsm-ai-folder-select:hover {
    background: var(--vsm-ai-primary);
    color: white;
}

.vsm-ai-folder-item.vsm-ai-folder-selected {
    background: var(--vsm-ai-primary);
    color: white;
}

.vsm-ai-folder-item.vsm-ai-folder-selected .vsm-ai-folder-name::before {
    color: rgba(255,255,255,0.7);
}

.vsm-ai-folder-item.vsm-ai-folder-selected .vsm-ai-folder-select {
    opacity: 1;
    color: rgba(255,255,255,0.9);
}

.vsm-ai-folder-item.vsm-ai-folder-selected .vsm-ai-folder-select:hover {
    background: rgba(255,255,255,0.2);
    color: white;
}

.vsm-ai-folder-empty {
    padding: 20px;
    text-align: center;
    color: var(--vsm-ai-text-muted);
    font-size: 13px;
}

.vsm-ai-selected-folder {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--vsm-ai-bg);
    border: 1px solid var(--vsm-ai-border);
    border-radius: 4px;
    font-size: 13px;
}

.vsm-ai-selected-label {
    color: var(--vsm-ai-text-muted);
}

.vsm-ai-selected-path {
    color: var(--vsm-ai-text-muted);
    font-style: italic;
}

.vsm-ai-selected-path.vsm-ai-has-selection {
    color: var(--vsm-ai-text);
    font-style: normal;
    font-weight: 500;
}

/* ============================================================================
   Actions
   ============================================================================ */
.vsm-ai-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding-top: 16px;
    border-top: 1px solid var(--vsm-ai-border);
    margin-top: 8px;
}

.vsm-ai-actions .tl_submit {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.vsm-ai-actions .tl_submit:not(.secondary) {
    background: var(--vsm-ai-primary);
    color: white;
    border: none;
}

.vsm-ai-actions .tl_submit:not(.secondary):hover {
    background: var(--vsm-ai-primary-hover);
}

.vsm-ai-actions .tl_submit.secondary {
    background: transparent;
    color: var(--vsm-ai-text-muted);
    border: 1px solid var(--vsm-ai-border);
}

.vsm-ai-actions .tl_submit.secondary:hover {
    background: var(--vsm-ai-bg-secondary);
    color: var(--vsm-ai-text);
}

/* ============================================================================
   Progress
   ============================================================================ */
.vsm-ai-progress {
    text-align: center;
    padding: 20px;
    border: 1px solid var(--vsm-ai-border);
    border-radius: 8px;
    background: var(--vsm-ai-bg-secondary);
}

.vsm-ai-progress h4 {
    margin: 0 0 20px 0;
    color: var(--vsm-ai-text);
}

.vsm-ai-progress-bar-container {
    background: var(--vsm-ai-bg-secondary);
    border-radius: 10px;
    height: 20px;
    overflow: hidden;
    margin-bottom: 16px;
}

.vsm-ai-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--vsm-ai-primary), var(--vsm-ai-primary-hover));
    border-radius: 10px;
    transition: width 0.3s ease;
}

.vsm-ai-progress-text {
    color: var(--vsm-ai-text-muted);
    font-size: 13px;
    margin-bottom: 20px;
}

/* ============================================================================
   Success State
   ============================================================================ */
.vsm-ai-success {
    text-align: center;
}

.vsm-ai-success h4 {
    color: var(--vsm-ai-success);
    margin: 0 0 16px 0;
}

/* Image Previews */
.vsm-ai-image-previews {
    margin-bottom: 16px;
    text-align: left;
}

.vsm-ai-image-previews h5 {
    margin: 0 0 12px 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--vsm-ai-text);
}

.vsm-ai-image-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.vsm-ai-image-preview-item {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--vsm-ai-bg-secondary);
    border-radius: 6px;
    padding: 8px;
    max-width: 200px;
}

.vsm-ai-image-preview-item img {
    width: 100%;
    height: auto;
    border-radius: 4px;
    max-height: 150px;
    object-fit: cover;
}

.vsm-ai-image-field {
    font-size: 11px;
    color: var(--vsm-ai-text-muted);
    text-align: center;
}

.vsm-ai-image-error {
    display: block;
    padding: 20px;
    text-align: center;
    color: var(--vsm-ai-text-muted);
    font-size: 11px;
}

.vsm-ai-result-preview {
    background: var(--vsm-ai-code-bg);
    border: 1px solid var(--vsm-ai-border);
    border-radius: 6px;
    padding: 16px;
    max-height: 200px;
    overflow: auto;
    text-align: left;
    margin-bottom: 20px;
}

.vsm-ai-result-preview pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 12px;
    color: var(--vsm-ai-text);
}

/* ============================================================================
   Error & Warning States
   ============================================================================ */
.vsm-ai-error,
.vsm-ai-warning {
    text-align: center;
    padding: 20px;
}

.vsm-ai-error h4 {
    color: var(--vsm-ai-error);
    margin: 0 0 12px 0;
}

.vsm-ai-warning h4 {
    color: var(--vsm-ai-warning);
    margin: 0 0 12px 0;
}

.vsm-ai-error p,
.vsm-ai-warning p {
    color: var(--vsm-ai-text-muted);
    margin: 0 0 20px 0;
}

/* ============================================================================
   Operation Button in List View
   ============================================================================ */
.vsm-ai-generate-btn {
    display: inline-block;
    padding: 2px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.vsm-ai-generate-btn:hover {
    opacity: 1;
}

/* ============================================================================
   Button in Edit Form (Widget)
   ============================================================================ */
.vsm-ai-generate-widget {
    background: var(--vsm-ai-bg-secondary);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.vsm-ai-generate-widget h3 {
    margin: 0 0 12px 0;
}

.vsm-ai-generate-widget h3 label {
    font-size: 14px;
    font-weight: 600;
}

.vsm-ai-generate-info {
    margin-bottom: 16px;
}

.vsm-ai-element-desc,
.vsm-ai-element-usage {
    margin: 0 0 8px 0;
    font-size: 13px;
    color: var(--vsm-ai-text);
}

.vsm-ai-generate-btn-large {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 14px;
}

.vsm-ai-icon {
    font-size: 16px;
}

.vsm-ai-disabled,
.vsm-ai-unsupported {
    opacity: 0.7;
}

/* ============================================================================
   #1 — Toast Notification System
   ============================================================================ */
.vsm-ai-toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: var(--z-modal-content, 6020);
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    max-width: 400px;
}

.vsm-ai-toast {
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.5;
    color: #fff;
    opacity: 0;
    transform: translateX(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.vsm-ai-toast-visible {
    opacity: 1;
    transform: translateX(0);
}

.vsm-ai-toast-success { background: var(--vsm-ai-success); }
.vsm-ai-toast-warning { background: #e67e22; }
.vsm-ai-toast-error { background: var(--vsm-ai-error); }
.vsm-ai-toast-info { background: var(--vsm-ai-primary); }

[data-color-scheme="dark"] .vsm-ai-toast-warning { background: #d4740e; }

/* #1 — Field Flash Animation */
@keyframes vsm-ai-flash {
    0%   { border-color: var(--vsm-ai-success); box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.25); }
    50%  { border-color: var(--vsm-ai-success); box-shadow: 0 0 0 6px rgba(40, 167, 69, 0.1); }
    100% { border-color: inherit; box-shadow: none; }
}

.vsm-ai-field-flash {
    animation: vsm-ai-flash 2s ease-out !important;
}

/* #1 — Unsaved Changes Banner */
.vsm-ai-unsaved-banner {
    padding: 12px 16px;
    margin-bottom: 16px;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 6px;
    font-size: 13px;
    color: #856404;
    line-height: 1.5;
}

[data-color-scheme="dark"] .vsm-ai-unsaved-banner {
    background: #3d3200;
    border-color: #665200;
    color: #ffdd57;
}

/* ============================================================================
   #2 — Image Status Badges
   ============================================================================ */
.vsm-ai-image-status-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    z-index: 1;
}

.vsm-ai-badge-success {
    background: var(--vsm-ai-success);
    color: #fff;
}

.vsm-ai-badge-error {
    background: var(--vsm-ai-error);
    color: #fff;
}

.vsm-ai-badge-skipped {
    background: var(--vsm-ai-text-muted);
    color: #fff;
}

.vsm-ai-image-summary {
    font-size: 12px;
    color: var(--vsm-ai-text-muted);
    margin: 0 0 10px 0;
}

.vsm-ai-image-status-failed {
    border: 1px solid var(--vsm-ai-error);
}

.vsm-ai-image-status-skipped {
    opacity: 0.6;
}

.vsm-ai-image-error-card,
.vsm-ai-image-skipped-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80px;
    padding: 12px;
    gap: 8px;
    font-size: 11px;
    color: var(--vsm-ai-text-muted);
    text-align: center;
}

.vsm-ai-image-error-card .vsm-ai-image-status-badge,
.vsm-ai-image-skipped-card .vsm-ai-image-status-badge {
    position: static;
    width: 28px;
    height: 28px;
    font-size: 14px;
}

.vsm-ai-image-error-msg {
    font-size: 11px;
    color: var(--vsm-ai-error);
    word-break: break-word;
}

/* ============================================================================
   #7 — Section Mode Info
   ============================================================================ */
.vsm-ai-section-info {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 4px 8px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--vsm-ai-primary) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--vsm-ai-primary) 30%, transparent);
    color: var(--vsm-ai-text);
    font-size: 12px;
    line-height: 1.4;
}

.vsm-ai-section-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--vsm-ai-primary);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

/* ============================================================================
   #8 — Diff Preview
   ============================================================================ */
.vsm-ai-diff {
    text-align: left;
}

.vsm-ai-diff h4 {
    margin: 0 0 8px 0;
    color: var(--vsm-ai-text);
}

.vsm-ai-diff-summary {
    font-size: 12px;
    color: var(--vsm-ai-text-muted);
    margin: 0 0 12px 0;
}

.vsm-ai-diff-table-wrapper {
    max-height: 400px;
    overflow: auto;
    border: 1px solid var(--vsm-ai-border);
    border-radius: 6px;
    margin-bottom: 16px;
}

.vsm-ai-diff-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.vsm-ai-diff-table th {
    position: sticky;
    top: 0;
    background: var(--vsm-ai-bg-secondary);
    padding: 8px 10px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--vsm-ai-text-muted);
    border-bottom: 2px solid var(--vsm-ai-border);
}

.vsm-ai-diff-table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--vsm-ai-border);
    vertical-align: top;
    word-break: break-word;
    max-width: 200px;
}

.vsm-ai-diff-field {
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 11px;
    white-space: nowrap;
    color: var(--vsm-ai-text);
}

.vsm-ai-diff-status {
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.vsm-ai-diff-new {
    background: rgba(40, 167, 69, 0.08);
}

.vsm-ai-diff-new .vsm-ai-diff-status { color: var(--vsm-ai-success); }

.vsm-ai-diff-changed {
    background: rgba(255, 193, 7, 0.08);
}

.vsm-ai-diff-changed .vsm-ai-diff-status { color: #b8860b; }
[data-color-scheme="dark"] .vsm-ai-diff-changed .vsm-ai-diff-status { color: var(--vsm-ai-warning); }

.vsm-ai-diff-same {
    opacity: 0.5;
}

/* ============================================================================
   #9 — Progressive Image Generation UI
   ============================================================================ */
.vsm-ai-image-progress-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 16px 0;
    justify-content: center;
}

.vsm-ai-image-progress-grid h5 {
    width: 100%;
    margin: 0 0 4px 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--vsm-ai-text-muted);
    text-align: left;
}

.vsm-ai-image-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 100px;
}

.vsm-ai-image-placeholder {
    width: 100px;
    height: 75px;
    border-radius: 6px;
    background: var(--vsm-ai-bg-secondary);
    border: 1px solid var(--vsm-ai-border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    transition: all 0.3s ease;
}

.vsm-ai-image-placeholder img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 5px;
    animation: vsm-ai-fade-in 0.4s ease;
}

.vsm-ai-image-slot-label {
    font-size: 10px;
    color: var(--vsm-ai-text-muted);
    text-align: center;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.vsm-ai-spinner-small {
    width: 20px;
    height: 20px;
    border: 2px solid var(--vsm-ai-border);
    border-top-color: var(--vsm-ai-primary);
    border-radius: 50%;
    animation: vsm-ai-spin 0.8s linear infinite;
}

.vsm-ai-image-slot-success .vsm-ai-image-placeholder {
    border-color: var(--vsm-ai-success);
}

.vsm-ai-image-slot-failed .vsm-ai-image-placeholder {
    border-color: var(--vsm-ai-error);
    background: rgba(220, 53, 69, 0.05);
}

.vsm-ai-image-slot-skipped .vsm-ai-image-placeholder {
    opacity: 0.5;
}

.vsm-ai-image-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    z-index: 1;
}

.vsm-ai-image-error-text {
    font-size: 9px;
    color: var(--vsm-ai-text-muted);
    text-align: center;
    max-width: 90px;
    word-break: break-word;
}

/* ============================================================================
   #11 — Accessibility: Focus-Visible
   ============================================================================ */
.vsm-ai-modal *:focus-visible {
    outline: 2px solid var(--vsm-ai-primary);
    outline-offset: 2px;
}

.vsm-ai-modal-close:focus-visible {
    outline-offset: 0;
}

.vsm-ai-folder-item:focus-visible {
    outline-offset: -2px;
    background: var(--vsm-ai-bg-secondary);
}

/* ============================================================================
   Reduced Motion
   ============================================================================ */
@media (prefers-reduced-motion: reduce) {
    .vsm-ai-modal-overlay,
    .vsm-ai-modal,
    .vsm-ai-toast,
    .vsm-ai-progress-bar,
    .vsm-ai-spinner,
    .vsm-ai-spinner-small,
    .vsm-ai-image-placeholder,
    .vsm-ai-image-placeholder img {
        animation: none !important;
        transition: none !important;
    }
}

/* ============================================================================
   Responsive
   ============================================================================ */
@media (max-width: 600px) {
    .vsm-ai-modal {
        width: 95%;
        max-height: 95vh;
    }

    .vsm-ai-actions {
        flex-direction: column;
    }

    .vsm-ai-actions .tl_submit {
        width: 100%;
    }

    .vsm-ai-toast-container {
        left: 10px;
        right: 10px;
        max-width: none;
    }

    .vsm-ai-diff-table-wrapper {
        max-height: 300px;
    }
}

/* ============================================================================
   Premium UI Alignment
   ============================================================================ */

:root {
    --vsm-ai-primary: var(--sm-orange, #d56e00);
    --vsm-ai-primary-hover: color-mix(in srgb, var(--sm-orange, #d56e00) 88%, #000);
    --vsm-ai-success: var(--vsm-success, #1d8e59);
    --vsm-ai-warning: var(--vsm-warning, #b97309);
    --vsm-ai-error: var(--vsm-danger, #bf3d2d);
    --vsm-ai-bg: var(--vsm-surface-1, #fffdfa);
    --vsm-ai-bg-secondary: var(--vsm-surface-2, #f6f0e7);
    --vsm-ai-border: var(--vsm-border-strong, #d7cab6);
    --vsm-ai-text: var(--sm-text, #212529);
    --vsm-ai-text-muted: color-mix(in srgb, var(--sm-text, #212529) 70%, transparent);
    --vsm-ai-overlay: rgba(16, 12, 5, 0.5);
    --vsm-ai-shadow: var(--vsm-shadow-modal, 0 32px 80px rgba(24, 16, 5, 0.28));
    --vsm-ai-code-bg: color-mix(in srgb, var(--vsm-ai-bg-secondary) 88%, #fff);
}

[data-color-scheme="dark"] {
    --vsm-ai-primary: var(--sm-orange, #4dabff);
    --vsm-ai-primary-hover: color-mix(in srgb, var(--sm-orange, #4dabff) 88%, #fff);
    --vsm-ai-text-muted: color-mix(in srgb, var(--sm-text, #e0e0e0) 76%, transparent);
    --vsm-ai-overlay: rgba(5, 8, 14, 0.7);
    --vsm-ai-code-bg: color-mix(in srgb, var(--vsm-ai-bg-secondary) 92%, #000);
}

.vsm-ai-modal {
    width: min(96vw, 1040px);
    max-width: 1040px;
    border-radius: 24px;
    border-color: var(--vsm-ai-border);
    box-shadow: var(--vsm-ai-shadow);
}

.vsm-ai-modal-header {
    padding: 22px 28px 18px;
    background: linear-gradient(180deg, color-mix(in srgb, var(--vsm-ai-bg) 98%, transparent), color-mix(in srgb, var(--vsm-ai-bg-secondary) 92%, transparent));
    border-bottom-color: color-mix(in srgb, var(--vsm-ai-border) 85%, transparent);
}

.vsm-ai-modal-content {
    padding: 24px 28px 28px;
    background: linear-gradient(180deg, color-mix(in srgb, var(--vsm-ai-bg) 98%, transparent), color-mix(in srgb, var(--vsm-ai-bg-secondary) 98%, transparent));
}

.vsm-ai-layout {
    display: grid;
    gap: 20px;
}

.vsm-ai-grid {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    gap: 18px;
}

.vsm-ai-grid--result {
    grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
}

.vsm-ai-hero,
.vsm-ai-panel,
.vsm-ai-state {
    border: 1px solid color-mix(in srgb, var(--vsm-ai-border) 86%, transparent);
    border-radius: 20px;
    background: color-mix(in srgb, var(--vsm-ai-bg) 98%, transparent);
    box-shadow: var(--vsm-shadow-soft, 0 18px 40px rgba(38, 28, 11, 0.12));
}

.vsm-ai-hero {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    padding: 20px 22px;
    background: linear-gradient(180deg, color-mix(in srgb, var(--vsm-ai-bg) 98%, transparent), color-mix(in srgb, var(--vsm-ai-bg-secondary) 96%, transparent));
}

.vsm-ai-hero__copy h4 {
    margin: 4px 0 8px;
    font-size: 1.2rem;
}

.vsm-ai-hero__copy p,
.vsm-ai-muted {
    margin: 0;
    color: var(--vsm-ai-text-muted);
    line-height: 1.6;
}

.vsm-ai-hero__eyebrow,
.vsm-ai-progress__eyebrow {
    display: inline-flex;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--vsm-ai-text-muted);
}

.vsm-ai-hero__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.vsm-ai-hero__meta-item,
.vsm-ai-section-info {
    display: inline-flex;
    flex-direction: column;
    gap: 5px;
    min-width: 120px;
    padding: 10px 12px;
    border-radius: 16px;
    background: color-mix(in srgb, var(--vsm-ai-bg-secondary) 88%, transparent);
}

.vsm-ai-hero__meta-item strong {
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.vsm-ai-panel,
.vsm-ai-state {
    padding: 18px 18px 20px;
}

.vsm-ai-panel > h4,
.vsm-ai-state > h4 {
    margin: 0 0 14px;
    font-size: 0.98rem;
    font-weight: 700;
}

.vsm-ai-actions--sticky {
    position: sticky;
    bottom: 0;
    z-index: 3;
    padding-top: 16px;
    margin-top: 4px;
    background: linear-gradient(180deg, rgba(255,255,255,0), color-mix(in srgb, var(--vsm-ai-bg) 92%, transparent) 32%);
}

[data-color-scheme="dark"] .vsm-ai-actions--sticky {
    background: linear-gradient(180deg, rgba(33,36,42,0), color-mix(in srgb, var(--vsm-ai-bg) 92%, transparent) 32%);
}

.vsm-ai-actions {
    gap: 10px;
}

.vsm-ai-actions .tl_submit {
    min-height: 40px;
    border-radius: 999px;
    font-weight: 700;
}

.vsm-ai-progress {
    display: grid;
    gap: 18px;
}

.vsm-ai-progress__header {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: flex-start;
}

.vsm-ai-progress__header h4 {
    margin: 4px 0 0;
}

.vsm-ai-progress-steps {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    padding: 0;
    margin: 0;
    list-style: none;
}

.vsm-ai-progress-step {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-height: 40px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--vsm-ai-border) 82%, transparent);
    background: color-mix(in srgb, var(--vsm-ai-bg-secondary) 88%, transparent);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--vsm-ai-text-muted);
}

.vsm-ai-progress-step.is-active {
    color: var(--vsm-ai-primary);
    border-color: color-mix(in srgb, var(--vsm-ai-primary) 24%, transparent);
    background: color-mix(in srgb, var(--vsm-ai-primary) 10%, var(--vsm-ai-bg));
}

.vsm-ai-progress-step.is-complete {
    color: var(--vsm-ai-success);
    border-color: color-mix(in srgb, var(--vsm-ai-success) 24%, transparent);
    background: color-mix(in srgb, var(--vsm-ai-success) 10%, var(--vsm-ai-bg));
}

.vsm-ai-progress-bar-container {
    border-radius: 999px;
    background: color-mix(in srgb, var(--vsm-ai-border) 45%, transparent);
}

.vsm-ai-image-progress-grid {
    min-height: 48px;
}

.vsm-ai-diff-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.vsm-ai-diff-stat {
    display: grid;
    gap: 4px;
    justify-items: center;
    padding: 14px 12px;
    border-radius: 16px;
    background: color-mix(in srgb, var(--vsm-ai-bg-secondary) 88%, transparent);
    border: 1px solid color-mix(in srgb, var(--vsm-ai-border) 82%, transparent);
}

.vsm-ai-diff-stat strong {
    font-size: 1.2rem;
}

.vsm-ai-result-preview {
    border-radius: 16px;
    border: 1px solid color-mix(in srgb, var(--vsm-ai-border) 82%, transparent);
    background: color-mix(in srgb, var(--vsm-ai-code-bg) 92%, transparent);
}

.vsm-ai-result-preview pre {
    margin: 0;
    padding: 16px 18px;
    max-height: 420px;
}

.vsm-ai-state--error {
    border-color: color-mix(in srgb, var(--vsm-ai-error) 34%, transparent);
    background: color-mix(in srgb, var(--vsm-ai-error) 6%, var(--vsm-ai-bg));
}

.vsm-ai-state--warning {
    border-color: color-mix(in srgb, var(--vsm-ai-warning) 34%, transparent);
    background: color-mix(in srgb, var(--vsm-ai-warning) 8%, var(--vsm-ai-bg));
}

.vsm-ai-image-previews {
    margin: 0;
}

.vsm-ai-image-error {
    margin-top: 6px;
    color: var(--vsm-ai-text-muted);
}

@media (max-width: 980px) {
    .vsm-ai-modal {
        width: min(98vw, 1040px);
        max-height: 96vh;
    }

    .vsm-ai-modal-header,
    .vsm-ai-modal-content {
        padding-left: 18px;
        padding-right: 18px;
    }

    .vsm-ai-grid,
    .vsm-ai-grid--result {
        grid-template-columns: minmax(0, 1fr);
    }

    .vsm-ai-hero {
        flex-direction: column;
    }

    .vsm-ai-hero__meta {
        justify-content: flex-start;
    }
}
