/* =============================================================================
   German Garrison Mail — Design-System
   (uebernommen vom codefish-Mail-Frontend; Marke ausgetauscht, sonst gleich)
   =============================================================================
   Eine einzige Quelle fuer Farben, Abstaende, Typografie und Komponenten.
   Kein Framework, kein Build-Schritt.

   Aufbau:
     1. Tokens (hell)          6. Formulare
     2. Tokens (dunkel)        7. Buttons
     3. Reset & Grundlagen     8. Karten, Listen, Tabellen
     4. Marke (Logo, Schrift)  9. Rueckmeldungen (Toast, Badge, Alert)
     5. Layout & Navigation   10. Hilfsklassen
   ========================================================================== */

/* --- 1. Tokens (hell) ------------------------------------------------------ */
:root {
    /* Flaechen, von hinten nach vorne */
    --bg:            #f4f5f7;
    --surface:       #ffffff;
    --surface-2:     #f8f9fb;
    --surface-hover: #eef1f6;

    /* Text */
    --text:          #1c2024;
    --text-muted:    #616b78;
    --text-inverse:  #ffffff;

    /* Linien */
    --border:        #dfe3e9;
    --border-strong: #c3cad4;

    /* Marke: ein ruhiges, dunkles Stahlblau. Neutral, ohne Logo - die
       German Garrison hat ihr eigenes Erscheinungsbild, das hier nicht nachgebaut wird. */
    --brand:         #2f5687;
    --brand-hover:   #264770;
    --brand-soft:    #e6edf6;
    --brand-text:    #1f3a5c;

    /* Semantik */
    --danger:        #b4252b;
    --danger-soft:   #fbeaea;
    --success:       #1f7a3f;
    --success-soft:  #e6f4ea;
    --warning:       #8a5a00;
    --warning-soft:  #fdf3e0;

    /* Form */
    --radius:        10px;
    --radius-sm:     6px;
    --radius-lg:     16px;

    --shadow:        0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --shadow-lg:     0 4px 12px rgba(16, 24, 40, .10), 0 12px 32px rgba(16, 24, 40, .10);

    /* Abstaende: 4px-Raster */
    --s-1: .25rem;  --s-2: .5rem;   --s-3: .75rem;  --s-4: 1rem;
    --s-5: 1.5rem;  --s-6: 2rem;    --s-7: 3rem;    --s-8: 4rem;

    /* Typografie */
    --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
    --font-brand: var(--font);

    --fs-xs: .75rem; --fs-sm: .875rem; --fs-md: 1rem;
    --fs-lg: 1.125rem; --fs-xl: 1.375rem; --fs-2xl: 1.75rem;

    --focus: 0 0 0 3px color-mix(in srgb, var(--brand) 35%, transparent);
}

/* --- 2. Tokens (dunkel) ---------------------------------------------------- */
/* Nur Farben werden ueberschrieben - Abstaende, Radien und Typografie bleiben.
   Deshalb kostet der Dunkelmodus fast nichts, solange jede Komponente
   ausschliesslich ueber Tokens faerbt. */
/* `[data-theme=dark]` steht bewusst daneben: es gibt keinen Umschalter in der
   Oberflaeche, aber damit laesst sich der Dunkelmodus testen, ohne die
   Systemeinstellung zu aendern - und ein spaeterer Umschalter waere trivial. */
