:root {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --popover: 0 0% 100%;
  --popover-foreground: 240 10% 3.9%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 0 0% 98%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 240 5.9% 10%;
  --brand: 226 46% 42%;
  --brand-foreground: 0 0% 100%;
  --brand-muted: 226 40% 95%;
  --highlight: 34 72% 42%;
  --highlight-foreground: 0 0% 100%;
  --highlight-muted: 38 80% 95%;
  --radius: 0.5rem;
  --destructive-text: 0 72% 44%;
  color-scheme: light;
}
.dark {
  --background: 240 10% 3.9%;
  --foreground: 0 0% 98%;
  --card: 240 10% 3.9%;
  --card-foreground: 0 0% 98%;
  --popover: 240 10% 3.9%;
  --popover-foreground: 0 0% 98%;
  --primary: 0 0% 98%;
  --primary-foreground: 240 5.9% 10%;
  --secondary: 240 3.7% 15.9%;
  --secondary-foreground: 0 0% 98%;
  --muted: 240 3.7% 15.9%;
  --muted-foreground: 240 5% 64.9%;
  --accent: 240 3.7% 15.9%;
  --accent-foreground: 0 0% 98%;
  --destructive: 0 62.8% 30.6%;
  --destructive-foreground: 0 0% 98%;
  --border: 240 3.7% 15.9%;
  --input: 240 3.7% 15.9%;
  --ring: 240 4.9% 83.9%;
  --brand: 226 70% 74%;
  --brand-foreground: 240 10% 10%;
  --brand-muted: 226 32% 16%;
  --highlight: 38 85% 62%;
  --highlight-foreground: 24 10% 10%;
  --highlight-muted: 34 40% 14%;
  --destructive-text: 0 82% 68%;
  color-scheme: dark;
}

