/*
 * Küche und Super-Admin: die Arbeitsoberflächen nach der Struktur der UI-Regeln
 * (/Users/lars/AI-Workspace/reference/workflows/ui-gestaltungsregeln.md) mit Salbei als Akzent
 * (docs/gestaltung/oberflaechen.md, farben-und-themes.md, schrift.md).
 *
 * Aufbau nach den UI-Regeln (T1 bis T4): erst die Rollen je Thema, dann die Bausteine, die nur Rollen verwenden.
 * Hell und dunkel folgen allein der Einstellung des Geräts (DARST-30); eine eigene Wahl gibt es nicht,
 * deshalb fehlt der Schalter [data-theme] der UI-Regeln.
 * Abweichend von den UI-Regeln gilt WCAG 2.2 AA ohne deren benannte Ausnahmen (J4): Ränder von Bedienelementen
 * haben mindestens 3 : 1 (--line-control), gedämpfter Text auf dem App-Rahmen nimmt --text-muted-strong.
 */

/* ===== Rollen, Thema hell ===== */
:root {
  color-scheme: light dark;

  /* Graufamilie zinc aus Tailwind 4.3.3, wie in den UI-Regeln */
  --n-50: oklch(98.5% 0 0);
  --n-100: oklch(96.7% 0.001 286.375);
  --n-300: oklch(87.1% 0.006 286.286);
  --n-400: oklch(70.5% 0.015 286.067);
  --n-500: oklch(55.2% 0.016 285.938);
  --n-600: oklch(44.2% 0.017 285.786);
  --n-800: oklch(27.4% 0.006 286.033);
  --n-900: oklch(21% 0.006 285.885);
  --n-950: oklch(14.1% 0.005 285.823);

  /* Tinte: daraus werden Linien und Hover-Flächen gemischt (G5) */
  --ink: var(--n-950);

  /* Flächen (C1) */
  --bg: #ffffff;
  --bg-subtle: var(--n-50);
  --bg-muted: var(--n-100);
  --surface: #ffffff;
  --field-bg: #ffffff;

  /* Schrift */
  --text: var(--n-950);
  --text-muted: var(--n-500);
  --text-muted-strong: var(--n-600);

  /* Linien und Hover-Flächen aus Tinte */
  --line-subtle: color-mix(in oklab, var(--ink) 5%, transparent);
  --line: color-mix(in oklab, var(--ink) 10%, transparent);
  --line-strong: color-mix(in oklab, var(--ink) 20%, transparent);
  --line-control: color-mix(in oklab, var(--ink) 45%, transparent);
  --hover: color-mix(in oklab, var(--ink) 5%, transparent);
  --hover-row: color-mix(in oklab, var(--ink) 2.5%, transparent);
  --ring-panel: color-mix(in oklab, var(--ink) 5%, transparent);

  /* Akzent Salbei (G1) */
  --accent: var(--sage-600);
  --accent-text: var(--sage-600);
  --focus: var(--sage-500);
  --primary-bg: var(--sage-600);
  --primary-border: color-mix(in oklab, var(--sage-700) 90%, transparent);
  --primary-hover: rgb(255 255 255 / 0.1);
  --primary-press: rgb(0 0 0 / 0.12);
  --on-primary: #ffffff;
  --control-on: var(--sage-600);
  --indicator: var(--sage-600);
  --selected: color-mix(in oklab, var(--sage-500) 12%, transparent);

  /* Gefahr und Fehler, Tailwind red */
  --danger: oklch(57.7% 0.245 27.325);
  --danger-border: oklch(50.5% 0.213 27.518 / 0.9);
  --danger-text: oklch(57.7% 0.245 27.325);
  --invalid: oklch(63.7% 0.237 25.331);

  /* Ton Grau für Plakette und Avatar, nach der Formel aus Abschnitt 4 der UI-Regeln (G6) */
  --tone-gray-badge-bg: color-mix(in oklab, var(--n-400) 20%, transparent);
  --tone-gray-badge-text: var(--n-800);

  /* Tiefe (C2) */
  --backdrop: color-mix(in oklab, var(--n-950) 25%, transparent);
  --shadow-ctl: var(--shadow-xs);
  --highlight: inset 0 1px 0 rgb(255 255 255 / 0.15);

  /* Schriftrollen (docs/gestaltung/schrift.md, Küche und Super-Admin) */
  --font-sans: var(--font-ui);
  --font-display: var(--font-text);
  --font-mono: var(--font-ui);

  /* Maße der Schale */
  --sidebar-width: 16rem;
  --icon-size: 1rem;
}

