:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #66737d;
  --line: #dbe2e7;
  --surface: #f6f8f9;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-2: #2563eb;
  --warn: #b45309;
  --bad: #b91c1c;
  --good: #15803d;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
}

.print-report-header {
  display: none;
}

.app-shell .print-table-title {
  display: none;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 7px;
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #9fb1bd;
}

button.primary,
button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.ghost {
  background: transparent;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 36px;
  padding: 7px 9px;
  background: #fff;
}

input[type="file"] {
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.patient-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.75fr) minmax(0, 1fr);
  gap: 10px;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) minmax(420px, 520px);
  height: 100vh;
  overflow: hidden;
}

.app-shell.results-collapsed {
  grid-template-columns: 320px minmax(0, 1fr) 48px;
}

.sidebar,
.results {
  overflow: auto;
  padding: 16px;
  background: #eef3f4;
  border-right: 1px solid var(--line);
}

.results {
  border-left: 1px solid var(--line);
  border-right: 0;
  background: #f7faf9;
  min-width: 0;
  position: relative;
  z-index: 2;
}

.results.collapsed {
  padding: 8px 6px;
  overflow: hidden;
}

.results.collapsed .panel-title {
  display: grid;
  justify-items: center;
  gap: 8px;
}

.results.collapsed .panel-title h2,
.results.collapsed .badge,
.results.collapsed .summary-grid,
.results.collapsed .diagnosis-card,
.results.collapsed .table-wrap {
  display: none;
}

.collapse-results-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 116px;
  min-width: 116px;
  max-width: 116px;
  height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
}

.results.collapsed .collapse-results-btn {
  width: 34px;
  min-width: 34px;
  max-width: 34px;
  height: 142px;
  padding: 10px 0;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 24px;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  letter-spacing: 0;
}

h2 {
  font-size: 15px;
}

.brand p,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
  display: grid;
  gap: 12px;
}

.collapsible-panel {
  gap: 0;
  padding: 0;
  overflow: hidden;
}

.panel-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: 0;
  padding: 0 14px;
  background: #fff;
  font-size: 15px;
  font-weight: 800;
  text-align: left;
}

.panel-toggle:hover {
  background: #f7faf9;
}

.chevron {
  color: var(--muted);
  font-size: 14px;
}

.panel-body {
  display: grid;
  gap: 12px;
  padding: 0 14px 14px;
}

.collapsible-panel.collapsed .panel-body {
  display: none;
}

.collapsible-panel.collapsed .chevron {
  transform: rotate(180deg);
}

.panel-actions {
  display: flex;
  justify-content: flex-end;
}

.panel-title,
.calibration-row,
.toolbar,
.tool-group,
.control-cluster {
  display: flex;
  align-items: center;
}

.panel-title {
  justify-content: space-between;
  gap: 10px;
}

.results > .panel-title {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
}

.calibration-row {
  gap: 10px;
}

.landmark-panel {
  min-height: 0;
}

.landmark-panel:not(.collapsed) {
  min-height: 360px;
}

.landmark-list {
  display: grid;
  gap: 8px;
  max-height: 46vh;
  overflow: auto;
  padding-right: 2px;
}

.landmark-item {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 12px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 62px;
  padding: 8px 9px;
  background: #fff;
  text-align: left;
}

.landmark-item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.13);
}

.landmark-code {
  display: grid;
  place-items: center;
  width: 54px;
  min-height: 34px;
  border-radius: 6px;
  background: #e7f4f2;
  color: var(--accent);
  font-weight: 800;
  font-size: 13px;
}

