/* =========================================================================
   Oikonomos – App-CSS, ergänzt das MudBlazor-Theme (AppTheme.cs)
   - In der App (interaktiv) werden Farben über die MudBlazor-Variablen
     --mud-palette-* bezogen → Hell/Dunkel wechselt automatisch mit.
   - Die --hh-*-Tokens sind für Seiten OHNE MudThemeProvider gedacht
     (Login im statischen SSR, Fehlerseiten) und als Fallback.
   - Markenfarben tauschen: --hh-primary / --hh-akzent (+ Konstanten in AppTheme).
   Einbinden NACH MudBlazor.min.css.
   ========================================================================= */

/* ---------- Schrift: Inter, selbst gehostet (SIL OFL 1.1) ----------------
   Datei: wwwroot/fonts/InterVariable.woff2 (+ InterVariable-Italic.woff2)
   Quelle: https://rsms.me/inter/ bzw. github.com/rsms/inter (Release-ZIP) */
@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("fonts/InterVariable.woff2") format("woff2");
}
@font-face {
    font-family: "Inter";
    font-style: italic;
    font-weight: 100 900;
    font-display: swap;
    src: url("fonts/InterVariable-Italic.woff2") format("woff2");
}

/* ---------- Tokens -------------------------------------------------------- */
:root {
    /* Marke */
    --hh-primary: #1D5C63;        /* Petrol */
    --hh-primary-hover: #174A50;
    --hh-primary-text: #FFFFFF;
    --hh-primary-tint: #E4ECED;
    --hh-akzent: #C8963E;         /* Messing – nur dekorativ auf hellem Grund */
    --hh-akzent-text: #7D5A1C;    /* Messing dunkel – textfähig (6,27:1) */

    /* Semantik */
    --hh-success: #1B6E3A;
    --hh-warning: #945400;
    --hh-error: #B3261E;
    --hh-info: #1F6FA3;

    /* Flächen & Text */
    --hh-bg: #F4F6F8;
    --hh-surface: #FFFFFF;
    --hh-text: #1F2328;
    --hh-text-2: #545B66;
    --hh-text-disabled: #8A919C;
    --hh-line: #DDE1E6;
    --hh-line-input: #8A919C;

    /* Raster 4 px */
    --hh-space-1: 0.25rem;
    --hh-space-2: 0.5rem;
    --hh-space-3: 0.75rem;
    --hh-space-4: 1rem;
    --hh-space-5: 1.5rem;
    --hh-space-6: 2rem;
    --hh-space-7: 3rem;

    --hh-radius: 6px;
    --hh-radius-lg: 10px;
    --hh-focus: 0 0 0 3px color-mix(in srgb, var(--hh-primary) 45%, transparent);
    --hh-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    /* Beträge: in der App aus der MudBlazor-Palette, sonst Fallback */
    --hh-betrag-plus: var(--mud-palette-success, var(--hh-success));
    --hh-betrag-minus: var(--mud-palette-error, var(--hh-error));
}

/* Fallback-Dunkelmodus für Seiten ohne MudThemeProvider (Login) */
@media (prefers-color-scheme: dark) {
    .login-seite {
        --hh-primary: #6FB7BF;
        --hh-primary-hover: #93CBD1;
        --hh-primary-text: #0F2A2D;
        --hh-primary-tint: #25343A;
        --hh-akzent: #C8963E;
        --hh-akzent-text: #C8963E;
        --hh-success: #7BD08F;
        --hh-warning: #F0A04B;
        --hh-error: #F2918A;
        --hh-info: #8EC3EA;
        --hh-bg: #121417;
        --hh-surface: #1B1E23;
        --hh-text: #E6E8EB;
        --hh-text-2: #A9B0BA;
        --hh-text-disabled: #6B727C;
        --hh-line: #2F343B;
        --hh-line-input: #8B929C;
    }
}

/* ---------- Basis --------------------------------------------------------- */
html, body {
    font-family: var(--hh-font);
    /* Inter: cv05 = „l“ mit Bogen, cv08 = „I“ mit Serifen → Il1 unterscheidbar */
    font-feature-settings: "cv05" 1, "cv08" 1;
    -webkit-font-smoothing: antialiased;
}

:focus-visible {
    outline: 2px solid var(--mud-palette-primary, var(--hh-primary));
    outline-offset: 2px;
}

/* „Zum Inhalt springen“ – nur bei Tastaturfokus sichtbar */
.sprung-link {
    position: absolute;
    left: var(--hh-space-4);
    top: -100px;
    z-index: 2000;
    padding: var(--hh-space-2) var(--hh-space-4);
    background: var(--mud-palette-surface, var(--hh-surface));
    color: var(--mud-palette-primary, var(--hh-primary));
    border-radius: var(--hh-radius);
    font-weight: 600;
}
.sprung-link:focus { top: var(--hh-space-2); }

