/* NumaSense Tablet-App – Gestaltung nach docs/CI.md und Konzept Abschnitt 15/16.
   Keine externen Ressourcen. Muring-Schriften werden ergänzt, sobald die woff2-Dateien vorliegen. */

:root {
  /* Markenfarben (CI) */
  --ultramarine: #4136c3;
  --white: #ffffff;
  --azure: #def1fa;
  --royal-blue: #4e71ff;
  --pale-turquoise: #a8fbd3;
  --light-blue-grey: #bbd4de;

  /* Abgeleitete Töne */
  --ultramarine-dark: #2f2696;
  --azure-50: #eef8fd;
  --text: #1c1748;          /* sehr dunkles Ultramarine für Fließtext, Kontrast > 14:1 */
  --text-muted: #4a4f6a;    /* Kontrast auf Weiß > 7:1 */
  --error: #b00020;         /* nicht in der Palette: nur mit Symbol + Text (Konzept 16) */
  --error-bg: #fdecee;

  --font-body: "Muring 01", Aptos, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-head: "Muring 02", Aptos, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --touch: 3.5rem;          /* 56 px Mindesthöhe */
  --gap: 0.75rem;           /* 12 px Mindestabstand */
  --radius: 1rem;
  --maxw: 46rem;
}

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

html {
  font-size: 100%;        /* Schriftvergrößerung des Geräts respektieren */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  font-size: 1.125rem;    /* 18 px */
  line-height: 1.55;
  color: var(--text);
  background: var(--white);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body.mode-staff { background: var(--azure); }

h1, h2, h3 { font-family: var(--font-head); color: var(--ultramarine); line-height: 1.25; margin: 0 0 0.75em; }
h1 { font-size: 2rem; font-weight: 700; }
h2 { font-size: 1.4rem; font-weight: 700; }
p { margin: 0 0 1em; }
code { font-size: 0.95em; }

:focus-visible { outline: 3px solid var(--royal-blue); outline-offset: 3px; }
/* Überschriften erhalten den Fokus nur für Screenreader beim Bildschirmwechsel */
h1[tabindex="-1"]:focus { outline: none; }

[hidden] { display: none !important; }

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

/* --- Kopfleiste ------------------------------------------------------------ */

.bar {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.75rem max(1.25rem, env(safe-area-inset-right)) 0.75rem max(1.25rem, env(safe-area-inset-left));
  border-bottom: 1px solid var(--light-blue-grey);
  background: var(--white);
  position: sticky; top: 0; z-index: 10;
}
.bar__brand { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.bar__logo { height: 36px; width: auto; }
.bar__logo--white { display: none; }
.bar__label { font-family: var(--font-head); font-weight: 700; font-size: 1.15rem; color: var(--ultramarine); }
.bar__progress { flex: 1; display: flex; flex-direction: column; gap: 0.25rem; max-width: 22rem; margin-left: auto; color: var(--text-muted); font-size: 1rem; }
.bar__action { margin-left: auto; }
.bar__progress:not([hidden]) + .bar__action { margin-left: 0; }

progress {
  appearance: none; -webkit-appearance: none;
  width: 100%; height: 0.5rem; border: 0; border-radius: 1rem;
  background: var(--azure); overflow: hidden;
}
progress::-webkit-progress-bar { background: var(--azure); border-radius: 1rem; }
progress::-webkit-progress-value { background: var(--royal-blue); border-radius: 1rem; }
progress::-moz-progress-bar { background: var(--royal-blue); border-radius: 1rem; }

/* Personal-Bereich: farbige Kopfleiste, klar vom Patientenbereich getrennt */
.bar--staff { background: var(--ultramarine); border-bottom-color: var(--ultramarine); }
.bar--staff .bar__logo--color { display: none; }
.bar--staff .bar__logo--white { display: block; }
.bar--staff .bar__label { color: var(--white); text-transform: uppercase; letter-spacing: 0.08em; }
.bar--staff .btn--quiet { color: var(--white); border-color: var(--white); }

/* --- Banner (Netzfehler) --------------------------------------------------- */

.banner {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  margin: 1rem auto 0; width: min(100% - 2.5rem, var(--maxw));
  padding: 1rem 1.25rem; border-radius: var(--radius);
  background: var(--error-bg); color: var(--error); border: 2px solid var(--error);
}
.banner p { margin: 0; flex: 1 1 16rem; font-weight: 600; }
.banner p::before { content: "! "; font-weight: 800; }

/* --- Bildschirm ------------------------------------------------------------ */

.screen {
  flex: 1;
  width: min(100% - 2.5rem, var(--maxw));
  margin: 0 auto;
  padding: 2rem 0 calc(2rem + env(safe-area-inset-bottom));
  display: flex; flex-direction: column;
}
.screen:focus { outline: none; }

.center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 1rem; }
.logo-hero { width: min(18rem, 60vw); height: auto; margin-bottom: 1.5rem; }
.muted { color: var(--text-muted); }
.lead { font-size: 1.25rem; }
.big { font-size: 1.75rem; font-family: var(--font-head); color: var(--ultramarine); font-weight: 700; }

/* Dezentes Wellenmuster (Atemfluss) auf Start- und Abschlussbildschirm */
.waves {
  position: relative;
}
.waves::after {
  content: ""; position: fixed; left: 0; right: 0; bottom: 0; height: 9rem; z-index: -1; pointer-events: none;
  background:
    radial-gradient(120% 60% at 50% 120%, var(--azure) 60%, transparent 61%),
    radial-gradient(140% 70% at 30% 135%, var(--azure-50) 60%, transparent 61%);
}

.card {
  background: var(--white); border-radius: var(--radius);
  padding: 1.5rem; border: 1px solid var(--light-blue-grey);
}
.card--azure { background: var(--azure-50); border-color: var(--azure); }

/* --- Buttons --------------------------------------------------------------- */

.actions { display: flex; flex-wrap: wrap; gap: var(--gap); margin-top: 1.5rem; }
.actions--end { justify-content: flex-end; }
.actions--split { display: grid; grid-template-columns: 1fr 1fr; }
.actions--stack { flex-direction: column; }
.screen__footer { margin-top: auto; padding-top: 2rem; }

.btn {
  min-height: var(--touch); min-width: var(--touch);
  padding: 0.75rem 1.75rem;
  border-radius: 999px; border: 2px solid var(--ultramarine);
  font: inherit; font-weight: 700; font-size: 1.15rem; line-height: 1.2;
  cursor: pointer; touch-action: manipulation;
  display: inline-flex; align-items: center; justify-content: center; text-align: center;
}
.btn--primary { background: var(--ultramarine); color: var(--white); }
.btn--primary:active { background: var(--ultramarine-dark); }
.btn--secondary { background: var(--white); color: var(--ultramarine); }
.btn--secondary:active { background: var(--azure); }
.btn--quiet { background: transparent; color: var(--ultramarine); border-color: var(--light-blue-grey); font-size: 1rem; min-height: 3rem; padding: 0.5rem 1.25rem; }
.btn--large { min-height: 4.5rem; font-size: 1.35rem; padding: 1rem 2.5rem; }
.btn--wide { flex: 1 1 14rem; }
.btn[disabled], .btn[aria-busy="true"] { opacity: 0.6; cursor: progress; }

/* --- Formulare ------------------------------------------------------------- */

.field { margin: 0 0 1.75rem; border: 0; padding: 0; min-width: 0; }
.field > label, .field > legend {
  display: block; font-weight: 700; margin-bottom: 0.5rem; padding: 0; font-size: 1.15rem;
}
.field__hint { color: var(--text-muted); margin: -0.25rem 0 0.75rem; font-size: 1rem; }
.field--sub { margin-left: 1rem; padding-left: 1.25rem; border-left: 4px solid var(--azure); }

input[type="text"], input[type="password"], textarea {
  width: 100%; min-height: var(--touch);
  padding: 0.75rem 1rem; font: inherit; font-size: 1.25rem; color: var(--text);
  background: var(--white); border: 2px solid var(--light-blue-grey); border-radius: 0.75rem;
}
textarea { min-height: 8rem; resize: vertical; }
input:focus, textarea:focus { border-color: var(--royal-blue); outline: none; box-shadow: 0 0 0 3px var(--azure); }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--error); }
.input--short { max-width: 10rem; }
.inline-form { display: flex; gap: var(--gap); flex-wrap: wrap; align-items: stretch; }
.inline-form .input--code { flex: 0 1 14rem; text-align: left; }
.input--code { letter-spacing: 0.3em; font-size: 1.75rem; text-align: center; max-width: 14rem; }