:root[data-theme="dark"] {
    --bg:            #14171a;
    --surface:       #1c2024;
    --surface-2:     #22272c;
    --surface-hover: #2a3036;
    --text:          #e7eaee;
    --text-muted:    #98a2b0;
    --text-inverse:  #14171a;
    --border:        #2f363d;
    --border-strong: #414a53;
    --brand:         #7fa8dc;
    --brand-hover:   #9bbce6;
    --brand-soft:    #1b2a3d;
    --brand-text:    #bcd3f0;
    --danger:        #f0787d;
    --danger-soft:   #3a1c1e;
    --success:       #5fc286;
    --success-soft:  #16301f;
    --warning:       #e0aa4e;
    --warning-soft:  #33280f;
    --shadow:        0 1px 2px rgba(0, 0, 0, .40), 0 1px 3px rgba(0, 0, 0, .30);
    --shadow-lg:     0 4px 12px rgba(0, 0, 0, .45), 0 12px 32px rgba(0, 0, 0, .35);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:            #14171a;
        --surface:       #1c2024;
        --surface-2:     #22272c;
        --surface-hover: #2a3036;

        --text:          #e7eaee;
        --text-muted:    #98a2b0;
        --text-inverse:  #14171a;

        --border:        #2f363d;
        --border-strong: #414a53;

        --brand:         #7fa8dc;
        --brand-hover:   #9bbce6;
        --brand-soft:    #1b2a3d;
        --brand-text:    #bcd3f0;

        --danger:        #f0787d;
        --danger-soft:   #3a1c1e;
        --success:       #5fc286;
        --success-soft:  #16301f;
        --warning:       #e0aa4e;
        --warning-soft:  #33280f;

        --shadow:        0 1px 2px rgba(0, 0, 0, .40), 0 1px 3px rgba(0, 0, 0, .30);
        --shadow-lg:     0 4px 12px rgba(0, 0, 0, .45), 0 12px 32px rgba(0, 0, 0, .35);
    }
}

/* --- 3. Reset & Grundlagen ------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: var(--fs-md);
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    /* Verhindert seitliches Scrollen auf schmalen Viewports. */
    overflow-x: hidden;
}

h1, h2, h3, h4 { margin: 0 0 var(--s-3); line-height: 1.25; font-weight: 600; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
p  { margin: 0 0 var(--s-4); }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, .mono { font-family: var(--font-mono); font-size: .9em; }

hr { border: 0; border-top: 1px solid var(--border); margin: var(--s-5) 0; }

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

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }

/* Respektiert die Systemeinstellung fuer reduzierte Bewegung. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* --- 4. Marke -------------------------------------------------------------- */
.brand-font { font-family: var(--font-brand); }

/* Wortmarke in der Kopfzeile */
.wordmark {
    font-family: var(--font-brand);
    font-weight: 650;
    letter-spacing: -.01em;
    font-size: var(--fs-lg);
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
}
.wordmark:hover { text-decoration: none; color: var(--brand); }

/* Briefumschlag als Zeichen - es gibt kein Logo, und keines wird erfunden. */
.icon.brand-mark { width: 3.5rem; height: 3.5rem; color: var(--brand); stroke-width: 1.5; }
.icon.brand-mark-sm { width: 1.4rem; height: 1.4rem; color: var(--brand); }

/* --- 5. Layout & Navigation ------------------------------------------------ */
.page { min-height: 100vh; display: flex; flex-direction: column; }

.container {
    width: 100%;
    max-width: 1100px;
    margin-inline: auto;
    padding-inline: var(--s-4);
}
.container-wide { max-width: 1600px; }
/* Lesebreite fuer formularlastige Ansichten. Eine Beschriftung links und ihr
   Wert 1300px weiter rechts sind als Paar nicht mehr lesbar - Formulare
   brauchen deshalb eine andere Breite als Tabellen und das Webmail.
   Welche Ansicht welche bekommt, entscheidet `meta.width` in `app/router.js`. */
.container-read { max-width: 880px; }

.main { flex: 1; padding-block: var(--s-6) var(--s-8); }

/* Vollhoehen-Modus (`meta.fixedHeight`): die Seite selbst scrollt nicht, die
   Spalten darin tun es. Sonst wandert bei einer langen Detailansicht die
   Auswahlliste links mit aus dem Bild.
   Frueher hing das an `body.webmail-page`, das die Webmail-Ansicht sich selbst
   setzte; jetzt setzt es der Rahmen anhand der Route - damit gilt es auch fuer
   Benutzer, Gruppen und Weiterleitungen. */
