:root {
  --bg: #15171a;
  --panel-bg: #1d2024;
  --panel-border: #2c3036;
  --text: #e6e8eb;
  --text-dim: #9aa1ab;
  --accent: #4c9ffe;
  --accent-hover: #6cb2ff;
  --canvas-bg: #000000;
  --danger: #ff6b6b;
  --on-accent: #0a1726;
  --surface-1: #191b1f;
  --surface-2: #22262b;
  --surface-3: #2b3038;
  --btn-bg: #2a2e34;
  --btn-hover: #343941;
  --btn-active: #3c424b;
  --pop-bg: #232830;
  --pop-border: #353c46;
  --row-active: #253040;
  --bar-bg: #22304a;
  --bar-text: #bcd6ff;
  --selected-edge: #ffffff;
  color-scheme: dark;
}

/* Light appearance (☀ in the top bar). The picture area itself always
   stays dark - see .canvas-wrap - because that is how X-rays are read. */
:root[data-theme="light"] {
  --bg: #f1f3f6;
  --panel-bg: #ffffff;
  --panel-border: #d3d9e0;
  --text: #1b2027;
  --text-dim: #5a6470;
  --accent: #1f6fd6;
  --accent-hover: #1759ae;
  --danger: #c62828;
  --on-accent: #ffffff;
  --surface-1: #f6f8fa;
  --surface-2: #eef1f5;
  --surface-3: #e1e7ee;
  --btn-bg: #edf0f3;
  --btn-hover: #e0e5ea;
  --btn-active: #d3d9df;
  --pop-bg: #ffffff;
  --pop-border: #ccd3da;
  --row-active: #dbe8fb;
  --bar-bg: #e2ecfb;
  --bar-text: #153a6e;
  --selected-edge: #1b2027;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

/* Several elements (buttons, panels, ...) get shown/hidden purely via the
   [hidden] attribute from JS. Without this rule, any element that also
   matches an author style setting its own "display" (e.g. .btn's
   "display: inline-flex") stays visible despite [hidden], since a normal
   author declaration always wins over the user-agent stylesheet's
   "[hidden] { display: none }" regardless of selector specificity. */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

h1, h2 {
  margin: 0;
  font-weight: 600;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
}

.topbar h1 {
  font-size: 16px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lang-select {
  font-size: 13px;
  padding: 7px 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--btn-bg);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.btn:hover {
  background: var(--btn-hover);
}

.btn:active {
  background: var(--btn-active);
}

.select-small {
  background: var(--btn-bg);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  cursor: pointer;
}

.btn-small {
  padding: 4px 8px;
  font-size: 12px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  overflow-y: auto;
  border-inline-end: 1px solid var(--panel-border);
  background: var(--panel-bg);
}

.panel {
  background: var(--surface-1);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px;
}

.panel h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
}

.file-list li {
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12.5px;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  color: var(--text-dim);
}

.file-list li:hover {
  background: var(--surface-2);
}

.file-list li.active {
  background: var(--row-active);
  color: var(--text);
}

.file-list li.file-error {
  color: var(--danger);
}

.file-list .empty-hint {
  cursor: default;
  font-style: italic;
}

.file-list .file-index {
  color: var(--text-dim);
  flex-shrink: 0;
}

#metaTableWrap {
  max-height: 46vh;
  overflow-y: auto;
}

.meta-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
}

.meta-table th {
  text-align: start;
  color: var(--text-dim);
  border-bottom: 1px solid var(--panel-border);
  padding: 4px 4px;
  position: sticky;
  top: 0;
  background: var(--surface-1);
}

.meta-table td {
  padding: 4px 4px;
  border-bottom: 1px solid var(--surface-2);
  vertical-align: top;
  word-break: break-word;
}

.meta-table td:first-child {
  color: var(--text-dim);
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.viewer-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--panel-border);
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tool-label {
  font-size: 12px;
  color: var(--text-dim);
  min-width: 2.5em;
}

input[type="range"] {
  width: 110px;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  background: var(--canvas-bg);
  overflow: hidden;
  /* dark palette inside the picture area, whatever the page's appearance */
  --text: #e6e8eb;
  --text-dim: #9aa1ab;
  --accent: #4c9ffe;
  --accent-hover: #6cb2ff;
  --danger: #ff6b6b;
  --on-accent: #0a1726;
  color-scheme: dark;
  display: flex;
  align-items: center;
  justify-content: center;
}

#dicomCanvas {
  position: absolute;
  image-rendering: pixelated;
  cursor: grab;
  touch-action: none;
}

#dicomCanvas:active {
  cursor: grabbing;
}

.empty-state {
  position: relative;
  z-index: 1;
  color: var(--text-dim);
  text-align: center;
  pointer-events: none;
  line-height: 1.6;
}

.error-state {
  color: var(--danger);
  max-width: 480px;
  padding: 16px;
}

/* Dragging a file over an already displayed snímek: a translucent overlay
   with the (translated) "release to open" label from data-drop-label. */
.canvas-wrap.dragover::after {
  content: attr(data-drop-label);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(76, 159, 254, 0.12);
  border: 2px dashed var(--accent);
  color: var(--accent-hover);
  font-size: 18px;
  z-index: 2;
}

/* With nothing loaded yet the drop card below reacts itself instead. */
.canvas-wrap.dragover:has(#emptyState:not([hidden]))::after {
  content: none;
}

/* -------------------------------------------------------------------------
   Empty viewer: an inviting drop area with an animated arrow.
   ------------------------------------------------------------------------- */
.drop-card {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(460px, calc(100vw - 48px));
  padding: 34px 28px 26px;
  border: 2px dashed #3a4350;
  border-radius: 18px;
  background: radial-gradient(120% 90% at 50% 0%, rgba(76, 159, 254, 0.1), rgba(76, 159, 254, 0) 70%), #0c0e11;
  transition: border-color 0.15s, background-color 0.15s, transform 0.15s;
}

.drop-card p {
  margin: 0;
}

.drop-art {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--accent);
  margin-bottom: 16px;
}

.drop-arrow {
  animation: drop-arrow-bounce 1.6s ease-in-out infinite;
}

