:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #252540;
    --bg-card: #1e1e35;
    --text-primary: #e8e8f0;
    --text-secondary: #a0a0b8;
    --text-muted: #6a6a80;
    --accent: #e74c3c;
    --accent-hover: #c0392b;
    --accent-soft: rgba(231, 76, 60, 0.15);
    --success: #27ae60;
    --warning: #f39c12;
    --info: #3498db;
    --danger: #e74c3c;
    --border: #2a2a45;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

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

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

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* Layout */
.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }
.page-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 16px 0;
    margin-bottom: 24px;
}
.page-header .container {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.page-header h1 { font-size: 1.4rem; font-weight: 600; }
.page-header .subtitle { color: var(--text-secondary); font-size: 0.85rem; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border: none; border-radius: var(--radius-sm);
    font-size: 0.875rem; font-weight: 500; cursor: pointer;
    transition: all 0.15s ease; text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-icon { padding: 6px 10px; }

/* Status badges */
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
}
.badge-none { background: var(--bg-tertiary); color: var(--text-muted); }
.badge-queued { background: rgba(243, 156, 18, 0.2); color: var(--warning); }
.badge-processing { background: rgba(52, 152, 219, 0.2); color: var(--info); animation: pulse 1.5s infinite; }
.badge-completed { background: rgba(39, 174, 96, 0.2); color: var(--success); }
.badge-failed { background: rgba(231, 76, 60, 0.2); color: var(--danger); }
.badge-draft { background: rgba(160, 160, 184, 0.2); color: var(--text-secondary); }
.badge-pending { background: rgba(243, 156, 18, 0.2); color: var(--warning); }
.badge-rendering { background: rgba(52, 152, 219, 0.2); color: var(--info); animation: pulse 1.5s infinite; }

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

/* Episode table */
.episode-table { width: 100%; border-collapse: collapse; }
.episode-table th {
    text-align: left; padding: 10px 12px;
    color: var(--text-muted); font-size: 0.75rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}
.episode-table td {
    padding: 12px; border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.episode-table tr:hover td { background: var(--bg-secondary); }
.episode-table .ep-number { color: var(--text-muted); font-size: 0.85rem; width: 50px; }
.episode-table .ep-title { font-weight: 500; }
.episode-table .ep-title a { color: var(--text-primary); }
.episode-table .ep-title a:hover { color: var(--accent); }
.episode-table .ep-date { color: var(--text-secondary); font-size: 0.85rem; white-space: nowrap; }
.episode-table .ep-duration { color: var(--text-secondary); font-size: 0.85rem; white-space: nowrap; }
.episode-table .ep-actions { white-space: nowrap; }

/* Cards */
.card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px;
}

/* Empty state */
.empty-state {
    text-align: center; padding: 60px 20px; color: var(--text-muted);
}
.empty-state p { margin-top: 8px; }

/* Flash / alerts */
.alert {
    padding: 12px 16px; border-radius: var(--radius-sm);
    margin-bottom: 16px; font-size: 0.9rem;
}
.alert-success { background: rgba(39,174,96,0.15); color: var(--success); border: 1px solid rgba(39,174,96,0.3); }
.alert-error { background: rgba(231,76,60,0.15); color: var(--danger); border: 1px solid rgba(231,76,60,0.3); }
.alert-info { background: rgba(52,152,219,0.15); color: var(--info); border: 1px solid rgba(52,152,219,0.3); }

/* Search */
.search-box {
    padding: 8px 14px; background: var(--bg-tertiary); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-primary); font-size: 0.9rem;
    width: 250px;
}
.search-box:focus { outline: none; border-color: var(--accent); }
.search-box::placeholder { color: var(--text-muted); }

/* Toolbar */
.toolbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.toolbar-group { display: flex; align-items: center; gap: 8px; }

