:root {
  --bg: #1f1f1f;
  --panel: #2a2a2a;
  --muted: #3a3a3a;
  --text: #e8e8e8;
  --accent: #4ea8de;
  --warn: #f4a261;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.menu-bar {
  min-height: 40px;
  background: #c9c9c9;
  color: #222;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  border-bottom: 1px solid #8a8a8a;
}

.menu-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.menu-dropdown {
  position: relative;
}

.menu-label {
  border: 0;
  background: transparent;
  color: #1f1f1f;
  font-size: 13px;
  padding: 4px 8px;
  cursor: pointer;
}

.menu-label:hover,
.menu-dropdown:focus-within > .menu-label {
  background: #f2f2f2;
}

.menu-list {
  display: none;
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  min-width: 210px;
  background: #f4f4f4;
  border: 1px solid #8c8c8c;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  z-index: 1200;
  padding: 4px 0;
}

.menu-dropdown:hover > .menu-list,
.menu-dropdown:focus-within > .menu-list {
  display: block;
}

.menu-item {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 7px 10px;
  font-size: 12px;
  color: #1f1f1f;
  cursor: pointer;
}

.menu-item:hover {
  background: #e3e3e3;
}

.toolbar-tray {
  height: 90px;
  padding: 6px 8px;
  background: #dbdbdb;
  display: flex;
  align-items: center;
  gap: 12px;
  overflow-x: auto;
  border-bottom: 1px solid #8a8a8a;
}

.patient-bar {
  min-height: 40px;
  background: #cfcfcf;
  color: #1a1a1a;
  border-bottom: 1px solid #9c9c9c;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
}

.patient-bar select,
.patient-bar input,
.patient-bar button {
  height: 28px;
  border: 1px solid #8b8b8b;
  border-radius: 4px;
  font-size: 12px;
}

.patient-bar input,
.patient-bar select {
  padding: 0 8px;
  min-width: 140px;
}

.patient-bar button {
  background: #efefef;
  cursor: pointer;
  padding: 0 10px;
}

.patient-bar-divider {
  width: 1px;
  height: 20px;
  background: #555;
  margin: 0 4px;
}

.patient-file-btn {
  background: #efefef;
  color: inherit;
  border: 1px solid #8b8b8b;
  border-radius: 4px;
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  cursor: pointer;
}

.patient-file-btn:not(:disabled):hover {
  background: #ddd;
}

.patient-file-btn:disabled {
  opacity: 0.38;
  cursor: default;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-right: 8px;
  border-right: 1px solid #b4b4b4;
}

.tool-group button {
  width: 46px;
  height: 46px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  border-radius: 4px;
}

.tool-group button.active {
  border-color: #6b6b6b;
  background: #ececec;
}

.tool-group img {
  width: 38px;
  height: 38px;
  object-fit: contain;
}

.text-tool-btn {
  width: auto !important;
  min-width: 52px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 600;
  color: #333;
  white-space: nowrap;
}

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 220px 1fr;
}

.left-panel,
.result-panel {
  background: var(--panel);
  border-right: 1px solid #515151;
  overflow: auto;
}

.result-panel {
  border-left: 1px solid #515151;
  border-right: 0;
  padding: 8px;
}

.results-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.results-modal.open {
  display: flex;
}

.results-modal-content {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(34vw, 640px);
  min-width: 420px;
  height: min(62vh, 560px);
  max-height: 62vh;
  background: var(--panel);
  border: 1px solid #5c5c5c;
  border-radius: 8px;
  padding: 12px;
  overflow: auto;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.45);
}

.results-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  cursor: move;
  user-select: none;
}

.results-modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.results-modal-close {
  border: 1px solid #6a6a6a;
  background: #3c3c3c;
  color: var(--text);
  border-radius: 4px;
  width: 28px;
  height: 28px;
  cursor: pointer;
}

.toast-panel {
  position: fixed;
  top: 52px;
  right: 12px;
  z-index: 1300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: min(420px, calc(100vw - 24px));
}

