/* DICOMShare Portal — design system
   Calm, clinical, high contrast. Light and dark are both first class; the image
   viewer is always dark because that is how radiological images are read. */

:root {
  color-scheme: light dark;

  --ink: #101720;
  --ink-2: #43505f;
  --ink-3: #6b7887;
  --bg: #f4f6f8;
  --bg-2: #e9edf1;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --line: #dde3e9;
  --line-strong: #c3ccd6;

  --accent: #0d7d78;
  --accent-ink: #ffffff;
  --accent-soft: #e2f2f1;
  --accent-line: #9fd3cf;

  --danger: #b3261e;
  --danger-soft: #fdecea;
  --warn: #8a5a00;
  --warn-soft: #fdf3e2;
  --ok: #176b45;

  --shadow-1: 0 1px 2px rgba(16, 23, 32, 0.06), 0 1px 3px rgba(16, 23, 32, 0.04);
  --shadow-2: 0 4px 12px rgba(16, 23, 32, 0.08), 0 1px 3px rgba(16, 23, 32, 0.06);
  --shadow-3: 0 18px 48px rgba(16, 23, 32, 0.18);

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
  --r-xl: 26px;

  --step: 4px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;

  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --ink: #e7eef5;
    --ink-2: #a4b2c1;
    --ink-3: #7d8b9b;
    --bg: #0a0e13;
    --bg-2: #0f151c;
    --surface: #131a23;
    --surface-2: #18212c;
    --line: #26313d;
    --line-strong: #384656;

    --accent: #3bbdb3;
    --accent-ink: #04201f;
    --accent-soft: #113330;
    --accent-line: #1f6a64;

    --danger: #ff9d94;
    --danger-soft: #3a1a17;
    --warn: #e5b567;
    --warn-soft: #33260f;
    --ok: #6cd39b;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-2: 0 6px 18px rgba(0, 0, 0, 0.55);
    --shadow-3: 0 24px 60px rgba(0, 0, 0, 0.65);
  }
}

:root[data-theme='dark'] {
  --ink: #e7eef5;
  --ink-2: #a4b2c1;
  --ink-3: #7d8b9b;
  --bg: #0a0e13;
  --bg-2: #0f151c;
  --surface: #131a23;
  --surface-2: #18212c;
  --line: #26313d;
  --line-strong: #384656;
  --accent: #3bbdb3;
  --accent-ink: #04201f;
  --accent-soft: #113330;
  --accent-line: #1f6a64;
  --danger: #ff9d94;
  --danger-soft: #3a1a17;
  --warn: #e5b567;
  --warn-soft: #33260f;
  --ok: #6cd39b;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-2: 0 6px 18px rgba(0, 0, 0, 0.55);
  --shadow-3: 0 24px 60px rgba(0, 0, 0, 0.65);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 15% -10%, color-mix(in oklab, var(--accent) 12%, transparent), transparent 60%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: -0.015em;
  font-weight: 650;
}

h1 {
  font-size: 1.55rem;
}
h2 {
  font-size: 1.15rem;
}
h3 {
  font-size: 0.98rem;
}

p {
  margin: 0;
}

a {
  color: var(--accent);
}

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

.small {
  font-size: 0.82rem;
}

.stack {
  display: flex;
  flex-direction: column;
}
.stack-2 > * + * {
  margin-top: calc(var(--step) * 2);
}
.stack-3 > * + * {
  margin-top: calc(var(--step) * 3);
}
.stack-5 > * + * {
  margin-top: calc(var(--step) * 5);
}
.row {
  display: flex;
  align-items: center;
  gap: calc(var(--step) * 2);
}
.spacer {
  flex: 1;
}

/* ---------------------------------------------------------------- buttons */

.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 550;
  padding: 9px 16px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.08s var(--ease);
  white-space: nowrap;
  /* Ein Link, der als Knopf auftritt, soll auch wie einer aussehen — die
     Unterstreichung aus der Grundregel für Links gehört hier weg. */
  text-decoration: none;
}

.btn:hover {
  background: var(--surface-2);
  border-color: var(--ink-3);
}
.btn:active {
  transform: translateY(1px);
}
.btn:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
}
.btn.primary:hover {
  background: color-mix(in oklab, var(--accent) 88%, black);
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-2);
}
.btn.ghost:hover {
  background: color-mix(in oklab, var(--ink) 8%, transparent);
}
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.btn.block {
  width: 100%;
  justify-content: center;
  padding: 13px 18px;
  font-size: 1rem;
}

