:root {
  --bg: #f1f5f9;
  --panel: #fff;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --dark: #0f172a;
  --dark-hover: #334155;
  --line: #e2e8f0;
  --danger: #dc2626;
  --ok: #15803d;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05);
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, a { transition: background-color .15s, border-color .15s, color .15s; }

.wrap { max-width: 1152px; margin: 0 auto; padding: 24px 16px 48px; }
.page-hero { margin-bottom: 24px; }
.eyebrow { margin: 0; color: #1d4ed8; font-size: 14px; font-weight: 700; }
.page-hero h1 { margin: 8px 0 0; font-size: clamp(30px, 5vw, 36px); line-height: 1.2; letter-spacing: -.025em; }
.page-hero .lead { max-width: 768px; margin-top: 12px; font-size: 14px; line-height: 1.7; color: var(--muted); }

.user-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.user-label { margin: 0 0 4px; color: var(--muted); font-size: 13px; font-weight: 700; }
.user-name { margin: 0; font-size: 17px; font-weight: 700; }
.user-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.nav-link { display: inline-flex; align-items: center; border: 1px solid #cbd5e1; border-radius: 6px; padding: 9px 14px; background: #fff; font-size: 14px; font-weight: 700; text-decoration: none; }
.nav-link:hover { background: #f8fafc; }

.panel, .upload-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.upload-panel { margin-bottom: 24px; padding: 16px; }
.panel { padding: 18px; }
.grid { display: block; }

.drop {
  padding: 40px 16px;
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius);
  background: #f8fafc;
  text-align: center;
  cursor: pointer;
}
.drop:hover, .drop.dragover { border-color: #3b82f6; background: #eff6ff; }
.drop strong { display: block; font-size: 18px; }
.drop span { display: block; margin-top: 8px; color: var(--muted); font-size: 14px; }
.drop .formats { margin-top: 16px; font-size: 12px; font-weight: 700; }
.selection-bar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-top: 16px; }
.selection-bar > :first-child { min-width: 0; }
.selected-file-panel { width: 100%; padding: 14px 16px; border: 1px solid #dbe3ef; border-radius: 8px; background: #f8fafc; }
.selection-title { color: #334155; font-size: 13px; font-weight: 800; }
.selected-file-panel .file-list { display: grid; gap: 9px; margin: 11px 0 0; padding-left: 24px; }
.selected-file-panel .file-list li { padding-left: 3px; }
.selected-file-name { display: block; color: #0f172a; font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.selected-file-detail { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 2px; color: #64748b; font-size: 12px; line-height: 1.5; }

.settings-grid { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.transcription-prompt-field { grid-column: 1 / -1; }
.transcription-prompt { width: 100%; min-height: 120px; padding: 11px 12px; resize: vertical; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: var(--text); font-size: 14px; line-height: 1.65; }
.engine-help { background: #f8fafc; }
select, input, textarea { border-color: #cbd5e1; }
select:focus, input:focus, textarea:focus { outline: 2px solid rgba(37, 99, 235, .2); border-color: #3b82f6; }

button { border-radius: 6px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.actions button, .result-actions button { padding: 10px 14px; border: 0; font-size: 14px; font-weight: 800; cursor: pointer; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { border: 1px solid #cbd5e1; background: #fff; color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #f8fafc; }
.btn-dark { border: 0; border-radius: 6px; padding: 10px 15px; background: var(--dark); color: #fff; font-size: 14px; font-weight: 800; cursor: pointer; }
.btn-dark:hover { background: var(--dark-hover); }
.btn-danger { border: 1px solid #fecaca; }
.btn-cancel { background: #ffedd5; color: #9a3412; }
.btn-cancel:disabled { cursor: wait; opacity: .7; }

.queue-section { margin-top: 4px; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-head h2 { font-size: 20px; }
.section-description { margin: 4px 0 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.queue-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.queue-actions button { padding: 10px 15px; font-size: 14px; font-weight: 800; cursor: pointer; }
.job-list { gap: 16px; }
.job-list { display: grid; }
.job { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }
.job-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.job-name { font-size: 16px; }
.job-name { font-weight: 800; overflow-wrap: anywhere; }
.pill { display: inline-flex; flex: 0 0 auto; padding: 4px 9px; border-radius: 999px; background: #f1f5f9; color: #334155; font-size: 12px; font-weight: 800; }
.pill.queued { background: #fef3c7; color: #92400e; }
.pill.processing { background: #e0f2fe; color: #075985; }
.pill.done { background: #dcfce7; color: #166534; }
.pill.failed { background: #fee2e2; color: #991b1b; }
.pill.cancelling { background: #ffedd5; color: #9a3412; }
.pill.cancelled { background: #e5e7eb; color: #4b5563; }
.progress { width: 100%; height: 8px; margin: 12px 0 8px; overflow: hidden; border-radius: 999px; background: #e2e8f0; }
.bar { height: 100%; background: linear-gradient(90deg, #2563eb, #06b6d4); transition: width .25s; }
.job-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 12px; padding-top: 2px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.job-meta .message { grid-column: 1 / -1; }
.empty-state { padding: 32px; border: 1px dashed #cbd5e1; border-radius: var(--radius); background: #fff; color: var(--muted); text-align: center; }

.modal { position: fixed; inset: 0; z-index: 30; display: none; align-items: center; justify-content: center; padding: 12px; background: rgba(15, 23, 42, .6); }
.modal.open { display: flex; }
.modal-panel { display: flex; width: calc(100vw - 24px); height: calc(100vh - 24px); max-width: none; max-height: none; flex-direction: column; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: 0 25px 50px rgba(15, 23, 42, .25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 66px; padding: 13px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { min-width: 0; margin: 0; font-size: 18px; line-height: 1.4; overflow-wrap: anywhere; }
.modal-head-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 8px; }
.meta-toggle-btn, .modal-close-btn { display: inline-flex; align-items: center; justify-content: center; border: 1px solid #cbd5e1; background: #fff; color: #475569; font-weight: 700; cursor: pointer; }
.meta-toggle-btn { min-height: 38px; padding: 8px 13px; font-size: 13px; }
.meta-toggle-btn::before { content: "−"; margin-right: 7px; color: var(--primary); font-size: 16px; line-height: 1; }
.meta-toggle-btn[aria-expanded="false"]::before { content: "+"; }
.modal-close-btn { width: 38px; height: 38px; padding: 0; border-color: transparent; background: #f1f5f9; font-size: 24px; font-weight: 400; line-height: 0; }
.modal-close-btn span { display: block; line-height: 1; transform: translateY(-1px); }
.meta-toggle-btn:hover, .modal-close-btn:hover { border-color: #94a3b8; background: #f8fafc; color: #0f172a; }
.meta-toggle-btn:focus-visible, .modal-close-btn:focus-visible, .result-toolbar button:focus-visible, .result-ai-toggle:focus-visible, .result-ai-panel button:focus-visible, .version-tabs button:focus-visible { outline: 3px solid rgba(37, 99, 235, .22); outline-offset: 2px; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; }
.result-toolbar { align-items: center; flex: 0 0 auto; justify-content: flex-end; gap: 12px; margin-top: 12px; padding: 10px 12px; border: 1px solid #e2e8f0; border-radius: 8px; background: #f8fafc; }
.result-action-group { display: flex; min-width: 0; flex-wrap: wrap; align-items: center; gap: 8px; }
.result-processing-actions { display: grid; width: 100%; grid-template-columns: minmax(0, .9fr) 1px minmax(0, 1.4fr); align-items: stretch; gap: 14px; }
.result-operation-section { min-width: 0; }
.result-operation-section h3 { margin: 0 0 10px; color: #1e293b; font-size: 15px; }
.result-operation-fields { display: grid; min-width: 0; align-items: end; gap: 10px; }
.cleanup-operation-fields { grid-template-columns: minmax(180px, 1fr) auto; }
.translation-operation-fields { grid-template-columns: minmax(160px, 1fr) minmax(130px, .7fr) auto; }
.result-operation-fields label { min-width: 0; margin: 0; }
.result-operation-fields label > span { display: block; margin-bottom: 6px; color: #475569; font-size: 12px; font-weight: 700; }
.result-operation-buttons { display: flex; align-items: center; gap: 8px; }
.cleanup-revert-btn { grid-column: 1 / -1; justify-self: start; }
.result-operation-separator { width: 1px; background: #cbd5e1; }
.result-output-actions { justify-content: flex-end; width: 100%; margin-left: 0; }
.result-toolbar button { min-height: 40px; padding: 9px 14px; border-radius: 6px; white-space: nowrap; }
.result-toolbar .btn-primary { box-shadow: 0 1px 2px rgba(30, 64, 175, .2); }
.result-toolbar .btn-cancel { border: 1px solid #fed7aa; background: #fff7ed; }
.result-toolbar .btn-secondary { border-color: #cbd5e1; background: #fff; color: #334155; }
.result-toolbar .btn-secondary:hover:not(:disabled) { border-color: #94a3b8; background: #f1f5f9; color: #0f172a; }
.result-ai-section { flex: 0 0 auto; margin-top: 12px; overflow: hidden; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; }
.result-ai-section[hidden] { display: none; }
.result-ai-toggle { display: flex; width: 100%; min-height: 44px; align-items: center; justify-content: space-between; padding: 10px 14px; border-radius: 0; background: #f8fafc; color: #334155; text-align: left; }
.result-ai-toggle::after { content: "+"; color: var(--primary); font-size: 20px; font-weight: 500; line-height: 1; }
.result-ai-toggle[aria-expanded="true"]::after { content: "−"; }
.result-ai-panel { padding: 14px; border-top: 1px solid #e2e8f0; background: #f8fafc; }
.result-ai-panel[hidden] { display: none; }
.result-ai-panel button { min-height: 40px; padding: 9px 14px; border-radius: 6px; white-space: nowrap; }
.result-ai-panel .btn-cancel { border: 1px solid #fed7aa; background: #fff7ed; }
.result-progress { flex: 0 0 auto; margin: 0 0 14px; padding: 12px; border: 1px solid #bfdbfe; border-radius: var(--radius); background: #eff6ff; }
.result-progress[hidden] { display: none; }
.result-progress-head { display: flex; justify-content: space-between; gap: 12px; color: #1e3a8a; font-size: 13px; font-weight: 800; }
.result-progress .progress { margin: 9px 0 0; }
.result-progress.failed { border-color: #fecaca; background: #fef2f2; }
.result-progress.failed .result-progress-head { color: #991b1b; }
.translation-controls { display: block; min-width: 0; }
.result-operation-fields select { width: 100%; min-width: 0; height: 40px; padding: 8px 34px 8px 11px; border-color: #cbd5e1; background-color: #fff; font-size: 14px; }
.modal-body { display: flex; min-height: 0; flex: 1 1 auto; flex-direction: column; padding: 18px; overflow-x: hidden; overflow-y: auto; }
.modal-meta { display: grid; max-height: 42%; flex: 0 1 auto; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 14px; margin-bottom: 14px; padding: 12px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #f8fafc; color: var(--muted); font-size: 13px; }
.modal-meta[hidden] { display: none; }
.modal-meta strong { display: block; margin-bottom: 3px; color: #334155; }
.modal-meta span { overflow-wrap: anywhere; }
.version-tabs { display: flex; flex: 0 0 auto; gap: 4px; margin-bottom: 12px; padding: 4px; overflow-x: auto; border-radius: 8px; background: #eef2f7; }
.version-tabs button { flex: 0 0 auto; min-height: 36px; padding: 7px 13px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: #475569; font-size: 13px; font-weight: 700; cursor: pointer; }
.version-tabs button:hover:not(.active) { background: rgba(255, 255, 255, .7); color: #0f172a; }
.version-tabs button.active { border-color: #dbeafe; background: #fff; color: #1d4ed8; box-shadow: 0 1px 3px rgba(15, 23, 42, .1); }
.speaker-names-section { flex: 0 0 auto; margin-bottom: 12px; padding: 12px; border: 1px solid #bfdbfe; border-radius: 8px; background: #eff6ff; }
.speaker-names-section[hidden] { display: none; }
.speaker-names-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.speaker-names-head strong { display: block; color: #1e3a8a; font-size: 14px; }
.speaker-names-head span { display: block; margin-top: 2px; color: #475569; font-size: 12px; }
.speaker-names-head button { flex: 0 0 auto; min-height: 38px; padding: 8px 13px; }
.speaker-name-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 8px 12px; margin-top: 10px; }
.speaker-name-fields label > span { display: block; margin-bottom: 4px; color: #334155; font-size: 12px; font-weight: 700; }
.speaker-name-fields label small { color: #64748b; font-weight: 500; }
.speaker-name-fields input { width: 100%; height: 38px; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; }
.speaker-transcript-blocks { display: grid; flex: 0 0 auto; gap: 10px; max-height: 300px; margin-bottom: 12px; padding: 12px; overflow: auto; border: 1px solid #dbeafe; border-radius: 8px; background: #f8fafc; }
.speaker-transcript-blocks[hidden] { display: none; }
.speaker-transcript-block { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: start; padding: 10px; border: 1px solid #e2e8f0; border-radius: 7px; background: #fff; line-height: 1.7; }
.speaker-badge { display: inline-flex; align-items: center; min-height: 28px; padding: 4px 9px; border-radius: 999px; background: #dbeafe; color: #1e3a8a; font-size: 12px; font-weight: 800; white-space: nowrap; }
.result-search { display: grid; flex: 0 0 auto; grid-template-columns: minmax(180px, 1fr) 72px 64px 64px; gap: 8px; align-items: center; margin-bottom: 12px; }
.result-search input { width: auto; min-width: 0; height: 40px; padding: 8px 11px; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; font-size: 14px; }
.result-search input:focus { outline: 3px solid rgba(37, 99, 235, .18); border-color: #3b82f6; }
.result-search-status { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; text-align: center; white-space: nowrap; }
.result-search button { min-height: 40px; padding: 8px 10px; border-radius: 6px; white-space: nowrap; }
.result-search button:disabled { cursor: default; opacity: .5; }
textarea#resultText { min-height: 240px; flex: 1 0 240px; resize: vertical; background: #020617; color: #f1f5f9; border-color: #020617; line-height: 1.75; }
.toast { position: fixed; right: 16px; bottom: 16px; z-index: 40; display: none; max-width: min(440px, calc(100vw - 32px)); padding: 13px 15px; border-radius: var(--radius); background: #111827; color: #fff; box-shadow: 0 12px 30px rgba(15,23,42,.2); line-height: 1.6; }
.toast.error { background: #991b1b; }

.page-footer { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 32px; padding-top: 16px; border-top: 1px solid #cbd5e1; color: var(--muted); font-size: 13px; }
.page-footer a { color: #1d4ed8; font-weight: 700; text-decoration: none; }

.history-toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 12px; }

.auth-body { display: grid; min-height: 100vh; place-items: center; padding: 20px; }
.auth-panel { width: min(448px, 100%); padding: 24px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }
.auth-panel h1 { margin: 0; font-size: 24px; }
.auth-panel .lead { margin: 8px 0 20px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.auth-panel button { background: var(--dark); }
.auth-panel button:hover { background: var(--dark-hover); }

@media (min-width: 640px) {
  .wrap { padding-right: 24px; padding-left: 24px; }
  .upload-panel { padding: 24px; }
}

@media (max-width: 720px) {
  .user-panel, .selection-bar, .history-toolbar { align-items: stretch; flex-direction: column; }
  .section-head { align-items: stretch; flex-direction: column; }
  .queue-actions { justify-content: stretch; }
  .queue-actions > * { flex: 1; justify-content: center; text-align: center; }
  .user-actions { width: 100%; }
  .user-actions > * { flex: 1; justify-content: center; text-align: center; }
  .modal-meta { grid-template-columns: 1fr 1fr; }
  .result-toolbar, .result-action-group { align-items: stretch; }
  .result-action-group { width: 100%; }
  .result-processing-actions { grid-template-columns: 1fr; }
  .result-operation-separator { width: 100%; height: 1px; }
  .cleanup-operation-fields, .translation-operation-fields { grid-template-columns: 1fr 1fr; }
  .speaker-names-head { align-items: stretch; flex-direction: column; }
  .speaker-names-head button { width: 100%; }
  .result-operation-buttons { align-self: end; }
  .job-meta { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .wrap { padding-top: 20px; }
  .page-hero h1 { font-size: 30px; }
  .modal { padding: 0; }
  .modal-panel { width: 100%; height: 100dvh; max-height: 100dvh; border: 0; border-radius: 0; }
  .modal-head { align-items: stretch; flex-direction: column; }
  .modal-head-actions { justify-content: flex-end; }
  .cleanup-operation-fields, .translation-operation-fields { grid-template-columns: 1fr; }
  .result-operation-buttons, .result-operation-buttons button { width: 100%; }
  .result-output-actions > button { flex: 1 1 auto; }
  .modal-meta { grid-template-columns: 1fr; }
  .result-search { grid-template-columns: 1fr 64px 64px; }
  .result-search input { grid-column: 1 / -1; }
}
