*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg-dark: #1a1a2e;
  --bg-panel: #16213e;
  --bg-input: #0f3460;
  --bg-track: #1a1a2e;
  --bg-clip-visual: #e94560;
  --bg-clip-audio: #0f9b58;
  --bg-clip-caption: #f5a623;
  --text-primary: #e0e0e0;
  --text-secondary: #8892a4;
  --text-muted: #5a6578;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --border: #2a2a4a;
  --scrollbar-thumb: #3a3a5a;
  --radius: 4px;
  --topbar-h: 48px;
  --transport-h: 48px;
  --statusbar-h: 28px;
  /* toolbar 36 + resize handle 5 + ruler 20 + 4 tracks × 50 = 261, plus
     headroom for the horizontal scrollbar — all four tracks stay visible */
  --timeline-h: 270px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-dark);
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }

/* ── Language Switcher ── */
.lang-switcher { display: flex; gap: 2px; align-items: center; }
.lang-btn {
  padding: 3px 6px; font-size: 16px; font-weight: 400;
  background: var(--bg-input); color: var(--text-secondary);
  border-radius: var(--radius); min-width: 30px; text-align: center;
  line-height: 1.4; opacity: 0.6;
}
.lang-btn.active { opacity: 1; }
.lang-btn:hover { background: #1a4a80; color: var(--text-primary); }
.lang-btn.active { background: var(--accent); color: #fff; }

/* ── Buttons ── */
button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  padding: 5px 12px;
  transition: background 0.15s;
}
button:hover { background: #1a4a80; }
button:disabled { opacity: 0.4; cursor: default; }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-danger { background: #c0392b; color: #fff; }
.btn-danger:hover { background: #e74c3c; }

/* ── Inputs ── */
input[type="text"], input[type="number"], input[type="password"],
textarea, select {
  font-family: inherit;
  font-size: 12px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px;
  outline: none;
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
}
input[type="range"] {
  accent-color: var(--accent);
}
input[type="color"] {
  padding: 0;
  width: 32px;
  height: 26px;
  border: 1px solid var(--border);
  background: none;
  cursor: pointer;
}
label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--text-secondary);
  flex: 1;
}
label.full-width { flex-basis: 100%; }

/* ── Top Bar ── */
#topbar {
  height: var(--topbar-h);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}
.logo span { color: var(--accent); }
.project-name {
  font-size: 13px;
  color: var(--text-secondary);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tb-btn { padding: 5px 14px; }
.tb-primary { background: var(--accent); color: #fff; }
.tb-primary:hover { background: var(--accent-hover); }
.tb-separator {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

/* ── Main Workspace ── */
#workspace {
  display: flex;
  height: calc(100vh - var(--topbar-h) - var(--transport-h) - var(--timeline-h) - var(--statusbar-h));
  overflow: hidden;
}

#transport {
  height: var(--transport-h);
  flex-shrink: 0;
}

/* ── Panels ── */
.panel { display: flex; flex-direction: column; }

.vsplitter {
  width: 5px;
  background: var(--border);
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.15s;
}
.vsplitter:hover, .vsplitter.dragging { background: var(--accent); }

.sidebar-tab.drop-target {
  background: rgba(233, 69, 96, 0.15);
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}

/* ── Toasts ── */
.toast-host {
  position: fixed;
  top: 60px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9000;
  pointer-events: none;
  max-width: 360px;
}
.toast {
  pointer-events: auto;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  box-shadow: 0 6px 18px rgba(0,0,0,0.4);
  color: var(--text);
  font-size: 12px;
  line-height: 1.4;
  cursor: pointer;
  opacity: 0;
  transform: translateX(20px);
  transition: opacity 0.18s, transform 0.18s;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-info { border-left: 3px solid var(--accent); }
.toast-success { border-left: 3px solid #2ecc71; }
.toast-error { border-left: 3px solid #e74c3c; }
.toast-warn { border-left: 3px solid #f5a623; }
.toast { display: flex; align-items: center; gap: 10px; }
.toast-action {
  margin-left: auto;
  padding: 4px 10px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  font-weight: 600;
}
.toast-action:hover { filter: brightness(1.15); }

.ducking-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-secondary);
  cursor: pointer;
}
.ducking-toggle input { margin: 0; }
.panel-header {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}
.panel-header h2 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-secondary); }
.panel-body { flex: 1; overflow-y: auto; padding: 8px; }
.panel-section { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.panel-section h3 { font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; margin-bottom: 8px; }

#panel-media { width: 260px; min-width: 180px; flex-shrink: 0; }
#panel-props { width: 260px; min-width: 180px; flex-shrink: 0; }

/* ── Drop Zone ── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
}
.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.08);
}
.drop-zone p { color: var(--text-muted); margin-bottom: 8px; font-size: 12px; }

.asr-drop-zone { padding: 12px; margin-bottom: 8px; }
.asr-controls { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.asr-controls .lang-select { width: 100%; padding: 4px 6px; }

/* ── Media Tabs ── */
.media-tabs {
  display: flex;
  gap: 2px;
  margin-top: 10px;
}
.media-tab {
  flex: 1;
  padding: 5px;
  font-size: 11px;
  text-align: center;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  color: var(--text-muted);
}
.media-tab.active { background: var(--bg-panel); color: var(--text-primary); }

.media-list {
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--bg-panel);
}
.media-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  cursor: grab;
  transition: background 0.1s;
  font-size: 12px;
}
.media-item:hover { background: rgba(233, 69, 96, 0.08); }
.media-item:last-child { border-bottom: none; }
.media-thumb {
  width: 36px;
  height: 28px;
  object-fit: cover;
  border-radius: 2px;
  background: var(--bg-dark);
  flex-shrink: 0;
}
.media-thumb-placeholder {
  width: 36px;
  height: 28px;
  border-radius: 2px;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.media-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.media-item-duration { color: var(--text-muted); font-size: 11px; flex-shrink: 0; }
.media-item-actions { display: flex; gap: 4px; flex-shrink: 0; }
.media-item-actions button { padding: 2px 6px; font-size: 11px; }

/* ── Text Clips ── */
.text-clip-controls { display: flex; flex-direction: column; gap: 6px; }
.text-clip-controls textarea { resize: vertical; min-height: 40px; }
.text-clip-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  cursor: grab;
  transition: background 0.1s;
  font-size: 12px;
}
.text-clip-item:hover { background: rgba(245, 166, 35, 0.12); }
.text-clip-item:last-child { border-bottom: none; }
.text-clip-item.dragging { opacity: 0.4; }
.text-clip-icon {
  width: 24px;
  height: 24px;
  border-radius: 3px;
  background: var(--bg-clip-caption);
  color: #1a1a2e;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.text-clip-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.text-clip-actions { display: flex; gap: 4px; flex-shrink: 0; }
.text-clip-actions button { padding: 2px 6px; font-size: 11px; }

.track-clips.drop-highlight {
  background: rgba(245, 166, 35, 0.1);
  outline: 2px dashed var(--bg-clip-caption);
  outline-offset: -2px;
}

.preview-container.drop-highlight-caption {
  outline: 2px dashed var(--bg-clip-caption);
  outline-offset: -2px;
}
.preview-container.drop-highlight-caption::after {
  content: 'Drop to place caption here';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(245, 166, 35, 0.9);
  color: #1a1a2e;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  pointer-events: none;
  z-index: 20;
  white-space: nowrap;
}
.preview-container { position: relative; }

/* ── TTS Controls ── */
.tts-controls { display: flex; flex-direction: column; gap: 6px; }
.tts-controls textarea { resize: vertical; min-height: 50px; }
.tts-row { display: flex; gap: 8px; align-items: end; }
.tts-row select { flex: 1; }
.tts-speed-label {
  flex-direction: row;
  align-items: center;
  gap: 4px;
  flex: 1;
}
.tts-speed-label input[type="range"] { width: 60px; }

/* ── Preview ── */
#panel-preview {
  flex: 1;
  min-width: 320px;
}
.preview-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: #000;
  min-height: 0;
}
#canvas-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  width: 100%;
}
#preview-canvas {
  max-width: 100%;
  max-height: 100%;
  background: #000;
  border-radius: 2px;
}

