/*
 * Warstwa wizualna zgodna z identyfikacją Labplus (brandbook „Labplus Visual Identification”).
 *
 * Paleta podstawowa: emerald, pearl, ivory. Akcenty: depth (głównie tekst), aqua, sage, blush.
 * Typografia: Lexend Deca — nagłówki i elementy wyróżnione; Poppins — tekst ciągły.
 * Promień narożnika przycisków i kart: 20 px (wartość z brandbooka).
 *
 * Zestawienia kolorów trzymają się dopuszczonych par z guide'u („permitted color combinations”),
 * z dodatkowym warunkiem kontrastu WCAG AA dla tekstu: aqua występuje wyłącznie jako element
 * dekoracyjny (linie, znaczniki, obramowania), nigdy jako kolor drobnego tekstu na jasnym tle.
 */

:root {
  /* Paleta z brandbooka */
  --emerald: #005b57;
  --pearl: #f1f1f1;
  --ivory: #fefdfd;
  --aqua: #59d5ae;
  --sage: #acead7;
  --depth: #003364;
  --blush: #ff9e95;

  /* Role w interfejsie */
  --bg: var(--pearl);
  --surface: var(--ivory);
  --surface-sunken: #e9eef0;
  --border: #dfe4e6;
  --border-strong: #c4d0d2;
  --text: var(--depth);
  --text-muted: #4c6784;
  --text-inverse: var(--ivory);

  --radius: 20px;
  --radius-sm: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 51, 100, 0.06);
  --shadow: 0 2px 4px rgba(0, 51, 100, 0.05), 0 12px 28px rgba(0, 51, 100, 0.07);

  --font-heading: 'Lexend Deca', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-body: 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --wrap: 1120px;
  /* Margines boczny rośnie wraz z ekranem — na telefonie każde 8 px treści jest na wagę złota. */
  --gutter: clamp(16px, 4vw, 24px);
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/*
 * Atrybut `hidden` musi ukrywać element także wtedy, gdy arkusz nadaje mu własny `display`.
 * Reguła `[hidden] { display: none }` pochodzi z arkusza przeglądarki, więc każda nasza deklaracja
 * `display` ją przebija — bez tego `.stats` i `.cases` zostawały widoczne mimo ustawienia `hidden`
 * (liczniki poprzedniego przebiegu wisiały na ekranie do końca następnego).
 */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  font-family: var(--font-heading);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 0;
}

p {
  margin: 0;
}

:where(a, button, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--aqua);
  outline-offset: 2px;
  border-radius: 4px;
}

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* ---------------------------------------------------------------- pasek górny */

.topbar {
  background: var(--ivory);
  border-bottom: 1px solid var(--border);
}

.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
}

.topbar__brand {
  display: inline-flex;
  align-items: center;
}

/* Logo zostaje w oryginalnych kolorach na jasnym tle — brandbook nie dopuszcza przebarwiania znaku. */
.topbar__logo {
  display: block;
  width: auto;
  height: 34px;
}

/*
 * Przełącznik języka: dwa odnośniki w jednej pigułce (segmented control). Aktywny język jest
 * wypełniony emeraldem — to jedyne miejsce w pasku, które ma nieść informację, więc kontrast
 * musi być mocny, a nie subtelny.
 */
.langswitch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--pearl);
  border: 1px solid var(--border);
}

.langswitch__option {
  padding: 6px 14px;
  border-radius: 999px;
  font-family: var(--font-heading);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-decoration: none;
  transition: background-color 140ms ease, color 140ms ease;
}

.langswitch__option:hover {
  color: var(--emerald);
  background: var(--sage);
}

.langswitch__option--active {
  background: var(--emerald);
  color: var(--ivory);
}

.langswitch__option--active:hover {
  background: var(--emerald);
  color: var(--ivory);
}

/* ---------------------------------------------------------------------- hero */

.hero {
  position: relative;
  overflow: hidden;
  background: var(--emerald);
  color: var(--text-inverse);
  padding: 64px 0 72px;
}

/* Delikatny poblask w aqua — gradienty emerald→aqua są w guide'ie dopuszczone. */
.hero::after {
  content: '';
  position: absolute;
  inset: -40% -20% auto auto;
  width: 620px;
  height: 620px;
  background: radial-gradient(circle, rgba(89, 213, 174, 0.28) 0%, rgba(89, 213, 174, 0) 68%);
  pointer-events: none;
}

.hero > .wrap {
  position: relative;
}

.eyebrow {
  font-family: var(--font-heading);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sage);
  margin-bottom: 14px;
}