/* ===== Rollen, Thema dunkel: nur über das Gerät (DARST-30, G4) ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #ffffff;

    --bg: var(--n-900);
    --bg-subtle: color-mix(in oklab, #ffffff 4%, var(--n-900));
    --bg-muted: var(--n-950);
    --surface: var(--n-800);
    --field-bg: rgb(255 255 255 / 0.05);

    --text: #ffffff;
    --text-muted: var(--n-400);
    --text-muted-strong: var(--n-400);

    --ring-panel: color-mix(in oklab, var(--ink) 10%, transparent);

    --accent: var(--sage-500);
    --accent-text: var(--sage-400);
    --indicator: var(--sage-500);

    --danger-text: oklch(70.4% 0.191 22.216);

    --tone-gray-badge-bg: color-mix(in oklab, var(--n-400) 10%, transparent);
    --tone-gray-badge-text: var(--n-300);

    --backdrop: color-mix(in oklab, var(--n-950) 60%, transparent);
    --shadow-ctl: 0 0 #0000;
  }
}

/* Auf Touch-Geräten wachsen Bedienelemente auf 44 px, Schrift auf 16 px, Symbole auf 20 px (H1) */
@media (pointer: coarse) {
  :root {
    --icon-size: 1.25rem;
  }
}

/* ===== Grundlage ===== */
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: 1.5rem;
}

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

/* Was mit hidden verborgen ist, bleibt verborgen, auch wenn ein Baustein display setzt */
[hidden] {
  display: none !important;
}

:where(a, button):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Text nur für Screenreader, etwa die Beschriftung eines Symbolknopfs */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ===== Atom: Symbol ===== */
.icon {
  width: var(--icon-size);
  height: var(--icon-size);
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ===== Atom: Bildmarke auf Salbei, Logo der Seitenleiste (docs/gestaltung/marke.md) ===== */
.brand-tile {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  flex: none;
  border-radius: var(--radius-lg);
  background: var(--primary-bg);
  color: var(--on-primary);
  box-shadow: var(--highlight);
}

.brand-tile .brand-mark {
  width: 1.375rem;
  height: 1.375rem;
}

/* ===== Vorlage: App-Schale (6.4) ===== */
/* Auf dem Handy eine Spalte: Inhalt, darunter die Leiste unten, die am unteren Rand haftet (sticky statt fixed,
   damit sie mitwächst, wenn eine Beschriftung umbricht, etwa bei größerer Schrift des Browsers) */
.shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  background: var(--bg);
}

.shell-side {
  display: none;
}

.shell-main {
  flex: 1;
  min-width: 0;
  background: var(--bg);
}

@media (min-width: 64rem) {
  .shell {
    flex-direction: row;
    align-items: stretch;
    background: var(--bg-muted);
  }

  .shell-side {
    display: flex;
    flex: none;
    width: var(--sidebar-width);
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
  }

  .shell-main {
    flex: 1;
    min-height: calc(100vh - 1rem);
    min-height: calc(100dvh - 1rem);
    margin: 0.5rem 0.5rem 0.5rem 0;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-ctl), 0 0 0 1px var(--ring-panel);
    overflow: clip;
  }
}

/* Inhalt einer Seite: höchstens 64 rem breit, Rand 16, 24 und 40 px (Richtmaße 6.4) */
.page {
  display: grid;
  align-content: start;
  gap: 2rem;
  max-width: 64rem;
  margin-inline: auto;
  padding: 2rem 1rem 4rem;
}

@media (min-width: 40rem) {
  .page {
    padding-inline: 1.5rem;
  }
}

@media (min-width: 64rem) {
  .page {
    padding: 2.5rem 2.5rem 5rem;
  }
}

/* ===== Organismus: Seitenleiste (6.3) ===== */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  width: 100%;
  padding: 1rem;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.25rem 0.5rem;
}

.sidebar-brand-text {
  display: grid;
}

.sidebar-brand .wordmark {
  color: var(--accent-text);
  font-size: var(--text-sm);
  line-height: var(--text-sm-lh);
}

.sidebar-brand-surface {
  font-size: var(--text-xs);
  line-height: var(--text-xs-lh);
  color: var(--text-muted-strong);
}

.nav-list {
  display: grid;
  gap: 2px;
  padding: 0;
  list-style: none;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  line-height: var(--text-sm-lh);
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  transition: background-color var(--duration) var(--ease-out);
}

.nav-item .icon {
  color: var(--text-muted);
}

a.nav-item[href]:hover,
.nav-item[aria-current="page"] {
  background: var(--hover);
}

a.nav-item[href]:hover .icon,
.nav-item[aria-current="page"] .icon {
  color: var(--text);
}

