/* =============================================================================
   Betriebskompass – Modernist Design System
   -----------------------------------------------------------------------------
   Einzige Quelle für Farben, Typografie, Abstände und Elevation. Alle weiteren
   Stylesheets (styles.css für die öffentliche Website, dashboard.css für die
   App) bauen ausschließlich auf diesen Tokens auf.

   Gestaltungsprinzip: sachlich, rasterbasiert, ohne Rundungen und ohne
   Farbverläufe. Struktur entsteht durch Linien, Flächen und Typografie – nicht
   durch Schatten oder Effekte. Das passt zum Werkstatt-/Betriebsumfeld und
   bleibt auch bei hoher Informationsdichte lesbar.

   Barrierefreiheit: Alle Text-/Hintergrundpaare sind auf mindestens 4,5:1
   getestet (WCAG 2.1 AA), Bedienelemente auf mindestens 3:1. Die
   Mindestgröße für Touch-Ziele beträgt 44 px.
   ========================================================================== */

/* — Archivo, lokal ausgeliefert. Keine externen Font-CDNs, damit keine
     IP-Adressen an Dritte abfließen (siehe docs/privacy_by_design.md). — */
@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-weight: 400 800;
  font-stretch: 100%;
  font-display: swap;
  src: url('../fonts/archivo-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-weight: 400 800;
  font-stretch: 100%;
  font-display: swap;
  src: url('../fonts/archivo-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-weight: 400 800;
  font-stretch: 100%;
  font-display: swap;
  src: url('../fonts/archivo-vietnamese.woff2') format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

:root {
  /* — Grundflächen und Schrift — */
  --color-bg: #f3f2f2;
  --color-surface: #eae9e9;
  --color-surface-raised: #ffffff;
  --color-text: #201e1d;

  /* Akzent: gedämpftes Stahl-Petrol. Kontrast auf --color-bg 5,38:1,
     erfüllt AA sowohl als Textfarbe als auch als Buttonfläche. */
  --color-accent: #3a6b6b;
  --color-accent-2: #4c7a78;

  /* Abgestufte Textfarben – alle Werte über 4,5:1 auf --color-bg geprüft.
     Frühere prozentuale Mischungen (55 %/50 %) lagen bei 3,7:1 bzw. 3,2:1
     und sind deshalb bewusst durch feste, geprüfte Werte ersetzt. */
  --color-text-muted: #646261;   /* 5,43:1 */
  --color-text-subtle: #5f5e5d;  /* 5,79:1 */

  /* Linien: dekorative Regel schwächer, Bedienelement-Rahmen mindestens 3:1. */
  --color-divider: #9f9d9d;
  --color-border: #7f7d7d;       /* 3,66:1 – Formularfelder, Steuerelemente */

  --color-neutral-100: #f8f4f4;
  --color-neutral-200: #eae7e7;
  --color-neutral-300: #d7d3d3;
  --color-neutral-400: #bab6b6;
  --color-neutral-700: #605d5d;
  --color-neutral-800: #444141;
  --color-neutral-900: #2d2b2b;

  --color-accent-100: #eef4f4;
  --color-accent-200: #d7e5e4;
  --color-accent-300: #b4d0ce;
  --color-accent-500: #5f8f8c;
  --color-accent-600: #3a6b6b;
  --color-accent-700: #2b5150;
  --color-accent-800: #1e3938;
  --color-accent-900: #132524;

  /* — Statusfarben. Nie allein als Bedeutungsträger verwenden: immer mit
       Text oder Symbol kombinieren (WCAG 1.4.1). — */
  --color-success: #1f5c3d;
  --color-success-bg: #e7f0ea;
  --color-warning: #7a4b0c;
  --color-warning-bg: #f7eddd;
  --color-danger: #8c2318;
  --color-danger-bg: #f8e9e7;
  --color-info: #1e3938;
  --color-info-bg: #eef4f4;

  /* — Typografie — */
  --font-heading: 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-body: 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, 'Roboto Mono', monospace;
  --font-heading-weight: 800;

  /* Fließtext 16 px – Untergrenze für komfortables Lesen auf Mobilgeräten. */
  --text-base: 16px;
  --text-sm: 14px;
  --text-xs: 12.5px;
  --leading: 1.6;

  /* — Raster und Abstände — */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;

  --content-width: 1240px;
  --measure: 68ch;
  --gutter: clamp(20px, 4vw, 56px);

  /* Rechtwinklig: keine Radien im gesamten System. */
  --radius: 0px;

  /* Mindestgröße für Touch-Ziele (WCAG 2.5.5 / Mobile-UX). */
  --touch-target: 44px;

  /* Zurückhaltende, tintengetönte Elevation. */
  --shadow-sm: 0 1px 2px rgba(45, 43, 43, 0.14);
  --shadow-md: 0 3px 10px rgba(45, 43, 43, 0.16);
  --shadow-lg: 0 12px 32px rgba(45, 43, 43, 0.22);

  --rule: 2px solid var(--color-divider);
  --rule-strong: 2px solid var(--color-text);
  --hairline: 1px solid var(--color-divider);
}

/* =============================================================================
   Reset und Grundtypografie
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* Platz für den Scrollbalken dauerhaft reservieren. Sonst weicht die Breite
     fest positionierter Leisten (z. B. der mobilen Handlungsleiste) von der
     Inhaltsbreite ab und erzeugt waagerechten Überlauf. */
  scrollbar-gutter: stable;
}

/* Kein horizontales Scrollen der Seite. Breite Inhalte (Tabellen, Diagramme)
   scrollen in ihrem eigenen Container, siehe .table-wrap. Verhindert außerdem,
   dass fest positionierte Leisten über die Scrollbalkenbreite hinausragen. */
body { overflow-x: clip; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: var(--font-heading-weight);
  line-height: 1.08;
  letter-spacing: -0.02em;
  margin: 0 0 var(--space-3);
  text-wrap: balance;
}

h1 { font-size: clamp(1.95rem, 4.1vw, 3.1rem); }
h2 { font-size: clamp(1.6rem, 3.2vw, 2.4rem); }
h3 { font-size: clamp(1.2rem, 2vw, 1.5rem); }
h4 { font-size: 1.15rem; }
h5 { font-size: 1rem; }
h6 {
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

p { margin: 0 0 var(--space-4); max-width: var(--measure); }
ul, ol { margin: 0 0 var(--space-4); padding-left: 1.2em; }
li { margin-bottom: var(--space-2); }

a {
  color: var(--color-accent-700);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}
a:hover { color: var(--color-accent-800); text-decoration-thickness: 2px; }

strong, b { font-weight: 700; }

small { font-size: var(--text-sm); }

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

img, svg, video { display: block; max-width: 100%; height: auto; }

hr {
  height: 0;
  border: 0;
  border-top: var(--rule);
  margin: var(--space-8) 0;
}

table { border-collapse: collapse; width: 100%; }

/* Sichtbarer Fokus für Tastaturbedienung – nie entfernen. */
:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--color-accent-700);
  outline-offset: 2px;
}
::selection { background: var(--color-accent-200); }

