:root {
  --bg: #0f1115;
  --panel: #161922;
  --border: #2a2f3a;
  --fg: #e6e9ef;
  --muted: #8a93a6;
  --accent: #5aa9ff;
  --ok: #4ade80;
  --warn: #facc15;
  --err: #f87171;
  --probing: #38bdf8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC",
    "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 10;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 600; }
.topbar .actions { display: flex; gap: 8px; align-items: center; }
.muted { color: var(--muted); font-weight: normal; }
.small { font-size: 12px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin: 16px 24px;
}
.card h2 { margin: 0 0 8px; font-size: 15px; font-weight: 600; }

.form-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
.form-grid label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--muted);
}
input[type="text"], select {
  background: #0b0d12; color: var(--fg);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px; font-size: 14px;
}
input[type="text"]:focus, select:focus { outline: 1px solid var(--accent); }

button {
  background: #1f2430; color: var(--fg);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 12px; cursor: pointer; font-size: 13px;
}
button:hover:not(:disabled) { background: #2a3142; border-color: #3a4256; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); color: #0a0e16; border-color: var(--accent); font-weight: 600; }
button.warn { color: var(--warn); }

.form-actions { display: flex; align-items: center; gap: 12px; }
.msg { font-size: 12px; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--err); }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button.active { background: var(--accent); color: #0a0e16; border-color: var(--accent); }

.task-list { display: grid; gap: 10px; }
.task {
  display: grid; gap: 6px;
  border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 12px; background: #0b0d12;
}
.task .row1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.task .title { font-weight: 600; }
.task .meta { color: var(--muted); font-size: 12px; }
.task .urls { font-family: ui-monospace, monospace; font-size: 12px; word-break: break-all; }
.task .urls .label { color: var(--muted); }
.task .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.task details { color: var(--muted); font-size: 12px; }
.task details pre {
  background: #060810; padding: 8px; border-radius: 4px;
  border: 1px solid var(--border); max-height: 200px; overflow: auto;
  white-space: pre-wrap; word-break: break-all; margin: 4px 0 0;
}

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
}
.badge.pending { background: #2a2f3a; color: var(--muted); }
.badge.probing { background: rgba(56, 189, 248, 0.15); color: var(--probing); }
.badge.extracting { background: rgba(56, 189, 248, 0.15); color: var(--probing); }
.badge.bt_probing { background: rgba(56, 189, 248, 0.15); color: var(--probing); }
.badge.metadata_ready { background: rgba(250, 204, 21, 0.15); color: var(--warn); }
.badge.playable { background: rgba(74, 222, 128, 0.15); color: var(--ok); }
.badge.external_ready { background: rgba(74, 222, 128, 0.25); color: var(--ok); }
.badge.expired { background: rgba(139, 92, 246, 0.12); color: #a78bfa; }
.badge.failed { background: rgba(248, 113, 113, 0.15); color: var(--err); }

.kind {
  display: inline-block; padding: 1px 6px; border-radius: 4px;
  border: 1px solid var(--border); color: var(--muted); font-size: 11px;
}

.magnet-info {
  margin-top: 4px; padding: 8px 10px; border-radius: 6px;
  background: #07090f; border: 1px dashed var(--border);
}
.magnet-info .row1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.magnet-info .urls { font-family: ui-monospace, monospace; font-size: 12px; word-break: break-all; margin-top: 4px; }
.magnet-info .urls .label { color: var(--muted); }
.magnet-info code { background: #060810; padding: 1px 4px; border-radius: 3px; }

/* === bt-probe 文件树（v0.3 T-3） === */
.bt-probe {
  margin-top: 6px; padding: 6px 8px; border-radius: 4px;
  border-top: 1px dashed var(--border);
}
.bt-probe .row1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bt-probe .label {
  font-weight: 600; color: var(--probing); letter-spacing: 0.04em;
}
.bt-probe details { margin-top: 4px; }
.bt-probe summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.bt-probe .note { margin: 6px 0 0; font-style: italic; }
table.bt-files {
  width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 6px;
}
table.bt-files th, table.bt-files td {
  border-bottom: 1px solid var(--border); padding: 4px 6px; text-align: left;
}
table.bt-files th { color: var(--muted); font-weight: 500; }
table.bt-files td.path { font-family: ui-monospace, monospace; word-break: break-all; }
table.bt-files td.size { white-space: nowrap; color: var(--muted); width: 80px; }
table.bt-files td.tag { width: 50px; }
table.bt-files tr.main td.path { color: var(--ok); font-weight: 600; }
table.bt-files tr.main td.size { color: var(--ok); }
.main-tag {
  display: inline-block; padding: 0 6px; border-radius: 3px;
  background: rgba(74, 222, 128, 0.2); color: var(--ok);
  font-size: 10px; font-weight: 600; letter-spacing: 0.03em;
}

/* === yt-dlp 候选（v0.3 T-3） === */
.extract {
  margin-top: 4px; padding: 8px 10px; border-radius: 6px;
  background: #07090f; border: 1px dashed var(--border);
}
.extract .row1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.extract .label {
  font-weight: 600; color: var(--probing); letter-spacing: 0.04em;
}
.cand-list { list-style: decimal inside; margin: 6px 0 0; padding: 0; }
.cand-list .cand {
  margin: 4px 0; padding: 6px 8px; border-radius: 4px;
  border: 1px solid var(--border); background: #0b0d12;
}
.cand-list .cand .row1 { gap: 6px; }
.cand-list .cand .cand-title { font-weight: 600; }
.cand-list .cand .urls { font-family: ui-monospace, monospace; font-size: 12px; word-break: break-all; margin-top: 4px; }
.cand-list .cand .urls .label { color: var(--muted); }
.cand-list .cand code { background: #060810; padding: 1px 4px; border-radius: 3px; }
.cand-list .cand .actions { margin-top: 6px; }

/* === in-flight 任务的"心跳"提示（v0.3 T-3 自动轮询配套） === */
.task.in-flight {
  border-color: var(--probing);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.15);
}
.task.in-flight .badge {
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

dialog {
  background: var(--panel); color: var(--fg);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 20px; min-width: 380px;
}
dialog::backdrop { background: rgba(0,0,0,0.6); }
dialog h3 { margin: 0 0 8px; }
dialog label { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; font-size: 12px; color: var(--muted); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 12px 0 0; }

.footer { padding: 16px 24px; border-top: 1px solid var(--border); margin-top: 24px; }

/* === CDN Quick Intake（Phase 1a Task B） === */
.quick-wrap { margin-top: 4px; }
.quick-wrap > summary {
  cursor: pointer; font-weight: 600; font-size: 14px; color: var(--fg);
  list-style: none;
}
.quick-wrap > summary::-webkit-details-marker { display: none; }
.quick-parse {
  padding: 8px 10px; border-radius: 6px; background: #07090f;
  border: 1px dashed var(--border); min-height: 2.5em;
}
.quick-parse .kv { margin: 2px 0; }
.task .cdn-meta { font-size: 12px; color: var(--warn); margin-top: 4px; }

/* === Sprint C：缓存下载状态 === */
.cache-status {
  margin-top: 4px; padding: 6px 8px; border-radius: 4px;
  font-size: 12px; display: flex; align-items: center; gap: 8px;
}
.cache-status.caching {
  background: #07090f; border: 1px dashed var(--border);
}
.cache-status.cached {
  background: rgba(74, 222, 128, 0.06); border: 1px solid rgba(74, 222, 128, 0.2);
}
.cache-status.failed {
  background: rgba(248, 113, 113, 0.06); border: 1px solid rgba(248, 113, 113, 0.2);
  color: var(--err);
}

.cache-bar {
  flex: 1; height: 6px; border-radius: 3px;
  background: var(--border); overflow: hidden;
}
.cache-fill {
  height: 100%; border-radius: 3px;
  background: var(--probing);
  transition: width 0.4s ease;
}
.cache-pct {
  color: var(--probing); font-weight: 600;
  font-variant-numeric: tabular-nums; min-width: 3em; text-align: right;
}
.cache-ok {
  color: var(--ok); font-weight: 600;
}
.cache-path {
  font-family: ui-monospace, monospace; font-size: 11px;
  word-break: break-all; color: var(--muted);
}

table.bt-files td.act {
  width: 60px; text-align: center;
}
table.bt-files td.act button {
  font-size: 11px; padding: 2px 8px;
}