.btn .spin {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ------------------------------------------------------------------ chips */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: color-mix(in oklab, var(--accent) 75%, var(--ink));
  border: 1px solid var(--accent-line);
}

.chip.neutral {
  background: var(--bg-2);
  color: var(--ink-2);
  border-color: var(--line);
}

/* ------------------------------------------------------------------ unlock */

.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: calc(var(--step) * 6) calc(var(--step) * 4);
}

.gate-card {
  width: min(430px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  padding: calc(var(--step) * 8);
}

.brandmark {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--accent);
  margin-bottom: calc(var(--step) * 4);
}

.field {
  display: block;
}

.field > .label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 6px;
}

.field > .hint {
  font-size: 0.78rem;
  color: var(--ink-3);
  margin-top: 6px;
}

input[type='text'],
input[type='email'],
input[type='password'] {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  padding: 12px 14px;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}

input::placeholder {
  color: color-mix(in oklab, var(--ink-3) 75%, transparent);
}

input.code {
  font-family: var(--mono);
  /* Fall-Nummer und Zugangscode sind lang. Auf einem schmalen Telefon müssen
     sie trotzdem ganz ins Feld passen, sonst tippt man blind — deshalb wächst
     die Schrift mit der Breite mit statt fest zu stehen. */
  font-size: clamp(0.92rem, 4.4vw, 1.12rem);
  letter-spacing: clamp(0.02em, 0.9vw, 0.16em);
  text-transform: uppercase;
  text-align: center;
  /* Durchgestrichene Null und tabellarische Ziffern: 0/O ist durch das
     Alphabet ausgeschlossen, 5/S und 2/Z trennt erst die Schrift. */
  font-variant-numeric: slashed-zero tabular-nums;
  font-feature-settings: 'zero' 1, 'ss01' 1;
}

input.dob {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  font-size: 1.05rem;
}

.notice {
  border-radius: var(--r);
  padding: 10px 13px;
  font-size: 0.87rem;
  border: 1px solid transparent;
}
.notice.error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in oklab, var(--danger) 35%, transparent);
}
.notice.warn {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: color-mix(in oklab, var(--warn) 35%, transparent);
}
.notice.info {
  background: var(--bg-2);
  color: var(--ink-2);
  border-color: var(--line);
}

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

.shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: calc(var(--step) * 6) calc(var(--step) * 5) calc(var(--step) * 20);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
  background: color-mix(in oklab, var(--bg) 82%, transparent);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px calc(var(--step) * 5);
  display: flex;
  align-items: center;
  gap: calc(var(--step) * 3);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand .dot {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
}

.patient-head {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: calc(var(--step) * 5);
  box-shadow: var(--shadow-1);
  display: flex;
  flex-wrap: wrap;
  gap: calc(var(--step) * 4);
  align-items: center;
}

.kv {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.kv .k {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-3);
  font-weight: 600;
}
.kv .v {
  font-weight: 600;
}

/* ------------------------------------------------------------------ study */

.study {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}

.study-head {
  display: flex;
  align-items: center;
  gap: calc(var(--step) * 3);
  padding: calc(var(--step) * 4) calc(var(--step) * 5);
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.series-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(184px, 1fr));
  gap: calc(var(--step) * 4);
  padding: calc(var(--step) * 5);
}

.series {
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  background: var(--surface-2);
  cursor: pointer;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), border-color 0.15s var(--ease);
  text-align: left;
  padding: 0;
  font: inherit;
  color: inherit;
  display: block;
}

.series:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
  border-color: var(--accent-line);
}

