/* === CSS 变量（亮色默认） === */
:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0f4c81;
  --primary-hover: #1d6fae;
  --primary-soft: #eff6ff;
  --primary-bg: linear-gradient(135deg, #0f4c81, #1d6fae);
  --primary-fg: #ffffff;
  --on-primary: #ffffff;
  --ok: #059669;
  --warn: #d97706;
  --err: #dc2626;
  --gate: #7c3aed;
  --gate-soft: #f5f3ff;
  --gate-line: #c4b5fd;
  --gate-meta-bg: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --shadow-1: 0 1px 3px rgba(15, 76, 129, 0.3);
  --term-bg: #0f172a;
  --term-fg: #a5f3fc;
  --header-shadow: 0 1px 0 rgba(0, 0, 0, 0.05);
  --pulse-color: rgba(15, 76, 129, 0.4);
  --toast-bg: #0f172a;
  --toast-fg: #ffffff;
  --header-fg: #ffffff;
}

/* === 暗色主题覆盖 === */
[data-theme='dark'] {
  --bg: #0b1220;
  --panel: #111a2c;
  --line: #1f2a44;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #5aa9e6;
  --primary-hover: #7bc1f5;
  --primary-soft: rgba(90, 169, 230, 0.15);
  --primary-bg: linear-gradient(135deg, #1e3a5f, #2c5d8c);
  --primary-fg: #ffffff;
  --on-primary: #0b1220;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --gate: #a78bfa;
  --gate-soft: rgba(167, 139, 250, 0.12);
  --gate-line: #4c3a8a;
  --gate-meta-bg: #0f172a;
  --surface-2: #1a2238;
  --surface-3: #1f2a44;
  --shadow-1: 0 1px 3px rgba(0, 0, 0, 0.5);
  --term-bg: #050810;
  --term-fg: #5eead4;
  --header-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
  --pulse-color: rgba(90, 169, 230, 0.5);
  --toast-bg: #1f2a44;
  --toast-fg: #e2e8f0;
  --header-fg: #f1f5f9;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  font-family: 'Microsoft YaHei', 'PingFang SC', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  transition: background 0.2s, color 0.2s;
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--primary-bg);
  color: var(--header-fg);
  box-shadow: var(--header-shadow);
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}
.logo {
  font-size: 30px;
}
h1 {
  font-size: 18px;
  font-weight: 700;
}
.sub {
  font-size: 12px;
  opacity: 0.85;
}
.header-right {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.badge {
  background: rgba(255, 255, 255, 0.18);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  color: var(--header-fg);
}
.btn {
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  background: var(--surface-3);
  color: var(--text);
  transition: 0.15s;
}
.btn:hover {
  filter: brightness(1.05);
}
.btn.primary {
  background: #f59e0b;
  color: #fff;
  font-weight: 600;
}
.btn.approve {
  background: var(--ok);
  color: #fff;
}
.btn.reject {
  background: var(--err);
  color: #fff;
}
.btn.icon {
  padding: 6px 10px;
  font-size: 14px;
}
.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  padding: 16px 24px;
  align-items: start;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}
