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

:root {
    --bg-deep: #070b14;
    --bg-base: #0f172a;
    --bg-surface: #1e293b;
    --bg-raised: #273548;
    --border: #334155;
    --border-focus: #3b82f6;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --font-body: 'DM Sans', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Courier New', monospace;
    --radius: 6px;
    --radius-lg: 10px;
}

body.light-theme {
    --bg-deep: #f1f5f9;
    --bg-base: #ffffff;
    --bg-surface: #f8fafc;
    --bg-raised: #e2e8f0;
    --border: #cbd5e1;
    --border-focus: #3b82f6;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
}

html, body {
    height: 100%;
    background: var(--bg-deep);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.5;
}

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

/* ─── Top Nav ──────────────────────────────────────── */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 48px;
    background: var(--bg-base);
    border-bottom: 1px solid var(--border);
}

.nav-brand {
    font-weight: 700;
    font-size: 15px;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}
.nav-brand:hover { text-decoration: none; color: var(--accent); }

.nav-right { display: flex; align-items: center; gap: 16px; }
.nav-user { color: var(--text-secondary); font-size: 13px; }
.nav-link { color: var(--text-muted); font-size: 13px; }
.nav-link:hover { color: var(--text-primary); }

/* ─── Flash Messages ───────────────────────────────── */
.flash-messages { padding: 0 24px; }
.flash {
    padding: 10px 16px;
    border-radius: var(--radius);
    margin-top: 8px;
    font-size: 13px;
}
.flash-error { background: #450a0a; color: #fca5a5; border: 1px solid #7f1d1d; }
.flash-success { background: #052e16; color: #86efac; border: 1px solid #14532d; }

/* ─── Buttons ──────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

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

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

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-surface); color: var(--text-primary); }

.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: #450a0a; }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-full { width: 100%; }

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

/* ─── Forms ────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 12px; font-weight: 500; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.form-hint { font-size: 11px; color: var(--text-muted); }

input[type="text"],
input[type="password"],
input[type="date"],
input[type="email"],
input[type="color"],
textarea,
select {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-family: var(--font-body);
    font-size: 14px;
    transition: border-color 0.15s;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

textarea::selection {
    background: #fef08a;
    color: #1a1a1a;
}

input[type="color"] { padding: 2px; height: 36px; width: 60px; cursor: pointer; }

select { cursor: pointer; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.form-panel {
    max-width: 900px;
    margin: 0 auto;
    padding: 32px;
}

.form-panel h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
}
.form-panel h2:first-child { border-top: none; padding-top: 0; }

.form-actions {
    padding-top: 24px;
    border-top: 1px solid var(--border);
    margin-top: 24px;
}

/* ─── Auth Pages ───────────────────────────────────── */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 32px;
}

.auth-header { text-align: center; margin-bottom: 32px; display: flex; flex-direction: column; align-items: center; }
.auth-header img { display: block; }
.auth-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }
.auth-header p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 13px; color: var(--text-muted); }

/* ─── Jobs Page ────────────────────────────────────── */
.jobs-page { max-width: 900px; margin: 0 auto; padding: 32px 24px; }

.jobs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}
.jobs-header h1 { font-size: 20px; font-weight: 700; }

.jobs-grid { display: flex; flex-direction: column; gap: 8px; }

.job-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    cursor: pointer;
    transition: all 0.15s;
}
.job-card:hover { border-color: var(--accent); background: var(--bg-surface); }

.job-card-body { flex: 1; }
.job-card-body h3 { font-size: 15px; font-weight: 600; }
.job-meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.job-card-actions { display: flex; gap: 8px; }

.jobs-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

/* ─── Modal ────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.modal {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    width: 100%;
    max-width: 420px;
}
.modal h2 { font-size: 18px; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ─── Editor Page ──────────────────────────────────── */
.editor-page {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 48px);
}

.editor-tabs {
    display: flex;
    gap: 0;
    background: var(--bg-base);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
}

.tab {
    padding: 10px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-back { margin-left: auto; color: var(--text-muted); text-decoration: none; display: flex; align-items: center; }
.tab-back:hover { color: var(--text-primary); text-decoration: none; }

.tab-panel { display: none; flex: 1; overflow: auto; }
.tab-panel.active { display: flex; flex-direction: column; }

/* Editor Toolbar */
.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-base);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 8px;
}
.toolbar-left, .toolbar-right { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.upload-btn { cursor: pointer; }

/* Toolbar Dropdown Menus (CSS-only, no Bootstrap) */
.toolbar-dropdown {
    position: relative;
    display: inline-block;
}
.toolbar-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 180px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 0;
    z-index: 1000;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    margin-top: 2px;
}
.toolbar-dropdown-menu.toolbar-dropdown-right {
    left: auto;
    right: 0;
}
.toolbar-dropdown:hover .toolbar-dropdown-menu,
.toolbar-dropdown:focus-within .toolbar-dropdown-menu {
    display: block;
}
.toolbar-dropdown-menu a {
    display: block;
    padding: 8px 14px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 13px;
    white-space: nowrap;
}
.toolbar-dropdown-menu a:hover {
    background: var(--accent);
    color: white;
}
.toolbar-dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* Status Bar */
.status-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #0c1929;
    font-size: 13px;
    color: var(--accent);
    border-bottom: 1px solid var(--border);
}
.status-bar.status-error { color: var(--danger); }
.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 1.2s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Find & Replace */
.find-replace-bar {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 16px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
}
.find-replace-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}
.find-replace-row label { color: var(--text-secondary); white-space: nowrap; font-size: 12px; }
.find-replace-row input[type="text"] { max-width: 200px; padding: 4px 8px; font-size: 13px; }
.find-replace-row input[type="checkbox"] { margin-right: 2px; }
#findCount { color: var(--text-muted); font-size: 12px; min-width: 40px; }

