:root {
  --bg: #0b0f17;
  --panel: #131a27;
  --panel-alt: #182132;
  --panel-deep: #0d1320;
  --border: #263349;
  --text: #e6edf7;
  --muted: #93a3bc;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(circle at top, #131c2e 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.app-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 20px 48px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  display: grid;
  place-items: center;
  font-size: 21px;
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.35);
}

h1 {
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.83rem;
  color: var(--muted);
}

/* Workspace Tabs */
.workspace-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  background: var(--accent);
  color: #fff;
}

.tab-count {
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.tab-count.has-error {
  background: var(--danger);
  color: #fff;
}

.caps-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
}

.badge-ok {
  color: #6ee7b7;
  border-color: rgba(16, 185, 129, 0.35);
  background: rgba(16, 185, 129, 0.1);
}

.badge-warn {
  color: #fcd34d;
  border-color: rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.1);
}

.badge-neutral {
  color: #93c5fd;
  border-color: rgba(59, 130, 246, 0.35);
  background: rgba(59, 130, 246, 0.1);
}

.grid {
  display: grid;
  grid-template-columns: 1.12fr 0.88fr;
  gap: 22px;
  align-items: start;
}

@media (max-width: 960px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 1.02rem;
  font-weight: 600;
}

.panel-header h2 {
  margin: 0;
}

.dropzone {
  border: 2px dashed #334463;
  border-radius: 10px;
  padding: 22px 16px;
  text-align: center;
  background: rgba(25, 34, 51, 0.55);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.08);
}

.dropzone-icon {
  font-size: 1.65rem;
  margin-bottom: 4px;
}

.dropzone-title {
  margin: 0;
  font-size: 0.93rem;
  font-weight: 500;
}

.dropzone-hint {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.link-accent {
  color: #60a5fa;
  text-decoration: underline;
}

.source-card {
  margin-top: 14px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.source-preview-wrap video {
  width: 100%;
  max-height: 210px;
  border-radius: 8px;
  background: #000;
  display: block;
}

.meta-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
  font-size: 0.77rem;
}

.meta-tag {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--text);
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 560px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-full {
  grid-column: 1 / -1;
}

.field label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
}

.muted-inline {
  font-weight: 400;
  opacity: 0.75;
}

select,
input[type="number"],
input[type="text"],
input[type="search"] {
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.86rem;
  outline: none;
  width: 100%;
}

input[type="file"] {
  font-size: 0.8rem;
  color: var(--muted);
}

select:focus,
input:focus {
  border-color: var(--accent);
}

select:disabled,
input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Pipeline Summary Bar */
.pipeline-summary {
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--panel-deep);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.pipeline-summary strong {
  color: var(--text);
}

.pipe-arrow {
  color: #60a5fa;
  font-weight: 700;
}

/* Advanced Settings Tree */
.advanced-details {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(13, 19, 32, 0.65);
  overflow: hidden;
}

.advanced-summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 14px;
  font-size: 0.86rem;
  font-weight: 600;
  color: #93c5fd;
  cursor: pointer;
  user-select: none;
  background: var(--panel-alt);
}

.advanced-summary::-webkit-details-marker {
  display: none;
}

.advanced-details[open] .summary-chevron {
  transform: rotate(180deg);
}

.summary-chevron {
  transition: transform 0.15s ease;
}

.codec-tree {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tree-branch {
  position: relative;
  border: 1px solid var(--border);
  border-left: 3px solid #3b82f6;
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
}

#audioBranch {
  border-left-color: #10b981;
}

#subtitleBranch {
  border-left-color: #f59e0b;
}

.branch-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
}

.stream-tag {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: inline-grid;
  place-items: center;
  font-size: 0.76rem;
  font-weight: 800;
  flex-shrink: 0;
  margin-bottom: 4px;
}

.stream-v {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
}

.stream-a {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
}

.stream-s {
  background: rgba(245, 158, 11, 0.2);
  color: #fcd34d;
}

