/* 所有页面共用：颜色、字体、顶部导航、按钮、输入框；排版页面（index.html）的布局 */
:root {
  --bg: #f4f2ed; --panel: #ffffff; --ink: #24211c; --muted: #77705f; --line: #e3ddd0; --line-strong: #cfc7b6;
  --accent: #1565c0; --accent-weak: #e7effa; --accent-ink: #0d47a1; --hover: #f3f6fb;
  --danger: #c62828; --danger-weak: #fdecea; --warn: #8d6e00; --warn-weak: #fff6dc; --ok: #2e7d32;
  --radius: 8px; --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 1px 1px rgba(40, 30, 10, .04);
  --sheet: #efe6d2; --sheet-edge: #8a7a5a;
  --part: #fbfaf6; --part-locked: #dce8f5; --part-moved: #fff3c4; --conflict: #fde0dc;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
       display: flex; flex-direction: column; }

/* ── 顶部：品牌、四个页面的导航、这一页的控件 ── */
header { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 6px 16px; flex: none; flex-wrap: wrap;
         background: var(--panel); border-bottom: 1px solid var(--line); box-shadow: var(--shadow); position: relative; z-index: 5; }
header .brand { display: flex; align-items: center; margin-right: 6px; }
/* 标志（marketing/inkline/logo/make_logo.py 出的，字已转轮廓）：中文界面 横线 + Inkline 墨线，英文界面不带"墨线" */
header .brand img { height: 16px; display: block; }
header .brand .lang-zh { height: 20.7px; }   /* 带"墨线"那张图上下多出汉字的高度（95.6 / 73.8）：两种语言里 Inkline 一样大 */
html[lang="en"] .brand .lang-zh, html:not([lang="en"]) .brand .lang-en { display: none; }
.appnav { display: flex; gap: 2px; }
.appnav a { color: var(--ink); text-decoration: none; padding: 5px 12px; border-radius: var(--radius-sm); white-space: nowrap; }
.appnav a:hover { background: var(--hover); }
.appnav a.cur { background: var(--accent-weak); color: var(--accent-ink); font-weight: 600; }
.bar-sep { width: 1px; height: 24px; background: var(--line); margin: 0 2px; }
header select { min-width: 260px; max-width: 40vw; }
header .nav { color: var(--accent); text-decoration: none; }
.spacer { flex: 1; }
/* 页内分页（设置：机床 / 刀具库 / 刀路模板 / 加工策略；标签：模板 / 打印机 / 标签纸）：分段按钮 */
.tabs { display: inline-flex; gap: 2px; padding: 3px; background: #eeeae1; border-radius: var(--radius); }
.tabs .tab { border: none; background: transparent; border-radius: var(--radius-sm); padding: 4px 14px; color: var(--muted); }
.tabs .tab:hover:not(:disabled) { color: var(--ink); background: rgba(255, 255, 255, .7); border: none; }
.tabs .tab.active, .tabs .tab.sel { background: #fff; color: var(--accent-ink); font-weight: 600; box-shadow: var(--shadow); }
.dirty { color: var(--warn); font-size: 12px; }

/* ── 按钮、输入框 ── */
button { font: inherit; line-height: 18px; padding: 5px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
         background: #fff; color: var(--ink); cursor: pointer; transition: background .12s, border-color .12s; }
button:hover:not(:disabled) { border-color: var(--accent); background: var(--hover); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: #0f58a8; border-color: #0f58a8; }
input, select, textarea { font: inherit; color: var(--ink); padding: 5px 8px; border: 1px solid var(--line-strong);
                          border-radius: var(--radius-sm); background: #fff; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(21, 101, 192, .15); }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; padding: 0; margin: 0 4px 0 0; vertical-align: middle;
                                           accent-color: var(--accent); box-shadow: none; }
input[type=color] { padding: 2px; height: 30px; width: 46px; }
input[type=range] { padding: 0; border: none; accent-color: var(--accent); }
input[readonly] { background: #f7f5f0; color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0; }
.empty { color: var(--muted); }
.muted { color: var(--muted); }

/* ── 排版页面 ── */
main { flex: 1; display: flex; min-height: 0; }
aside { width: 310px; flex: none; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); padding: 6px 14px 14px; }
aside section { border-bottom: 1px solid var(--line); padding: 12px 0; }
aside section:last-child { border-bottom: none; }
aside h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.row { display: flex; justify-content: space-between; align-items: center; margin: 4px 0; }
.rev-nav { display: flex; align-items: center; gap: 4px; }
.rev-nav button { padding: 0 8px; }
.buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
/* 问题列表（排版页、标签页三个分页共用）：错误红、警告黄、没有问题绿 */
.issues { padding-left: 0; margin: 0; }
.issues li { list-style: none; color: var(--danger); background: var(--danger-weak); border-radius: var(--radius-sm); padding: 5px 8px;
             margin: 4px 0; cursor: pointer; font-size: 13px; border-left: 3px solid var(--danger); }
.issues li.warning { color: var(--warn); background: var(--warn-weak); border-left-color: #d6a300; }
.issues li.ok { color: var(--ok); background: #edf6ee; border-left-color: var(--ok); cursor: default; }
/* 左边的大板列表：按材料分组，点一张右边滚到它；看到哪张高亮哪张 */
#sheet-list { max-height: 40vh; overflow-y: auto; margin: 0 -6px; }
.sl-group { margin-bottom: 6px; }
.sl-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 600; padding: 4px 6px;
           position: sticky; top: 0; background: var(--panel); }
.sl-head .sl-mat { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sl-head .sl-sum { color: var(--muted); font-weight: 400; white-space: nowrap; }
.sl-item { display: grid; grid-template-columns: 3.2em 1fr auto auto; gap: 6px; align-items: baseline; width: 100%;
           font-size: 12px; text-align: left; border: none; background: none; padding: 3px 6px; border-radius: var(--radius-sm); cursor: pointer; }
.sl-item:hover:not(:disabled) { background: var(--hover); }
/* 选中的要压过通用按钮的悬停样式（button:hover:not(:disabled)）：点完鼠标还停在上面 */
.sl-item.active, .sl-item.active:hover:not(:disabled) { background: var(--accent); color: #fff; }
.sl-item .sl-no { font-weight: 600; }
.sl-item .sl-tag { font-size: 11px; color: var(--warn); margin-left: 4px; }
.sl-item.active .sl-tag { color: #fff; }
.sl-item .sl-util { font-variant-numeric: tabular-nums; }
#events { font-size: 12px; color: var(--muted); padding-left: 28px; max-height: 260px; overflow-y: auto; margin: 0; }
#canvas-wrap { flex: 1; position: relative; min-width: 0; }
#canvas { position: absolute; inset: 0; overflow: auto; padding: 52px 16px 16px; }   /* 上边让出缩放按钮（.zoom 浮在右上角），不压第一张板的标题和"模拟加工" */
#canvas svg { display: block; background: var(--bg); }
.zoom { position: absolute; right: 24px; top: 12px; z-index: 2; display: flex; gap: 4px; }
.zoom button { background: rgba(255, 255, 255, .92); box-shadow: var(--shadow); }
svg .sheet-bg { fill: var(--sheet); stroke: var(--sheet-edge); }
svg .trim { fill: none; stroke: #b9a984; stroke-dasharray: 8 6; }
svg .part .outline { fill: var(--part); stroke: var(--ink); }
svg .part.locked .outline { fill: var(--part-locked); }
svg .part.moved .outline { fill: var(--part-moved); }
svg .part.conflict .outline, svg .part.flagged .outline { fill: var(--conflict); stroke: var(--danger); }
svg .part.selected .outline { stroke: var(--accent); stroke-width: 3; }
svg .part { cursor: grab; }
svg.readonly .part, svg .part.locked { cursor: default; }
svg .part.dragging { cursor: grabbing; opacity: .85; }
svg .feat { fill: none; }
svg .feat.machining { stroke: #c0392b; }
svg .note { fill: none; stroke: #1565c0; }                          /* 不切割的：文字、封边记号、纹理线（和标签里的颜色一样） */
svg text.note { fill: #1565c0; stroke: none; font-family: Arial, "Liberation Sans", sans-serif; pointer-events: none; }
svg .outline, svg .feat, svg .note, svg .sheet-bg, svg .trim { vector-effect: non-scaling-stroke; }
svg text { pointer-events: none; fill: var(--ink); font-family: system-ui, sans-serif; }
svg .sheet-label { fill: var(--muted); }
svg .ruler path { stroke: var(--muted); fill: none; vector-effect: non-scaling-stroke; }
svg .ruler text { fill: var(--muted); }   /* 字号在 <g class="ruler" font-size> 上：按缩放算、屏幕上一样大（app.js rulers） */
svg .sim-link text { fill: var(--accent); cursor: pointer; pointer-events: auto; }
svg .sim-link:hover text { text-decoration: underline; }
svg .sim-link.pending text { fill: var(--warn); font-weight: 600; }
dialog { width: min(820px, 92vw); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0, 0, 0, .18); padding: 18px 20px; }
dialog::backdrop { background: rgba(30, 25, 15, .35); }
#new-issues { max-height: 30vh; overflow-y: auto; margin: 8px 0 0; padding-left: 20px; }
#new-issues li { color: var(--danger); margin: 2px 0; }
#new-issues li.warning { color: var(--warn); }
#new-issues li.head { list-style: none; margin-left: -20px; color: var(--ink); font-weight: 600; }
#new-issues li.head.info { color: var(--accent); font-weight: 400; }
#new-issues summary { cursor: pointer; }
#new-issues .more { color: var(--muted); font-size: 12px; }
#new-issues li.group ul { padding-left: 18px; margin: 2px 0; }
dialog .tabs { margin-bottom: 10px; }
.field { display: flex; flex-direction: column; gap: 3px; margin: 8px 0; }
.field input, .field textarea { font: inherit; width: 100%; }
#f-dirs { font: 12px/1.4 ui-monospace, Consolas, monospace; }
.fields { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin: 8px 0; }
.fields label { display: flex; flex-direction: column; gap: 3px; }
.fields input[type=number] { width: 90px; }
.check { display: inline-flex; align-items: center; gap: 4px; margin: 6px 0; }
#f-materials table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 6px 0; }
#f-materials th, #f-materials td { border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: left; }
#f-materials th { background: #f6f3ec; font-weight: 600; }
#f-materials td input[type=number] { width: 72px; }
#f-materials td.num { text-align: right; }
#f-materials .lib { color: var(--muted); font-size: 12px; }
#f-materials tr.missing td { background: #fff3f0; }
/* 排版页面里的模拟：右边画布换成模拟（sim-core.js），左边"模拟加工"一节是控制面板 */
#sim-area { position: absolute; inset: 0; display: flex; flex-direction: column; }
#sim-area[hidden], #canvas-wrap > .zoom[hidden] { display: none; }
.sim-bar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.sim-bar #sim-title { font-weight: 600; }
#sim-view-box { flex: 1; }
#sim-box .sim-panel section { padding: 6px 0; }
#sim-box .sim-panel section:last-child { border-bottom: none; }
#sim-box #sim-code { height: 30vh; }
/* 新任务：选进来的图纸目录（材质目录、零件文件可勾选） */
button.link { border: none; background: none; color: var(--accent); padding: 0 4px; cursor: pointer; }
button.link:hover:not(:disabled) { background: none; text-decoration: underline; }
.hint.ok { color: var(--ok); } .hint.bad { color: var(--danger); }
.src-field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.src-bar { display: flex; align-items: center; gap: 6px 10px; flex-wrap: wrap; }
/* 按钮、下拉、勾选不让长提示挤得换行、截断；提示占剩下的地方，不够就换到下一行 */
.src-bar > button, .src-bar > label, .src-bar select, #qid-opts { flex: none; white-space: nowrap; }
.src-bar > .hint { flex: 1 1 18em; min-width: 0; }
#f-sources { display: flex; flex-direction: column; gap: 8px; max-height: 38vh; overflow-y: auto; }
.src { border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; background: #fcfbf8; }
.src-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.src-head .path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-dirs { list-style: none; margin: 4px 0 0; padding: 0 0 0 6px; }
.src-dirs > li { margin: 2px 0; }
.src-dirs .tw { border: none; background: none; padding: 0 4px; width: 22px; color: var(--muted); }
.src-files { margin: 2px 0 6px 50px; border-collapse: collapse; font-size: 12px; }
.src-files td { padding: 1px 8px 1px 0; }
.src-files td.num { text-align: right; color: var(--muted); white-space: nowrap; }
.src-files th { font-weight: normal; color: var(--muted); text-align: left; padding: 0 8px 0 0; }
.src-files td.rot { white-space: nowrap; color: var(--muted); }
.src-files td.rot.changed { color: var(--accent-ink); font-weight: 600; }     /* 和图纸里写的不一样 */
.src-issues { margin: 4px 0 0; padding-left: 18px; font-size: 12px; }
.src-issues li { color: var(--danger); } .src-issues li.warning { color: var(--warn); }
#f-materials select.r-size { max-width: 170px; }
#f-materials tr:not(.last) td { border-bottom-style: dashed; }
/* 选目录的弹窗 */
#dir-dialog { width: min(720px, 92vw); }
#busy { width: min(520px, 92vw); }
#busy .task-prog { white-space: normal; display: block; }
#busy progress { display: block; width: 100%; height: 14px; margin: 4px 0 10px; }
#export-dialog { width: min(640px, 92vw); }
.renest-opts { display: flex; gap: 12px; align-items: center; margin-top: 10px; }
.renest-nums { display: grid; gap: 6px; font-size: 13px; }
.renest-nums label { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.renest-nums label span { min-width: 3.5em; color: var(--muted); }
.renest-nums input { width: 5.5em; }
/* 对齐：3 × 3 小方格，和板一样的方位（上一排 = 板的上边）；选中的那格实心 */
.align-grid { display: inline-grid; grid-template-columns: repeat(3, 18px); grid-template-rows: repeat(3, 18px); gap: 3px;
  padding: 3px; border: 1px solid var(--line); border-radius: var(--radius-sm); vertical-align: middle; background: var(--sheet); }
.align-grid button { width: 18px; height: 18px; min-width: 0; padding: 0; border: 1.5px solid var(--muted); border-radius: 3px;
  background: #fff; box-shadow: none; cursor: pointer; transition: none; }   /* 小方格不渐变：点了立刻实心 */
.align-grid button.on { background: var(--accent); border-color: var(--accent); }
.align-grid[aria-disabled="true"] button { cursor: default; opacity: .5; }
.ex-name { display: flex; gap: 8px; align-items: center; }
.ex-dir { margin: 6px 0; overflow-wrap: anywhere; }
.task-prog { white-space: nowrap; }
.task-prog progress { width: 140px; height: 10px; vertical-align: middle; margin-right: 4px; }
.ex-dir button { margin-left: 4px; }
.ex-name input { flex: 1; min-width: 0; font-family: ui-monospace, Consolas, monospace; }
#ex-names { list-style: none; margin: 6px 0; padding: 4px 8px; max-height: 40vh; overflow-y: auto; border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
#ex-names li { padding: 3px 0; }
#ex-names li.note { color: var(--muted); font-family: inherit; font-size: 12px; }
#ex-names li .len { color: var(--muted); white-space: nowrap; }
#ex-names li.bad, #ex-names li.bad .len { color: var(--danger); }
#new-dialog { width: min(1080px, 95vw); }
#f-materials th { white-space: nowrap; }
#f-materials td.mat { min-width: 200px; }
.dir-path { display: flex; gap: 6px; }
.dir-path input { flex: 1; min-width: 0; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
#dir-list { list-style: none; margin: 6px 0; padding: 4px; height: 46vh; overflow-y: auto; border: 1px solid var(--line);
            border-radius: var(--radius); background: #fff; }
#dir-list li { padding: 4px 8px; border-radius: var(--radius-sm); cursor: pointer; }
#dir-list li:hover { background: var(--hover); }
#dir-list li.sel { background: var(--accent-weak); color: var(--accent-ink); }
#dir-list li.none { color: var(--muted); cursor: default; }
#dir-list .ico { margin-right: 6px; }
#dir-list .tag { font-size: 11px; padding: 0 5px; border-radius: 8px; background: var(--accent-weak); color: var(--accent-ink); }
/* 新任务：策略不认得的层 */
.unknown { border: 1px solid #e8d38a; background: var(--warn-weak); border-radius: var(--radius); padding: 6px 12px; margin: 6px 0; font-size: 13px; }
.unknown p { margin: 4px 0; }
.unknown table { border-collapse: collapse; margin: 4px 0 6px; }
.unknown td { padding: 2px 10px 2px 0; }
.queue .q-head { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.queue .q-list { border-collapse: collapse; font-size: 13px; margin-top: 4px; }
.queue .q-list td { padding: 3px 8px; border-top: 1px solid #e5e1d8; white-space: nowrap; }

/* 云端（host.js 给 <html> 加 .cloud）：本机才有的东西藏起来 */
.cloud:not(.shell) .tab[data-tab="printers"], .cloud:not(.shell) #pane-printers, .cloud:not(.shell) #test-printer, .cloud:not(.shell) #test-print { display: none !important; }
.host-dialog { border: 1px solid #ccc; border-radius: 8px; padding: 18px 22px; min-width: 360px; }
.host-dialog .actions { display: flex; gap: 8px; margin-top: 12px; }
.host-dialog .bad { color: #b42318; }
.host-logout { margin-left: 8px; }
.host-support { margin-left: 8px; white-space: nowrap; }
.host-download { margin-left: 8px; color: var(--accent); white-space: nowrap; }
.host-version { margin-left: 8px; color: #888; font-size: 12px; white-space: nowrap; }
.host-upgrade { display: flex; align-items: center; gap: 10px; padding: 6px 16px; background: #fff7e0; border-bottom: 1px solid #f0d58a; }

/* 新任务零件表：数量、旋转可改（改过的标出来） */
.src-files .f-qty { width: 5em; text-align: right; }
.src-files .f-qty.bad { border-color: var(--bad, #c0392b); }
.src-files td.changed .f-qty, .src-files td.changed .f-rot { font-weight: 600; color: var(--accent-ink); }

/* 新任务问题列表："细节""忽略"；细节对话框里的板件缩略图（红 = 问题所在） */
#new-issues .iss-act { font-size: 12px; padding: 0 4px; margin-left: 4px; }
#issue-dialog { width: min(760px, 94vw); }
#issue-dialog .iss-msg { color: var(--danger); margin: 4px 0 8px; }
#issue-dialog .iss-svg { border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; height: min(52vh, 460px); }
#issue-dialog svg.iss-part { width: 100%; height: 100%; }
#issue-dialog svg.iss-part * { fill: none; vector-effect: non-scaling-stroke; }
#issue-dialog svg.iss-part .ol { stroke: #333; stroke-width: 1.5; }
#issue-dialog svg.iss-part .ft { stroke: #8a8f98; stroke-width: 1; }
#issue-dialog svg.iss-part .hit { stroke: #d32f2f; stroke-width: 3; }
#issue-dialog svg.iss-part .dash { stroke-dasharray: 8 5; }
#issue-dialog .iss-info { white-space: pre-line; }
#issue-dialog svg.iss-part text.tx { fill: #8a8f98; stroke: none; }
#issue-dialog svg.iss-part text.tx.hit { fill: #d32f2f; }
