:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --bg: #f4f6fa;
    --panel: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --muted: #64748b;
    --ok: #16a34a;
    --warn: #d97706;
    --danger: #dc2626;
    --info: #0891b2;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Microsoft YaHei", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- 布局 ---------------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 224px;
    flex: 0 0 224px;
    background: #101a2e;
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand {
    padding: 16px 18px;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    line-height: 1.4;
}
.brand small { display: block; font-weight: 400; font-size: 11px; color: #7c8bab; margin-top: 3px; }

.sidebar nav { padding: 8px 0 30px; }
.nav-group { padding: 12px 18px 5px; font-size: 11px; letter-spacing: .08em; color: #64748b; text-transform: uppercase; }
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    color: #cbd5e1;
    font-size: 13.5px;
    border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: rgba(37, 99, 235, .22); color: #fff; border-left-color: var(--primary); font-weight: 600; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: 54px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 40;
}
.topbar h1 {
    font-size: 16px; margin: 0; font-weight: 600;
    flex: 1 1 auto; min-width: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .user { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); flex: 0 0 auto; }
.role-chip { background: var(--primary-light); color: var(--primary-dark); padding: 2px 9px; border-radius: 20px; font-size: 12px; }
.company-chip {
    background: #101a2e; color: #fff; padding: 3px 10px; border-radius: 20px;
    font-size: 12px; font-weight: 600; max-width: 220px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.content { padding: 18px 20px 60px; flex: 1; }

/* ---------------- 卡片 ---------------- */
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}
.card > .card-head {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.card > .card-head h2 { font-size: 14.5px; margin: 0; font-weight: 600; }
.card > .card-head .sub { color: var(--muted); font-size: 12.5px; font-weight: 400; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1180px) { .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) {
    .grid.c2, .grid.c3 { grid-template-columns: 1fr; }
    /* 侧栏不再隐藏，改为抽屉（见文末「移动端适配」区块） */
}

/* ---------------- 统计卡 ---------------- */
.stat {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 6px; letter-spacing: -.5px; }
.stat .extra { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat.accent { border-left: 3px solid var(--primary); }
.stat.accent-warn { border-left: 3px solid var(--warn); }
.stat.accent-danger { border-left: 3px solid var(--danger); }
.stat.accent-ok { border-left: 3px solid var(--ok); }

/* ---------------- 表格 ---------------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.table th, table.table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table.table thead th {
    background: #f8fafc;
    font-weight: 600;
    color: #475569;
    white-space: nowrap;
    position: sticky;
    top: 0;
    font-size: 12.5px;
}
table.table tbody tr:hover { background: #f8fbff; }
table.table td.num, table.table th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.table td.mono { font-family: Consolas, "Courier New", monospace; font-size: 12.5px; }
table.table tr.total-row td { font-weight: 700; background: #f8fafc; }
table.table.compact th, table.table.compact td { padding: 5px 8px; }
/* 日报列表里一条工作内容一行（项目 + 工作内容） */
.item-line + .item-line { margin-top: 3px; padding-top: 3px; border-top: 1px dashed var(--border); }
.item-line { line-height: 1.55; }
.empty { padding: 34px; text-align: center; color: var(--muted); }

/* ---------------- 徽标 ---------------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; line-height: 1.6; white-space: nowrap; }
.badge.ok { background: #dcfce7; color: #15803d; }
.badge.warn { background: #fef3c7; color: #b45309; }
.badge.danger { background: #fee2e2; color: #b91c1c; }
.badge.info { background: #cffafe; color: #0e7490; }
.badge.muted { background: #e2e8f0; color: #475569; }
.badge.primary { background: var(--primary-light); color: var(--primary-dark); }

/* ---------------- 按钮 ---------------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 13px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    line-height: 1.6;
    white-space: nowrap;
    font-family: inherit;
}
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { background: #b91c1c; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.btn.lg { padding: 9px 20px; font-size: 14px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------------- 表单 ---------------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px 16px; }
.form-grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.span2 { grid-column: span 2; }
.field.span3 { grid-column: span 3; }
.field > label { font-size: 12.5px; color: #475569; font-weight: 500; }
.field > label .req { color: var(--danger); margin-left: 2px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=email],
select, textarea {
    width: 100%;
    padding: 6px 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text);
    background: #fff;
    outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
textarea { resize: vertical; min-height: 62px; }
input[readonly] { background: #f8fafc; color: var(--muted); }
.hint { font-size: 11.5px; color: var(--muted); }
.checkbox { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.checkbox input { width: auto; }

.filter-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: #fcfdff;
}
.filter-bar input[type=text], .filter-bar select { width: auto; min-width: 130px; }

/* ---------------- Flash ---------------- */
.flash-area { position: fixed; top: 62px; right: 20px; z-index: 999; display: flex; flex-direction: column; gap: 8px; max-width: 460px; }
.flash { padding: 10px 16px; border-radius: 6px; box-shadow: 0 4px 14px rgba(15, 23, 42, .14); font-size: 13px; animation: slideIn .25s ease; }
.flash.success { background: #ecfdf5; border-left: 4px solid var(--ok); color: #065f46; }
.flash.error { background: #fef2f2; border-left: 4px solid var(--danger); color: #991b1b; }
.flash.warn { background: #fffbeb; border-left: 4px solid var(--warn); color: #92400e; }
@keyframes slideIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }

/* ---------------- Tab ---------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 16px; background: #fcfdff; flex-wrap: wrap; }
.tabs a, .tabs button {
    padding: 10px 15px;
    font-size: 13.5px;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    background: none;
    border-top: 0; border-left: 0; border-right: 0;
    cursor: pointer;
    font-family: inherit;
}
.tabs a:hover, .tabs button:hover { color: var(--primary); text-decoration: none; }
.tabs a.active, .tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* 整机 BOM 明细：按分区单独查看的筛选条 */
.section-filter {
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
    padding: 9px 16px; border-bottom: 1px solid var(--border); background: #fcfdff;
}
.section-filter > .muted { font-size: 12.5px; margin-right: 4px; }
.section-filter .btn.active {
    background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600;
}

/* ---------------- 物料搜索 ---------------- */
.mat-search-wrap { position: relative; }
.mat-search-drop {
    position: fixed;            /* 挂到 body 后用固定定位，避免被表格滚动容器裁剪 */
    top: 0; left: 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .16);
    max-height: 320px;
    overflow-y: auto;
    z-index: 900;
    display: none;
}
.mat-search-drop.open { display: block; }
.mat-search-drop .item { padding: 7px 11px; cursor: pointer; font-size: 12.5px; border-bottom: 1px solid #f1f5f9; }
.mat-search-drop .item:hover, .mat-search-drop .item.sel { background: var(--primary-light); }
.mat-search-drop .item .c { font-family: Consolas, monospace; color: var(--primary-dark); font-weight: 600; }
.mat-search-drop .item .d { color: var(--muted); font-size: 11.5px; }
.mat-search-drop .empty { padding: 14px; text-align: center; color: var(--muted); font-size: 12.5px; }
.mat-search-wrap.invalid .mat-search { border-color: var(--danger); background: #fff5f5; }
.mat-search-wrap.invalid::after {
    content: '请从列表中选择';
    position: absolute; left: 0; top: 100%; margin-top: 2px;
    font-size: 11px; color: var(--danger);
}

/* 选中后常驻的物料规格描述（型号参数 / 封装），无需打开下拉即可核对 */
.mat-info {
    margin-top: 3px;
    font-size: 11.5px;
    line-height: 1.35;
    color: var(--muted);
    word-break: break-all;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.mat-info:empty { display: none; }
select.invalid, input.invalid { border-color: var(--danger) !important; }

/* ---------------- 分页 ---------------- */
.pager { display: flex; gap: 4px; align-items: center; justify-content: flex-end; padding: 12px 16px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.pager a, .pager span.cur {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: #fff;
}
.pager span.cur { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------------- 登录页 ---------------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 55%, #2563eb 100%);
    padding: 20px;
}
.login-box {
    background: #fff;
    border-radius: 14px;
    padding: 34px 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 24px 60px rgba(2, 6, 23, .35);
}
.login-box h1 { font-size: 20px; margin: 0 0 4px; text-align: center; }
.login-box .sub { text-align: center; color: var(--muted); font-size: 12.5px; margin-bottom: 22px; }
.login-box .field { margin-bottom: 14px; }
.login-box .accounts { margin-top: 20px; padding-top: 16px; border-top: 1px dashed var(--border); font-size: 12px; color: var(--muted); line-height: 1.9; }

/* ---------------- 打印 ---------------- */
.print-body { background: #fff; }
.print-sheet { max-width: 1080px; margin: 0 auto; padding: 26px; background: #fff; }
.print-head { text-align: center; margin-bottom: 18px; }
.print-head h2 { margin: 0 0 6px; font-size: 20px; }
@media print {
    .no-print, .sidebar, .topbar, .flash-area { display: none !important; }
    .table-wrap.tall { max-height: none !important; overflow: visible !important; }
    .row-bar { display: none !important; }
    .content { padding: 0; }
    .card { border: none; box-shadow: none; }
    body { background: #fff; }
}

/* ---------------- 打印单据 ---------------- */
.print-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; border-bottom: 2px solid #0f172a; padding-bottom: 10px; }
table.print-meta { border-collapse: collapse; font-size: 13px; }
table.print-meta td { padding: 2px 10px 2px 0; }
.print-sheet { max-width: 900px; margin: 0 auto; }

/* ---------------- 逾期行高亮 ---------------- */
table.table tr.row-late > td { background: #fff1f2; }

/* ---------------- 通用工具类 ---------------- */
.center { text-align: center; }

/* ---------------- 其他 ---------------- */
.tag-list { display: flex; gap: 6px; flex-wrap: wrap; }
.msg-ok { color: var(--ok); }
.msg-warn { color: var(--warn); }
.msg-err { color: var(--danger); }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; }
.mb0 { margin-bottom: 0; } .mb8 { margin-bottom: 8px; }
.right { text-align: right; } .center { text-align: center; }
.issue-list { list-style: none; margin: 0; padding: 0; }
.issue-list li { padding: 8px 12px; border-radius: 6px; margin-bottom: 7px; font-size: 13px; display: flex; gap: 8px; align-items: flex-start; }
.issue-list li.error { background: #fef2f2; color: #991b1b; }
.issue-list li.warn { background: #fffbeb; color: #92400e; }
.issue-list li.info { background: #eff6ff; color: #1e40af; }
.row-del { color: var(--danger); cursor: pointer; font-size: 15px; line-height: 1; }
.row-del:hover { color: #b91c1c; }
.row-ops { white-space: nowrap; text-align: center; }
.row-ins { color: var(--primary); cursor: pointer; font-size: 15px; line-height: 1; margin-right: 10px; }
.row-ins:hover { color: var(--primary-dark); }

/* 长明细表：表格区域自身滚动 + 表头吸顶，底部工具条常驻可见 */
.table-wrap.tall { max-height: calc(100vh - 300px); min-height: 240px; overflow: auto; }
.table-wrap.tall table.table thead th { top: 0; z-index: 6; box-shadow: inset 0 -1px 0 var(--border); }
.row-bar {
    position: sticky;
    bottom: 0;
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 8px 12px;
    background: #fff;
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(15, 23, 42, .07);
    z-index: 30;
}
.row-bar .muted { font-size: 12.5px; }

/* 位号输入框：多行显示，随内容自动增高，方便核对长串位号 */
.refdes-input {
    width: 100%;
    min-height: 30px;
    max-height: 190px;
    padding: 4px 7px;
    font-size: 12.5px;
    line-height: 1.5;
    overflow-wrap: anywhere;
    word-break: break-all;
    resize: vertical;
    overflow-y: auto;
}

/* 位号：允许折行并按列宽收敛，避免一长串位号把整张表撑宽。
   位号在库里是逗号分隔（R1,R2,C5…），所以这里不用 break-all ——
   让浏览器优先在逗号处断行，读起来一个位号一段；
   真遇到没分隔符的超长串，才由 overflow-wrap 在词内强行断开。 */
th.refdes, td.refdes {
    width: 220px;
    max-width: 220px;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.45;
    font-size: 12.5px;
}
.drag-row td { background: #f8fafc; }

/* ================= 折叠式多级菜单（导航改版） ================= */
.sidebar .nav-top {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 18px; color: #cbd5e1; font-size: 13.5px;
    border-left: 3px solid transparent;
}
.sidebar .nav-top.active {
    background: rgba(37, 99, 235, .22); color: #fff;
    border-left-color: var(--primary); font-weight: 600;
}

.nav-sec { margin-top: 2px; }
.sidebar .nav-head {
    display: flex; align-items: center; gap: 6px;
    width: 100%; margin: 0;
    padding: 10px 18px 6px;
    background: none; border: 0; cursor: pointer;
    font-family: inherit; font-size: 11px; letter-spacing: .08em;
    color: #64748b; text-transform: uppercase; text-align: left;
}
.sidebar .nav-head:hover { color: #94a3b8; }
.nav-head .caret {
    width: 0; height: 0; margin-left: auto;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    transition: transform .18s ease;
}
.nav-sec.collapsed .nav-head .caret { transform: rotate(-90deg); }

.nav-sub { overflow: hidden; }
.nav-sec.collapsed .nav-sub { display: none; }
.sidebar .nav-sub a {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 18px 7px 30px;            /* 缩进 12px，体现层级归属 */
    color: #cbd5e1; font-size: 13px;
    border-left: 3px solid transparent;
}
.sidebar .nav-sub a:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.sidebar .nav-sub a.active {
    background: rgba(37, 99, 235, .22); color: #fff;
    border-left-color: var(--primary); font-weight: 600;
}
.nav-sub .badge { margin-left: auto; }

/* 首页常用功能快捷区 */
.quick-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); }
.quick-card {
    display: block; padding: 12px 14px; border: 1px solid var(--border);
    border-radius: var(--radius); background: #fff; color: var(--text);
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.quick-card:hover {
    text-decoration: none; transform: translateY(-1px);
    border-color: var(--primary); box-shadow: 0 4px 14px rgba(37, 99, 235, .14);
}
.quick-card .q-title { font-size: 13.5px; font-weight: 600; }
.quick-card .q-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.quick-card .q-badge { float: right; }

/* ================= 移动端适配：汉堡按钮 + 抽屉导航 + 表格卡片化 ================= */
.nav-toggle {
    display: none; flex: 0 0 auto;
    width: 38px; height: 34px; padding: 0;
    background: #fff; border: 1px solid var(--border); border-radius: 6px;
    cursor: pointer; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
}
.nav-toggle span {
    display: block; width: 18px; height: 2px; border-radius: 2px; background: var(--text);
    transition: transform .2s ease, opacity .2s ease;
}
.nav-backdrop { display: none; }

@media (max-width: 900px) {
    .nav-toggle { display: flex; }
    .topbar { height: 52px; padding: 0 12px; gap: 10px; }
    .topbar h1 { font-size: 15px; }
    .topbar .user { gap: 8px; font-size: 12px; }
    .role-chip { display: none; }
    .content { padding: 12px 12px 80px; }
    .flash-area { left: 12px; right: 12px; top: 58px; max-width: none; }
    .table-wrap.tall { max-height: none; min-height: 0; overflow-x: auto; }

    /* 侧栏改为左侧抽屉 */
    .sidebar {
        position: fixed; top: 0; left: 0; bottom: 0; z-index: 60;
        width: 78%; max-width: 300px; height: 100%;
        transform: translateX(-103%);
        transition: transform .22s ease;
        box-shadow: 2px 0 18px rgba(15, 23, 42, .32);
    }
    body.nav-open .sidebar { transform: none; }
    body.nav-open { overflow: hidden; }

    .nav-backdrop {
        display: block; position: fixed; inset: 0; z-index: 55;
        background: rgba(15, 23, 42, .45);
        opacity: 0; pointer-events: none; transition: opacity .22s ease;
    }
    body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }

    /* 汉堡变叉号 */
    body.nav-open .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
    body.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
    body.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
}

@media (max-width: 720px) {
    .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; }
    .form-grid.c2, .form-grid.c3 { grid-template-columns: 1fr; }
    .field.span2, .field.span3 { grid-column: auto; }
    .card > .card-head, .card-body, .filter-bar { padding-left: 12px; padding-right: 12px; }
    .btn { padding: 8px 14px; }
    .btn.sm { padding: 5px 10px; font-size: 12.5px; }
    .pager { justify-content: center; }
    .tabs { padding: 0 8px; flex-wrap: nowrap; overflow-x: auto; }
    .tabs a, .tabs button { padding: 10px 12px; white-space: nowrap; }

    /* 只读表格：每行变一张卡片；编辑类表格由 JS 打上 .table-form，保持横向滚动 */
    table.table:not(.table-form) thead { display: none; }
    table.table:not(.table-form),
    table.table:not(.table-form) tbody,
    table.table:not(.table-form) tfoot,
    table.table:not(.table-form) tr,
    table.table:not(.table-form) td { display: block; width: 100%; }
    table.table:not(.table-form) tr {
        background: var(--panel);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
        margin-bottom: 10px;
        padding: 4px 0;
        overflow: hidden;
    }
    table.table:not(.table-form) td {
        border-bottom: 0;
        display: flex; align-items: baseline; justify-content: space-between; gap: 14px;
        padding: 6px 12px; text-align: right;
        white-space: normal; word-break: break-word;
    }
    table.table:not(.table-form) td[data-label]::before {
        content: attr(data-label);
        flex: 0 0 auto; max-width: 46%;
        color: var(--muted); font-size: 12px; text-align: left;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    table.table:not(.table-form) tr.total-row td { font-weight: 700; background: transparent; }
    table.table:not(.table-form) tr.row-late > td { background: transparent; }
    table.table:not(.table-form) td.row-ops { justify-content: flex-start; flex-wrap: wrap; gap: 8px; text-align: left; }
    th.refdes, td.refdes { width: auto; max-width: none; }

    /* 编辑型表格（日报填报 / 采购 / 生产明细）：窄屏同样卡片化，
       每个字段纵向排列、输入框占满整行，手机上不用左右拖动即可填写 */
    table.table.table-form thead { display: none; }
    table.table.table-form,
    table.table.table-form tbody,
    table.table.table-form tfoot,
    table.table.table-form tr,
    table.table.table-form td { display: block; width: 100%; }
    table.table.table-form tr {
        background: var(--panel);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
        margin-bottom: 10px;
        padding: 6px 0;
        overflow: hidden;
    }
    table.table.table-form td { border-bottom: 0; padding: 6px 12px; text-align: left; }
    table.table.table-form td[data-label]::before {
        content: attr(data-label);
        display: block; color: var(--muted); font-size: 12px; margin-bottom: 3px;
    }
    table.table.table-form td input,
    table.table.table-form td select,
    table.table.table-form td textarea { width: 100%; box-sizing: border-box; }
    table.table.table-form td:last-child { text-align: right; }

    /* 触摸优化：iOS 上输入框字号小于 16px 会触发页面自动放大，且按钮要够大好点 */
    input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea { font-size: 16px; }
    .btn { padding: 10px 16px; }
    .btn.sm { padding: 7px 12px; font-size: 13px; }

    /* 长表单（日报填报等）：保存按钮固定在屏幕底部，不必滚到最后才能提交 */
    .form-actions {
        position: sticky; bottom: 0; z-index: 20;
        display: flex; gap: 8px; align-items: center;
        margin: 0 -12px !important;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
        background: rgba(255, 255, 255, .97);
        border-top: 1px solid var(--border);
        box-shadow: 0 -4px 14px rgba(15, 23, 42, .06);
    }
    .form-actions .btn { flex: 1; text-align: center; justify-content: center; }
    /* 表单末尾留出与固定条等高的空白（用空元素而非 :has，兼容旧版内置浏览器） */
    .form-actions-gap { height: 78px; }
}

/* ---------------- 工艺文档（A4 纸张观感） ----------------
   编辑区(.doc-page[contenteditable]) 与查看页、打印页共用同一套排版，
   这样"写的什么样、看的就是什么样"，导出的 PDF 也一致。 */
.doc-page {
    background: #fff;
    color: #1f2328;
    font-family: "Microsoft YaHei", "PingFang SC", "Source Han Sans SC", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.8;
    padding: 20mm 18mm;
    max-width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .12);
    box-sizing: border-box;
    overflow-wrap: break-word;
}
.doc-page:focus { outline: none; }
.doc-page > *:first-child { margin-top: 0; }
.doc-page p { margin: 0 0 8px; }
.doc-page h1 { font-size: 24px; margin: 18px 0 12px; line-height: 1.4; }
.doc-page h2 { font-size: 19px; margin: 16px 0 10px; line-height: 1.4; }
.doc-page h3 { font-size: 16px; margin: 14px 0 8px; }
.doc-page h4, .doc-page h5, .doc-page h6 { font-size: 14px; margin: 12px 0 6px; }
.doc-page ul, .doc-page ol { margin: 0 0 8px; padding-left: 24px; }
.doc-page li { margin: 2px 0; }
.doc-page table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 13px; }
.doc-page th, .doc-page td {
    border: 1px solid #94a3b8;
    padding: 6px 8px;
    vertical-align: top;
    min-width: 40px;
}
.doc-page th { background: #f1f5f9; font-weight: 600; }
.doc-page img { max-width: 100%; height: auto; }
.doc-page hr { border: none; border-top: 1px solid #cbd5e1; margin: 14px 0; }
.doc-page blockquote {
    margin: 10px 0; padding: 6px 12px; color: #475569;
    border-left: 3px solid #cbd5e1; background: #f8fafc;
}
.doc-page a { color: #1d4ed8; }

/* 编辑器外壳：工具栏吸顶，纸张区域自己滚动 */
.pe-toolbar {
    position: sticky; top: 0; z-index: 22;
    display: flex; flex-wrap: wrap; gap: 3px; align-items: center;
    padding: 7px 8px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px 8px 0 0;
}
.pe-toolbar button {
    min-width: 30px; height: 28px; padding: 0 7px;
    border: 1px solid transparent; border-radius: 5px;
    background: transparent; color: #334155;
    font-size: 13px; line-height: 1; cursor: pointer; font-family: inherit;
}
.pe-toolbar button:hover { background: #e2e8f0; }
.pe-toolbar button.on { background: #dbeafe; border-color: #bfdbfe; color: #1d4ed8; }
.pe-toolbar select {
    height: 28px; width: auto; padding: 0 4px; font-size: 12.5px; border-radius: 5px;
}
.pe-toolbar .sep { width: 1px; height: 18px; background: var(--border); margin: 0 3px; }
.pe-shell {
    border: 1px solid var(--border); border-top: none;
    border-radius: 0 0 8px 8px;
    background: #eef2f7;
    padding: 16px 8px;
    max-height: calc(100vh - 300px);
    overflow: auto;
}
.pe-shell .doc-page { box-shadow: 0 2px 10px rgba(15, 23, 42, .10); }
.pe-hint { font-size: 12px; color: #64748b; }
.pe-status { font-size: 12px; color: #64748b; margin-left: auto; }
@media (max-width: 900px) {
    .pe-shell { max-height: none; }
    .doc-page { padding: 12mm 8mm; min-height: auto; }
}

/* ---------------- 工艺文档：分页纸张 / 页码 / 目录 ----------------
   屏幕上一页一页摆着（和 Word 一样），打印时每张 .pg 正好一页 A4。
   正文排版规则在这里重复一遍，是因为分页后内容被搬进 .pg-body，
   不再挂在 .doc-page 下面（编辑器那边仍用 .doc-page）。 */
.pg {
    width: 210mm;
    height: 297mm;
    background: #fff;
    margin: 0 auto 14px;
    padding: 16mm 16mm 9mm;
    box-sizing: border-box;
    box-shadow: 0 2px 10px rgba(15, 23, 42, .12);
    display: flex;
    flex-direction: column;
    position: relative;
}
.pg-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    font-family: "Microsoft YaHei", "PingFang SC", "Source Han Sans SC", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.8;
    color: #1f2328;
    overflow-wrap: break-word;
}
.pg-body > *:first-child { margin-top: 0; }
.pg-body p { margin: 0 0 8px; }
.pg-body h1 { font-size: 24px; margin: 16px 0 10px; line-height: 1.4; }
.pg-body h2 { font-size: 19px; margin: 14px 0 8px; line-height: 1.4; }
.pg-body h3 { font-size: 16px; margin: 12px 0 6px; }
.pg-body h4, .pg-body h5, .pg-body h6 { font-size: 14px; margin: 10px 0 6px; }
.pg-body ul, .pg-body ol { margin: 0 0 8px; padding-left: 24px; }
.pg-body table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
.pg-body th, .pg-body td { border: 1px solid #94a3b8; padding: 6px 8px; vertical-align: top; }
.pg-body th { background: #f1f5f9; font-weight: 600; }
.pg-body img { max-width: 100%; height: auto; }
.pg-body hr { border: none; border-top: 1px solid #cbd5e1; margin: 12px 0; }
.pg-body blockquote {
    margin: 10px 0; padding: 6px 12px; color: #475569;
    border-left: 3px solid #cbd5e1; background: #f8fafc;
}
.pg-body a { color: #1d4ed8; }

/* 横向 A4 */
.pg.land { width: 297mm; height: 210mm; }

/* 页眉：工艺名做通栏大标题，下面一行挂产品名称 / 型号 / 编号版本 / 页码 */
.pg-head {
    flex: none;
    padding-bottom: 2mm;
    border-bottom: 1.5px solid #334155;
    margin-bottom: 4mm;
}
.pg-head-t {
    text-align: center;
    font-size: 19px;
    font-weight: 700;
    letter-spacing: 3px;
    line-height: 1.5;
    color: #1f2328;
}
.pg-head-m {
    display: flex;
    align-items: baseline;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 2mm;
    font-size: 11px;
    color: #475569;
}
.pg-head-m .right { margin-left: auto; }
.pg-head-m .pg-no { color: #94a3b8; }

/* 页脚：拟制 / 审核 / 批准 三格签署表，压成一行，尽量不占版面 */
.pg-foot { flex: none; margin-top: 2mm; }
table.sign-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 10.5px;
    color: #334155;
}
table.sign-table td {
    border: 1px solid #94a3b8;
    padding: 1mm 1.5mm;
    vertical-align: middle;
    white-space: nowrap;
}
/* 一格两段：拟制日期：______ —— 标签后一条下划线拉满剩余宽度，直接能签字写日期 */
.sign-k { display: flex; align-items: center; gap: 4px; line-height: 1.6; }
.sign-t { flex: none; }
.sign-line {
    flex: 1 1 0;
    min-width: 8mm;
    height: 1em;
    border-bottom: 1px solid #64748b;
}

/* 目录页 */
.toc-title {
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    letter-spacing: 8px;
    margin: 6mm 0 8mm;
}
.toc-list { font-size: 13.5px; line-height: 2; }
.toc-item {
    display: flex;
    align-items: baseline;
    gap: 4px;
    padding: 1px 0;
    color: #1f2328;
    text-decoration: none;
}
.toc-item:hover { color: #1d4ed8; text-decoration: none; }
.toc-item.lv2 { padding-left: 18px; }
.toc-item.lv3 { padding-left: 36px; }
.toc-item.lv4 { padding-left: 54px; }
.toc-t { flex: none; max-width: 72%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toc-d { flex: 1; min-width: 24px; border-bottom: 1px dotted #cbd5e1; transform: translateY(-3px); }
.toc-p { flex: none; color: #475569; }

/* 从目录跳过去时闪一下，长文档里好找位置 */
.sec-hit { animation: secFlash 1.6s ease; }
@keyframes secFlash {
    0%, 55% { background: #fef08a; }
    100% { background: transparent; }
}

@media (max-width: 900px) {
    .pg { transform-origin: top center; }
}

/* 目录条目按正文色显示（打印出来是黑的），悬停才变蓝 */
.pg-body .toc-item { color: #1f2328; }
.pg-body .toc-item:hover { color: #1d4ed8; }

/* 编辑区也跟着纸张方向变：横向时铺开到 297mm，写的什么样排出来就什么样 */
.doc-page.land { max-width: 297mm; min-height: 210mm; }

/* ---------------- 编辑器：分页编辑（一页一页写，所见即所得） ----------------
   编辑区直接摆 .pg 纸（和查看页、打印页同一套类名、同一套页边距）。
   页眉页脚在编辑时也照样排出来，可编辑区就是"纸张高度 − 页眉 − 页脚 − 上下页边距"，
   被 .pg 的 flex 布局卡死，不会跟着内容长高；写满就断到下一页。
   这样编辑、保存后查看、导出 PDF 三处的断页位置和页数完全一致。 */
.pe-pages { padding-bottom: 6px; }
/* 注意：这里不要加 contain: paint —— 会裁剪绘制层，contenteditable 的光标和点选定位会出问题 */
.pe-pages .pg { cursor: text; }
.pe-pages .pg-body { outline: none; }
.pe-pages .pg-body:focus { box-shadow: inset 0 0 0 1px #bfdbfe; }
.pe-pages .pg-head,
.pe-pages .pg-foot { user-select: none; }
.pe-pages .pg-body img.pe-sel { outline: 1.5px solid #2563eb; }

/* 编辑模式的纸和查看页用同一套边距（16mm / 16mm / 9mm），不再单独收窄。
   正文区高度由 .pg 的 flex 布局算出来：页眉、页脚都是 flex:none，剩下的全给正文，
   所以"可编辑区"永远等于纸内除去页眉页脚的那一块，内容再多也不会把纸撑长。 */
.pe-pages .pg-body { flex: 1 1 auto; min-height: 0; }

/* ---------------- 编辑器：图片缩放框 ---------------- */
.pe-shell { position: relative; }
.doc-page img.pe-sel { outline: 1.5px solid #2563eb; }
.pe-img-box {
    position: absolute; border: 1.5px solid #2563eb; pointer-events: none;
    z-index: 6; box-sizing: border-box;
}
.pe-img-box .h {
    position: absolute; width: 10px; height: 10px; background: #fff;
    border: 1.5px solid #2563eb; border-radius: 2px; pointer-events: auto;
}
.pe-img-box .h.nw { left: -5px; top: -5px; cursor: nwse-resize; }
.pe-img-box .h.ne { right: -5px; top: -5px; cursor: nesw-resize; }
.pe-img-box .h.sw { left: -5px; bottom: -5px; cursor: nesw-resize; }
.pe-img-box .h.se { right: -5px; bottom: -5px; cursor: nwse-resize; }
.pe-img-box .tb {
    position: absolute; left: 0; top: -32px;
    display: flex; gap: 2px; align-items: center;
    padding: 2px 4px; background: #fff; border: 1px solid #cbd5e1; border-radius: 6px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, .12);
    pointer-events: auto; white-space: nowrap;
}
.pe-img-box .tb button {
    font-size: 11px; line-height: 1.6; padding: 1px 6px; border: none; background: transparent;
    color: #334155; cursor: pointer; border-radius: 4px; font-family: inherit;
}
.pe-img-box .tb button:hover { background: #e2e8f0; }

/* 顶栏子公司切换 */
.sub-switch { display: inline-block; margin: 0; }
.sub-switch select {
    height: 28px; padding: 2px 8px; font-size: 12.5px;
    border: 1px solid var(--border); border-radius: 6px;
    background: #fff; color: var(--text); max-width: 170px;
}
.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 18px; }
.kv-grid > div { display: flex; gap: 8px; align-items: baseline; }

/* ============ 物料附件：缩略图墙 + 在线预览弹层 ============ */
.att-gallery { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 14px; }
.att-thumb { margin: 0; width: 148px; }
.att-thumb > a { display: block; width: 148px; height: 108px; border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden; background: #f8fafc; }
.att-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.att-thumb figcaption { font-size: 11.5px; color: var(--muted); margin-top: 4px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 项目产品效果图：完整显示不裁切，封面加一圈主色描边 */
.att-thumb.contain img { object-fit: contain; background: #fff; }
.att-thumb.is-cover > a { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37, 99, 235, .18); }
.proj-img-ops { display: flex; gap: 6px; margin-top: 4px; }

#att-view { width: min(1120px, 94vw); height: min(88vh, 940px); padding: 0; border: none;
    border-radius: 10px; box-shadow: 0 20px 60px rgba(15, 23, 42, .35); }
#att-view::backdrop { background: rgba(15, 23, 42, .55); }
#att-view .att-view-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px;
    border-bottom: 1px solid var(--border); }
#att-view .att-view-head b { flex: 1; font-size: 13.5px; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap; }
#att-view .att-view-body { height: calc(100% - 46px); display: flex; align-items: center;
    justify-content: center; background: #f1f5f9; overflow: auto; }
#att-view iframe { width: 100%; height: 100%; border: none; background: #fff; }
#att-view img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