main:focus { outline: none; }

/* ---------- Layout -------------------------------------------------------- */
/* Messing-Zierlinie unter der AppBar (dekorativ, 3px) */
.hh-appbar { border-bottom: 3px solid var(--hh-akzent); }
.hh-produktname { font-weight: 600; letter-spacing: -0.01em; }

.hh-kontext {
    display: inline-flex;
    align-items: center;
    gap: var(--hh-space-2);
    max-width: 32ch;
    font-size: 0.9375rem;
    font-weight: 500;
}
.hh-kontext-mandant {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.hh-jahr-button {
    font-variant-numeric: tabular-nums;
    border-color: currentColor !important;
}
@media (max-width: 599.98px) {
    .hh-kontext { display: none; }   /* Jahr-Button bleibt sichtbar */
}

.hh-drawer { border-right: 1px solid var(--mud-palette-divider); }
.hh-nav .mud-nav-link { min-height: 44px; }          /* Klickfläche ≥ 44 px */
.hh-nav .mud-nav-link.active { font-weight: 600; }

.hh-inhalt {
    padding-top: var(--hh-space-5);
    padding-bottom: var(--hh-space-7);
}

/* ---------- Seitenkopf: Titel links, Aktionen rechts ---------------------- */
.seitenkopf {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--hh-space-3) var(--hh-space-4);
    margin-bottom: var(--hh-space-5);
}
.seitenkopf-titel { min-width: 0; }
.seitenkopf-titel h1,
.seitenkopf-titel .mud-typography-h4 { margin: 0; }
.seitenkopf-untertitel {
    margin-top: var(--hh-space-1);
    color: var(--mud-palette-text-secondary, var(--hh-text-2));
}
.seitenkopf-aktionen {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--hh-space-2);
}

/* ---------- Zahlen & Beträge ---------------------------------------------- */
.tabular,
.betrag,
.mud-table-cell.spalte-betrag,
.mud-table-cell.spalte-zahl,
.mud-input input.betrag-eingabe {
    font-variant-numeric: tabular-nums lining-nums;
}

.betrag {
    display: inline-block;
    min-width: 9ch;
    text-align: right;
    white-space: nowrap;      /* nie „1.234,“ / „56 €“ umbrechen */
}
.betrag-positiv { color: var(--hh-betrag-plus); }
.betrag-negativ { color: var(--hh-betrag-minus); }
.betrag-null    { color: var(--mud-palette-text-secondary, var(--hh-text-2)); }
.betrag-summe {
    font-weight: 600;
    border-top: 1px solid currentColor;
    padding-top: 2px;
}
.betrag-endsumme {
    font-weight: 700;
    border-bottom: 3px double currentColor;
}

/* Betragsspalten in MudTable/MudDataGrid: Kopf + Zellen rechtsbündig */
.mud-table-cell.spalte-betrag,
.mud-table-cell.spalte-zahl,
th.spalte-betrag,
th.spalte-zahl { text-align: right; white-space: nowrap; }
th.spalte-betrag .column-header,
th.spalte-zahl .column-header { justify-content: flex-end; }

/* Eingabefeld für Beträge rechtsbündig (MudNumericField Class="betrag-eingabe") */
.betrag-eingabe input { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Tabellen ------------------------------------------------------ */
.mud-table-head .mud-table-cell {
    font-weight: 600;
    color: var(--mud-palette-text-secondary);
    white-space: nowrap;
}
.mud-table-dense .mud-table-row { height: 40px; }
.mud-table-foot .mud-table-cell { font-weight: 600; }
/* Ausgewählte Zeile deutlich, nicht nur über Farbe: linker Balken */
.mud-table-row.zeile-ausgewaehlt > td:first-child {
    box-shadow: inset 4px 0 0 var(--mud-palette-primary);
}
.zeile-storniert > td { color: var(--mud-palette-text-secondary); text-decoration: line-through; }
.zeile-festgeschrieben > td:first-child::before {
    content: "🔒\FE0E";
    margin-right: var(--hh-space-1);
    font-size: 0.8em;
    color: var(--mud-palette-text-secondary);
}

/* ---------- Formulare ----------------------------------------------------- */
.formular-raster {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
    gap: var(--hh-space-4) var(--hh-space-5);
}
.formular-raster .breit { grid-column: 1 / -1; }
.formular-abschnitt + .formular-abschnitt { margin-top: var(--hh-space-6); }
.formular-abschnitt > h2 { font-size: 1.125rem; font-weight: 600; margin: 0 0 var(--hh-space-3); }
.pflicht-hinweis {
    font-size: 0.8125rem;
    color: var(--mud-palette-text-secondary, var(--hh-text-2));
}
.formular-aktionen {
    display: flex;
    flex-wrap: wrap;
    gap: var(--hh-space-2);
    justify-content: flex-end;
    margin-top: var(--hh-space-5);
    padding-top: var(--hh-space-4);
    border-top: 1px solid var(--mud-palette-divider, var(--hh-line));
}
/* Validierungstexte etwas größer als MudBlazor-Standard */
.mud-input-helper-text.mud-input-error { font-size: 0.8125rem; }

/* ---------- Leerer Zustand ------------------------------------------------ */
.leerzustand {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--hh-space-2);
    padding: var(--hh-space-7) var(--hh-space-4);
    color: var(--mud-palette-text-secondary, var(--hh-text-2));
}
.leerzustand .mud-icon-root,
.leerzustand-icon {
    font-size: 3rem;
    width: 3rem;
    height: 3rem;
    opacity: 0.7;
}
.leerzustand-titel {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--mud-palette-text-primary, var(--hh-text));
}
.leerzustand-text { max-width: 48ch; }
.leerzustand-aktionen { margin-top: var(--hh-space-3); display: flex; gap: var(--hh-space-2); flex-wrap: wrap; justify-content: center; }

