/* ============================================================================
   tokens.css — die gemeinsame Basis aller H.U.G.I.N-Designs
   ----------------------------------------------------------------------------
   Diese Datei ändert sich NICHT, wenn ein neues Design dazukommt.
   Sie enthält:
     1. den Token-Vertrag  (:root — alle Namen mit sicheren Rückfallwerten)
     2. die Komponenten-Schicht (Elemente + wenige Klassen, alles über var())

   Ladereihenfolge in jeder Seite:
       <link rel="stylesheet" href="/web/tokens.css">
       <link rel="stylesheet" href="/web/designs/<gewaehlt>.css">

   Ein Design darf ausschließlich Token-Werte setzen (und höchstens eine
   Handvoll variantenspezifische Regeln). Wer hier unten Regeln ändert,
   ändert sie für ALLE Designs — das ist die Grenze.
   Vollständige Bauanleitung: DESIGN.md
   ========================================================================== */

:root {
  /* --- Grundflächen ------------------------------------------------------ */
  --color-bg: #161826;              /* Seitengrund */
  --color-surface: #232532;         /* Karten, Eingabefelder, Tabellenkopf */
  --color-surface-2: #14161f;       /* Leisten: header, nav, footer */
  --color-text: #e9e9ed;            /* Textfarbe */
  --color-text-muted: #9397ab;      /* Zweitrangiger Text, Spaltenköpfe */
  --color-text-faint: #75798c;      /* Fußnoten, Hilfstexte */
  --color-divider: rgba(233,233,237,0.16); /* Linien und Rahmen */

  /* --- Akzent (genau EINER; Zweitakzent nur wenn das Design ihn braucht) - */
  --color-accent: #9184d9;
  --color-accent-tint: rgba(145,132,217,0.12);  /* Hover-Fläche */
  --color-accent-tint-2: rgba(145,132,217,0.22); /* gedrückt */
  --color-accent-deep: #2b2741;     /* Fläche für Akzent-Text */
  --color-accent-on-deep: #d2cefd;  /* Text auf --color-accent-deep */
  --color-on-accent: #161826;       /* Text auf gefüllter Akzentfläche */

  /* --- Zustandsfarben (Pflicht in jedem Design, Auftrag D1 Regel 5) ------ */
  --color-ok: #6fbf8e;              /* laeuft, bestanden, zugestellt */
  --color-warn: #d5a75f;            /* startet, veraltet, Warteschlange */
  --color-error: #dd7d72;           /* Fehler, nicht erreichbar, verweigert */
  --color-off: #9397ab;             /* gestoppt, einschaltbar, kein Wert */
  --color-mock-bg: #423a6a;         /* Untergrund von <mark> (Mock/Hinweis) */
  --color-mock-text: #e7e5fe;

  /* --- Schrift ----------------------------------------------------------- */
  /* Selbst gehostet oder Systemschrift — NIE ein CDN (Regel 4).
     Optionales @font-face steht im Design, nicht hier. */
  --font-body: system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-heading: var(--font-body);
  --font-mono: ui-monospace, "Cascadia Mono", "Consolas", monospace;
  --font-heading-weight: 500;
  --font-body-weight: 400;

  --text-xs: 11px;   /* Marken, Fußnoten, Spaltenköpfe */
  --text-sm: 12px;   /* Hilfstext, Tabellen-Nebenzeile */
  --text-md: 13px;   /* Bedienelemente */
  --text-base: 14px; /* Tabellen, Formulare */
  --text-lg: 16px;   /* Seitentitel in der Leiste */
  --text-xl: 20px;   /* h3 */
  --text-2xl: 25px;  /* h2 — Seitentitel */
  --text-3xl: 32px;  /* h1 */
  --leading: 1.55;
  --leading-tight: 1.15;
  --tracking-caps: 0.09em;  /* für Kapitälchen-Köpfe */

  /* --- Abstände (eine Skala, nichts dazwischen) -------------------------- */
  --space-1: 3px;
  --space-2: 6px;
  --space-3: 9px;
  --space-4: 12px;
  --space-6: 17px;
  --space-8: 23px;
  --space-12: 34px;

  /* --- Radien und Erhebung ---------------------------------------------- */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;
  --radius-pill: 999px;
  --shadow-sm: 0 0 0 1px #3f424d;
  --shadow-md: 0 0 0 1px #595d6c, 0 6px 18px rgba(0,0,0,0.55);
  --shadow-lg: 0 0 0 1px #9397ab, 0 16px 40px rgba(0,0,0,0.65);

  /* --- Chrome ------------------------------------------------------------ */
  --inhalt-breite: 1240px;          /* Maximalbreite von <main> */
  --leiste-breite: 246px;           /* Seitenleiste in Ausbaustufe 2 */
  /* Linien laufen an den Enden aus (Nocturne-Signatur). Ein Design, das
     durchgezogene Linien will, setzt: --rule: var(--color-divider); */
  --rule: linear-gradient(to right, transparent, var(--color-divider) 48px,
          var(--color-divider) calc(100% - 48px), transparent);
  --focus-ring: 2px solid var(--color-accent);
}

