:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --subtle: #f3f4f6;
  --raised: #f7f8fa;
  --ink: #111318;
  --ink-2: #3a3f4b;
  --muted: #5b6070;
  --faint: #9aa0ad;
  --line: #e2e4e9;
  --field: #c9cdd6;
  --accent: #c2410c;
  --accent-soft: #fff7f2;
  --accent-line: #f4c9b0;
  --on-accent: #ffffff;
  --info: #1d4ed8;
  --info-soft: #e8eefd;
  --fail: #b42318;
  --fail-soft: #fdecea;
  --warn: #a15c00;
  --inverse: #111318;
  --on-inverse: #ffffff;
  --bar: #111318;
  --bar-2: #1f2229;
  --bar-line: #3a3f4b;
  --bar-text: #f3f4f6;
  --bar-muted: #a9aebb;
  --online: #4ade80;
  --offline: #f87171;
  --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f12;
    --surface: #17191e;
    --subtle: #1f2229;
    --raised: #1b1d23;
    --ink: #ecedef;
    --ink-2: #c9cdd6;
    --muted: #9aa0ad;
    --faint: #6b7180;
    --line: #2a2e36;
    --field: #3a3f4b;
    --accent-soft: #2a1a12;
    --accent-line: #7c3a1a;
    --info: #7da2ff;
    --info-soft: #1a2442;
    --fail: #f87171;
    --fail-soft: #3a1717;
    --warn: #fbbf24;
    --inverse: #ecedef;
    --on-inverse: #111318;
    --bar: #08090b;
    color-scheme: dark;
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
}

