/* ==========================================================================
   Bähr Holzmanufaktur – Basis-Styles und Corporate Design
   Farbwelt: dunkles Waldgrün (#2E5339), Naturtöne, warme Hintergründe.

   Verbindliche Design-Entscheidungen (Begründungen, Kontrastwerte, Regeln):
   design-system/baehr-holzmanufaktur-verwaltung/MASTER.md
   Keine rohen Hexwerte in Razor-Dateien – immer die Tokens von hier verwenden.
   ========================================================================== */

:root {
    /* ---- Marke ---- */
    --bh-primary: #2E5339;
    --bh-primary-dark: #22402B;
    --bh-primary-light: #3E6B4C;
    --bh-secondary: #7A9B76;   /* kein weißer Fließtext darauf (3,1:1) */
    --bh-tertiary: #A67B5B;    /* kein weißer Fließtext darauf (3,8:1) */

    /* ---- Flächen und Text ---- */
    --bh-bg: #F7F5F0;
    --bh-surface: #FFFFFF;
    --bh-surface-sunken: #FBFAF7;
    --bh-text: #22301F;
    --bh-text-secondary: #5C6B58;
    --bh-on-primary: #F7F5F0;
    --bh-border: #E3E0D7;      /* nur dekorative Trennlinien (1,3:1) */
    --bh-border-strong: #8C8677; /* Rahmen bedienbarer Elemente (3,6:1) */

    /* ---- Signalfarben (alle ≥ 4,5:1 als Text und mit Weiß darauf) ---- */
    --bh-error: #C62828;
    --bh-error-text: #C62828;
    --bh-warning: #8A5A1C;     /* Ocker der Belegvorlage; vorher #DB8B00 = 2,7:1 */
    --bh-warning-text: #8A5A1C;
    --bh-success: #2E6B3C;     /* vorher #3C8C4E = 4,2:1 */
    --bh-success-text: #2E6B3C;
    --bh-info: #1F6F8B;        /* vorher #4E7A8A = 4,7:1 und auf der Karte nicht als Blau erkennbar */
    --bh-info-text: #1F6F8B;

    /* ---- Getönte Meldungsflächen ---- */
    --bh-success-bg: #EAF5EC;
    --bh-success-border: #BCDCC3;
    --bh-success-on-bg: #205B2E;
    --bh-error-bg: #FDEBEB;
    --bh-error-border: #F0C1C1;
    --bh-error-on-bg: #8E1F1F;
    --bh-notice-bg: #FFF7E8;
    --bh-notice-border: #F0DCB0;

    /* ---- Fokus ---- */
    --bh-focus-ring: #3E6B4C;
    --bh-focus-ring-inverse: #F7F5F0; /* auf Waldgrün-Flächen (Appbar) */

    /* ---- Abstände (dichte 4-px-Skala) ---- */
    --bh-space-1: 4px;
    --bh-space-2: 8px;
    --bh-space-3: 12px;
    --bh-space-4: 16px;
    --bh-space-5: 24px;
    --bh-space-6: 32px;
    --bh-space-7: 48px;

    /* ---- Schriftgrößen ---- */
    --bh-text-xs: .75rem;      /* Untergrenze, nie kleiner */
    --bh-text-sm: .8125rem;
    --bh-text-base: .9rem;     /* Tabellen, Formulare */
    --bh-text-md: 1rem;        /* Fließtext */
    --bh-text-lg: 1.05rem;
    --bh-text-xl: 1.25rem;
    --bh-text-2xl: 1.5rem;
    --bh-leading-body: 1.5;
    --bh-leading-tight: 1.3;

    /* ---- Form ---- */
    --bh-radius-sm: 6px;
    --bh-radius: 10px;
    --bh-radius-lg: 14px;
    --bh-shadow: 0 1px 3px rgba(34, 48, 31, .08), 0 4px 14px rgba(34, 48, 31, .06);
    --bh-shadow-hover: 0 4px 16px rgba(34, 48, 31, .16);

    /* ---- Bewegung ---- */
    --bh-duration-fast: 120ms;
    --bh-duration: 180ms;
    --bh-duration-slow: 280ms;
    --bh-ease: cubic-bezier(.2, .7, .3, 1);
}

html, body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bh-bg);
    color: var(--bh-text);
    line-height: var(--bh-leading-body);
}