/* ==========================================================================
   1. Grundlagen
   ========================================================================== */

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

html, body { margin: 0; }

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--font-body-weight);
  line-height: var(--leading);
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: var(--font-heading-weight);
  line-height: var(--leading-tight);
  margin: 0 0 var(--space-3);
  letter-spacing: -0.01em;
}
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-base); }
h6 {
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

p { margin: 0 0 var(--space-3); text-wrap: pretty; }
small, .klein { font-size: var(--text-sm); color: var(--color-text-faint); }
code, kbd, samp, .wert { font-family: var(--font-mono); font-size: 0.92em; }
a { color: var(--color-accent); text-underline-offset: 3px; }
a:hover { color: var(--color-accent-on-deep); }
hr {
  height: 1px; border: 0; margin: var(--space-6) 0;
  background: var(--rule);
}
:focus { outline: none; }
:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }
::selection { background: var(--color-accent-tint-2); }

/* Mock-/Hinweis-Auszeichnung — P5/P10-Anker, MUSS erkennbar bleiben */
mark {
  background: var(--color-mock-bg);
  color: var(--color-mock-text);
  padding: 1px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
}

/* ==========================================================================
   2. Gerüst: header / nav / main / footer
   Das Skelett liefert diese Elemente ohne Klassen — hier werden sie gestaltet.
   ========================================================================== */

body > header {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-8);
  background: var(--color-surface-2);
  border-bottom: 1px solid var(--color-divider);
}
body > header > h1 {
  font-size: var(--text-lg);
  margin: 0; margin-right: auto;
  white-space: nowrap;
}

/* Dauerhafter Hinweis „ohne Anmeldung" (P5-Anker) — dezent, aber sichtbar */
.heimdall-hinweis {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-warn);
  border: 1px solid var(--color-warn);
  border-radius: var(--radius-md);
  background: transparent;
}
.heimdall-hinweis::before { content: "●"; font-size: 8px; }

body > header > nav, body > nav {
  display: flex; flex-wrap: wrap; gap: var(--space-1);
  width: 100%;
}
body > header > nav a, body > nav a {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  color: var(--color-text-muted);
  text-decoration: none;
}
body > header > nav a:hover, body > nav a:hover {
  background: var(--color-accent-tint);
  color: var(--color-text);
}
body > header > nav a[aria-current], body > nav a[aria-current] {
  background: var(--color-accent-deep);
  color: var(--color-accent-on-deep);
  box-shadow: inset 0 0 0 1px var(--color-accent);
}

main {
  display: block;
  max-width: var(--inhalt-breite);
  padding: var(--space-8) var(--space-8) var(--space-12);
}
main > h2 { margin-bottom: var(--space-6); }
main > section { margin: 0 0 var(--space-12); }
main > section > h3 { margin-bottom: var(--space-4); }

body > footer {
  padding: var(--space-6) var(--space-8);
  border-top: 1px solid var(--color-divider);
  background: var(--color-surface-2);
  color: var(--color-text-faint);
  font-size: var(--text-sm);
}

/* Ausbaustufe 2 (optional, braucht einen Wrapper in oberflaeche.py):
   <div class="flaeche"><nav>…</nav><main>…</main></div>  → Seitenleiste links */
.flaeche { display: flex; align-items: flex-start; min-height: 100vh; }
.flaeche > nav {
  width: var(--leiste-breite); flex: none;
  position: sticky; top: 0;
  display: flex; flex-direction: column; gap: var(--space-1);
  padding: var(--space-4) var(--space-3);
  background: var(--color-surface-2);
  border-right: 1px solid var(--color-divider);
}
.flaeche > nav a { width: 100%; }
.flaeche > main { flex: 1; min-width: 0; }

/* ==========================================================================
   3. Meldungen (P5-Anker: .meldung / .fehler)
   ========================================================================== */

