:root {
  --page: #F4F6F8;
  --card: #FFFFFF;
  --line: #DFE4EA;
  --ink: #17202A;
  --muted: #64717F;
  --accent: #1D6FD4;
  --accent-soft: #EAF2FC;
  /* Radiographs are read on a black canvas even in light software, so the image
     mat stays dark. It also makes letterboxing around a scan look deliberate. */
  --mat: #0E1317;
  --abnormal: #C0392E;
  --abnormal-soft: #FCEFEC;
  --normal: #1B7A57;
  --normal-soft: #E9F6F0;

  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --gutter: 28px;
  --content: 1180px;
}

/* One centred column. The bars keep their full-width background and bottom rule
   while their contents line up with the work area on any screen width. */
.topbar,
.tabbar,
.surface {
  padding-inline: max(var(--gutter), (100% - var(--content)) / 2);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.micro {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--muted);
}

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
  padding-block: 12px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: baseline; gap: 8px; margin-right: auto; }

.brand-mark {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

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

.conn { display: flex; align-items: center; gap: 7px; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: #B6BFC9; flex: none; }
.dot-ok { background: var(--normal); }
.dot-bad { background: var(--abnormal); }

.conn-text { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }

.settings { display: flex; gap: 10px; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 3px; }

input, select {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 6px 9px;
}

input:hover, select:hover { border-color: #C3CCD6; }

#baseUrl { width: 240px; }
#apiKey { width: 150px; }

/* ---------- tabs ---------- */

.tabbar {
  display: flex;
  gap: 2px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.tab {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 11px 14px 10px;
  margin-bottom: -1px;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

.tab:hover { color: var(--ink); }

.tab-on { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- surface ---------- */

.surface { padding-block: 24px 56px; }

.surface-head { margin-bottom: 16px; }

.surface-head h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.path { margin: 4px 0 0; font-size: 11.5px; color: var(--muted); word-break: break-all; }

/* ---------- the well ---------- */

.well {
  position: relative;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 12px;
}

.well-drag { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.well-busy::before {
  content: "";
  position: absolute;
  top: 0; left: 0;
  height: 2px; width: 34%;
  background: var(--accent);
  animation: sweep 1.15s ease-in-out infinite;
}

@keyframes sweep {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(392%); }
}

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 168px;
  width: 100%;
  background: var(--page);
  border: 1px dashed #C7D0DA;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
}

.drop:hover { border-color: var(--accent); background: var(--accent-soft); }

.drop-hint { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }

.frames { display: grid; gap: 12px; grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr)); }

.frame { display: flex; flex-direction: column; gap: 7px; min-width: 0; }

.frame-body {
  background: var(--mat);
  border-radius: 3px;
  /* flex:1 keeps both frames the same height so the captions share a baseline */
  flex: 1;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.frame-body img { max-width: 100%; max-height: 330px; display: block; }

.frame-foot { display: flex; align-items: center; gap: 10px; min-height: 25px; }

.frame-label {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: auto;
}

.no-preview { text-align: center; color: #8B98A6; padding: 22px 14px; }
.no-preview-name { font-family: var(--mono); font-size: 12.5px; color: #DCE3EA; word-break: break-all; }
.no-preview-note { font-family: var(--mono); font-size: 10.5px; margin-top: 5px; }

/* ---------- options and actions ---------- */

.options { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px 24px; margin: 16px 0 0; }

.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; }

.toggle input { width: 15px; height: 15px; accent-color: var(--accent); margin: 0; padding: 0; }

.opt-hint { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; max-width: 320px; }

.actions { display: flex; align-items: center; gap: 9px; margin: 18px 0 0; }

.btn {
  font: inherit;
  font-weight: 500;
  border-radius: 4px;
  padding: 9px 17px;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #1A63BE; }
.btn-primary:disabled { background: #C4CDD7; color: #7B8794; cursor: not-allowed; }

.btn-ghost { background: var(--card); color: var(--muted); border-color: var(--line); }
.btn-ghost:hover { color: var(--ink); border-color: #C3CCD6; }

.btn-small {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.05em;
  padding: 5px 10px;
  border-radius: 3px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
}

.btn-small:hover { border-color: var(--accent); color: var(--accent); }

.file-chip { display: flex; align-items: center; gap: 10px; margin: 12px 0 0; }

.file-name { font-family: var(--mono); font-size: 11.5px; color: var(--muted); word-break: break-all; }

/* ---------- readout ---------- */

/* Contained in a card like the image well above it, so the result does not read
   as loose text sitting on the page. */
.readout {
  margin: 22px 0 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 16px;
}

.result-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

/* the finding, tinted by its state */
.verdict {
  border-left: 3px solid;
  border-radius: 0 4px 4px 0;
  padding: 14px 16px 16px;
}

.verdict.is-abnormal { border-left-color: var(--abnormal); background: var(--abnormal-soft); }
.verdict.is-normal { border-left-color: var(--normal); background: var(--normal-soft); }

.verdict-head { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; flex-wrap: wrap; }

.verdict-label {
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.is-abnormal .verdict-label { color: var(--abnormal); }
.is-normal .verdict-label { color: var(--normal); }

.prob { font-family: var(--mono); font-size: 2.5rem; line-height: 1; font-variant-numeric: tabular-nums; }

.verdict-sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; }

/* the probability-against-threshold gauge */
.gauge { margin: 16px 0 0; }

.track { position: relative; height: 6px; background: rgba(17, 24, 33, 0.12); border-radius: 3px; }

.fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 3px; transition: width 620ms cubic-bezier(.22,.7,.25,1); }

.is-abnormal .fill { background: var(--abnormal); }
.is-normal .fill { background: var(--normal); }

.thr { position: absolute; top: -4px; bottom: -4px; width: 2px; border-radius: 1px; background: rgba(17, 24, 33, 0.45); }

.marker {
  position: absolute;
  top: 50%;
  left: 0;
  width: 13px; height: 13px;
  margin: -6.5px 0 0 -6.5px;
  border-radius: 50%;
  background: var(--ink);
  border: 2.5px solid var(--card);
  transition: left 620ms cubic-bezier(.22,.7,.25,1);
}

.scale { position: relative; height: 15px; margin-top: 9px; font-family: var(--mono); font-size: 10px; color: var(--muted); }

.scale-min { position: absolute; left: 0; }
.scale-max { position: absolute; right: 0; }
.scale-thr { position: absolute; transform: translateX(-50%); white-space: nowrap; color: var(--ink); }

/* returned values, as a divided list rather than floating pairs */
.stats { border: 1px solid var(--line); border-radius: 4px; }

.stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}

.stat:last-child { border-bottom: 0; }

.stat-value { font-family: var(--mono); font-size: 12.5px; text-align: right; }

.notes { margin: 14px 0 0; display: flex; flex-direction: column; gap: 8px; }

.warn {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  padding: 9px 12px;
  border-radius: 0 4px 4px 0;
  font-size: 13px;
}

.disclaimer { margin: 14px 0 0; padding-top: 13px; border-top: 1px solid var(--line); }

.disclaimer p { margin: 5px 0 0; font-size: 12px; line-height: 1.55; color: var(--muted); max-width: 92ch; }

.error {
  margin: 22px 0 0;
  border-left: 3px solid var(--abnormal);
  background: var(--abnormal-soft);
  padding: 11px 13px;
  border-radius: 0 4px 4px 0;
  font-size: 14px;
}

.error-title { font-weight: 600; color: var(--abnormal); }

/* ---------- image switch, narrow screens only ---------- */

.switch { display: none; margin: 10px 0 0; }

.switch-btn {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 6px 13px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
}

.switch-btn:first-child { border-radius: 3px 0 0 3px; }
.switch-btn:last-child { border-radius: 0 3px 3px 0; border-left: 0; }
.switch-on { background: var(--accent-soft); color: var(--accent); }

/* The verdict panel needs room for the label, the number and the gauge, so the
   returned-values list drops beneath it before the main layout changes. */
@media (max-width: 900px) {
  .result-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 720px) {
  :root { --gutter: 16px; }
  .surface { padding-block: 20px 44px; }
  .frames { --cols: 1 !important; }
  .switch-shown { display: flex; }
  .view-a .frame-b { display: none; }
  .view-b .frame-a { display: none; }
  .prob { font-size: 2.3rem; }
  .settings { width: 100%; }
  #baseUrl, #apiKey { width: 100%; }
  .field { flex: 1 1 150px; }
}

@media (prefers-reduced-motion: reduce) {
  .fill, .marker { transition: none; }
  .well-busy::before { animation: none; width: 100%; opacity: 0.5; }
}
