/* ===== CSS Variables ===== */
:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --success: #10b981;
    --success-light: #34d399;
    --warning: #f59e0b;
    --error: #ef4444;
    --error-light: #fca5a5;
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --bg-hover: #475569;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    --border: #334155;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.4);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

.app {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px;
}

/* ===== Header ===== */
.header {
    padding: 24px 0 32px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 32px;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 16px;
}

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

.logo svg {
    filter: drop-shadow(0 2px 8px rgba(99, 102, 241, 0.4));
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light), var(--success-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* ===== Config Panel ===== */
.config-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 24px;
    overflow: hidden;
}

.panel-header {
    padding: 16px 24px;
    background: rgba(99, 102, 241, 0.08);
    border-bottom: 1px solid var(--border);
}

.panel-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.panel-body {
    padding: 24px;
}

.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.form-group input[type="text"],
.form-group input[type="password"] {
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    transition: var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.form-group select {
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
}

.form-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    cursor: pointer;
}

/* ===== Pipeline ===== */
.pipeline {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.pipeline-title {
    padding: 20px 24px;
    background: rgba(99, 102, 241, 0.08);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.pipeline-title h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.progress-summary span {
    font-size: 0.85rem;
    color: var(--text-muted);
    background: var(--bg-input);
    padding: 4px 12px;
    border-radius: 20px;
}

/* ===== Pipeline Steps ===== */
.pipeline-steps {
    padding: 0;
}

.pipeline-step {
    border-bottom: 1px solid var(--border);
    transition: var(--transition);
}

.pipeline-step:last-child {
    border-bottom: none;
}

.pipeline-step.active {
    background: rgba(99, 102, 241, 0.05);
}

.pipeline-step.active .step-number {
    background: var(--primary);
    color: white;
    animation: pulse 2s infinite;
}

.pipeline-step.completed {
    border-left: 3px solid var(--success);
}

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

.pipeline-step.error {
    border-left: 3px solid var(--error);
    background: rgba(239, 68, 68, 0.05);
}

.pipeline-step.error .step-number {
    background: var(--error);
    color: white;
}

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

.step-header {
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
}

.step-header:hover {
    background: rgba(255, 255, 255, 0.02);
}

.step-number {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-input);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    flex-shrink: 0;
    transition: var(--transition);
}

.step-info {
    flex: 1;
}

.step-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.step-status {
    font-size: 0.8rem;
    color: var(--text-dim);
}

.step-icon {
    color: var(--text-dim);
    flex-shrink: 0;
}

.step-header:hover .step-icon {
    color: var(--text-muted);
}

/* ===== Step Bodies ===== */
.step-body {
    padding: 0 24px 20px;
}

/* ===== Drop Zone ===== */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--bg-input);
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
}

.drop-zone svg {
    margin-bottom: 16px;
}