/* Nur für Screenreader */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Sprunglink zum Hauptinhalt. Wird per clip-path versteckt statt per
   negativem Offset – das erzeugt keinen Überlauf nach links. */
.skip-link {
  position: absolute;
  top: var(--space-4);
  left: var(--space-4);
  z-index: 999;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  background: var(--color-text);
  color: var(--color-bg);
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-heading);
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
  align-items: center;
}
.skip-link:focus-visible, .skip-link:focus { display: inline-flex; min-height: var(--touch-target); }
.skip-link:focus-visible, .skip-link:focus {
  width: auto;
  height: auto;
  overflow: visible;
  clip-path: none;
  color: var(--color-bg);
}

/* =============================================================================
   Primitive Komponenten
   ========================================================================== */

/* — Buttons. Mindesthöhe 44 px für sichere Touch-Bedienung. — */
.btn,
.button,
button.button,
input[type="submit"],
.cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  padding: var(--space-3) var(--space-5);
  border: 2px solid var(--color-text);
  border-radius: var(--radius);
  background: transparent;
  color: var(--color-text);
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: var(--text-sm);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  transition: background-color 120ms linear, color 120ms linear;
}
.btn:hover,
.button:hover,
.cta:hover { background: var(--color-text); color: var(--color-bg); }

.btn-primary,
.button.primary,
.button-primary,
.cta,
input[type="submit"],
button[type="submit"] {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-bg);
}
.btn-primary:hover,
.button.primary:hover,
.button-primary:hover,
.cta:hover,
input[type="submit"]:hover,
button[type="submit"]:hover {
  background: var(--color-accent-700);
  border-color: var(--color-accent-700);
  color: var(--color-bg);
}

