/* ===== ThermoFlow Web — global styles ===== */
* { box-sizing: border-box; }
:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --border: #d8dee9;
  --border-strong: #b6c0cf;
  --text: #1f2933;
  --muted: #6b7785;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --accent: #0e7490;
  --ok: #15803d;
  --warn: #b45309;
  --err: #b91c1c;
  --steam: #0e7490;
  --gas: #b45309;
  --water: #2563eb;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
  --radius: 8px;
}
html, body {
  margin: 0; height: 100%;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 13px; color: var(--text); background: var(--bg);
}
body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* Topbar */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 8px 14px; background: var(--panel);
  border-bottom: 1px solid var(--border); box-shadow: var(--shadow); z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand .logo { color: var(--primary); font-size: 20px; }
.brand small { color: var(--muted); font-weight: 600; font-size: 11px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex: 1 1 100%; }
.tool-group { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; }
.divider { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.status { font-size: 12px; color: var(--muted); padding: 4px 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 20px; margin-left: auto; }
.status.err { color: var(--err); border-color: #f0c0c0; background: #fdf0f0; }
.status.ok { color: var(--ok); border-color: #c0e0c8; background: #f0faf2; }

.btn, .select {
  font: inherit; padding: 6px 12px; border: 1px solid var(--border-strong);
  background: var(--panel); border-radius: var(--radius); cursor: pointer; color: var(--text);
  transition: .12s;
}
.btn:hover, .select:hover { background: var(--panel-2); border-color: var(--primary); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary-d); font-weight: 600; }
.btn-primary:hover { background: var(--primary-d); }
.btn-lang { font-weight: 600; }
.select { padding: 6px 8px; }

/* Layout */
.layout { flex: 1; display: flex; min-height: 0; }
.palette { width: 200px; background: var(--panel); border-right: 1px solid var(--border); overflow-y: auto; padding: 8px; }
.canvas-wrap { position: relative; flex: 1; overflow: auto; background:
  radial-gradient(circle, #e3e8ef 1px, transparent 1px) 0 0 / 22px 22px, var(--bg); }
.inspector { width: 290px; background: var(--panel); border-left: 1px solid var(--border); overflow-y: auto; padding: 10px; }

.panel-title { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 6px 4px; }
.palette-group { font-size: 11px; font-weight: 700; color: var(--accent); margin: 10px 4px 4px; text-transform: uppercase; letter-spacing: .03em; }
.palette-items { display: flex; flex-wrap: wrap; gap: 6px; }
.palette-item {
  display: flex; align-items: center; gap: 6px; width: calc(50% - 3px);
  padding: 7px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2);
  cursor: grab; font-size: 11.5px; user-select: none; transition: .12s;
}
.palette-item:hover { border-color: var(--primary); box-shadow: var(--shadow); transform: translateY(-1px); }
.palette-item .pi-icon { font-size: 15px; width: 18px; text-align: center; }
.palette-item:active { cursor: grabbing; }

/* Canvas nodes */
.nodes { position: absolute; inset: 0; min-width: 100%; min-height: 100%; }
.wires { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.node {
  position: absolute; width: 132px; background: var(--panel); border: 1.5px solid var(--border-strong);
  border-radius: 8px; box-shadow: var(--shadow); user-select: none; cursor: move;
}
.node.selected { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.25), var(--shadow); }
.node .node-head { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-bottom: 1px solid var(--border); border-radius: 7px 7px 0 0; font-weight: 600; font-size: 12px; }
.node .node-head .ni { font-size: 15px; }
.node .node-body { font-size: 10.5px; color: var(--muted); padding: 4px 8px 6px; line-height: 1.35; max-height: 54px; overflow: hidden; }
.node .node-body b { color: var(--text); font-weight: 600; }
.node .port {
  position: absolute; width: 13px; height: 13px; border-radius: 50%; background: #fff;
  border: 2px solid var(--primary); cursor: crosshair; z-index: 3;
}
.node .port.in { left: -7px; }
.node .port.out { right: -7px; }
.node .port:hover { background: var(--primary); transform: scale(1.25); }
.node .port-label { position: absolute; font-size: 9px; color: var(--muted); white-space: nowrap; }
.node .port-label.in { left: 10px; }
.node .port-label.out { right: 10px; }

.node.cat-boundary .node-head { background: #eef2ff; }
.node.cat-rotating .node-head { background: #fef3e7; }
.node.cat-thermal .node-head { background: #ecfeff; }
.node.cat-flow .node-head { background: #f0fdf4; }

.canvas-hint { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); background: rgba(255,255,255,.92); border: 1px solid var(--border); padding: 8px 14px; border-radius: 20px; font-size: 11.5px; color: var(--muted); max-width: 70%; text-align: center; pointer-events: none; }

/* Wires */
.wire { stroke: #94a3b8; stroke-width: 2; fill: none; }
.wire.selected { stroke: var(--primary); stroke-width: 3; }
.wire.hot { stroke: var(--gas); }
.wire.cold { stroke: var(--water); }
.wire-label { font-size: 9.5px; fill: var(--muted); }
.wire-hit { stroke: transparent; stroke-width: 12; fill: none; pointer-events: stroke; cursor: pointer; }

/* toolbar toggle buttons */
.btn-toggle.active { background: var(--primary); color: #fff; border-color: var(--primary-d); }
.btn-toggle.active:hover { background: var(--primary-d); }

/* alignment guide lines while dragging */
.guide { stroke: #f43f5e; stroke-width: 1; stroke-dasharray: 4 3; opacity: .85; pointer-events: none; }

/* Inspector */
.inspector-body .field { margin-bottom: 9px; }
.inspector-body label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.inspector-body input, .inspector-body select {
  width: 100%; padding: 5px 7px; border: 1px solid var(--border-strong); border-radius: 6px; font: inherit; color: var(--text); background: var(--panel);
}
.inspector-body input:focus, .inspector-body select:focus { outline: none; border-color: var(--primary); }
.insp-title { font-weight: 700; font-size: 13px; margin-bottom: 2px; display: flex; align-items: center; gap: 6px; }
.insp-sub { font-size: 11px; color: var(--muted); margin-bottom: 10px; }
.insp-section { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--accent); margin: 12px 0 4px; letter-spacing: .03em; }
.result-mini { font-size: 11px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; margin-bottom: 6px; }
.result-mini b { color: var(--text); }
.btn-del { background: #fef2f2; border-color: #f0c0c0; color: var(--err); width: 100%; margin-top: 8px; }
.btn-del:hover { background: #fde8e8; }

/* Results panel */
.results { height: 240px; background: var(--panel); border-top: 1px solid var(--border); display: flex; flex-direction: column; }
.results-tabs { display: flex; gap: 2px; padding: 4px 8px 0; border-bottom: 1px solid var(--border); background: var(--panel-2); }
.tab { font: inherit; padding: 7px 14px; border: none; background: transparent; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.results-body { flex: 1; overflow: auto; padding: 10px 14px; }

/* Tables */
table.tbl { width: 100%; border-collapse: collapse; font-size: 11.5px; }
table.tbl th, table.tbl td { border: 1px solid var(--border); padding: 4px 7px; text-align: right; }
table.tbl th { background: var(--panel-2); color: var(--muted); font-weight: 600; }
table.tbl td.lbl, table.tbl th.lbl { text-align: left; }
table.tbl tr:nth-child(even) td { background: #fbfcfe; }
table.tbl td.pos { color: var(--ok); font-weight: 600; }
table.tbl td.neg { color: var(--err); font-weight: 600; }
.tbl-scroll { overflow-x: auto; margin-bottom: 6px; }
.finance-form .fld { min-width: 130px; }
.finance-form input { width: 100%; box-sizing: border-box; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.kpi .k-label { font-size: 11px; color: var(--muted); }
.kpi .k-value { font-size: 20px; font-weight: 700; margin-top: 2px; }
.kpi .k-unit { font-size: 11px; color: var(--muted); font-weight: 400; }
.section-h { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 6px; }
.section-h2 { font-weight: 600; font-size: 12.5px; color: var(--text); margin: 10px 0 6px; }
.kpi-inline { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0; font-size: 13px; }
.kpi-mini { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; }
.demo-bar { margin-bottom: 8px; }
svg.chart { display: block; max-width: 680px; margin: 6px 0; background: #fff; border: 1px solid var(--border); border-radius: 8px; }
.muted { color: var(--muted); }
.msg { font-size: 11.5px; padding: 4px 8px; border-radius: 5px; margin-bottom: 4px; }
.msg.info { background: #eff6ff; color: #1e40af; }
.msg.warn { background: #fffbeb; color: var(--warn); }
.msg.err { background: #fef2f2; color: var(--err); }
.chart-wrap { margin-top: 8px; }
.empty-note { color: var(--muted); font-size: 12px; padding: 20px; text-align: center; }

/* connection dragging */
#temp-wire { stroke: var(--primary); stroke-width: 2; stroke-dasharray: 5 4; fill: none; pointer-events: none; }

/* ===== PDE (Plant Design Expert) wizard ===== */
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: #0c5e76; }
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, .45);
  display: none; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  width: 540px; max-width: 100%; max-height: 92vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--border-strong);
  border-radius: 12px; box-shadow: 0 12px 40px rgba(16, 24, 40, .25);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 6px; }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-x { border: none; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-x:hover { color: var(--err); }
.modal-sub { margin: 0 18px 10px; font-size: 12px; color: var(--muted); }
.modal-body { padding: 6px 18px 4px; }
.fld { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.fld > span { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.fld input, .fld select {
  font: inherit; padding: 7px 9px; border: 1px solid var(--border-strong);
  border-radius: var(--radius); background: var(--panel);
}
.fld-row { display: flex; gap: 12px; }
.fld-row .fld { flex: 1; }
.fld-row.checks { gap: 20px; margin: 4px 0 6px; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 12.5px; cursor: pointer; }
.chk input { width: 15px; height: 15px; }
.modal-note { margin: 6px 18px; padding: 8px 10px; border-radius: 8px; font-size: 12px; line-height: 1.5; min-height: 0; }
.modal-note.ok { background: #f0faf2; color: var(--ok); border: 1px solid #c0e0c8; }
.modal-note.err { background: #fef2f2; color: var(--err); border: 1px solid #f0c0c0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 8px 18px 16px; }

/* sensitivity analysis */
.modal-wide { width: 900px; }
.sens-form { padding: 4px 18px 8px; }
.sens-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.sens-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.sens-field select, .sens-field input { min-width: 160px; }
.sens-range .sens-field input { min-width: 84px; }
.sens-range .btn-primary { height: 34px; margin-left: auto; }
.sens-chart { padding: 4px 18px; }
.sens-note { margin: 6px 18px; font-size: 12px; color: var(--muted); }
.sens-table { padding: 8px 18px 18px; max-height: 220px; overflow: auto; }
.sens-table table { width: 100%; border-collapse: collapse; font-size: 12px; }
.sens-table th, .sens-table td { border: 1px solid var(--border); padding: 4px 8px; text-align: right; }
.sens-table th { background: var(--bg-2); color: var(--muted); position: sticky; top: 0; }
.sens-table td.dev-pos { color: #1e824c; font-weight: 600; }
.sens-table td.dev-neg { color: #c0392b; font-weight: 600; }
.sens-table tr.design-row { background: #fff4e6; }
.sens-table tr.design-row td:first-child { font-weight: 600; }
.sens-table tr.best-row { background: #eef4ff; }
.sens-table tr.best-row td { font-weight: 600; }
.btn-sm { padding: 2px 8px; font-size: 11px; min-height: auto; }
.variants-list { margin: 8px 18px; }
.variants-list .tbl td { font-size: 12px; }