.meldung, .fehler {
  margin: 0 0 var(--space-6);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  display: flex; gap: var(--space-3); align-items: flex-start;
}
.meldung {
  background: color-mix(in srgb, var(--color-ok) 16%, transparent);
  color: var(--color-ok);
}
.fehler {
  background: color-mix(in srgb, var(--color-error) 16%, transparent);
  color: var(--color-error);
}
.meldung::before { content: "✓"; }
.fehler::before  { content: "!"; font-weight: 700; }
.fehler ul, .meldung ul { margin: var(--space-2) 0 0; padding-left: var(--space-6); }

/* ==========================================================================
   4. Tabellen — das Herz der Fläche
   ========================================================================== */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-base);
}
caption {
  text-align: left;
  padding: var(--space-2) var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}
th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  font-weight: var(--font-heading-weight);
  color: var(--color-text-muted);
  white-space: nowrap;
}
td {
  padding: var(--space-3);
  vertical-align: top;
}
thead tr { background: var(--rule) no-repeat bottom / 100% 1px; }
tbody tr { background: var(--rule) no-repeat bottom / 100% 1px; }
tbody tr:hover {
  background:
    linear-gradient(color-mix(in srgb, var(--color-text) 4%, transparent),
                    color-mix(in srgb, var(--color-text) 4%, transparent))
      no-repeat 0 0 / 100% 100%,
    var(--rule) no-repeat bottom / 100% 1px;
}
/* Zahlen bündig: jede Zelle mit numerischem Inhalt bekommt data-zahl */
td[data-zahl], th[data-zahl] {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Zustands-Anker (P5/P10): data-zustand am <td> oder <span> */
[data-zustand] {
  display: inline-flex; align-items: center; gap: var(--space-2);
  white-space: nowrap;
  font-size: var(--text-md);
}
[data-zustand]::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex: none;
}
[data-zustand="laeuft"]   { color: var(--color-ok); }
[data-zustand="startet"]  { color: var(--color-warn); }
[data-zustand="gestoert"] { color: var(--color-warn); }
[data-zustand="veraltet"] { color: var(--color-warn); }
[data-zustand="fehler"]   { color: var(--color-error); }
[data-zustand="gestoppt"] { color: var(--color-off); }
[data-zustand="neu"]      { color: var(--color-off); }

/* Tabellen bleiben bis 380 px bedienbar: Wrapper um jede breite Tabelle */
.tabelle-scroll { overflow-x: auto; }

/* ==========================================================================
   5. Formulare und Bedienelemente
   ========================================================================== */

label { display: block; font-size: var(--text-sm); color: var(--color-text-muted); margin-bottom: var(--space-1); }

input[type="text"], input[type="number"], input[type="password"],
input[type="email"], input[type="search"], select, textarea {
  width: 100%;
  min-height: 36px;
  padding: var(--space-2) var(--space-3);
  font: inherit;
  font-size: var(--text-base);
  color: var(--color-text);
  caret-color: var(--color-accent);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
}
textarea { min-height: 90px; resize: vertical; }
input:hover, select:hover, textarea:hover {
  border-color: color-mix(in srgb, var(--color-text) 45%, transparent);
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--color-accent);
  outline: var(--focus-ring); outline-offset: 0;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--color-accent); width: auto; min-height: 0; }
:disabled { opacity: 0.45; cursor: not-allowed; }

/* Feldgruppe für generierte Masken (Manifest-Einstellungen) */
.feld { margin-bottom: var(--space-4); max-width: 420px; }
.feld small { display: block; margin-top: var(--space-1); }
.felder { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-4); }

button, .knopf {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2);
  min-height: 34px;
  padding: var(--space-2) var(--space-4);
  font-family: var(--font-heading);
  font-weight: var(--font-heading-weight);
  font-size: var(--text-md);
  line-height: 1.2;
  color: var(--color-text);
  background: transparent;
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
}
button:hover, .knopf:hover { background: color-mix(in srgb, var(--color-text) 7%, transparent); }
button:active, .knopf:active { background: color-mix(in srgb, var(--color-text) 14%, transparent); }

/* Hauptaktion. Ob Umriss oder Füllung ist Sache des Designs:
   ein Design, das füllt, setzt die drei Zeilen in seiner eigenen Datei um. */
button.haupt, .knopf.haupt {
  color: var(--color-accent);
  border-color: var(--color-accent);
}
button.haupt:hover, .knopf.haupt:hover { background: var(--color-accent-tint); }
button.haupt:active, .knopf.haupt:active { background: var(--color-accent-tint-2); }

button.leise, .knopf.leise { border-color: transparent; color: var(--color-accent); }
button.leise:hover { background: var(--color-accent-tint); }
button.gefahr { color: var(--color-error); border-color: var(--color-error); }
button.gefahr:hover { background: color-mix(in srgb, var(--color-error) 14%, transparent); }