/* Der Titel bekommt beim Seitenwechsel programmatisch den Fokus – dort ist der Ring
   irreführend. Bedienelemente behalten ihn (siehe :focus-visible weiter unten). */
h1:focus { outline: none; }

/* Sichtbarer Tastaturfokus ist Pflicht; einzelne Regeln dürfen ihn nur ersetzen,
   nie ersatzlos entfernen. */
:focus-visible {
    outline: 2px solid var(--bh-focus-ring);
    outline-offset: 2px;
}

/* Auf Waldgrün-Flächen wäre der grüne Ring unsichtbar (1,4:1). */
.mud-appbar :focus-visible,
.auth-header :focus-visible {
    outline-color: var(--bh-focus-ring-inverse);
}

/* Bewegung ist Rückmeldung, kein Schmuck – wer sie abbestellt, bekommt keine. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}

.baehr-main { background-color: var(--bh-bg); min-height: 100vh; }
.baehr-appbar-title { font-weight: 600; letter-spacing: .2px; }
.baehr-nav { padding: var(--bh-space-3) var(--bh-space-2); }

.baehr-global-search { width: 420px; max-width: 40vw; }
.baehr-global-search .mud-input-control { margin: 0; }
.baehr-global-search .mud-input-outlined { background: rgba(255, 255, 255, .95); border-radius: var(--bh-radius-sm); }

.baehr-kpi { cursor: pointer; transition: box-shadow var(--bh-duration) var(--bh-ease), transform var(--bh-duration) var(--bh-ease); }
.baehr-kpi:hover { box-shadow: var(--bh-shadow-hover); transform: translateY(-1px); }

/* ---------- Statisches Auth-Layout (Login, Passwort, 2FA) ---------- */

.auth-shell { min-height: 100vh; display: flex; flex-direction: column; }

.auth-header {
    background: var(--bh-primary);
    padding: var(--bh-space-3) var(--bh-space-5);
}

.auth-header-brand {
    color: var(--bh-on-primary);
    text-decoration: none;
    font-weight: 600;
    font-size: var(--bh-text-lg);
}

.auth-page {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: var(--bh-space-7) var(--bh-space-4);
}

.auth-card {
    background: var(--bh-surface);
    border-radius: var(--bh-radius);
    box-shadow: var(--bh-shadow);
    border: 1px solid var(--bh-border);
    padding: var(--bh-space-6);
    width: 100%;
    max-width: 420px;
}

.auth-brand { text-align: center; margin-bottom: var(--bh-space-5); }
.auth-brand h1 { font-size: var(--bh-text-2xl); line-height: var(--bh-leading-tight); margin: var(--bh-space-3) 0 var(--bh-space-1); }
.auth-brand p { color: var(--bh-text-secondary); margin: 0; font-size: var(--bh-text-base); }

/* Wortmarke auf den Anmeldeseiten - ersetzt das frühere Platzhalter-Kürzel "BH". */
.auth-wordmark {
    display: block;
    width: min(240px, 78%);
    height: auto;
    margin: 0 auto;
}

/* Markenzeichen in der Kopfleiste, als Kachel auf dem grünen Balken. */
.baehr-appbar-logo {
    width: 30px;
    height: 30px;
    border-radius: var(--bh-radius-sm);
    margin-right: var(--bh-space-3);
    flex: 0 0 auto;
}

/* Bleibt für die Fehlerseiten (rotes Ausrufezeichen). */
.auth-logo {
    width: 56px; height: 56px;
    margin: 0 auto;
    border-radius: var(--bh-radius-lg);
    background: var(--bh-primary);
    color: var(--bh-on-primary);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: var(--bh-text-xl);
}

.auth-logo-error { background: var(--bh-error); }

.auth-field { margin-bottom: var(--bh-space-4); display: flex; flex-direction: column; gap: var(--bh-space-1); }
.auth-field label { font-size: var(--bh-text-sm); font-weight: 600; color: var(--bh-text-secondary); }

.auth-field input {
    padding: var(--bh-space-3);
    /* border-strong statt border: Rahmen bedienbarer Elemente brauchen 3:1 (WCAG 1.4.11) */
    border: 1px solid var(--bh-border-strong);
    border-radius: var(--bh-radius-sm);
    font-size: var(--bh-text-md);
    background: var(--bh-surface-sunken);
    color: var(--bh-text);
}

