/* ===== CSS Variables & Reset ===== */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a25;
    --bg-glass: rgba(255, 255, 255, 0.03);
    --bg-glass-hover: rgba(255, 255, 255, 0.06);

    --border-color: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(139, 92, 246, 0.5);

    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-muted: rgba(255, 255, 255, 0.4);

    --accent-primary: #8b5cf6;
    --accent-secondary: #a855f7;
    --accent-gradient: linear-gradient(135deg, #8b5cf6 0%, #a855f7 50%, #d946ef 100%);

    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 40px rgba(139, 92, 246, 0.15);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s ease;

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

/* ===== App Container ===== */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(ellipse at 20% 0%, rgba(139, 92, 246, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 100%, rgba(168, 85, 247, 0.1) 0%, transparent 50%),
        var(--bg-primary);
}

/* ===== Header ===== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-gradient);
    border-radius: var(--radius-md);
    color: white;
}

.logo-icon svg {
    width: 22px;
    height: 22px;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 600;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.btn svg {
    width: 18px;
    height: 18px;
}

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

.btn-ghost:hover {
    background: var(--bg-glass-hover);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.15);
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: var(--shadow-sm), 0 0 20px rgba(139, 92, 246, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md), 0 0 30px rgba(139, 92, 246, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

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

.btn-lg {
    padding: 1rem 2rem;
    font-size: 1rem;
    border-radius: var(--radius-lg);
}

.btn-randomize {
    background: linear-gradient(135deg, #22c55e 0%, #10b981 50%, #059669 100%);
    color: white;
    padding: 0.5rem 0.875rem;
    font-size: 0.75rem;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.3);
}

.btn-randomize:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4);
}

.btn-randomize svg {
    width: 14px;
    height: 14px;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* ===== Upload Section ===== */
.upload-section {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.upload-dropzone {
    width: 100%;
    max-width: 600px;
    padding: 4rem 3rem;
    background: var(--bg-glass);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-xl);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.upload-dropzone:hover,
.upload-dropzone.drag-over {
    border-color: var(--accent-primary);
    background: rgba(139, 92, 246, 0.05);
    box-shadow: var(--shadow-glow);
}

.upload-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-gradient);
    border-radius: 50%;
    color: white;
    animation: pulse 2s ease-in-out infinite;
}

.upload-icon svg {
    width: 40px;
    height: 40px;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.05);
        opacity: 0.8;
    }
}

.upload-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

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

.upload-formats {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* ===== Editor Section ===== */
.editor-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1.5rem 2rem;
    animation: fadeIn 0.4s ease;
}

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

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

.editor-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 1.5rem;
    flex: 1;
}

/* ===== Panels ===== */
.preview-panel,
.settings-panel {
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(20px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-glass);
}

.panel-header h3 {
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.badge {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--success);
    border-radius: 50%;
    animation: blink 1.5s ease-in-out infinite;
}

.badge-server {
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 600;
    background: linear-gradient(135deg, #22c55e 0%, #10b981 100%);
    color: white;
    border-radius: 4px;
    margin-left: 0.5rem;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

/* ===== Video Preview ===== */
.video-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: rgba(0, 0, 0, 0.3);
    min-height: 400px;
}

#videoPreview {
    max-width: 100%;
    max-height: 100%;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

/* ===== Output Specs Panel ===== */
.output-specs {
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
}

.specs-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-glass);
}

.specs-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.specs-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: var(--border-color);
}

.spec-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 0.5rem;
    background: var(--bg-tertiary);
    text-align: center;
}

.spec-label {
    font-size: 0.65rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.spec-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent-primary);
    font-variant-numeric: tabular-nums;
}

.original-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
}

.original-label {
    color: var(--text-muted);
}

/* ===== Settings Panel ===== */
.settings-content {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}

.settings-group {
    margin-bottom: 1.5rem;
}

.group-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.group-title svg {
    width: 16px;
    height: 16px;
    color: var(--accent-primary);
}

.setting-item {
    margin-bottom: 1.25rem;
}

.setting-item label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.setting-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.375rem;
}

/* ===== Form Inputs ===== */
.select-input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
}

.select-input:hover {
    border-color: rgba(255, 255, 255, 0.15);
}

.select-input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.slider {
    flex: 1;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    appearance: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent-gradient);
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition-fast);
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.4);
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--accent-gradient);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

.slider-value {
    min-width: 70px;
    text-align: right;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--accent-primary);
    font-variant-numeric: tabular-nums;
}