/* ── Transport ── */
#transport {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-panel);
  width: 100%;
  border-top: 1px solid var(--border);
}
.transport-btn {
  width: 32px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  padding: 0;
}
.time-display {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 120px;
}
.seek-bar {
  flex: 1;
  height: 6px;
  cursor: pointer;
}

/* ── Properties ── */
.prop-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  align-items: end;
}
.hint { color: var(--text-muted); font-style: italic; font-size: 12px; }
.status-msg { font-size: 11px; color: var(--text-secondary); }
.status-msg.error { color: #e74c3c; }
.status-msg.success { color: #2ecc71; }
.error-msg { color: #e74c3c; font-size: 12px; margin-top: 4px; }

/* ── Timeline ── */
#panel-timeline {
  height: var(--timeline-h);
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.timeline-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  border-bottom: 1px solid var(--border);
}
.timeline-toolbar h2 { font-size: 12px; font-weight: 600; text-transform: uppercase; color: var(--text-secondary); }
.timeline-actions { display: flex; align-items: center; gap: 8px; }
.timeline-actions label { flex-direction: row; align-items: center; gap: 4px; font-size: 11px; }
.timeline-actions input[type="range"] { width: 80px; }

#timeline-container {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  position: relative;
}

#timeline-resize-handle {
  height: 5px;
  background: var(--border);
  cursor: ns-resize;
  flex-shrink: 0;
}
#timeline-resize-handle:hover, #timeline-resize-handle.dragging {
  background: var(--accent);
}

.timeline-ruler {
  height: 20px;
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border);
  position: relative;
  min-width: 100%;
}
.ruler-tick {
  position: absolute;
  top: 0;
  height: 100%;
  border-left: 1px solid var(--border);
  font-size: 9px;
  color: var(--text-muted);
  padding-left: 3px;
  line-height: 20px;
  pointer-events: none;
}
.ruler-tick.major { border-left-color: var(--text-muted); }

