/*
 * Basislayout des ADESTIS Partnerportals (UX-DR1 bis UX-DR7).
 *
 * Farben, Abstände und Schriftgrößen nur über die Tokens aus tokens.css (var(--…)).
 * Kontrastregel (tests/test_ui_rules.py): Jede Regel mit `color` hat zu ihrem Hintergrund
 * mindestens 4,5 : 1. Hintergrund ist der der eigenen Regel, sonst der des Headers für
 * Selektoren unter .site-header, sonst der von body. Neue dunkle Flächen setzen ihre
 * Hintergrundfarbe deshalb in derselben Regel wie die Textfarbe.
 */

/* --- Schrift: Roboto (variabel), selbst gehostet ------------------------- */
/* Fontsource @fontsource-variable/roboto 5.3.0, OFL-1.1 (fonts/roboto/OFL.txt) */

@font-face {
  font-family: "Roboto";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("../fonts/roboto/roboto-latin-ext-wght-normal.a6323dda0842.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: "Roboto";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("../fonts/roboto/roboto-latin-wght-normal.665db5e157d2.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;
}

/* --- Grundlage ------------------------------------------------------------ */

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

html {
  font-family: var(--font-family-base);
  font-size: 100%;
  line-height: var(--line-height-base);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--color-white);
  color: var(--adestis-gray-5);
  font-size: var(--font-size-base);
  overflow-wrap: break-word;
}

h1,
h2,
h3 {
  margin: 0 0 var(--space-4);
  font-weight: 500;
  line-height: 1.25;
}

h1 {
  font-size: var(--font-size-xl);
}

h2 {
  font-size: var(--font-size-lg);
}

p {
  margin: 0 0 var(--space-4);
}

img {
  max-width: 100%;
  height: auto;
}

a {
  color: var(--adestis-red-1);
  text-underline-offset: 0.15em;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: var(--focus-width) solid var(--adestis-red-2);
  outline-offset: var(--focus-offset);
}

/* --- Barrierefreiheit ------------------------------------------------------ */

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

.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 10;
  padding: var(--space-2) var(--space-3);
  background-color: var(--color-white);
  color: var(--adestis-red-1);
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
}

/* --- Header ------------------------------------------------------------- */

.site-header {
  background-color: var(--adestis-gray-5);
  color: var(--adestis-gray-1);
}

.site-header__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3) var(--space-5);
  max-width: var(--content-width);
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
}

.site-header a {
  color: var(--color-white);
}

.site-header :focus-visible {
  outline-color: var(--color-white);
}

/* Logo-Platzhalter: rotes Quadrat (red-2) und Wortmarke, bis das freigegebene Logo kommt. */
.logo {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
}

.logo__mark {
  display: inline-block;
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  background-color: var(--adestis-red-2);
}