h1, h2 { margin: 0; letter-spacing: -0.02em; }
h1 { font-size: 22px; }
h2 { font-size: 20px; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--info); }

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { margin: 0; color: var(--fail); font-size: 14px; white-space: pre-line; }
.empty { margin: 0; padding: 28px 20px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--field); border-radius: 14px; }
.empty.inset { border: 0; border-radius: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* --- top bar --------------------------------------------------------------------------- */

.topbar { background: var(--bar); color: var(--bar-text); }
.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
}
.brand { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.logo { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; }
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.brand-tagline { font-size: 12px; color: var(--bar-muted); }

.views { display: flex; gap: 4px; margin-left: 12px; padding: 4px; background: var(--bar-2); border-radius: 10px; }
.views a {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 14px;
  border-radius: 7px;
  color: #c9cdd6;
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
}
.views a:hover { color: #fff; }
.views a[aria-current="page"] { background: #f3f4f6; color: #111318; font-weight: 600; }

.server { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 12px; }
.backend { display: inline-flex; align-items: center; gap: 8px; color: var(--bar-muted); font-size: 13px; }
.select-wrap { position: relative; display: inline-flex; align-items: center; }
.select-wrap svg { position: absolute; right: 12px; pointer-events: none; color: #c9cdd6; }
.backend select {
  appearance: none;
  height: 36px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--bar-line);
  border-radius: 8px;
  background: var(--bar-2);
  color: var(--bar-text);
  font-family: var(--mono);
  font-size: 13px;
  cursor: pointer;
}
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 999px; background: var(--bar-2); color: #c9cdd6; font-family: var(--mono); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bar-muted); }
.pill.online .dot { background: var(--online); }
.pill.offline { color: #fecaca; }
.pill.offline .dot { background: var(--offline); }

/* --- shared building blocks --------------------------------------------------------------- */

.view { max-width: 1240px; margin: 0 auto; padding: 32px 24px 64px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.panel-head { display: flex; flex-direction: column; gap: 4px; }
.panel-head p { margin: 0; font-size: 14px; }

fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.group { display: flex; flex-direction: column; gap: 10px; }
.group-title { padding: 0; margin-bottom: 10px; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.group > span.group-title { margin-bottom: 0; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field legend { padding: 0; margin-bottom: 6px; }
.field select, .field input[type="url"] {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--field);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  width: 100%;
}
.field.disabled, .switch-row.disabled { opacity: 0.5; }
.hint { font-size: 12px; color: var(--muted); }

.button, .primary, .secondary, .icon-button, .small-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 10px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.button { height: 44px; padding: 0 18px; }
.button.dark { background: var(--inverse); color: var(--on-inverse); border: 0; }
.button.outline { background: var(--surface); color: var(--ink); border: 1px solid var(--field); }
.primary { height: 52px; border: 0; border-radius: 12px; background: var(--accent); color: var(--on-accent); font-size: 16px; }
.primary:disabled { opacity: 0.6; cursor: default; }
.secondary { height: 44px; padding: 0 16px; border: 1px solid var(--field); background: var(--surface); color: var(--ink-2); font-weight: 500; }
.icon-button { width: 44px; height: 44px; border: 1px solid var(--field); background: var(--surface); color: var(--ink-2); }
.small-button { height: 36px; min-width: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--field); background: var(--surface); color: var(--ink); font-size: 13px; }
.small-button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; }

.segmented { display: grid; grid-auto-columns: minmax(0, 1fr); grid-auto-flow: column; gap: 4px; padding: 4px; background: var(--subtle); border-radius: 10px; }
.seg {
  position: relative;
  height: 44px;
  border: 0;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}
.seg[aria-pressed="true"], .seg:has(input:checked) { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(17, 19, 24, 0.12); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg:has(input:focus-visible) { outline: 2px solid var(--info); outline-offset: 2px; }

.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }

/* --- jobs view ----------------------------------------------------------------------------- */

.jobs-view { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 24px; }

.new-job { flex: 1 1 360px; max-width: 460px; min-width: 0; padding: 24px; display: flex; flex-direction: column; gap: 22px; }

.drop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 150px;
  padding: 20px;
  border: 1.5px dashed var(--faint);
  border-radius: 12px;
  background: repeating-linear-gradient(90deg, var(--raised) 0 14px, var(--subtle) 14px 16px);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s;
}
.drop:hover, .drop.over, .drop:has(input:focus-visible) { border-color: var(--accent); }
.drop-icon { width: 44px; height: 44px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; color: var(--accent); }
.drop-title { font-weight: 600; }
.drop-hint { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }

.choices { display: flex; flex-direction: column; gap: 8px; }
.choice {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 60px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
}
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice-dot { width: 18px; height: 18px; flex: none; border-radius: 50%; border: 1.5px solid var(--faint); display: flex; align-items: center; justify-content: center; }
.choice-text { display: flex; flex-direction: column; gap: 2px; }
.choice-text small { font-size: 13px; color: var(--muted); }
.choice:has(input:checked) { border: 1.5px solid var(--accent); background: var(--accent-soft); }
.choice:has(input:checked) .choice-dot { border: 2px solid var(--accent); }
.choice:has(input:checked) .choice-dot::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.choice:has(input:focus-visible) { outline: 2px solid var(--info); outline-offset: 2px; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.switch-text { display: flex; flex-direction: column; }
.switch-text small { font-size: 12px; color: var(--muted); }
.switch {
  appearance: none;
  flex: none;
  width: 44px;
  height: 26px;
  margin: 0;
  border-radius: 999px;
  background: var(--field);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
}
.switch::before { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch:checked { background: var(--accent); }
.switch:checked::before { transform: translateX(18px); }
.switch:disabled { cursor: default; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--field);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-2);
  font-weight: 500;
  cursor: pointer;
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip input:checked + span { border-color: var(--inverse); background: var(--inverse); color: var(--on-inverse); }
.chip input:checked + span::before { content: "✓"; }
.chip input:focus-visible + span { outline: 2px solid var(--info); outline-offset: 2px; }
.chip input:disabled + span { cursor: default; }

.jobs-col { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; }
.section-head h2 { font-size: 22px; }
.jobs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 16px; }

.job { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.job-head { display: flex; align-items: flex-start; gap: 12px; }
.job-icon { width: 40px; height: 40px; flex: none; border-radius: 10px; background: var(--subtle); display: flex; align-items: center; justify-content: center; color: var(--ink-2); }
.job .icon-link, .job.youtube .icon-file { display: none; }
.job.youtube .icon-link { display: block; }
.job-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.job-name { font-size: 16px; overflow-wrap: anywhere; }
.job-sub { font-size: 12px; color: var(--muted); }
.badge { flex: none; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--subtle); color: var(--ink-2); }
.job.processing .badge { background: var(--info-soft); color: var(--info); }
.job.done .badge { background: var(--inverse); color: var(--on-inverse); }
.job.failed .badge { background: var(--fail-soft); color: var(--fail); }

.track { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.track li { display: flex; flex-direction: column; gap: 6px; min-width: 0; font-size: 11px; color: var(--muted); }
.track li::before { content: ""; display: block; height: 6px; border-radius: 3px; background: var(--line); }
.track span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track .done::before { background: var(--inverse); }
.track .running { color: var(--info); font-weight: 600; }
.track .running::before { background: var(--info); animation: pulse 1.4s ease-in-out infinite; }
.track .failed { color: var(--fail); font-weight: 600; }
.track .failed::before { background: var(--fail); }
.track .skipped { color: var(--faint); }
.track .skipped::before { background: transparent; border: 1px dashed var(--field); }
@keyframes pulse { 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) { .track .running::before { animation: none; } }

.job-detail { margin: 0; font-size: 14px; color: var(--ink-2); }
.job.processing .job-detail { color: var(--info); }
.job.failed .job-detail { color: var(--fail); }
.job-detail .warn { color: var(--warn); }
.meta { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.meta li { padding: 4px 10px; border-radius: 999px; background: var(--subtle); font: 12px var(--mono); color: var(--ink-2); }
.job-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

/* --- archive view ------------------------------------------------------------------------ */

.archive-view { display: flex; flex-direction: column; gap: 20px; }
.archive-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.archive-head h1 { font-size: 26px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.search { position: relative; display: flex; align-items: center; }
.search svg { position: absolute; left: 12px; color: var(--muted); }
.search input { height: 44px; width: 260px; max-width: 100%; padding: 0 14px 0 36px; border: 1px solid var(--field); border-radius: 10px; background: var(--surface); color: var(--ink); font-size: 14px; }

.archive-body { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 20px; }
.archive-list { flex: 999 1 520px; min-width: 0; overflow: hidden; }
.list-head { display: flex; justify-content: space-between; gap: 8px; padding: 12px 18px; border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
#archive-list { list-style: none; margin: 0; padding: 0; }
.archive-row {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 14px;
  padding: 14px 18px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
}
#archive-list li:last-child .archive-row { border-bottom: 0; }
.archive-row:hover { background: var(--raised); }
.archive-row[aria-pressed="true"] { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.row-text { flex: 1 1 260px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-name { font-weight: 600; overflow-wrap: anywhere; }
.row-key { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.row-meta { font-size: 12px; color: var(--muted); }
.tag { flex: none; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--subtle); color: var(--muted); }
.tag.ready { background: var(--inverse); color: var(--on-inverse); }
.tag.processing { background: var(--info-soft); color: var(--info); }

.archive-detail { flex: 1 1 380px; max-width: 520px; min-width: 0; padding: 22px; display: flex; flex-direction: column; gap: 18px; }
.detail-head { display: flex; flex-direction: column; gap: 4px; }
.detail-head h2 { overflow-wrap: anywhere; }
.kv { margin: 0; display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 8px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.note { margin: 0; padding: 14px; border-radius: 10px; background: var(--subtle); color: var(--ink-2); font-size: 14px; }
.report { display: flex; flex-direction: column; gap: 10px; }
.files { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.file { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.file.current { background: var(--accent-soft); border-color: var(--accent-line); }
.file-text { flex: 1 1 160px; min-width: 0; display: flex; flex-direction: column; }
.file-name { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.file-lang { font-size: 12px; color: var(--muted); }
.file-actions { display: flex; gap: 6px; }

.preview { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; background: var(--raised); border-bottom: 1px solid var(--line); font: 12px var(--mono); color: var(--ink-2); overflow-wrap: anywhere; }
.preview-body { padding: 16px; max-height: 420px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; font-size: 14px; color: var(--ink-2); }
.preview-body p { margin: 0; }
.preview-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.55 var(--sans); }
.preview-text.mono { font-family: var(--mono); font-size: 12px; }
