/* ============================
   CSS Variables & Theme
   ============================ */
:root {
    --bg-primary: #0D0D0F;
    --bg-secondary: #151518;
    --bg-tertiary: #1C1C21;
    --bg-elevated: #222228;
    
    --surface-1: #28282E;
    --surface-2: #323238;
    --surface-3: #3C3C44;
    
    --text-primary: #FAFAFA;
    --text-secondary: #A0A0A8;
    --text-muted: #6C6C74;
    
    --accent-primary: #FF6B6B;
    --accent-secondary: #FF8E53;
    --accent-gradient: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    
    --success: #4ADE80;
    --warning: #FBBF24;
    --error: #F87171;
    
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-default: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.15);
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 40px rgba(255, 107, 107, 0.15);
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    
    --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(255, 107, 107, 0.08), transparent),
        radial-gradient(ellipse 60% 40% at 100% 100%, rgba(255, 142, 83, 0.05), transparent);
    pointer-events: none;
    z-index: -1;
}

/* ============================
   App Layout
   ============================ */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.header-actions {
    display: flex;
    gap: 12px;
}

/* ============================
   Buttons
   ============================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

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

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: var(--shadow-sm), 0 0 20px rgba(255, 107, 107, 0.2);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md), 0 0 30px rgba(255, 107, 107, 0.3);
}

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

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

.btn-secondary:hover:not(:disabled) {
    background: var(--surface-2);
    border-color: var(--border-strong);
}

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

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

.upload-zone {
    width: 100%;
    max-width: 600px;
    aspect-ratio: 16 / 10;
    border: 2px dashed var(--border-default);
    border-radius: var(--radius-xl);
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.upload-zone::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--accent-gradient);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.upload-zone:hover {
    border-color: var(--accent-primary);
    transform: scale(1.01);
}

.upload-zone:hover::before {
    opacity: 0.03;
}

.upload-zone.dragover {
    border-color: var(--accent-primary);
    border-style: solid;
    transform: scale(1.02);
}

.upload-zone.dragover::before {
    opacity: 0.08;
}

.upload-content {
    text-align: center;
    position: relative;
    z-index: 1;
}

.upload-icon {
    margin-bottom: 20px;
    color: var(--text-muted);
    transition: color var(--transition-normal);
}

.upload-zone:hover .upload-icon {
    color: var(--accent-primary);
}

.upload-content h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.upload-content p {
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.upload-hint {
    display: inline-block;
    padding: 6px 14px;
    background: var(--surface-1);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
}

/* ============================
   Editor Section
   ============================ */
.editor-section {
    flex: 1;
    padding: 24px;
}

.editor-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 24px;
    max-width: 1600px;
    margin: 0 auto;
    height: calc(100vh - 130px);
}

/* ============================
   Controls Panel
   ============================ */
.controls-panel {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.panel-section h3 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.original-preview {
    aspect-ratio: 9 / 16;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-subtle);
}

.original-preview video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.video-info {
    display: flex;
    gap: 16px;
    margin-top: 12px;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.info-item svg {
    color: var(--text-muted);
}

/* Checkbox Field */
.checkbox-field {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
    padding: 12px;
    margin: -12px;
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.checkbox-field:hover {
    background: var(--surface-1);
}

.checkbox-field input {
    display: none;
}

.checkbox-custom {
    width: 20px;
    height: 20px;
    border: 2px solid var(--surface-3);
    border-radius: 5px;
    flex-shrink: 0;
    margin-top: 2px;
    transition: all var(--transition-fast);
    position: relative;
}

.checkbox-custom::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 6px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg) scale(0);
    transition: transform var(--transition-fast);
}

.checkbox-field input:checked + .checkbox-custom {
    background: var(--accent-gradient);
    border-color: transparent;
}

.checkbox-field input:checked + .checkbox-custom::after {
    transform: rotate(45deg) scale(1);
}

.checkbox-label {
    font-size: 0.875rem;
    line-height: 1.4;
}

.checkbox-label small {
    display: block;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 4px;
}

/* Input Group */
.input-group {
    margin-top: 12px;
}

.input-group label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.input-group input[type="number"] {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    transition: all var(--transition-fast);
}

.input-group input[type="number"]:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.15);
}

.input-group input[type="range"] {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    background: var(--surface-1);
    border-radius: 3px;
    margin-bottom: 8px;
}

.input-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent-gradient);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(255, 107, 107, 0.3);
}

