/* CSS Variables */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #22d3ee;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border: #475569;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.2s ease;
}

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

html {
    font-size: 16px;
}

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

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

/* Header */
.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.logo h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.anycoder-badge {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: var(--transition);
}

.anycoder-badge:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* Main Content */
.main-content {
    flex: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    width: 100%;
}

/* Page Management */
.page {
    display: none;
}

.page.active {
    display: block;
}

/* Setup Container */
.setup-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Sections */
section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    border: 1px solid var(--border);
}

section h2 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* Upload Section */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem;
    text-align: center;
    transition: var(--transition);
    cursor: pointer;
}

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

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    color: var(--text-secondary);
}

.upload-content svg {
    color: var(--primary);
}

.browse {
    color: var(--primary);
    font-weight: 500;
    cursor: pointer;
}

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

/* Video Preview Section */
.preview-section {
    position: relative;
}

.video-wrapper {
    position: relative;
    display: inline-block;
    max-width: 100%;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #000;
}

#video-preview, #result-video {
    display: block;
    max-width: 100%;
    max-height: 500px;
}

.subtitle-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.subtitle-box {
    position: absolute;
    border: 2px solid var(--primary);
    background: rgba(99, 102, 241, 0.1);
    cursor: move;
    min-width: 100px;
    min-height: 30px;
}

.subtitle-box::before {
    content: 'Subtitle Area';
    position: absolute;
    top: -24px;
    left: 0;
    background: var(--primary);
    color: white;
    padding: 2px 8px;
    font-size: 0.75rem;
    border-radius: 4px;
}

.resize-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--primary);
    border: 2px solid white;
    border-radius: 50%;
}

.resize-handle.nw { top: -6px; left: -6px; cursor: nw-resize; }
.resize-handle.ne { top: -6px; right: -6px; cursor: ne-resize; }
.resize-handle.sw { bottom: -6px; left: -6px; cursor: sw-resize; }
.resize-handle.se { bottom: -6px; right: -6px; cursor: se-resize; }

/* Subtitle Controls */
.subtitle-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
}

.control-group input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.control-group .value {
    font-size: 0.875rem;
    color: var(--primary);
    font-weight: 500;
}

.control-group.checkbox {
    flex-direction: row;
    align-items: center;
}

.control-group.checkbox input {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.quick-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

/* Language Section */
.language-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
}

.lang-btn {
    padding: 0.875rem 1rem;
    border: 1px solid var(--border);
    background: var(--surface-light);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.875rem;
}

.lang-btn:hover {
    border-color: var(--primary);
}

.lang-btn.active {
    background: var(--primary);
    border-color: var(--primary);
}

/* Time Section */
.time-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.time-input-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.time-input-group label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.time-input {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--surface-light);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
}

.time-input input {
    width: 50px;
    text-align: center;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: monospace;
}

.time-input input::-webkit-inner-spin-button,
.time-input input::-webkit-outer-spin-button {
    -webkit-appearance: none;
}

.time-input span {
    color: var(--text-secondary);
}

.btn-small {
    padding: 0.5rem 0.875rem;
    font-size: 0.875rem;
}

/* Time Range Slider */
.time-slider-container {
    padding: 1rem 0;
}

.range-slider {
    position: relative;
    height: 40px;
    margin: 0 10px;
}

.range-track {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 100%;
    height: 6px;
    background: var(--surface-light);
    border-radius: 3px;
}

.range-fill {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 6px;
    background: var(--primary);
    border-radius: 3px;
    left: 0%;
    right: 0%;
}

.range-thumb {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    background: var(--primary);
    border: 3px solid white;
    border-radius: 50%;
    cursor: grab;
    box-shadow: var(--shadow);
    z-index: 2;
}

.range-thumb:active {
    cursor: grabbing;
}

.range-thumb.start { left: 0%; }
.range-thumb.end { left: 100%; }

.time-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-family: monospace;
}

/* Process Section */
.process-section {
    text-align: center;
    padding: 2rem;
}

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