/* Strich am aktuellen Eintrag, am Rand der Seitenleiste (K4, J2) */
.nav-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -1rem;
  top: 0.5rem;
  bottom: 0.5rem;
  width: 2px;
  border-radius: var(--radius-full);
  background: var(--indicator);
}

@media (pointer: coarse) {
  .nav-item {
    padding-block: 0.625rem;
    font-size: var(--text-base);
    line-height: 1.5rem;
  }
}

/* ===== Molekül: Nutzerbereich (Pattern Library, Seitenleiste) ===== */
/* Ab 1024 px unten in der Seitenleiste, auf dem Handy unter dem Inhalt, über der Leiste unten */
.user-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 0.5rem 0.5rem;
  border-top: 1px solid var(--line-subtle);
}

.sidebar .user-area {
  margin-top: auto;
}

.user-area-text {
  display: grid;
  flex: 1;
  min-width: 0;
}

.user-area-name {
  font-weight: 500;
  line-height: 1.25rem;
}

.user-area-detail {
  font-size: var(--text-xs);
  line-height: var(--text-xs-lh);
  color: var(--text-muted-strong);
  overflow-wrap: anywhere;
}

/* Der Knopf ist schlicht; er rückt an den Rand, damit die Adresse in der Unterzeile Platz hat */
.user-area .icon-button {
  margin-right: -0.5rem;
}

.shell-user {
  padding: 0 1rem 0.5rem;
}

.shell-user .user-area {
  padding-inline: 0;
}

@media (min-width: 40rem) {
  .shell-user {
    padding-inline: 1.5rem;
  }
}

@media (min-width: 64rem) {
  .shell-user {
    display: none;
  }
}

/* ===== Organismus: Leiste unten auf dem Handy (docs/gestaltung/oberflaechen.md) ===== */
.tabbar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  padding: 0.375rem 0.5rem calc(0.375rem + env(safe-area-inset-bottom));
  background: var(--bg);
  box-shadow: inset 0 1px 0 var(--line);
}

.tabbar-list {
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Alle Einträge so hoch wie der höchste, auch wenn nur eine Beschriftung umbricht */
.tabbar-list > li {
  display: flex;
}

.tabbar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  min-height: 3.25rem;
  padding: 0.25rem 0.125rem;
  border-radius: var(--radius-lg);
  font-size: var(--text-xs);
  line-height: var(--text-xs-lh);
  font-weight: 500;
  color: var(--text-muted);
  text-align: center;
  text-decoration: none;
  transition: background-color var(--duration) var(--ease-out);
}

.tabbar-item .icon {
  width: 1.25rem;
  height: 1.25rem;
}

/* Lange Beschriftungen brechen mit Silbentrennung um, statt über die Nachbarn zu laufen (UI-Regeln, Abschnitt 8) */
.tabbar-item span {
  max-width: 100%;
  -webkit-hyphens: auto;
  hyphens: auto;
  overflow-wrap: anywhere;
}

a.tabbar-item[href]:hover {
  background: var(--hover);
}

.tabbar-item[aria-current="page"] {
  background: var(--selected);
  color: var(--accent-text);
  font-weight: 600;
}

@media (min-width: 64rem) {
  .tabbar {
    display: none;
  }
}

/* Bereiche, die es noch nicht gibt, sind sichtbar, aber nicht bedienbar (K4, deaktiviert) */
.nav-item[aria-disabled="true"],
.tabbar-item[aria-disabled="true"] {
  opacity: 0.5;
  cursor: default;
}

/* ===== Vorlage: Seitenkopf (A1, A2, A4) ===== */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem 1.5rem;
}

.page-head-main {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
  max-width: 42rem;
}

.page-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  line-height: var(--text-2xl-lh);
  font-weight: 600;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

/* ===== Organismus: leerer Zustand (6.3) ===== */
.empty-state {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  padding: 3rem 1.5rem;
  text-align: center;
}

.empty-state-icon {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border-radius: var(--radius-full);
  background: var(--hover);
  color: var(--text-muted);
}

.empty-state-icon .icon {
  width: 1.5rem;
  height: 1.5rem;
}

.empty-state-title {
  margin-top: 0.5rem;
  font-size: var(--text-sm);
  line-height: var(--text-sm-lh);
  font-weight: 600;
}

/* Fließtext, der erklärt, steht in Nunito 400 (docs/gestaltung/schrift.md) */
.empty-state-text {
  max-width: 22rem;
  font-family: var(--font-text);
  color: var(--text-muted);
}

