:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1c2433;
  --muted: #6b7486;
  --line: #e4e8ef;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eaf1ff;
  --good: #15803d;
  --good-soft: #e7f6ec;
  --bad: #c2410c;
  --bad-soft: #fdeee6;
  --warn: #b45309;
  --warn-soft: #fdf3e1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  font-size: 14px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.loc { color: var(--muted); }
.bad-text { color: var(--bad); }

h1, h2, h3 { margin: 0; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 16px; margin-bottom: 14px; }

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { border-color: #cbd2de; background: #f8f9fc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(0, 0, 0, 0.04); }
.btn.block { width: 100%; height: 40px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn.loading::after {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.link {
  border: 0;
  background: none;
  padding: 2px 4px;
  color: var(--primary);
  font: inherit;
  cursor: pointer;
}
.link:hover { text-decoration: underline; }
.link.danger { color: var(--bad); }
.link:disabled { color: #b6bcc8; cursor: default; text-decoration: none; }

/* 表单 */
label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; margin-bottom: 12px; }
input[type=text], input:not([type]), input[type=password], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-weight: 400;
  color: var(--text);
  background: #fff;
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
label.check { flex-direction: row; align-items: flex-start; gap: 8px; font-weight: 400; }
label.check input { margin-top: 3px; }
.form-error { color: var(--bad); min-height: 1em; margin: 4px 0 8px; font-size: 13px; }

/* 登录 */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand.small { margin: 0; gap: 10px; }
.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.brand.small .logo { width: 30px; height: 30px; border-radius: 8px; font-size: 12px; }
.brand p { margin: 2px 0 0; }

/* 顶栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-actions { display: flex; gap: 4px; }

.container { max-width: 1180px; margin: 0 auto; padding: 20px 24px 48px; }

/* 状态卡片 */
.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 2fr;
  gap: 14px;
  margin-bottom: 16px;
}
.stat {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
.stat-value.good { color: var(--good); }
.stat-value.bad { color: var(--bad); }
.stat-value.warn { color: var(--warn); }
.stat-sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }

/* 卡片 */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.card-head p { margin: 4px 0 0; }
.card-head.inner { align-items: center; margin: 12px 0; }
.card-foot { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-top: 12px; }
.card-foot .muted { margin-right: auto; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

details.card > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before {
  content: "▸";
  color: var(--muted);
  transition: transform 0.15s;
}
details.card[open] > summary::before { transform: rotate(90deg); }
details.card[open] > summary { margin-bottom: 12px; }

/* 表格 */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; min-width: 860px; }
.table th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  font-size: 13px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tr.row-active { background: #f5f9ff; }
.table tr.row-disabled td { opacity: 0.55; }
.table tr.row-disabled td.col-switch, .table tr.row-disabled td.col-ops { opacity: 1; }
.table tr.direct td { background: #fbfbfd; }
.table td.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.col-use { width: 92px; white-space: nowrap; }
.col-switch { width: 64px; }
.col-ops { width: 170px; white-space: nowrap; }
.ops { display: flex; flex-wrap: wrap; gap: 2px; }
.name { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tag {
  font-weight: 500;
  font-size: 11px;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 4px;
  padding: 0 6px;
}
.order { font-weight: 600; color: var(--muted); margin-right: 6px; }
.badge {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  border-radius: 10px;
  padding: 1px 8px;
  vertical-align: middle;
}
.badge.warn { background: var(--warn); }

.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.good-pill { color: var(--good); background: var(--good-soft); }
.bad-pill { color: var(--bad); background: var(--bad-soft); }
.muted-pill { color: var(--muted); background: #eef0f4; }

/* 开关 */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; margin: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  border-radius: 22px;
  background: #cdd3dd;
  cursor: pointer;
  transition: background 0.15s;
}
.slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(16px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--primary-soft); }

/* 策略 */
.mode-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 10px; }
.mode {
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  cursor: pointer;
  font-weight: 400;
  margin: 0;
}
.mode:has(input:checked) { border-color: var(--primary); background: #f5f9ff; }
.mode input { margin-top: 3px; }
.mode strong { display: block; margin-bottom: 4px; }
.mode span { color: var(--muted); font-size: 13px; }

/* 弹窗 */
dialog {
  border: 0;
  border-radius: 14px;
  padding: 0;
  box-shadow: 0 20px 50px rgba(16, 24, 40, 0.25);
  width: min(560px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(15, 23, 42, 0.45); }
.dialog { padding: 22px 24px; }
.dialog.narrow { max-width: 420px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.spacer { flex: 1; }
.formats {
  background: #f6f7fa;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  margin: 6px 0 12px;
  white-space: pre-wrap;
}
.test-result {
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: #f6f7fa;
  font-size: 13px;
}
.test-result.ok { background: var(--good-soft); color: var(--good); }
.test-result.ok strong { color: var(--text); }
.test-result.fail { background: var(--bad-soft); color: var(--bad); }
#import-error div { font-size: 13px; }

/* 提示 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  max-width: min(640px, calc(100vw - 32px));
  padding: 10px 18px;
  border-radius: 10px;
  color: #fff;
  background: #1f2937;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  z-index: 50;
}
.toast.ok { background: #166534; }
.toast.error { background: #b91c1c; }
.toast.warn { background: #92400e; }

@media (max-width: 760px) {
  .topbar { padding: 10px 14px; }
  .container { padding: 14px 12px 40px; }
  .status-grid { grid-template-columns: 1fr 1fr; }
  .stat.wide { grid-column: 1 / -1; }
  .mode-options, .grid2 { grid-template-columns: 1fr; }
  .card { padding: 16px 14px; }
}

/* ===== 卡图库存 ===== */
.small { font-size: 12px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; background: #f1f3f7; border-radius: 4px; padding: 1px 5px; overflow-wrap: anywhere; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); border-color: #f5c6ad; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }

.status-grid.four { grid-template-columns: 1.4fr 1fr 1fr 1fr; }

.banner { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; font-size: 13px; white-space: pre-line; }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }

.tabs { display: inline-flex; background: #eef0f4; border-radius: 10px; padding: 3px; gap: 2px; }
.tab { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; cursor: pointer; font: inherit; color: var(--muted); }
.tab.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

.target { max-width: 420px; }
.gen { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 20px; }
.gen-preview { display: flex; flex-direction: column; gap: 6px; }
.preview-box { border: 1px dashed var(--line); border-radius: 10px; min-height: 240px; display: flex; align-items: center; justify-content: center; background: #fafbfc; padding: 10px; text-align: center; color: var(--muted); font-size: 13px; }
.preview-box img { max-width: 100%; max-height: 420px; border-radius: 6px; box-shadow: var(--shadow); }
.preview-box.error { color: var(--bad); }

.drop { position: relative; border: 2px dashed #cbd2de; border-radius: 12px; padding: 36px 16px; align-items: center; text-align: center; cursor: pointer; background: #fafbfc; margin: 0; }
.drop:hover, .drop.over { border-color: var(--primary); background: var(--primary-soft); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload-progress { margin-top: 10px; font-size: 13px; white-space: pre-line; }

.cardbox { border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.cardbox:last-child { margin-bottom: 0; }
.cardbox-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.cardbox-title { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cardbox-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.problems { margin: 6px 0 10px; padding: 0; list-style: none; font-size: 13px; }
.problems li { padding: 4px 10px; border-radius: 6px; margin-bottom: 4px; }
.problems li.error { background: var(--bad-soft); color: var(--bad); }
.problems li.warn { background: var(--warn-soft); color: var(--warn); }
.empty-note { color: var(--muted); padding: 14px 4px; font-size: 13px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
.tile { position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; display: flex; flex-direction: column; }
.tile.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.tile.next { border-color: var(--good); }
.tile .thumb { aspect-ratio: 1 / 1; background: #f6f7fa; display: flex; align-items: center; justify-content: center; cursor: zoom-in; border: 0; padding: 0; width: 100%; }
.tile .thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.tile .thumb .missing { color: var(--bad); font-size: 12px; padding: 8px; }
.tile .cap { padding: 6px 8px; font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; }
.tile .cap .muted { font-size: 11px; }
.tile .ops { padding: 0 6px 6px; gap: 0; }
.tile .pick { position: absolute; top: 6px; left: 6px; width: 18px; height: 18px; margin: 0; }
.tile .seq { position: absolute; top: 6px; left: 6px; background: rgba(28, 36, 51, 0.75); color: #fff; font-size: 11px; border-radius: 6px; padding: 0 6px; }
.tile.next .seq { background: var(--good); }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar select { width: auto; max-width: 260px; }
label.check.inline { margin: 0; align-items: center; }
label.check.inline input { margin-top: 0; }

.col-thumb { width: 72px; }
.mini { width: 56px; height: 56px; object-fit: contain; background: #f6f7fa; border-radius: 6px; cursor: zoom-in; display: block; }

.events { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.events li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.events li:last-child { border-bottom: 0; }
.events .lv { font-weight: 600; margin-right: 6px; }
.events .lv.error { color: var(--bad); }
.events .lv.warn { color: var(--warn); }

.help p { margin: 0 0 10px; font-size: 13px; }

dialog:has(.dialog.wide) { width: min(820px, calc(100vw - 32px)); }
.result-list { max-height: 52vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; margin: 10px 0; }
.result-row { display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); align-items: center; }
.result-row:last-child { border-bottom: 0; }
.result-row .mono { font-size: 12px; overflow-wrap: anywhere; }
.image-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.image-detail img { width: 100%; border-radius: 8px; border: 1px solid var(--line); background: #f6f7fa; }
.image-info { display: flex; flex-direction: column; }
#image-meta { font-size: 13px; margin-bottom: 12px; }
#image-meta div { margin-bottom: 3px; }
.copy-row { display: flex; gap: 6px; }
.copy-row input { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

@media (max-width: 760px) {
  .status-grid.four { grid-template-columns: 1fr 1fr; }
  .gen, .image-detail { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}