.stream-g {
  background: rgba(148, 163, 184, 0.2);
  color: #cbd5e1;
  margin-bottom: 0;
}

.branch-title-text {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.branch-select-field {
  flex: 1;
  min-width: 200px;
}

.branch-scope-field {
  width: 165px;
}

.branch-hint {
  margin: 6px 0 0 36px;
  font-size: 0.76rem;
  color: var(--muted);
}

.codec-suboptions {
  margin-top: 11px;
  margin-left: 12px;
  padding-left: 14px;
  border-left: 1px dashed #334463;
}

.subgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 560px) {
  .subgrid {
    grid-template-columns: 1fr;
  }
}

.inline-file-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  color: var(--text);
  font-size: 0.83rem;
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, opacity 0.15s ease;
}

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

.btn-sm {
  padding: 5px 10px;
  font-size: 0.77rem;
}

.btn-primary {
  flex: 1;
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--panel-alt);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: #4b6188;
}

.btn-ghost {
  background: transparent;
  color: #93c5fd;
  border-color: rgba(59, 130, 246, 0.35);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(59, 130, 246, 0.12);
}

.btn-success {
  width: 100%;
  background: var(--success);
  color: #05291e;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.4);
}

/* Status & Output */
.status-box {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.status-top,
.status-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
}

.progress-track {
  height: 9px;
  background: var(--panel-deep);
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #06b6d4);
  transition: width 0.12s linear;
}

.engine-pill {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.error-banner {
  margin-top: 12px;
  padding: 11px 14px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca;
  font-size: 0.84rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.output-card {
  margin-top: 16px;
  background: var(--panel-alt);
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: 10px;
  padding: 14px;
}

.output-preview-area video,
.output-preview-area img {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 8px;
  background: #000;
  display: block;
}

.output-preview-area audio {
  width: 100%;
  display: block;
}

.output-summary {
  margin: 10px 0 12px;
  font-size: 0.84rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
}

.history-section {
  margin-top: 18px;
}

.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.section-title-row h3 {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.history-table th,
.history-table td {
  padding: 7px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.history-table th {
  background: var(--panel-alt);
  color: var(--muted);
  font-weight: 600;
}

/* DEDICATED FULL-SIZE DEBUG CONSOLE (TAB OR POPUP MODAL) */
.console-workspace {
  width: 100%;
}

.console-workspace.popup-mode {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(5, 8, 15, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.console-card {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

.console-workspace.popup-mode .console-card {
  max-width: 1180px;
  height: 86vh;
}

.console-topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.console-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.console-title-group h2 {
  margin: 0;
  font-size: 1.05rem;
}

.console-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.console-autoscroll {
  margin-right: 6px;
}

.cli-preview-box {
  background: var(--panel-deep);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.cli-preview-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.76rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.cli-preview-code {
  display: block;
  font-size: 0.83rem;
  color: #93c5fd;
  word-break: break-all;
}

.console-filter-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill-btn {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
}

.pill-btn.active {
  background: rgba(59, 130, 246, 0.2);
  border-color: var(--accent);
  color: #93c5fd;
}

.log-search-input {
  max-width: 260px;
}

.console-viewport {
  flex: 1;
  min-height: 58vh;
  max-height: 68vh;
  overflow-y: auto;
  background: #070a10;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.55;
}

.console-workspace.popup-mode .console-viewport {
  min-height: 0;
  max-height: none;
}

.log-line {
  white-space: pre-wrap;
  word-break: break-word;
  padding: 1px 0;
  color: #cbd5e1;
}

.log-ts {
  color: #64748b;
  margin-right: 8px;
}

.log-cat-router {
  color: #67e8f9;
}

.log-cat-webcodecs {
  color: #93c5fd;
}

.log-cat-ffmpeg {
  color: #86efac;
}

.log-cat-error {
  color: #fca5a5;
  font-weight: 600;
}

.hidden {
  display: none !important;
}