.landmark-name {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.landmark-name strong,
.landmark-name span {
  display: block;
  overflow-wrap: anywhere;
}

.landmark-name strong {
  font-size: 13px;
  line-height: 1.15;
}

.landmark-name span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.dot-state {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #cbd5df;
}

.dot-state.done {
  background: var(--good);
}

.workspace {
  display: grid;
  grid-template-rows: 1fr;
  min-width: 0;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.toolbar {
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  min-height: 56px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  min-width: 0;
}

.tool-group {
  gap: 8px;
}

.viewer-controls {
  position: absolute;
  left: 50%;
  top: 14px;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: min(calc(100% - 28px), 900px);
  transform: translateX(-50%);
  pointer-events: none;
}

.control-cluster {
  gap: 6px;
  padding: 6px;
  border: 1px solid rgba(207, 216, 223, 0.82);
  border-radius: 8px;
  background: rgba(247, 250, 249, 0.92);
  box-shadow: 0 10px 28px rgba(7, 18, 24, 0.18);
  backdrop-filter: blur(10px);
  pointer-events: auto;
}

.control-cluster button,
.download-buttons button {
  min-height: 34px;
  border-radius: 6px;
  font-weight: 750;
}

.control-cluster button {
  padding: 0 10px;
}

.brightness-cluster {
  gap: 4px;
  padding: 5px;
}

.brightness-cluster button {
  width: 34px;
  min-width: 34px;
  padding: 0;
}

.brightness-cluster span {
  min-width: 40px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-align: center;
}

.active-landmark-hint {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 5;
  display: grid;
  gap: 2px;
  max-width: min(360px, calc(100% - 32px));
  padding: 10px 12px;
  border: 1px solid rgba(207, 216, 223, 0.75);
  border-radius: 8px;
  background: rgba(7, 18, 24, 0.78);
  color: #f8fafc;
  box-shadow: 0 10px 28px rgba(7, 18, 24, 0.22);
  pointer-events: none;
}

.active-landmark-hint .hint-label {
  color: #9bd6d0;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.active-landmark-hint strong {
  font-size: 15px;
  line-height: 1.2;
}

.active-landmark-hint span:last-child {
  color: #cbd5df;
  font-size: 12px;
  line-height: 1.25;
}

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

.download-buttons button {
  width: 100%;
}

.app-credits {
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
}

.app-credits span {
  display: block;
}

.app-credits a {
  color: var(--accent);
  text-decoration: none;
}

.app-credits a:hover {
  text-decoration: underline;
}

.app-disclaimer {
  margin: 8px 2px 0;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  line-height: 1.35;
}

.viewer-wrap {
  position: relative;
  min-height: 0;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  background: #11181d;
  overflow: hidden;
}

#cephCanvas {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

#cephCanvas.pan-ready {
  cursor: grab;
}

#cephCanvas.panning {
  cursor: grabbing;
}

#cephCanvas.profile-ready {
  cursor: copy;
}

#printImage {
  display: none;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: #d8e3ea;
  pointer-events: none;
}

.empty-state strong {
  font-size: 22px;
}

.empty-state span {
  color: #a9bac5;
}

.badge {
  border-radius: 999px;
  background: #e4f1ee;
  color: var(--accent);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.summary-card {
  min-width: 0;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 10px;
}

.summary-card strong {
  display: block;
  font-size: 20px;
}

.summary-card span {
  color: var(--muted);
  font-size: 11px;
}

.diagnosis-card {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
}

.diagnosis-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #eef8f6;
}

.diagnosis-title span {
  font-size: 13px;
  font-weight: 850;
}

.diagnosis-title small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  text-align: right;
}

.diagnosis-body {
  display: grid;
  gap: 8px;
  max-height: 24vh;
  overflow: auto;
  padding: 12px;
}

.diagnosis-body p {
  margin: 0;
  color: #34434d;
  font-size: 12px;
  line-height: 1.45;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 360px);
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: fixed;
}

th:nth-child(1),
td:nth-child(1) {
  width: 23%;
}

th:nth-child(2),
td:nth-child(2),
th:nth-child(3),
td:nth-child(3),
th:nth-child(4),
td:nth-child(4) {
  width: 14%;
}

th,
td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #edf5f3;
  text-align: left;
  font-size: 11px;
}

.result-name {
  font-weight: 750;
}

.result-system {
  color: var(--muted);
  font-size: 11px;
}

.status-ok {
  color: var(--good);
}