* { box-sizing: border-box; }
* { scrollbar-width: thin; scrollbar-color: hsl(var(--border)) transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: ui-sans-serif, system-ui, "Segoe UI", "Microsoft YaHei UI", "PingFang SC", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: hsl(var(--brand)); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: hsl(var(--muted-foreground)); }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 24px;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--background) / .95);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.brand-line { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand-line h1 { font-size: 14px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.brand-line span { font-size: 12px; color: hsl(var(--muted-foreground)); }
.spacer { flex: 1; }

/* ---------- 布局 ---------- */
.wrap { padding: 24px; max-width: 1400px; margin: 0 auto; }
.cols { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .cols { grid-template-columns: 1fr; } }

.card {
  border: 1px solid hsl(var(--border));
  border-radius: 12px;
  background: hsl(var(--card));
  padding: 24px;
}
.card + .card { margin-top: 16px; }
.card h2 { font-size: 14px; font-weight: 600; margin: 0 0 4px; }
.card p.hint { margin: 0 0 16px; font-size: 12px; color: hsl(var(--muted-foreground)); }

/* ---------- 控件 ---------- */
.btn {
  height: 36px; padding: 0 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 6px; border: 1px solid transparent;
  font: inherit; font-weight: 500; cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, opacity .15s ease;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 2px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.btn-primary:hover:not([disabled]) { background: hsl(var(--primary) / .9); }
.btn-secondary { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.btn-secondary:hover:not([disabled]) { background: hsl(var(--accent)); }
.btn-outline { background: transparent; border-color: hsl(var(--input)); color: hsl(var(--foreground)); }
.btn-outline:hover:not([disabled]) { background: hsl(var(--accent)); }
.btn-ghost { background: transparent; color: hsl(var(--foreground)); }
.btn-ghost:hover:not([disabled]) { background: hsl(var(--accent)); }
.btn-sm { height: 32px; padding: 0 10px; font-size: 13px; }

label.field { display: block; margin-bottom: 16px; }
label.field > .lbl { display: block; font-size: 13px; font-weight: 500; margin-bottom: 8px; }
select.input, input.input {
  width: 100%; height: 36px; padding: 0 10px;
  background: hsl(var(--card)); color: hsl(var(--foreground));
  border: 1px solid hsl(var(--input)); border-radius: 6px; font: inherit;
}
select.input option {
  background: hsl(var(--popover));
  color: hsl(var(--popover-foreground));
}
select.input option:checked {
  background: hsl(var(--brand-muted));
  color: hsl(var(--brand));
}
input.input:-webkit-autofill,
input.input:-webkit-autofill:hover,
input.input:-webkit-autofill:focus {
  -webkit-text-fill-color: hsl(var(--foreground));
  -webkit-box-shadow: 0 0 0 1000px hsl(var(--card)) inset;
  caret-color: hsl(var(--foreground));
}
select.input:focus, input.input:focus { outline: 1px solid hsl(var(--ring)); outline-offset: 0; border-color: hsl(var(--ring)); }
textarea.input {
  width: 100%; min-height: 76px; padding: 8px 10px; resize: vertical;
  background: hsl(var(--card)); color: hsl(var(--foreground));
  border: 1px solid hsl(var(--input)); border-radius: 6px; font: inherit; line-height: 1.5;
}
textarea.input:focus { outline: 1px solid hsl(var(--ring)); border-color: hsl(var(--ring)); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- 上传区 ---------- */
.drop {
  border: 1px dashed hsl(var(--muted-foreground) / .3);
  border-radius: 8px;
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease;
}
.drop:hover, .drop.over { border-color: hsl(var(--foreground)); background: hsl(var(--muted)); }
.drop .big { font-size: 14px; font-weight: 500; }
.drop .small { font-size: 12px; color: hsl(var(--muted-foreground)); margin-top: 4px; }

.files { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow: auto; }
.file-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border: 1px solid hsl(var(--border)); border-radius: 6px;
  font-size: 12px;
}
.file-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row button { margin-left: auto; }

/* ---------- 进度 ---------- */
.bar { height: 10px; border-radius: 999px; background: hsl(var(--secondary)); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: hsl(var(--primary)); transition: width .2s ease; }
.status-line { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; color: hsl(var(--muted-foreground)); margin-top: 8px; }

/* ---------- 日志 ---------- */
.log {
  margin-top: 12px; max-height: 260px; overflow: auto;
  background: hsl(var(--muted) / .4);
  border: 1px solid hsl(var(--border)); border-radius: 8px;
  padding: 12px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.6;
}
.log div { white-space: pre-wrap; word-break: break-word; }
.log div::before { content: "› "; color: hsl(var(--muted-foreground)); }
.log .warn { color: hsl(var(--highlight)); }
.log .err { color: hsl(var(--destructive-text)); }
.task-status.err { color: hsl(var(--destructive-text)); }
.log .ok { color: hsl(var(--foreground)); }

/* ---------- 结果 ---------- */
.result { border: 1px solid hsl(var(--border)); border-radius: 12px; padding: 16px; }
.result + .result { margin-top: 12px; }
.result-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.result-head .name { font-weight: 600; font-size: 14px; }
.badge {
  font-size: 12px; padding: 2px 8px; border-radius: 6px; border: 1px solid hsl(var(--border));
  background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground));
}
.badge.brand { background: hsl(var(--brand-muted)); color: hsl(var(--brand)); border-color: transparent; }
.badge.hl { background: hsl(var(--highlight-muted)); color: hsl(var(--highlight)); border-color: transparent; }
.badge.err { color: hsl(var(--destructive-text)); border-color: hsl(var(--destructive-text) / .5); background: transparent; }

.thumbs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 700px) { .thumbs { grid-template-columns: repeat(2, 1fr); } }
.thumb { position: relative; border: 1px solid hsl(var(--border)); border-radius: 6px; overflow: hidden; background: hsl(var(--muted) / .5); display: block; }
.thumb img { width: 100%; height: auto; display: block; }
.thumb:hover img { opacity: .92; }
.thumb .idx {
  position: absolute; left: 6px; top: 6px; font-size: 11px; padding: 1px 6px; border-radius: 4px;
  background: hsl(var(--background) / .85); border: 1px solid hsl(var(--border)); color: hsl(var(--foreground));
}

/* ---------- 登录 ---------- */
.gate { position: fixed; inset: 0; display: grid; place-items: center; background: hsl(var(--background)); z-index: 50; }
.gate .card { width: 340px; }
.gate h2 { font-size: 18px; margin: 0 0 4px; letter-spacing: -0.01em; }

.alert {
  border: 1px solid hsl(var(--destructive-text) / .45);
  color: hsl(var(--destructive-text));
  border-radius: 6px; padding: 8px 12px; font-size: 12px; margin-top: 12px;
}
.alert.info { border-color: transparent; background: hsl(var(--brand-muted)); color: hsl(var(--brand)); }
.hidden { display: none !important; }

/* ---------- 任务列表（一张图 = 一个任务） ---------- */
.summary { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sum-num { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.sum-sep { color: hsl(var(--muted-foreground)); margin: 0 2px; }

.task {
  border: 1px solid hsl(var(--border));
  border-radius: 12px;
  background: hsl(var(--card));
  padding: 16px 24px;
  margin-top: 12px;
}
.task-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.t-idx {
  font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums;
  color: hsl(var(--muted-foreground));
  border: 1px solid hsl(var(--border)); border-radius: 4px; padding: 1px 5px;
}
.t-name {
  font-size: 14px; font-weight: 500; max-width: 40ch;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.task-status { font-size: 12px; margin-top: 8px; word-break: break-word; }
.task .thumbs { margin-top: 12px; }
.task .alert { margin-top: 12px; }

.task-log { margin-top: 12px; }
.task-log summary {
  cursor: pointer; font-size: 12px; color: hsl(var(--muted-foreground));
  padding: 4px 0; user-select: none;
}
.task-log summary:hover { color: hsl(var(--foreground)); }
.task-log[open] summary { margin-bottom: 8px; }

.empty {
  border: 1px dashed hsl(var(--muted-foreground) / .3);
  border-radius: 12px; padding: 48px 24px; text-align: center; margin-top: 12px;
}
.empty .big { font-size: 14px; font-weight: 500; }
.empty .small { font-size: 12px; color: hsl(var(--muted-foreground)); margin-top: 6px; }

/* ---------- 多选下载 ---------- */
.pick {
  width: 14px; height: 14px; margin: 0 2px 0 0;
  accent-color: hsl(var(--brand)); cursor: pointer;
}
.pick:disabled { cursor: not-allowed; opacity: .35; }
.pick:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 2px; }
.task-head .pick { flex: none; }
#selInfo { font-variant-numeric: tabular-nums; }