.drop-tray {
  margin-top: -4px;
  color: #4a5564;
  transition: color 0.15s;
}

@keyframes drop-arrow-bounce {
  0%,
  100% {
    transform: translateY(-8px);
    opacity: 0.55;
  }
  55% {
    transform: translateY(4px);
    opacity: 1;
  }
}

.drop-title {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}

.drop-title-touch,
.drop-title-release {
  display: none;
}

.drop-or {
  margin: 10px 0 !important;
  font-size: 13px;
  color: var(--text-dim);
}

.drop-button {
  padding: 10px 22px;
  font-size: 14px;
}

.drop-formats {
  margin-top: 14px !important;
  font-size: 12.5px;
  color: var(--text-dim);
}

.drop-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 16px !important;
  padding-top: 14px;
  width: 100%;
  border-top: 1px solid #1f242b;
  font-size: 12.5px;
  line-height: 1.4;
  color: #7fcfa6;
}

.drop-note svg {
  flex-shrink: 0;
}

/* A file is being dragged over the window. */
.canvas-wrap.dragover .drop-card {
  border-color: var(--accent);
  border-style: solid;
  background-color: #101a28;
  transform: scale(1.02);
}

.canvas-wrap.dragover .drop-tray {
  color: var(--accent);
}

.canvas-wrap.dragover .drop-arrow {
  animation-duration: 0.7s;
}

.canvas-wrap.dragover .drop-title-mouse,
.canvas-wrap.dragover .drop-title-touch {
  display: none;
}

.canvas-wrap.dragover .drop-title-release {
  display: block;
  color: var(--accent-hover);
}

/* Touch devices cannot drag a file in - lead with the button instead. */
@media (hover: none) and (pointer: coarse) {
  .drop-title-mouse,
  .drop-or {
    display: none;
  }

  .drop-title-touch {
    display: block;
    margin-bottom: 16px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .drop-arrow {
    animation: none;
  }

  .drop-card {
    transition: none;
  }
}

@media (max-height: 560px) {
  .drop-card {
    padding: 18px 22px 16px;
  }

  .drop-art {
    margin-bottom: 8px;
  }

  .drop-arrow {
    width: 40px;
    height: 40px;
  }
}

.measure-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  background: var(--bar-bg);
  border-bottom: 1px solid var(--panel-border);
  border-inline-start: 3px solid var(--accent);
  color: var(--bar-text);
  font-size: 13.5px;
  font-weight: 500;
}

/* The bar slides in and glows when it appears; the first few times ever
   it pulses a little longer so it is not missed. A new step flashes. */
.measure-bar.bar-appear {
  animation: bar-appear 0.8s ease-out;
}

.measure-bar.bar-appear.bar-intro {
  animation:
    bar-appear 0.8s ease-out,
    bar-glow 1.1s ease-in-out 0.4s 3;
}

#measureInstruction.step-flash {
  animation: step-flash 0.7s ease-out;
}

@keyframes bar-appear {
  0% {
    opacity: 0;
    transform: translateY(-6px);
    box-shadow: inset 0 0 0 2px var(--accent);
  }
  35% {
    opacity: 1;
    transform: none;
  }
  100% {
    box-shadow: inset 0 0 0 0 transparent;
  }
}

@keyframes bar-glow {
  0%,
  100% {
    box-shadow: inset 0 0 0 0 transparent;
  }
  50% {
    box-shadow:
      inset 0 0 0 2px var(--accent),
      0 0 14px var(--accent);
  }
}

@keyframes step-flash {
  0% {
    text-shadow: 0 0 10px var(--accent);
  }
  100% {
    text-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .measure-bar.bar-appear,
  .measure-bar.bar-appear.bar-intro,
  #measureInstruction.step-flash {
    animation: none;
  }
}

#dicomCanvas.measuring {
  cursor: crosshair;
}

/* While actively dragging (panning) during a measurement, show the normal
   grabbing cursor instead of the crosshair, since a drag pans rather than
   placing a point. */
#dicomCanvas.measuring:active {
  cursor: grabbing;
}

/* While dragging an existing circle's center/edge handle (move or resize),
   always show grabbing - even outside "measuring" mode, since a finished
   measurement's circles stay draggable afterwards. */
/* A shape / crop tool is waiting for clicks. */
#dicomCanvas.tool-active {
  cursor: crosshair;
}

#dicomCanvas.dragging-handle {
  cursor: grabbing !important;
}

.norberg-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.norberg-hip {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--surface-2);
  border-inline-start: 4px solid var(--accent);
}

.norberg-hip .nh-side {
  font-size: 12px;
  color: var(--text-dim);
}

.norberg-hip .nh-angle {
  font-size: 18px;
  font-weight: 700;
}

.norberg-empty-hint {
  font-size: 12.5px;
  color: var(--text-dim);
  font-style: italic;
  margin-bottom: 8px;
}

.norberg-disclaimer {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 0;
}

.slice-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel-bg);
  border-top: 1px solid var(--panel-border);
}

.slice-bar input[type="range"] {
  flex: 1;
  width: auto;
}

.statusbar {
  flex-shrink: 0;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--panel-bg);
  border-top: 1px solid var(--panel-border);
}

.statusbar.error {
  color: var(--danger);
}

.copyright {
  flex-shrink: 0;
  padding: 4px 14px 8px;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--panel-bg);
  text-align: center;
}

.copyright p {
  margin: 0;
}

.copyright .free-note {
  margin-bottom: 3px;
  font-size: 11.5px;
  line-height: 1.45;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 14px;
}

/* Light / dark switch: shows the appearance it switches TO. */
.theme-toggle {
  padding-inline: 10px;
}

.theme-icon::before {
  content: "☀";
}

:root[data-theme="light"] .theme-icon::before {
  content: "🌙";
}

/* Bar for rotating by an exact angle (opens with the ∡ button). */
.rotate-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--panel-border);
  font-size: 13px;
}

.rotate-bar input[type="range"] {
  flex: 1 1 180px;
  min-width: 120px;
  max-width: 420px;
}

.rot-number-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-dim);
}

