:root {
  color-scheme: dark;
  font: 14px/1.45 system-ui, -apple-system, sans-serif;
  color: #e1eaeb;
  background: #101619;
  --muted: #91a7ae;
  --edge: #2d3c42;
  --panel: #161f23;
  --accent: #70e3cd;
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button, input { font: inherit; }
button {
  min-height: 2.35rem;
  padding: .42rem .74rem;
  border: 1px solid var(--edge);
  border-radius: .38rem;
  background: #202d33;
  color: inherit;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: #2a3b42; }
button[aria-pressed="true"] {
  color: var(--accent);
  border-color: #468e84;
  background: #203d3d;
}
button:focus-visible, input:focus-visible, .viewport:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
h1, h2, p { margin: 0; }

.load-status { min-height: 100dvh; display: grid; place-items: center; padding: 1rem; color: var(--muted); }

#viewer { display: flex; flex-direction: column; height: 100dvh; }
.header {
  background: #132026;
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--edge);
  display: flex;
  align-items: center;
  gap: 1.2rem;
}
.header h1 { font-size: 1.14rem; letter-spacing: -.02em; flex: none; }
.studies { display: flex; gap: .35rem; flex-wrap: wrap; }

.workspace {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #111a1e;
}
.workspace.expanded { position: fixed; inset: 0; z-index: 5; }
.workspace:fullscreen { width: 100%; height: 100%; }
.toolbar {
  padding: .5rem .8rem;
  display: flex;
  gap: .5rem 1rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--edge);
}
.layout, .actions { display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; }
.control-label { color: var(--muted); font-size: .86rem; margin-right: .3rem; }
.layout button { min-width: 2.8rem; font-variant-numeric: tabular-nums; }
.view-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 13rem minmax(0, 1fr); }
.sidebar { overflow: auto; border-right: 1px solid var(--edge); background: var(--panel); }
.series-heading { display: grid; gap: .6rem; padding: 1.05rem .9rem .9rem; }
.series-heading h2 { font-size: 1.08rem; }
.series-heading time { color: var(--muted); font-size: .87rem; }
.series-list { padding: 0 .55rem .55rem; display: grid; gap: .28rem; }
.series-list button {
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: .28rem;
  padding: .58rem .52rem;
  white-space: normal;
  background-color: #1a252a;
}
.series-list button[aria-pressed="true"] { background: #203d3d; }
.series-list small { color: var(--muted); font-variant-numeric: tabular-nums; }
.reports { display: grid; gap: .3rem; }
.imaging { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.viewport-grid {
  padding: .32rem;
  flex: 1;
  min-height: 0;
  display: grid;
  gap: .28rem;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows, 1), minmax(0, 1fr));
  background: #0d1417;
}
.viewport {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #334149;
  border-radius: .25rem;
  background: #030708;
  user-select: none;
}
.viewport.active { border-color: var(--accent); }
.viewport.empty { background: #080e10; border-color: #1d2c31; }
.viewport-head {
  height: 1.65rem;
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: .25rem;
  padding: 0 .46rem;
  background: #172226;
  color: #d9e4e6;
  font-size: .8rem;
}
.viewport.active .viewport-head { background: #24403f; }
.viewport-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.viewport-counter { flex: none; font-size: .74rem; color: #adc2c7; font-variant-numeric: tabular-nums; }
.surface { flex: 1; min-height: 0; position: relative; cursor: crosshair; touch-action: none; }
.surface canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.surface-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: .3rem;
  color: var(--muted);
  pointer-events: none;
}
.window-label { position: absolute; bottom: .3rem; left: .44rem; color: #bad0d1; font-size: .68rem; pointer-events: none; text-shadow: 0 1px 3px #000; }
.image-footer {
  min-height: 2.6rem;
  padding: .25rem .72rem;
  display: flex;
  align-items: center;
  gap: .2rem 1.1rem;
  justify-content: space-between;
  flex-wrap: wrap;
  color: var(--muted);
  background: #132025;
  border-top: 1px solid var(--edge);
  font-size: .79rem;
}
.slice-controls { display: flex; gap: .52rem; align-items: center; color: #c4d8da; }
.slice-controls input { width: clamp(4rem, 13vw, 10rem); accent-color: var(--accent); }
.slice-controls output { min-width: 3.3rem; font-variant-numeric: tabular-nums; }
.hint b { color: #507278; padding-inline: .08rem; }
dialog { width: min(43rem, 95vw); max-height: 90dvh; padding: 1rem; color: inherit; background: var(--panel); border: 1px solid var(--edge); border-radius: .5rem; }
dialog::backdrop { background: #000b; }
dialog form { float: right; }
dialog pre { clear: both; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; }
@media (max-width: 840px) {
  .header { gap: .55rem; padding-inline: .55rem; }
  .toolbar { padding-inline: .55rem; }
  .view-body { grid-template-columns: 10rem minmax(0, 1fr); }
}
@media (max-width: 610px) {
  .header h1 { font-size: .95rem; }
  .header, .toolbar { gap: .4rem; }
  button { padding-inline: .5rem; }
  .view-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .sidebar { border: 0; border-bottom: 1px solid var(--edge); }
  .series-heading { padding: .3rem .6rem; display: flex; align-items: center; }
  .series-heading > div:first-child { display: flex; align-items: baseline; gap: .5rem; }
  .series-heading h2 { font-size: .9rem; }
  .series-list { display: flex; overflow-x: auto; padding: 0 .5rem .35rem; }
  .series-list button { white-space: nowrap; padding: .35rem .46rem; }
  .image-footer .hint { display: none; }
  .viewport-head { height: 1.2rem; padding-inline: .2rem; }
  .window-label { display: none; }
}
