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

:root {
  --bg: #0a0a0a;
  --surface: #111;
  --surface-2: #1a1a1a;
  --surface-3: #222;
  --border: #2a2a2a;
  --border-light: #3a3a3a;
  --text: #f2f2f2;
  --text-secondary: #c0c0c0;
  --text-muted: #999;
  --text-dim: #666;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --sidebar-w: 290px;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px;
}

.app { display: flex; height: 100vh; overflow: hidden; }

/* ===================== Sidebar ===================== */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}

.sidebar-header { padding: 1.1rem 1.2rem; border-bottom: 1px solid var(--border); }
.sidebar-header h1 { font-size: 1.25rem; font-weight: 800; letter-spacing: -0.03em; }

.sidebar-actions { padding: 0.75rem; }

.btn-new-job {
  width: 100%; display: flex; align-items: center; justify-content: center;
  gap: 0.5rem; padding: 0.6rem; background: #fff; color: #0a0a0a;
  border: none; border-radius: 8px; font-size: 0.9rem; font-weight: 700;
  cursor: pointer; transition: background 0.15s;
}
.btn-new-job:hover { background: #e0e0e0; }

.sidebar-list { flex: 1; overflow-y: auto; padding: 0 0.5rem; }
.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-track { background: transparent; }
.sidebar-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-empty { text-align: center; color: var(--text-muted); font-size: 0.88rem; padding: 2rem 1rem; font-weight: 500; }

.sidebar-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.55rem 0.65rem; border-radius: 7px;
  cursor: pointer; transition: all 0.1s;
  margin-bottom: 2px; border: 1px solid transparent;
}
.sidebar-item:hover { background: var(--surface-2); }
.sidebar-item.active { background: var(--surface-3); border-color: var(--border-light); }

.sidebar-item-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.sidebar-item-dot.processing, .sidebar-item-dot.queued { background: var(--primary); }
.sidebar-item-dot.completed { background: var(--success); }
.sidebar-item-dot.error { background: var(--error); }
.sidebar-item-dot.stopped { background: var(--warning); }

.sidebar-item-info { flex: 1; min-width: 0; }

.sidebar-item-name {
  font-size: 0.88rem; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.sidebar-item-meta {
  font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.15rem; font-weight: 500;
}

.sidebar-item-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }

.sidebar-icon-btn {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 0.25rem; border-radius: 4px;
  display: flex; align-items: center; transition: all 0.1s;
}
.sidebar-icon-btn:hover { color: var(--text); background: var(--surface-3); }
.sidebar-icon-btn.delete:hover { color: var(--error); background: rgba(239,68,68,0.1); }

.sidebar-footer {
  padding: 0.65rem; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 0.3rem;
}

/* ===================== Buttons ===================== */
.btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.55rem 1.1rem; border: none; border-radius: 8px;
  cursor: pointer; font-size: 0.92rem; font-weight: 600; transition: all 0.15s;
}