.date-row { display: flex; gap: var(--gap); flex-wrap: wrap; }
.date-row > div { display: flex; flex-direction: column; }
.date-row label { font-weight: 400; color: var(--text-muted); font-size: 1rem; margin-bottom: 0.25rem; }
.date-row .dd, .date-row .mm { width: 5.5rem; }
.date-row .yyyy { width: 8rem; }

.field__label-static { font-weight: 700; margin: 0 0 0.25rem; font-size: 1.15rem; }
.spacer { height: 1.5rem; }
.readonly-value { font-size: 1.35rem; font-weight: 700; margin: 0; }

/* Auswahlfelder als große Touch-Ziele; echtes input bleibt für Bedienhilfen erhalten */
.choices { display: flex; flex-wrap: wrap; gap: var(--gap); }
.choices--column { flex-direction: column; }
.choice { position: relative; display: block; flex: 1 1 12rem; }
.choices--column .choice { flex: none; }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice > span {
  display: flex; align-items: center; gap: 0.75rem;
  min-height: var(--touch); padding: 0.75rem 1.25rem;
  border: 2px solid var(--light-blue-grey); border-radius: 0.75rem;
  background: var(--white); cursor: pointer; font-weight: 600;
}
.choice > span::before {
  content: ""; flex: none; width: 1.5rem; height: 1.5rem;
  border: 2px solid var(--ultramarine); border-radius: 50%; background: var(--white);
}
.choice > input[type="checkbox"] + span::before { border-radius: 0.35rem; }
.choice > input:checked + span { border-color: var(--ultramarine); background: var(--azure); }
.choice > input:checked + span::before {
  background: var(--ultramarine);
  box-shadow: inset 0 0 0 4px var(--white);
}
.choice > input[type="checkbox"]:checked + span::before {
  box-shadow: none;
  background:
    linear-gradient(45deg, transparent 45%, var(--white) 45%, var(--white) 58%, transparent 58%) 0.2rem 0.45rem / 0.55rem 0.55rem no-repeat,
    linear-gradient(-45deg, transparent 42%, var(--white) 42%, var(--white) 56%, transparent 56%) 0.45rem 0.2rem / 0.85rem 0.85rem no-repeat,
    var(--ultramarine);
}
.choice > input:focus-visible + span { outline: 3px solid var(--royal-blue); outline-offset: 2px; }
.field[aria-invalid="true"] .choice > span,
.choice > input[aria-invalid="true"] + span { border-color: var(--error); }