/* ---------- Status-Chips (Icon + Text, nie nur Farbe) --------------------- */
.status-chip { font-weight: 600; }
.status-chip .mud-chip-icon { margin-inline-end: 4px; }

/* ---------- Dialog für unumkehrbare Aktionen ------------------------------ */
.dialog-unumkehrbar .dialog-warnung {
    display: flex;
    gap: var(--hh-space-3);
    padding: var(--hh-space-3) var(--hh-space-4);
    border-left: 4px solid var(--mud-palette-error);
    background: color-mix(in srgb, var(--mud-palette-error) 8%, transparent);
    border-radius: var(--hh-radius);
}
.dialog-zusammenfassung {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: var(--hh-space-1) var(--hh-space-4);
    margin: var(--hh-space-4) 0;
}
.dialog-zusammenfassung dt { color: var(--mud-palette-text-secondary); }
.dialog-zusammenfassung dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Blazor-Fehlerleiste ------------------------------------------- */
#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    z-index: 3000;
    padding: var(--hh-space-3) var(--hh-space-5);
    background: #FDECEA;
    color: #5F1410;
    border-top: 2px solid #B3261E;
    box-shadow: 0 -2px 8px rgb(0 0 0 / 0.15);
}
#blazor-error-ui .reload { color: inherit; font-weight: 600; margin-left: var(--hh-space-2); }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: var(--hh-space-4); top: var(--hh-space-3); }

/* =========================================================================
   Login (statisches SSR, ohne MudBlazor-Komponenten)
   Markup-Gerüst:
   <div class="login-seite">
     <main class="login-karte">
       <div class="login-logo">Oikonomos</div>
       <p class="login-slogan">Treu verwalten, was anvertraut ist.</p>
       <h1>Anmelden</h1>
       <p class="login-untertitel">Bitte melden Sie sich mit Ihrem Benutzerkonto an.</p>
       <div class="login-fehler" role="alert">…</div>
       <form method="post">
         <div class="login-feld">
           <label for="benutzer">Benutzername oder E-Mail</label>
           <input id="benutzer" name="Benutzer" autocomplete="username" required>
         </div>
         <div class="login-feld">
           <label for="passwort">Passwort</label>
           <input id="passwort" name="Passwort" type="password" autocomplete="current-password" required>
           <span class="login-feld-fehler">…</span>
         </div>
         <label class="login-check"><input type="checkbox" name="Merken"> Angemeldet bleiben</label>
         <button class="login-button" type="submit">Anmelden</button>
       </form>
       <p class="login-fuss"><a href="/passwort-vergessen">Passwort vergessen?</a></p>
     </main>
   </div>
   ========================================================================= */
.login-seite {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    grid-template-columns: minmax(0, 26rem);
    justify-content: center;
    padding: var(--hh-space-5) var(--hh-space-4);
    background: var(--hh-bg);
    color: var(--hh-text);
    font-family: var(--hh-font);
    font-size: 1rem;
    line-height: 1.5;
}
.login-karte {
    width: 100%;
    max-width: 26rem;
    padding: var(--hh-space-6);
    background: var(--hh-surface);
    border: 1px solid var(--hh-line);
    border-radius: var(--hh-radius-lg);
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 8px 24px rgb(0 0 0 / 0.06);
}
.login-karte { border-top: 4px solid var(--hh-akzent); }
.login-logo { margin-bottom: var(--hh-space-1); color: var(--hh-primary); font-weight: 700; font-size: 1.5rem; letter-spacing: -0.01em; }
.login-slogan { margin: 0 0 var(--hh-space-5); color: var(--hh-akzent-text); font-style: italic; font-size: 0.9375rem; }
.login-karte h1 { font-size: 1.5rem; font-weight: 600; margin: 0 0 var(--hh-space-1); }
.login-untertitel { margin: 0 0 var(--hh-space-5); color: var(--hh-text-2); }

