:root {
  color-scheme: dark;
  --bg: #0d0f12;
  --panel: #15171d;
  --panel-2: #1b1f27;
  --panel-3: #222832;
  --line: #303844;
  --line-soft: #252b34;
  --text: #edf2f4;
  --muted: #a5b0ba;
  --dim: #737f89;
  --accent: #58d6b0;
  --accent-2: #76a7ff;
  --warn: #f6b44b;
  --danger: #ff6b6b;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.36);
  --radius: 8px;
  font-family: Inter, "SF Pro Display", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.imaging-shell {
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background:
    radial-gradient(circle at 22% -20%, rgba(88, 214, 176, 0.18), transparent 30%),
    radial-gradient(circle at 90% 0%, rgba(246, 180, 75, 0.12), transparent 26%),
    var(--bg);
}

.imaging-topbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  min-height: 64px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 15, 18, 0.88);
  backdrop-filter: blur(18px);
}

.imaging-topbar-compact {
  min-height: 46px;
  padding: 6px 8px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: linear-gradient(145deg, #1d222b, #111319);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

h1,
h2,
p {
  margin: 0;
}

.brand-block h1 {
  font-size: 17px;
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: 0;
}

.brand-block p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-start;
  min-width: 0;
  width: 100%;
  max-width: none;
}

.demo-picker {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 8px;
  color: var(--muted);
  background: #141922;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.demo-picker span {
  font-size: 12px;
  white-space: nowrap;
}

.demo-picker select {
  width: clamp(150px, 16vw, 230px);
  min-width: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: none;
  font-size: 13px;
  cursor: pointer;
}

.demo-picker select option {
  color: #111827;
  background: #f8fafc;
}

.primary-button,
.secondary-button,
.ghost-button,
.text-button,
.tool-button,
.window-presets button {
  min-height: 34px;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.primary-button {
  padding: 0 14px;
  color: #07110e;
  background: var(--accent);
  font-weight: 700;
}

.secondary-button {
  width: 100%;
  color: #08120e;
  background: var(--warn);
  font-weight: 700;
}

.ghost-button {
  padding: 0 12px;
  color: var(--text);
  background: #202631;
  border: 1px solid var(--line);
}

.text-button {
  color: var(--accent);
  background: transparent;
  padding: 0 2px;
  min-height: 24px;
  font-size: 12px;
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.tool-button:hover,
.window-presets button:hover {
  transform: translateY(-1px);
}

.viewer-workbench {
  min-height: 0;
  display: grid;
  grid-template-columns: clamp(190px, 16vw, 300px) minmax(0, 1fr) clamp(220px, 20vw, 360px);
  grid-template-areas: "left stage right";
  gap: 8px;
  padding: 8px;
  overflow: hidden;
}

.left-rail,
.right-rail,
.viewer-stage {
  min-height: 0;
  background: rgba(21, 23, 29, 0.95);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.left-rail {
  grid-area: left;
}

.viewer-stage {
  grid-area: stage;
}

.right-rail {
  grid-area: right;
}

.left-rail,
.right-rail {
  display: grid;
  align-content: start;
  gap: 8px;
  overflow: auto;
  padding: 8px;
}

.rail-section {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--panel-2);
  overflow: hidden;
}

.section-head {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-soft);
}

.section-head h2 {
  font-size: 13px;
  line-height: 1.2;
  font-weight: 700;
}

.section-head span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.drop-card {
  margin: 10px;
  min-height: 112px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--muted);
  border: 1px dashed #4b5864;
  border-radius: var(--radius);
  background: #12161d;
  text-align: center;
  padding: 14px;
}

.drop-card strong {
  color: var(--text);
  font-size: 13px;
}

.drop-card span {
  font-size: 12px;
}

.viewer-workbench.is-dragging .drop-card,
.drop-card.is-hot {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(88, 214, 176, 0.08);
}

.series-list,
.history-list,
.annotation-list {
  display: grid;
  gap: 7px;
  padding: 8px;
}

.series-item,
.history-item,
.annotation-item {
  width: 100%;
  text-align: left;
  border-radius: 6px;
  border: 1px solid var(--line-soft);
  background: #12161c;
  color: var(--text);
  padding: 8px 9px;
}

.series-item {
  cursor: pointer;
}

.series-item.is-active {
  border-color: var(--accent);
  background: rgba(88, 214, 176, 0.12);
}

.series-title,
.history-title,
.annotation-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
}

