* { box-sizing: border-box; }
:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --line: #d6dde5;
  --text: #1d2733;
  --muted: #6d7b8a;
  --accent: #0f7c8a;
  --accent-dark: #0a5b65;
  --danger: #b33336;
  --shadow: 0 10px 28px rgba(18, 28, 45, 0.08);
}
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 22px;
  background: #17202b;
  color: #f6f8fb;
  border-bottom: 1px solid #0d141d;
}
.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
}
.topbar p {
  margin: 5px 0 0;
  color: #9fb0c2;
  font-size: 13px;
}
.project-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}
.workspace {
  display: grid;
  grid-template-columns: minmax(420px, 0.9fr) minmax(440px, 1.1fr);
  gap: 18px;
  padding: 18px;
}
.editor,
.results {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 10px;
}
.section-header:first-child { margin-top: 0; }
h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: 0;
}
.grid {
  display: grid;
  gap: 10px;
}
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
input,
select,
button,
.file-button {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}
input,
select {
  width: 100%;
  min-width: 0;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
}
button,
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  background: #f9fbfc;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}
button:hover,
.file-button:hover {
  border-color: var(--accent);
}
button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button.primary:hover { background: var(--accent-dark); }
button.danger {
  color: var(--danger);
}
.file-button input { display: none; }
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
}
.toggle input {
  width: 18px;
  height: 18px;
}
.connected-header {
  margin: 14px 0 0;
  padding: 10px 12px;
  background: #edf7f8;
  border: 1px solid #b9dce1;
  border-radius: 6px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 650;
}
.model-editor {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.model-editor svg {
  width: 100%;
  height: auto;
  min-height: 180px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  touch-action: none;
}
.model-editor-damper-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.damper-config {
  align-items: end;
}
.diagram-pipe {
  stroke: #2f465c;
  stroke-width: 14;
  stroke-linecap: round;
}
.diagram-reservoir {
  fill: #e8eef3;
  stroke: #8190a0;
  stroke-width: 2;
}
.diagram-pump {
  fill: #f6fbfc;
  stroke: var(--accent);
  stroke-width: 3;
}
.diagram-pump-label {
  fill: var(--accent-dark);
  font-size: 17px;
  font-weight: 750;
}
.diagram-valve {
  fill: #f8fbfc;
  stroke: #2f465c;
  stroke-width: 2.5;
}
.diagram-boundary {
  stroke: #8190a0;
  stroke-width: 2;
  stroke-dasharray: 5 5;
}
.diagram-axis,
.diagram-tick {
  stroke: #aeb8c3;
  stroke-width: 1.5;
}
.diagram-label {
  fill: var(--muted);
  font-size: 13px;
  font-weight: 650;
}
.damper-line {
  stroke: var(--danger);
  stroke-width: 2;
}
.damper-handle {
  fill: var(--danger);
  stroke: #7e2225;
  stroke-width: 1.5;
  cursor: grab;
}
.damper-marker:active .damper-handle {
  cursor: grabbing;
}
.damper-label {
  fill: var(--danger);
}
.segment-row {
  display: grid;
  grid-template-columns: 1.2fr repeat(4, minmax(90px, 1fr)) 36px;
  gap: 8px;
  align-items: end;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 8px;
}
.segment-row button {
  width: 36px;
  padding: 0;
  color: var(--danger);
}
.actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}
.report-export-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}
.report-export-controls select {
  width: 150px;
}
.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.metric {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 19px;
}
canvas {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.chart-header {
  margin-top: 14px;
}
pre {
  white-space: pre-wrap;
  margin: 14px 0 0;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}
.analysis-artifacts {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}
.analysis-artifacts details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 10px 12px;
}
.analysis-artifacts summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 750;
}
.artifact-actions {
  display: flex;
  justify-content: flex-end;
  margin: 10px 0 8px;
}
.analysis-artifacts textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fff;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
}
@media (max-width: 980px) {
  .topbar,
  .workspace {
    display: block;
  }
  .project-bar {
    justify-content: flex-start;
    margin-top: 12px;
  }
  .results {
    margin-top: 18px;
  }
  .grid.three,
  .grid.four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .report-export-controls {
    justify-content: flex-start;
    margin-top: 10px;
  }
}
@media (max-width: 620px) {
  .workspace {
    padding: 12px;
  }
  .grid.two,
  .grid.three,
  .grid.four,
  .metrics {
    grid-template-columns: 1fr;
  }
  .segment-row {
    grid-template-columns: 1fr;
  }
  .segment-row button {
    width: 100%;
  }
  .report-export-controls {
    display: grid;
    grid-template-columns: 1fr;
  }
  .report-export-controls select {
    width: 100%;
  }
}
