/* === Transcriber Pro v2 — Polished UI === */
:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --border: #e2e8f0;
    --border-hover: #cbd5e1;
    --text: #0f172a;
    --text-2: #475569;
    --text-3: #94a3b8;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-light: #eef2ff;
    --accent-glow: rgba(99,102,241,.12);
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius: 14px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,.08);
    --shadow-lg: 0 12px 32px rgba(0,0,0,.12);
    --transition: .18s cubic-bezier(.4,0,.2,1);

    --spk0: #6366f1; --spk0-bg: #eef2ff;
    --spk1: #06b6d4; --spk1-bg: #ecfeff;
    --spk2: #10b981; --spk2-bg: #ecfdf5;
    --spk3: #f59e0b; --spk3-bg: #fffbeb;
    --spk4: #ef4444; --spk4-bg: #fef2f2;
    --spk5: #8b5cf6; --spk5-bg: #f5f3ff;
    --spk6: #ec4899; --spk6-bg: #fdf2f8;
    --spk7: #14b8a6; --spk7-bg: #f0fdfa;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    font-size: 16px;
}

/* === Header === */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    height: 68px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 19px;
    color: var(--accent);
}
.logo b { color: var(--text); }
nav { display: flex; gap: 2px; background: var(--surface-2); padding: 4px; border-radius: var(--radius-sm); }
.nav-btn {
    padding: 9px 20px;
    border: none;
    background: none;
    color: var(--text-2);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 7px;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
}
.nav-btn:hover { color: var(--text); }
.nav-btn.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }

/* === Buttons === */
.btn {
    padding: 10px 18px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.btn:hover { border-color: var(--border-hover); background: var(--surface-2); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-accent:hover { background: var(--accent-hover); }
.btn-danger { color: var(--danger); border-color: rgba(239,68,68,.3); }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-ghost { border: none; background: none; color: var(--text-2); padding: 6px 10px; }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-icon { padding: 6px; border: none; background: none; color: var(--text-3); cursor: pointer; border-radius: var(--radius-xs); }
.btn-icon:hover { color: var(--text); background: var(--surface-2); }

/* === Layout === */
.layout { display: flex; min-height: calc(100vh - 68px); }

/* === Sidebar === */
.sidebar {
    width: 280px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
}
.sidebar-search {
    position: relative;
    margin-bottom: 8px;
}
.sidebar-search input {
    width: 100%;
    padding: 10px 14px 10px 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    font-size: 13px;
    color: var(--text);
    background: var(--surface-2);
    transition: var(--transition);
    font-family: inherit;
}
.sidebar-search input:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-glow); }
.sidebar-search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.sidebar-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
}
.stat-card {
    background: var(--surface-2);
    border-radius: var(--radius-xs);
    padding: 10px 12px;
    text-align: center;
}
.stat-value { font-size: 24px; font-weight: 700; color: var(--accent); line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--text-3); margin-top: 3px; }
.sidebar-section {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .08em;
    padding: 8px 10px 4px;
}
.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: var(--transition);
    font-size: 14px;
    color: var(--text-2);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
}
.sidebar-item:hover { background: var(--surface-2); color: var(--text); }
.sidebar-item.active { background: var(--accent-light); color: var(--accent); font-weight: 600; }
.sidebar-item .item-icon { width: 20px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar-item .item-count {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-3);
    background: var(--surface-2);
    padding: 1px 7px;
    border-radius: 10px;
    font-weight: 600;
}
.sidebar-item.active .item-count { background: rgba(99,102,241,.15); color: var(--accent); }
.folder-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.sidebar-add {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border: 1.5px dashed var(--border);
    border-radius: var(--radius-xs);
    cursor: pointer;
    font-size: 12px;
    color: var(--text-3);
    background: none;
    width: 100%;
    transition: var(--transition);
    font-family: inherit;
    margin-top: 2px;
}
.sidebar-add:hover { border-color: var(--accent); color: var(--accent); }
.sidebar-add input {
    flex: 1;
    border: none;
    background: none;
    font-size: 12px;
    color: var(--text);
    outline: none;
    font-family: inherit;
    padding: 0;
}
.folder-actions {
    display: none;
    gap: 2px;
    margin-left: auto;
}
.sidebar-item:hover .folder-actions { display: flex; }
.folder-actions button {
    padding: 2px 4px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-3);
    border-radius: 3px;
    font-size: 12px;
    line-height: 1;
}
.folder-actions button:hover { color: var(--text); background: var(--surface); }