/* ===== Vorlage: Anmeldung (docs/gestaltung/marke.md, „Kopf der Anmeldung“) ===== */
/* Oben der Kopf mit schattierter Bildmarke und Tellerringen in festen Farben, darunter ein Blatt mit einer Aufgabe. */
.auth {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.auth-head {
  position: relative;
  overflow: hidden;
  height: 18.75rem;
  flex: none;
  padding: 4rem 1.5rem 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  background: var(--brand-soft);
  color: var(--sage-700);
}

.auth-rings {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.auth-brand {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.125rem;
}

.auth-mark {
  position: relative;
  width: 7rem;
  height: 7rem;
}

.auth-brand .wordmark {
  font-size: var(--text-3xl);
  line-height: var(--text-3xl-lh);
}

.auth-surface {
  font-weight: 500;
}

.auth-sheet {
  position: relative;
  flex: 1;
  margin-top: -1rem;
  padding: 2rem 1.5rem;
  border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
  background: var(--bg);
}

.auth-content {
  display: grid;
  gap: 1.5rem;
  max-width: 24rem;
  margin: 0 auto;
}

.auth-intro {
  display: grid;
  gap: 0.375rem;
}

.auth-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  line-height: var(--text-2xl-lh);
  font-weight: 600;
  letter-spacing: -0.025em;
}

.auth-step {
  font-weight: 500;
  color: var(--text-muted-strong);
}

/* Fließtext, der erklärt, steht in Nunito 400 (docs/gestaltung/schrift.md) */
.auth-text {
  font-family: var(--font-text);
  color: var(--text-muted-strong);
}

.auth-form {
  display: grid;
  gap: 1.5rem;
}

/* ===== Atom: Knopf (6.1), groß und auf ganzer Breite in der Anmeldung ===== */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.625rem 0.875rem;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--duration) var(--ease-out);
}

.button-primary {
  background: var(--primary-bg);
  border-color: var(--primary-border);
  color: var(--on-primary);
  box-shadow: var(--highlight), var(--shadow-ctl);
}

.button-primary:hover {
  background-image: linear-gradient(var(--primary-hover), var(--primary-hover));
}

.button-primary:active {
  background-image: linear-gradient(var(--primary-press), var(--primary-press));
}

.auth .button {
  width: 100%;
}

/* ===== Atom: Symbolknopf, schlicht (6.1): quadratisch 36 / 44 px, ohne Fläche und Rand ===== */
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  flex: none;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color var(--duration) var(--ease-out);
}

.icon-button:hover {
  background: var(--hover);
  color: var(--text);
}

@media (pointer: coarse) {
  .icon-button {
    width: 2.75rem;
    height: 2.75rem;
  }
}

/* ===== Atom: Avatar (6.1): 32 px, Initiale in 40 % der Größe, grau nach der Formel der Plakette ===== */
.avatar {
  display: inline-grid;
  place-content: center;
  width: 2rem;
  height: 2rem;
  flex: none;
  border-radius: var(--radius-full);
  background: var(--tone-gray-badge-bg);
  color: var(--tone-gray-badge-text);
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 0.8rem;
  line-height: 1;
  font-weight: 500;
}

/* ===== Molekül: Formularfeld (6.2) ===== */
.form-field {
  display: grid;
  gap: 0.5rem;
}

.field-label {
  font-weight: 500;
}

/* Rand mit 3 : 1 gegen den Grund (WCAG 2.2, 1.4.11), ohne die Ausnahme der UI-Regeln */
.field-input {
  width: 100%;
  height: 2.25rem;
  padding: 0 0.75rem;
  border: 1px solid var(--line-control);
  border-radius: var(--radius-lg);
  background: var(--field-bg);
  box-shadow: var(--shadow-ctl);
}

.field-input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

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

/* Codes in Atkinson mit gleich breiten Ziffern und etwas Luft, damit sie sich leicht abgleichen lassen */
.field-code {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.2em;
}

@media (pointer: coarse) {
  .field-input {
    height: 2.75rem;
    font-size: var(--text-base);
  }
}

/* Fehlermeldung mit Symbol (J2) */
.field-error {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  color: var(--danger-text);
}

.field-error .icon {
  margin-top: 0.25rem;
}

/* ===== Hinweis im Inhalt (6.3) ===== */
.notice {
  padding: 1rem;
  border-radius: var(--radius-lg);
  background: var(--selected);
  font-family: var(--font-text);
}

/* ===== Einrichtung des Super-Admins ===== */
/* Der QR-Code steht in beiden Themen auf Weiß, weil Kameras ihn sonst schlecht lesen. */
.setup-qr {
  justify-self: center;
  padding: 0.75rem;
  border-radius: var(--radius-lg);
  background: #ffffff;
  box-shadow: 0 0 0 1px var(--line);
  line-height: 0;
}

.setup-secret {
  font-size: var(--text-base);
  letter-spacing: 0.05em;
  word-spacing: 0.25em;
  user-select: all;
  overflow-wrap: anywhere;
}