.toast {
  background: #2f2f2f;
  color: var(--text);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.4;
  white-space: pre-line;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.toast-error {
  border-left-color: #ff6b6b;
}

.toast.toast-success {
  border-left-color: #51cf66;
}

.toast.toast-warning {
  border-left-color: var(--warn);
}

.tab-header {
  display: flex;
  border-bottom: 1px solid #515151;
}

.tab-btn {
  flex: 1;
  border: 0;
  background: #373737;
  color: var(--text);
  padding: 10px 6px;
  cursor: pointer;
}

.tab-btn.active {
  background: #4a4a4a;
}

.tab-content {
  display: none;
  padding: 8px;
}

.tab-content.active {
  display: block;
}

.cmd-actions {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cmd-actions button {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid #666;
  background: #3a3a3a;
  color: #eee;
}

.cmd-delete-btn {
  background: #6b2020 !important;
  border-color: #a03030 !important;
  color: #ffd0d0 !important;
}

.cmd-delete-btn:hover {
  background: #8b2020 !important;
}

.canvas-grid {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 5px 1fr;
  background: #111;
}

.splitter {
  background: #666;
}

.image-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.image-pane > header {
  height: 28px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  background: #2e2e2e;
  border-bottom: 1px solid #484848;
}

.canvas-host {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #000;
}

.canvas-host.drag-over {
  outline: 2px dashed #4a9eff;
  outline-offset: -2px;
}

.canvas-host.drag-over-blocked {
  outline-color: #e05050;
}

.canvas-host .drop-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 10;
}

.canvas-host.drag-over .drop-hint {
  opacity: 1;
}

.drop-hint-inner {
  background: rgba(0, 0, 0, 0.72);
  border: 2px dashed #4a9eff;
  border-radius: 8px;
  padding: 20px 36px;
  color: #4a9eff;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-align: center;
  pointer-events: none;
}

.canvas-host.drag-over-blocked .drop-hint-inner {
  border-color: #e05050;
  color: #e05050;
}

.viewport {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
}

.viewport img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.viewport svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.guide-line {
  stroke: #fff;
  stroke-width: 1;
  stroke-dasharray: 4 2;
}

.entity-line {
  stroke: #ff4b4b;
  stroke-width: 1.3;
}

.measurement-line {
  stroke: #fff;
  stroke-width: 1.2;
}

.entity-point {
  fill: #87cefa;
  stroke: #000;
  stroke-width: 1;
}

.entity-point-left {
  fill: #b7e9ff;
}

.entity-point-right {
  fill: #66b9df;
}

.entity-point-hover {
  fill: #ffeb3b !important;
}

.entity-point.magenta {
  fill: #e67ab3;
}

.entity-point.white {
  fill: #fff;
}

.entity-circle {
  fill: rgba(0, 191, 255, 0.5);
  stroke: #111;
  stroke-width: 1;
}

.entity-bezier {
  stroke: #ff4b4b;
  stroke-width: 3;
  fill: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  border: 1px solid #636363;
  padding: 4px;
  text-align: center;
}

thead th {
  background: #bdbdbd;
  color: #111;
}

tbody tr:nth-child(odd) {
  background: #3a3a3a;
}

tbody tr:nth-child(even) {
  background: #2f2f2f;
}

/* Simulation (predicted spine) — full-window modal over the program */
.sim-window { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 200; display: none; align-items: center; justify-content: center; }
.sim-window[aria-hidden="false"] { display: flex; }
.sim-window-inner { width: min(96vw,1400px); height: min(92vh,920px); background: var(--panel); border: 1px solid #5c5c5c; border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,0.6); display: flex; flex-direction: column; overflow: hidden; }
.sim-window-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid #4a4a4a; }
.sim-window-header h3 { margin: 0; font-size: 15px; }
.sim-window-close { background: transparent; border: none; color: #ddd; font-size: 22px; line-height: 1; cursor: pointer; }
.sim-window-body { flex: 1; display: flex; min-height: 0; }
.sim-canvas-wrap { flex: 1; min-width: 0; background: #0d0d0d; display: flex; }
.sim-canvas-wrap svg { width: 100%; height: 100%; }
.sim-controls { width: 420px; flex-shrink: 0; border-left: 1px solid #4a4a4a; padding: 12px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.sim-controls-title { font-size: 13px; font-weight: 700; color: #cbd5e1; }
.sim-note { font-size: 11px; color: #9aa; font-style: italic; }

/* Right-hand Spine List rows (checkbox | name | colour | UIV | LIV | GAP). */
.sim-families { display: flex; flex-direction: column; gap: 4px; }
.sim-spine-row { display: grid; grid-template-columns: 18px 1fr 22px 56px 52px 30px; align-items: center; gap: 6px; font-size: 12px; }
.sim-spine-head { color: #9aa; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.3px; border-bottom: 1px solid #3d3d3d; padding-bottom: 3px; }
.sim-spine-head span { text-align: center; }
.sim-spine-head span:nth-child(2) { text-align: left; }
.sim-spine-name { font-weight: 600; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sim-spine-group { border-bottom: 1px solid #2c2c2c; padding: 3px 0; }
.sim-spine-row select { background: #1e1e1e; color: #eee; border: 1px solid #555; border-radius: 4px; padding: 2px 3px; font-size: 11px; width: 100%; }
.sim-spine-row select:disabled { opacity: 0.5; cursor: not-allowed; }
.sim-gap-score { text-align: center; font-weight: 700; color: #cbd5e1; }
.sim-col-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 2px; border: 1px solid #000; }
.sim-family-params { display: none; flex-direction: column; gap: 6px; margin: 6px 0 4px 24px; }
.sim-spine-group.open .sim-family-params { display: flex; }
.sim-family-params label { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; }
.sim-family-params input { width: 90px; background: #1e1e1e; color: #eee; border: 1px solid #555; border-radius: 4px; padding: 3px 6px; }
.sim-family-note { font-size: 11px; color: #e0a050; }
.sim-results { font-size: 11px; color: #8ab; white-space: pre-line; border-top: 1px solid #3d3d3d; padding-top: 8px; min-height: 14px; }

/* Left-hand parameter table with rotated spine-name headers. */
.sim-param-table { width: 240px; flex-shrink: 0; border-right: 1px solid #4a4a4a; overflow: auto; background: var(--panel); }
.sim-param-table table { border-collapse: collapse; font-size: 12px; width: 100%; }
.sim-param-table th, .sim-param-table td { border: 1px solid #3d3d3d; padding: 4px 6px; text-align: center; white-space: nowrap; font-weight: 600; }
.sim-param-table thead th { background: #1e1e1e; height: 92px; vertical-align: bottom; }
.sim-param-table thead th span.sim-col-swatch { display: none; }
.sim-param-table thead th { writing-mode: vertical-rl; transform: rotate(180deg); }
.sim-param-table thead th.sim-param-name { writing-mode: horizontal-tb; transform: none; }
.sim-param-table td.sim-param-name, .sim-param-table th.sim-param-name { text-align: left; color: #cbd5e1; background: #1a1a1a; position: sticky; left: 0; }
.sim-param-table tbody tr.alt td { background: rgba(120,170,255,0.07); }

/* MSK (OpenSim) simulation controls + plots panel */
.sim-window-inner { position: relative; }
.sim-msk { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid #3d3d3d; padding-top: 8px; margin-top: 4px; }
.sim-msk-field { display: flex; flex-direction: column; font-size: 11px; color: #cbd5e1; gap: 3px; }
.sim-msk-field select, .sim-msk-field input { background: #1f1f1f; color: var(--text); border: 1px solid #4a4a4a; border-radius: 4px; padding: 4px 6px; font-size: 12px; }
.sim-msk-run { margin-top: 4px; padding: 8px 10px; background: var(--accent); color: #06222f; border: none; border-radius: 5px; font-weight: 700; cursor: pointer; }
.sim-msk-run:hover { filter: brightness(1.08); }
.sim-msk-run:disabled { opacity: 0.55; cursor: progress; }
.sim-msk-status { font-size: 11px; color: #8ab; min-height: 14px; }

.sim-msk-panel { position: absolute; inset: 0; top: 41px; background: #232323; display: none; flex-direction: column; z-index: 5; }
.sim-msk-panel[aria-hidden="false"] { display: flex; }
.sim-msk-panel-header { display: flex; align-items: center; gap: 14px; padding: 8px 14px; border-bottom: 1px solid #4a4a4a; }
.sim-msk-panel-header h4 { margin: 0; font-size: 14px; }
.sim-msk-legend { display: flex; flex-wrap: wrap; gap: 12px; flex: 1; font-size: 12px; color: #cbd5e1; }
.sim-msk-legend-item { display: inline-flex; align-items: center; gap: 5px; }
.sim-msk-plots { flex: 1; overflow: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 14px; }
.sim-msk-chart { background: #1b1b1b; border: 1px solid #3a3a3a; border-radius: 6px; padding: 6px 10px 2px; }
.sim-msk-chart h5 { margin: 2px 0 0; font-size: 12px; color: #cbd5e1; font-weight: 600; }
.sim-msk-chart-svg { width: 100%; height: auto; display: block; }
.sim-msk-logs-wrap { border-top: 1px solid #4a4a4a; padding: 6px 14px; font-size: 11px; color: #9aa; }
.sim-msk-logs-wrap summary { cursor: pointer; }
.sim-msk-logs { max-height: 160px; overflow: auto; white-space: pre-wrap; background: #141414; padding: 8px; border-radius: 4px; margin-top: 6px; font-size: 10px; line-height: 1.35; }