/* === Main === */
main { flex: 1; min-width: 0; padding: 28px 24px; max-width: 1100px; }

/* === Cards Grid === */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }

/* === Transcript Card === */
.t-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 22px;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}
.t-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent);
    opacity: 0;
    transition: var(--transition);
}
.t-card:hover { box-shadow: var(--shadow-md); border-color: var(--border-hover); }
.t-card:hover::before { opacity: 1; }
.t-card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 10px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.t-card-meta {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    color: var(--text-3);
    font-size: 13px;
    align-items: center;
}
.t-card-meta span { display: flex; align-items: center; gap: 3px; }
.badge {
    display: inline-flex;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .02em;
}
.badge-processing { background: #fef3c7; color: #92400e; }
.badge-completed { background: #dcfce7; color: #166534; }
.badge-error { background: #fee2e2; color: #991b1b; }

/* === Detail === */
.detail-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-3);
    font-size: 13px;
    cursor: pointer;
    border: none;
    background: none;
    padding: 4px 0;
    margin-bottom: 16px;
    font-family: inherit;
    transition: var(--transition);
}
.detail-back:hover { color: var(--accent); }
.detail-title-row { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.detail-title {
    font-size: 26px;
    font-weight: 700;
    border: none;
    background: none;
    width: 100%;
    color: var(--text);
    outline: none;
    padding: 0;
    line-height: 1.3;
}
.detail-title:focus { box-shadow: 0 2px 0 var(--accent); }
.detail-meta {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    font-size: 15px;
    color: var(--text-2);
}
.detail-meta span { display: flex; align-items: center; gap: 4px; }
.detail-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
/* Export dropdown */
.export-wrap { position: relative; display: inline-block; }
.export-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    min-width: 160px;
    z-index: 50;
    padding: 4px;
}
.export-menu.open { display: block; }
.export-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: none;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    border-radius: var(--radius-xs);
    text-align: left;
    font-family: inherit;
}
.export-menu button:hover { background: var(--surface-2); }
.export-menu .fmt-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 4px;
    text-transform: uppercase;
}
.fmt-docx { background: #dbeafe; color: #1e40af; }
.fmt-pdf { background: #fee2e2; color: #991b1b; }
.fmt-txt { background: #e2e8f0; color: #475569; }

/* === Speaker Mappings === */
.speaker-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin-bottom: 20px;
}
.speaker-panel h3 {
    font-size: 11px;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .08em;
}
.mapping-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 2px;
}
.mapping-row:hover { background: var(--surface-2); }
.mapping-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.mapping-label { flex: 1; font-size: 15px; font-weight: 500; }
.mapping-conf {
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text-2);
    font-weight: 600;
}
.mapping-action {
    font-size: 12px;
    color: var(--accent);
    font-weight: 500;
    opacity: 0;
    transition: var(--transition);
}
.mapping-row:hover .mapping-action { opacity: 1; }

/* === Segments === */
.segments { display: flex; flex-direction: column; gap: 3px; }
.segment {
    display: flex;
    gap: 16px;
    padding: 14px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--border);
    transition: var(--transition);
}
.segment:hover { box-shadow: var(--shadow-sm); border-color: var(--border-hover); }
.seg-left { min-width: 110px; flex-shrink: 0; }
.seg-speaker { font-size: 14px; font-weight: 600; }
.seg-time { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.seg-text { flex: 1; line-height: 1.6; font-size: 15px; color: var(--text); }

/* === Speaker Cards === */
.speaker-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: var(--transition);
}
.speaker-card:hover { box-shadow: var(--shadow); }
.speaker-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-light), #c7d2fe);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    flex-shrink: 0;
}
.speaker-info { flex: 1; }
.speaker-name { font-size: 16px; font-weight: 600; }
.speaker-stats { font-size: 13px; color: var(--text-3); margin-top: 3px; }
.speaker-actions { display: flex; gap: 4px; }

/* === Empty State === */
.empty-state { text-align: center; padding: 80px 20px; color: var(--text-3); }
.empty-icon { margin-bottom: 16px; opacity: .4; }
.empty-state h3 { font-size: 20px; color: var(--text); margin-bottom: 8px; font-weight: 600; }
.empty-state p { font-size: 15px; max-width: 400px; margin: 0 auto; line-height: 1.5; }

