:root {
  --bg: #f4efe4;
  --bg2: #ece4d4;
  --paper: #fffdf7;
  --ink: #2f2a24;
  --ink-soft: #6b6152;
  --line: #d9cdb6;
  --accent: #9c3b2e;
  --accent2: #3f6b5e;
  --gold: #b98a2f;
  --shadow: 0 2px 10px rgba(80, 60, 30, 0.10);
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% 0%, #faf6ec, var(--bg));
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px;
  background: linear-gradient(120deg, #3a2f26, #503f30);
  color: #f6efe0;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  display: grid; place-items: center;
  width: 46px; height: 46px; border-radius: 10px;
  background: linear-gradient(135deg, var(--gold), #8a6420);
  color: #241d12; font-weight: 800; font-size: 15px; letter-spacing: 1px;
}
.topbar h1 { font-size: 18px; letter-spacing: 1px; }
.topbar p { margin: 2px 0 0; font-size: 12px; color: #cdbfa6; }
.topbar-actions { display: flex; gap: 8px; }

/* ---------- 布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 320px;
  gap: 14px;
  padding: 14px;
  align-items: start;
}
.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 14px; margin-bottom: 10px; color: var(--accent); letter-spacing: .5px; }
.card.grow { flex: 1; min-height: 120px; }

/* ---------- 表单 ---------- */
.field { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.field > span { font-size: 13px; color: var(--ink-soft); }
.field input[type="number"] {
  width: 96px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; font-size: 13px; text-align: right;
}
.field input[type="range"] { flex: 1; accent-color: var(--accent); }
.field-line { display: flex; justify-content: space-between; padding: 6px 0; border-top: 1px dashed var(--line); color: var(--ink-soft); }
.field-line b { color: var(--accent); font-size: 15px; }
.hint { font-size: 11.5px; color: #948a78; margin: 6px 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 9px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--line); background: #fff; cursor: pointer; color: var(--ink-soft);
  transition: all .15s;
}
.chip:hover { border-color: var(--accent2); }
.chip.on { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.chip-ic { font-size: 13px; }

.demand-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; max-height: 220px; overflow-y: auto; }
.demand-row { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.dr-name { flex: 1; color: var(--ink-soft); }
.demand-row input { width: 56px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; text-align: right; font-size: 12px; }

.intensity-list { display: flex; flex-direction: column; gap: 5px; max-height: 260px; overflow-y: auto; }
.int-row { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.int-name { width: 46px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.int-row input[type="range"] { flex: 1; accent-color: var(--accent2); }
.int-val { width: 26px; text-align: right; color: var(--accent2); }
.field.toggle input { width: auto; }

/* ---------- 甘特 / 负载 ---------- */
.gantt { display: flex; flex-direction: column; gap: 4px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fff; }
.grow2 { display: grid; grid-template-columns: 190px 1fr; gap: 8px; align-items: center; }
.glabel { font-size: 11px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gtrack { position: relative; height: 18px; background: var(--bg2); border-radius: 4px; overflow: hidden; }
.gblock { position: absolute; top: 0; height: 18px; border-radius: 3px; color: #fff; font-size: 10px; text-align: center; line-height: 18px; opacity: .92; border-left: 1px solid #fff; }
.gaxis { position: relative; height: 16px; margin-left: 198px; margin-top: 4px; border-top: 1px dashed var(--line); }
.gaxis span { position: absolute; transform: translateX(-50%); font-size: 10px; color: #948a78; top: 2px; }
.loadbar { height: 24px; background: var(--bg2); border-radius: 6px; overflow: hidden; }
.loadfill { height: 100%; background: linear-gradient(90deg, var(--accent2), #6fae9b); color: #fff; font-size: 11px; line-height: 24px; padding-left: 8px; white-space: nowrap; }
.scroll-wrap { max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.scroll-wrap .data-table th { position: sticky; top: 0; z-index: 1; }

/* ---------- 弹窗 ---------- */
.modal { display: none; position: fixed; inset: 0; background: rgba(40, 32, 24, .45); z-index: 50; align-items: center; justify-content: center; }
.modal.show { display: flex; }
.modal-box { background: var(--paper); width: min(900px, 94vw); max-height: 88vh; border-radius: 14px; box-shadow: 0 12px 40px rgba(0, 0, 0, .3); display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 14px 16px; overflow-y: auto; }
.edit-table input, .edit-table select { width: 100%; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; }
.bld-list { display: flex; flex-direction: column; gap: 12px; }
.bld-edit { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fff; }
.bld-edit-head { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.bld-edit-head input { padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; }
.mini-table input { width: 100%; padding: 3px 5px; border: 1px solid var(--line); border-radius: 5px; font-size: 11px; }
code { background: var(--bg2); padding: 1px 5px; border-radius: 4px; font-size: 11px; }

/* ---------- 建筑库 ---------- */
.palette { display: flex; flex-direction: column; gap: 6px; max-height: 460px; overflow-y: auto; }
.palette-cat { font-size: 11px; color: #a2967f; margin: 6px 0 2px; letter-spacing: 1px; }
.pal-card {
  display: flex; align-items: center; gap: 10px; padding: 7px 9px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: grab;
  transition: all .15s;
}
.pal-card:hover { border-color: var(--gold); transform: translateX(2px); box-shadow: var(--shadow); }
.pal-ic { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; font-size: 18px; }
.pal-name { font-size: 13px; font-weight: 600; }
.pal-cost { font-size: 11px; color: #998d78; }

/* ---------- 工具栏 ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; }
.toolbar .spacer { flex: 1; }
.stat { font-size: 12px; color: var(--ink-soft); }
.stat i { font-style: normal; font-weight: 700; color: var(--accent); }
select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 13px;
}

/* ---------- 按钮 ---------- */
.btn {
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; font-size: 13px; cursor: pointer; font-weight: 600;
  transition: all .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn.primary { background: var(--accent2); border-color: var(--accent2); }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn.danger { background: #fff; color: #b03a2e; border-color: #d8b3ad; }

/* ---------- 画布 ---------- */
.canvas {
  position: relative;
  height: 420px;
  background:
    linear-gradient(#e6dcc6 1px, transparent 1px) 0 0 / 100% 26px,
    linear-gradient(90deg, #e6dcc6 1px, transparent 1px) 0 0 / 26px 100%,
    var(--bg2);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: inset 0 1px 6px rgba(120, 100, 60, .12);
}
.graph-svg { width: 100%; height: 100%; display: block; }
.graph-svg.linking { cursor: crosshair; }
.node { cursor: grab; }
.node .node-bg { filter: drop-shadow(0 2px 3px rgba(80, 60, 30, .18)); }
.node.selected .node-bg { stroke-width: 2.5; }
.node-title { font-size: 13px; font-weight: 700; fill: var(--ink); }
.node-sub { font-size: 11px; fill: var(--ink-soft); }
.node-sub.dim { fill: #a2967f; }
.port { fill: #fff; stroke: var(--gold); stroke-width: 2; opacity: 0; transition: opacity .15s; }
.node:hover .port { opacity: 1; }
.edge { fill: none; stroke: #b4a184; stroke-width: 2; opacity: .85; }
.edge.hover { stroke: var(--accent); stroke-width: 3; cursor: pointer; }
.temp-link { fill: none; stroke: var(--accent2); stroke-width: 2; stroke-dasharray: 5 4; }
.link-hint { display: none; }

/* ---------- 检查器 ---------- */
.insp-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 15px; }
.insp-total { margin-left: auto; font-size: 12px; color: var(--accent); font-weight: 700; }
.insp-modes-title { font-size: 12px; color: #948a78; margin: 10px 0 4px; }
.parts { display: flex; flex-direction: column; gap: 6px; }
.part-row { display: flex; align-items: center; gap: 6px; }
.part-row span { font-size: 12px; color: var(--ink-soft); }
.part-count { width: 52px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; text-align: right; font-size: 12px; }
.part-level { flex: 1; accent-color: var(--accent2); }
.part-lv { font-size: 12px; color: var(--accent2); min-width: 40px; }
.part-del { padding: 2px 8px; line-height: 1; }
.btn.small { padding: 5px 10px; font-size: 12px; margin-top: 8px; }
.mini-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.mini-table th, .mini-table td { border: 1px solid var(--line); padding: 3px 5px; text-align: left; }
.mini-table th { background: var(--bg2); color: var(--ink-soft); font-weight: 600; }
.insp-actions { display: flex; gap: 8px; margin-top: 12px; }

/* ---------- 结果 ---------- */
.results { margin-top: 0; }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tab {
  padding: 9px 14px; border: none; background: transparent; cursor: pointer;
  font-size: 13px; color: var(--ink-soft); border-bottom: 2px solid transparent; font-weight: 600;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel-head p { margin: 2px 0 0; font-size: 12px; color: var(--ink-soft); }
.panel-body { min-height: 80px; }
.muted { color: #948a78; font-size: 13px; }
.bad { color: #b03a2e; font-size: 13px; padding: 10px; background: #fbeae7; border-radius: 8px; }

.kpis { display: flex; gap: 12px; margin-bottom: 14px; }
.kpi { flex: 1; background: var(--bg2); border-radius: 10px; padding: 10px 12px; }
.kpi-v { font-size: 22px; font-weight: 800; color: var(--accent); }
.kpi-l { font-size: 11px; color: var(--ink-soft); }

h4 { font-size: 13px; margin: 16px 0 8px; color: var(--accent2); }

.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th, .data-table td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; }
.data-table thead th { background: var(--bg2); color: var(--ink-soft); font-weight: 600; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .pos { color: var(--accent2); }
.data-table .neg { color: #b03a2e; }

.act-list { margin: 0; padding-left: 16px; font-size: 12px; color: var(--ink-soft); }
.design-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.design-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fff; }
.dc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.dc-count { margin-left: auto; font-size: 12px; color: var(--accent); font-weight: 700; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px);
  background: #2f2a24; color: #fff; padding: 10px 18px; border-radius: 8px;
  opacity: 0; transition: all .25s; pointer-events: none; font-size: 13px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr; }
  .canvas { height: 340px; }
}

/* ---------- 画布缩放 / 连线过滤 ---------- */
.toolbar { flex-wrap: wrap; }
.zoom-group { display: inline-flex; align-items: center; gap: 4px; }
.zoom-group .btn.small { margin-top: 0; padding: 4px 8px; }
.edge-filter { position: relative; }
.edge-filter > summary {
  list-style: none; cursor: pointer; padding: 7px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; font-size: 13px; font-weight: 600; color: var(--ink);
  user-select: none;
}
.edge-filter > summary::-webkit-details-marker { display: none; }
.edge-filter[open] > summary { border-color: var(--accent2); color: var(--accent2); }
.edge-filter-body {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30;
  width: 290px; max-height: 280px; overflow-y: auto;
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 10px; background: var(--paper); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 10px 28px rgba(60, 44, 24, .18);
}
.edge-filter-body .chip { cursor: pointer; user-select: none; }
.chip.off { opacity: .42; text-decoration: line-through; }
.edge-filter-empty { font-size: 12px; color: var(--ink-soft); }

/* ---------- 校验 ---------- */
.verify {
  background: #f7f2e7; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 12.5px; color: var(--ink-soft);
  margin-bottom: 14px; display: flex; flex-direction: column; gap: 4px;
}
.verify b { color: var(--ink); }

/* ---------- 编辑器扩展 ---------- */
.bld-edit-head code, .edit-table code { font-size: 11px; color: var(--ink-soft); }
.bld-edit-sub { font-size: 11.5px; color: var(--ink-soft); margin-bottom: 8px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.bld-edit-sub .arrow { color: #b7a98f; }
.inline { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--ink-soft); }
input.tiny { width: 64px; padding: 3px 5px; border: 1px solid var(--line); border-radius: 5px; font-size: 11px; }
.bad-input { border-color: #b03a2e !important; background: #fbeae7 !important; }
.warn { font-size: 11.5px; color: #b03a2e; background: #fbeae7; border-radius: 6px; padding: 4px 8px; margin-bottom: 6px; }
.tier-del { padding: 2px 7px; margin-top: 0; line-height: 1; }
.tier-add { padding: 3px 8px; margin-top: 6px; }
.use-count { font-style: normal; font-size: 10px; opacity: .7; margin-left: 2px; }

.add-row { display: flex; gap: 6px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.add-row input { padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; }
.add-row .btn.small { margin-top: 0; }

.storage-note { font-size: 12.5px; border-radius: 8px; padding: 8px 10px; margin-top: 10px; background: var(--bg2); color: var(--ink-soft); }
.storage-note b { color: var(--ink); }

/* ---------- 多城运输分配 ---------- */
.tp-setup { margin-bottom: 12px; }
.tp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 4px 18px; margin-bottom: 8px; }
.tp-grid .field { margin-bottom: 4px; }
.tp-grid select { padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font-size: 12.5px; }
.tp-scroll { max-height: none; margin-top: 6px; }
.tp-table input { width: 100%; min-width: 54px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; font-size: 12px; }
.tp-table input[data-k="name"] { min-width: 84px; }
.tp-actions { display: flex; gap: 8px; margin-top: 10px; }
.mini-btn { border: 1px solid var(--line); background: #fff; border-radius: 5px; padding: 3px 8px; font-size: 11.5px; color: #b03a2e; cursor: pointer; }
.mini-btn:hover { border-color: #b03a2e; background: #fbeae7; }
.tp-rule-head { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 6px; }
.tp-rules { margin: 0 0 12px; padding-left: 18px; font-size: 12.5px; line-height: 1.7; }
.tp-rules b { color: var(--accent); }
.tp-warns { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.tp-warn { font-size: 12.5px; line-height: 1.6; border-radius: 8px; padding: 7px 10px; background: var(--bg2); border-left: 3px solid var(--line); }
.tp-warn b { margin-right: 8px; font-size: 11px; letter-spacing: .5px; }
.tp-warn.bad { background: #fbeae7; border-left-color: #b03a2e; }
.tp-warn.bad b { color: #b03a2e; }
.tp-warn.warn { background: #fdf3e2; border-left-color: #c98a2e; }
.tp-warn.warn b { color: #a86f1f; }
.tp-warn.info { border-left-color: var(--accent2); }
.tp-warn.info b { color: var(--accent2); }

/* ---------- 完整生产链 ---------- */
.rule-tag { display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 999px; font-size: 10.5px; background: var(--accent2); color: #fff; vertical-align: 1px; }
.chain-eq { color: var(--accent); font-style: italic; }
.chain-ops { white-space: nowrap; }
.mini-btn.alt { color: var(--accent); margin-right: 4px; }
.mini-btn.alt:hover { border-color: var(--accent); background: #f6efe4; }
.chain-editor .chain-table input { min-width: 58px; }
.chain-editor .chain-table input[data-f="in"], .chain-editor .chain-table input[data-f="out"] { min-width: 92px; }
.chain-editor .chain-table input[data-f="name"] { min-width: 72px; }
.chain-equivalent { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: var(--bg2); font-size: 12.5px; line-height: 1.7; }
.chain-equivalent b { color: var(--accent); }
.chain-cards { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.chain-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fff; }
.cc-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; font-size: 13px; }
.cc-eq { color: var(--ink-soft); font-size: 12px; }
.chain-card .scroll-wrap { max-height: none; }
