:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #14171c;
  --muted: #5f6774;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #eef0ff;
  --ok: #138a4b;
  --ok-soft: #e6f6ed;
  --warn: #a15c00;
  --warn-soft: #fff4e0;
  --err: #c02d2d;
  --err-soft: #fdecec;
  --info: #1f6fd1;
  --info-soft: #e8f1fd;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --border: #2b303a;
    --text: #e8eaee;
    --muted: #9aa2af;
    --accent: #8b85ff;
    --accent-text: #0f1115;
    --accent-soft: #24234a;
    --ok: #4ccf8a;
    --ok-soft: #13301f;
    --warn: #f0b04a;
    --warn-soft: #33260f;
    --err: #ff7b7b;
    --err-soft: #3a1717;
    --info: #6aa8ff;
    --info-soft: #14243b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .9em; }

/* ---- layout ------------------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner, .container { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.topbar-inner { display: flex; align-items: center; gap: 24px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text);
}
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--muted); padding: 6px 12px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.container { padding-top: 32px; padding-bottom: 64px; }
.page-head { margin-bottom: 24px; }
.page-head h1 { font-size: 28px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -.02em; }
.page-head p { margin: 0; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.stack { display: grid; gap: 24px; }

/* ---- cards ------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h2 { margin: 0; font-size: 15px; font-weight: 600; }

/* ---- forms ------------------------------------------------------------- */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.hint { color: var(--muted); font-size: 13px; font-weight: 400; }
.field { margin-bottom: 18px; }
input[type=text], input[type=url], input[type=password], select {
  width: 100%; height: 42px; padding: 0 12px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.url-input { height: 50px !important; font-size: 16px !important; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 160px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; margin: 0; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
details.advanced { margin: 4px 0 18px; }
details.advanced summary { cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 500; user-select: none; }
details.advanced[open] summary { margin-bottom: 14px; }

.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  margin: 0; display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px;
  border: 1px solid var(--border); border-radius: 999px; cursor: pointer; font-weight: 500; font-size: 14px;
  background: var(--surface);
}
.segmented label:hover { background: var(--surface-2); }
.segmented input:checked + label { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.segmented input:focus-visible + label { box-shadow: 0 0 0 3px var(--accent-soft); }
.segmented label.detected::after { content: "detected"; font-size: 11px; color: var(--accent); font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---- buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px;
  font: inherit; font-weight: 600; font-size: 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn-danger { color: var(--err); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { height: 48px; padding: 0 24px; font-size: 15px; }
.btn-block { width: 100%; }

/* ---- badges ------------------------------------------------------------ */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.completed, .badge.success { background: var(--ok-soft); color: var(--ok); }
.badge.failed { background: var(--err-soft); color: var(--err); }
.badge.processing, .badge.running { background: var(--info-soft); color: var(--info); }
.badge.processing::before, .badge.running::before { animation: pulse 1.2s ease-in-out infinite; }
.badge.queued, .badge.skipped, .badge.pending { background: var(--surface-2); color: var(--muted); }
.badge.cached { background: var(--warn-soft); color: var(--warn); }
.badge.plain::before { display: none; }
@keyframes pulse { 50% { opacity: .25; } }

/* ---- job view ---------------------------------------------------------- */
.job-title { font-size: 18px; font-weight: 650; margin: 0 0 4px; overflow-wrap: anywhere; }
.job-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; }
.job-source { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; margin: 0 0 12px; }
.player { width: 100%; max-height: 480px; background: #000; border-radius: 10px; display: block; }
.link-box { display: flex; gap: 8px; margin-top: 14px; }
.link-box input { font-family: var(--mono); font-size: 13px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-top: 16px; }
.fact { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.fact dt { color: var(--muted); font-size: 12px; }
.fact dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.section-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; margin: 20px 0 10px; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.timeline li { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: start; padding: 8px 0; }
.timeline .icon { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.timeline .success .icon { background: var(--ok-soft); color: var(--ok); }
.timeline .failed .icon { background: var(--err-soft); color: var(--err); }
.timeline .running .icon { background: var(--info-soft); color: var(--info); }
.timeline .running .icon::after { content: ""; width: 10px; height: 10px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
.timeline .name { font-weight: 600; font-size: 14px; }
.timeline .err { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; margin-top: 2px; }
.timeline .secs { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; padding-top: 2px; }
.timeline .skipped .name, .timeline .pending .name { color: var(--muted); font-weight: 500; }
@keyframes spin { to { transform: rotate(360deg); } }

.progress { height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 14px 0 4px; }
.progress span { display: block; height: 100%; width: 40%; background: var(--accent); border-radius: 4px; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }

.alert { border-radius: 10px; padding: 12px 14px; font-size: 14px; overflow-wrap: anywhere; }
.alert-err { background: var(--err-soft); color: var(--err); }
.alert-info { background: var(--info-soft); color: var(--info); }

/* ---- lists / tables ---------------------------------------------------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--border); }
.list a.item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 20px; color: var(--text); }
.list a.item:hover { background: var(--surface-2); text-decoration: none; }
.item-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { color: var(--muted); font-size: 12px; }
.empty { padding: 28px 20px; text-align: center; color: var(--muted); font-size: 14px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.title-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
td.num { font-variant-numeric: tabular-nums; color: var(--muted); }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.toolbar select { width: auto; height: 34px; }

.strategy-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.strategy-list li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.strategy-list .off { color: var(--muted); }
.provider-block + .provider-block { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.provider-block h3 { margin: 0 0 8px; font-size: 14px; display: flex; align-items: center; gap: 8px; }

/* ---- dialog / toast ---------------------------------------------------- */
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 0; width: min(440px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10, 12, 16, .45); }
dialog form { padding: 22px; }
dialog h2 { margin: 0 0 6px; font-size: 18px; }
dialog p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 500;
  transition: .2s ease; pointer-events: none; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.yt { background: #ff3b30; } .vimeo { background: #1ab7ea; } .drive { background: #1fa463; }

@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  .nav a { padding: 6px 8px; }
  .topbar-inner { gap: 12px; }
  .brand span { display: none; }
}
@media (max-width: 520px) {
  .link-box { flex-wrap: wrap; }
  .link-box .btn { flex: 1; }
  .page-head h1 { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---- links + player ---------------------------------------------------- */
.link-row { margin-top: 14px; }
.link-label { font-size: 13px; margin-bottom: 6px; }
.link-row .link-box { margin-top: 0; }
.player-wrap { margin-top: 16px; position: relative; }
.player-bar { display: flex; justify-content: flex-end; margin-top: 8px; }
.quality-select { width: auto !important; height: 32px !important; font-size: 13px; }
