:root {
  --bg: #0e1726; --bg2: #14213a; --panel: #182742; --panel2: #1e3052;
  --line: #2a3f63; --line2: #38507a; --text: #e7eef9; --muted: #93a6c6;
  --accent: #36b3ff; --accent2: #1f7fd0; --good: #38d39f; --warn: #ffbb4d;
  --bad: #ff6b6b; --chw: #36b3ff; --cw: #ff8c42; --ref: #b86bff;
  --radius: 9px; --shadow: 0 6px 22px rgba(0,0,0,.32);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: radial-gradient(1200px 700px at 75% -10%, #1a2c4d 0%, var(--bg) 55%);
  color: var(--text); font-size: 14px; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }
.hidden { display: none !important; }

/* ---- Auth ---- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 380px; max-width: 100%; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 11px; margin-bottom: 6px; }
.brand .logo { width: 38px; height: 38px; }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: .2px; }
.brand .sub { color: var(--muted); font-size: 12px; }
.auth-card h2 { font-size: 16px; margin: 18px 0 14px; }
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 10px 11px; background: var(--bg2); border: 1px solid var(--line2);
  border-radius: 8px; color: var(--text); font-size: 13px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 15px; border-radius: 8px; border: 1px solid var(--line2);
  background: var(--panel2); color: var(--text); cursor: pointer; font-size: 13px;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #24385f; border-color: var(--line2); }
.btn.primary { background: linear-gradient(180deg, var(--accent), var(--accent2)); border: none; color: #04141f; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.full { width: 100%; }
.btn.danger { color: var(--bad); border-color: #50324a; }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.muted { color: var(--muted); }
.error { color: var(--bad); font-size: 12.5px; min-height: 16px; margin-top: 4px; }
.switch-line { margin-top: 14px; font-size: 12.5px; color: var(--muted); text-align: center; }

/* ---- App shell ---- */
.app { display: grid; grid-template-rows: 50px 1fr; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 0 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar .brand h1 { font-size: 15px; }
.topbar .spacer { flex: 1; }
.proj-name { font-weight: 600; }
.proj-name input { width: 230px; padding: 6px 9px; font-size: 13px; }
.chip { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--bg2); color: var(--muted); border: 1px solid var(--line); }
.workspace { display: grid; grid-template-columns: 232px 1fr 332px; overflow: hidden; }
.sidebar, .inspector { background: var(--panel); overflow-y: auto; }
.sidebar { border-right: 1px solid var(--line); }
.inspector { border-left: 1px solid var(--line); }
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); padding: 13px 14px 6px; }

/* palette */
.palette-group { padding: 0 10px 8px; }
.palette-group h4 { font-size: 11px; color: var(--muted); margin: 10px 4px 6px; text-transform: uppercase; letter-spacing: .5px; }
.pal-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px; margin: 4px 0;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 7px;
  cursor: grab; font-size: 12.5px; user-select: none;
}
.pal-item:hover { border-color: var(--accent2); background: #1b2c4b; }
.pal-item .ic { width: 18px; height: 18px; flex: none; }

/* canvas */
.canvas-wrap { position: relative; overflow: hidden; background:
  linear-gradient(0deg, transparent 23px, #16243f 24px), linear-gradient(90deg, transparent 23px, #16243f 24px);
  background-size: 24px 24px; background-color: #0f1b30; }
#canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.canvas-toolbar {
  position: absolute; top: 10px; left: 10px; display: flex; gap: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 5px;
}
.canvas-hint { position: absolute; bottom: 10px; left: 10px; font-size: 11.5px; color: var(--muted); background: rgba(15,27,48,.8); padding: 5px 9px; border-radius: 6px; }

/* node + ports */
.node rect.body { fill: var(--panel2); stroke: var(--line2); stroke-width: 1.5; }
.node.selected rect.body { stroke: var(--accent); stroke-width: 2.5; }
.node text.label { fill: var(--text); font-size: 11px; }
.node text.tag { fill: var(--accent); font-size: 10px; font-weight: 700; }
.port { stroke: #0f1b30; stroke-width: 1.5; cursor: crosshair; }
.port.chilled_water { fill: var(--chw); }
.port.condenser_water { fill: var(--cw); }
.port.refrigerant { fill: var(--ref); }
.port.air { fill: var(--good); }
.port.armed { stroke: #fff; stroke-width: 2.5; }
.edge { fill: none; stroke-width: 2.4; }
.edge.chilled_water { stroke: var(--chw); }
.edge.condenser_water { stroke: var(--cw); }
.edge.refrigerant { stroke: var(--ref); }
.edge.selected { stroke-dasharray: 6 4; }

/* inspector tabs */
.tabs { display: flex; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.tab { flex: 1; padding: 11px 4px; text-align: center; font-size: 12px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-body { padding: 12px 14px; }
.row { display: flex; gap: 8px; margin-bottom: 9px; }
.row .field { flex: 1; margin-bottom: 0; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px dashed var(--line); font-size: 12.5px; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.result-card { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 10px; }
.result-card h5 { margin: 0 0 6px; font-size: 12px; color: var(--accent); }
.calc-block { border: 1px solid var(--line); border-radius: 9px; margin-bottom: 12px; overflow: hidden; }
.calc-block > summary { padding: 10px 12px; cursor: pointer; font-weight: 600; font-size: 13px; background: var(--bg2); list-style: none; }
.calc-block > summary::-webkit-details-marker { display: none; }
.calc-block[open] > summary { border-bottom: 1px solid var(--line); }
.calc-inner { padding: 11px 12px; }
.ph-chart { width: 100%; background: #0f1b30; border: 1px solid var(--line); border-radius: 8px; }
.list-proj { padding: 4px 10px 14px; }
.proj-row { display: flex; align-items: center; gap: 6px; padding: 8px 9px; border-radius: 7px; cursor: pointer; font-size: 12.5px; }
.proj-row:hover { background: var(--bg2); }
.proj-row.active { background: #1b2c4b; }
.proj-row .pn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line2); padding: 10px 16px; border-radius: 9px; box-shadow: var(--shadow); font-size: 13px; z-index: 50; }
.toast.good { border-color: var(--good); }
.toast.bad { border-color: var(--bad); }
.legend { display: flex; gap: 12px; font-size: 11px; color: var(--muted); padding: 8px 14px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
