/* ===== Multiphase Studio — light engineering theme ===== */
:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1f2733;
  --muted: #5b6470;
  --line: #e2e7ee;
  --brand: #1f6fb2;
  --brand-d: #155a93;
  --accent: #c0392b;
  --ok: #27ae60;
  --shadow: 0 1px 3px rgba(20,30,50,.08), 0 6px 18px rgba(20,30,50,.06);
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    "PingFang SC", "Microsoft YaHei", "Noto Sans", sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark { font-size: 20px; }
.brand-name { font-size: 15px; letter-spacing: .2px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lang-select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink); font-size: 13px; cursor: pointer;
}
.btn {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
  padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer;
  transition: .15s;
}
.btn:hover { border-color: #c7d0db; background: #f7f9fc; }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-d); }
.btn-home { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-home:hover { background: var(--brand-d); }
.btn-mail { background: #fff; color: var(--accent); border-color: #f0c9c4; }
.btn-mail:hover { background: #fdf2f0; }

/* Layout */
.layout { display: flex; align-items: stretch; min-height: calc(100vh - 56px); }
.sidebar {
  width: 220px; flex: 0 0 220px; background: var(--panel); border-right: 1px solid var(--line);
  padding: 14px 10px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 56px;
  height: calc(100vh - 56px); overflow-y: auto;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 10px 12px; border: none; background: transparent; color: var(--muted);
  font-size: 14px; border-radius: 8px; cursor: pointer; font-weight: 500;
}
.nav-item:hover { background: #f1f4f8; color: var(--ink); }
.nav-item.active { background: #e7f1fa; color: var(--brand-d); font-weight: 700; }
.nav-ico { font-size: 16px; }

.content { flex: 1; padding: 22px 26px; max-width: 1200px; }
.module { display: none; }
.module.active { display: block; }
.content h1 { font-size: 22px; margin: 0 0 6px; }
.lead { color: var(--muted); margin: 0 0 18px; max-width: 760px; line-height: 1.5; }

/* Dashboard cards */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-top: 10px; }
.card {
  text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; cursor: pointer; box-shadow: var(--shadow); transition: .15s; font: inherit; color: var(--ink);
}
.card:hover { transform: translateY(-2px); border-color: #c7d0db; }
.card h3 { margin: 0 0 6px; font-size: 16px; color: var(--brand-d); }
.card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }

/* Work grid */
.work-grid { display: grid; grid-template-columns: 360px 1fr; gap: 20px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel h3 { margin: 0 0 14px; font-size: 15px; color: var(--brand-d); }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.field label { font-size: 13px; color: var(--muted); flex: 1; }
.field input, .field select {
  width: 150px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px;
  font-size: 13px; color: var(--ink); background: #fff;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--brand); }
.btn-row { display: flex; gap: 10px; margin-top: 14px; }

/* Results */
.results { margin-bottom: 14px; }
.res-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.res-item {
  background: #f7f9fc; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.res-k { font-size: 12px; color: var(--muted); }
.res-v { font-size: 16px; font-weight: 700; color: var(--ink); }
.err { color: var(--accent); font-weight: 600; }

.chart { width: 100%; max-width: 540px; background: #fcfdfe; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; }
.disclaimer { margin-top: 26px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 14px; line-height: 1.5; }

/* Engineering UI extras */
.btn-tool { padding: 6px 12px; font-size: 12.5px; font-weight: 600; }
.nav-sep {
  margin: 12px 4px 4px; padding-top: 10px; border-top: 1px solid var(--line);
  font-size: 10.5px; letter-spacing: .6px; text-transform: uppercase;
  color: var(--muted); font-weight: 700;
}
.eqgrp { border-top: 1px dashed var(--line); margin-top: 4px; padding-top: 6px; }
.eqgrp[style*="none"] { display: none; }
/* sub-headings inside a long input panel (two-fluid kernel) */
h4.sub-h {
  width: 100%; margin: 16px 0 6px; padding-bottom: 4px;
  font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: var(--brand-d); border-bottom: 1px solid var(--line);
}
h4.sub-h:first-of-type { margin-top: 4px; }
.field.hide { display: none; }
/* stacked fields (used for textarea inputs) */
.field-col { flex-direction: column; align-items: stretch; gap: 6px; }
.field-col > label { margin-bottom: 0; }
.field textarea {
  width: 100%; min-height: 84px; padding: 8px;
  border: 1px solid var(--line); border-radius: 7px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Courier New", monospace;
  font-size: 12.5px; line-height: 1.5; color: var(--ink); background: #fff; resize: vertical;
}
.field textarea:focus { outline: none; border-color: var(--brand); }
.res-ok { color: var(--ok); font-weight: 600; }
.res-warn { color: var(--accent); font-weight: 600; }
.res-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 12.5px; }
.res-table th, .res-table td { border: 1px solid var(--line); padding: 5px 8px; text-align: right; }
.res-table th:first-child, .res-table td:first-child { text-align: left; }
.res-table th { background: #f1f4f8; color: var(--muted); font-weight: 600; }
.res-table tr:nth-child(even) td { background: #fafbfc; }
.res-table td.res-id { font-weight: 700; color: var(--brand-d); }

.res-table tr.row-bad td { background: #fdf1ef; color: #a5322a; }
.res-table tr.row-bad td.res-id { color: #a5322a; }

/* ===== Flowsheet (PFD) editor ===== */
#m-flow .lead { max-width: 900px; }
.fs-toolbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  padding: 10px 12px; margin-bottom: 10px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.fs-toolbar .btn { padding: 7px 12px; font-size: 12.5px; }
.fs-sep { width: 1px; height: 22px; background: var(--line); margin: 0 2px; }
.fs-toolbar .btn.btn-ico {
  padding: 6px 0; width: 30px; text-align: center;
  font-size: 15px; font-weight: 700; line-height: 1;
}
.fs-zoom {
  min-width: 46px; text-align: center; font-size: 12px; font-weight: 700;
  color: var(--muted); font-variant-numeric: tabular-nums;
}
.fs-toolbar .btn.on { background: #eaf2fb; border-color: #1f6fb2; color: #1f6fb2; }
.fs-status { font-size: 12px; font-weight: 600; color: #2e7d32; margin-left: 4px; }
.fs-status.bad { color: #c62828; }
.fs-analysis-panel { margin-bottom: 14px; }
.fs-analysis-panel canvas { width: 100%; max-width: 940px; height: auto; }
.fs-analysis-panel .hint { margin: 2px 0 8px; }

.fs-palette {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  padding: 8px 12px; margin-bottom: 14px;
  background: #f7f9fc; border: 1px dashed var(--line); border-radius: var(--radius);
}
.fs-pal-label { font-size: 12px; font-weight: 700; color: var(--muted); margin-right: 4px; }
.fs-pal {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border: 1px solid var(--line); border-radius: 999px;
  background: #fff; color: var(--ink); font: inherit; font-size: 12.5px;
  font-weight: 600; cursor: pointer; transition: .15s;
}
.fs-pal:hover { border-color: var(--brand); background: #eaf3fb; color: var(--brand-d); }
.fs-pal span:first-child { font-size: 14px; line-height: 1; }

.fs-grid { display: grid; grid-template-columns: 1fr 320px; gap: 18px; align-items: start; }
.fs-canvas-panel { padding: 12px; }
.fs-wrap {
  position: relative; width: 100%; height: 520px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fbfcfe; overflow: hidden;
}
#fs_canvas { display: block; width: 100%; height: 100%; cursor: default; touch-action: none; }
.fs-hint { margin: 8px 2px 0; font-size: 11.5px; color: var(--muted); line-height: 1.5; }

.fs-props-panel { position: sticky; top: 72px; max-height: calc(100vh - 96px); overflow-y: auto; }
.fs-props .field { margin-bottom: 8px; }
.fs-props .field label { font-size: 12px; }
.fs-props .field input, .fs-props .field select { width: 130px; padding: 6px 8px; font-size: 12.5px; }
.fs-props .fs-group {
  margin: 12px 0 6px; padding-top: 8px; border-top: 1px solid var(--line);
  font-size: 10.5px; letter-spacing: .6px; text-transform: uppercase;
  color: var(--muted); font-weight: 700;
}
.fs-props .fs-empty { font-size: 12.5px; color: var(--muted); line-height: 1.55; }

.fs-results-panel { margin-top: 18px; }
.fs-warn {
  margin: 12px 0; padding: 10px 14px; border-radius: 8px;
  background: #fff8e6; border: 1px solid #f0dca8; color: #8a6100; font-size: 12.5px;
}
.fs-warn ul { margin: 6px 0 0; padding-left: 18px; }
.fs-warn li { margin: 2px 0; }
.fs-note { margin-top: 12px; font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.hint { font-size: 13px; color: var(--muted); }

/* ---- Flowsheet: grouped, collapsible equipment palette ---- */
.fs-grp {
  display: flex; flex-direction: column; gap: 5px;
  padding: 7px 9px; background: #fff; border: 1px solid var(--line);
  border-radius: 8px;
}
.fs-grp-h {
  font-size: 11px; font-weight: 700; color: var(--brand-d);
  text-transform: uppercase; letter-spacing: .4px; cursor: pointer;
  user-select: none; margin: 0; display: flex; align-items: center; gap: 5px;
}
.fs-grp-h::before { content: '\25BE'; font-size: 10px; color: var(--muted); transition: transform .15s; }
.fs-grp.collapsed .fs-grp-h::before { transform: rotate(-90deg); }
.fs-grp-b { display: flex; flex-wrap: wrap; gap: 6px; }
.fs-grp.collapsed .fs-grp-b { display: none; }

/* ---- Flowsheet: inspector sub-headings & notes ---- */
.fs-props h5 {
  margin: 12px 0 5px; font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px;
}
.fs-sub { font-size: 11.5px; color: var(--muted); margin: 2px 0 7px; line-height: 1.45; }
.btn-del { color: var(--accent); border-color: #f0c9c4; }
.btn-del:hover { background: #fdf2f0; }

/* ---- Flowsheet: result table section headers ---- */
h6.fs-th {
  margin: 16px 0 3px; font-size: 13px; font-weight: 700; color: var(--brand-d);
  padding-left: 8px; border-left: 3px solid var(--brand);
}
.rg-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  margin-right: 4px; vertical-align: middle; flex: 0 0 auto;
}

@media (max-width: 1100px) {
  .fs-grid { grid-template-columns: 1fr; }
  .fs-props-panel { position: static; max-height: none; }
}

/* Responsive */
@media (max-width: 900px) {
  .work-grid { grid-template-columns: 1fr; }
  .fs-wrap { height: 380px; }
  .sidebar { position: fixed; left: 0; top: 56px; z-index: 20; transform: translateX(-100%); transition: .2s; }
  .sidebar.open { transform: translateX(0); }
  .field { flex-direction: column; align-items: stretch; }
  .field label { margin-bottom: 4px; }
  .field input, .field select { width: 100%; }
  .brand-name { display: none; }
}
.menu-toggle { display: none; }
@media (max-width: 900px) { .menu-toggle { display: inline-flex; } }