#rotNumber {
  width: 76px;
  padding: 4px 6px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

/* Side panel listing the extra measurements (angle, circle, ellipse, point). */
.shapes-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.shapes-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 8px 7px 9px;
  border-radius: 6px;
  background: var(--surface-2);
  border-inline-start: 4px solid #ffb454;
  font-size: 12.5px;
  line-height: 1.4;
  cursor: pointer;
}

.shapes-list li.selected {
  border-inline-start-color: var(--selected-edge);
  background: var(--surface-3);
}

.shape-n {
  flex-shrink: 0;
  min-width: 1.4em;
  font-weight: 700;
  color: #ffb454;
}

.shape-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.shape-title strong {
  font-size: 14px;
  margin-inline-start: 4px;
}

.shape-details {
  color: var(--text-dim);
  font-size: 12px;
}

.shape-del {
  flex-shrink: 0;
  padding: 2px 7px;
  line-height: 1.2;
}

/* Full screen: the whole page goes full screen and only the viewer is kept. */
body.viewer-fullscreen .topbar,
body.viewer-fullscreen .sidebar,
body.viewer-fullscreen .statusbar,
body.viewer-fullscreen .copyright,
body.viewer-fullscreen .cookie-notice {
  display: none !important;
}

/* Printing the picture itself (🖨): one page, picture as large as fits. */
.print-image {
  background: #ffffff;
  color: #000000;
  text-align: center;
  font-family: Helvetica, Arial, sans-serif;
}

.print-image img {
  display: block;
  margin: 0 auto 8px;
  max-width: 100%;
  max-height: 245mm;
}

.print-image p {
  margin: 2px 0;
  font-size: 11px;
}

/* Cookie notice: a small floating card in the bottom-left corner (over the
   sidebar in the viewer, so it never covers the snímek). */
.cookie-notice {
  position: fixed;
  inset-inline-start: 16px;
  bottom: 16px;
  z-index: 40;
  width: 288px;
  max-width: calc(100vw - 32px);
  display: flex;
  gap: 12px;
  padding: 14px 16px 14px 14px;
  color: var(--text);
  background: var(--pop-bg);
  border: 1px solid var(--pop-border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  animation: cookie-notice-in 0.25s ease-out;
}

@keyframes cookie-notice-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .cookie-notice {
    animation: none;
  }
}

.cookie-notice-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: #5fd39a;
  background: rgba(95, 211, 154, 0.12);
}

.cookie-notice p {
  margin: 0;
}

.cookie-notice-title {
  font-size: 13.5px;
  font-weight: 600;
}

.cookie-notice-text {
  margin-top: 3px !important;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-dim);
}

.cookie-notice-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 10px;
}

.cookie-notice-actions .btn {
  padding: 6px 14px;
}

.cookie-notice-actions a {
  font-size: 12.5px;
  color: var(--text-dim);
  text-decoration: underline;
}

.cookie-notice-actions a:hover {
  color: var(--text);
}

@media (max-width: 520px) {
  .cookie-notice {
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
    max-width: none;
  }
}

.copyright a {
  color: var(--text-dim);
  text-decoration: underline;
}

.copyright a:hover {
  color: var(--accent-hover);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 11, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 18px 20px;
  width: 300px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.modal h3 {
  font-size: 15px;
  margin-bottom: 4px;
}

.modal-hint {
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 0 0 10px;
}

.modal-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.modal-options label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  padding: 5px 6px;
  border-radius: 5px;
}

.modal-options label:hover {
  background: var(--surface-2);
}

.modal-options input[type="radio"] {
  width: auto;
  margin: 0;
  flex-shrink: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* -------------------------------------------------------------------------
   Text annotations: free-standing, user-editable captions placed on the
   image itself (see "Přidat text" in the toolbar). The crosshair cursor
   below only applies while placing a NEW one; already-placed ones stay
   draggable via the generic .dragging-handle cursor rule above.
   ------------------------------------------------------------------------- */
#dicomCanvas.text-adding {
  cursor: crosshair;
}
#dicomCanvas.text-adding:active {
  cursor: crosshair;
}

.text-meta-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 50vh;
  overflow-y: auto;
  margin-bottom: 14px;
}

.text-meta-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  padding: 5px 6px;
  border-radius: 5px;
}

.text-meta-row:hover {
  background: var(--surface-2);
}

.text-meta-row input[type="checkbox"] {
  width: auto;
  margin: 2px 0 0;
  flex-shrink: 0;
}

.text-meta-row input[type="checkbox"]:disabled + span {
  color: var(--text-dim);
}

.text-meta-row span {
  line-height: 1.4;
}

/* The floating editor that appears over the canvas when placing/editing a
   text annotation - positioned in JS (left/top/width) to sit exactly over
   the annotation's on-screen box, accounting for the canvas's current
   zoom/pan transform. */
.text-annotation-editor {
  position: fixed;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #15171aee;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  min-width: 160px;
  /* Safety net on top of the font-size cap in positionTextEditorFor(): the
     panel itself must never grow taller than the viewport, so its buttons
     (Hotovo / Z metadat / Smazat) always stay reachable - if the textarea
     ever still needs more room than that (very long text), IT scrolls
     internally (see max-height below) rather than pushing the toolbar off
     the bottom of the screen. */
  max-height: calc(100vh - 16px);
}

.text-annotation-editor[hidden] {
  display: none;
}

.text-annotation-editor textarea {
  background: rgba(10, 12, 15, 0.85);
  color: #ffffff;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 6px 8px;
  font-family: inherit;
  font-weight: 600;
  resize: none;
  min-height: 1.6em;
  max-height: 40vh;
  overflow-y: auto;
  line-height: 1.35;
}

.text-annotation-editor textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.text-annotation-editor-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

/* -------------------------------------------------------------------------
   Responsive layout - tablet/mobile widths.
   Below this breakpoint the sidebar (file list / Norberg panel / metadata)
   stops being a fixed 320px column next to the viewer and stacks instead,
   scrolling along with the rest of the page. The viewer (image + toolbar)
   is shown first so the X-ray itself is the first thing visible, with the
   sidebar panels reachable by scrolling down.
   ------------------------------------------------------------------------- */