#timeline-tracks {
  position: relative;
  min-width: 100%;
}

.track {
  display: flex;
  height: 48px;
  border-bottom: 1px solid var(--border);
}
.track-label {
  width: 70px;
  min-width: 70px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-dark);
  border-right: 1px solid var(--border);
  display: flex;
  align-items: center;
}
.track-clips {
  flex: 1;
  position: relative;
  min-width: 0;
}

/* ── Clips on Timeline ── */
.timeline-clip {
  position: absolute;
  top: 4px;
  height: 40px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  padding: 0 6px;
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: none;
  border: 1px solid transparent;
  transition: border-color 0.1s;
}
.timeline-clip.selected { border-color: #fff; box-shadow: 0 0 6px rgba(255,255,255,0.3); }
.timeline-clip.visual { background: var(--bg-clip-visual); color: #fff; }
.timeline-clip.audio { background: var(--bg-clip-audio); color: #fff; }
.timeline-clip.caption { background: var(--bg-clip-caption); color: #1a1a2e; }
.timeline-clip .clip-handle {
  position: absolute;
  top: 0;
  width: 6px;
  height: 100%;
  cursor: ew-resize;
}
.timeline-clip .clip-handle.left { left: 0; }
.timeline-clip .clip-handle.right { right: 0; }

/* ── Playhead ── */
.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
  pointer-events: none;
  z-index: 10;
  left: 70px;
}
.playhead::before {
  content: '';
  position: absolute;
  top: -10px;
  left: -5px;
  width: 12px;
  height: 10px;
  background: var(--accent);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

/* ── Modals ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.active:not([hidden]) {
  display: flex;
}
.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 700px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.modal-sm { width: 400px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 14px; }
.modal-close { background: none; font-size: 20px; padding: 0 4px; color: var(--text-muted); }
.modal-close:hover { color: var(--text-primary); background: none; }
.modal-body { flex: 1; padding: 16px; overflow-y: auto; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}
#json-editor {
  width: 100%;
  height: 400px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  resize: vertical;
  tab-size: 2;
}

/* ── Progress bar ── */
.progress-bar {
  height: 6px;
  background: var(--bg-dark);
  border-radius: 3px;
  overflow: hidden;
  margin: 8px 0;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.2s;
}

/* ── Statusbar ── */
#statusbar {
  height: var(--statusbar-h);
  background: var(--bg-dark);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 12px;
  font-size: 11px;
  color: var(--text-muted);
}
.statusbar-btn {
  background: none;
  color: var(--text-secondary);
  font-size: 11px;
  padding: 2px 8px;
  text-decoration: underline;
}
.statusbar-btn:hover { color: var(--text-primary); background: none; }
.token-display { margin-left: auto; }

/* ── Drag ── */
.dragging { opacity: 0.5; }
.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 999;
  opacity: 0.9;
  background: var(--bg-clip-caption);
  color: #1a1a2e;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

#preview-canvas.caption-hover { cursor: grab; }
#preview-canvas.caption-dragging { cursor: grabbing; }

/* ── Waveform ── */
.waveform-canvas {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
  opacity: 0.8;
}
.clip-label {
  position: relative;
  z-index: 1;
  pointer-events: none;
}

/* ── Context Menu ── */
.context-menu {
  position: fixed;
  z-index: 200;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  min-width: 140px;
  overflow: hidden;
}
.context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 14px;
  border-radius: 0;
  background: none;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}
.context-menu button:last-child { border-bottom: none; }
.context-menu button:hover { background: rgba(233,69,96,0.15); }

/* ── Translate row ── */
.translate-row {
  display: flex;
  gap: 4px;
  align-items: center;
}
.lang-select { flex: 1; font-size: 11px; }

/* ── Toggle labels (bold/italic checkboxes) ── */
.toggle-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-secondary);
  cursor: pointer;
  flex: 1;
}
.toggle-label input[type="checkbox"] { width: auto; }

/* ── Size presets ── */
.preset-row {
  gap: 4px;
  flex-wrap: wrap;
}
.size-preset {
  flex: 1;
  min-width: 52px;
  font-size: 10px;
  padding: 3px 6px;
  text-align: center;
  background: var(--bg-input);
}
.size-preset:hover { background: #1a4a80; }

/* ── Shortcuts modal ── */
.shortcuts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.shortcuts-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.shortcuts-table td:first-child {
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--accent);
  white-space: nowrap;
  width: 45%;
}
.shortcuts-table tr:last-child td { border-bottom: none; }

/* ── Translation confirmation modal ── */
.translate-confirm-label { font-size: 11px; color: var(--text-muted); margin: 0 0 6px; }
.translate-confirm-preview {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 10px;
}
.translate-confirm-hint { font-size: 12px; color: var(--text-muted); margin: 0; }

/* Lists under the Fetch/Add buttons (was an inline style, blocked by CSP) */
#palefo-clips-list, #text-clip-list { margin-top: 8px; }