.button.secondary,
.btn-secondary {
  background: transparent;
  border-color: var(--color-text);
  color: var(--color-text);
}
.button.secondary:hover,
.btn-secondary:hover { background: var(--color-text); color: var(--color-bg); }

.btn:disabled,
.button[disabled],
button:disabled,
input[type="submit"]:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-block { width: 100%; }

/* Textlink mit Pfeilcharakter */
.text-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: var(--text-sm);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--color-accent-700);
  text-decoration: none;
  border-bottom: 2px solid var(--color-accent-700);
  align-self: flex-start;
  padding-bottom: 2px;
}
.text-link:hover { color: var(--color-accent-800); border-bottom-color: var(--color-accent-800); }

/* — Formularelemente — */
label {
  display: block;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: var(--text-sm);
  letter-spacing: 0.02em;
  color: var(--color-text);
  margin-bottom: var(--space-1);
}

input, textarea, select, .form-control, .input {
  width: 100%;
  min-height: var(--touch-target);
  padding: var(--space-3);
  font: inherit;
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-surface-raised);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  caret-color: var(--color-accent);
}
textarea, textarea.form-control { min-height: 120px; resize: vertical; }
select, select.form-control {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--color-text) 50%),
                    linear-gradient(135deg, var(--color-text) 50%, transparent 50%);
  background-position: calc(100% - 18px) center, calc(100% - 12px) center;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: var(--space-10);
}
input:hover, textarea:hover, select:hover { border-color: var(--color-text); }
input:focus-visible, textarea:focus-visible, select:focus-visible {
  border-color: var(--color-accent-700);
  outline: 3px solid var(--color-accent-300);
  outline-offset: 0;
}
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] {
  border-color: var(--color-danger);
}
input[type="checkbox"], input[type="radio"] {
  width: 20px;
  min-height: 20px;
  height: 20px;
  accent-color: var(--color-accent);
}
::placeholder { color: var(--color-text-muted); opacity: 1; }

.form-note, .form-hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: var(--space-2) 0 0;
}

/* Feldbezogene Fehlermeldung – direkt am Feld, nicht nur gesammelt oben. */
.field-error {
  display: block;
  margin-top: var(--space-1);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-danger);
}

/* — Meldungen — */
.errors, .alert {
  margin: 0 0 var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: 2px solid var(--color-danger);
  border-left-width: 8px;
  background: var(--color-danger-bg);
  color: var(--color-danger);
  font-weight: 600;
  list-style: none;
  max-width: none;
}
.errors li { margin: 0 0 var(--space-1); }
.errors li:last-child { margin-bottom: 0; }

.alert-success { border-color: var(--color-success); background: var(--color-success-bg); color: var(--color-success); }
.alert-warning { border-color: var(--color-warning); background: var(--color-warning-bg); color: var(--color-warning); }
.alert-info    { border-color: var(--color-accent); background: var(--color-info-bg);    color: var(--color-info); }