.login-feld { display: flex; flex-direction: column; gap: var(--hh-space-1); margin-bottom: var(--hh-space-4); }
.login-feld label { font-weight: 600; font-size: 0.9375rem; }
.login-feld input {
    font: inherit;
    min-height: 44px;
    padding: var(--hh-space-2) var(--hh-space-3);
    color: var(--hh-text);
    background: var(--hh-surface);
    border: 1px solid var(--hh-line-input);
    border-radius: var(--hh-radius);
    transition: border-color 120ms ease, box-shadow 120ms ease;
}
.login-feld input:hover { border-color: var(--hh-text-2); }
.login-feld input:focus { outline: none; border-color: var(--hh-primary); box-shadow: var(--hh-focus); }
.login-feld input[aria-invalid="true"],
.login-feld input.invalid { border-color: var(--hh-error); }
.login-feld-fehler,
.login-feld .validation-message { color: var(--hh-error); font-size: 0.875rem; }

.login-check { display: flex; align-items: center; gap: var(--hh-space-2); margin-bottom: var(--hh-space-5); cursor: pointer; }
.login-check input { width: 1.125rem; height: 1.125rem; accent-color: var(--hh-primary); }

.login-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 44px;
    padding: var(--hh-space-2) var(--hh-space-4);
    font: inherit;
    font-weight: 600;
    color: var(--hh-primary-text);
    background: var(--hh-primary);
    border: 0;
    border-radius: var(--hh-radius);
    cursor: pointer;
    transition: background-color 120ms ease;
}
.login-button:hover { background: var(--hh-primary-hover); }
.login-button:focus-visible { outline: none; box-shadow: var(--hh-focus); }
.login-button:disabled { opacity: 0.6; cursor: not-allowed; }

.login-fehler {
    margin-bottom: var(--hh-space-4);
    padding: var(--hh-space-3) var(--hh-space-4);
    border-left: 4px solid var(--hh-error);
    background: color-mix(in srgb, var(--hh-error) 10%, var(--hh-surface));
    border-radius: var(--hh-radius);
}
.login-fehler:empty { display: none; }
.login-fuss { margin: var(--hh-space-5) 0 0; text-align: center; font-size: 0.9375rem; }
.login-fuss a, .login-karte a { color: var(--hh-primary); }

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

/* ---------- Druck --------------------------------------------------------- */
.nur-druck { display: none; }

@media print {
    @page { size: A4; margin: 15mm 12mm 18mm; }

    html, body {
        background: #FFFFFF !important;
        color: #000000 !important;
        font-size: 10pt;
    }

    .mud-appbar, .mud-drawer, .mud-overlay, .mud-snackbar-provider,
    .sprung-link, #blazor-error-ui, .seitenkopf-aktionen,
    .mud-table-pagination, .mud-table-toolbar .mud-button-root,
    .mud-button-root, .mud-icon-button, .kein-druck { display: none !important; }

    .nur-druck { display: block !important; }

    .mud-main-content { padding-top: 0 !important; margin: 0 !important; }
    .mud-container, .hh-inhalt { max-width: none !important; padding: 0 !important; }
    .mud-paper { box-shadow: none !important; border: 0 !important; }

    .mud-table-container { overflow: visible !important; max-height: none !important; }
    .mud-table-root { width: 100%; border-collapse: collapse; }
    .mud-table-head { display: table-header-group; }   /* Kopf auf jeder Seite */
    .mud-table-foot { display: table-footer-group; }
    .mud-table-row { break-inside: avoid; }
    .mud-table-cell {
        padding: 2pt 4pt !important;
        border-bottom: 0.5pt solid #999 !important;
        color: #000 !important;
    }
    /* Beträge schwarz drucken – Vorzeichen bleibt die Information */
    .betrag-positiv, .betrag-negativ { color: #000 !important; }
    .mud-chip { border: 0.5pt solid #666 !important; background: none !important; color: #000 !important; }

    h1, h2, h3 { break-after: avoid; }
    a { color: inherit; text-decoration: none; }
}

/* Registerkarten ohne Großbuchstaben (bessere Lesbarkeit, siehe Designsystem) */
.mud-tab { text-transform: none; letter-spacing: normal; }