.series-meta,
.history-meta,
.annotation-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.viewer-stage {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 34px;
  overflow: hidden;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 46px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  background: #11141a;
}

.tool-group,
.window-presets {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-button {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--panel-3);
  border: 1px solid var(--line);
  padding: 0;
}

.tool-button.is-active {
  color: #08120e;
  background: var(--accent);
  border-color: var(--accent);
}

.window-presets button {
  height: 32px;
  padding: 0 9px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
}

.window-presets button.is-active {
  color: var(--text);
  border-color: var(--accent-2);
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    #050607;
  background-size: 28px 28px;
}

.cornerstone-viewport {
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
  cursor: crosshair;
}

.cornerstone-viewport canvas,
.cornerstone-viewport svg {
  width: 100% !important;
  height: 100% !important;
}

.cornerstone-viewport.is-empty {
  pointer-events: none;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.empty-state[hidden] {
  display: none;
}

.empty-state strong {
  color: var(--text);
  font-size: 17px;
}

.empty-state span {
  max-width: 390px;
  font-size: 13px;
  line-height: 1.6;
}

.viewer-status {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: #11141a;
  font-size: 12px;
}

.viewer-status span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.metadata-grid {
  display: grid;
  gap: 0;
  margin: 0;
}

.metadata-grid div {
  display: grid;
  grid-template-columns: 94px minmax(0, 1fr);
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-soft);
}

.metadata-grid div:last-child {
  border-bottom: 0;
}

.metadata-grid dt {
  color: var(--muted);
  font-size: 12px;
}