.site-header .logo__wordmark {
  color: var(--color-white);
  font-size: var(--font-size-lg);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.site-header .logo__product {
  color: var(--adestis-gray-1);
  font-size: var(--font-size-base);
  font-weight: 400;
}

/* Hauptnavigation aus der Registry (FR-65); bricht auf schmalen Geräten um (375 px). */
.site-header .site-nav {
  min-width: 0;
}

.site-header .site-nav__list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.site-header .site-nav__link {
  display: inline-block;
  padding: var(--space-1) 0;
  border-bottom: var(--border-width-medium) solid transparent;
  color: var(--color-white);
  text-decoration: none;
}

.site-header .site-nav__link:hover {
  text-decoration: underline;
}

/* Aktuelle Seite: Unterstrich als Rahmen, nicht nur über Farbe (UX-DR4). */
.site-header .site-nav__link[aria-current="page"] {
  border-bottom-color: var(--color-white);
  font-weight: 700;
}

.site-header .site-nav__link:focus-visible {
  outline: var(--focus-width) solid var(--color-white);
  outline-offset: var(--focus-offset);
}

/* Benutzermenü: Abmelden als POST-Formular; rückt auf schmalen Geräten (375 px) in eine
 * eigene Zeile, statt die Seite zu verbreitern. */
.site-header .user-menu {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  min-width: 0;
  margin: 0;
}

/* Links „Profil“ (Story 1.12) und Zwei-Faktor-Authentifizierung (Story 1.9); Letzterer
 * bricht am Bindestrich um. */
.site-header .user-menu__link {
  color: var(--color-white);
}

.site-header .user-menu__logout {
  padding: var(--space-1) var(--space-3);
  border: var(--border-width-medium) solid var(--color-white);
  border-radius: var(--radius);
  background-color: var(--adestis-gray-5);
  color: var(--color-white);
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

/* Hover invertiert die Farben (12,4 : 1 wie im Ruhezustand). */
.site-header .user-menu__logout:hover {
  background-color: var(--color-white);
  color: var(--adestis-gray-5);
}

.site-header .user-menu__logout:focus-visible {
  outline: var(--focus-width) solid var(--color-white);
  outline-offset: var(--focus-offset);
}

/* --- Inhalt --------------------------------------------------------------- */

.site-main {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-6);
}

/* --- Formulare und Buttons ------------------------------------------------ */

.form-field {
  margin: 0 0 var(--space-4);
}

/* Checkbox mit der Beschriftung daneben, z. B. „Dealreg-Pflicht“ eines Produkts. */
.form-field--checkbox {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.form-field--checkbox input {
  width: auto;
}

.form-field--checkbox label {
  margin: 0;
}

/* Eine Gruppe von Feldern mit Legende, z. B. „Weitere Produkte“ einer Kombinationsregel: ohne
   Rahmen und Innenabstand, Abstand wie .form-field, die Legende wie ein label. */
.form-fieldset {
  margin: 0 0 var(--space-4);
  padding: 0;
  border: 0;
}

.form-fieldset legend {
  margin: 0 0 var(--space-1);
  padding: 0;
  font-weight: 500;
}

label {
  display: block;
  margin: 0 0 var(--space-1);
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  max-width: 30rem;
  padding: var(--space-2) var(--space-3);
  border: var(--border-width) solid var(--adestis-gray-4);
  border-radius: var(--radius);
  background-color: var(--color-white);
  color: var(--adestis-gray-5);
  font: inherit;
}

.button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: var(--border-width-medium) solid var(--adestis-gray-4);
  border-radius: var(--radius);
  background-color: var(--color-white);
  color: var(--adestis-gray-5);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}

/* Primär-Button: weiße Schrift auf red-1 (UX-DR2). */
.button--primary {
  border-color: var(--adestis-red-1);
  background-color: var(--adestis-red-1);
  color: var(--color-white);
}

.button--primary:hover {
  border-color: var(--adestis-gray-5);
  background-color: var(--adestis-gray-5);
  color: var(--color-white);
}

/* Zweites Formular unter dem Hauptformular, z. B. „Abbrechen“ im Code-Schritt. */
.form-secondary {
  margin: var(--space-4) 0;
}

/* Schreibgeschütztes Feld, z. B. die Adresse auf der Annahmeseite der Einladung. */
input[readonly] {
  background-color: var(--adestis-gray-1);
}

/* Knopf und Link eines Formulars nebeneinander („Einladung senden“, „Abbrechen“). */
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin: 0 0 var(--space-4);
}

/* Hauptaktion einer Seite über der Tabelle, z. B. „ADESTIS-Admin einladen“. */
.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin: 0 0 var(--space-4);
}

/* Name und Wert untereinander, z. B. auf der Bestätigung „Einladung zurückziehen“. */
.detail-list {
  margin: 0 0 var(--space-4);
}

.detail-list dt {
  font-weight: 500;
}

.detail-list dd {
  margin: 0 0 var(--space-2);
  overflow-wrap: anywhere;
}

/* Abschnitte einer Seite untereinander, z. B. „Persönliche Angaben“ und „Passwort ändern“
 * auf der Profilseite (Story 1.12). */
.site-main section + section {
  margin-top: var(--space-6);
}

/* --- Zwei-Faktor-Authentifizierung (Story 1.9) ---------------------------- */

/* QR-Code: Module in gray-5 (currentColor im Inline-SVG) auf Weiß, mit Ruhezone (Rand des
 * SVG plus Innenabstand); skaliert mit der Breite, höchstens 16rem (375 px ohne Scrollen). */
.totp-qr {
  max-width: 16rem;
  margin: 0 0 var(--space-4);
  padding: var(--space-3);
  border: var(--border-width) solid var(--adestis-gray-2);
  border-radius: var(--radius);
  background-color: var(--color-white);
  color: var(--adestis-gray-5);
}

.totp-qr svg {
  display: block;
  width: 100%;
  height: auto;
}

/* Schlüssel zur manuellen Eingabe: bricht auf schmalen Geräten an jeder Stelle um. */
.totp-secret {
  font-family: var(--font-family-mono);
  font-size: var(--font-size-lg);
  overflow-wrap: anywhere;
}

/* Wiederherstellungscodes: Monospace, auf breiten Geräten in Spalten; der Einzug fasst auch
 * die Nummer „10.“. */