.auth-field input:focus-visible {
    outline: 2px solid var(--bh-focus-ring);
    outline-offset: 1px;
    border-color: var(--bh-focus-ring);
}

.auth-field input:disabled { background: var(--bh-bg); color: var(--bh-text-secondary); cursor: not-allowed; }

.auth-checkbox { display: flex; align-items: center; gap: var(--bh-space-2); margin: var(--bh-space-1) 0 var(--bh-space-4); font-size: var(--bh-text-base); }

.auth-submit {
    display: block;
    width: 100%;
    min-height: 44px;
    padding: var(--bh-space-3) var(--bh-space-4);
    background: var(--bh-primary);
    color: var(--bh-on-primary);
    font-weight: 600;
    font-size: var(--bh-text-md);
    border: none;
    border-radius: var(--bh-radius-sm);
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    box-sizing: border-box;
    transition: background var(--bh-duration-fast) var(--bh-ease);
}

.auth-submit:hover { background: var(--bh-primary-dark); }

.auth-button-secondary,
.auth-button-danger {
    display: inline-block;
    min-height: 40px;
    padding: var(--bh-space-2) var(--bh-space-4);
    border-radius: var(--bh-radius-sm);
    font-weight: 600;
    font-size: var(--bh-text-base);
    text-decoration: none;
    cursor: pointer;
    border: 1px solid var(--bh-border-strong);
    background: var(--bh-surface);
    color: var(--bh-text);
    transition: background var(--bh-duration-fast) var(--bh-ease), border-color var(--bh-duration-fast) var(--bh-ease), color var(--bh-duration-fast) var(--bh-ease);
}

.auth-button-secondary:hover { border-color: var(--bh-primary); color: var(--bh-primary); }

.auth-button-danger { border-color: var(--bh-error); color: var(--bh-error-text); }
.auth-button-danger:hover { background: var(--bh-error); color: #fff; }

.auth-links { margin-top: var(--bh-space-4); text-align: center; font-size: var(--bh-text-base); }
.auth-links a { color: var(--bh-primary); text-decoration: none; }
.auth-links a:hover { text-decoration: underline; }

.auth-error, .validation-message { color: var(--bh-error-text); font-size: var(--bh-text-sm); }

.auth-notice {
    background: var(--bh-notice-bg);
    border: 1px solid var(--bh-notice-border);
    border-radius: var(--bh-radius-sm);
    padding: var(--bh-space-3) var(--bh-space-4);
    margin-bottom: var(--bh-space-4);
    font-size: var(--bh-text-base);
}

.auth-notice-error { background: var(--bh-error-bg); border-color: var(--bh-error-border); }

.auth-steps { padding-left: var(--bh-space-5); }
.auth-steps li { margin-bottom: var(--bh-space-3); }

.qr-code { margin: var(--bh-space-3) 0; }
.qr-code svg { width: 180px; height: 180px; }

.status-message {
    border-radius: var(--bh-radius-sm);
    padding: var(--bh-space-3) var(--bh-space-4);
    margin-bottom: var(--bh-space-4);
    font-size: var(--bh-text-base);
}

.status-message-success { background: var(--bh-success-bg); border: 1px solid var(--bh-success-border); color: var(--bh-success-on-bg); }
.status-message-error { background: var(--bh-error-bg); border: 1px solid var(--bh-error-border); color: var(--bh-error-on-bg); }

.recovery-codes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: var(--bh-space-2);
    margin: var(--bh-space-4) 0;
}

.recovery-codes code {
    background: var(--bh-bg);
    border: 1px solid var(--bh-border);
    border-radius: var(--bh-radius-sm);
    padding: var(--bh-space-2);
    text-align: center;
    font-size: var(--bh-text-base);
}

/* ---------- Kontoverwaltung ---------- */

.manage-page { max-width: 960px; margin: var(--bh-space-6) auto; padding: 0 var(--bh-space-4); }
.manage-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: var(--bh-space-2); }
.manage-back { color: var(--bh-primary); text-decoration: none; font-size: var(--bh-text-base); }
.manage-container { display: flex; gap: var(--bh-space-5); margin-top: var(--bh-space-4); flex-wrap: wrap; }
.manage-nav { flex: 0 0 220px; }
.manage-content {
    flex: 1;
    min-width: 280px;
    background: var(--bh-surface);
    border: 1px solid var(--bh-border);
    border-radius: var(--bh-radius);
    box-shadow: var(--bh-shadow);
    padding: var(--bh-space-5);
}