.panel-title {
  font-weight: 700;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--primary);
}
.factory-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.factory-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  transition: 0.15s;
  background: var(--panel);
}
.factory-item:hover {
  border-color: var(--primary);
}
.factory-item.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.factory-item.waiting {
  border-color: var(--gate);
  background: var(--gate-soft);
}
.factory-item.terminated {
  border-color: rgba(220, 38, 38, 0.4);
  background: rgba(220, 38, 38, 0.04);
  opacity: 0.7;
  position: relative;
}
.factory-item.terminated .nm {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-color: rgba(220, 38, 38, 0.4);
}
.factory-item.terminated .st {
  color: var(--err);
  font-weight: 600;
}
.factory-item .countdown {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 10px;
  background: var(--err);
  color: #fff;
  border-radius: 8px;
  font-weight: 600;
  vertical-align: middle;
  animation: pulse 1s infinite;
}
.factory-item.archived-section {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}
.factory-item.archived {
  border-color: var(--line);
  background: var(--surface-2);
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 8px;
}
.factory-item.archived .nm {
  flex: 1;
  text-decoration: none;
  margin-bottom: 0;
  color: var(--muted);
}
.factory-item.archived .restore-btn {
  flex-shrink: 0;
  padding: 3px 10px;
  font-size: 11px;
  border: 1px solid var(--primary);
  background: var(--panel);
  color: var(--primary);
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}
.factory-item.archived .restore-btn:hover {
  background: var(--primary);
  color: var(--primary-fg);
}
.factory-item.archived .archived-meta {
  font-size: 10px;
  color: var(--muted);
  flex-shrink: 0;
}
.factory-archived-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 8px 0 4px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}
.factory-archived-header button {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 2px 8px;
  font-size: 10px;
  border-radius: 4px;
  cursor: pointer;
}
.factory-archived-header button:hover {
  color: var(--primary);
  border-color: var(--primary);
}
/* 报告导出下拉菜单 */
.export-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 200px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 100;
  padding: 4px 0;
}
.export-menu a {
  display: block;
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text);
  text-decoration: none;
  transition: background 0.1s;
}
.export-menu a:hover {
  background: var(--primary-soft);
  color: var(--primary);
}
.export-menu-note {
  padding: 6px 14px 4px;
  font-size: 10px;
  color: var(--muted);
  border-top: 1px dashed var(--line);
  margin-top: 4px;
  font-style: italic;
}
.factory-item .nm {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
  word-break: break-all;
}
.factory-item .st {
  font-size: 12px;
  color: var(--muted);
}
.empty {
  color: var(--muted);
  font-size: 12px;
  padding: 8px;
}
textarea {
  width: 100%;
  height: 120px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  font-size: 12px;
  font-family: Consolas, monospace;
  resize: vertical;
  background: var(--panel);
  color: var(--text);
}
/* 输入模式切换：分段式单选 */
.mode-switch {
  display: flex;
  gap: 4px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 8px;
}
.mode-opt {
  flex: 1;
  text-align: center;
  cursor: pointer;
}
.mode-opt input {
  display: none;
}
.mode-opt span {
  display: block;
  padding: 6px 4px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--muted);
  transition: 0.15s;
  white-space: nowrap;
}
.mode-opt:hover span {
  color: var(--primary);
}
.mode-opt input:checked + span {
  background: var(--primary);
  color: var(--primary-fg);
  font-weight: 600;
  box-shadow: var(--shadow-1);
}
.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* === 拖拽上传区（P-A4/P-A5）=== */
.drop-zone {
  border: 2px dashed var(--muted);
  border-radius: 8px;
  padding: 18px 12px;
  text-align: center;
  margin-bottom: 10px;
  background: var(--bg);
  transition: all 0.15s ease;
  cursor: pointer;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.06);
}
.drop-zone.dragover {
  transform: scale(1.01);
}
.drop-icon {
  font-size: 28px;
  margin-bottom: 4px;
  opacity: 0.7;
}
.drop-text {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 4px;
}
.drop-text .link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  font-size: 13px;
}
.drop-formats {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.3px;
}
.upload-progress {
  margin-top: 10px;
}
.upload-bar {
  height: 4px;
  background: var(--muted);
  border-radius: 2px;
  overflow: hidden;
}
.upload-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.2s ease;
}
.upload-status {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  text-align: left;
}
/* === P-B 多文件进度列表 === */
.upload-files {
  margin-top: 8px;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}
