/* icd-onsite — the Klinik design system.
 *
 * Hand-written, no build step, no CDN: a hospital network or a demo laptop may
 * resolve nothing at all (docs/ONSITE_PLAN.md §4). Fonts are vendored next to
 * this file and served from the binary.
 *
 * Three sheets, two layers. This one is the design system — tokens, type,
 * the topbar, cards, buttons, form controls — and every page links it. On
 * top of it a product links its own: `demo.css` for the demo's screens,
 * `klinik.css` for the Klinik's. A rule goes here when a second product
 * could use it as it is; a rule that names a screen stays with the product.
 *
 * Colour tokens are §4 verbatim. Anything derived from the artboards but not
 * named in the plan lives in its own block below, so the canonical set stays
 * recognisable.
 */

/* ---------------------------------------------------------------- fonts -- */

@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/static/fonts/IBMPlexSans-Regular.woff2') format('woff2');
}

@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/static/fonts/IBMPlexSans-Medium.woff2') format('woff2');
}

@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/static/fonts/IBMPlexSans-SemiBold.woff2') format('woff2');
}

@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/static/fonts/IBMPlexMono-Regular.woff2') format('woff2');
}

@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/static/fonts/IBMPlexMono-Medium.woff2') format('woff2');
}

/* --------------------------------------------------------------- tokens -- */

:root {
  /* Klinik palette — ONSITE_PLAN.md §4. */
  --ground: #FAFAF8;
  --surface: #FFFFFF;
  --border: #E4E3DE;
  --ink: #2C3138;
  --muted: #6E7178;
  --accent: #2E6E8E;
  --accent-soft: #EAF1F5;
  --green: #3F7A55;
  --amber: #9A6B1F;
  --error: #B04A38;
  --error-soft: #FAEDEA;
  --error-border: #EBD5CF;

  /* Derived from the artboards, not named in §4. */
  --border-faint: #EFEEEA;
  --border-hair: #F5F4F1;
  --border-dashed: #E0DFDA;
  --ink-soft: #4A4F57;
  --trail-line: #EAE9E5;
  --trail-dot: #CFD3D8;
  --amber-soft: #FBF6EC;
  --amber-border: #E8DCC4;
  --green-soft: #EDF5F0;
  --green-border: #CBE0D2;
  --surface-sunk: #FCFCFA;
  --dim: #9CA0A7;
  --placeholder: #B2B6BC;
  --accent-border: #D6E3EB;
  --accent-strong: #1F4F68;

  /* Type. Real fallbacks: the page must be legible before the woff2 lands, and
     stay legible if it never does. */
  --font-sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Geometry — cards 10px, buttons 7-8px (§4). */
  --radius-card: 10px;
  --radius-button: 7px;
  --radius-chip: 6px;
}

/* ---------------------------------------------------------------- reset -- */

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

html {
  -webkit-text-size-adjust: 100%;
}

/* The browser's own `[hidden] { display: none }` is a UA rule, so any author
   `display:` beats it — and several components here set `display: flex`. Without
   this, hiding an element with the `hidden` attribute silently does nothing. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
}

h1,
h2,
h3,
p {
  margin: 0;
}

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

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

code,
kbd,
samp,
pre,
.mono {
  font-family: var(--font-mono);
}

/* ICD codes are always mono: 0/O and 1/l have to stay apart (§4). */
.code {
  font-family: var(--font-mono);
  font-weight: 500;
}

/* --------------------------------------------------------------- topbar -- */

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  height: 56px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar__mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-chip);
  background: var(--accent);
  color: var(--surface);
}

.topbar__name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.topbar__spacer,
/* The same "push the rest to the right" job, outside the topbar. */
.spacer {
  flex-grow: 1;
}

.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--ground);
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  font-size: 12px;
}

.chip--link {
  color: inherit;
  text-decoration: none;
}

.chip--link:hover {
  border-color: var(--accent);
}

.chip__label {
  color: var(--muted);
}

.chip__value {
  font-weight: 500;
}

.status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--muted);
}

.status__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.status--ready .status__dot {
  background: var(--green);
}

.status--error .status__dot {
  background: var(--error);
}

/* Amber: the coding GPU is on its way up. Not an error — a wait. */
.status--warn .status__dot {
  background: var(--amber);
}

/* The two model chips side by side, in the line of the session chip: the
   topbar is one row, and a stacked pair would be the only thing in it two
   lines tall. Each keeps its own dot, so they still read as two answers. */
.statusbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-right: 6px;
}

.statusbar .status {
  font-size: 11.5px;
}

/* The logged-in person's name and the way out, at the right end of the topbar. */
.topbar__session {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ----------------------------------------------------------------- page -- */

.page {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 44px 40px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 22px;
  width: 100%;
  max-width: 860px;
}

.page__title {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 14px;
}

.page__title h1 {
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.page__subtitle {
  font-size: 13.5px;
  color: var(--muted);
}

/* ----------------------------------------------------------------- card -- */

.card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

.card--main .card__body {
  padding: 20px 22px 22px 22px;
}

.card--empty {
  border-style: dashed;
  border-color: var(--border-dashed);
}

.card__header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-faint);
}

