: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-files-panel {
  background: #2d2d2d;
  border-bottom: 1px solid #464646;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 6px 8px;
}

.patient-files-col h4 {
  margin: 0 0 4px;
  font-size: 12px;
  color: #ddd;
}

.patient-files-col ul {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 84px;
  overflow: auto;
}

.patient-files-col li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  padding: 2px 0;
}

.patient-files-col button {
  height: 22px;
  border: 1px solid #666;
  border-radius: 4px;
  background: #3a3a3a;
  color: #eee;
  font-size: 11px;
  cursor: pointer;
}

.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;
}

.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;
}

.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;
}