@media (max-width: 860px) {
  html, body {
    height: auto;
  }

  body {
    overflow-y: auto;
  }

  .topbar {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .topbar-actions {
    flex-wrap: wrap;
    min-width: 0;
  }

  /* nothing may make the page wider than the screen (the toolbar strip
     scrolls inside itself instead) */
  .viewer,
  .layout {
    min-width: 0;
    max-width: 100vw;
  }

  .layout {
    flex-direction: column;
    overflow: visible;
  }

  .viewer {
    order: 1;
    min-height: 72vh;
  }

  /* The toolbar becomes a single strip that scrolls sideways - with this
     many tools, wrapped rows would push the picture off a small screen. */
  .viewer-toolbar {
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 16px;
    overflow-x: auto;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }

  .tool-group {
    flex-wrap: nowrap;
    flex-shrink: 0;
  }

  .viewer-toolbar .btn,
  .viewer-toolbar .select-small,
  .viewer-toolbar .tool-label {
    flex-shrink: 0;
  }

  .canvas-wrap {
    min-height: 50vh;
  }

  .sidebar {
    order: 2;
    width: 100%;
    max-height: none;
    overflow-y: visible;
    border-inline-end: none;
    border-top: 1px solid var(--panel-border);
  }

  .file-list,
  #metaTableWrap {
    max-height: 40vh;
  }

  input[type="range"] {
    width: 90px;
  }

  .modal {
    width: calc(100vw - 32px);
    max-width: 340px;
  }
}

@media (max-width: 520px) {
  .topbar-actions {
    width: 100%;
  }

  .topbar-actions .btn {
    flex: 1;
    justify-content: center;
  }

  .tool-label {
    min-width: 0;
  }

  .viewer-toolbar {
    gap: 8px 14px;
  }

  input[type="range"] {
    width: 72px;
  }

  .text-annotation-editor {
    min-width: 140px;
    max-width: calc(100vw - 24px);
  }
}

/* -------------------------------------------------------------------------
   PDF export ("Export do PDF"): a plain text/tables report built into
   #pdfReport right before window.print() is called, deliberately WITHOUT
   the rentgen image itself. It stays invisible on screen and is the only
   thing shown when printing - see the @media print block below.
   ------------------------------------------------------------------------- */
#pdfReport {
  display: none;
}

.pdf-page {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #000;
  max-width: 760px;
  margin: 0 auto;
  padding: 24px;
}

.pdf-page h1 {
  font-size: 19px;
  margin: 0 0 4px;
}

.pdf-page h2 {
  font-size: 14.5px;
  margin: 22px 0 8px;
  border-bottom: 1px solid #999;
  padding-bottom: 3px;
}

.pdf-subtitle {
  font-size: 12px;
  color: #444;
  margin: 0 0 6px;
}

.pdf-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.pdf-table th,
.pdf-table td {
  border: 1px solid #999;
  padding: 5px 8px;
  text-align: left;
  vertical-align: top;
}

.pdf-meta-table th {
  width: 170px;
  background: #f0f0f0;
}

.pdf-table thead th {
  background: #e6e6e6;
}

.pdf-table tfoot th,
.pdf-table tfoot td {
  background: #f0f0f0;
}

.pdf-empty {
  font-size: 12.5px;
  color: #555;
  font-style: italic;
  margin: 4px 0 0;
}

.pdf-disclaimer {
  font-size: 10.5px;
  color: #444;
  line-height: 1.5;
  margin-top: 26px;
  border-top: 1px solid #ccc;
  padding-top: 8px;
}

@media print {
  /* Printing always means printing the report - hide the rest of the app
     (including the rentgen snímek itself) and show only #pdfReport. */
  body > *:not(#pdfReport) {
    display: none !important;
  }

  #pdfReport {
    display: block !important;
  }
}

/* Fingers need bigger targets than a mouse pointer (tablets, phones). */
@media (pointer: coarse) {
  .btn-small {
    padding: 8px 11px;
    font-size: 13px;
  }

  .select-small {
    padding: 8px 9px;
    font-size: 13px;
  }

  input[type="range"] {
    height: 28px;
  }

  .shape-del {
    padding: 6px 10px;
  }
}

/* The floating text-note editor sits on top of the picture: dark palette. */
.text-annotation-editor {
  --text: #e6e8eb;
  --text-dim: #9aa1ab;
  --panel-border: #2c3036;
  --accent: #4c9ffe;
  --accent-hover: #6cb2ff;
  --on-accent: #0a1726;
  --btn-bg: #2a2e34;
  --btn-hover: #343941;
  --btn-active: #3c424b;
  color-scheme: dark;
}

/* -------------------------------------------------------------------------
   Settings menu (⚙ in the top bar)
   ------------------------------------------------------------------------- */
.settings-menu {
  position: relative;
}

.settings-menu summary {
  list-style: none;
  padding-inline: 11px;
}

.settings-menu summary::-webkit-details-marker {
  display: none;
}

.settings-menu[open] summary {
  background: var(--btn-active);
}

.settings-pop {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 6px);
  z-index: 45;
  width: 300px;
  max-width: calc(100vw - 24px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--pop-border);
  border-radius: 12px;
  background: var(--pop-bg);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  font-size: 13px;
}

.settings-pop p {
  margin: 0;
}

/* menus that do not fit the window are moved / shortened by js/site.js */
.settings-pop,
.lang-menu ul {
  overflow-y: auto;
  overscroll-behavior: contain;
}

.settings-pop > * {
  flex-shrink: 0;
}

.settings-heading {
  font-size: 14px;
  font-weight: 600;
}

.settings-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin-bottom: -4px !important;
}

.settings-hint {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-dim);
}

.segmented {
  display: flex;
  gap: 6px;
}

.segmented .btn {
  flex: 1;
  justify-content: center;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  line-height: 1.4;
  cursor: pointer;
}

.check-row input {
  margin: 2px 0 0;
  flex-shrink: 0;
}

.panel-hint {
  margin: 4px 0 0;
  font-size: 11.5px;
  color: var(--text-dim);
}