.card__meta {
  font-size: 12px;
  color: var(--dim);
}

.card__label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}

.card__body {
  padding: 18px;
}

.card__footer {
  padding: 11px 18px;
  background: var(--surface-sunk);
  border-top: 1px solid var(--border-faint);
}

.placeholder {
  color: var(--placeholder);
  font-size: 14.5px;
  line-height: 1.6;
}

.note {
  font-size: 12.5px;
  color: var(--muted);
}

.note--warn {
  border-left: 2px solid var(--amber);
  padding-left: 9px;
}

/* A card that takes the height it is given: the list in the centre. */
.card--fill {
  flex-grow: 1;
}

.card__title {
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* The sidebar cards hold a list of rows, 8px in from the card edge. */
.card__list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
}

.card__empty {
  padding: 8px 10px;
  font-size: 12.5px;
  color: var(--placeholder);
}

.card__footer--note {
  font-size: 12px;
  color: var(--dim);
}

/* The context panel's card is sectioned: a head, then rules between blocks. */
.card__head {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px 14px 18px;
  border-bottom: 1px solid var(--border-faint);
}

.card__section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-faint);
}

.card__section:last-child {
  border-bottom: 0;
}

.card__section--actions {
  gap: 8px;
}

/* --------------------------------------------------------------- button -- */

.button {
  padding: 11px 22px;
  border: 1px solid transparent;
  border-radius: var(--radius-button);
  background: var(--accent);
  color: var(--surface);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.button:hover {
  background: var(--accent-strong);
}

.button--quiet {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

.button--quiet:hover {
  background: var(--accent-border);
  color: var(--accent-strong);
}

.button:disabled {
  background: var(--border);
  color: var(--dim);
  cursor: default;
}

/* Anchors styled as buttons: `a` has no `cursor: pointer` reset to undo, but it
   does need the text-decoration and colour taken off. */
a.button {
  display: inline-block;
  text-decoration: none;
  color: var(--surface);
}

a.button:hover {
  color: var(--surface);
}

.link {
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
}

.link:hover {
  text-decoration: underline;
}

/* Buttons at panel scale, and the three quieter kinds the panel needs. */
.button--small {
  padding: 6px 12px;
  font-size: 13px;
}

.button--block {
  display: block;
  width: 100%;
  padding: 8px 15px;
  font-size: 13px;
  text-align: center;
}

.button--plain,
a.button--plain {
  background: var(--surface);
  border-color: var(--border);
  color: var(--ink-soft);
}

.button--plain:hover,
a.button--plain:hover {
  background: var(--surface-sunk);
  color: var(--ink);
}

.button--plain:disabled,
.button--plain:disabled:hover {
  background: var(--surface);
  color: var(--placeholder);
  cursor: default;
}

.button--danger {
  align-self: flex-start;
  margin-top: 4px;
  padding: 6px 4px;
  background: transparent;
  color: var(--error);
  font-size: 13px;
}

.button--danger:hover {
  background: var(--error-soft);
}

/* A submit button that has to read as a plain text action ("Rückgängig"): same
   look as .link, but it posts a form, so it must be a button. */
.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}

.link-button:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

/* ----------------------------------------------------------------- form -- */

/* For labels that exist for screen readers but would repeat a visible heading. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.card__body--flush {
  padding: 0;
}

.textarea {
  display: block;
  width: 100%;
  min-height: 268px;
  padding: 18px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.6;
  resize: vertical;
}

.textarea::placeholder {
  color: var(--placeholder);
}

.textarea:focus {
  outline: 2px solid var(--accent-border);
  outline-offset: -2px;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid;
  border-radius: var(--radius-button);
  font-size: 13.5px;
  line-height: 1.45;
}

.message__icon {
  flex-shrink: 0;
  margin-top: 1px;
}

.message--error {
  background: var(--error-soft);
  border-color: var(--error-border);
  color: var(--error);
}

.message--warning {
  background: var(--amber-soft);
  border-color: var(--amber-border);
  color: var(--amber);
}

.message--info {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

.message--success {
  background: var(--green-soft);
  border-color: var(--green-border);
  color: var(--green);
}

.message--toast {
  position: fixed;
  top: 72px;
  right: 24px;
  z-index: 50;
  width: min(380px, calc(100vw - 48px));
  box-shadow: 0 10px 30px rgba(44, 49, 56, 0.14), 0 2px 6px rgba(44, 49, 56, 0.06);
  pointer-events: none;
  animation: message-toast 4600ms ease forwards;
}

@keyframes message-toast {
  0% { opacity: 0; transform: translateY(-8px); }
  6% { opacity: 1; transform: none; }
  88% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-4px); visibility: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .message--toast {
    animation: none;
  }
}

.form-error {
  padding: 10px 14px;
  background: var(--error-soft);
  border: 1px solid var(--error-border);
  border-radius: var(--radius-button);
  color: var(--error);
  font-size: 13px;
  font-weight: 500;
}

/* The same box for a form that went through. */
.form-done {
  padding: 10px 14px;
  background: #EEF5F0;
  border: 1px solid #CFE0D4;
  border-radius: var(--radius-button);
  color: var(--green);
  font-size: 13px;
  font-weight: 500;
}

.actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.hint {
  font-size: 12.5px;
  color: var(--dim);
}

.details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

.details__summary {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 16px 18px;
  cursor: pointer;
  list-style: none;
}

.details__summary::-webkit-details-marker {
  display: none;
}

/* The disclosure triangle from the artboard, drawn rather than vendored. */
.details__summary::before {
  content: '';
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 120ms ease;
}

.details[open] .details__summary::before {
  transform: rotate(45deg);
}

.details__title {
  font-size: 13px;
  font-weight: 600;
}

.details__hint {
  font-size: 12.5px;
  color: var(--dim);
}

.details__body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 18px 16px 18px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field__label {
  font-size: 12px;
  color: var(--muted);
}

.input {
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-button);
  background: var(--surface-sunk);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 13px;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
}