.notice-box {
  padding: var(--space-4);
  border: var(--rule);
  border-left: 8px solid var(--color-accent);
  background: var(--color-surface);
}

/* — Kennzeichnungen — */
.badge, .tag, .status-pill, .pricing-badge, .org-pill, .module-status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 4px var(--space-3);
  border: 1px solid var(--color-accent-700);
  border-radius: var(--radius);
  background: var(--color-accent-100);
  color: var(--color-accent-800);
  font-family: var(--font-heading);
  font-size: var(--text-xs);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge.neutral, .tag-neutral {
  border-color: var(--color-border);
  background: var(--color-neutral-200);
  color: var(--color-neutral-900);
}
.badge.success, .status-pill.ok { border-color: var(--color-success); background: var(--color-success-bg); color: var(--color-success); }
.badge.warning, .status-pill.warning { border-color: var(--color-warning); background: var(--color-warning-bg); color: var(--color-warning); }
.badge.danger, .status-pill.error { border-color: var(--color-danger); background: var(--color-danger-bg); color: var(--color-danger); }

/* — Kicker/Overline über Überschriften — */
.eyebrow, .card-kicker, .preview-label, .footer-overline, .section-overline {
  display: block;
  margin: 0 0 var(--space-2);
  font-family: var(--font-heading);
  font-size: var(--text-xs);
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-accent-700);
  max-width: none;
}

/* — Karten. Flächen statt Rahmen; Trennung über das Raster. — */
.card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-5);
  background: var(--color-surface);
  border-radius: var(--radius);
}
.card-title {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.15rem;
  line-height: 1.15;
  margin: 0;
}
.card-body { margin: 0; font-size: var(--text-sm); color: var(--color-text-muted); flex: 1; }

/* Rasterband: 2 px Fugen zeigen die Trennfarbe durch. Signatur des Systems. */
.rule-grid {
  display: grid;
  gap: 2px;
  background: var(--color-divider);
  border-top: var(--rule);
  border-bottom: var(--rule);
}
.rule-grid > * { background: var(--color-bg); }

/* — Tabellen — */
.table, table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.table th {
  text-align: left;
  padding: var(--space-3);
  font-family: var(--font-heading);
  font-size: var(--text-xs);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
  border-bottom: var(--rule-strong);
  white-space: nowrap;
}
.table td {
  padding: var(--space-3);
  border-bottom: var(--hairline);
  vertical-align: top;
}
.table tbody tr:hover { background: var(--color-surface); }

/* Tabellen dürfen horizontal scrollen, die Seite nicht.
   min-width:0 ist nötig, weil Grid-/Flex-Kinder sonst auf ihre Inhaltsbreite
   wachsen und den Container sprengen (min-width:auto ist der Standardwert). */
.table-wrap, .legal-table-wrap {
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  border: var(--rule);
  background: var(--color-surface-raised);
  -webkit-overflow-scrolling: touch;
}
.table-wrap > table, .legal-table-wrap > table { min-width: 640px; }

/* Gleiche Absicherung für alle Raster- und Flex-Kinder. */
.rule-grid > *, .container > *, main > * { min-width: 0; }

/* — Layoutbausteine — */
.container {
  width: min(var(--content-width), calc(100% - 2 * var(--gutter)));
  margin-inline: auto;
}

.section, .section-pad {
  padding-block: clamp(var(--space-10), 7vw, var(--space-20));
  border-bottom: var(--rule);
}
.section:last-of-type, .section-pad:last-of-type { border-bottom: 0; }

.section-heading-row {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: var(--space-8);
  align-items: end;
  margin-bottom: var(--space-8);
}
.section-heading-row h2, .section-heading-row h3 { margin: 0; max-width: 20ch; }
.section-heading-row p { margin: 0; color: var(--color-text-muted); }

@media (max-width: 780px) {
  .section-heading-row { grid-template-columns: 1fr; gap: var(--space-4); align-items: start; }
}

.text-muted { color: var(--color-text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mono { font-family: var(--font-mono); }
