/* --------------------------------------------------------------------------
   PA & Aorta Analysis — non-contrast CT prototype

   The layout borrows the one true dichotomy of the subject: radiology is read
   in a dark room, and reported on white paper. So the viewport is near-black
   and the report is paper, sitting directly against each other. Mask colours
   are IngeniumAI's own from the PHAST report — indigo for pulmonary artery,
   green for aorta — so the demo reads as continuous with their product.
   -------------------------------------------------------------------------- */

:root {
  --vp:        #0b0e14;
  --vp-2:      #151b28;
  --vp-line:   #232c3d;
  --paper:     #fcfcfa;
  --paper-2:   #f2f2ee;
  --ink:       #101623;
  --muted:     #626c80;
  --rule:      #dfe1dc;
  --pa:        #4338e8;
  --ao:        #4fca3c;
  --flag:      #c2410c;
  --flag-wash: #fdf0e8;

  --rail-w:   224px;
  --report-w: 384px;

  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sans: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

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

code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--paper-2);
  padding: 1px 4px;
  border-radius: 3px;
}

.muted { color: var(--muted); }

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

/* ---------------------------------------------------------------- topbar -- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  height: 52px;
  background: var(--vp);
  color: #e8ecf4;
  border-bottom: 1px solid var(--vp-line);
}

.topbar__mark { display: flex; align-items: baseline; gap: 10px; min-width: 0; }

.topbar__dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--pa);
  box-shadow: 0 0 0 3px rgba(67, 56, 232, 0.22);
  align-self: center;
  flex: none;
}

.topbar__name {
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: 15px;
}

.topbar__sub {
  font-family: var(--mono);
  font-size: 11px;
  color: #7c8aa4;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.chip {
  display: inline-block;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 3px;
  white-space: nowrap;
}

.chip--warn {
  color: #ffcda9;
  background: rgba(194, 65, 12, 0.2);
  border: 1px solid rgba(194, 65, 12, 0.5);
}

/* ----------------------------------------------------------------- shell -- */

.shell {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--report-w);
  grid-template-areas:
    "rail viewer report"
    "rail explain report";
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: calc(100dvh - 52px);
}

.rail    { grid-area: rail; }
.viewer  { grid-area: viewer; }
.report  { grid-area: report; }
.explain { grid-area: explain; }

.panel {
  grid-column: 2 / -1;
  padding: 48px;
  background: var(--paper);
}
.panel h2 { margin: 0 0 8px; font-size: 18px; }
.panel--error h2 { color: var(--flag); }

/* ------------------------------------------------------------------ rail -- */

.rail {
  background: var(--vp-2);
  border-right: 1px solid var(--vp-line);
  padding: 16px 0;
  overflow-y: auto;
}