.input[aria-invalid="true"] {
  border-color: var(--error);
}

.field__error {
  margin: 0;
  font-size: 12.5px;
  color: var(--error);
}

.input::placeholder {
  color: var(--placeholder);
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

/* A select is not an input and inherits none of its box; match it so the row
   does not step. `appearance: none` also drops the platform arrow, which at this
   size reads as a misaligned glyph rather than a control. */
select.input {
  appearance: none;
  font-family: inherit;
  cursor: pointer;
}

/* A select has no `placeholder`, so its empty option is one — and has to look
   like one, or „keine Angabe“ reads as a chosen value. `:has` updates live as
   the selection changes, which an attribute selector could not; a browser
   without it just shows the text in the normal colour. */
select.input:has(option[value=""]:checked) {
  color: var(--placeholder);
}

/* `input[type=date]` ignores `placeholder` and draws its own localized mask
   (tt.mm.jjjj), in the same colour as a real value — so an empty date field
   reads as a filled one next to three actual placeholders. There is no selector
   for "a date input with no value" (an optional empty one is `:valid`), so the
   state is rendered as a class instead: server-side from the value, and kept up
   to date by the island. Without scripting the initial render is still right. */
.input--empty::-webkit-datetime-edit {
  color: var(--placeholder);
}

@media (max-width: 720px) {
  .grid-3,
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* A two-way choice as a segmented control, driven by the radio inside each
   half: the input is hidden, the label carries the look. */
.seg {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-button);
  overflow: hidden;
}

.seg__o {
  flex: 1;
  padding: 6px 8px;
  background: var(--surface);
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  user-select: none;
}

.seg__o + .seg__o {
  border-left: 1px solid var(--border);
}

.seg__o input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.seg__o:has(input:checked) {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}

.seg__o:has(input:focus-visible) {
  box-shadow: inset 0 0 0 2px var(--accent-border);
}

.seg__o:has(input:disabled) {
  cursor: default;
  opacity: 0.6;
}

.tick {
  width: 18px;
  height: 18px;
  margin: 0 auto;
  accent-color: var(--accent);
  cursor: pointer;
}

.kv__k {
  font-size: 11.5px;
  color: var(--dim);
}

.kv__v {
  font-size: 12.5px;
  color: var(--ink-soft);
}

.kv__v--dim {
  color: var(--dim);
}

.kv__row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.kv__mode {
  margin-left: auto;
  font-size: 11.5px;
  color: var(--dim);
}

/* ----------------------------------------------------------------- pill -- */

/* One pill shape, stamped by a status, a role, a code. Mono by default: the
   first pills were codes; the sans variants say so themselves. */
.pill {
  padding: 2px 9px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
}

/* ---------------------------------------------------------------- panel -- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

.panel--error {
  border-color: var(--error-border);
}

.panel__title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--error);
}

.panel__text {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink-soft);
}

/* The machine's own words. Wrapped, not clipped: a truncated error message is
   worth nothing to whoever has to report it. */
.detail-box {
  padding: 10px 13px;
  background: var(--surface-sunk);
  border: 1px solid var(--border-faint);
  border-radius: var(--radius-button);
  color: var(--dim);
  font-size: 11.5px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------- login -- */

.login {
  max-width: 480px;
}

.login__body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 22px;
}

/* --------------------------------------------------------------- narrow -- */

@media (max-width: 720px) {
  .page {
    padding: 24px 16px;
  }

  .grid-3 {
    grid-template-columns: 1fr;
  }
}
