:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-sidebar: #1e293b;
    --bg-sidebar-hover: #334155;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-sidebar: #e2e8f0;
    --text-sidebar-muted: #94a3b8;
    --border-color: #e2e8f0;
    --accent-color: #6366f1;
    --accent-hover: #4f46e5;
    --accent-sidebar: #818cf8;
    --success-color: #22c55e;
    --error-color: #ef4444;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --accent-color: #818cf8;
    --accent-hover: #6366f1;
    --bg-sidebar: #020617;
    --accent-sidebar: #818cf8;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* Layout */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 700;
}

.logo span {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.5rem;
    background: none;
    border: none;
    color: var(--text-sidebar-muted);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    width: 100%;
    text-align: left;
}

.nav-item:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar);
}

.nav-item.active {
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-sidebar);
    border-right: 3px solid var(--accent-sidebar);
}

.nav-item svg {
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius-md);
    color: var(--text-sidebar-muted);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.15s;
}

.theme-toggle:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text-sidebar);
}

.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 240px;
    padding: 2rem;
    max-width: calc(100% - 240px);
}

.section {
    display: none;
    animation: fadeIn 0.2s ease;
}

.section.active {
    display: block;
}

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

.section-header {
    margin-bottom: 2rem;
}

.section-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.section-header p {
    color: var(--text-secondary);
}

/* Upload Zone */
.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 3rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-primary);
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent-color);
    background: rgba(99, 102, 241, 0.02);
}

.image-preview {
    display: none;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 1rem;
}

.image-preview.show {
    display: flex;
}

.image-preview-item {
    width: 120px;
    height: 120px;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 2px solid var(--border-color);
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.image-preview-item img {
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
}

.image-preview-item .img-icon {
    font-size: 2.5rem;
    opacity: 0.5;
}

.image-preview-item .file-type {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.7);
    color: white;
    font-size: 0.7rem;
    padding: 0.25rem;
    text-align: center;
    font-weight: 600;
}

.upload-zone svg {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.upload-content p {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.upload-content .link {
    color: var(--accent-color);
    font-weight: 600;
}

.upload-content .hint {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* File List */
.file-list {
    margin-top: 1rem;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 0.5rem;
}

.file-item svg {
    flex-shrink: 0;
    color: var(--accent-color);
}

.file-item .name {
    flex: 1;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-item .size {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.file-item .remove {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}

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

/* Action Bar */
.action-bar {
    margin-top: 1.5rem;
    display: flex;
    justify-content: center;
}

/* Options Panel */
.options-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.option-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

.option-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.option-row {
    margin-bottom: 1rem;
}

.option-row:last-child {
    margin-bottom: 0;
}

.option-row > label:not(.checkbox-item):not(.radio-item) {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

/* Form Controls */
.radio-group,
.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.radio-item,
.checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.95rem;
}

.radio-item input,
.checkbox-item input {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-color);
    cursor: pointer;
}

.select,
.input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.select:focus,
.input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.select[multiple] {
    min-height: 100px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.15s;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

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

.btn-secondary:hover {
    background: var(--bg-secondary);
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.1rem;
}

/* Results */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.results-actions {
    display: flex;
    gap: 0.5rem;
}

.results-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    flex-wrap: wrap;
}

.tab-btn {
    padding: 0.625rem 1rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}

.tab-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.tab-btn.active {
    background: var(--accent-color);
    color: white;
}

.results-content {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.code-block {
    max-height: 70vh;
    overflow: auto;
    padding: 1.5rem;
}

.code-block pre {
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.code-block code {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
}

.html-block {
    background: #fefefe;
    color: #333;
    padding: 1.5rem;
}

.html-block img {
    max-width: 100%;
    height: auto;
}

/* Progress Overlay */
.progress-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.progress-overlay.show {
    display: flex;
}

.progress-card {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    text-align: center;
    min-width: 300px;
    box-shadow: var(--shadow-lg);
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1.5rem;
}

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

.progress-text {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.progress-detail {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Error Toast */
.error-toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--error-color);
    color: white;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    display: none;
    align-items: center;
    gap: 0.75rem;
    box-shadow: var(--shadow-lg);
    z-index: 1001;
    max-width: 400px;
}

.error-toast.show {
    display: flex;
}

.error-toast button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.25rem;
    opacity: 0.8;
}

.error-toast button:hover {
    opacity: 1;
}

/* Syntax Highlighting */
.hljs {
    background: transparent !important;
    padding: 0 !important;
}

/* Responsive */
@media (max-width: 900px) {
    .sidebar {
        width: 72px;
    }

    .logo span,
    .nav-item span,
    .theme-toggle span {
        display: none;
    }

    .nav-item {
        justify-content: center;
        padding: 1rem;
    }

    .theme-toggle {
        justify-content: center;
    }

    .sidebar-header {
        padding: 1rem;
        text-align: center;
    }

    .main-content {
        margin-left: 72px;
        max-width: calc(100% - 72px);
    }
}

@media (max-width: 640px) {
    .main-content {
        padding: 1rem;
    }

    .options-panel {
        grid-template-columns: 1fr;
    }

    .section-header h1 {
        font-size: 1.5rem;
    }
}
