* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: #0e1117;
  color: #eef3ff;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

#app {
  flex: 1 1 auto;
  min-height: 0;
  height: 100vh;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header header"
    "controls viewer";
  gap: 14px;
  width: 100%;
  height: 100%;
  padding: 12px 16px 16px;
}

header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(20, 24, 35, 0.92);
  border: 1px solid rgba(118, 155, 255, 0.25);
  border-radius: 12px;
  padding: 9px 12px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
}


.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

header h1 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.2px;
}

#status {
  margin: 0;
  font-size: 10.5px;
  color: #9fbfff;
  font-weight: 600;
  white-space: nowrap;
}

.load-meter {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 130px;
  margin-left: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  visibility: hidden;
  --progress: 0%;
}

.load-meter span {
  font-size: 9.5px;
  color: rgba(223, 231, 255, 0.7);
  white-space: nowrap;
}

.load-meter.active {
  opacity: 1;
  visibility: visible;
}

.load-meter-bar {
  position: relative;
  flex: 1 1 80px;
  height: 5px;
  background: rgba(110, 140, 230, 0.25);
  border-radius: 999px;
  overflow: hidden;
  transform: translateZ(0);
}

.load-meter-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(129, 173, 255, 0.85), rgba(200, 220, 255, 0.85));
  transform: translateX(calc(-100% + var(--progress, 0%)));
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.load-meter.indeterminate .load-meter-fill {
  animation: loadSlide 1s linear infinite;
}

.load-meter.active:not(.indeterminate) .load-meter-fill {
  animation: none;
}

@keyframes loadSlide {
  0% {
    transform: translateX(-100%);
  }
  50% {
    transform: translateX(-10%);
  }
  100% {
    transform: translateX(100%);
  }
}

#controls {
  grid-area: controls;
  display: flex;
  flex-direction: column;
  gap: 6px;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

#controls .control-block:last-child {
  margin-bottom: 0;
}

.control-block {
  background: rgba(20, 24, 35, 0.92);
  border: 1px solid rgba(118, 155, 255, 0.25);
  border-radius: 10px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  box-shadow: 0 6px 20px rgba(6, 8, 14, 0.45);
}

.block-title {
  font-weight: 600;
  font-size: 10px;
  color: #d2e0ff;
  text-transform: uppercase;
  letter-spacing: 0.45px;
}

.button-row {
  display: flex;
  gap: 6px;
}

.button-row .mode-button {
  flex: 1 1 0;
}

.mode-button.active {
  outline: 2px solid rgba(122, 169, 255, 0.95);
  outline-offset: 2px;
  box-shadow: 0 0 18px rgba(122, 169, 255, 0.45);
}

.control-block label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 10px;
}

.control-block input[type="text"],
.control-block select {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(134, 164, 255, 0.35);
  border-radius: 4px;
  padding: 5px 6px;
  color: inherit;
}

.control-block input[type="text"]::placeholder {
  color: rgba(228, 236, 255, 0.65);
}

.control-block input[type="range"] {
  width: 100%;
}

.control-block button,
header button {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 5px 7px;
  font-weight: 600;
  font-size: 10.5px;
  background: linear-gradient(120deg, #81adff, #c8dcff);
  color: #0d1423;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.render-flash {
  position: relative;
  isolation: isolate;
  box-shadow: 0 0 12px rgba(129, 173, 255, 0.35);
  animation: renderGlowPulse 0.9s ease-in-out infinite alternate;
}

.render-flash::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: conic-gradient(from 0deg, #7aa9ff, #9f7aff, #f86dd7, #ffb26f, #7aa9ff);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask-composite: exclude;
  pointer-events: none;
  opacity: 0.75;
}

.render-flash::before {
  content: '';
  display: none;
}

@keyframes renderGlowPulse {
  0% {
    opacity: 0.4;
  }
  100% {
    opacity: 0.9;
  }
}

.control-block button:hover:enabled,
header button:hover:enabled {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.32);
}