.error {
  color: var(--error); font-weight: 600; margin: 0.5rem 0 0; display: flex; gap: 0.5rem; align-items: flex-start;
}
.error::before {
  content: "!"; flex: none; display: inline-grid; place-items: center;
  width: 1.4rem; height: 1.4rem; border-radius: 50%;
  background: var(--error); color: var(--white); font-weight: 800; font-size: 0.95rem; line-height: 1;
}

/* --- Einwilligung ------------------------------------------------------------ */

.consent-section { margin: 0 0 1.75rem; }
.consent-section h2 { font-size: 1.35rem; margin-bottom: 0.4rem; }
.consent-section:first-child h2 { font-size: 1.75rem; }
.consent-confirm { margin-top: 1rem; }
.consent-confirm .choice > span::before { width: 2rem; height: 2rem; }
.consent-confirm .choice > span { font-weight: 500; align-items: flex-start; padding: 1rem 1.25rem; }
.consent-confirm .choice > input[type="checkbox"]:checked + span::before {
  background:
    linear-gradient(45deg, transparent 45%, var(--white) 45%, var(--white) 58%, transparent 58%) 0.3rem 0.6rem / 0.75rem 0.75rem no-repeat,
    linear-gradient(-45deg, transparent 42%, var(--white) 42%, var(--white) 56%, transparent 56%) 0.6rem 0.25rem / 1.15rem 1.15rem no-repeat,
    var(--ultramarine);
}
.required-hint { color: var(--text-muted); font-weight: 400; white-space: nowrap; }
.consent-confirm .choice > span { display: block; padding-left: 4rem; position: relative; }
.consent-confirm .choice > span::before { position: absolute; left: 1.25rem; top: 1rem; }