.rail__title {
  display: flex;
  justify-content: space-between;
  margin: 0 16px 12px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #7c8aa4;
}
.rail__title span { color: #4d596e; }

.rail__empty { margin: 0 16px; font-size: 13px; color: #7c8aa4; }
.rail__empty code { background: #0b0e14; color: #a9b6cc; }

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

.caselink {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 16px;
  color: #b6c1d4;
  text-decoration: none;
  border-left: 2px solid transparent;
}
.caselink:hover { background: rgba(255, 255, 255, 0.04); color: #e8ecf4; }
.caselink.is-active {
  background: rgba(67, 56, 232, 0.16);
  border-left-color: var(--pa);
  color: #fff;
}

.caselink__id { font-family: var(--mono); font-size: 12.5px; }

.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.dot--above   { background: var(--flag); }
.dot--within  { background: var(--ao); }
.dot--pending { background: #4d596e; }

/* ---------------------------------------------------------------- viewer -- */

.viewer {
  background: var(--vp);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.viewer__frame {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
  min-height: 340px;
  background:
    radial-gradient(ellipse at 50% 40%, #171f2e 0%, var(--vp) 72%);
}

.stack {
  position: relative;
  width: min(100%, 460px);
  aspect-ratio: 1;
  border: 1px solid var(--vp-line);
  background: #000;
}

.stack img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.stack__over { opacity: 0.7; transition: opacity 90ms linear; }

.stack--none {
  display: grid;
  place-items: center;
  color: #5b6880;
  font-size: 13px;
  aspect-ratio: 16 / 10;
}

.viewer__controls {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 12px 20px;
  border-top: 1px solid var(--vp-line);
  background: var(--vp-2);
}

.seg { display: flex; border: 1px solid var(--vp-line); border-radius: 4px; overflow: hidden; }

.seg__btn {
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 500;
  color: #99a6bd;
  background: transparent;
  border: 0;
  padding: 7px 13px;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 7px;
}
.seg__btn + .seg__btn { border-left: 1px solid var(--vp-line); }
.seg__btn em {
  font-family: var(--mono);
  font-style: normal;
  font-size: 10.5px;
  color: #5b6880;
}
.seg__btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.05); color: #dde3ee; }
.seg__btn.is-on { background: var(--pa); color: #fff; }
.seg__btn.is-on em { color: #c3bffa; }
.seg__btn:disabled { opacity: 0.35; cursor: not-allowed; }

.fade { display: flex; align-items: center; gap: 10px; }
.fade span {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7c8aa4;
}
.fade input[type="range"] { width: 130px; accent-color: var(--pa); }
.fade output {
  font-family: var(--mono);
  font-size: 11.5px;
  color: #99a6bd;
  min-width: 36px;
}

.key {
  display: flex;
  gap: 14px;
  list-style: none;
  margin: 0 0 0 auto;
  padding: 0;
  font-size: 11.5px;
  color: #99a6bd;
}
.key li { display: flex; align-items: center; gap: 6px; }
.key__sw { width: 10px; height: 10px; border-radius: 2px; }
.key__sw--pa { background: var(--pa); }
.key__sw--ao { background: var(--ao); }

/* ---------------------------------------------------------------- report -- */

.report {
  background: var(--paper);
  border-left: 1px solid var(--rule);
  padding: 22px 24px 28px;
  overflow-y: auto;
}

.report__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--ink);
}

.report__head h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.report__id {
  margin: 3px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.verdict {
  font-family: var(--mono);
  font-size: 10px;
  white-space: nowrap;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 3px;
  text-align: right;
  flex: none;
}
.verdict--above   { background: var(--flag-wash); color: var(--flag); }
.verdict--within  { background: #edf9ea; color: #2f7a22; }
.verdict--pending { background: var(--paper-2); color: var(--muted); }

.kv {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  margin: 16px 0;
}
.kv > div { min-width: 0; }
.kv dt {
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.kv dd {
  margin: 2px 0 0;
  font-family: var(--mono);
  font-size: 12.5px;
  overflow-wrap: anywhere;
}
.kv--tight { gap: 7px 16px; margin: 10px 0 0; }

.report__locate {
  margin: 0 0 12px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
  font-size: 12.5px;
  color: var(--muted);
}
.report__locate b { font-family: var(--mono); color: var(--ink); }

.figure {
  background: #eef1fb;
  border-left: 3px solid var(--pa);
  padding: 10px 12px;
}

.figure--primary { padding: 12px 14px; }

.figure__label {
  display: block;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.figure__num {
  display: block;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 26px;
  letter-spacing: -0.02em;
  margin-top: 2px;
}
.figure--primary .figure__num { font-size: 34px; }
.figure__num small { font-size: 0.44em; font-weight: 500; margin-left: 3px; color: var(--muted); }
.figure__num.is-above { color: var(--flag); }

.figure-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
.figure-row .figure__num { font-size: 21px; }

/* ----------------------------------------------------------------- gauge -- */

.gauge { margin: 30px 0 4px; }

.gauge__track {
  position: relative;
  height: 10px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
}

.gauge__over {
  position: absolute;
  top: 0; bottom: 0; right: 0;
  background: repeating-linear-gradient(
    -45deg,
    var(--flag-wash) 0 4px,
    #f8e0d2 4px 8px
  );
}

.gauge__cut {
  position: absolute;
  top: -3px; bottom: -3px;
  width: 1px;
  background: var(--flag);
}

.gauge__marker {
  position: absolute;
  top: -4px;
  width: 2px;
  height: 18px;
  background: var(--pa);
  transform: translateX(-1px);
  animation: gauge-drop 420ms cubic-bezier(0.2, 0.9, 0.25, 1) both;
}
.gauge__marker.is-above { background: var(--flag); }

.gauge__value {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--paper);
  padding: 0 3px;
}

@keyframes gauge-drop {
  from { opacity: 0; transform: translate(-1px, -8px); }
  to   { opacity: 1; transform: translate(-1px, 0); }
}

.gauge__scale { position: relative; height: 16px; margin-top: 2px; }

.gauge__tick { position: absolute; top: 0; transform: translateX(-50%); }
.gauge__tick i {
  display: block;
  width: 1px;
  height: 3px;
  background: var(--rule);
  margin: 0 auto;
}
.gauge__tick b {
  display: block;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 400;
  color: var(--muted);
}

.gauge__legend { font-size: 10.5px; color: var(--muted); margin-top: 6px; }

/* -------------------------------------------------------------- warnings -- */

.warnings {
  margin: 14px 0 0;
  padding: 10px 12px 10px 26px;
  background: var(--flag-wash);
  border-left: 3px solid var(--flag);
  font-size: 12.5px;
  color: #8a3308;
}
.warnings li + li { margin-top: 4px; }

.provenance {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
}
.provenance h3 {
  margin: 0;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.provenance p { font-size: 12px; margin: 10px 0 0; }

/* --------------------------------------------------------------- explain -- */

.explain {
  background: var(--paper);
  border-top: 1px solid var(--rule);
  padding: 18px 24px 22px;
}

.explain__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}
.explain__head h2 { margin: 0; font-size: 14px; font-weight: 600; }

.btn {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  background: var(--ink);
  border: 0;
  border-radius: 4px;
  padding: 8px 15px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: #26303f; }
.btn:disabled { opacity: 0.5; cursor: progress; }

.explain__body { font-size: 14px; max-width: 74ch; }
.explain__body p { margin: 0 0 10px; }

.explain__body h4 {
  margin: 14px 0 6px;
  font-size: 10.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.explain__body ul { margin: 0; padding-left: 18px; }
.explain__body li { margin-bottom: 4px; }

.explain__meta {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 12px;
}

.explain__note {
  background: #eef1fb;
  border-left: 3px solid var(--pa);
  padding: 8px 12px;
  font-size: 12px;
  color: #33308f;
}

.explain__err {
  background: var(--flag-wash);
  border-left: 3px solid var(--flag);
  padding: 9px 12px;
  font-size: 12.5px;
  color: #8a3308;
}

.explain__disclaimer {
  margin: 16px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
  font-size: 11.5px;
  color: var(--muted);
  max-width: 74ch;
}

/* --------------------------------------------------------------- narrow -- */

@media (max-width: 1080px) {
  .shell {
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
    grid-template-areas:
      "rail viewer"
      "rail report"
      "rail explain";
    grid-template-rows: auto auto auto;
  }
  .report { border-left: 1px solid var(--rule); border-top: 1px solid var(--rule); }
  .panel { grid-column: 2 / -1; }
}

@media (max-width: 720px) {
  .topbar {
    height: auto;
    min-height: 52px;
    padding: 9px 14px;
    gap: 10px;
  }
  .topbar__sub { display: none; }
  .topbar__name { font-size: 14px; }
  .chip { font-size: 9.5px; padding: 3px 7px; white-space: normal; text-align: right; }

  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "rail" "viewer" "report" "explain";
  }
  .rail { border-right: 0; border-bottom: 1px solid var(--vp-line); padding-bottom: 10px; }
  .rail__list { display: flex; overflow-x: auto; gap: 6px; padding: 0 12px; }
  .caselink { border-left: 0; border-bottom: 2px solid transparent; padding: 7px 11px; }
  .caselink.is-active { border-left: 0; border-bottom-color: var(--pa); }
  .key { margin-left: 0; }
  .panel { grid-column: 1 / -1; padding: 28px 20px; }
  .figure--primary .figure__num { font-size: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}