/* -------------------------------------------------------------------------
   Icons-only toolbar (Settings): labels hidden, icons stay
   ------------------------------------------------------------------------- */
.btn-icon-extra {
  display: none;
}

body.icons-only .viewer-toolbar .btn-label,
body.icons-only #shareBtn .btn-label {
  display: none;
}

body.icons-only .viewer-toolbar [data-keep-label] .btn-label {
  display: inline;
}

body.icons-only .viewer-toolbar .btn-icon-extra {
  display: inline;
}

body.icons-only .viewer-toolbar .btn {
  min-width: 30px;
  justify-content: center;
}

/* -------------------------------------------------------------------------
   Tips panel: what the viewer can do (each tip starts its tool)
   ------------------------------------------------------------------------- */
.tips-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tip {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 7px 9px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.tip:hover {
  background: var(--surface-3);
  border-color: var(--panel-border);
}

.tip-title {
  font-size: 12.5px;
  font-weight: 600;
}

.tip-desc {
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-dim);
}

/* -------------------------------------------------------------------------
   Colour / thickness controls of measurements
   ------------------------------------------------------------------------- */
.style-row,
.shape-style {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  margin: 6px 0;
  font-size: 12px;
  color: var(--text-dim);
}

.style-row label,
.shape-style label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.style-row input[type="color"],
.shape-style input[type="color"] {
  width: 30px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  background: none;
  cursor: pointer;
}

.style-row input[type="range"],
.shape-style input[type="range"] {
  width: 84px;
}

.shape-style {
  cursor: default;
}

/* -------------------------------------------------------------------------
   Tips: one at a time, with arrows
   ------------------------------------------------------------------------- */
.tips-list li[hidden] {
  display: none;
}

.tips-list .tip {
  min-height: 62px;
}

.tips-nav {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-transform: none;
  letter-spacing: 0;
}

.tips-counter {
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  text-align: center;
}

.tip-nav {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.tip-nav:hover {
  background: var(--surface-3);
}

[dir="rtl"] .tip-nav {
  transform: scaleX(-1);
}

/* -------------------------------------------------------------------------
   Export dialog: format choice
   ------------------------------------------------------------------------- */
.format-choice {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.format-choice label {
  flex: 1;
  position: relative;
  cursor: pointer;
}

.format-choice input {
  position: absolute;
  opacity: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.format-choice span {
  display: block;
  text-align: center;
  padding: 6px 4px;
  font-size: 12.5px;
  font-weight: 600;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: var(--surface-2);
}

.format-choice input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.format-choice input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.format-desc {
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-dim);
  margin: 0 0 12px;
  min-height: 17px;
}

.modal-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  line-height: 1.4;
  margin-bottom: 14px;
  cursor: pointer;
}

.modal-check input {
  width: auto;
  margin: 2px 0 0;
  flex-shrink: 0;
}

.modal-options[hidden],
.modal-hint[hidden] {
  display: none;
}

.modal-actions {
  flex-wrap: wrap;
}

/* -------------------------------------------------------------------------
   Text size and icon size (Settings)
   --ui-zoom scales the whole interface around the picture (texts, buttons,
   panels, dialogs) - the picture itself keeps its own zoom.
   --icon-scale enlarges only the icons of the toolbar buttons.
   ------------------------------------------------------------------------- */
.topbar,
.sidebar,
.viewer-toolbar,
.measure-bar,
.rotate-bar,
.slice-bar,
.empty-state,
.statusbar,
.copyright,
.modal,
.cookie-notice,
.page-nav,
.page-content {
  zoom: var(--ui-zoom, 1);
}

.viewer-toolbar .btn-icon:not(.btn-icon-extra),
body.icons-only .viewer-toolbar .btn-icon {
  display: inline-block;
  font-size: calc(1em * var(--icon-scale, 1));
  line-height: 1;
  vertical-align: middle;
}

.size-choice .btn {
  padding-inline: 4px;
}

#guideLink {
  text-decoration: none;
}

/* -------------------------------------------------------------------------
   Language menu with flags (viewer and text pages)
   ------------------------------------------------------------------------- */
.lang-menu {
  position: relative;
}

.lang-menu summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: var(--btn-bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.lang-menu summary::-webkit-details-marker {
  display: none;
}

.lang-menu summary::after {
  content: "";
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  transform: rotate(45deg);
}

.lang-menu[open] summary::after {
  margin-top: 3px;
  transform: rotate(225deg);
}

.lang-menu ul {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 6px);
  z-index: 30;
  min-width: 180px;
  margin: 0;
  padding: 6px;
  list-style: none;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: var(--pop-bg);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  columns: 2;
  column-gap: 4px;
}

.lang-menu li {
  break-inside: avoid;
}

.lang-menu a {
  display: block;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-dim);
  text-decoration: none;
  white-space: nowrap;
}

.lang-menu a:hover {
  color: var(--text);
  background: var(--btn-hover);
}

.lang-menu a[aria-current="true"] {
  color: var(--text);
  font-weight: 600;
}

.flag {
  width: 21px;
  height: 14px;
  flex-shrink: 0;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(128, 128, 128, 0.45);
  object-fit: cover;
}

.lang-menu a {
  display: flex;
  align-items: center;
  gap: 8px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0 !important;
  margin: -1px;
  border: 0 !important;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.app-version {
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
}

/* -------------------------------------------------------------------------
   Settings: language by browser
   ------------------------------------------------------------------------- */
#langModeSelect {
  width: 100%;
}

/* -------------------------------------------------------------------------
   Offer of the visitor's own language (js/i18n.js), under the top bar
   ------------------------------------------------------------------------- */
.lang-offer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 8px 16px;
  background: var(--pop-bg);
  border-bottom: 1px solid var(--panel-border);
  font-size: 13px;
  flex-shrink: 0;
  zoom: var(--ui-zoom, 1);
}

.lang-offer-text {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 260px;
}

.lang-offer-hint {
  color: var(--text-dim);
  font-size: 12px;
}

.lang-offer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* -------------------------------------------------------------------------
   PDF report: all DICOM metadata (optional)
   ------------------------------------------------------------------------- */
