:root {
  color-scheme: dark;
  --room: #080b0e;
  --panel: #11171d;
  --panel-2: #151d24;
  --line: #27313a;
  --muted: #8e9ba6;
  --bone: #eef3f6;
  --scan: #67c4e8;
  --amber: #f1b567;
  --sidebar: 318px;
  font-family: "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  background: var(--room);
  color: var(--bone);
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: var(--room); }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, canvas:focus-visible { outline: 2px solid var(--scan); outline-offset: 2px; }
[hidden] { display: none !important; }

.app-shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); height: 100dvh; }

.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: hidden;
  z-index: 20;
}

.brand-block { display: flex; align-items: center; gap: 14px; min-height: 88px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.brand-mark { position: relative; display: grid; width: 48px; height: 48px; place-items: center; border: 1px solid #4c5d69; background: #0a0f13; font: 700 16px/1 ui-monospace, monospace; letter-spacing: .06em; }
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; background: var(--scan); opacity: .8; }
.brand-mark::before { width: 12px; height: 2px; right: -7px; top: 12px; box-shadow: 0 10px 0 var(--scan), 0 20px 0 var(--scan); }
.brand-mark::after { width: 2px; height: 12px; bottom: -7px; left: 11px; box-shadow: 10px 0 0 var(--scan), 20px 0 0 var(--scan); }
.brand-mark i { position: absolute; inset: 5px; border: 1px solid #293640; }
.eyebrow { margin: 0 0 2px; color: var(--muted); font: 600 10px/1.2 ui-monospace, monospace; letter-spacing: .14em; text-transform: uppercase; }
.brand-block h1 { margin: 0; font: 600 33px/.9 "Avenir Next Condensed", "Arial Narrow", sans-serif; letter-spacing: .05em; }
.sidebar-close { display: none; margin-left: auto; }

.patient-card { padding: 17px 20px 15px; border-bottom: 1px solid var(--line); }
.patient-name { margin: 0 0 12px; color: var(--bone); font: 600 13px/1.25 ui-monospace, monospace; text-transform: uppercase; }
.patient-card dl { display: grid; gap: 5px; margin: 0; font: 11px/1.35 ui-monospace, monospace; }
.patient-card dl div { display: grid; grid-template-columns: 84px 1fr; gap: 8px; }
.patient-card dt { color: var(--muted); }
.patient-card dd { margin: 0; color: #cfd7dd; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.study-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin: 14px 16px; border: 1px solid var(--line); background: var(--line); }
.study-tab { min-width: 0; padding: 11px 8px; border: 0; background: var(--panel); color: var(--muted); cursor: pointer; font: 700 11px/1.1 ui-monospace, monospace; letter-spacing: .06em; text-transform: uppercase; }
.study-tab[aria-selected="true"] { background: #172731; color: var(--scan); box-shadow: inset 0 -2px 0 var(--scan); }
.study-tab:hover { color: var(--bone); }

.series-heading { display: flex; justify-content: space-between; padding: 0 20px 8px; color: var(--muted); font: 600 10px/1 ui-monospace, monospace; letter-spacing: .12em; text-transform: uppercase; }
.series-list { flex: 1; overflow: auto; scrollbar-color: #34424d transparent; scrollbar-width: thin; }
.series-item { position: relative; display: grid; grid-template-columns: 78px minmax(0, 1fr); gap: 12px; width: 100%; min-height: 82px; padding: 9px 18px 9px 20px; border: 0; border-top: 1px solid rgba(39,49,58,.7); background: transparent; text-align: left; cursor: pointer; }
.series-item:last-child { border-bottom: 1px solid rgba(39,49,58,.7); }
.series-item::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: transparent; }
.series-item:hover { background: rgba(255,255,255,.025); }
.series-item[aria-current="true"] { background: #14232c; }
.series-item[aria-current="true"]::before { background: var(--scan); box-shadow: 0 0 18px rgba(103,196,232,.45); }
.series-thumb { width: 78px; height: 62px; object-fit: contain; background: #020304; border: 1px solid #303d47; }
.series-copy { min-width: 0; align-self: center; }
.series-copy strong { display: -webkit-box; overflow: hidden; color: #dfe6eb; font-size: 12px; font-weight: 570; line-height: 1.25; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.series-meta { display: flex; gap: 8px; margin-top: 7px; color: var(--muted); font: 10px/1 ui-monospace, monospace; text-transform: uppercase; }
.plane-badge { color: var(--scan); }
.sidebar-note { min-height: 45px; display: flex; align-items: center; gap: 9px; padding: 11px 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.temporary-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 10px rgba(241,181,103,.45); }

.viewer-main { min-width: 0; display: grid; grid-template-rows: 64px minmax(0, 1fr) auto; background: #030506; }
.topbar { min-width: 0; display: flex; align-items: center; gap: 14px; padding: 0 18px; border-bottom: 1px solid var(--line); background: rgba(17,23,29,.96); }
.study-context { min-width: 0; flex: 1; }
.study-context p { margin: 0 0 4px; color: var(--muted); font: 10px/1 ui-monospace, monospace; letter-spacing: .08em; text-transform: uppercase; }
.study-context div { display: flex; min-width: 0; align-items: baseline; gap: 8px; font-size: 13px; }
#seriesTitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sliceLabel, .context-separator { color: var(--muted); font-family: ui-monospace, monospace; white-space: nowrap; }
.top-actions { display: flex; gap: 8px; }
.text-button, .icon-button, .tool-button, .transport-button { border: 1px solid #34424d; background: #11181e; cursor: pointer; }
.text-button:hover, .icon-button:hover, .tool-button:hover, .transport-button:hover { border-color: #657580; background: #182129; }
.text-button { padding: 8px 11px; font-size: 11px; }
.icon-button { width: 34px; height: 34px; display: grid; place-items: center; padding: 0; font-size: 18px; }
.icon-button.sidebar-close { display: none; }
.menu-button { display: none; }

.viewport-shell { position: relative; min-height: 0; overflow: hidden; background: #000; touch-action: none; user-select: none; }
.viewport-shell::before { content: ""; position: absolute; inset: 13px; border: 1px solid rgba(110,133,148,.2); pointer-events: none; z-index: 2; }
#dicomCanvas { display: block; width: 100%; height: 100%; cursor: grab; will-change: filter; }
#dicomCanvas.is-dragging { cursor: grabbing; }
.overlay { position: absolute; z-index: 3; display: flex; flex-direction: column; gap: 3px; color: rgba(238,243,246,.82); font: 10px/1.25 ui-monospace, monospace; pointer-events: none; text-shadow: 0 1px 3px #000; }
.overlay strong { color: var(--scan); font-weight: 600; }
.overlay-top-left { top: 26px; left: 28px; max-width: 45%; }
.overlay-top-right { top: 26px; right: 28px; align-items: flex-end; }
.orientation { position: absolute; z-index: 3; color: rgba(103,196,232,.75); font: 700 12px/1 ui-monospace, monospace; pointer-events: none; }
.orientation-top { top: 25px; left: 50%; }
.orientation-bottom { bottom: 25px; left: 50%; }
.orientation-left { left: 25px; top: 50%; }
.orientation-right { right: 25px; top: 50%; }
.loading-state { position: absolute; z-index: 5; left: 50%; bottom: 28px; transform: translateX(-50%); display: flex; align-items: center; gap: 9px; padding: 8px 11px; background: rgba(8,11,14,.82); border: 1px solid #34424d; color: #c7d0d7; font: 10px/1 ui-monospace, monospace; }
.loading-state span { width: 8px; height: 8px; border: 1px solid var(--scan); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.loading-state.is-idle { opacity: 0; visibility: hidden; transition: opacity .15s; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-state { position: absolute; z-index: 7; inset: 50% auto auto 50%; width: min(460px, calc(100% - 40px)); transform: translate(-50%, -50%); padding: 20px; border: 1px solid #784b4b; background: #1b1113; box-shadow: 0 18px 60px #000; }
.error-state strong, .error-state code { display: block; margin-bottom: 12px; }
.error-state code { overflow-wrap: anywhere; color: #d8a5a5; font-size: 11px; }
.help-panel { position: absolute; z-index: 8; top: 18px; right: 18px; width: 330px; padding: 15px; background: rgba(17,23,29,.97); border: 1px solid #41505b; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.help-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.help-panel dl { display: grid; gap: 1px; margin: 0; background: var(--line); }
.help-panel dl div { display: grid; grid-template-columns: 145px 1fr; gap: 10px; padding: 9px; background: var(--panel); font-size: 11px; }
.help-panel dt { color: var(--scan); font-family: ui-monospace, monospace; }
.help-panel dd { margin: 0; color: #c6cfd6; }

.control-deck { display: grid; gap: 10px; padding: 12px 16px 14px; border-top: 1px solid var(--line); background: var(--panel); }
.slice-controls, .image-controls { display: flex; min-width: 0; align-items: center; gap: 8px; }
.transport-button { width: 36px; height: 34px; padding: 0; font-size: 22px; line-height: 1; }
.play-button { color: var(--scan); font-size: 14px; }
.play-button[aria-pressed="true"] { background: #17303d; border-color: var(--scan); }
.slice-range-label { display: grid; grid-template-columns: 32px minmax(80px, 1fr) 32px; align-items: center; gap: 8px; flex: 1; min-width: 0; color: var(--muted); font: 10px/1 ui-monospace, monospace; text-align: center; }
input[type="range"] { width: 100%; height: 20px; margin: 0; accent-color: var(--scan); cursor: pointer; }
.image-controls { padding-left: 116px; }
.image-controls label { display: grid; grid-template-columns: auto minmax(70px, 130px); align-items: center; gap: 8px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.image-controls label:last-child { grid-template-columns: auto minmax(60px, 90px) 42px; }
.image-controls output { color: #c9d2d9; font: 9px/1 ui-monospace, monospace; }
.tool-button { width: 34px; height: 30px; padding: 0; }
.tool-button.wide { width: auto; padding: 0 10px; font-size: 10px; }

@media (max-width: 980px) {
  .image-controls { padding-left: 0; overflow-x: auto; padding-bottom: 2px; }
  .image-controls label { grid-template-columns: auto 90px; }
  .top-actions .text-button:first-child { display: none; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(330px, 88vw); transform: translateX(-105%); transition: transform .2s ease; box-shadow: 20px 0 70px rgba(0,0,0,.65); }
  .app-shell.sidebar-open .sidebar { transform: translateX(0); }
  .app-shell.sidebar-open::after { content: ""; position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.54); }
  .icon-button.sidebar-close, .menu-button { display: grid; }
  .viewer-main { height: 100dvh; grid-template-rows: 58px minmax(0, 1fr) auto; }
  .topbar { padding: 0 10px; }
  .top-actions .text-button { padding: 7px 8px; }
  .control-deck { padding: 9px 10px 11px; }
  .image-controls { display: grid; grid-template-columns: 34px 34px auto minmax(0, 1fr); overflow: visible; }
  .image-controls label { grid-column: 1 / -1; grid-template-columns: 100px minmax(0, 1fr); }
  .image-controls label:last-child { grid-template-columns: 100px minmax(0, 1fr) 42px; }
  .orientation, .overlay-top-left span:nth-child(n+2), #overlayDimensions { display: none; }
}

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