.recovery-codes {
  margin: 0 0 var(--space-5);
  padding-left: calc(var(--space-6) + var(--space-3));
  column-width: 10rem;
  column-gap: var(--space-6);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-lg);
}

.recovery-codes li {
  margin: 0 0 var(--space-1);
  break-inside: avoid;
}

/* --- Filter, Tabellen und Seitenlinks (UX-DR14, UX-DR15) ------------------ */

/* Filterformular (GET): Felder nebeneinander, auf schmalen Geräten untereinander. */
.filter-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0 var(--space-4);
  margin: 0 0 var(--space-4);
}

/* min-width: 0, damit lange Einträge einer Auswahl das Feld nicht verbreitern. */
.filter-form .form-field {
  flex: 1 1 12rem;
  min-width: 0;
}

.filter-form__actions {
  display: flex;
  flex: 1 1 100%;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin: 0 0 var(--space-4);
}

/* Breite Tabellen scrollen in ihrem Container, nie die Seite (UX-DR15). Der Container ist
 * per Tastatur fokussierbar (tabindex="0") und trägt den globalen Fokusrahmen.
 * position: relative (Story 4.6c): Absolut positionierte Inhalte wie der .visually-hidden-Text
 * im Kopf „Aktionen“ des Katalogs bleiben im Container, den overflow-x sonst nicht beschneidet;
 * so scrollt die Seite bei 375 px nicht (README, „Oberflächenregeln“). */
.table-scroll {
  position: relative;
  max-width: 100%;
  margin: 0 0 var(--space-4);
  overflow-x: auto;
  border: var(--border-width) solid var(--adestis-gray-2);
  border-radius: var(--radius);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.data-table th,
.data-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--border-width) solid var(--adestis-gray-1);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  background-color: var(--adestis-gray-1);
  color: var(--adestis-gray-5);
  font-weight: 500;
  white-space: nowrap;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table__nowrap {
  white-space: nowrap;
}

.data-table__details {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Lange Texte, z. B. die Fehlermeldung des SMTP-Servers, brechen in der Zelle um. */
.data-table__wrap {
  min-width: 12rem;
  max-width: 24rem;
  overflow-wrap: anywhere;
}

/* Knöpfe und Links einer Tabellenzeile (z. B. „Erneut senden“ als POST-Formular und
 * „Zurückziehen“); nebeneinander, ohne Umbruch innerhalb eines Knopfs. */
.table-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.table-actions form {
  margin: 0;
}

.table-actions .button {
  padding: var(--space-1) var(--space-3);
  white-space: nowrap;
}

/* Knöpfe in einer Liste einer Tabellenzelle (die Auswahl eines Konflikts im Prüfergebnis):
 * höchstens 24rem breit, der Text bricht um und steht am Anfang. */
.data-table__details .table-actions .button {
  max-width: 24rem;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: start;
}

/* Seitenlinks „Neuere Einträge“ und „Ältere Einträge“. */
.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin: 0 0 var(--space-4);
}

/* --- Dashboard (FR-61, UX-DR13, Story 1.13) ------------------------------ */

/* Widgets nebeneinander, soweit jedes mindestens 18rem breit sein kann; bei 375 px eine
 * Spalte, nie horizontales Scrollen. */
.dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
  gap: var(--space-4);
  margin: 0 0 var(--space-4);
}

/* Eine Kachel. min-width: 0, damit lange Wörter im Grid-Element umbrechen; margin: 0 hebt
 * den Abstand von ``.site-main section + section`` auf, den das Grid selbst über gap regelt. */
.dashboard .widget {
  min-width: 0;
  margin: 0;
  padding: var(--space-4);
  border: var(--border-width) solid var(--adestis-gray-2);
  border-radius: var(--radius);
  background-color: var(--color-white);
  color: var(--adestis-gray-5);
}

.widget > :last-child {
  margin-bottom: 0;
}

/* Die Kennzahl eines Widgets, z. B. die Zahl der fehlgeschlagenen E-Mails (ein Link). */
.widget__value {
  margin: 0 0 var(--space-3);
  font-size: var(--font-size-xl);
  font-weight: 500;
  line-height: 1.25;
}

/* Zeilen eines Widgets, jede eine Meldung mit Icon und Text. */
.widget__list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.widget__list li:last-child .message {
  margin-bottom: 0;
}

/* --- Meldungen (immer Icon und Text, UX-DR4) ------------------------------ */