.btn-ghost {
  background: transparent; color: var(--text-secondary); border: 1px solid transparent;
  font-size: 0.88rem; padding: 0.45rem 0.7rem; font-weight: 600;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-ghost-outline {
  background: transparent; color: var(--text-secondary);
  border: 1px solid var(--border-light); border-radius: 8px;
  padding: 0.55rem 1.1rem; font-size: 0.92rem; font-weight: 600;
  cursor: pointer; transition: all 0.15s;
}
.btn-ghost-outline:hover { background: var(--surface-2); color: var(--text); border-color: var(--text-dim); }

.btn-block { width: 100%; justify-content: flex-start; }

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

.btn-danger-solid { background: var(--error); color: white; }
.btn-danger-solid:hover { background: #dc2626; }

.btn-sm {
  background: none; border: 1px solid var(--border-light);
  color: var(--text-secondary); padding: 0.3rem 0.5rem;
  border-radius: 5px; cursor: pointer; display: inline-flex; align-items: center; transition: all 0.15s;
}
.btn-sm:hover { background: var(--surface-3); color: var(--text); }

.btn-close { background: none; border: none; color: var(--text-muted); font-size: 1.6rem; cursor: pointer; line-height: 1; }
.btn-close:hover { color: var(--text); }

.badge {
  background: #0a0a0a; color: #fff; font-size: 0.78rem;
  padding: 0.18rem 0.55rem; border-radius: 999px; font-weight: 700;
}

.badge-sm {
  background: var(--surface-3); color: var(--text-secondary);
  font-size: 0.72rem; padding: 0.1rem 0.45rem; border-radius: 999px; font-weight: 600;
}

/* ===================== Main ===================== */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ===================== Upload View ===================== */
.view-upload { flex: 1; display: flex; padding: 1.5rem; overflow: hidden; }

.drop-zone {
  flex: 1; display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--border-light); border-radius: 14px;
  text-align: center; cursor: pointer;
  transition: all 0.2s; background: var(--surface);
}
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--primary); background: rgba(59, 130, 246, 0.04); }
.drop-zone-content { max-width: 520px; padding: 2rem; }
.drop-zone-content svg { color: var(--text-muted); margin-bottom: 1rem; }
.drop-zone-content p { color: var(--text-secondary); font-size: 1rem; font-weight: 500; }
.browse-link { color: var(--primary); text-decoration: underline; cursor: pointer; font-weight: 600; }
.formats { font-size: 0.82rem !important; margin-top: 0.5rem; opacity: 0.6; font-weight: 500; }