.control-block button:disabled,
header button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  box-shadow: none;
  animation: none !important;
}

.control-block button:disabled.render-flash::after,
.control-block button:disabled.render-flash::before,
header button:disabled.render-flash::after,
header button:disabled.render-flash::before {
  display: none;
}

.viewer-pane {
  grid-area: viewer;
  position: relative;
  background: radial-gradient(circle at top, rgba(32, 40, 60, 0.85), #05070c 72%);
  border: 1px solid rgba(122, 169, 255, 0.25);
  border-radius: 14px;
  box-shadow: 0 24px 55px rgba(5, 8, 14, 0.6);
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#viewer-volume,
#viewer-slices {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  width: 100%;
}

#viewer-volume .vtk-container,
#viewer-volume canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

#viewer-slices {
  display: flex;
  flex-direction: column;
}

.viewer-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 10, 18, 0.6);
  color: #dce6ff;
  font-size: clamp(18px, 3vw, 32px);
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  pointer-events: none;
  text-align: center;
  padding: 0 24px;
  z-index: 50;
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.55);
}

.slice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas:
    "axial axial"
    "sagittal coronal";
  gap: 10px;
  width: 100%;
  height: 100%;
  padding: 12px;
  box-sizing: border-box;
}

.slice-panel {
  position: relative;
  background: #020204;
  border: 1px solid rgba(122, 169, 255, 0.25);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.slice-panel.axial {
  grid-area: axial;
}

.slice-panel.sagittal {
  grid-area: sagittal;
}

.slice-panel.coronal {
  grid-area: coronal;
}

.slice-title {
  margin: 8px 12px 6px;
  padding: 3px 8px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  color: #0b101d;
  background: rgba(200, 220, 255, 0.85);
  align-self: flex-start;
}

.slice-wrapper {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.slice-wrapper .vtk-container,
.slice-wrapper canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  background: #000;
}

.slice-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  cursor: crosshair;
  touch-action: none;
}

.slice-overlay::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0);
}

.crosshair-line {
  position: absolute;
  background: rgba(255, 255, 255, 0.85);
  mix-blend-mode: screen;
  pointer-events: none;
}

.crosshair-line.horizontal {
  height: 2px;
  width: 100%;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
}

.crosshair-line.vertical {
  width: 2px;
  height: 100%;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
}

.hidden {
  display: none !important;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(6px);
}

.auth-overlay.hidden {
  display: none;
}

.auth-card {
  background: rgba(22, 28, 42, 0.96);
  border: 1px solid rgba(130, 162, 255, 0.35);
  border-radius: 14px;
  padding: 20px 24px;
  width: min(280px, 90vw);
  box-shadow: 0 20px 48px rgba(3, 5, 12, 0.55);
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}

.auth-card h2 {
  margin: 0;
  font-size: 16px;
  color: #dce9ff;
}

.auth-card p {
  margin: 0;
  font-size: 11px;
  color: rgba(223, 231, 255, 0.75);
}

.auth-card input {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(134, 164, 255, 0.45);
  border-radius: 8px;
  padding: 7px 9px;
  color: #eef3ff;
  font-size: 12px;
}

.auth-card input:focus {
  outline: 2px solid rgba(134, 164, 255, 0.65);
  outline-offset: 2px;
}

.auth-card button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 7px 10px;
  font-weight: 600;
  background: linear-gradient(120deg, #81adff, #c8dcff);
  color: #0d1423;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.auth-card button:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}

.auth-error {
  font-size: 11px;
  color: #ff8c9b;
}

body.auth-locked #app {
  filter: blur(3px);
  pointer-events: none;
  user-select: none;
}

@media (max-width: 1100px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "header"
      "controls"
      "viewer";
  }

  #controls {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
  }

  .control-block {
    flex: 1 1 300px;
  }
}