/* Aktions-Knöpfe des Skeletts: form.inline + button (P5-Anker) */
form.inline { display: inline-flex; gap: var(--space-2); margin: 0; align-items: center; }
form.inline + form.inline { margin-left: var(--space-2); }

/* Knopfzeile */
.aktionen { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }

/* AN/AUS-Schalter der Audit-Seite. AUS heißt „einschaltbar", nicht „abgeschaltet". */
.schalter { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-md); }
.schalter[data-an="1"] { color: var(--color-ok); }
.schalter[data-an="0"] { color: var(--color-off); }
.schalter::before {
  content: ""; width: 30px; height: 17px; flex: none;
  border-radius: var(--radius-pill);
  background: currentColor;
  opacity: 0.35;
}
.schalter[data-an="1"]::before { opacity: 1; }

/* ==========================================================================
   6. Karten, Steckbriefe, Kennzahlen, Marken
   ========================================================================== */

.karte {
  display: flex; flex-direction: column; gap: var(--space-2);
  padding: var(--space-4);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.karten { display: grid; grid-template-columns: repeat(auto-fit, minmax(268px, 1fr)); gap: var(--space-4); }
.karte > h3, .karte > h4 { margin: 0; }
.karte > p { margin: 0; font-size: var(--text-md); color: var(--color-text-muted); }

/* AppStore-Steckbrief: <dl> mit <dt>/<dd>-Paaren (P5-Struktur) */
dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: var(--space-1) var(--space-4); font-size: var(--text-sm); }
dt { color: var(--color-text-faint); }
dd { margin: 0; color: var(--color-text); }

.kennzahlen { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-4); }
.kennzahl { display: flex; flex-direction: column; gap: var(--space-1); padding: var(--space-4); background: var(--color-surface); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); }
.kennzahl > .titel { font-size: var(--text-xs); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--color-text-faint); }
.kennzahl > .wert { font-family: var(--font-heading); font-size: var(--text-2xl); line-height: 1.1; }
.kennzahl > small { margin: 0; }

/* Marke / Etikett */
.marke {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  background: var(--color-accent-deep);
  color: var(--color-accent-on-deep);
  white-space: nowrap;
}
.marke.umriss { background: transparent; border: 1px solid var(--color-accent); color: var(--color-accent); }
.marke.neutral { background: color-mix(in srgb, var(--color-text) 12%, transparent); color: var(--color-text); }

/* Auslastungsbalken (Telemetrie) */
.balken { height: 5px; border-radius: var(--radius-pill); background: color-mix(in srgb, var(--color-text) 12%, transparent); overflow: hidden; min-width: 60px; }
.balken > span { display: block; height: 100%; background: var(--color-accent); }
.balken[data-hoch="1"] > span { background: var(--color-warn); }

/* Schrittfolge (Registrierungs-Fragereihe) */
.schritte { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-6); padding: 0; list-style: none; }
.schritte > li { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-4); border: 1px solid var(--color-divider); border-radius: var(--radius-md); font-size: var(--text-md); color: var(--color-text-faint); }
.schritte > li[aria-current] { border-color: var(--color-accent); color: var(--color-accent); }

/* ==========================================================================
   7. Handy bis ~380 px (Skidbladnir) — ohne JavaScript
   ========================================================================== */

@media (max-width: 720px) {
  :root { --inhalt-breite: 100%; }
  body > header { padding: var(--space-3) var(--space-4); gap: var(--space-2); }
  body > header > h1 { font-size: var(--text-base); }
  main { padding: var(--space-6) var(--space-4) var(--space-12); }
  body > footer { padding: var(--space-4); }
  /* Seitenleiste wird wieder eine Zeile */
  .flaeche { display: block; }
  .flaeche > nav { width: auto; position: static; flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--color-divider); }
  /* Breite Tabellen scrollen waagerecht statt zu quetschen */
  table { display: block; overflow-x: auto; white-space: nowrap; }
  thead, tbody, tr { display: table; width: 100%; table-layout: fixed; }
  dl { grid-template-columns: 1fr; gap: 0 0; }
  dt { margin-top: var(--space-2); }
  form.inline, .aktionen > * { min-height: 44px; }  /* Fingerziele */
}

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

/* Druck: Fläche als Nachweis ausdrucken (Audit-Log) */
@media print {
  body { background: #fff; color: #000; }
  body > header, body > footer, form, .aktionen { display: none; }
  main { max-width: none; padding: 0; }
}