/* === Modal === */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.45);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(6px);
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--surface);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    width: 92%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    animation: modalIn .2s;
}
.modal-wide { max-width: 560px; }
@keyframes modalIn { from { transform: translateY(12px); opacity: 0; } }
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 0;
}
.modal-header h2 { font-size: 19px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-3); padding: 0 4px; border-radius: var(--radius-xs); }
.modal-close:hover { color: var(--text); background: var(--surface-2); }
.modal-body { padding: 18px 24px; }
.modal-footer { padding: 0 24px 20px; display: flex; justify-content: flex-end; gap: 8px; }

/* === Form === */
.form-group { margin-bottom: 14px; }
.form-row { display: flex; gap: 12px; }
.form-group label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; color: var(--text-2); }
.form-group label .hint { font-weight: 400; color: var(--text-3); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    font-size: 15px;
    color: var(--text);
    background: var(--surface);
    transition: var(--transition);
    font-family: inherit;
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

/* === Dropzone === */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px 20px;
    text-align: center;
    transition: var(--transition);
    margin-bottom: 14px;
    cursor: pointer;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-light); }
.dropzone .link { color: var(--accent); cursor: pointer; font-weight: 500; }
.hint { font-size: 12px; color: var(--text-3); }
.selected-file {
    padding: 10px 14px;
    background: var(--accent-light);
    border-radius: var(--radius-xs);
    margin-bottom: 14px;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--accent);
    font-weight: 500;
}

/* === Progress === */
.progress-bar { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin-bottom: 6px; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 2px; width: 0%; transition: width .3s; }

/* === Toast === */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
    padding: 10px 18px;
    background: var(--text);
    color: #fff;
    border-radius: var(--radius-xs);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    animation: toastIn .25s;
    max-width: 360px;
}
.toast.error { background: var(--danger); }
.toast.success { background: #059669; }
@keyframes toastIn { from { transform: translateY(8px) scale(.97); opacity: 0; } }

/* === Assign Modal Options === */
.assign-sample-phrases {
    background: var(--surface-2);
    border-radius: var(--radius-xs);
    padding: 10px 14px;
    margin-bottom: 14px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-2);
    max-height: 140px;
    overflow-y: auto;
}
.assign-sample-phrases .sample-item { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.assign-sample-phrases .sample-item:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
.assign-sample-phrases .phrase { margin-top: 6px; }
.assign-sample-phrases .phrase em { font-style: normal; color: var(--text-3); font-size: 11px; }
.assign-options { display: flex; flex-direction: column; gap: 6px; }
.assign-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}
.assign-option:hover { border-color: var(--accent); background: var(--accent-light); }
.assign-option.active { border-color: var(--accent); background: var(--accent-light); }
.assign-new {
    padding: 10px 14px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-3);
    font-size: 13px;
}
.assign-new:hover { border-color: var(--accent); color: var(--accent); }
.assign-new input {
    margin-top: 8px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    font-size: 14px;
    width: 100%;
    text-align: center;
    font-family: inherit;
}

/* === Loading === */
.loading { text-align: center; padding: 48px; color: var(--text-3); }
.spinner {
    display: inline-block;
    width: 28px;
    height: 28px;
    border: 2.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    margin-bottom: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Responsive === */
@media (max-width: 900px) {
    .sidebar { width: 220px; }
}
@media (max-width: 768px) {
    header { padding: 0 14px; }
    .header-right .btn span { display: none; }
    .layout { flex-direction: column; }
    .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); padding: 12px; flex-direction: row; flex-wrap: wrap; overflow-x: auto; }
    .sidebar-stats { display: none; }
    .sidebar-search { width: 100%; margin-bottom: 4px; }
    .sidebar-section { display: none; }
    .sidebar-item { white-space: nowrap; width: auto; }
    .sidebar-add { width: auto; white-space: nowrap; }
    main { padding: 16px 12px; }
    .cards-grid { grid-template-columns: 1fr; }
    .segment { flex-direction: column; gap: 2px; }
    .seg-left { min-width: auto; display: flex; gap: 8px; align-items: center; }
    .detail-actions { gap: 4px; }
}
