:root {
  --primary: #2f6fed;
  --primary-dark: #245bc4;
  --bg: #f4f6fa;
  --card: #ffffff;
  --border: #e3e8f0;
  --text: #1f2937;
  --text2: #6b7280;
  --danger: #e5484d;
  --warn: #f0a020;
  --ok: #22a06b;
  --radius: 10px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { color: var(--primary); text-decoration: none; }

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #e8efff 0%, #f4f6fa 60%);
}
.login-card {
  background: var(--card); border-radius: 16px; padding: 40px 44px;
  box-shadow: 0 12px 40px rgba(47,111,237,.12); width: 380px;
}
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card .sub { color: var(--text2); margin-bottom: 24px; }
.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 6px; color: var(--text2); font-size: 13px; }
.field input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; outline: none;
}
.field input:focus { border-color: var(--primary); }
.btn {
  display: inline-block; padding: 10px 18px; border: none; border-radius: 8px;
  background: var(--primary); color: #fff; font-size: 14px; cursor: pointer;
}
.btn:hover { background: var(--primary-dark); }
.btn.block { width: 100%; }
.btn.ghost { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { border-color: var(--primary); color: var(--primary); background: #f6f9ff; }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.err-msg { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.hint { color: var(--text2); font-size: 13px; }
.hint-list { color: var(--text2); font-size: 12px; line-height: 1.8; }

/* ---------- 主框架 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 210px; background: #101827; color: #cbd5e1; padding: 20px 0; flex-shrink: 0;
}
.sidebar .logo { padding: 0 20px 20px; font-size: 16px; font-weight: 600; color: #fff; border-bottom: 1px solid #1e293b; }
.sidebar .nav { margin-top: 12px; }
.sidebar .nav-item {
  display: block; padding: 12px 20px; cursor: pointer; color: #94a3b8;
  border-left: 3px solid transparent;
}
.sidebar .nav-item:hover { color: #e2e8f0; }
.sidebar .nav-item.active { color: #fff; background: rgba(47,111,237,.15); border-left-color: var(--primary); }
.sidebar .nav-item .badge { display: inline-block; margin-left: 6px; background: var(--danger); color: #fff; font-size: 11px; padding: 0 6px; border-radius: 8px; }
.sidebar .user { padding: 16px 20px; font-size: 13px; color: #64748b; border-top: 1px solid #1e293b; margin-top: 12px; }
.main { flex: 1; padding: 24px 28px; overflow-x: auto; }
.page { display: none; }
.page.active { display: block; }
.page h2 { font-size: 18px; margin-bottom: 16px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card h3 { font-size: 15px; margin-bottom: 14px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }

/* ---------- 表格 ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text2); font-weight: 500; font-size: 13px; white-space: nowrap; background: #fafbfe; }
tr:hover td { background: #f8faff; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 12px; white-space: nowrap; }
.tag.urgent { background: #fdecec; color: var(--danger); }
.tag.normal { background: #e9f2ff; color: var(--primary); }
.tag.defer { background: #f4f4f5; color: var(--text2); }
.tag.done { background: #e7f7f0; color: var(--ok); }
.tag.rework { background: #fef4e0; color: var(--warn); }
.tag.pending { background: #f1f3f7; color: var(--text2); }

/* ---------- 进度条 ---------- */
.proc-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.step { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 3px 8px; border-radius: 6px; background: #f1f3f7; color: var(--text2); }
.step.done { background: #e7f7f0; color: var(--ok); }
.step.cur { background: #e9f2ff; color: var(--primary); font-weight: 600; }
.step.rework { background: #fef4e0; color: var(--warn); }
.step.skip { background: #f6f6f7; color: #c2c8d2; text-decoration: line-through; }
.arrow { color: #c2c8d2; }

/* ---------- 统计卡片 ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-card .num { font-size: 26px; font-weight: 700; color: var(--primary); }
.stat-card .lbl { color: var(--text2); font-size: 13px; margin-top: 4px; }

/* ---------- 其他 ---------- */
select, textarea, input[type="text"] {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; outline: none; background: #fff;
}
select:focus, textarea:focus, input[type="text"]:focus { border-color: var(--primary); }
textarea { font-family: inherit; line-height: 1.7; resize: vertical; }
.check-row { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: #fafbfe; }
.check-row label { flex: 1; cursor: pointer; }
.check-row .sub { color: var(--text2); font-size: 12px; }
.empty { text-align: center; color: #b0b8c4; padding: 30px 0; }
.matrix-table td:first-child { font-weight: 600; }
.matrix-type-row td { background: #eef4ff; color: var(--primary); font-weight: 700; font-size: 13px; }

/* 已报废任务行：变灰 */
.scrap-row td {
  color: #9ca3af;
  background: #f7f8fa;
}
.scrap-row td .tag { filter: grayscale(0.6); opacity: 0.7; }
.scrap-toggle td { cursor: pointer; }
/* 三期需求10：暂停件行（蓝灰，可恢复） */
.paused-row td { background: #eef3fb !important; color: #374151; }
.paused-toggle td { cursor: pointer; }

/* 需求16/17：今日必完成 / 待处理审批 高亮行 */
.today-required-row td { background: #fff7e6 !important; }
.today-required-row td:first-child { box-shadow: inset 3px 0 0 #f59e0b; }
.tag.rework { background: #fff1e6; color: #d97706; }
.toast {
  position: fixed; top: 20px; right: 20px; background: #101827; color: #fff;
  padding: 10px 18px; border-radius: 8px; z-index: 999; opacity: 0; transition: opacity .3s;
}
.toast.show { opacity: 1; }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,23,42,.4); display: flex;
  align-items: center; justify-content: center; z-index: 100;
}
.modal { background: #fff; border-radius: 12px; padding: 24px 26px; width: 620px; max-width: 92vw; max-height: 88vh; overflow-y: auto; }
.modal-wide { width: 1100px; max-width: 97vw; }
.modal-wide table { font-size: 13px; }
.modal h3 { margin-bottom: 14px; }
.modal .btn-row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ============ v1.0 需求8：布局与信息层级轻量统稿 ============ */
/* 操作列多个小按钮自动间距 */
td .btn + .btn { margin-left: 6px; }
/* 弹窗内段落与区块间距收紧、层级清晰 */
.modal .hint-list { margin: 6px 0 12px; }
.modal .field + .field { margin-top: 4px; }
/* 任务详情大弹窗内工序表格区内部滚动（40 道工序不撑爆可视区） */
.modal-wide .table-scroll { max-height: 46vh; overflow: auto; }
/* 主标题与信息区层次 */
.card h3 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.page h2 { letter-spacing: .5px; }
/* 标签与辅助信息弱化，主字段突出 */
table td strong { color: var(--text); }
.hint-list strong { color: var(--text2); }
/* 工具栏按钮组视觉分组（相邻组间留白） */
.row > .btn + .btn { margin-left: 2px; }
/* 检验清单任务折叠行 hover 提示 */
.check-task-item:hover { border-color: #b8cdff !important; }
.check-task-item .row:hover { background: #f6f9ff; }

/* ============ 四批：排产/延期/临时任务 ============ */
tr.delay-row td { background: #fff4f3 !important; }
tr.delay-row .tag.danger { background: #ff4d4f; color: #fff; }
.g-row:hover { background: #f7f9ff; }
.g-row .hint { white-space: nowrap; }
#page-planning .card { margin-bottom: 16px; }

/* ============ 产能配置：每个填写框带可见标注 ============ */
.cap-field-row { display: flex; flex-wrap: wrap; gap: 12px 22px; align-items: flex-end; margin-bottom: 10px; }
.cap-field { display: flex; flex-direction: column; gap: 4px; }
.cap-label { font-size: 11.5px; color: #3f4756; white-space: nowrap; }
.cap-label i { font-style: normal; color: #99a1b0; font-size: 11px; }
.cap-actions { display: flex; }
.cap-group { background: #f7f9fd; border: 1px dashed #d4dcea; border-radius: 8px; padding: 8px 12px 0; margin-bottom: 10px; }
.cap-group-title { font-size: 12px; color: #5b6472; margin: 2px 0 8px; }
.cap-group-title b { color: #1f3f8f; }

/* 数字 / 时间输入统一控件样式 */
input[type="number"], input[type="time"], input[type="date"] {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
  outline: none; background: #fff;
}
input[type="number"]:focus, input[type="time"]:focus, input[type="date"]:focus { border-color: var(--primary); }

/* ============ 甘特图：表头=日期，每任务三行（投产计划/最新计划/实际进度） ============ */
#gantt-wrap { background: #fff; }
.gt-task { border-bottom: 1px solid #e9edf5; }
.gt-task:hover { box-shadow: inset 0 0 0 1px #d7e2f6; }
.gt-task-head { border-bottom: 1px solid #eef1f6; }
.gt-task-head:hover { background: #f2f6ff; }
.gt-gut {
  display: flex; align-items: center; gap: 5px; padding: 0 10px;
  border-right: 1px solid #eef1f6; font-size: 11px; color: #64748b;
  white-space: nowrap; overflow: hidden;
}
.gt-gut i { width: 9px; height: 9px; border-radius: 2px; flex: none; display: inline-block; }
.gbar {
  position: absolute; top: 2px; height: 15px; line-height: 15px; border-radius: 3px;
  font-size: 10px; text-align: center; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; z-index: 2; min-width: 3px; cursor: help;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .35);
}

/* ============ 第五批：整体布局 —— 左侧任务栏固定 + 内容区独立滚动 ============ */
html, body { height: 100%; }
body { overflow: hidden; }
.app { height: 100vh; overflow: hidden; }
.sidebar { overflow-y: auto; }
.main { height: 100vh; overflow: auto; min-width: 0; }

/* 页面吸顶头部：标题 + 板块页签/筛选批量工具行整体固定（JS 计算其高度供表头避让） */
.page-top {
  position: sticky; top: 0; z-index: 40;
  background: var(--bg);
  padding: 12px 0 10px;
  margin-bottom: 8px;
  box-shadow: 0 10px 10px -10px rgba(16, 24, 40, .22);
}
.page-top h2 { margin-bottom: 10px; }
.page-top .card { margin-bottom: 0; }

/* 表格表头吸顶：仅"单表单内容"的页面启用（top 由 JS 写入 --ptop 避开吸顶头部）。
   多表格堆叠区域（如工序产能总览的型号分组表、统计页矩阵表）不吸顶，避免表头互相遮挡数据。 */
#page-board table thead th, #page-approvals table thead th, #page-users table thead th,
#page-products table thead th, #page-export table thead th,
#pl-capcfg .scrap-table thead th, #pl-delay table thead th {
  position: sticky; top: var(--ptop, 0px); z-index: 6;
}

/* ============ 工序产能总览：按型号收纳 ============ */
.cv-group { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 12px; overflow: hidden; background: #fff; }
.cv-group-head { display: flex; align-items: baseline; gap: 10px; padding: 9px 14px; background: #f2f6fe; border-bottom: 1px solid var(--border); }
.cv-group-head .cv-title { font-weight: 700; color: #1f3f8f; font-size: 13.5px; white-space: nowrap; }
.cv-group table { font-size: 13px; }
.cv-group td { padding: 8px 10px; }
.cv-group .empty { padding: 12px 0; }

/* 2) 页面吸顶后视口顶部不留空隙：主区顶部内边距移除，由每页 .page-top 自带留白 */
.main { padding-top: 0 !important; }
.page-top { padding-top: 14px; }

/* 3) 时间单位自选：数值框 + 单位下拉并排 */
.cap-unit-row { display: flex; gap: 4px; align-items: center; }

/* 5) 甘特图：自成一体的冻结滚动区（表头日期纵向固定 + 左侧任务名横向固定，滚动仅发生在右侧计划区） */
#gantt-wrap {
  overflow: auto;
  max-height: clamp(520px, calc(100vh - 185px), 2400px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
/* 左侧任务名列横向冻结 */
.gt-gut { position: sticky; left: 0; z-index: 6; }
/* 甘特分组标题行左部固定在左列 */
.gantt-group-title { position: sticky; left: 0; z-index: 6; }

/* ============ 第六批 S1：扫码作业页 ============ */
.scan-notice { margin: 8px 0; padding: 8px 12px; border-radius: 8px; font-size: 13px; line-height: 1.7; }
.scan-notice.ok { background: #f0f9f4; border: 1px solid #b7e4c8; color: #0a7a5a; }
.scan-notice.warn { background: #fff8e6; border: 1px solid #ffe1a6; color: #b45309; }
.scan-notice.err { background: #fdecec; border: 1px solid #f7c0c0; color: #c0392b; }
.scan-cur { margin: 8px 0 4px; padding: 10px 14px; background: #f6f9ff; border: 1px solid #cfe0ff; border-radius: 8px; }
.scan-cur-head { font-weight: 600; color: #1f3f8f; margin-bottom: 6px; }
.scan-kv { font-size: 13px; margin-top: 4px; line-height: 1.7; }
.scan-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #ff4d4f; margin-left: 5px; vertical-align: 1px; }
tr.scan-hit-row td { background: #fff8e6 !important; }
tr.scan-cur-row td { background: #f2f8ff !important; }
#scan-input:focus { border-color: #2f6fed; box-shadow: 0 0 0 3px rgba(47, 111, 237, .15); outline: none; }
#print-area { display: none; }

/* ============ 第六批 S1：A4 二维码标签（3 列 × 8 行 = 24 格/页）============ */
#qr-preview .lbl-sheet { margin-bottom: 10px; background: #fff; }
.lbl-sheet { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(8, 1fr); gap: 2mm; }
.lbl-cell { border: 1px dashed #b9c0cc; border-radius: 2mm; padding: 1.5mm; display: flex; gap: 1.5mm; align-items: center; overflow: hidden; height: 33mm; box-sizing: border-box; background: #fff; }
.lbl-cell.lbl-empty { border-style: dotted; border-color: #e3e8f0; }
.lbl-qr { flex: 0 0 26mm; width: 26mm; height: 26mm; }
.lbl-qr svg { display: block; width: 100%; height: 100%; }
.lbl-txt { flex: 1; min-width: 0; }
.lbl-title { font-weight: 700; font-size: 11px; color: #111; line-height: 1.3; word-break: break-all; }
.lbl-sub { font-size: 9px; color: #555; margin-top: 2px; line-height: 1.3; word-break: break-all; }
.lbl-code { font-size: 7px; color: #888; margin-top: 3px; font-family: Consolas, monospace; word-break: break-all; }
.lbl-err { font-size: 9px; color: #c0392b; }

@media print {
  .app, .toast, .modal-mask { display: none !important; }
  html, body { height: auto !important; overflow: visible !important; background: #fff !important; }
  #print-area { display: block !important; position: absolute; left: 0; top: 0; width: 100%; }
  .print-sheet { page-break-after: always; break-after: page; position: relative; }
  .print-sheet:last-child { page-break-after: auto; break-after: auto; }
  .lbl-cell { border: 1px solid #ddd; }
  .lbl-foot { position: absolute; left: 0; right: 0; bottom: -4mm; font-size: 8px; color: #999; text-align: center; }
  @page { size: A4 portrait; margin: 8mm; }
}

/* ============ 第六批 S3/S5：异常登记与处理结果（检验清单 + 任务详情共用） ============ */
.hist-sections { margin-top: 10px; }
.hist-sec { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: #fff; overflow: hidden; }
.hist-sec > summary { cursor: pointer; padding: 7px 12px; font-size: 13px; font-weight: 600; color: #475069; background: #f7f9fd; list-style: none; display: flex; align-items: center; gap: 6px; }
.hist-sec > summary::-webkit-details-marker { display: none; }
.hist-sec > summary::before { content: '▸'; color: #8a93a6; font-size: 11px; }
.hist-sec[open] > summary::before { content: '▾'; }
.hist-sec-body { padding: 8px 12px 10px; }
.hist-sub { font-size: 12px; color: #8a93a6; margin: 6px 0 4px; }
.hist-card { border: 1px solid #e6eaf2; border-left: 3px solid #cbd5e6; border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; background: #fdfefe; }
.hist-card.hist-dispose { display: flex; align-items: center; gap: 8px; border-left-color: #f0b4b4; background: #fffafa; }
.hist-head { font-size: 12.5px; line-height: 1.8; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.hist-body { font-size: 12.5px; line-height: 1.8; color: #3f4756; margin-top: 3px; }
.hist-imgs a { margin-right: 8px; color: #1f3f8f; }
.hist-result { margin-top: 6px; padding: 6px 9px; background: #f2f8ff; border-radius: 6px; font-size: 12.5px; line-height: 1.8; }
.hist-result.hist-pending { background: #fffaf0; }