/* ===================== Job View ===================== */
.view-job { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.job-bar {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.65rem 1.1rem; border-bottom: 1px solid var(--border);
  background: var(--surface); flex-shrink: 0;
}

.job-bar-info { display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }

.job-filename {
  font-size: 0.95rem; font-weight: 600; color: var(--text);
  max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.status-badge {
  font-size: 0.75rem; padding: 0.22rem 0.6rem; border-radius: 999px;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap;
}
.status-badge.queued { background: var(--surface-3); color: var(--text-secondary); }
.status-badge.processing { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.status-badge.completed { background: rgba(34, 197, 94, 0.15); color: #4ade80; }
.status-badge.error { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.status-badge.stopped { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }

.job-bar-progress { flex: 1; display: flex; align-items: center; gap: 0.85rem; }

.progress-bar { flex: 1; height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }

.progress-fill {
  height: 100%; background: var(--primary); border-radius: 3px;
  transition: width 0.3s ease; width: 0%;
}
.progress-fill.completed { background: var(--success); }

.progress-text {
  font-size: 0.82rem; color: var(--text-secondary); font-weight: 600;
  white-space: nowrap; min-width: 150px; text-align: right;
}

.job-bar-actions { flex-shrink: 0; display: flex; gap: 0.45rem; align-items: center; }

.btn-action {
  width: 38px; height: 38px; border: none; border-radius: 8px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.btn-action:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-action-play { background: var(--success); color: #fff; }
.btn-action-play:hover:not(:disabled) { background: #16a34a; }

.btn-action-stop { background: var(--warning); color: #fff; }
.btn-action-stop:hover:not(:disabled) { background: #d97706; }

.btn-action-delete { background: transparent; color: var(--text-muted); border: 1px solid var(--border-light); }
.btn-action-delete:hover:not(:disabled) { background: rgba(239,68,68,0.1); color: var(--error); border-color: var(--error); }

/* ===================== Split Panels ===================== */
.panels { flex: 1; display: flex; overflow: hidden; }

.panel { display: flex; flex-direction: column; overflow: hidden; }
.panel-logs { flex: 0 0 40%; min-width: 200px; }
.panel-transcript { flex: 1; min-width: 200px; }

.panel-divider {
  width: 4px; background: var(--border); cursor: col-resize;
  flex-shrink: 0; transition: background 0.15s;
}
.panel-divider:hover, .panel-divider.dragging { background: var(--primary); }

.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.5rem 0.85rem; border-bottom: 1px solid var(--border);
  background: var(--surface-2); font-size: 0.82rem; font-weight: 700;
  color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; flex-shrink: 0;
}

.panel-actions { display: flex; gap: 0.35rem; }
.panel-body { flex: 1; overflow-y: auto; padding: 0.85rem; }

/* Logs */
.logs-body {
  font-family: var(--font-mono); font-size: 0.8rem;
  line-height: 1.6; color: var(--text-secondary); font-weight: 500;
}

.log-entry { padding: 0.14rem 0; }
.log-time { color: var(--text-muted); margin-right: 0.5rem; user-select: none; font-weight: 600; }
.log-msg { color: var(--text-secondary); }
.log-msg.log-info { color: #60a5fa; }
.log-msg.log-ok { color: #4ade80; }
.log-msg.log-warn { color: #fbbf24; }
.log-msg.log-err { color: #f87171; }
.log-msg.log-section { color: var(--text); font-weight: 700; }

/* Transcription */
.transcript-body {
  font-size: 0.95rem; line-height: 1.85;
  white-space: pre-wrap; word-wrap: break-word; color: var(--text); font-weight: 400;
}

.placeholder { color: var(--text-muted); font-style: italic; font-size: 0.9rem; font-weight: 500; }

/* ===================== Modal ===================== */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-content {
  position: relative; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px;
  width: 90%; max-width: 600px; max-height: 80vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1.1rem 1.3rem; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.1rem; font-weight: 700; }
.modal-body { padding: 1.1rem 1.3rem; overflow-y: auto; flex: 1; }

/* Mode Modal */
.modal-mode-content { max-width: 560px; }
.mode-body { text-align: center; }
.mode-file-name { font-size: 0.88rem; color: var(--text-secondary); margin-bottom: 1.25rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.mode-card {
  background: var(--surface-2); border: 2px solid var(--border);
  border-radius: 12px; padding: 1.25rem 0.85rem; cursor: pointer;
  text-align: center; transition: all 0.2s;
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem; color: var(--text);
}
.mode-card:hover { border-color: var(--primary); background: rgba(59, 130, 246, 0.06); }
.mode-icon { color: var(--text-muted); transition: color 0.2s; }
.mode-card:hover .mode-icon { color: var(--primary); }
.mode-label { font-size: 0.95rem; font-weight: 700; }
.mode-desc { font-size: 0.78rem; color: var(--text-muted); line-height: 1.4; font-weight: 500; }

/* Keys Modal */
.add-key-form { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.input {
  background: var(--surface-2); border: 1px solid var(--border-light);
  border-radius: 7px; padding: 0.5rem 0.75rem; color: var(--text);
  font-size: 0.9rem; font-weight: 500; outline: none; transition: border-color 0.15s;
}
.input:focus { border-color: var(--primary); }
.input:first-child { flex: 1; }
.input-sm { width: 140px; flex-shrink: 0; }
.input-full { width: 100%; }
.btn-full { width: 100%; justify-content: center; margin-top: 0.5rem; padding: 0.65rem; }

.keys-list { display: flex; flex-direction: column; gap: 0.4rem; }
.key-item {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.55rem 0.7rem; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 7px; font-size: 0.85rem;
}
.key-item.inactive { opacity: 0.4; }
.key-toggle {
  width: 34px; height: 20px; border-radius: 10px; border: none;
  cursor: pointer; position: relative; transition: background 0.2s;
  flex-shrink: 0; background: var(--surface-3);
}
.key-toggle.on { background: var(--success); }
.key-toggle::after {
  content: ''; position: absolute; width: 16px; height: 16px;
  border-radius: 50%; background: white; top: 2px; left: 2px; transition: transform 0.2s;
}
.key-toggle.on::after { transform: translateX(14px); }
.key-info { flex: 1; min-width: 0; }
.key-value { font-family: var(--font-mono); font-size: 0.82rem; color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-label { font-size: 0.76rem; color: var(--text-secondary); font-weight: 500; }
.key-stats { font-size: 0.74rem; color: var(--text-secondary); text-align: right; flex-shrink: 0; font-weight: 500; }
.key-error { color: var(--error); font-size: 0.72rem; font-weight: 600; }
.key-delete { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 0.2rem; font-size: 1.1rem; line-height: 1; flex-shrink: 0; }
.key-delete:hover { color: var(--error); }

/* Password Modal */
.modal-password-content { max-width: 420px; }
.pw-notice { background: rgba(245,158,11,0.1); border: 1px solid rgba(245,158,11,0.3); color: var(--warning); padding: 0.7rem 0.9rem; border-radius: 8px; font-size: 0.9rem; font-weight: 600; margin-bottom: 1.25rem; line-height: 1.5; }
.pw-error { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); color: var(--error); padding: 0.55rem 0.8rem; border-radius: 7px; font-size: 0.88rem; font-weight: 600; margin-bottom: 1rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.9rem; font-weight: 600; margin-bottom: 0.35rem; color: var(--text-secondary); }

/* Dialog Modal (confirm/prompt) */
.modal-dialog-content { max-width: 440px; }

.dialog-message {
  font-size: 0.95rem; font-weight: 500; color: var(--text-secondary);
  line-height: 1.5; margin-bottom: 1.1rem;
}

.dialog-error {
  background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3);
  color: var(--error); padding: 0.5rem 0.75rem; border-radius: 7px;
  font-size: 0.85rem; font-weight: 600; margin-bottom: 1rem;
}

.dialog-buttons {
  display: flex; gap: 0.6rem; justify-content: flex-end; margin-top: 0.5rem;
}

/* ===================== Translation bar ===================== */
.translate-bar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.45rem 1.1rem; border-bottom: 1px solid var(--border);
  background: var(--surface-2); flex-shrink: 0;
}
.translate-bar-actions { display: flex; gap: 0.3rem; align-items: center; flex-shrink: 0; }

.btn-action-sm {
  width: 28px; height: 28px; border: none; border-radius: 6px;
  cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.15s;
}
.btn-action-sm:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-action-sm.btn-action-play { background: var(--success); color: #fff; }
.btn-action-sm.btn-action-play:hover:not(:disabled) { background: #16a34a; }
.btn-action-sm.btn-action-stop { background: var(--warning); color: #fff; }
.btn-action-sm.btn-action-stop:hover:not(:disabled) { background: #d97706; }
.btn-action-sm.btn-action-delete { background: transparent; color: var(--text-muted); border: 1px solid var(--border-light); }
.btn-action-sm.btn-action-delete:hover:not(:disabled) { background: rgba(239,68,68,0.1); color: var(--error); border-color: var(--error); }

.translate-bar-label {
  font-size: 0.78rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap;
}

/* Transcript tabs */
.transcript-tabs { display: flex; gap: 0; }
.transcript-tab {
  background: none; border: none; color: var(--text-dim);
  font-size: 0.82rem; font-weight: 600; padding: 0.2rem 0.6rem;
  cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.15s;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.transcript-tab:hover { color: var(--text-secondary); }
.transcript-tab.active { color: var(--text); border-bottom-color: var(--primary); }

/* Translate button */
.btn-translate { gap: 0.3rem; font-weight: 600; }

/* Language cards */
.modal-lang-content { max-width: 440px; }
.lang-card {
  background: var(--surface-2); border: 2px solid var(--border);
  border-radius: 10px; padding: 0.9rem; cursor: pointer;
  text-align: center; transition: all 0.2s; color: var(--text);
  font-size: 0.95rem; font-weight: 600;
}
.lang-card:hover { border-color: var(--primary); background: rgba(59, 130, 246, 0.06); }

/* OpenRouter modal */
.modal-openrouter-content { max-width: 440px; }

/* OpenRouter status dot */
.badge-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; margin-left: 0.2rem;
  background: var(--error);
}
.badge-dot.active { background: var(--success); }

/* ===================== Scrollbars ===================== */
.panel-body::-webkit-scrollbar, .modal-body::-webkit-scrollbar { width: 5px; }
.panel-body::-webkit-scrollbar-track, .modal-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb, .modal-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===================== Responsive ===================== */
@media (max-width: 768px) {
  .sidebar { width: 230px; }
  .panels { flex-direction: column; }
  .panel-logs { flex: 0 0 35%; min-width: unset; }
  .panel-divider { width: 100%; height: 4px; cursor: row-resize; }
  .panel-transcript { min-width: unset; }
  .add-key-form { flex-wrap: wrap; }
  .input-sm { width: 100%; }
}