.manage-form { max-width: 480px; }
.manage-form .auth-submit { width: auto; padding: var(--bh-space-3) var(--bh-space-5); }
.manage-hint { color: var(--bh-text-secondary); font-size: var(--bh-text-sm); }
.manage-actions { display: flex; gap: var(--bh-space-3); flex-wrap: wrap; margin: var(--bh-space-3) 0; }

.manage-nav-list { list-style: none; margin: 0; padding: 0; }
.manage-nav-list li a {
    display: block;
    min-height: 40px;
    padding: var(--bh-space-3) var(--bh-space-4);
    border-radius: var(--bh-radius-sm);
    color: var(--bh-text);
    text-decoration: none;
    font-size: var(--bh-text-base);
    margin-bottom: var(--bh-space-1);
    box-sizing: border-box;
}
.manage-nav-list li a:hover { background: #EDEAE2; }
.manage-nav-list li a.active { background: var(--bh-primary); color: var(--bh-on-primary); font-weight: 600; }

/* ---------- Blazor-Fehlerleiste ---------- */

#blazor-error-ui {
    color-scheme: light only;
    background: var(--bh-notice-bg);
    border-top: 1px solid var(--bh-notice-border);
    bottom: 0;
    box-shadow: 0 -1px 4px rgba(0, 0, 0, .1);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: .6rem 1.25rem .7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

.blazor-error-boundary {
    background: var(--bh-error);
    color: #fff;
    padding: var(--bh-space-4);
    border-radius: var(--bh-radius-sm);
}

.blazor-error-boundary::before { content: "Ein Fehler ist aufgetreten. "; font-weight: 600; }

/* ---------- Vertriebskarte (Leaflet) ----------
   Marker und Popups erzeugt Leaflet außerhalb des Blazor-Baums; die Styles
   müssen daher global stehen (keine CSS-Isolation).                          */

.bh-map {
    width: 100%;
    height: 560px;
    border-radius: var(--bh-radius);
    overflow: hidden;
    z-index: 0; /* bleibt unter MudBlazor-Overlays und -Dialogen */
}

.bh-map-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 560px;
    background: var(--bh-bg);
    border: 1px dashed var(--bh-border);
    border-radius: var(--bh-radius);
}

.bh-map-pin-wrapper { background: transparent; border: 0; }

.bh-map-pin {
    display: block;
    width: 20px;
    height: 20px;
    margin-left: 1px;
    border: 2px solid #fff;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    box-shadow: 0 1px 3px rgba(34, 48, 31, .45);
}

/* Statuspunkt: Tabelle, Kartenlegende und Marker zeigen denselben Ton. */
.bh-status-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 8px;
    border: 1px solid rgba(255, 255, 255, .9);
    box-shadow: 0 0 0 1px rgba(34, 48, 31, .18);
    flex: 0 0 auto;
}

.bh-map-popup { font-size: var(--bh-text-base); color: var(--bh-text); }
.bh-map-popup-title { font-weight: 600; font-size: var(--bh-text-md); margin-bottom: var(--bh-space-1); }
/* Der Status steht bewusst als Text im Popup: Markerfarbe allein ist kein Informationsträger. */
.bh-map-popup-status { display: flex; align-items: center; margin-bottom: var(--bh-space-1); color: var(--bh-text-secondary); }
.bh-map-popup-line { color: var(--bh-text-secondary); line-height: var(--bh-leading-body); }

.bh-map-popup-button {
    margin-top: var(--bh-space-3);
    width: 100%;
    min-height: 44px; /* Touch-Trefferfläche – die Karte wird auch auf Tablets bedient */
    padding: var(--bh-space-2) var(--bh-space-3);
    font: inherit;
    font-weight: 600;
    color: var(--bh-on-primary);
    background: var(--bh-primary);
    border: 0;
    border-radius: var(--bh-radius-sm);
    cursor: pointer;
    transition: background var(--bh-duration-fast) var(--bh-ease);
}

.bh-map-popup-button:hover { background: var(--bh-primary-dark); }

/* ---------- Responsive ---------- */

@media (max-width: 600px) {
    .auth-card { padding: var(--bh-space-5) var(--bh-space-4); }
    .manage-nav { flex-basis: 100%; }
    .bh-map, .bh-map-empty { height: 420px; }
}