body.app-fixed { overflow: hidden; }
body.app-fixed .page { height: 100vh; }
body.app-fixed .main {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding-block: var(--s-4);
}
body.app-fixed .main > .container {
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
/* Ueberschrift und Erklaerung behalten ihre Hoehe, das Raster darunter fuellt
   den Rest. Bewusst nicht `:last-child`: ein geoeffneter Bestaetigungsdialog
   ist im DOM das letzte Element und wuerde die Zuordnung springen lassen. */
body.app-fixed .main > .container > .split,
body.app-fixed .main > .container > .webmail { flex: 1; min-height: 0; }

/* Kopfzeile */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar-inner {
    display: flex;
    align-items: center;
    gap: var(--s-4);
    min-height: 56px;
}

/* Die Leiste nimmt die Restbreite ein; die Trennung zwischen taeglichem
   Geschaeft und Nebensachen liegt im Layout, nicht in der Reihenfolge. */
.nav {
    display: flex;
    align-items: center;
    gap: var(--s-4);
    flex: 1;
    min-width: 0;
}
.nav-group { display: flex; align-items: center; gap: var(--s-1); min-width: 0; }
.nav-right { margin-left: auto; }

.nav-link {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-2) var(--s-3);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: var(--fs-sm);
    font-weight: 500;
    white-space: nowrap;
    /* "Abmelden" ist ein <button>. Ohne diesen Reset erbt es den
       Standardrahmen des Browsers und sieht neben den Links wie ein
       herausgestanzter Kasten aus. */
    background: none;
    border: 0;
    font-family: inherit;
    line-height: inherit;
    cursor: pointer;
}
.nav-link:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--brand-soft); color: var(--brand-text); }

/* Aufklappmenue "Administration" */
.nav-dropdown { position: relative; }
.nav-dropdown .nav-link svg:last-child { transition: transform .12s ease; }

.nav-menu {
    position: absolute;
    top: calc(100% + var(--s-2));
    left: 0;
    z-index: 30;
    min-width: 220px;
    padding: var(--s-1);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
/* Rechtsbuendige Variante fuer Kategorien am rechten Rand der Leiste. */
.nav-menu-right { left: auto; right: 0; }

.nav-menu-item {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-2) var(--s-3);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: var(--fs-sm);
    white-space: nowrap;
}
.nav-menu-item:hover { background: var(--surface-hover); text-decoration: none; }
.nav-menu-item.active { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }

/* Zwischenueberschrift im Mobilmenue */
.nav-heading {
    padding: var(--s-3) var(--s-3) var(--s-1);
    font-size: var(--fs-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
}
.nav-sub { padding-left: var(--s-5); }

/* Menuschalter - nur auf Mobil sichtbar */
.nav-toggle {
    display: none;
    margin-left: auto;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--s-2);
    color: var(--text);
    cursor: pointer;
}

@media (max-width: 860px) {
    .nav-toggle { display: inline-flex; }
    .nav {
        display: none;
        position: absolute;
        top: 100%; left: 0; right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        margin: 0;
        padding: var(--s-2);
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        box-shadow: var(--shadow-lg);
    }
    .nav.open { display: flex; }
    .nav-group { flex-direction: column; align-items: stretch; gap: 0; width: 100%; }
    .nav-right { margin-left: 0; border-top: 1px solid var(--border); margin-top: var(--s-2); padding-top: var(--s-2); }
    .nav-link { padding: var(--s-3); border-radius: var(--radius-sm); }
    .topbar { position: relative; }
}

/* Fusszeile */
.footer {
    padding-block: var(--s-5);
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: var(--fs-sm);
    color: var(--text-muted);
}
.footer a { color: var(--text-muted); margin-inline: var(--s-3); }
.footer a:hover { color: var(--text); }

/* --- 6. Formulare ---------------------------------------------------------- */
/* Aufklappbare Schritt-fuer-Schritt-Anleitung in einer Karte. Es gibt in dieser
   Anwendung keine Markdown-Darstellung - solche Texte stehen als HTML in der Ansicht. */
.anleitung {
    margin-top: var(--s-3);
    padding: var(--s-3) var(--s-4);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: var(--fs-sm);
}
.anleitung ol { margin: 0 0 var(--s-2); padding-left: var(--s-5); }
.anleitung li { margin-bottom: var(--s-2); }
.anleitung li:last-child { margin-bottom: 0; }

/* Schreibgeschuetzte Adressliste - bewusst kein Eingabefeld. */
.adressliste {
    margin: var(--s-2) 0;
    padding: var(--s-2) var(--s-3);
    max-height: 320px;
    overflow-y: auto;
    list-style: none;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: var(--fs-sm);
}
.adressliste li { padding: 2px 0; overflow-wrap: anywhere; }

/* Speichern-Balken: bleibt am unteren Rand sichtbar, statt hinter sechs Karten
   zu verschwinden. `position: sticky` und nicht `fixed` - so bleibt er im
   Textfluss und legt sich am Ende der Liste nicht ueber den Inhalt. */
