:root {
  color-scheme: dark;
  --bg: #121212;
  --panel: #1c1c1a;
  --panel-2: #242420;
  --line: #3b3a34;
  --text: #f4f2e9;
  --muted: #a9a79d;
  --accent: #39d0b5;
  --accent-2: #e4b84b;
  --danger: #ff6b5f;
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
select,
input,
textarea {
  font: inherit;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #171715;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid #4c4a42;
  border-radius: var(--radius);
  background: #0b0b0a;
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.15;
  font-weight: 750;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
  font-weight: 750;
}

.brand p,
.panel-head p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.select-wrap {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  min-width: 190px;
}

.case-tools {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.notes-toggle {
  align-self: end;
  min-width: 92px;
}

.text-wrap,
.note-field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.text-wrap {
  min-width: 150px;
}

.select-wrap.compact {
  min-width: 150px;
}

.head-controls {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

select,
input[type="search"],
input[type="text"],
textarea {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #10100f;
  padding: 0 30px 0 10px;
}

input[type="search"],
input[type="text"],
textarea {
  width: 100%;
  padding-right: 10px;
}

textarea {
  min-height: 56px;
  padding: 8px 10px;
  resize: vertical;
  line-height: 1.35;
}

.case-notes {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(160px, 0.7fr) minmax(260px, 1.5fr);
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: #151514;
}

.case-notes.is-hidden {
  display: none;
}

.case-info {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(220px, 0.75fr) minmax(220px, 0.75fr);
  gap: 14px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #151514;
  max-height: 38vh;
  overflow: auto;
}

.case-info.is-hidden {
  display: none;
}

.info-section {
  min-width: 0;
}

.info-section h3 {
  margin: 0 0 7px;
  color: var(--text);
  font-size: 12px;
  line-height: 1.2;
  font-weight: 750;
}

.info-section p,
.series-list,
.nodule-table {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.annotation-section {
  grid-row: span 3;
}

.annotation-headline {
  color: var(--text);
  font-weight: 650;
}

.info-note {
  margin-top: 8px;
  color: #d9d1aa;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
  margin: 0;
}

.info-item {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 8px;
  font-size: 12px;
  line-height: 1.25;
}

.info-item dt {
  color: var(--muted);
}

.info-item dd {
  min-width: 0;
  margin: 0;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.diagnosis-section .info-item dd,
.count-section .info-item dd {
  white-space: normal;
}

.series-list {
  display: grid;
  gap: 5px;
  padding: 0;
  list-style: none;
}

.series-list li {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metadata-list {
  margin-top: 8px;
}

.metadata-list li {
  white-space: normal;
}

.compact-grid {
  margin-bottom: 8px;
}

.nodule-table-wrap {
  max-height: 230px;
  margin: 8px 0 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.nodule-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.nodule-table th,
.nodule-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(59, 58, 52, 0.72);
  text-align: left;
  vertical-align: top;
}

.nodule-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #151514;
  color: var(--text);
  font-weight: 750;
}

.nodule-table td.num {
  color: var(--text);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.info-warning {
  margin-top: 8px;
  color: var(--danger);
}

.credit-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.credit-links a {
  color: var(--accent);
  text-decoration: none;
}

.credit-links a:hover {
  text-decoration: underline;
}

.case-notes span,
.case-tools span {
  white-space: nowrap;
}

.workspace {
  flex: 1;
  height: auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
}

.dataset-credit-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  background: #151514;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.dataset-credit-footer p {
  min-width: 0;
}

.dataset-credit-footer nav {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.dataset-credit-footer a {
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}

.dataset-credit-footer a:hover {
  text-decoration: underline;
}

.viewer-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr) auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.panel-head {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.panel-head > div {
  min-width: 0;
}

.panel-head p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 52vw;
}

.canvas-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background:
    linear-gradient(45deg, #0b0b0b 25%, transparent 25%),
    linear-gradient(-45deg, #0b0b0b 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #0b0b0b 75%),
    linear-gradient(-45deg, transparent 75%, #0b0b0b 75%);
  background-color: #050505;
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  cursor: grab;
}

.canvas-stage.dragging {
  cursor: grabbing;
}

.canvas-stage.has-status::after {
  content: attr(data-status);
  position: sticky;
  left: 12px;
  top: 12px;
  z-index: 2;
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(16, 16, 15, 0.92);
  color: var(--text);
  font-size: 12px;
}

canvas {
  display: block;
  margin: 12px auto;
  image-rendering: auto;
  background: #000;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.visible-nodules {
  border-top: 1px solid var(--line);
  background: #131311;
}

.visible-nodules-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px 6px;
}

.visible-nodules-header h3 {
  margin: 0;
  font-size: 13px;
  color: var(--text);
}

.visible-nodule-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.visible-nodule-badge {
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 7px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.visible-nodule-badge.seg {
  border-color: rgba(57, 208, 181, 0.46);
  color: #bdf8ed;
}

.visible-nodule-badge.xml {
  border-color: rgba(255, 127, 111, 0.5);
  color: #ffd4ce;
}

.visible-nodules-body {
  max-height: 145px;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(245px, 1fr));
  gap: 7px;
  padding: 0 12px 10px;
}

.visible-nodules-empty {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.visible-nodule-item {
  border: 1px solid var(--line);
  border-left: 3px solid var(--item-color);
  border-radius: 6px;
  background: #10100f;
  padding: 7px 8px;
  min-width: 0;
}

.visible-nodule-head {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  margin-bottom: 5px;
}

.visible-nodule-head strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.visible-nodule-source {
  flex: 0 0 auto;
  border: 1px solid var(--item-color);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--text);
  font-size: 10px;
}

.visible-nodule-details {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  gap: 5px 10px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.controls {
  display: grid;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
  background: #171715;
}

.control-line {
  display: grid;
  grid-template-columns: 62px minmax(100px, 1fr) 72px;
  gap: 9px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.control-line output {
  color: var(--text);
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.button-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 34px;
}

button,
.toggle {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #10100f;
  color: var(--text);
  padding: 0 11px;
}

button {
  cursor: pointer;
}

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

.mode-row {
  gap: 6px;
}

.mode-button.active {
  border-color: var(--accent);
  background: rgba(57, 208, 181, 0.16);
  color: #effffb;
}

#ctNoduleToggle.active {
  border-color: var(--accent-2);
  background: rgba(228, 184, 75, 0.16);
  color: #fff6d4;
}

#ctXmlNoduleToggle.active {
  border-color: #ff7f6f;
  background: rgba(255, 127, 111, 0.16);
  color: #ffe1dd;
}

.mode-row output {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  padding: 0 4px;
  font-variant-numeric: tabular-nums;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-2);
}

@media (max-width: 950px) {
  body {
    height: auto;
    min-height: 100%;
    overflow: auto;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .case-tools,
  .case-notes,
  .case-info {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .case-info {
    max-height: none;
  }

  .annotation-section {
    grid-row: auto;
  }

  .case-tools {
    justify-content: stretch;
  }

  .workspace {
    height: auto;
    min-height: 0;
    grid-template-columns: 1fr;
  }

  .dataset-credit-footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 7px;
  }

  .dataset-credit-footer nav {
    justify-content: flex-start;
  }

  .viewer-panel {
    min-height: 700px;
  }

  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .head-controls {
    align-items: stretch;
    justify-content: stretch;
  }

  .panel-head p {
    max-width: 100%;
  }

  .select-wrap,
  .select-wrap.compact {
    min-width: 0;
  }
}

@media (max-width: 560px) {
  .workspace {
    padding: 8px;
    gap: 8px;
  }

  .control-line {
    grid-template-columns: 54px minmax(80px, 1fr) 62px;
    gap: 7px;
  }
}