.status-watch {
  color: var(--warn);
}

.status-alert {
  color: var(--bad);
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 300px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) 40vh;
  }

  .sidebar {
    grid-row: 1 / 3;
  }

  .results {
    grid-column: 2;
    grid-row: 2;
    height: auto;
    min-height: 0;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .workspace {
    grid-column: 2;
    grid-row: 1;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
    height: auto;
    overflow: visible;
  }

  .sidebar,
  .results,
  .workspace {
    height: auto;
  }

  .viewer-wrap {
    height: 66vh;
  }

  .toolbar {
    flex-wrap: wrap;
  }

  .viewer-controls {
    top: 10px;
    width: calc(100% - 20px);
  }

  .patient-grid {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    margin: 10mm;
    size: letter portrait;
  }

  body {
    background: #fff;
  }

  .app-shell {
    display: block;
    height: auto;
    overflow: visible;
  }

  .print-report-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 2px solid #0f766e;
  }

  .print-report-header div {
    display: grid;
    gap: 3px;
  }

  .print-report-header div:last-child {
    text-align: right;
  }

  .print-report-header strong {
    color: #0f766e;
    font-size: 20px;
    line-height: 1;
  }

  .print-report-header span {
    color: #45545f;
    font-size: 11px;
    font-weight: 700;
  }

  .sidebar,
  .toolbar,
  .viewer-controls,
  .active-landmark-hint,
  .app-credits,
  .app-disclaimer {
    display: none;
  }

  .workspace {
    display: block;
    height: auto;
    overflow: visible;
  }

  .viewer-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: auto;
    margin: 0 0 8px;
    padding: 6px;
    border: 1px solid #cfd8df;
    border-radius: 8px;
    background: #fff;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  #cephCanvas {
    display: none;
  }

  #printImage {
    display: block;
    width: 100%;
    height: auto;
    max-height: 132mm;
    object-fit: contain;
  }

  .empty-state {
    display: none;
  }

  .results {
    border: 0;
    background: #fff;
    height: auto;
    padding: 0;
    overflow: visible;
  }

  .results > .panel-title,
  .results.collapsed .panel-title,
  .collapse-results-btn,
  .summary-grid {
    display: none !important;
  }

  .results.collapsed .diagnosis-card,
  .diagnosis-card {
    display: block;
    margin-bottom: 0;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .diagnosis-title {
    padding: 6px 9px;
  }

  .diagnosis-body {
    display: block;
    max-height: none;
    overflow: visible;
    padding: 7px 9px;
  }

  .diagnosis-body p {
    margin: 0 0 3px;
    font-size: 8.2px;
    line-height: 1.18;
  }

  .results.collapsed .table-wrap,
  .table-wrap {
    display: block;
    max-height: none;
    overflow: visible;
    border-radius: 8px;
    page-break-before: always;
    break-before: page;
  }

  .app-shell .print-table-title {
    display: grid;
    gap: 2px;
    margin-bottom: 8px;
    padding: 0 0 8px;
    border-bottom: 2px solid #0f766e;
  }

  .print-table-title span {
    color: #0f766e;
    font-size: 16px;
    font-weight: 850;
  }

  .print-table-title small {
    color: #45545f;
    font-size: 10px;
    font-weight: 700;
  }

  table {
    font-size: 7.4px;
    line-height: 1.12;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  th:nth-child(1),
  td:nth-child(1) {
    width: 21%;
  }

  th:nth-child(2),
  td:nth-child(2) {
    width: 12%;
  }

  th:nth-child(3),
  td:nth-child(3) {
    width: 14%;
  }

  th:nth-child(4),
  td:nth-child(4) {
    width: 11%;
  }

  th {
    position: static;
    background: #e7f4f2;
    color: #172026;
    padding: 4px 5px;
  }

  td {
    padding: 3.2px 5px;
    vertical-align: top;
  }

  .result-name {
    font-size: 7.5px;
    line-height: 1.05;
  }

  .result-system {
    font-size: 6.8px;
    line-height: 1.05;
  }
}