.metadata-grid dd {
  margin: 0;
  color: var(--text);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.assist-box {
  display: grid;
  gap: 10px;
  padding: 10px;
}

.assist-box label {
  display: grid;
  gap: 6px;
}

.assist-box label span {
  color: var(--muted);
  font-size: 12px;
}

textarea {
  width: 100%;
  min-height: 76px;
  resize: vertical;
  color: var(--text);
  background: #10141b;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  padding: 9px 10px;
  line-height: 1.55;
  font-size: 13px;
}

textarea:focus {
  border-color: var(--accent);
}

.annotation-item {
  position: relative;
}

.annotation-item button {
  position: absolute;
  right: 8px;
  top: 7px;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.annotation-item button:hover {
  color: var(--danger);
  background: rgba(255, 107, 107, 0.1);
}

.is-hidden {
  display: none !important;
}

@media (max-width: 1280px), (max-height: 760px) {
  :root {
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  }

  body {
    overflow: hidden;
  }

  .imaging-shell {
    min-height: 100dvh;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .imaging-topbar {
    min-height: 46px;
    padding: 6px 10px;
    gap: 8px;
  }

  .imaging-topbar-compact {
    padding: 5px 6px;
  }

  .brand-block {
    gap: 8px;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
  }

  .brand-block h1 {
    font-size: 14px;
    line-height: 1.15;
  }

  .brand-block p {
    display: none;
  }

  .topbar-actions {
    gap: 6px;
    min-width: 0;
    flex-wrap: nowrap;
  }

  .demo-picker,
  .primary-button,
  .ghost-button {
    min-height: 30px;
    font-size: 12px;
  }

  .demo-picker {
    max-width: 230px;
    padding: 0 7px;
  }

  .demo-picker span {
    display: none;
  }

  .demo-picker select {
    width: clamp(132px, 18vw, 196px);
    font-size: 12px;
  }

  .viewer-workbench {
    grid-template-columns: clamp(178px, 18vw, 260px) minmax(0, 1fr) clamp(205px, 22vw, 320px);
    grid-template-areas: "left stage right";
    gap: 6px;
    padding: 6px;
  }

  .left-rail,
  .right-rail {
    grid-auto-flow: row;
    grid-auto-columns: auto;
    grid-template-columns: minmax(0, 1fr);
    align-content: stretch;
    overflow: auto;
    padding: 6px;
  }

  .right-rail {
    grid-template-columns: minmax(0, 1fr);
  }

  .rail-section {
    min-height: 0;
    min-width: 0;
    overflow: auto;
  }

  .section-head {
    min-height: 32px;
    padding: 6px 8px;
  }

  .drop-card {
    min-height: 74px;
    margin: 8px;
    gap: 5px;
    padding: 8px;
  }

  .drop-card strong,
  .drop-card span,
  .series-meta,
  .history-meta,
  .annotation-meta {
    font-size: 11px;
  }

  .drop-card span {
    line-height: 1.35;
  }

  .drop-card svg {
    width: 22px;
    height: 22px;
  }

  .series-list,
  .history-list,
  .annotation-list {
    max-height: 116px;
    overflow: auto;
    padding: 6px;
  }

  .metadata-grid {
    max-height: 138px;
    overflow: auto;
  }

  .metadata-grid div {
    grid-template-columns: 78px minmax(0, 1fr);
    padding: 7px 9px;
  }

  .assist-box {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    align-items: end;
    gap: 8px;
    padding: 8px;
  }

  textarea {
    min-height: 66px;
    padding: 7px 8px;
    font-size: 12px;
  }

  .secondary-button {
    width: auto;
    min-width: 116px;
    min-height: 32px;
    padding: 0 10px;
    font-size: 12px;
    white-space: normal;
  }

  .viewer-stage {
    grid-template-rows: auto minmax(0, 1fr) 30px;
  }

  .viewer-toolbar {
    min-height: 38px;
    padding: 4px 6px;
    gap: 6px;
  }

  .tool-group,
  .window-presets {
    gap: 4px;
  }

  .tool-button {
    width: 30px;
    height: 30px;
  }

  .window-presets button {
    height: 30px;
    padding: 0 8px;
    font-size: 12px;
  }

  .viewer-status {
    grid-template-columns: minmax(140px, 1.4fr) repeat(3, minmax(96px, 1fr));
    gap: 8px;
    padding: 0 9px;
    font-size: 11px;
  }
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .imaging-shell {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    grid-template-rows: auto auto;
  }

  .imaging-topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .demo-picker {
    max-width: none;
  }

  .demo-picker span {
    display: inline;
  }

  .viewer-workbench {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(360px, 64vh) auto auto;
    grid-template-areas:
      "stage"
      "left"
      "right";
    overflow: visible;
  }

  .left-rail,
  .right-rail {
    grid-auto-flow: row;
    grid-template-columns: minmax(0, 1fr);
    grid-auto-columns: auto;
    overflow: visible;
  }

  .series-list,
  .history-list,
  .annotation-list,
  .metadata-grid {
    max-height: none;
  }

  .assist-box {
    grid-template-columns: minmax(0, 1fr);
  }

  .secondary-button {
    width: 100%;
  }

  .viewer-toolbar,
  .viewer-status {
    overflow-x: auto;
  }

  .viewer-toolbar {
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .viewer-status {
    grid-template-columns: repeat(4, minmax(140px, 1fr));
  }
}

@media (max-width: 620px) {
  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .demo-picker {
    grid-column: 1 / -1;
  }

  .topbar-actions button,
  .demo-picker {
    width: 100%;
  }

  .demo-picker select {
    width: 100%;
  }

  .viewer-workbench {
    grid-template-rows: minmax(320px, 62vh) auto auto;
  }

  .window-presets {
    width: 100%;
  }

  .window-presets button {
    flex: 1;
  }
}

@media (max-height: 650px) and (min-width: 901px) {
  .imaging-topbar {
    min-height: 42px;
  }

  .viewer-workbench {
    grid-template-columns: clamp(168px, 16vw, 240px) minmax(0, 1fr) clamp(188px, 20vw, 280px);
  }

  .series-list,
  .history-list,
  .annotation-list {
    max-height: 96px;
  }

  .metadata-grid {
    max-height: 110px;
  }
}