.pdf-dicom-table {
  font-size: 10.5px;
  table-layout: fixed;
}

.pdf-dicom-table th,
.pdf-dicom-table td {
  padding: 3px 6px;
  overflow-wrap: anywhere;
}

.pdf-dicom-table thead th:nth-child(1) {
  width: 92px;
}

.pdf-dicom-table thead th:nth-child(2) {
  width: 190px;
}

.pdf-dicom-table tr {
  break-inside: avoid;
}

/* -------------------------------------------------------------------------
   Drop-down menus in the viewer's toolbar ("More", "Save / load") -
   placed on the window by js/site.js
   ------------------------------------------------------------------------- */
.tool-menu {
  position: relative;
}

.tool-menu summary {
  list-style: none;
}

.tool-menu summary::-webkit-details-marker {
  display: none;
}

.tool-menu summary::after {
  content: "▾";
  margin-inline-start: 2px;
  opacity: 0.7;
}

.tool-menu[open] summary {
  background: var(--btn-active);
}

body.icons-only .tool-menu .tm-label {
  display: none;
}

.tool-menu-pop {
  position: fixed;
  z-index: 45;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 220px;
  padding: 6px;
  border: 1px solid var(--pop-border);
  border-radius: 10px;
  background: var(--pop-bg);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  overflow-y: auto;
}

.tool-menu-pop .btn {
  justify-content: flex-start;
  width: 100%;
  white-space: nowrap;
}

/* -------------------------------------------------------------------------
   Comparing two pictures side by side
   ------------------------------------------------------------------------- */
.stage-row {
  flex: 1;
  display: flex;
  min-height: 0;
  min-width: 0;
}

.stage-row > .canvas-wrap {
  min-width: 0;
}

.compare-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  background: var(--canvas-bg);
  border-inline-start: 2px solid var(--panel-border);
}

#compareCanvas {
  position: absolute;
  left: 50%;
  top: 50%;
  image-rendering: pixelated;
  pointer-events: none;
}

.compare-name {
  position: absolute;
  top: 8px;
  inset-inline-start: 8px;
  max-width: calc(100% - 16px);
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(10, 12, 15, 0.75);
  color: #e6e8eb;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compare-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--panel-border);
  font-size: 13px;
  zoom: var(--ui-zoom, 1);
}

.compare-bar select {
  max-width: min(360px, 60vw);
}

@media (max-width: 860px) {
  .stage-row {
    flex-direction: column;
  }

  .compare-wrap {
    min-height: 40vh;
    border-inline-start: none;
    border-top: 2px solid var(--panel-border);
  }
}

/* -------------------------------------------------------------------------
   Pixel value under the pointer, magnifier
   ------------------------------------------------------------------------- */
.pixel-readout {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 2;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(10, 12, 15, 0.78);
  color: #e6e8eb;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
  pointer-events: none;
}

.loupe {
  position: fixed;
  z-index: 60;
  width: 210px; /* set by js/app.js */
  height: 210px;
  border-radius: 50%;
  border: 3px solid #ffe14d;
  outline: 1px solid rgba(0, 0, 0, 0.8);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

/* -------------------------------------------------------------------------
   Measurements panel: calibration, comparing two measurements
   ------------------------------------------------------------------------- */
.calib-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 12px;
}

.compare-result {
  margin: 8px 0 0;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 12.5px;
}

.shapes-list .shape-cmp,
.shapes-list .shape-profile {
  flex-shrink: 0;
}

/* Norberg: coverage and left/right difference */
.norberg-hip {
  flex-wrap: wrap;
}

.norberg-hip .nh-sub {
  flex-basis: 100%;
  font-size: 12px;
  color: var(--text-dim);
}

.norberg-diff {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 10px;
  font-size: 12.5px;
  color: var(--text-dim);
}

/* -------------------------------------------------------------------------
   Dialogs: fields, the profile chart
   ------------------------------------------------------------------------- */
.modal-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 12.5px;
}

.modal-field input,
.modal-field textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  resize: vertical;
}

.pdf-assess-hint {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--panel-border);
}

.calib-error {
  color: var(--danger);
}

.modal-wide {
  width: min(700px, calc(100vw - 32px));
}

.profile-chart {
  width: 100%;
  height: auto;
  aspect-ratio: 640 / 280;
  margin: 6px 0 4px;
  border-radius: 6px;
  background: var(--surface-2);
}

.pdf-pre {
  white-space: pre-wrap;
}

/* A low window (a laptop with the browser's bars, a split screen): the
   toolbar becomes one strip that scrolls sideways, as on a phone, so the
   picture keeps its room. */
@media (max-height: 640px) and (min-width: 861px) {
  .viewer-toolbar {
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 16px;
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .tool-group {
    flex-wrap: nowrap;
    flex-shrink: 0;
  }

  .viewer-toolbar .btn,
  .viewer-toolbar .select-small,
  .viewer-toolbar .tool-label {
    flex-shrink: 0;
  }
}

/* -------------------------------------------------------------------------
   1.13: names of measurements, repeated measurements, window presets,
   the picture in the PDF report
   ------------------------------------------------------------------------- */
.shape-name-row {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
}

.shape-name-row input {
  flex: 1;
  min-width: 0;
  padding: 3px 6px;
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

.shape-name-text {
  font-style: normal;
  font-weight: 600;
}

.shape-summary {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 8px 0 0;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 12.5px;
}

#wlPresetSelect {
  max-width: 150px;
}

.pdf-image {
  margin: 10px 0 4px;
  text-align: center;
  break-inside: avoid;
}

.pdf-image img {
  max-width: 100%;
  max-height: 125mm;
}

/* the Magnifier panel */
.loupe-zoom-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 4px;
  font-size: 12.5px;
}

.loupe-zoom-row input[type="range"] {
  flex: 1;
  min-width: 0;
  width: auto;
}