.thumb {
  aspect-ratio: 1 / 1;
  background: #05080b;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.thumb canvas,
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.thumb .count {
  position: absolute;
  right: 8px;
  bottom: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(4, 8, 12, 0.72);
  color: #dfe8f0;
  backdrop-filter: blur(4px);
}

.series-meta {
  padding: 10px 12px 12px;
}

.series-meta .title {
  font-weight: 600;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actionbar {
  position: sticky;
  bottom: 0;
  z-index: 15;
  margin-top: calc(var(--step) * 6);
  padding: calc(var(--step) * 3) calc(var(--step) * 4);
  background: color-mix(in oklab, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  display: flex;
  align-items: center;
  gap: calc(var(--step) * 3);
  flex-wrap: wrap;
}

.progress {
  height: 4px;
  border-radius: 999px;
  background: var(--bg-2);
  overflow: hidden;
  flex: 1;
  min-width: 120px;
}
.progress > i {
  display: block;
  height: 100%;
  background: var(--accent);
  width: 0;
  transition: width 0.2s var(--ease);
}

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

.viewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #05080b;
  color: #dbe4ee;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.viewer-top,
.viewer-bottom {
  display: flex;
  align-items: center;
  gap: calc(var(--step) * 3);
  padding: 10px 14px;
  background: rgba(10, 15, 20, 0.9);
  border-bottom: 1px solid #1b2530;
}

.viewer-bottom {
  border-bottom: none;
  border-top: 1px solid #1b2530;
  flex-wrap: wrap;
}

.viewer .btn {
  background: #131b24;
  border-color: #2a3644;
  color: #cbd7e3;
}
.viewer .btn:hover {
  background: #1a2532;
}
.viewer .btn.primary {
  background: var(--accent);
  color: #04201f;
  border-color: transparent;
}

.stage {
  position: relative;
  min-height: 0;
}

.stage > .canvas-host {
  position: absolute;
  inset: 0;
}

.stage .disclaimer {
  position: absolute;
  left: 12px;
  bottom: 10px;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  color: #8296aa;
  pointer-events: none;
}

.stage .overlay-tag {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 0.74rem;
  color: #8296aa;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

input[type='range'] {
  accent-color: var(--accent);
  width: 100%;
}

.frame-slider {
  flex: 1;
  min-width: 160px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Der Zähler darf nicht umbrechen — "1 / 12" über zwei Zeilen sieht kaputt aus. */
.frame-slider > .small {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 4.5em;
  text-align: right;
  color: #8296aa;
}

/* -------------------------------------------------------------- utilities

   These exist because the portal ships with `style-src 'self'`: a `style="…"`
   attribute is blocked outright, so every one-off style needs a class. */

.spin-lg {
  width: 26px;
  height: 26px;
  border-width: 3px;
  color: var(--accent);
}

.thumb.doc {
  background: var(--bg-2);
}

/* Muted text inside the always-dark viewer, where the page tokens do not apply. */
.viewer .dim {
  color: #8296aa;
}

.stage-error {
  position: absolute;
  inset: 0;
  color: #cbd7e3;
}

.stage-error p {
  max-width: 40ch;
}

/* ------------------------------------------------------------------- misc */

.center-note {
  display: grid;
  place-items: center;
  min-height: 60vh;
  text-align: center;
  gap: 10px;
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-2), var(--surface-2), var(--bg-2));
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
  border-radius: var(--r);
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 600px) {
  .shell {
    padding: calc(var(--step) * 4) calc(var(--step) * 3) calc(var(--step) * 16);
  }
  .gate-card {
    padding: calc(var(--step) * 6);
  }
  .series-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    padding: calc(var(--step) * 3);
    gap: calc(var(--step) * 3);
  }

  /* Ein Knopf mit langer Beschriftung darf umbrechen, statt die Seite
     breiter zu machen — seitliches Scrollen ist auf dem Telefon der
     sicherste Weg, jemanden zu verlieren. */
  .btn {
    white-space: normal;
    max-width: 100%;
  }

  /* Die Werkzeugleiste über dem Bild sitzt auf schmalen Geräten in zwei
     Reihen statt gedrängt in einer. */
  .actionbar,
  .viewer-top,
  .viewer-bottom {
    flex-wrap: wrap;
  }
}


@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Impressumspflicht: die Fußzeile steht im Grundgerüst und ist deshalb auf
   jedem Bildschirm des Portals sichtbar — auch auf der Anmeldung. */

.portal-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 18px 20px 26px;
  font-size: 0.82rem;
  color: var(--ink-3);
}

.portal-foot a {
  color: var(--ink-3);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.portal-foot a:hover {
  color: var(--accent);
}

/* Im Betrachter würde sie stören: der liegt ohnehin als Vollbild darüber. */
body:has(.viewer) .portal-foot {
  display: none;
}