.hero__title {
  font-size: clamp(2rem, 1.2rem + 2.6vw, 3rem);
  font-weight: 600;
  max-width: 24ch;
}

.hero__lead {
  margin-top: 18px;
  max-width: 62ch;
  color: var(--sage);
  font-size: 1.02rem;
}

.hero__steps {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr));
  gap: 12px;
  margin: 40px 0 0;
  padding: 0;
}

.hero__step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: rgba(254, 253, 253, 0.07);
  border: 1px solid rgba(172, 234, 215, 0.28);
}

.hero__step-index {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--aqua);
  color: var(--emerald);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.9rem;
}

.hero__step-label {
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--ivory);
}

/* ------------------------------------------------------------------- sekcje */

.section {
  padding: 56px 0;
}

.section--muted {
  background: var(--surface-sunken);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.section__label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-heading);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--emerald);
}

/* Cienka linia w aqua obok etykiety sekcji — motyw powtarzany na stronach brandbooka. */
.section__label::after {
  content: '';
  flex: 1 1 auto;
  height: 1px;
  background: var(--aqua);
  max-width: 180px;
}

.section__title {
  margin-top: 10px;
  font-size: 1.55rem;
  color: var(--emerald);
}

.status {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.section__status {
  margin-top: 8px;
}

/* --------------------------------------------------------- lista przypadków */

/*
 * `min(100%, 330px)` zamiast samego `330px`: bez tego minimalny tor siatki jest szerszy niż
 * kontener na telefonie, karty wystają poza ekran i cała strona przewija się w poziomie.
 */
.cases {
  list-style: none;
  margin: 28px 0 0;
  padding: 0;
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
}

.case {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  height: 100%;
  text-align: left;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.case:hover:not(:disabled) {
  border-color: var(--aqua);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.case:disabled {
  cursor: default;
  opacity: 0.5;
}

.case[aria-pressed='true'] {
  border-color: var(--emerald);
  box-shadow: inset 0 0 0 1px var(--emerald), var(--shadow-sm);
}

/* Numer przypadku obok tytułu — ta sama kolejność co pliki w data/cases/. */
.case__head {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.case__index {
  flex: 0 0 auto;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: var(--sage);
  color: var(--emerald);
  font-family: var(--font-heading);
  font-size: 0.76rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.case__title {
  font-size: 1.02rem;
  color: var(--emerald);
}

.case__description {
  font-size: 0.88rem;
  color: var(--text-muted);
}

.case__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.chip {
  font-size: 0.72rem;
  line-height: 1.5;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--pearl);
  color: var(--text-muted);
  /* Bez nowrap — najdłuższa etykieta („wywiad w całości automatyczny") nie mieści się w jednej
     linii na 320 px i rozpychałaby kartę. */
  max-width: 100%;
}

/* Dane pacjenta i zakres badań — wyróżnione, bo to one opisują przypadek merytorycznie. */
.chip--fact {
  background: var(--sage);
  color: var(--emerald);
  font-weight: 500;
}

.chip--accent {
  background: var(--emerald);
  color: var(--ivory);
  font-weight: 500;
}

.case__cta {
  margin-top: auto;
  align-self: flex-start;
  padding: 10px 20px;
  border-radius: var(--radius);
  background: var(--emerald);
  color: var(--ivory);
  font-family: var(--font-heading);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.case:disabled .case__cta {
  background: var(--border-strong);
  color: var(--ivory);
}

/* ---------------------------------------------------------- ekran logowania */

/*
 * Ekran logowania ma tę samą oprawę co strona z przykładami (pasek, stopka, karta), tylko treść
 * jest jedna i wyśrodkowana. Pasek → treść → stopka układają się w kolumnę flex, a treść rozpycha
 * się na resztę wysokości — dzięki temu stopka trzyma się dołu bez liczenia wysokości na piechotę
 * (każde takie równanie rozjeżdża się przy innej długości tekstu).
 */
.page--gate {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.gate {
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  padding: clamp(32px, 8vw, 72px) 0;
  background: var(--surface-sunken);
}

.gate__card {
  width: 100%;
  max-width: 440px;
  margin-inline: auto;
}

.eyebrow--dark {
  color: var(--emerald);
  margin-bottom: 10px;
}

.gate__title {
  font-size: 1.45rem;
  color: var(--emerald);
}

.gate__lead {
  margin-top: 10px;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.gate__form {
  display: grid;
  gap: 8px;
  margin-top: 22px;
}

.gate__label {
  font-family: var(--font-heading);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.gate__input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
}

.gate__input:focus-visible {
  outline: 3px solid var(--aqua);
  outline-offset: 1px;
  border-color: var(--emerald);
}

.gate__submit {
  justify-self: start;
  margin-top: 10px;
  padding: 12px 26px;
  border: 0;
  border-radius: var(--radius);
  background: var(--emerald);
  color: var(--ivory);
  font-family: var(--font-heading);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 140ms ease;
}

.gate__submit:hover {
  background: #004a47;
}

.gate__card .alert {
  margin-top: 18px;
}

/* ------------------------------------------------------------------ przebieg */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

.run {
  margin-top: 28px;
}

.run__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.run__title {
  font-size: 1.05rem;
  color: var(--emerald);
}

.badge {
  font-family: var(--font-heading);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--pearl);
  color: var(--text-muted);
}

.badge--running {
  background: var(--sage);
  color: var(--emerald);
}

.badge--succeeded {
  background: var(--emerald);
  color: var(--ivory);
}

.badge--failed {
  background: var(--blush);
  color: var(--depth);
}

.steps {
  list-style: none;
  margin: 20px 0 0;
  padding: 0;
  display: grid;
  gap: 14px;
}

.step {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 14px;
  align-items: start;
  position: relative;
}

.step__marker {
  width: 14px;
  height: 14px;
  margin-top: 5px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: var(--ivory);
}

.step--active .step__marker {
  border-color: var(--aqua);
  background: var(--aqua);
  animation: pulse 1.4s ease-in-out infinite;
}

.step--done .step__marker {
  border-color: var(--emerald);
  background: var(--emerald);
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(89, 213, 174, 0.55);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(89, 213, 174, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .step--active .step__marker {
    animation: none;
  }
  .case:hover:not(:disabled) {
    transform: none;
  }
}

.step__label {
  font-family: var(--font-heading);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--emerald);
}

.step__label small {
  display: block;
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.alert {
  margin-top: 20px;
  padding: 16px 18px;
  border-radius: var(--radius-sm);
  background: rgba(255, 158, 149, 0.16);
  border-left: 4px solid var(--blush);
}

.alert__message {
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--depth);
}

.alert__hint {
  margin-top: 6px;
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* Ścieżki endpointów i komunikaty z API bywają długie i bez spacji — muszą się łamać, a nie
   rozpychać kartę. To samo dotyczy adresu hosta i list odpowiedzi niżej. */
.alert__details {
  margin: 10px 0 0;
  padding-left: 20px;
  font-size: 0.85rem;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

/* Na telefonie liczniki układają się w dwie kolumny zamiast czterech wierszy jeden pod drugim. */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 130px), 1fr));
  gap: 18px;
  margin: 22px 0 0;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.stats div {
  margin: 0;
}

.stats dt {
  font-family: var(--font-heading);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stats dd {
  margin: 4px 0 0;
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--emerald);
  overflow-wrap: anywhere;
}

/* -------------------------------------------------------------------- raport */

.frame-container {
  margin-top: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

#report-frame {
  display: block;
  width: 100%;
  height: 1400px;
  border: 0;
  background: var(--ivory);
}

/* -------------------------------------------------------------------- stopka */

.footer {
  background: var(--emerald);
  color: var(--sage);
  padding: 36px 0;
}

.footer__inner {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

/* Wersja monochromatyczna znaku na ciemnym tle — brandbook przewiduje taki wariant. */
.footer__logo {
  width: auto;
  height: 28px;
  filter: brightness(0) invert(1);
  opacity: 0.9;
}

.footer__note {
  flex: 1 1 420px;
  font-size: 0.82rem;
  line-height: 1.6;
}

@media (max-width: 620px) {
  .hero {
    padding: 44px 0 52px;
  }

  .hero__steps {
    margin-top: 28px;
  }

  .section {
    padding: 40px 0;
  }

  .card,
  .case {
    padding: 18px;
  }

  /* Zanim ramka zgłosi swoją wysokość, 1400 px to na telefonie prawie dwa ekrany pustki. */
  #report-frame {
    height: 120vh;
  }
}

/* Poniżej ~380 px liczniki mieszczą się już tylko w jednej kolumnie, a logo i przełącznik języka
   przestają się mieścić obok siebie w pasku górnym w pełnych rozmiarach. */
@media (max-width: 380px) {
  .stats {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .run__head {
    align-items: flex-start;
  }

  .topbar__logo {
    height: 28px;
  }

  .langswitch__option {
    padding: 5px 10px;
    font-size: 0.72rem;
  }
}