/* Spinner */
.spinner {
    display: inline-block; width: 16px; height: 16px;
    border: 2px solid var(--border); border-top-color: var(--accent);
    border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 768px) {
    .page-header .container { flex-direction: column; align-items: flex-start; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .search-box { width: 100%; }
    .episode-table .ep-date, .episode-table .ep-duration { display: none; }
}

/* ========== Editor Styles (Stage 4) ========== */

.editor-header {
    display: flex; align-items: center; gap: 16px;
    background: var(--bg-secondary); border-bottom: 1px solid var(--border);
    padding: 12px 20px;
}
.editor-header .back-link { color: var(--text-secondary); font-size: 0.9rem; }
.editor-header h1 { font-size: 1.1rem; flex: 1; }
.editor-header .meta { color: var(--text-muted); font-size: 0.85rem; }

/* Waveform */
.waveform-panel {
    background: var(--bg-secondary); padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.waveform-container { border-radius: var(--radius-sm); overflow: hidden; }
.transport-controls {
    display: flex; align-items: center; gap: 12px; margin-top: 12px;
}
.transport-controls .time-display { font-family: monospace; font-size: 0.9rem; color: var(--text-secondary); }
.transport-controls .zoom-control { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.transport-controls .zoom-control label { font-size: 0.8rem; color: var(--text-muted); }
.transport-controls input[type="range"] {
    width: 120px; accent-color: var(--accent);
}

/* Editor columns */
.editor-columns {
    display: grid; grid-template-columns: 1fr 360px;
    min-height: calc(100vh - 220px);
}
@media (max-width: 900px) {
    .editor-columns { grid-template-columns: 1fr; }
}

/* Transcript panel */
.transcript-panel {
    padding: 16px 20px; overflow-y: auto;
    max-height: calc(100vh - 220px);
    border-right: 1px solid var(--border);
}
.transcript-panel .segment {
    margin-bottom: 12px; line-height: 1.8;
    padding: 4px 0; border-bottom: 1px solid var(--border);
}
.transcript-panel .segment-time {
    display: block; font-size: 0.75rem; color: var(--text-muted);
    font-family: monospace; margin-bottom: 2px; cursor: pointer;
}
.transcript-panel .segment-time:hover { color: var(--accent); }
.transcript-panel .word {
    cursor: pointer; padding: 1px 2px; border-radius: 2px;
    transition: background 0.1s;
}
.transcript-panel .word:hover { background: var(--bg-tertiary); }
.transcript-panel .word.active {
    background: var(--accent); color: #fff; border-radius: 3px;
}
.transcript-panel .word.in-region {
    background: var(--accent-soft); border-radius: 2px;
}

/* Clip panel (sidebar) */
.clip-panel {
    padding: 16px 20px; overflow-y: auto;
    max-height: calc(100vh - 220px);
    background: var(--bg-secondary);
}
.clip-panel h3 {
    font-size: 0.9rem; color: var(--text-muted); text-transform: uppercase;
    letter-spacing: 0.5px; margin-bottom: 12px; padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
.clip-form label {
    display: block; font-size: 0.8rem; color: var(--text-secondary);
    margin-bottom: 4px; margin-top: 10px;
}
.clip-form input[type="text"],
.clip-form select {
    width: 100%; padding: 8px 10px; background: var(--bg-tertiary);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text-primary); font-size: 0.9rem;
}
.clip-form input:focus, .clip-form select:focus { outline: none; border-color: var(--accent); }
.clip-form .time-inputs { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.clip-form .clip-actions { display: flex; gap: 8px; margin-top: 16px; }
.clip-form .clip-actions .btn { flex: 1; justify-content: center; }

/* Transcript preview in clip panel */
.clip-transcript-preview {
    max-height: 100px; overflow-y: auto; margin-top: 8px;
    padding: 8px; background: var(--bg-primary); border-radius: var(--radius-sm);
    font-size: 0.85rem; color: var(--text-secondary); line-height: 1.5;
}

/* Saved clips list */
.clip-list-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px; margin-bottom: 8px;
    background: var(--bg-primary); border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}
.clip-list-item .clip-info { flex: 1; min-width: 0; }
.clip-list-item .clip-title {
    font-size: 0.85rem; font-weight: 500; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.clip-list-item .clip-meta { font-size: 0.75rem; color: var(--text-muted); }
.clip-list-item .clip-actions-mini { display: flex; gap: 4px; }

/* Video preview */
.video-preview {
    margin-top: 16px; background: #000; border-radius: var(--radius);
    overflow: hidden;
}
.video-preview video { width: 100%; max-height: 400px; display: block; }

/* Modal */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7); display: flex; align-items: center;
    justify-content: center; z-index: 1000;
}
.modal {
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 24px; max-width: 500px; width: 90%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.modal h3 { margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 20px; justify-content: flex-end; }

/* AI Suggestions */
.suggestion-card {
    background: var(--bg-primary); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
}
.suggestion-card .suggestion-title { font-weight: 600; font-size: 0.95rem; }
.suggestion-card .suggestion-time {
    font-family: monospace; font-size: 0.8rem; color: var(--text-muted); margin-top: 4px;
}
.suggestion-card .suggestion-reason {
    font-size: 0.85rem; color: var(--text-secondary); margin-top: 6px;
    font-style: italic;
}
.suggestion-card .suggestion-actions { margin-top: 10px; display: flex; gap: 6px; }

/* Caption style radio group */
.radio-group { display: flex; gap: 8px; margin-top: 4px; }
.radio-group label {
    display: flex; align-items: center; gap: 4px;
    padding: 6px 12px; background: var(--bg-tertiary);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    cursor: pointer; font-size: 0.85rem; margin: 0;
}
.radio-group input[type="radio"] { accent-color: var(--accent); }
.radio-group label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

/* Notification toast */
.toast {
    position: fixed; bottom: 20px; right: 20px;
    padding: 12px 20px; border-radius: var(--radius);
    background: var(--bg-secondary); border: 1px solid var(--border);
    box-shadow: var(--shadow); z-index: 2000;
    animation: slideUp 0.3s ease;
}
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
