/* TGDYL MRP —— 无外部依赖。密度优先：编辑时一屏能看到尽量多的行。 */
/* 配色：灰蓝。浅色 = 白顶栏；深色 = 深色顶栏。<html data-theme="dark"> 切深色，每个账号自己选（点顶栏的名字） */
:root {
  --bg: #f2f4f7;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --line: #e1e5eb;
  --line-2: #ccd3dc;
  --text: #1d2632;
  --muted: #677486;
  --accent: #3b5b86;
  --accent-2: #4a6c99;
  --accent-soft: #eaeff6;
  --warn: #b45309;
  --warn-soft: #fef3e2;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --info: #2563eb;
  --info-soft: #e9f0fe;
  --draft: #7c3aed;
  --draft-soft: #f1ebff;
  --skip: #ccd3dc;           /* 进度条里「跳过」那一段 */
  --focus: 0 0 0 3px rgba(59, 91, 134, .25);
  --c-quote: #2563eb;
  --c-std: #7c9fd6;
  --c-cost: #dc2626;
  --c-material: #d97706;
  --c-history: #059669;
  --c-others: #a3acb6;
  --topbar: var(--panel);
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
  --radius: 8px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f141b;
  --panel: #161c25;
  --panel-2: #1b222d;
  --line: #262f3c;
  --line-2: #343f4f;
  --text: #e8ecf1;
  --muted: #a3adbb;          /* 次要文字。12px 的说明字在深色底上会显得细，这里比浅色模式提得更亮（对比度约 7.4:1） */
  --accent: #86a6d0;
  --accent-2: #6f90bd;
  --accent-soft: #1d2838;
  --warn: #fbbf24;
  --warn-soft: #33270f;
  --danger: #f87171;
  --danger-soft: #3a1a1a;
  --ok: #4ade80;
  --ok-soft: #12301d;
  --info: #93b4ff;
  --info-soft: #18233d;
  --draft: #c4b5fd;
  --draft-soft: #261d3d;
  --skip: #5d6878;
  --focus: 0 0 0 3px rgba(134, 166, 208, .3);
  --c-quote: #60a5fa;
  --c-std: #8fa8cf;
  --c-cost: #f87171;
  --c-material: #fbbf24;
  --c-history: #34d399;
  --c-others: #5b6672;
  --topbar: #141b26;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.small { font-size: 12px; }
.hidden { display: none !important; }
kbd {
  font: 11px var(--mono); padding: 0 5px; border: 1px solid var(--line-2); border-bottom-width: 2px;
  border-radius: 4px; background: var(--panel-2); color: var(--muted);
}

/* ------------------------------------------------------------ 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  height: 48px; padding: 0 16px;
  background: var(--topbar); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark, .login-mark {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent); color: #fff; font-weight: 700;
}
.tabs { display: flex; gap: 2px; overflow-x: auto; }
.tabs a {
  padding: 6px 12px; border-radius: 6px; color: var(--muted); white-space: nowrap; font-weight: 500;
}
.tabs a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.tabs a.active { background: var(--accent-soft); color: var(--accent); }
.search-trigger {
  margin-left: auto; display: flex; align-items: center; gap: 24px; min-width: 260px;
  padding: 5px 8px 5px 12px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel-2); color: var(--muted); cursor: pointer; font: inherit;
}
.search-trigger:hover { border-color: var(--line-2); }
.user-menu { position: relative; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.user-menu form { margin: 0; }
/* 点名字弹出的账号菜单：外观（浅色 / 深色） */
.user-btn {
  display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 8px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer;
}
.user-btn .muted { color: inherit; }
.user-btn:hover, .user-btn[aria-expanded="true"] { background: var(--panel-2); color: var(--text); }
.user-btn:focus-visible { outline: none; box-shadow: var(--focus); }
.user-btn svg { width: 10px; height: 10px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: .7; }
.user-pop {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 60; min-width: 180px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px; box-shadow: 0 12px 32px rgba(0,0,0,.18);
  white-space: nowrap; color: var(--text);
}
.user-pop .sec { padding: 4px 8px 6px; font-size: 11px; font-weight: 600; color: var(--muted); }
.user-pop .opt {
  display: flex; align-items: center; gap: 8px; width: 100%; height: 30px; padding: 0 8px; border: 0; border-radius: 6px;
  background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.user-pop .opt:hover, .user-pop .opt:focus-visible { background: var(--panel-2); outline: none; }
.user-pop .opt .ck { width: 14px; margin-left: auto; color: var(--accent); font-weight: 700; text-align: center; }
.user-pop .sw { display: inline-grid; place-items: center; width: 22px; height: 16px; border-radius: 4px; border: 1px solid var(--line-2); }
.user-pop .sw i { display: block; width: 10px; height: 4px; border-radius: 2px; }
.user-pop .sw.light { background: #f2f4f7; } .user-pop .sw.light i { background: #3b5b86; }
.user-pop .sw.dark { background: #141b26; } .user-pop .sw.dark i { background: #86a6d0; }

/* 深色模式的顶栏：比页面更深的一条，字用白色 */
:root[data-theme="dark"] .topbar { border-bottom-color: var(--topbar); }
:root[data-theme="dark"] .topbar .brand { color: #fff; }
:root[data-theme="dark"] .topbar .brand-mark:not(.buy) { background: #fff; color: var(--topbar); }
:root[data-theme="dark"] .topbar .tabs a { color: rgba(255,255,255,.72); }
:root[data-theme="dark"] .topbar .tabs a:hover { background: rgba(255,255,255,.08); color: #fff; }
:root[data-theme="dark"] .topbar .tabs a.active { background: rgba(255,255,255,.16); color: #fff; }
:root[data-theme="dark"] .topbar .search-trigger { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.16); color: rgba(255,255,255,.7); }
:root[data-theme="dark"] .topbar .search-trigger:hover { border-color: rgba(255,255,255,.32); }
:root[data-theme="dark"] .topbar .search-trigger kbd { background: transparent; color: rgba(255,255,255,.7); border-color: rgba(255,255,255,.3); }
:root[data-theme="dark"] .topbar > .btn.ghost, :root[data-theme="dark"] .topbar .user-menu > .btn.ghost,
:root[data-theme="dark"] .topbar .user-menu form .btn.ghost, :root[data-theme="dark"] .topbar .user-btn { color: rgba(255,255,255,.82); }
:root[data-theme="dark"] .topbar > .btn.ghost:hover, :root[data-theme="dark"] .topbar .user-menu > .btn.ghost:hover,
:root[data-theme="dark"] .topbar .user-menu form .btn.ghost:hover, :root[data-theme="dark"] .topbar .user-btn:hover,
:root[data-theme="dark"] .topbar .user-btn[aria-expanded="true"] { background: rgba(255,255,255,.1); color: #fff; }

.view { padding: 16px; max-width: 1680px; margin: 0 auto; outline: none; }

/* ------------------------------------------------------------ 基础控件 */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  height: 30px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 6px;
  background: var(--panel); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent-2); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.small { height: 26px; padding: 0 8px; font-size: 12px; }
.btn.icon-btn { width: 30px; height: 30px; padding: 0; }
.btn.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn kbd { margin-left: 2px; }
.btn.primary kbd { background: transparent; color: rgba(255,255,255,.85); border-color: rgba(255,255,255,.4); }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line-2); border-radius: 6px; padding: 4px 8px; height: 30px;
}
textarea { height: auto; min-height: 60px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-2); box-shadow: var(--focus); }
input[type=checkbox] { height: auto; width: 15px; height: 15px; accent-color: var(--accent); }
input.cell {
  width: 100%; height: 26px; padding: 2px 6px; border-color: transparent; background: transparent;
}
input.cell:hover { border-color: var(--line); }
input.cell:focus { background: var(--panel); border-color: var(--accent-2); }
input.cell.num { text-align: right; }
input.w-num { width: 84px; text-align: right; }
.saved-flash { animation: flash 1s ease-out; }
@keyframes flash { from { background: var(--ok-soft); } to { background: transparent; } }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--muted); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.tight { gap: 4px; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.panel > .panel-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.panel > .panel-head h2, .panel > .panel-head h3 { margin: 0; font-size: 14px; }
.panel > .panel-body { padding: 12px; }
.panel.flush > .panel-body { padding: 0; }

h1 { font-size: 18px; margin: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.page-head .hint { color: var(--muted); }

/* ------------------------------------------------------------ 表格 */
.table-wrap { overflow: auto; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.grid th {
  position: sticky; top: 0; z-index: 2; background: var(--panel-2); color: var(--muted);
  font-weight: 500; font-size: 12px; white-space: nowrap;
}
table.grid tbody tr:hover { background: var(--panel-2); }
table.grid tr.selected, table.grid tbody tr.selected:hover { background: var(--accent-soft); }
table.grid tr.clickable { cursor: pointer; }
table.grid td.code { font-family: var(--mono); white-space: nowrap; }
/* 数字列右对齐：上面 table.grid td 的 text-align 优先级比 .num 高，要单独写 */
table.grid th.num, table.grid td.num { text-align: right; }
table.grid.dense td { padding: 2px 6px; }
/* 颜色条：格子背景上的横条，长短按这一列显示的行里最大的数。上下各留 3px，左边留 10px、右边 2px，
   相邻两列都开着时，最长的条也不会和右边一列的条连在一起。数字照常读 */
:root { --bar: color-mix(in srgb, var(--accent) 24%, transparent); --bar-neg: color-mix(in srgb, var(--danger) 24%, transparent); }
table.grid td.has-bar { background-repeat: no-repeat; background-position: 10px center; background-size: calc(100% - 12px) calc(100% - 6px); }
/* 表头里的开关：三根长短不一的小横条 */
.bar-btn { border: 0; background: none; margin-left: 3px; padding: 2px 3px; border-radius: 3px; cursor: pointer; line-height: 0; vertical-align: middle; }
.bar-btn:hover { background: var(--line); }
.bar-ico { display: inline-flex; flex-direction: column; gap: 2px; width: 11px; }
.bar-ico i { display: block; height: 2px; border-radius: 1px; background: var(--line-2); }
.bar-ico i:nth-child(2) { width: 65%; }
.bar-ico i:nth-child(3) { width: 35%; }
.bar-btn:hover .bar-ico i { background: var(--muted); }
.bar-btn.on .bar-ico i { background: var(--accent); }
table.grid.dense th { padding: 4px 6px; }
.scroll-y { max-height: calc(100vh - 210px); overflow: auto; }
/* 表头筛选 */
.col-btn { border: 0; background: none; color: var(--muted); margin-left: 3px; padding: 0 3px; border-radius: 3px; font-size: 11px; line-height: 15px; cursor: pointer; }
.col-btn:hover { background: var(--line); color: var(--text); }
.col-btn.on { background: var(--accent); color: #fff; }
.col-pop {
  position: fixed; z-index: 60; width: 240px; display: flex; flex-direction: column; gap: 8px; padding: 10px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px; box-shadow: 0 12px 32px rgba(0,0,0,.18);
}
.col-pop.dates { width: 320px; }
.col-pop input:not([type=checkbox]) { width: 100%; box-sizing: border-box; }
.col-pop .range { display: flex; align-items: center; gap: 6px; }
.col-pop .range input { min-width: 0; }
.col-pop .opts { max-height: 260px; overflow: auto; }
.col-pop .opt { display: flex; align-items: center; gap: 6px; padding: 3px 4px; border-radius: 4px; cursor: pointer; }
.col-pop .opt:hover { background: var(--panel-2); }
.col-pop .opt .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-pop .opt .n { color: var(--muted); font-size: 12px; }
.col-tokens { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-bottom: 10px; }
.col-tokens:empty { display: none; }
.panel > .col-tokens { margin: 0; padding: 8px 12px; border-bottom: 1px solid var(--line); }

/* ------------------------------------------------------------ 徽章 */
.badge {
  display: inline-flex; align-items: center; gap: 3px; height: 20px; padding: 0 7px; border-radius: 10px;
  font-size: 11px; font-weight: 500; white-space: nowrap; background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line);
}
.badge.todo { background: var(--panel-2); color: var(--muted); }
.badge.draft { background: var(--draft-soft); color: var(--draft); border-color: transparent; }
.badge.done { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.skip { background: transparent; color: var(--muted); border-style: dashed; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.price { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }

.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  height: 26px; padding: 0 10px; border-radius: 13px; border: 1px solid var(--line-2); background: var(--panel);
  color: var(--muted); cursor: pointer; font: inherit; font-size: 12px; white-space: nowrap;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .n { opacity: .75; margin-left: 4px; }

.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; }
.seg button {
  height: 28px; padding: 0 12px; border: 0; border-right: 1px solid var(--line-2); background: var(--panel);
  color: var(--muted); font: inherit; cursor: pointer;
}
.seg button:last-child { border-right: 0; }
.seg button:hover { color: var(--text); }
.seg button.on.todo { background: var(--panel-2); color: var(--text); font-weight: 600; }
.seg button.on.draft { background: var(--draft-soft); color: var(--draft); font-weight: 600; }
.seg button.on.done { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.seg button.on.skip { background: var(--panel-2); color: var(--muted); font-weight: 600; }

/* ------------------------------------------------------------ 进度 */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-bottom: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card .label { color: var(--muted); font-size: 12px; }
.card .big { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; margin: 2px 0 8px; }
.card .big small { font-size: 13px; color: var(--muted); font-weight: 400; }
.bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--panel-2); border: 1px solid var(--line); }
.bar > span { display: block; height: 100%; }
.bar .done { background: var(--ok); }
.bar .draft { background: var(--draft); }
.bar .skip { background: var(--skip); }
.bar .good { background: var(--ok); }
.bar .warn { background: var(--warn); }
/* 不可报价（型号对不上产品族）：斜纹，和「跳过」的实心灰分开 */
.bar .out, .legend i.out { background: repeating-linear-gradient(135deg, var(--warn) 0 1.5px, var(--warn-soft) 1.5px 4px); }
.audit-back { color: var(--muted); text-decoration: none; }
.audit-back:hover { color: var(--accent); }
.audit-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 14px; }
.audit-card { display: flex; flex-direction: column; gap: 10px; color: inherit; text-decoration: none; }
.audit-card:hover { border-color: var(--accent); }
.audit-card h3 { margin: 0; font-size: 15px; }
.audit-card svg { width: 100%; height: auto; background: var(--panel-2); border-radius: 6px; }
.audit-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.sk-label { fill: var(--muted); font-size: 11px; }
.sk-axis { stroke: var(--line-2); stroke-width: 1; }
.mp-pie { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px; }
.mp-pie .pie { position: relative; flex: 0 0 240px; max-width: 100%; }
.mp-pie .mp-table { flex: 1 1 300px; width: auto; min-width: 0; }
.pie-svg { display: block; width: 100%; height: auto; overflow: visible; }
.pie-slice { stroke: var(--panel); stroke-width: 2; transition: opacity .12s, transform .18s ease; }
.pie-slice.dim { opacity: .3; }
.pie-slice.pop { transform: translate(var(--dx), var(--dy)); }
.pie-label { fill: var(--text); font-size: 12px; font-variant-numeric: tabular-nums; }
.mp-table tbody tr.on td { background: var(--panel-2); }
.mp-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.mp-two { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); gap: 12px; margin-bottom: 12px; }
.mp-two .panel { margin-bottom: 0; min-width: 0; }
.mp-detail-box .panel-head { flex-wrap: wrap; }
.mp-detail-box .seg { flex-wrap: wrap; }
.mp-main { margin-bottom: 12px; }
.mp-main .panel-head { flex-wrap: wrap; }
.mp-formula { font-variant-numeric: tabular-nums; }
.mp-period { margin-left: auto; }
.mp-big { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 620px); gap: 20px; align-items: center; }
.mp-big .pie { position: relative; }
.mp-big-table { width: 100%; }
.mp-big-table tbody tr { cursor: pointer; animation: pie-fade .3s ease both; }
.mp-big-table td { vertical-align: top; }
.mp-big-name { font-weight: 600; }
.mp-big-note { margin: 3px 0 2px 16px; line-height: 1.55; white-space: normal; }
.mp-big-table tbody tr.still { cursor: default; }
.mp-big-table tr.mp-subtotal td { font-weight: 600; border-top: 1px solid var(--line-2); }
.mp-unmatched { margin: 4px 0 2px 16px; padding: 4px 8px; border-left: 2px solid var(--warn); background: var(--warn-soft); color: var(--warn); font-size: 12px; line-height: 1.55; white-space: normal; }
.mp-errors-text { color: var(--muted); }
.mp-cost { width: 100%; margin-top: 4px; border-collapse: collapse; }
.mp-cost td { padding: 2px 8px 2px 0; vertical-align: top; color: var(--muted); }
.mp-cost td:first-child { white-space: nowrap; color: var(--text); }
.mp-cost td.num { white-space: nowrap; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
.mp-cost .mp-misc td { color: var(--text); }
.mp-cost .mp-subtotal td { font-weight: 600; color: var(--text); border-top: 1px solid var(--line-2); }
.pie-slice.detached { transform: translate(var(--dx), var(--dy)); }
.pie-callout-note { fill: var(--warn); font-size: 12px; }
.mp-errors { margin-top: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); font-size: 12px; line-height: 1.6; }
.mp-errors-title { font-weight: 600; margin-bottom: 4px; }
.mp-errors ol { margin: 0; padding-left: 18px; color: var(--muted); }
.mp-errors strong { color: var(--text); font-weight: 600; }
.pie-callout { animation: pie-fade .35s ease both; }
.pie-leader { fill: none; stroke: var(--line-2); stroke-width: 1; }
.pie-callout-name { fill: var(--muted); font-size: 13px; }
.pie-callout-pct { fill: var(--text); font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pie-callout-amt { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
@keyframes pie-fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (max-width: 1000px) { .mp-big { grid-template-columns: minmax(0, 1fr); } .mp-period { margin-left: 0; } }
@media (prefers-reduced-motion: reduce) { .pie-callout, .mp-big-table tbody tr { animation: none; } .pie-slice { transition: none; } }
.mp-table { width: 100%; }
.mp-table tfoot td, .mp-detail tfoot td { font-weight: 600; border-top: 1px solid var(--line-2); }
.mp-detail tfoot td { position: sticky; bottom: 0; background: var(--panel); }
.mp-foot { margin-top: 8px; line-height: 1.6; }
.mp-verdict { margin-bottom: 12px; line-height: 1.7; }
.mp-tip { padding: 8px 12px 0; }
.mp-detail { max-height: 620px; overflow-x: auto; }
.note-box.warn-box { background: var(--warn-soft); color: var(--warn); margin-bottom: 12px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 6px; color: var(--muted); font-size: 12px; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }
/* 电缆采购与消耗：＋ 多买、− 少买 */
.cb-over { color: var(--warn); font-weight: 600; }
.cb-short { color: var(--info); font-weight: 600; }
.cb-branch { display: inline-block; width: 18px; color: var(--muted); font-family: var(--mono); }
/* 每个规格一块：第一行（规格合计，或单独一种的那根电缆）上面一条粗线 */
table.grid tr.cb-block td { border-top: 2px solid var(--line-2); }
table.grid tr.cb-group td { color: var(--text); }
table.grid tr.cb-group td .muted { color: var(--muted); }
.cb-year .small { font-weight: 400; white-space: nowrap; }
.cb-checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.cb-check { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 10px; align-items: start; line-height: 1.65; }
.cb-check > .badge { justify-self: start; margin-top: 1px; }
.cb-check-body { color: var(--muted); }
.cb-check-body strong { color: var(--text); font-weight: 600; }
.cb-small { width: auto; min-width: min(640px, 100%); margin-top: 6px; color: var(--text); }
.cb-small-wrap { overflow-x: auto; }
.cb-shift { display: inline-block; margin: 0 10px 2px 0; white-space: nowrap; }
.cb-detail { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(440px, 100%), 1fr)); gap: 16px; align-items: start; }
.cb-detail > div { min-width: 0; overflow-x: auto; }
.cb-detail h4 { margin: 0 0 6px; font-size: 13px; }
.cb-via { margin-top: 8px; line-height: 1.7; }

/* ------------------------------------------------------------ 产品族编辑器 */
.editor { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(360px, 1fr); gap: 12px; align-items: start; }
@media (max-width: 1200px) { .editor { grid-template-columns: 1fr; } }
.editor-head {
  position: sticky; top: 48px; z-index: 20; background: var(--bg);
  display: flex; align-items: center; gap: 10px; padding: 8px 0 10px; flex-wrap: wrap;
}
.editor-head .template { font: 600 18px var(--mono); }
.meta-grid { display: grid; grid-template-columns: 90px 1fr; gap: 6px 10px; align-items: center; }
.meta-grid > .k { color: var(--muted); font-size: 12px; }
.cable-spec { font-family: var(--mono); color: var(--warn); }
.price-hint { font: 12px/1.6 var(--mono); color: var(--muted); white-space: pre-wrap; max-height: 120px; overflow: auto; margin: 0; }

.recipe-block + .recipe-block { margin-top: 18px; }
.recipe-group {
  display: flex; align-items: center; gap: 8px; padding: 0 2px 6px; margin-bottom: 8px;
  border-bottom: 2px solid var(--accent-soft); color: var(--accent);
}
.recipe { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.recipe + .recipe { margin-top: 12px; }
.recipe.dirty { border-color: var(--warn); box-shadow: 0 0 0 1px var(--warn) inset; }
.recipe-head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 10px;
  border-bottom: 1px solid var(--line); background: var(--panel-2); border-radius: var(--radius) var(--radius) 0 0;
}
.recipe-head .title { font-weight: 600; }
.recipe-head-row { flex-basis: 100%; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.recipe-head label { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; }
.recipe-head input { height: 26px; }
.recipe-head input.company { width: 130px; }
.recipe-head input.meter { width: 64px; text-align: right; }
.recipe-head input.date { width: 128px; }
.recipe table.grid td { padding: 2px 6px; }
.recipe .line-code { font-family: var(--mono); white-space: nowrap; cursor: pointer; }
.recipe .line-code:hover { color: var(--accent); }
.recipe .add-row td { padding: 6px; background: var(--panel-2); }
.recipe .add-row input { width: 100%; }
.recipe-foot {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 10px; border-top: 1px solid var(--line);
}
.recipe-foot .costs { display: flex; gap: 6px; flex-wrap: wrap; }
.cost-pill {
  display: inline-flex; gap: 6px; align-items: baseline; padding: 2px 8px; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent); font-variant-numeric: tabular-nums;
}
.cost-pill b { font-size: 14px; }
.cost-pill .m { color: var(--muted); font-size: 11px; }
.lc input.cell { min-width: 60px; }
.drag-handle { cursor: grab; color: var(--muted); width: 18px; text-align: center; user-select: none; letter-spacing: -2px; }
tr.dragging { opacity: .4; }
tr.drop-before td { box-shadow: inset 0 2px 0 var(--accent); }
tr.drop-after td { box-shadow: inset 0 -2px 0 var(--accent); }
.del { color: var(--muted); cursor: pointer; border: 0; background: none; font-size: 15px; padding: 0 4px; }
.del:hover { color: var(--danger); }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.margin-neg { color: var(--danger); font-weight: 600; }
.margin-low { color: var(--warn); }

/* ------------------------------------------------------------ 就地关联采购记录 */
.badge-btn { cursor: pointer; }
.badge-btn:hover .badge { box-shadow: 0 0 0 1px var(--accent-2); }
.badge-btn:hover { color: var(--accent); }
.link-results { border: 1px solid var(--line); border-radius: 6px; max-height: 300px; overflow: auto; }
.link-opt {
  display: grid; grid-template-columns: minmax(70px, auto) 1fr auto auto; gap: 10px; align-items: center;
  padding: 5px 10px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.link-opt:last-child { border-bottom: 0; }
.link-opt.active { background: var(--accent-soft); }
.link-opt .d, .sug-row .d { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sug-row { display: grid; grid-template-columns: auto minmax(60px, auto) 1fr auto; gap: 8px; align-items: center; font-size: 12px; padding: 2px 0; cursor: pointer; }

/* ------------------------------------------------------------ 下拉选择器 */
.picker-pop {
  position: fixed; z-index: 60; min-width: 420px; max-width: 760px; max-height: 420px; overflow: auto;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0,0,0,.18);
}
.picker-pop .sec { padding: 4px 10px; font-size: 11px; color: var(--muted); background: var(--panel-2); border-bottom: 1px solid var(--line); position: sticky; top: 0; }
.picker-pop .opt { display: grid; grid-template-columns: minmax(120px, auto) 1fr auto; gap: 10px; align-items: center; padding: 5px 10px; cursor: pointer; border-bottom: 1px solid var(--line); }
.picker-pop .opt:last-child { border-bottom: 0; }
.picker-pop .opt.active { background: var(--accent-soft); }
.picker-pop .opt .c { font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; }
.picker-pop .opt .d { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-pop .opt .r { white-space: nowrap; }
.picker-pop .opt.new .c { color: var(--accent); font-weight: 600; }
.picker-pop .opt.more .c { color: var(--accent); }
.picker-pop .none { padding: 10px; color: var(--muted); }

/* ------------------------------------------------------------ 弹窗 / 抽屉 */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(15, 23, 30, .35); display: flex; align-items: flex-start; justify-content: center; padding-top: 8vh; }
.modal {
  width: min(640px, 94vw); max-height: 84vh; overflow: auto; background: var(--panel); border-radius: 10px;
  border: 1px solid var(--line); box-shadow: 0 24px 64px rgba(0,0,0,.25);
}
.modal.wide { width: min(980px, 96vw); }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 14px 16px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--panel-2); border-radius: 0 0 10px 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.form-grid .full { grid-column: 1 / -1; }

.drawer {
  position: fixed; top: 48px; right: 0; bottom: 0; z-index: 40; width: min(760px, 96vw);
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: -12px 0 32px rgba(0,0,0,.12);
  overflow: auto;
}
.drawer .drawer-head { position: sticky; top: 0; z-index: 3; background: var(--panel); display: flex; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.drawer .drawer-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 14px; }
.drawer h4 { margin: 0 0 6px; font-size: 13px; }

/* ------------------------------------------------------------ 全局搜索 */
.qs-input { width: 100%; height: 42px; font-size: 16px; border: 0; border-bottom: 1px solid var(--line); border-radius: 10px 10px 0 0; padding: 0 16px; }
.qs-input:focus { box-shadow: none; }
.qs-list { max-height: 60vh; overflow: auto; }
.qs-list .opt { display: grid; grid-template-columns: 56px minmax(160px, auto) 1fr auto; gap: 10px; align-items: center; padding: 7px 14px; cursor: pointer; border-bottom: 1px solid var(--line); }
.qs-list .opt.active { background: var(--accent-soft); }
.qs-list .opt .c { font-family: var(--mono); }
.qs-list .opt .d { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------ 提示 */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 9px 14px; border-radius: 8px; background: var(--text); color: var(--panel); box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 420px; }
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
.alert { padding: 8px 12px; border-radius: 6px; background: var(--danger-soft); color: var(--danger); margin-bottom: 12px; }
.note-box { padding: 8px 12px; border-radius: 6px; background: var(--info-soft); color: var(--info); }
.keys { color: var(--muted); font-size: 12px; display: flex; gap: 12px; flex-wrap: wrap; }

/* ------------------------------------------------------------ 登录 */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card { width: min(360px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; }
.login-brand { text-align: center; margin-bottom: 18px; }
.login-mark { width: 44px; height: 44px; font-size: 22px; border-radius: 12px; }
.login-brand h1 { margin: 10px 0 2px; font-size: 18px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form input { height: 36px; }
.login-form .btn { height: 38px; }

/* 关联采购记录里，物料单价正在用的那条 */
tr.in-use td { background: var(--ok-soft); }

/* ------------------------------------------------------------ 成本审计：产品分析 */
.seg button.tab.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chart-wrap { position: relative; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); }
.chart .axis { stroke: var(--line-2); }
.chart .tick { fill: var(--muted); font-size: 12px; }
.chart .seg { stroke: var(--muted); stroke-dasharray: 4 4; opacity: .55; }
.chart .seg-label { fill: var(--muted); font-size: 11px; }
.chart .hover-line { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart { user-select: none; }
.chart .deal { fill-opacity: var(--deal-op, .28); stroke-opacity: .6; stroke-width: 1; transition: fill-opacity .12s, stroke-opacity .12s; }
.chart .deal.out { fill-opacity: .1; stroke-opacity: .25; }
.chart .deal.dim { fill-opacity: .04; stroke-opacity: .1; }
.chart .range-band { fill: var(--accent); fill-opacity: .07; pointer-events: none; }
.chart .range-edge { stroke: var(--accent); stroke-width: 1.5; pointer-events: none; }
.chart .range-rail { stroke: var(--accent); stroke-width: 4; pointer-events: none; }
.chart .range-axis { fill: transparent; cursor: ew-resize; touch-action: none; }
.chart .range-axis:hover { fill: var(--line); fill-opacity: .35; }
.dot-size { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }
.dot-slider { width: 150px; height: auto; padding: 0; border: 0; background: none; box-shadow: none; accent-color: var(--accent); cursor: pointer; }
.chart .deal.hit { fill-opacity: .6; stroke-opacity: 1; stroke-width: 1.5; }
.chart .hover-dot { stroke: var(--panel); stroke-width: 2; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 5; background: var(--panel); border: 1px solid var(--line-2);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.15); white-space: nowrap;
}
.chart-tip .tip-title { font-weight: 600; margin-bottom: 4px; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 6px; }
.chart-tip .tip-row b { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }
.chart-tip .tip-gap { margin-top: 4px; }
.legend-toggles label { display: inline-flex; align-items: center; gap: 5px; margin-right: 6px; cursor: pointer; }
.swatch { display: inline-block; width: 16px; height: 3px; border-radius: 2px; }
.swatch.dot { width: 9px; height: 9px; border-radius: 50%; }
.swatch.dashed { height: 2px; opacity: .85; }

.link-panel { border-color: var(--info); }

/* 产品族：销售型号表重算中 */
tbody.stale { opacity: .45; }

/* 管理：导入规则 */
.rule-list { margin: 0; padding-left: 18px; }
.rule-list li { margin-bottom: 5px; line-height: 1.55; }

/* PCB 物料库：类别小标题 */
table.grid tr.group-row td { background: var(--panel-2); padding-top: 8px; border-bottom: 1px solid var(--line-2); color: var(--accent); }
table.grid tbody tr.group-row:hover { background: inherit; }
table.grid tr.group-row.foldable td { cursor: pointer; }
.fold-tri { display: inline-block; width: 18px; padding: 0; border: 0; background: none; color: inherit; font: inherit; font-size: 16px; line-height: 1; text-align: left; cursor: pointer; vertical-align: -1px; }
.fold-tri.off { opacity: .3; cursor: default; }
table.grid tr.group-more td { padding-top: 2px; padding-bottom: 4px; color: var(--muted); cursor: pointer; }
table.grid tbody tr.group-more:hover td { color: var(--accent); }

/* ------------------------------------------------------------ 带下拉建议的输入框（类别、公司）和单位下拉
   右侧画一个居中的小箭头；点框就列出全部选项（app.js 的 suggest），不用浏览器自带的 datalist */
input[data-suggest], select.cell {
  padding-right: 22px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238b98a5' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 7px center;
  background-size: 10px 6px;
}
/* 表格里的格子只在鼠标移上去 / 正在编辑时显示箭头，整张表不显得乱 */
input.cell[data-suggest], select.cell { background-image: none; }
input.cell[data-suggest]:hover, input.cell[data-suggest]:focus, select.cell:hover, select.cell:focus {
  background-repeat: no-repeat; background-position: right 7px center; background-size: 10px 6px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238b98a5' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
select.cell {
  appearance: none; width: 100%; height: 26px; padding: 2px 20px 2px 6px; cursor: pointer;
  border-color: transparent; background-color: transparent;
}
select.cell:hover { border-color: var(--line); }
select.cell:focus { background-color: var(--panel); border-color: var(--accent-2); }
.picker-pop.suggest-pop { min-width: 140px; max-height: 280px; }
.picker-pop.suggest-pop .opt { display: block; padding: 5px 10px; white-space: nowrap; }
.picker-pop.suggest-pop .opt.current { font-weight: 600; color: var(--accent); }
/* 物料库表格总宽超出时，浏览器会把类别、单位两列挤到看不见内容，给它们保底宽度 */
td > input.cell[data-suggest] { min-width: 96px; }
td > select.cell { min-width: 56px; }

/* 账号权限 */
.perm-table th.perm-cell, .perm-table td.perm-cell { text-align: center; width: 96px; }
.perm-table td { vertical-align: middle; }
.perm-table td.perm-cell input { width: 16px; height: 16px; margin: 0; cursor: pointer; }
.perm-table td.perm-cell input:disabled { cursor: not-allowed; }
.pw-reveal { font-family: var(--mono); font-size: 18px; padding: 6px 12px; border-radius: 6px; background: var(--panel-2); letter-spacing: .5px; user-select: all; }
.role-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.role-list > div { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
.chip:disabled { opacity: .6; cursor: default; }
tr.muted td { color: var(--muted); }