.message {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin: 0 0 var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: var(--border-width) solid var(--adestis-gray-4);
  border-left-width: var(--border-width-strong);
  border-radius: var(--radius);
  background-color: var(--adestis-gray-1);
  color: var(--adestis-gray-5);
}

.message > .icon {
  margin-top: var(--icon-offset);
}

/* min-width: 0, damit lange Wörter (URL, E-Mail-Adresse) im Flex-Item umbrechen. */
.message__text {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.message a {
  color: inherit;
  text-decoration: underline;
}

/* Fehler: red-1 als Fläche mit weißer Schrift. */
.message--error {
  border-color: var(--adestis-red-1);
  background-color: var(--adestis-red-1);
  color: var(--color-white);
}

.message--error :focus-visible {
  outline-color: var(--color-white);
}

/* Warnung: orange erreicht mit keiner Palettenfarbe 4,5 : 1, daher nur als Rahmen. */
.message--warning {
  border-color: var(--adestis-orange);
  background-color: var(--color-white);
  color: var(--adestis-gray-5);
}

/* Erfolg: green als Fläche mit Schrift in gray-5 (6,1 : 1). */
.message--success {
  border-color: var(--adestis-green);
  background-color: var(--adestis-green);
  color: var(--adestis-gray-5);
}

/* red-2 auf green hätte nur 2,3 : 1; der Fokusrahmen braucht mindestens 3 : 1. */
.message--success :focus-visible {
  outline-color: var(--adestis-gray-5);
}

.message--info {
  border-color: var(--adestis-gray-4);
  background-color: var(--adestis-gray-1);
  color: var(--adestis-gray-5);
}

/*
 * Fläche für gescheiterte htmx-Requests (Story 6.1d, static/js/portal.js): Breite und
 * Seitenabstände wie .site-main, oben angeheftet über dem Inhalt, damit die Meldung beim Scrollen
 * sichtbar bleibt. Leer hat die Fläche keine Höhe.
 */
.request-error {
  position: sticky;
  top: 0;
  z-index: 5;
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.request-error > .message {
  margin: var(--space-4) 0 0;
}

/*
 * Knopf „Meldung schließen“ als letztes Kind der Meldung (Nacharbeit zu Story 6.1d): Das Icon mit
 * Innenabstand ergibt mindestens 24 × 24 px. Den Fokusrahmen in Weiß auf red-1 setzt
 * .message--error :focus-visible.
 */
.message__close {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  padding: var(--space-1);
  border: 0;
  border-radius: var(--radius);
  background-color: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

/*
 * Solange #request-error eine Meldung hält, setzt static/js/portal.js ihre Höhe als
 * --request-error-height: Ein fokussiertes Element liegt dann samt Fokusrahmen nicht unter der
 * angehefteten Meldung. Ohne Meldung gilt die Regel nicht.
 */
html:has(#request-error > .message) {
  scroll-padding-top: calc(
    var(--request-error-height, 0px) + var(--focus-width) + var(--focus-offset)
  );
}

/* --- Badges (immer mit Textlabel, UX-DR3) --------------------------------- */

.badge {
  display: inline-block;
  padding: 0 var(--space-2);
  border: var(--border-width) solid var(--adestis-gray-1);
  border-radius: var(--radius);
  background-color: var(--adestis-gray-1);
  color: var(--adestis-gray-5);
  font-size: var(--font-size-sm);
  font-weight: 500;
  line-height: 1.6;
  white-space: nowrap;
}

.badge--success {
  border-color: var(--adestis-green);
  background-color: var(--adestis-green);
  color: var(--adestis-gray-5);
}

.badge--warning {
  border-color: var(--adestis-orange);
  background-color: var(--color-white);
  color: var(--adestis-gray-5);
}

.badge--error {
  border-color: var(--adestis-red-1);
  background-color: var(--adestis-red-1);
  color: var(--color-white);
}

.badge--info {
  border-color: var(--adestis-gray-4);
  background-color: var(--adestis-gray-4);
  color: var(--color-white);
}

.badge--neutral {
  border-color: var(--adestis-gray-1);
  background-color: var(--adestis-gray-1);
  color: var(--adestis-gray-5);
}

/* --- Icons (SVG mit currentColor) ----------------------------------------- */

.icon {
  flex: none;
  width: 1.25em;
  height: 1.25em;
  vertical-align: -0.25em;
}

/* --- htmx-Ladeanzeige (includeIndicatorStyles ist false, UX-DR7) ---------- */

.htmx-indicator {
  opacity: 0;
  transition: opacity 200ms ease-in;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
}
