:root {
  --bg: #f7f5f0;
  --panel: #ffffff;
  --ink: #1a1f2a;
  --muted: #546275;
  --line: #d5dce6;
  --accent: #1451a3;
  --fwd: #1f9858;
  --reflux: #d06b16;
  --outflow: #7e56c6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Source Sans 3", "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, #f0f5ff 0, #f0f5ff 16%, transparent 45%),
    radial-gradient(circle at 85% 20%, #fff6e5 0, #fff6e5 12%, transparent 40%),
    var(--bg);
}

.page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 360px minmax(560px, 1fr) 320px;
  gap: 14px;
  padding: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

h1 {
  margin: 0 0 2px;
  font-family: "IBM Plex Serif", "Georgia", serif;
  font-size: 1.2rem;
}

h2 {
  margin-top: 0;
  font-family: "IBM Plex Serif", "Georgia", serif;
}

.sub {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

label {
  font-size: 0.82rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

input,
select,
button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
  background: #fff;
}

button {
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

.actions {
  margin-top: 10px;
}

#run_btn {
  width: 100%;
  background: linear-gradient(90deg, #1451a3, #1776b7);
  color: #fff;
  border: none;
  font-weight: 600;
}

.hint {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--muted);
  min-height: 2.2em;
}

.guide {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfdff;
  padding: 8px;
  max-height: 35vh;
  overflow: auto;
}

.guide h3 {
  margin: 0 0 8px;
  font-size: 0.88rem;
  color: var(--ink);
}

.guide table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.73rem;
}

.guide th,
.guide td {
  border-top: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
  padding: 6px 4px;
}

.guide th {
  color: var(--muted);
  font-weight: 600;
}

.viewer {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
}

#flow_canvas {
  width: 100%;
  max-height: 430px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    linear-gradient(180deg, #fcfdff 0%, #f8fbff 46%, #f4f6f9 100%);
}

#timeseries_canvas {
  width: 100%;
  max-height: 250px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fcfdff;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 3px 10px;
  font-size: 0.72rem;
  background: #fff;
}

.pill.fwd {
  border-color: #b8e2cb;
  color: var(--fwd);
}

.pill.reflux {
  border-color: #f4d5ba;
  color: var(--reflux);
}

.pill.outflow {
  border-color: #d7c9ee;
  color: var(--outflow);
}

.pill.press {
  border-color: #c5d6fb;
  color: #2458a8;
}

.pill.pelvis {
  border-color: #f8c7c7;
  color: #b14a4a;
}

#frame_metrics,
#summary_preop,
#summary_postop {
  margin: 0;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fcfdff;
  font-size: 0.78rem;
  line-height: 1.35;
  white-space: pre-wrap;
}

#status {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.8rem;
  min-height: 2em;
}

@media (max-width: 1320px) {
  .page {
    grid-template-columns: 1fr;
  }
}