/* --- Personal --------------------------------------------------------------- */

.status {
  display: flex; align-items: center; gap: 1rem;
  padding: 1.25rem 1.5rem; border-radius: var(--radius); font-weight: 700; font-size: 1.35rem;
}
.status::before {
  content: ""; flex: none; width: 2.25rem; height: 2.25rem; border-radius: 50%;
}
.status--ok { background: var(--pale-turquoise); color: var(--ultramarine-dark); }
.status--ok::before {
  background:
    linear-gradient(45deg, transparent 45%, var(--white) 45%, var(--white) 58%, transparent 58%) 0.45rem 0.85rem / 0.75rem 0.75rem no-repeat,
    linear-gradient(-45deg, transparent 42%, var(--white) 42%, var(--white) 56%, transparent 56%) 0.8rem 0.4rem / 1.15rem 1.15rem no-repeat,
    var(--ultramarine);
}
.status--no { background: var(--error-bg); color: var(--error); }
.status--no::before { content: "!"; display: grid; place-items: center; background: var(--error); color: var(--white); font-size: 1.4rem; }

.card + .card, .status + .lead + .card { margin-top: 1rem; }
.code-display {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: clamp(1.75rem, 6vw, 2.75rem); letter-spacing: 0.08em; font-weight: 700;
  color: var(--ultramarine); margin: 0.25rem 0 0;
}

.table-wrap { overflow-x: auto; background: var(--white); border-radius: var(--radius); border: 1px solid var(--light-blue-grey); }
table.overview { width: 100%; border-collapse: collapse; font-size: 1.05rem; }
.overview th, .overview td { padding: 0.6rem 0.9rem; text-align: left; border-bottom: 1px solid var(--azure); white-space: nowrap; }
.overview th { color: var(--text-muted); font-weight: 600; font-size: 0.95rem; }
.overview tr:last-child td { border-bottom: 0; }
.overview .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; color: var(--ultramarine); font-weight: 700; }
.overview .ok::before { content: "✓ "; color: var(--ultramarine); font-weight: 800; }
.overview .warn { color: var(--error); font-weight: 600; }
.overview .warn::before { content: "! "; font-weight: 800; }
.overview .btn--quiet { min-height: 2.75rem; }
.overview .row-actions { display: flex; flex-direction: column; align-items: stretch; gap: 0.5rem; }
.overview td:first-child { white-space: normal; min-width: 5.5rem; }
@media (max-width: 820px) {
  .overview th, .overview td { padding: 0.5rem 0.6rem; font-size: 0.98rem; }
}
.overview .test { color: var(--text-muted); font-weight: 700; }
.btn--danger { color: var(--error); border-color: var(--error); }
.status--test { background: var(--light-blue-grey); color: var(--text); }
.status--test::before { content: "T"; display: grid; place-items: center; background: var(--text-muted); color: var(--white); font-weight: 800; }
.banner--info { background: var(--azure); color: var(--ultramarine-dark); border-color: var(--ultramarine); }
.banner--info p::before { content: "✓ "; }
.status + .muted, .table-wrap + .status { margin-top: 1rem; }

/* --- Overlay (Inaktivität, Abbruch) ---------------------------------------- */

.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(28, 23, 72, 0.55);
  display: grid; place-items: center; padding: 1.25rem;
}
.overlay__box {
  background: var(--white); border-radius: var(--radius); padding: 2rem;
  width: min(100%, 34rem); box-shadow: 0 1rem 3rem rgba(28, 23, 72, 0.25);
}
.overlay__box .actions { flex-direction: column; }

/* --- Einrichtung ---------------------------------------------------------- */

.setup { max-width: 34rem; margin: 2rem auto; }

/* --- Querformat / große Tablets ------------------------------------------- */

@media (min-width: 900px) and (orientation: landscape) {
  .screen { padding-top: 2.5rem; }
  h1 { font-size: 2.25rem; }
}

@media (max-width: 560px) {
  .actions--split { grid-template-columns: 1fr; }
  h1 { font-size: 1.65rem; }
}

@media (prefers-reduced-motion: no-preference) {
  .screen > * { animation: fade-in 180ms ease-out; }
  @keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}