.loupe-zoom-row output {
  min-width: 2.6em;
  text-align: end;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* -------------------------------------------------------------------------
   1.14: comparing - the active picture, clicking the other one;
   the overview of all opened pictures
   ------------------------------------------------------------------------- */
.stage-row.comparing > .canvas-wrap {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.stage-row.main-right > .canvas-wrap {
  order: 2;
}

.stage-row.main-right > .compare-wrap {
  order: 1;
  border-inline-start: none;
  border-inline-end: 2px solid var(--panel-border);
}

.compare-wrap {
  cursor: pointer;
  touch-action: none;
}

.compare-wrap:hover {
  box-shadow: inset 0 0 0 2px rgba(76, 159, 254, 0.45);
}

.main-name {
  z-index: 2;
  pointer-events: none;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.compare-hint {
  color: var(--text-dim);
  font-size: 12px;
}

.file-star {
  color: #ffc23d;
}

.overview-overlay {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
  background: rgba(8, 9, 11, 0.96);
  color: #e6e8eb;
  zoom: var(--ui-zoom, 1);
}

.overview-overlay[hidden] {
  display: none;
}

.overview-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}

.overview-head h3 {
  margin: 0;
  font-size: 16px;
}

.overview-hint {
  flex-basis: 100%;
  margin: 0;
  font-size: 12.5px;
  color: #9aa1ab;
}

.overview-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  align-content: start;
  overflow-y: auto;
  padding: 2px;
}

.ov-tile {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 2px solid #2c3138;
  border-radius: 8px;
  background: #000;
  cursor: pointer;
}

.ov-tile:hover {
  border-color: #4c9ffe;
}

.ov-tile:focus-visible {
  outline: 3px solid #4c9ffe;
  outline-offset: 2px;
}

.ov-tile.current {
  border-color: #4c9ffe;
}

.ov-tile.starred {
  border-color: #ffc23d;
}

.ov-tile img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.ov-wait {
  font-size: 12px;
  color: #9aa1ab;
}

.ov-name {
  position: absolute;
  inset-inline-start: 6px;
  bottom: 6px;
  max-width: calc(100% - 12px);
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(10, 12, 15, 0.8);
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ov-btn {
  position: absolute;
  top: 6px;
  width: 34px;
  height: 34px;
  border: 1px solid #3a4049;
  border-radius: 8px;
  background: rgba(10, 12, 15, 0.8);
  color: #e6e8eb;
  font-size: 17px;
  cursor: pointer;
}

.ov-star {
  inset-inline-end: 6px;
  color: #6b727c;
}

.ov-star[aria-pressed="true"] {
  color: #ffc23d;
}

.ov-cmp {
  inset-inline-end: 46px;
}

.ov-btn:hover {
  border-color: #4c9ffe;
}

/* -------------------------------------------------------------------------
   1.15: the Assessment panel (guided measurements, forms, protocols)
   ------------------------------------------------------------------------- */
.assess-panel {
  border-color: var(--accent);
}

.assess-groups {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.assess-group {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--surface-2);
}

.assess-group > summary {
  padding: 7px 10px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  list-style-position: inside;
}

.assess-methods {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 8px 8px;
}

.assess-methods .btn {
  justify-content: flex-start;
  text-align: start;
  white-space: normal;
}

.proto-list {
  list-style: none;
  margin: 0;
  padding: 0 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.proto-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--panel-bg);
}

.proto-name {
  font-weight: 600;
  font-size: 12.5px;
}

.proto-steps-text {
  flex-basis: 100%;
  order: 3;
  font-size: 11.5px;
  color: var(--text-dim);
}

.proto-actions {
  margin-inline-start: auto;
  display: flex;
  gap: 4px;
}

.assess-group .panel-hint {
  padding: 0 10px;
}

.proto-new {
  margin: 0 8px 8px;
}

.proto-new > summary {
  font-size: 12.5px;
  cursor: pointer;
  padding: 4px 0;
}

.proto-steps {
  margin: 4px 0;
  padding-inline-start: 22px;
  font-size: 12px;
}

.proto-steps li {
  margin: 2px 0;
}

.proto-add {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}

.proto-add select,
.proto-add input {
  flex: 1 1 140px;
  min-width: 0;
}

.proto-add input {
  padding: 4px 6px;
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  background: var(--panel-bg);
  color: var(--text);
  font: inherit;
  font-size: 12px;
}

/* -------------------------------------------------------------------------
   1.16: customizing the toolbar
   ------------------------------------------------------------------------- */
.tb-off {
  display: none !important;
}

#toolbarCustomBtn {
  width: 100%;
}

.toolbar-modal {
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
}

.toolbar-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px 18px;
  margin-bottom: 12px;
}

.toolbar-list h4 {
  margin: 0 0 4px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

.toolbar-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toolbar-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 2px 0;
  font-size: 13px;
}

.toolbar-list label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.tb-arrows {
  display: flex;
  gap: 3px;
}

.tb-arrows .btn {
  padding: 1px 7px;
}

.assess-search {
  padding: 0 8px 6px;
}

.assess-search input {
  width: 100%;
  box-sizing: border-box;
  padding: 5px 8px;
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  background: var(--panel-bg);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
}

/* the choice of an implant template while placing one */
.implant-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 6px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--panel-border);
  font-size: 12.5px;
}

.implant-bar label,
.implant-params label,
.shape-style label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.implant-params {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.implant-bar input[type="number"],
.shape-style input[type="number"] {
  width: 64px;
  padding: 2px 4px;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  background: var(--panel-bg);
  color: var(--text);
  font: inherit;
}

.implant-note {
  color: var(--text-dim);
  font-size: 11.5px;
}

/* trend over time */
.trend-body {
  display: grid;
  gap: 14px;
  max-height: 60vh;
  overflow: auto;
}

.trend-item h4 {
  margin: 0 0 6px;
  font-size: 13.5px;
}

.trend-chart {
  display: block;
  max-width: 100%;
  height: auto;
  background: var(--surface-1);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
}

.trend-axis {
  stroke: var(--panel-border);
}

.trend-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
}

.trend-chart circle {
  fill: var(--accent);
}

.trend-tick {
  fill: var(--text-dim);
  font-size: 10px;
}

.trend-table {
  margin-top: 6px;
}

/* library of studies */
.library-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  max-height: 50vh;
  overflow: auto;
}

.library-list li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 0;
  border-bottom: 1px solid var(--panel-border);
}