.upload-file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  font-size: 11px;
  border-bottom: 1px solid var(--line);
}
.upload-file-item:last-child {
  border-bottom: none;
}
.upload-file-item .ufi-icon {
  font-size: 14px;
  flex-shrink: 0;
}
.upload-file-item .ufi-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.upload-file-item .ufi-bar {
  width: 60px;
  height: 4px;
  background: var(--muted);
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
}
.upload-file-item .ufi-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.2s ease;
}
.upload-file-item.done .ufi-fill {
  background: var(--ok);
  width: 100%;
}
.upload-file-item.err .ufi-fill {
  background: var(--err);
  width: 100%;
}
.upload-file-item .ufi-pct {
  width: 32px;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.upload-detail {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--line);
  font-size: 11px;
  line-height: 1.6;
}
.upload-result {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.5;
}
.upload-result.ok {
  background: rgba(5, 150, 105, 0.1);
  border: 1px solid rgba(5, 150, 105, 0.3);
  color: #047857;
}
.upload-result.err {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #b91c1c;
}
.upload-result button {
  margin-top: 4px;
  background: none;
  border: 1px solid currentColor;
  color: inherit;
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 4px;
  cursor: pointer;
}
.hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px;
  line-height: 1.5;
}
.events {
  max-height: 200px;
  overflow-y: auto;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.8;
}
.events div {
  border-bottom: 1px dashed var(--line);
  padding: 2px 0;
}
main {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  min-height: 70vh;
}
.placeholder-main {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60vh;
  color: var(--muted);
}
.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.detail-head h2 {
  font-size: 16px;
}
.status-pill {
  padding: 3px 12px;
  border-radius: 12px;
  font-size: 12px;
  color: #fff;
  font-weight: 600;
}
.sp-queued {
  background: #94a3b8;
}
.sp-running {
  background: var(--primary);
}
.sp-waiting_gate {
  background: var(--gate);
}
.sp-completed {
  background: var(--ok);
}
.sp-rejected {
  background: var(--err);
}
.sp-failed {
  background: var(--err);
}

/* 流水线时间线 */
.pipeline {
  display: flex;
  gap: 0;
  margin: 18px 0;
  overflow-x: auto;
  padding-bottom: 6px;
}
.pnode {
  min-width: 118px;
  text-align: center;
  position: relative;
  padding: 0 4px;
}
.pnode .dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 6px;
  font-size: 13px;
  font-weight: 700;
  background: var(--surface-3);
  color: var(--muted);
  border: 2px solid var(--line);
}
.pnode.done .dot {
  background: var(--ok);
  color: #fff;
  border-color: var(--ok);
}
.pnode.active .dot {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  animation: pulse 1.5s infinite;
}
.pnode.gate .dot {
  background: var(--gate);
  color: #fff;
  border-color: var(--gate);
}
.pnode.gate.pending-gate .dot {
  animation: pulse 1.2s infinite;
}
.pnode.gate.rejected-gate .dot {
  background: var(--err);
}
.pnode .lbl {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}
.pnode.done .lbl,
.pnode.active .lbl {
  color: var(--text);
  font-weight: 600;
}
.pnode:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 17px;
  left: calc(50% + 20px);
  width: calc(100% - 40px);
  height: 2px;
  background: var(--line);
}
.pnode.done:not(:last-child)::after {
  background: var(--ok);
}
@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 var(--pulse-color);
  }
  50% {
    box-shadow: 0 0 0 8px transparent;
  }
}