/* Checkbox styling */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

.checkbox-label span {
    flex: 1;
}

/* ===== Export Section ===== */
.export-section {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-glass);
}

.export-section .btn-lg {
    width: 100%;
}

.export-progress {
    margin-top: 1rem;
}

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

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent-gradient);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-text {
    margin-top: 0.75rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: center;
}

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

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

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

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

.loading-text {
    font-size: 1rem;
    color: var(--text-secondary);
}

/* ===== Utility Classes ===== */
.hidden {
    display: none !important;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .editor-layout {
        grid-template-columns: 1fr;
    }

    .settings-panel {
        max-height: none;
    }

    .header {
        padding: 1rem;
    }

    .editor-section {
        padding: 1rem;
    }
}

@media (max-width: 600px) {
    .upload-dropzone {
        padding: 2.5rem 1.5rem;
    }

    .upload-icon {
        width: 60px;
        height: 60px;
    }

    .upload-icon svg {
        width: 28px;
        height: 28px;
    }

    .upload-title {
        font-size: 1.25rem;
    }
}

/* ===== History Badge ===== */
.history-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--accent-primary);
    color: white;
    border-radius: 10px;
    margin-left: 4px;
}

/* ===== History Panel (Slide-in Sidebar) ===== */
.history-panel {
    position: fixed;
    top: 0;
    right: -380px;
    width: 360px;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    backdrop-filter: blur(20px);
    z-index: 200;
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
}

.history-panel.open {
    right: 0;
}

.history-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-glass);
}

.history-panel-header h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-close {
    padding: 0.5rem;
    border-radius: var(--radius-sm);
}

.btn-close svg {
    width: 16px;
    height: 16px;
}

.history-panel-actions {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.history-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
    padding: 2rem 1rem;
}

/* ===== History Item ===== */
.history-item {
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.875rem;
    transition: all var(--transition-fast);
}

.history-item:hover {
    background: var(--bg-glass-hover);
    border-color: rgba(255, 255, 255, 0.12);
}

.history-item.status-completed {
    border-left: 3px solid var(--success);
}

.history-item.status-failed {
    border-left: 3px solid var(--error);
}

.history-item.status-processing {
    border-left: 3px solid var(--warning);
}

.history-item-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.history-status {
    font-size: 1rem;
}

.history-filename {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-item-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.history-error {
    font-size: 0.75rem;
    color: var(--error);
    padding: 0.375rem 0.5rem;
    background: rgba(239, 68, 68, 0.1);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
}

.history-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

/* ===== Small Buttons ===== */
.btn-sm {
    padding: 0.375rem 0.625rem;
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
}

.btn-sm svg {
    width: 14px;
    height: 14px;
}

.btn-download {
    background: linear-gradient(135deg, #22c55e 0%, #10b981 100%);
    color: white;
}

.btn-download:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.4);
}

.btn-delete {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

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

/* ===== Toast Notifications ===== */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 0.875rem 1.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast-success {
    border-color: var(--success);
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.15) 0%, var(--bg-secondary) 100%);
}

.toast-error {
    border-color: var(--error);
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.15) 0%, var(--bg-secondary) 100%);
}

.toast-info {
    border-color: var(--accent-primary);
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15) 0%, var(--bg-secondary) 100%);
}

/* ===== History Panel Responsive ===== */
@media (max-width: 600px) {
    .history-panel {
        width: 100%;
        right: -100%;
    }
}

/* ===== Preview Canvas ===== */
.preview-canvas {
    max-width: 100%;
    max-height: 100%;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
}

.video-container {
    position: relative;
}

/* ===== Audio Separation Status ===== */
.audio-separation-status {
    padding: 0.75rem 1rem;
    background: rgba(139, 92, 246, 0.1);
    border-top: 1px solid var(--border-color);
}

.separation-indicator {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.separation-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--bg-tertiary);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.separation-indicator.ready .separation-spinner {
    display: none;
}

.separation-indicator.ready::before {
    content: '✓';
    color: var(--success);
    font-weight: bold;
}

/* ===== FFmpeg Loading Status ===== */
.ffmpeg-status {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    padding: 0.5rem 0.75rem;
    background: rgba(0, 0, 0, 0.7);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--text-muted);
    z-index: 10;
    backdrop-filter: blur(10px);
}

.ffmpeg-status.loading {
    color: var(--warning);
}

.ffmpeg-status.ready {
    color: var(--success);
}

.ffmpeg-status.error {
    color: var(--error);
}