/* Editor Layout */
.editor-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Speaker Sidebar */
.speaker-sidebar {
    width: 180px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    overflow: hidden;
    flex-shrink: 0;
    position: relative;
}

.speaker-sidebar-content {
    position: relative;
    width: 100%;
}

.sidebar-marker {
    padding: 0 8px;
    height: 21.45px;
    display: flex;
    align-items: center;
}

.sidebar-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.sidebar-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--bg-base);
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.sidebar-dot:hover {
    transform: scale(1.3);
}

.sidebar-dropdown {
    flex: 1;
    font-size: 11px;
    padding: 4px 6px;
    background: var(--bg-base);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    min-width: 0;
}

.sidebar-dropdown:hover,
.sidebar-dropdown:focus {
    border-color: var(--accent);
    outline: none;
}

.editor-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.video-player {
    width: 100%;
    max-height: 300px;
    background: #000;
    border-bottom: 1px solid var(--border);
}

.transcript-editor {
    flex: 1;
    background: var(--bg-base);
    color: var(--text-primary);
    border: none;
    padding: 20px 24px;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.65;
    resize: none;
    outline: none;
    tab-size: 4;
}
.transcript-editor::placeholder { color: var(--text-muted); }

/* Playback Controls */
.playback-controls {
    padding: 12px 16px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
}
.playback-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}
.time-display { font-size: 12px; color: var(--text-muted); font-family: var(--font-mono); }

/* Audio file tags for multi-audio jobs */
.audio-file-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    background: var(--bg-raised);
    color: var(--text-muted);
    border: 1px solid var(--border);
    transition: all 0.15s;
}
.audio-file-tag:hover { background: var(--bg-surface); color: var(--text-primary); }
.audio-file-tag.active { background: var(--accent); color: white; border-color: var(--accent); }
.audio-file-tag.transcribed { }
.audio-file-tag.pending { opacity: 0.6; }

.progress-bar {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-raised);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}
.progress-bar::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

/* Segments Panel */
.segments-panel {
    width: 340px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.segments-panel.hidden { display: none; }

.segments-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.segments-header h3 { font-size: 14px; font-weight: 600; }
.segment-count {
    background: var(--bg-raised);
    color: var(--text-muted);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
}

.segments-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.segment-item {
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.1s;
    margin-bottom: 4px;
}
.segment-item:hover { background: var(--bg-raised); }

.segment-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.segment-speaker { font-size: 12px; font-weight: 600; }
.segment-time { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }
.segment-text { font-size: 12px; color: var(--text-secondary); line-height: 1.4; margin-bottom: 6px; }

.segment-actions { display: flex; gap: 6px; }
.segment-speaker-select, .segment-marker-select {
    font-size: 11px;
    padding: 2px 6px;
    background: var(--bg-base);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.empty-hint { color: var(--text-muted); font-size: 13px; padding: 20px; text-align: center; }

/* ─── Speakers Tab ─────────────────────────────────── */
.speakers-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.speakers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.speaker-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ─── Scrollbars ───────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── Responsive ───────────────────────────────────── */
@media (max-width: 768px) {
    .editor-layout { flex-direction: column; }
    .speaker-sidebar { display: none !important; }
    .segments-panel { width: 100%; max-height: 300px; border-left: none; border-top: 1px solid var(--border); }
    .form-grid { grid-template-columns: 1fr; }
    .editor-toolbar { padding: 8px; }
    .toolbar-left, .toolbar-right { flex-wrap: wrap; }
}

/* ─── Responsive Typography ─────────────────────────── */

/* Extra small devices (phones, <480px) */
@media (max-width: 479px) {
    .transcript-editor {
        font-size: 12px;
        line-height: 1.6;
        padding: 16px 12px;
        /* Adjust margin line for smaller padding */
        background-image: linear-gradient(
            to right,
            transparent 0,
            transparent calc(61ch + 12px),
            rgba(255, 193, 7, 0.3) calc(61ch + 12px),
            rgba(255, 193, 7, 0.3) calc(61ch + 14px),
            transparent calc(61ch + 14px)
        );
    }
}

/* Small devices (phones landscape, tablets portrait, 480-767px) */
@media (min-width: 480px) and (max-width: 767px) {
    .transcript-editor {
        font-size: 13px;
        line-height: 1.62;
        padding: 18px 16px;
        /* Adjust margin line for medium padding */
        background-image: linear-gradient(
            to right,
            transparent 0,
            transparent calc(61ch + 16px),
            rgba(255, 193, 7, 0.3) calc(61ch + 16px),
            rgba(255, 193, 7, 0.3) calc(61ch + 18px),
            transparent calc(61ch + 18px)
        );
    }
}

/* Medium to Large devices (tablets landscape, desktops, ≥768px) */
@media (min-width: 768px) {
    .transcript-editor {
        font-size: 14px;
        line-height: 1.65;
    }
}

/* Extra large devices (large desktops, ≥1440px) */
@media (min-width: 1440px) {
    .transcript-editor {
        font-size: 15px;
        line-height: 1.7;
    }
}
