:root,
[data-theme="light"] {
  --bg: #f0f2f5;
  --surface: #fff;
  --border: #dde1e8;
  --text: #1c2333;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --input-bg: #fff;
  --log-bg: #f8f9fb;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  --ok: #059669;
  --err: #dc2626;
  --run: #2563eb;
}

[data-theme="dark"] {
  --bg: #0e1014;
  --surface: #181b22;
  --border: #2d3340;
  --text: #e8eaef;
  --muted: #9aa3b2;
  --accent: #5b8def;
  --accent-hover: #4a7de0;
  --input-bg: #12151c;
  --log-bg: #12151c;
  --shadow: none;
  --ok: #34d399;
  --err: #f87171;
  --run: #5b8def;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.wrap {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1rem 1.25rem 2rem;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.top h1 { margin: 0; font-size: 1.35rem; font-weight: 600; }
.sub { margin: 0.2rem 0 0; font-size: 0.88rem; color: var(--muted); }

.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); }

/* —— 3 cột ngang —— */
.grid-wide {
  display: grid;
  grid-template-columns: minmax(280px, 1.1fr) minmax(240px, 0.85fr) minmax(320px, 1.25fr);
  gap: 1rem;
  align-items: stretch;
}

@media (max-width: 1024px) {
  .grid-wide {
    grid-template-columns: 1fr 1fr;
  }
  .col-results { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .grid-wide { grid-template-columns: 1fr; }
  .panel { min-height: 0; height: auto; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  height: 100%;
  min-height: 460px;
  display: flex;
  flex-direction: column;
}

.col-input .file-list {
  flex: 1;
  min-height: 0;
  max-height: none;
}

.col-input .input-actions {
  margin-top: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.col-input .input-actions .btn.block {
  margin-top: 0;
}

.col-settings .settings-folds {
  margin-top: auto;
}

.col-results {
  min-height: 0;
}

.panel-title {
  margin: 0 0 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.pane-hint {
  margin: 0 0 0.65rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.kind-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  margin-bottom: 0.65rem;
}

.kind-opt {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.86rem;
  cursor: pointer;
}

.kind-opt[hidden] {
  display: none !important;
}

.kind-opt input:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.block-input {
  width: 100%;
  padding: 0.5rem 0.65rem;
  margin-bottom: 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
}

.channel-opts { margin-bottom: 0.5rem; }

.tabs {
  display: flex;
  gap: 0.3rem;
  margin-bottom: 0.65rem;
  padding: 0.2rem;
  background: var(--bg);
  border-radius: 8px;
}
.tab {
  flex: 1;
  padding: 0.4rem 0.5rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}
.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.pane.hidden { display: none; }

#urlInput {
  width: 100%;
  min-height: 160px;
  padding: 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  resize: vertical;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 2rem 1rem;
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  min-height: 140px;
  justify-content: center;
}
.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}
.dropzone input[type="file"] {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
}
.drop-title { font-weight: 500; }
.drop-hint { font-size: 0.8rem; color: var(--muted); }

.file-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  font-size: 0.8rem;
  max-height: 120px;
  overflow-y: auto;
}
.file-list li { padding: 0.12rem 0; }
.muted { color: var(--muted); }

/* —— Nhóm Video dài / Hiệu ứng (căn đều, trung tính) —— */
.settings-folds {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  width: 100%;
}

.fold-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.fold-card > summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  padding: 0.65rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
  cursor: pointer;
  list-style: none;
  user-select: none;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.fold-card > summary::-webkit-details-marker,
.fold-card > summary::marker {
  display: none;
  content: '';
}

.fold-card > summary::before {
  content: '';
  flex-shrink: 0;
  width: 0.45rem;
  height: 0.45rem;
  margin-right: 0.1rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}

.fold-card[open] > summary::before {
  transform: rotate(45deg);
}

.fold-card > summary:hover {
  background: color-mix(in srgb, var(--text) 4%, var(--bg));
}

.fold-body {
  padding: 0.65rem 0.85rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.fold-body .checks {
  margin: 0;
}

.fold-body .opts {
  margin: 0;
}

.long-video-fields {
  margin: 0;
}

.long-video-fields .check-row {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.86rem;
  margin-bottom: 0.15rem;
  cursor: pointer;
}

.field-hint {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

.job-parts {
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: 0.35rem;
}

.opts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}
.opts-2 { grid-template-columns: 1fr 1fr; }

.opt {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.opt span {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.opt input,
.opt select {
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  margin: 0.6rem 0;
  font-size: 0.85rem;
}
.checks label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.fx-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem 0.75rem;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.secondary {
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn.secondary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.btn.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
  padding: 0.3rem 0.6rem;
  font-size: 0.78rem;
}
.btn.ghost:hover { border-color: var(--accent); }
.btn.block { width: 100%; margin-top: 0.75rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* —— Kết quả —— */
.results-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.65rem;
}
.results-head .panel-title { margin: 0; flex: 1; min-width: 80px; }
.results-head .status { margin: 0; font-size: 0.82rem; flex: 2; min-width: 160px; }

.jobs-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--log-bg);
}

.jobs-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.5rem 0.5rem;
  align-items: center;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}

.job-actions {
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
}
.jobs-list li:last-child { border-bottom: none; }

.job-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  flex-shrink: 0;
}
.badge.done { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.error { background: color-mix(in srgb, var(--err) 15%, transparent); color: var(--err); }
.badge.running { background: color-mix(in srgb, var(--run) 15%, transparent); color: var(--run); min-width: 2.5rem; text-align: center; }
.badge.queued { background: var(--border); color: var(--muted); }
.badge.cancelled { background: var(--border); color: var(--muted); font-style: italic; }

.log-fold {
  margin-top: 0.65rem;
  flex-shrink: 0;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
.modal-box {
  position: relative;
  width: min(420px, 100%);
  max-height: 90vh;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.modal-box video {
  display: block;
  width: 100%;
  max-height: calc(90vh - 48px);
  background: #000;
}

.log {
  margin: 0.4rem 0 0;
  padding: 0.5rem;
  max-height: 140px;
  overflow: auto;
  font-size: 0.72rem;
  line-height: 1.35;
  white-space: pre-wrap;
  background: var(--log-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
