:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --pending: #d97706;
  --pending-bg: #fef3c7;
  --review: #2563eb;
  --review-bg: #dbeafe;
  --done: #059669;
  --done-bg: #d1fae5;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
h1, h2, h3 { margin: 0 0 8px; font-weight: 600; }
h2 { font-size: 18px; }
h3 { font-size: 17px; }

/* 品牌 */
.brand { display: flex; align-items: center; gap: 12px; }
.brand.small { gap: 10px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff; font-weight: 700; display: grid; place-items: center; font-size: 18px;
}
.brand.small .brand-mark { width: 30px; height: 30px; font-size: 14px; border-radius: 8px; }
.brand h1 { font-size: 22px; margin: 0; }
.brand p { margin: 0; font-size: 13px; }

/* 登录 */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--card); border-radius: 16px;
  padding: 32px; box-shadow: var(--shadow);
}
.tabs { display: flex; border-bottom: 1px solid var(--line); margin: 24px 0 20px; }
.tab {
  flex: 1; background: none; border: none; padding: 10px; cursor: pointer;
  font-size: 15px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }

/* 表单 */
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: #374151; }
input, textarea, select {
  font: inherit; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--text); width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }
textarea { resize: vertical; }
input[type="file"] { padding: 6px; }
.form-grid { display: flex; flex-direction: column; gap: 14px; }
.file-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.file-pick span { background: #f3f4f6; border-radius: 6px; padding: 2px 8px; font-size: 13px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* 按钮 */
.btn {
  font: inherit; font-size: 14px; padding: 8px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--text); white-space: nowrap;
}
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #eef2f7; color: var(--text); }
.btn.danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.success { background: var(--done); border-color: var(--done); color: #fff; }
.btn.success:hover { background: #047857; }
.btn.block { width: 100%; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* 顶栏 */
.topbar {
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 12px 24px; display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 10;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }
.badge {
  font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #eef2ff; color: #4338ca; font-weight: 500;
}

.container { max-width: 1040px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 20px; }
.card { background: var(--card); border-radius: var(--radius); padding: 20px 24px; box-shadow: var(--shadow); }

/* 统计 */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--shadow); cursor: pointer; border: 2px solid transparent; }
.stat:hover { border-color: var(--line); }
.stat.active { border-color: var(--primary); }
.stat .num { font-size: 28px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat.pending .num { color: var(--pending); }
.stat.review .num { color: var(--review); }
.stat.done .num { color: var(--done); }

/* 列表 */
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.filters { display: flex; gap: 8px; }
.filters input { width: 240px; }
.filters select { width: auto; }
.task-list { display: flex; flex-direction: column; gap: 12px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.task {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px;
  display: grid; gap: 12px;
}
.task-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.task-title { font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.task-meta { color: var(--muted); font-size: 13px; display: flex; gap: 14px; flex-wrap: wrap; }
.status {
  font-size: 12px; padding: 2px 10px; border-radius: 999px; font-weight: 600; white-space: nowrap;
}
.status.pending { background: var(--pending-bg); color: var(--pending); }
.status.review { background: var(--review-bg); color: var(--review); }
.status.done { background: var(--done-bg); color: var(--done); }

.task-body { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .task-body { grid-template-columns: 1fr; } .filters input { width: 160px; } }
.files h4 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.files ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.files li { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.files li a { color: var(--primary); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files li a:hover { text-decoration: underline; }
.files li .size { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.files .none { color: var(--muted); font-size: 13px; }
.note { background: #f9fafb; border-radius: 8px; padding: 8px 12px; font-size: 14px; white-space: pre-wrap; }
.note.warn { background: #fef2f2; color: #991b1b; }
.note b { font-weight: 600; }
.task-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; border-top: 1px dashed var(--line); padding-top: 12px; }

/* 弹窗 */
dialog {
  border: none; border-radius: 14px; padding: 24px; width: min(480px, calc(100vw - 32px));
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(17, 24, 39, 0.5); }
dialog form { display: flex; flex-direction: column; gap: 14px; }

/* toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3); z-index: 100;
}
.toast.err { background: var(--danger); }

/* 视图切换（管理员） */
.view-tabs { max-width: 1040px; margin: 16px auto -8px; padding: 0 24px; display: flex; gap: 4px; }
.view-tab {
  font: inherit; font-size: 14px; background: none; border: none; padding: 8px 16px; border-radius: 8px;
  cursor: pointer; color: var(--muted);
}
.view-tab:hover { background: #e9edf3; color: var(--text); }
.view-tab.active { background: var(--card); color: var(--primary); font-weight: 600; box-shadow: var(--shadow); }

.small-text { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }
.warn-text { color: var(--pending); }
.link-btn { font: inherit; font-size: 13px; background: none; border: none; padding: 0; color: var(--primary); cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }

/* 表格 */
.table-wrap { overflow-x: auto; }
.grid-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid-table th { text-align: left; font-weight: 500; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid-table td { padding: 6px 8px; border-bottom: 1px solid #f1f3f6; vertical-align: top; }
.grid-table td.num { text-align: right; white-space: nowrap; }
.grid-table input, .grid-table select { padding: 5px 7px; font-size: 13px; min-width: 90px; }
.grid-table input.w-s { min-width: 56px; width: 64px; }
.grid-table input.w-m { min-width: 80px; width: 96px; }
.sku-table td { vertical-align: middle; }

/* 合同解析结果 */
.parsed { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.empty-parsed, .parsed.failed, .parsed.running { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.parsed.failed { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.parsed.running { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.parsed.done { background: #fcfcfd; }
.parsed.done summary { cursor: pointer; list-style: none; display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.parsed.done summary::-webkit-details-marker { display: none; }
.parsed.done summary::before { content: "▸"; color: var(--muted); }
.parsed.done[open] summary::before { content: "▾"; }
.parsed-body { display: grid; gap: 12px; margin-top: 12px; }
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 4px 20px; }
.kv-grid > div { display: flex; gap: 8px; font-size: 13px; }
.kv-grid .k { color: var(--muted); flex-shrink: 0; width: 84px; }
.kv-grid .v { word-break: break-all; }
.parsed-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.parsed-foot .btns { display: flex; gap: 6px; flex-wrap: wrap; }
.sku-tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 6px; background: #ecfdf5; color: #047857; }
.sku-tag.manual { background: #eef2ff; color: #4338ca; }
.sku-tag.none { background: #fef3c7; color: #92400e; }
.spinner {
  width: 14px; height: 14px; border-radius: 50%; border: 2px solid #bfdbfe; border-top-color: #2563eb;
  animation: spin 0.8s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 宽弹窗与表单栅格 */
dialog.wide { width: min(1000px, calc(100vw - 32px)); }
dialog h4 { margin: 4px 0 -4px; font-size: 14px; color: var(--muted); font-weight: 500; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
#sku-dialog { width: min(620px, calc(100vw - 32px)); }

/* 拖拽上传 */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 14px; color: #374151; }
.dropzone {
  border: 2px dashed #cbd5e1; border-radius: 12px; background: #f8fafc; padding: 18px;
  cursor: pointer; transition: border-color .15s, background .15s; outline: none;
}
.dropzone:hover, .dropzone:focus-visible { border-color: #93c5fd; background: #f0f7ff; }
.dropzone.dragover { border-color: var(--primary); background: #e0edff; }
.dropzone.has-files { padding: 12px; }
.dz-prompt { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; font-size: 14px; pointer-events: none; }
.dropzone.has-files .dz-prompt { flex-direction: row; justify-content: center; gap: 8px; }
.dropzone.has-files .dz-prompt .muted, .dropzone.has-files .dz-icon { display: none; }
.dz-icon {
  width: 36px; height: 36px; border-radius: 50%; background: #e0e7ff; color: var(--primary);
  display: grid; place-items: center; font-size: 16px; margin-bottom: 4px;
}
.dropzone.dragover .dz-icon { background: var(--primary); color: #fff; }
.dz-link { color: var(--primary); margin-left: 2px; }
.dropzone .file-pick { margin-top: 0; justify-content: center; }
.dropzone.has-files .file-pick { margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: #fff !important; border: 1px solid var(--line);
  border-radius: 8px !important; padding: 3px 4px 3px 10px !important; font-size: 13px; max-width: 100%;
}
.chip em { font-style: normal; color: var(--muted); font-size: 12px; }
.chip-x {
  border: none; background: none; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1;
  width: 22px; height: 22px; border-radius: 6px;
}
.chip-x:hover { background: #fee2e2; color: var(--danger); }
.shake { animation: shake .4s; border-color: var(--danger) !important; }
@keyframes shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }

/* 系统设置 */
.ai-status { display: flex; align-items: center; gap: 8px; background: #f8fafc; border-radius: 10px; padding: 10px 14px; margin: 12px 0 16px; font-size: 14px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #cbd5e1; flex-shrink: 0; }
.dot.on { background: var(--done); box-shadow: 0 0 0 3px var(--done-bg); }
.provider-box { border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px 6px; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.provider-box legend { font-weight: 600; padding: 0 6px; }
.provider-box p { margin: 0; }
.key-row { display: flex; gap: 8px; align-items: center; }
.key-row input { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.test-result { font-size: 13px; min-height: 1em; margin: 0 0 6px !important; }
.test-result.ok { color: var(--done); }
.test-result.bad { color: var(--danger); }

/* 新建任务：解析 */
.parse-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.parse-row .small-text { display: inline-flex; align-items: center; gap: 6px; }
.parse-preview { border: 1px solid #bfdbfe; background: #f5f9ff; border-radius: 10px; padding: 12px 14px; display: grid; gap: 10px; }
.spinner.inline { width: 12px; height: 12px; display: inline-block; }
.ok-text { color: var(--done); }
.err-text { color: var(--danger); }

/* 销售方信息 */
.seller-row { display: flex; gap: 10px; align-items: flex-end; }
.seller-row label { flex: 1; }
.seller-row .btn { margin-bottom: 2px; }
#seller-form .actions { align-items: center; }
#seller-form input[name="taxId"], #seller-form input[name="bankAccount"] { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