.save-bar {
    position: sticky;
    bottom: var(--s-4);
    z-index: 10;
    display: flex;
    align-items: center;
    gap: var(--s-3);
    flex-wrap: wrap;
    margin-bottom: var(--s-6);
    padding: var(--s-3) var(--s-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
/* Nur wenn es etwas zu speichern gibt, draengt sich der Balken auf. */
.save-bar.dirty { border-color: var(--brand); }

/* Trennt einen eigenstaendigen Bereich vom Rest der Seite ab - etwa die
   Passwortaenderung, die der Speichern-Knopf darueber nicht betrifft. */
.section-head {
    margin-top: var(--s-7);
    margin-bottom: var(--s-2);
    padding-top: var(--s-5);
    border-top: 1px solid var(--border);
    font-size: var(--fs-lg);
}

.field { margin-bottom: var(--s-4); }
.field-row { display: grid; gap: var(--s-2); }

label, .label {
    display: block;
    font-size: var(--fs-sm);
    font-weight: 600;
    margin-bottom: var(--s-1);
    color: var(--text);
}

.hint { font-size: var(--fs-sm); color: var(--text-muted); margin-top: var(--s-1); }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=search], select, textarea {
    width: 100%;
    padding: var(--s-2) var(--s-3);
    font: inherit;
    font-size: var(--fs-sm);
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    /* Unter 16px zoomt iOS beim Fokussieren in das Feld hinein. */
    min-height: 40px;
}
@media (max-width: 860px) {
    input[type=text], input[type=email], input[type=password], input[type=number],
    input[type=search], select, textarea { font-size: 16px; }
}

input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: var(--focus); outline: none; }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-muted); cursor: not-allowed; }

textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
textarea.mono { font-family: var(--font-mono); }

.check { display: flex; align-items: flex-start; gap: var(--s-2); margin-bottom: var(--s-3); }
.check input[type=checkbox] { width: 18px; height: 18px; margin-top: 3px; accent-color: var(--brand); flex: none; }
.check label { margin: 0; font-weight: 400; }

/* --- 7. Buttons ------------------------------------------------------------ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    padding: var(--s-2) var(--s-4);
    min-height: 40px;
    font: inherit;
    font-size: var(--fs-sm);
    font-weight: 600;
    line-height: 1;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--surface-hover); text-decoration: none; }
.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--text-inverse); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }

.btn-sm { min-height: 32px; padding: var(--s-1) var(--s-2); font-size: var(--fs-xs); }
.btn-lg { min-height: 48px; padding: var(--s-3) var(--s-5); font-size: var(--fs-md); }
.btn-block { width: 100%; }

/* Zusammenhaengende Schaltergruppe */
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group .btn:last-child  { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.btn-group .btn.active { background: var(--brand); border-color: var(--brand); color: var(--text-inverse); z-index: 1; }

/* --- 8. Karten, Listen, Tabellen ------------------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: var(--s-5);
    overflow: hidden;
}
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    padding: var(--s-3) var(--s-4);
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    font-weight: 600;
}
.card-head.danger { background: var(--danger-soft); color: var(--danger); border-bottom-color: var(--danger); }
.card-body { padding: var(--s-4); }
.card-foot { padding: var(--s-3) var(--s-4); border-top: 1px solid var(--border); background: var(--surface-2); }

/* Master/Detail - stapelt auf Mobil.
   Der Umbruch liegt bei 900px, nicht bei 860px: derselbe Punkt, an dem der
   Vollhoehen-Modus abgeschaltet wird. Zwei dicht beieinander liegende
   Umbrueche ergaeben dazwischen einen Streifen, in dem die Spalten schon
   gestapelt, die Seite aber noch fixiert waere. */
.split { display: grid; gap: var(--s-5); grid-template-columns: minmax(220px, 280px) 1fr; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

/* In Vollhoehe scrollen die beiden Spalten getrennt statt der ganzen Seite.
   `align-items: start` bleibt bestehen, dazu `max-height: 100%`: eine kurze
   Liste behaelt ihre natuerliche Hoehe, statt als grosse leere Karte ueber den
   Bildschirm gezogen zu werden - erst wenn sie nicht mehr passt, scrollt sie. */
body.app-fixed .split { margin-bottom: 0; }
body.app-fixed .split > .card {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: 100%;
    margin-bottom: 0;
}
body.app-fixed .split > .card > .card-head { flex: none; }
body.app-fixed .split > .card > .list { flex: 1; min-height: 0; overflow-y: auto; }
/* Die Detailspalte scrollt als Ganzes; die Innenabstaende halten den
   Schattenwurf der Karten vom Scrollrand frei. */
.split-detail { min-width: 0; }
body.app-fixed .split-detail {
    overflow-y: auto;
    min-height: 0;
    max-height: 100%;
    padding-inline: 2px;
    padding-bottom: var(--s-2);
}

/* Filterzeile ueber einer Auswahlliste. Sitzt ausserhalb von `.list`, damit sie
   im Vollhoehen-Modus nicht mitscrollt. */
.list-filter { padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--border); }
.list-filter input { width: 100%; }
body.app-fixed .split > .card > .list-filter { flex: none; }

.list { display: flex; flex-direction: column; }
.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    padding: var(--s-3) var(--s-4);
    border-bottom: 1px solid var(--border);
    color: var(--text);
    text-align: left;
    background: none;
    border-left: 0; border-right: 0; border-top: 0;
    font: inherit;
    width: 100%;
    cursor: pointer;
}
/* Zweizeiliger Eintrag: Bezeichnung oben, Beiwerk darunter. Ohne das laufen
   beide Spans in einer Zeile ineinander. */