.process-hint {
    margin-top: 1rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Buttons */
.btn-primary, .btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    border: none;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

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

.btn-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon:hover {
    background: var(--primary);
    border-color: var(--primary);
}

/* Processing Page */
.processing-container {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
    padding: 3rem;
}

.processing-animation {
    position: relative;
    width: 200px;
    height: 200px;
    margin: 0 auto 2rem;
}

.spinner {
    width: 100%;
    height: 100%;
    border: 4px solid var(--surface-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.processing-video {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 120px;
    height: 80px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.processing-video::before {
    content: '🎬';
    font-size: 2rem;
}

.progress-container {
    margin: 2rem 0;
}

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

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

.progress-info {
    display: flex;
    justify-content: space-between;
    margin-top: 0.75rem;
    font-size: 0.875rem;
}

.progress-info span:first-child {
    color: var(--text-secondary);
}

#progress-percent {
    color: var(--primary);
    font-weight: 600;
}

.processing-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin: 2rem 0;
}

.stat {
    background: var(--surface-light);
    padding: 1rem;
    border-radius: var(--radius-sm);
}

.stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary);
    margin-top: 0.25rem;
}

/* Results Page */
.results-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.result-video-wrapper {
    margin: 0 auto;
}

.active-subtitle-display {
    position: absolute;
    bottom: 10%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    font-size: 1.125rem;
    text-align: center;
    max-width: 90%;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

.active-subtitle-display.visible {
    opacity: 1;
}

.active-subtitle-display.highlighted {
    box-shadow: 0 0 20px var(--primary), 0 0 40px var(--secondary);
    border: 2px solid var(--primary);
}

.playback-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
}

/* Subtitle List */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.view-toggle {
    display: flex;
    gap: 0.25rem;
    background: var(--surface-light);
    padding: 0.25rem;
    border-radius: var(--radius-sm);
}

.toggle-btn {
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    font-size: 0.875rem;
    transition: var(--transition);
}

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

.subtitle-list {
    background: var(--surface-light);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.list-header {
    display: grid;
    grid-template-columns: 60px 120px 1fr 100px;
    gap: 1rem;
    padding: 0.875rem 1rem;
    background: var(--surface);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.subtitles-container {
    max-height: 400px;
    overflow-y: auto;
}

.subtitle-item {
    display: grid;
    grid-template-columns: 60px 120px 1fr 100px;
    gap: 1rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
    transition: var(--transition);
    cursor: pointer;
}

.subtitle-item:hover {
    background: rgba(99, 102, 241, 0.05);
}

.subtitle-item.active {
    background: rgba(99, 102, 241, 0.15);
    border-left: 3px solid var(--primary);
}

.subtitle-item .index {
    color: var(--text-secondary);
    font-family: monospace;
}

.subtitle-item .time {
    color: var(--secondary);
    font-family: monospace;
    font-size: 0.8125rem;
}

.subtitle-item .text {
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.subtitle-item .status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot.entered { background: var(--warning); }
.status-dot.active { background: var(--success); animation: pulse 1s infinite; }
.status-dot.exited { background: var(--text-secondary); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* JSON View */
.json-view {
    background: var(--surface-light);
    border-radius: var(--radius-sm);
    padding: 1rem;
}

.json-view pre {
    max-height: 400px;
    overflow: auto;
    font-size: 0.8125rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

/* Export Section */
.export-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.export-buttons button {
    flex: 1;
    min-width: 140px;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-overlay.active {
    display: flex;
}

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

.loading-content .spinner {
    width: 60px;
    height: 60px;
    margin: 0 auto 1.5rem;
    border-width: 4px;
}

.loading-content p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.model-progress {
    width: 300px;
    height: 4px;
    background: var(--surface-light);
    border-radius: 2px;
    overflow: hidden;
}

.model-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--primary);
    transition: width 0.3s ease;
}

/* Error Toast */
.error-toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--error);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-sm);
    display: none;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow-lg);
    z-index: 1001;
    animation: slideIn 0.3s ease;
}

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

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

.error-toast button {
    background: none;
    border: none;
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    opacity: 0.8;
}

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

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

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

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

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

/* Responsive */
@media (max-width: 768px) {
    .main-content {
        padding: 1rem;
    }
    
    .header-content {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .subtitle-controls {
        grid-template-columns: 1fr;
    }
    
    .time-controls {
        grid-template-columns: 1fr;
    }
    
    .processing-stats {
        grid-template-columns: 1fr;
    }
    
    .list-header, .subtitle-item {
        grid-template-columns: 40px 80px 1fr 80px;
        gap: 0.5rem;
        font-size: 0.75rem;
    }
    
    .export-buttons {
        flex-direction: column;
    }
    
    .export-buttons button {
        width: 100%;
    }
}