.gate-box {
  background: var(--gate-soft);
  border: 1px solid var(--gate-line);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 12px 0;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.gate-box b {
  color: var(--gate);
}
.gate-comment {
  flex: 1;
  min-width: 180px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  background: var(--panel);
  color: var(--text);
}
.gate-meta {
  width: 100%;
  font-size: 12px;
  background: var(--gate-meta-bg);
  border: 1px dashed var(--gate-line);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text);
}
.gate-meta a {
  color: var(--primary);
  font-weight: 600;
  margin-left: 10px;
}
.gate-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 9px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  background: var(--gate);
  color: #fff;
  vertical-align: middle;
  animation: pulse 1.2s infinite;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: none;
}
/* 入队反馈 toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(16px);
  background: var(--toast-bg);
  color: var(--toast-fg);
  padding: 10px 22px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: 0.25s;
  z-index: 99;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--line);
  margin: 16px 0 12px;
}
.tab {
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  border-radius: 6px 6px 0 0;
  color: var(--muted);
  background: transparent;
}
.tab.active {
  background: var(--panel);
  color: var(--primary);
  font-weight: 700;
  border: 2px solid var(--line);
  border-bottom: 2px solid var(--panel);
  margin-bottom: -2px;
}
.tabbody {
  display: none;
}
.tabbody.active {
  display: block;
}

.term {
  background: var(--term-bg);
  color: var(--term-fg);
  border-radius: 8px;
  padding: 14px;
  font-family: Consolas, monospace;
  font-size: 12px;
  line-height: 1.7;
  max-height: 360px;
  overflow-y: auto;
  white-space: pre-wrap;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  margin: 8px 0;
  background: var(--panel);
}
th,
td {
  border: 1px solid var(--line);
  padding: 7px 9px;
  text-align: left;
}
th {
  background: var(--surface-2);
}
.g-A {
  color: var(--ok);
  font-weight: 700;
}
.g-B {
  color: #2563eb;
  font-weight: 700;
}
.g-C {
  color: var(--warn);
  font-weight: 700;
}
.g-D {
  color: var(--err);
  font-weight: 700;
}
.veto-banner {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid var(--err);
  color: var(--err);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
}
.veto-pill {
  display: inline-block;
  background: var(--err);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  border-radius: 8px;
  padding: 1px 8px;
  margin-left: 6px;
  vertical-align: middle;
}
.conf-ok {
  color: var(--ok);
}
.conf-part {
  color: var(--warn);
}
.conf-no {
  color: var(--muted);
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin: 12px 0;
}
.stat-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}
.stat-card .num {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
}
.stat-card .cap {
  font-size: 12px;
  color: var(--muted);
}
iframe#report-frame {
  width: 100%;
  height: 70vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.qc-issue {
  font-size: 12px;
  color: var(--err);
  margin-top: 4px;
}

/* === 追加文件模态（Phase 2.5） === */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-box {
  background: var(--bg, #fff);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  padding: 24px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}
.modal-sub {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
  line-height: 1.5;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.drop-zone.compact {
  padding: 18px 12px;
}
.drop-zone.compact .drop-icon {
  font-size: 22px;
}
.drop-zone.over {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.06);
}
.detail-head-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.files-strip {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg-soft, #f6f7f9);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  margin: 8px 0;
  word-break: break-all;
}
.upload-result.error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #b91c1c;
}
.upload-result.success {
  background: rgba(5, 150, 105, 0.1);
  border: 1px solid rgba(5, 150, 105, 0.3);
  color: #047857;
}

/* === 品牌 chips（v2.1 per-brand）=== */
.brand-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  align-items: center;
}
.brand-chips-row.detail {
  margin-top: 8px;
  margin-bottom: 4px;
}
.brand-chip {
  display: inline-block;
  background: #0f4c81;
  color: #fff;
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  line-height: 1.6;
}
.brand-chip.more {
  background: var(--muted);
  opacity: 0.85;
}
.multi-brand-hint {
  font-size: 11px;
  color: var(--muted);
  margin-right: 4px;
  font-weight: 500;
}
.brand-section {
  margin-top: 16px;
  padding: 12px;
  background: var(--bg-soft, #f6f7f9);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.brand-section h4 {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: var(--primary);
  font-weight: 600;
}
.brand-block {
  margin-bottom: 16px;
}
.brand-block h3 {
  margin: 8px 0;
  color: var(--primary);
  font-size: 15px;
}
.brand-block h4 {
  margin: 12px 0 6px 0;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.muted {
  color: var(--muted);
  font-size: 12px;
}