.range-value {
    display: block;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.trim-input {
    margin-left: 32px;
    padding-left: 12px;
    border-left: 2px solid var(--border-subtle);
    opacity: 0.4;
    pointer-events: none;
    transition: opacity var(--transition-fast);
}

.trim-input.active {
    opacity: 1;
    pointer-events: auto;
}

/* ============================
   Preview Grid
   ============================ */
.preview-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.preview-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.preview-label {
    font-size: 0.875rem;
    font-weight: 500;
}

.preview-zoom {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    padding: 4px 10px;
    background: var(--accent-gradient);
    border-radius: var(--radius-sm);
    color: white;
}

.preview-container {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: 
        repeating-linear-gradient(
            45deg,
            var(--bg-tertiary),
            var(--bg-tertiary) 10px,
            var(--bg-secondary) 10px,
            var(--bg-secondary) 20px
        );
}

.preview-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 9 / 16;
    max-height: 100%;
    overflow: hidden;
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    box-shadow: var(--shadow-lg);
}

.preview-image {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Crop Overlay System */
.crop-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

.crop-mask {
    position: absolute;
    background: rgba(0, 0, 0, 0.5);
}

.crop-mask-top {
    top: 0;
    left: 0;
    right: 0;
    height: 0;
}

.crop-mask-right {
    top: 0;
    right: 0;
    bottom: 0;
    width: 0;
}

.crop-mask-bottom {
    bottom: 0;
    left: 0;
    right: 0;
    height: 0;
}

.crop-mask-left {
    top: 0;
    left: 0;
    bottom: 0;
    width: 0;
}

.crop-border {
    position: absolute;
    border: 2px solid #FF6B6B;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3);
    inset: 0;
}

/* Resize Handle */
.resize-handle {
    position: absolute;
    width: 24px;
    height: 24px;
    background: var(--accent-gradient);
    border-radius: 50%;
    cursor: nwse-resize;
    z-index: 20;
    box-shadow: var(--shadow-md);
    transition: transform var(--transition-fast);
}

.resize-handle::before {
    content: '';
    position: absolute;
    inset: 6px;
    background: white;
    border-radius: 50%;
}

.resize-handle:hover {
    transform: scale(1.2);
}

.resize-handle:active {
    transform: scale(1.1);
}

[data-direction="bottom-right"] { bottom: 8px; right: 8px; cursor: nwse-resize; }
[data-direction="bottom-left"] { bottom: 8px; left: 8px; cursor: nesw-resize; }
[data-direction="top-right"] { top: 8px; right: 8px; cursor: nesw-resize; }
[data-direction="top-left"] { top: 8px; left: 8px; cursor: nwse-resize; }

/* ============================
   Modal
   ============================ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal[hidden] {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 500px;
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-default);
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-subtle);
}

.modal-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--surface-1);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
}

.export-progress {
    margin-bottom: 24px;
}

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

.progress-fill {
    height: 100%;
    background: var(--accent-gradient);
    width: 0%;
    transition: width var(--transition-normal);
}

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

.export-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.export-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.export-item-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--surface-1);
}

.export-item-icon.success {
    background: rgba(74, 222, 128, 0.2);
    color: var(--success);
}

.export-item-icon.error {
    background: rgba(248, 113, 113, 0.2);
    color: var(--error);
}

.export-item-icon.pending {
    color: var(--text-muted);
}

.export-item-icon.processing {
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
}

.export-item-icon.processing .spin {
    animation: spin 1s linear infinite;
}

.export-item-name {
    flex: 1;
    font-size: 0.875rem;
}

/* ============================
   Loading Overlay
   ============================ */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    background: rgba(13, 13, 15, 0.95);
    backdrop-filter: blur(8px);
}

.loading-overlay[hidden] {
    display: none;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--surface-2);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-overlay p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 16px;
}

.loading-progress {
    width: 280px;
    text-align: center;
}

.loading-progress .progress-bar {
    height: 6px;
    background: var(--surface-1);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.loading-progress .progress-fill {
    height: 100%;
    background: var(--accent-gradient);
    width: 0%;
    transition: width 0.2s ease;
}

.loading-progress span {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* ============================
   Responsive
   ============================ */
@media (max-width: 1024px) {
    .editor-layout {
        grid-template-columns: 1fr;
        height: auto;
    }
    
    .controls-panel {
        order: 2;
    }
    
    .preview-grid {
        order: 1;
    }
    
    .original-preview {
        aspect-ratio: 16 / 9;
    }
}

@media (max-width: 640px) {
    .preview-grid {
        grid-template-columns: 1fr;
    }
    
    .header {
        flex-wrap: wrap;
        gap: 12px;
    }
    
    .header-actions {
        width: 100%;
        justify-content: flex-end;
    }
}