.list-item-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--surface-hover); text-decoration: none; }
.list-item.active { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
th, td { padding: var(--s-3); text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; color: var(--text-muted); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: var(--surface-2); }

/* --- 9. Rueckmeldungen ----------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    padding: 2px var(--s-2);
    border-radius: 999px;
    font-size: var(--fs-xs);
    font-weight: 600;
    background: var(--surface-2);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.badge-brand   { background: var(--brand-soft);   color: var(--brand-text); border-color: transparent; }
.badge-danger  { background: var(--danger-soft);  color: var(--danger);     border-color: transparent; }
.badge-success { background: var(--success-soft); color: var(--success);    border-color: transparent; }
.badge-warning { background: var(--warning-soft); color: var(--warning);    border-color: transparent; }

.alert {
    padding: var(--s-3) var(--s-4);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    margin-bottom: var(--s-4);
    font-size: var(--fs-sm);
}
.alert-danger  { background: var(--danger-soft);  border-color: var(--danger);  color: var(--danger); }
.alert-success { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.alert-warning { background: var(--warning-soft); border-color: var(--warning); color: var(--warning); }
.alert-info    { background: var(--brand-soft);   border-color: var(--brand);   color: var(--brand-text); }

/* Toast - global, ueberlagert alles */
.toast {
    position: fixed;
    left: 50%;
    bottom: var(--s-5);
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    align-items: flex-start;
    gap: var(--s-3);
    max-width: min(560px, calc(100vw - 2 * var(--s-4)));
    padding: var(--s-3) var(--s-4);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: var(--fs-sm);
    background: var(--danger-soft);
    border: 1px solid var(--danger);
    color: var(--danger);
}
.toast-success { background: var(--success-soft); border-color: var(--success); color: var(--success); }

/* Leerzustand */
.empty { padding: var(--s-7) var(--s-4); text-align: center; color: var(--text-muted); }

/* Ladeanzeige */
.spinner {
    display: inline-block;
    width: 1em; height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    vertical-align: -.125em;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Fortschrittsbalken (Spam-Test) */
.meter { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.meter > span { display: block; height: 100%; background: var(--brand); }
.meter.danger  > span { background: var(--danger); }
.meter.success > span { background: var(--success); }

/* --- 10. Hilfsklassen ------------------------------------------------------ */
/* Strich-Icons aus /icons/sprite.svg.
   fill/stroke werden hier gesetzt und vererben sich in den Shadow-Tree, den
   <use> aus der externen Datei aufspannt - deshalb faerben sich die Symbole
   automatisch mit der Textfarbe. */
.icon {
    width: 1.15em;
    height: 1.15em;
    flex: none;
    vertical-align: -.2em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.icon-lg { width: 1.5em; height: 1.5em; }
.icon-sm { width: .9em; height: .9em; }

.muted     { color: var(--text-muted); }
.small     { font-size: var(--fs-sm); }
.xs        { font-size: var(--fs-xs); }
.strong    { font-weight: 600; }
.center    { text-align: center; }
.right     { text-align: right; }
.nowrap    { white-space: nowrap; }
.truncate  { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.break     { overflow-wrap: anywhere; }

.row     { display: flex; align-items: center; gap: var(--s-3); }
.row-top { display: flex; align-items: flex-start; gap: var(--s-3); }
.wrap    { flex-wrap: wrap; }
.spread  { justify-content: space-between; }
.stack   { display: flex; flex-direction: column; gap: var(--s-3); }
.grow    { flex: 1; min-width: 0; }

.mt-0 { margin-top: 0; }      .mt-2 { margin-top: var(--s-2); }
.mt-3 { margin-top: var(--s-3); } .mt-4 { margin-top: var(--s-4); }
.mt-5 { margin-top: var(--s-5); } .mt-6 { margin-top: var(--s-6); }
.mb-0 { margin-bottom: 0; }   .mb-2 { margin-bottom: var(--s-2); }
.mb-3 { margin-bottom: var(--s-3); } .mb-4 { margin-bottom: var(--s-4); }
.mb-5 { margin-bottom: var(--s-5); }

.hide { display: none !important; }
@media (max-width: 860px) { .hide-mobile { display: none !important; } }
@media (min-width: 861px) { .only-mobile { display: none !important; } }

/* Nur fuer Screenreader */
.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* --- 11. Dialog ------------------------------------------------------------ */
.dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: grid;
    place-items: center;
    padding: var(--s-4);
    background: rgba(16, 24, 40, .45);
}
.dialog { width: 100%; max-width: 460px; margin: 0; box-shadow: var(--shadow-lg); }

/* --- 12. Webmail ----------------------------------------------------------- */
/* Breit: drei Spalten, die den Bildschirm ausfuellen. Gescrollt wird in den
   Spalten, nicht in der Seite - eine Mailliste, die die ganze Seite mitnimmt,
   verschiebt beim Blaettern auch Ordner und Detail aus dem Blick. */
.webmail {
    display: grid;
    grid-template-columns: minmax(180px, 220px) minmax(300px, 380px) 1fr;
    gap: var(--s-4);
    align-items: stretch;
    height: 100%;
    min-height: 0;
}

.webmail > .card {
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin-bottom: 0;
}
.webmail > .card > .card-head,
.webmail > .card > .card-foot { flex: none; }

/* Die scrollenden Bereiche */
.webmail .list,
.webmail .card-body,
.webmail .empty { overflow-y: auto; min-height: 0; flex: 1; }

/* ... alles andere in einer Spalte behaelt seine Hoehe. */
.webmail > .card > .webmail-search,
.webmail > .card > .webmail-compose-bar { flex: none; }

/* Die Vollhoehe selbst steht in Abschnitt 5 (`body.app-fixed`) und wird vom
   Rahmen anhand von `meta.fixedHeight` gesetzt - sie gilt inzwischen auch fuer
   Benutzer, Gruppen und Weiterleitungen. Hier bleibt nur Webmail-Eigenes. */

.mail-row { flex-direction: column; align-items: stretch; gap: 0; padding-block: var(--s-2); }
.mail-row.unread { background: color-mix(in srgb, var(--brand-soft) 45%, transparent); }
.mail-row.unread.active { background: var(--brand-soft); }

/* Feste Hoehe noetig: der Mail-Body laeuft in einer sandbox-iframe ohne
   allow-scripts und kann seine eigene Hoehe deshalb nicht melden. */
/* Rahmen um die HTML-Mail. Traegt auf schmalen Bildschirmen die *sichtbare* Hoehe
   (Inhaltshoehe mal Verkleinerungsfaktor), waehrend der iframe darin seine volle
   Layouthoehe behaelt - sonst passten Layout- und Anzeigehoehe nicht zusammen und
   es entstuende ein Streifen Leerraum. */
.mail-frame {
    width: 100%;
    height: 100%;
    min-height: 420px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
}

.mail-body {
    width: 100%;
    height: 100%;
    border: 0;
    background: #fff;   /* fremdes HTML erwartet hellen Grund - auch im Dunkelmodus */
    /* Verkleinert wird von der oberen linken Ecke aus, sonst waendert der Inhalt
       beim Skalieren aus dem Rahmen. */
    transform-origin: top left;
}

.mail-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-family: inherit;
    font-size: var(--fs-sm);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--s-3);
    margin: 0;
}

/* Suchfeld ueber der Mailliste. Ausserhalb von `.list`, damit es im
   Vollhoehen-Modus nicht mitscrollt. */
.webmail-search {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    flex: none;
    padding: var(--s-2) var(--s-3);
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
}
.webmail-search input { flex: 1; min-width: 0; }

/* Leiste mit "Neue Mail" ueber der Ordnerliste. */
.webmail-compose-bar {
    display: flex;
    flex: none;
    padding: var(--s-2) var(--s-3);
    border-bottom: 1px solid var(--border);
}

/* Aufklappmenue fuer das Verschieben. Gleiche Form wie das Navigationsmenue,
   aber rechtsbuendig - es sitzt am rechten Rand der Detailspalte und liefe sonst
   aus dem Bild. */
.menu {
    position: absolute;
    top: calc(100% + var(--s-2));
    right: 0;
    z-index: 30;
    min-width: 220px;
    max-width: min(320px, 80vw);
    max-height: 60vh;
    overflow-y: auto;
    padding: var(--s-1);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
.menu-item {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    width: 100%;
    padding: var(--s-2) var(--s-3);
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text);
    font: inherit;
    font-size: var(--fs-sm);
    text-align: left;
    cursor: pointer;
}
.menu-item:hover { background: var(--surface-hover); }
.menu-note {
    margin: var(--s-1) 0 0;
    padding: var(--s-2) var(--s-3);
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: var(--fs-xs);
    white-space: normal;
}

/* Ladeanzeige am Ende der Liste beim Nachladen */
.mail-more { padding: var(--s-4); text-align: center; color: var(--text-muted); font-size: var(--fs-sm); }

/* Schmal: immer nur ein Bereich, gesteuert ueber data-pane. */
@media (max-width: 900px) {
    .webmail { grid-template-columns: 1fr; height: auto; }
    /* Selektor-Spezifitaet muss die der Desktop-Regel `.webmail > .card`
       erreichen - Media Queries zaehlen dabei nicht mit. Sonst gewinnt oben
       `display: flex` und es sind alle Bereiche gleichzeitig sichtbar. */
    .webmail > .card { display: none; }
    .webmail[data-pane="folders"] > .webmail-folders,
    .webmail[data-pane="list"]    > .webmail-list,
    .webmail[data-pane="detail"]  > .webmail-detail { display: flex; }

    .webmail .list, .webmail .card-body, .webmail .empty { overflow-y: visible; }
    /* Der Rahmen waechst auf die tatsaechliche Inhaltshoehe (in JS gesetzt), damit
       die Seite als Ganzes scrollt. Vorher war er ein Kasten mit eigenem Scrollbereich
       innerhalb der scrollenden Seite - die klassische Scroll-Falle auf Touchgeraeten:
       man scrollt die Seite, trifft den Kasten, und ab da bewegt sich etwas anderes. */
    .mail-frame {
        height: auto;
        min-height: 60vh;
        border: 0;
        border-radius: 0;
    }
    .mail-body { height: auto; min-height: 60vh; }
}

/* Schmal: kein Vollhoehen-Modus. Eine auf 100vh fixierte Seite ist auf dem
   Handy unbrauchbar, sobald die Tastatur aufgeht oder die Adressleiste
   einfaehrt - dort scrollt wieder die Seite als Ganzes. */
@media (max-width: 900px) {
    body.app-fixed { overflow: auto; }
    body.app-fixed .page { height: auto; min-height: 100vh; }
    body.app-fixed .main { overflow: visible; }
    body.app-fixed .main > .container { height: auto; display: block; }
    body.app-fixed .split { margin-bottom: var(--s-5); }
    body.app-fixed .split > .card { margin-bottom: var(--s-5); }
    body.app-fixed .split > .card > .list,
    body.app-fixed .split-detail { overflow-y: visible; }
    body.app-fixed .split-detail { padding-inline: 0; }
}

/* Zweizeiliger Listeneintrag: Adresse oben, Name/Beschreibung darunter. */
.stack { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.stack > * { display: block; }

/* Angemeldete Person in der Kopfzeile: Text, kein Knopf. */
.nav-user { cursor: default; max-width: 16rem; }
.nav-user:hover { background: none; }