.lib-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
}

.lib-names,
.lib-saved,
.lib-empty {
  color: var(--text-dim);
  font-size: 11.5px;
  overflow-wrap: anywhere;
}

.lib-actions {
  display: flex;
  gap: 4px;
}

/* the clinic's header and the signature box of the PDF report */
.pdf-clinic {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid #999;
}

.pdf-clinic-logo {
  max-height: 60px;
  max-width: 200px;
}

.pdf-clinic-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: 11pt;
}

.pdf-signature {
  margin-top: 18px;
}

.pdf-sign-box {
  width: 70mm;
  height: 28mm;
  margin-top: 6px;
  border: 1px solid #777;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font-size: 9pt;
  color: #555;
}

.pdf-sign-box span {
  padding-bottom: 2mm;
}

.clinic-logo-row,
.phrase-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
}

.clinic-logo-preview {
  max-height: 48px;
  max-width: 160px;
  background: #fff;
  border-radius: 4px;
}

.phrases-text {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: var(--panel-bg);
  color: var(--text);
}

/* own keyboard shortcuts */
.shortcuts-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  max-height: 55vh;
  overflow: auto;
  columns: 2 260px;
  column-gap: 20px;
}

.shortcuts-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  break-inside: avoid;
  font-size: 12.5px;
}

.sc-name {
  flex: 1;
}

.sc-key {
  min-width: 70px;
  font-family: ui-monospace, monospace;
}

/* joining two images */
.stitch-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
  align-items: start;
}

.stitch-view {
  max-width: 100%;
  cursor: crosshair;
  background: #000;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
}

.stitch-preview {
  display: block;
  max-width: 100%;
  margin-top: 10px;
  background: #000;
  border-radius: 4px;
}

@media (max-width: 640px) {
  .stitch-pair {
    grid-template-columns: 1fr;
  }
}

/* presentation: only the picture, with a laser pointer */
body.presenting .topbar,
body.presenting .sidebar,
body.presenting .viewer-toolbar,
body.presenting .measure-bar,
body.presenting .implant-bar,
body.presenting .slice-bar,
body.presenting .rotate-bar,
body.presenting .statusbar,
body.presenting .copyright,
body.presenting .cookie-notice {
  display: none !important;
}

body.presenting .layout {
  grid-template-columns: 1fr !important;
  height: 100vh;
}

body.presenting #dicomCanvas {
  cursor: none;
}

.laser-canvas {
  position: fixed;
  inset: 0;
  z-index: 9998;
  pointer-events: none;
}

.present-exit {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 9999;
  opacity: 0.55;
}

.present-exit:hover {
  opacity: 1;
}

.quiz-hidden .shape-title {
  color: var(--text-dim);
  font-style: italic;
}

/* protection of the library */
.lib-lock {
  margin: 8px 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--surface-1);
}

.lock-row,
.lock-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.lock-row {
  justify-content: space-between;
  margin-top: 0;
}

.lock-state {
  font-weight: 600;
  margin: 0;
}

.lock-form .modal-field input {
  width: 100%;
  box-sizing: border-box;
}

.lock-forgot {
  margin-top: 8px;
  font-size: 11.5px;
}

/* tips: the "New" mark and the list of all tips */
.tip-new {
  align-self: flex-start;
  order: -1;
  margin-bottom: 2px;
  padding: 0 6px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tips-all {
  margin-top: 6px;
  width: 100%;
}

.tips-all-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 6px;
  max-height: 60vh;
  overflow: auto;
}

.tips-all-list .tip {
  height: 100%;
}

/* the library: when a study was saved, to tell saved versions apart */
.lib-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
}

.lib-when {
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text);
  font-weight: 600;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* the Save menu: exports and print, a line, saving and loading */
.tool-menu-sep {
  width: 100%;
  margin: 2px 0;
  border: 0;
  border-top: 1px solid var(--pop-border);
}

/* in a menu the labels stay, also with "icons only" */
body.icons-only .tool-menu-pop .btn-label {
  display: inline;
}

/* reading the steps aloud: the switch at the end of the instruction bar */
.speak-btn {
  margin-inline-start: auto;
  flex-shrink: 0;
  min-width: 34px;
  font-size: 15px;
  line-height: 1;
}

.speak-btn.speak-novoice {
  opacity: 0.6;
  text-decoration: line-through;
}

/* Settings: speed and voice of reading aloud, under its switch */
.speech-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 6px 24px;
}

[dir="rtl"] .speech-options {
  margin: 0 24px 6px 0;
}

.speech-rate-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
}

.speech-rate-row input[type="range"] {
  flex: 1;
  min-width: 80px;
}

.speech-options select {
  max-width: 100%;
}

/* Assessment: screening forms (filled in by the user) */
.screen-forms {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 8px 8px;
}

.assess-form {
  border-radius: 6px;
  background: var(--panel-bg);
}

.assess-form > summary {
  padding: 6px 8px;
  font-size: 12.5px;
  cursor: pointer;
}

.assess-form.sf-filled > summary::after {
  content: " ●";
  color: var(--accent, #3b82f6);
}

.sf-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.sf-table th,
.sf-table td {
  padding: 3px 6px;
  text-align: start;
  vertical-align: middle;
}

.sf-table thead th {
  color: var(--text-dim);
  font-weight: 600;
}

.sf-table thead th,
.sf-table td {
  text-align: center;
}

.sf-table tbody th {
  font-weight: 500;
}

.sf-table select,
.sf-table input[type="text"],
.sf-table input[type="number"] {
  width: 100%;
  min-width: 52px;
  box-sizing: border-box;
}

.sf-note {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 8px;
  font-size: 12px;
}

.sf-note textarea {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
}

.assess-form .sf-clear {
  margin: 2px 8px 8px;
}

/* Start screen: an ad below the drop card, only until a file is opened */
.start-ad {
  pointer-events: auto;
  width: min(728px, calc(100vw - 32px));
  margin: 18px auto 0;
  text-align: center;
}

.start-ad-label {
  display: block;
  margin-bottom: 4px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.start-ad ins.adsbygoogle {
  min-height: 90px;
}