.drop-text {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.browse-link {
    color: var(--primary-light);
    text-decoration: underline;
    cursor: pointer;
}

.drop-hint {
    font-size: 0.8rem;
    color: var(--text-dim);
}

/* ===== File Info ===== */
.file-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.file-icon {
    font-size: 2rem;
}

.file-details {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.file-name {
    font-weight: 500;
    font-size: 0.95rem;
}

.file-size {
    font-size: 0.8rem;
    color: var(--text-dim);
}

.btn-remove {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 1.1rem;
    border-radius: 4px;
    transition: var(--transition);
}

.btn-remove:hover {
    color: var(--error);
    background: rgba(239, 68, 68, 0.1);
}

/* ===== Stats Cards ===== */
.conversion-stats {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.stat-card {
    flex: 1;
    padding: 16px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-light);
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-top: 4px;
}

/* ===== Progress Bar ===== */
.describe-progress {
    margin-bottom: 16px;
}

.progress-bar {
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ===== Image Thumbnails ===== */
.image-thumbnails {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    max-height: 200px;
    overflow-y: auto;
}

.image-thumb {
    width: 80px;
    height: 60px;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid var(--border);
    position: relative;
    flex-shrink: 0;
}

.image-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-thumb .thumb-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.75);
    color: white;
    font-size: 0.6rem;
    padding: 2px 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.image-thumb .thumb-check {
    position: absolute;
    top: 2px;
    right: 2px;
    background: var(--success);
    color: white;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    opacity: 0;
    transition: var(--transition);
}

.image-thumb.described .thumb-check {
    opacity: 1;
}

/* ===== Markdown Actions ===== */
.markdown-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

/* ===== MD Preview ===== */
.md-preview-container {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.md-preview-toolbar {
    display: flex;
    gap: 0;
    background: var(--bg-input);
    border-bottom: 1px solid var(--border);
}

.toolbar-btn {
    padding: 8px 16px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.85rem;
    cursor: pointer;
    border-right: 1px solid var(--border);
    transition: var(--transition);
    font-family: inherit;
}

.toolbar-btn:last-child {
    border-right: none;
}

.toolbar-btn:hover {
    color: var(--text);
    background: rgba(255,255,255,0.03);
}

.toolbar-btn.active {
    color: var(--primary-light);
    background: rgba(99, 102, 241, 0.1);
}

.md-preview {
    display: flex;
    min-height: 300px;
}

.md-source,
.md-rendered {
    flex: 1;
    padding: 16px;
    overflow: auto;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.85rem;
    line-height: 1.7;
    max-height: 400px;
}

.md-source {
    background: var(--bg);
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
    border-right: 1px solid var(--border);
}

.md-rendered {
    background: var(--bg);
    overflow-y: auto;
}

.md-rendered img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    margin: 8px 0;
}

.md-rendered h1, .md-rendered h2, .md-rendered h3, .md-rendered h4 {
    margin: 16px 0 8px;
    color: var(--text);
}

.md-rendered p {
    margin: 8px 0;
    color: var(--text-muted);
}

.md-rendered strong {
    color: var(--text);
}

.md-rendered em {
    color: var(--text-muted);
}

.md-rendered table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
}

.md-rendered td, .md-rendered th {
    border: 1px solid var(--border);
    padding: 6px 10px;
    font-size: 0.85rem;
}

.md-rendered th {
    background: var(--bg-input);
    font-weight: 600;
}

.md-rendered blockquote {
    border-left: 3px solid var(--primary);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-dim);
}

.md-rendered code {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
}

.md-rendered hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 12px 0;
}

/* ===== Upload Summary ===== */
.upload-summary {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.upload-stat {
    flex: 1;
    padding: 16px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    text-align: center;
}

.upload-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--success);
}

.upload-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-top: 4px;
}

.upload-path {
    padding: 12px 16px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--success-light);
    word-break: break-all;
}

/* ===== Logs ===== */
.step-log {
    margin-top: 12px;
    padding: 12px 16px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.8rem;
    font-family: 'JetBrains Mono', monospace;
    line-height: 1.8;
    color: var(--text-dim);
    border: 1px solid var(--border);
}

.step-log .log-entry {
    animation: fadeIn 0.3s ease;
}

.step-log .log-entry.success {
    color: var(--success-light);
}

.step-log .log-entry.error {
    color: var(--error-light);
}

.step-log .log-entry.info {
    color: var(--primary-light);
}

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

/* ===== Action Bar ===== */
.action-bar {
    padding: 20px 24px;
    background: rgba(99, 102, 241, 0.05);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* ===== Buttons ===== */
.btn-primary,
.btn-secondary,
.btn-danger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-primary:disabled:hover {
    transform: none;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: slideInRight 0.3s ease;
    max-width: 360px;
    backdrop-filter: blur(8px);
}

.toast.success {
    background: rgba(16, 185, 129, 0.9);
    color: white;
}

.toast.error {
    background: rgba(239, 68, 68, 0.9);
    color: white;
}

.toast.info {
    background: rgba(99, 102, 241, 0.9);
    color: white;
}

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

.loading-spinner {
    text-align: center;
}

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

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

.loading-spinner p {
    color: var(--text-muted);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-dim);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .app {
        padding: 16px;
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .config-grid {
        grid-template-columns: 1fr;
    }

    .conversion-stats,
    .upload-summary {
        flex-direction: column;
    }

    .md-preview {
        flex-direction: column;
    }

    .md-source {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .md-source,
    .md-rendered {
        max-height: 300px;
    }

    .action-bar {
        flex-direction: column;
    }

    .btn-primary,
    .btn-secondary,
    .btn-danger {
        width: 100%;
        justify-content: center;
    }
}
