/* Shared design tokens and building blocks. --accent* and, for brands with their own color scheme (BrandPalette), the
   color tokens below are set per brand by the layouts (LoginBrand.CssVariables); these values are the defaults. */
:root {
    --accent: #FEED00;
    --accent-text: #0A0D15;
    --accent-border: #C4B600;
    --accent-rgb: 254, 237, 0;
    --font-family: 'Open Sans', 'Segoe UI', Calibri, sans-serif;
    /* Factor for every font size (calc(<size> * var(--font-scale))); the app shell lowers it (app.css). */
    --font-scale: 1;
    --page-background: #FAF9F5;
    --surface: #FFFFFF;
    --text-primary: #111111;
    --text-body: #555555;
    --text-secondary: #666666;
    --text-muted: #999999;
    --text-faint: #BBBBBB;
    --field-background: #FAFAF8;
    --field-border: #E0E0D8;
    --card-border: #EEEEEE;
    --divider: #F0F0EA;
    /* Chat surfaces: sidebar of the chat pages, own message bubble and composer border. */
    --sidebar-background: #F3F2EC;
    --message-background: #EFEEE8;
    --composer-border: #D6D5CC;
    --error: #EF4444;
    --error-text: #B91C1C;
    --error-rgb: 239, 68, 68;
    --error-surface: #FEF2F2;
    --primary: #111111;
    --primary-hover: #000000;
    --on-primary: #FFFFFF;
    --on-primary-muted: #CFCFCF;
    /* Headings and titles of list entries. */
    --heading: var(--text-primary);
    /* Inline links (e.g. "Ganzer Lernplan", citations); both keep 4.5:1 on --page-background and --field-background. */
    --link: var(--text-primary);
    --link-hover: #000000;
    /* Accent for text on --primary; set per brand by MainLayout when the brand accent has enough contrast there. */
    --accent-on-dark: var(--on-primary);
    --notice: #805B00;
    --notice-surface: #FFF8E6;
    --notice-border: #E4C264;
    --success: #176B44;
    --success-surface: #EEF8F1;
    --success-border: #A9D7BB;
    /* Work in progress (e.g. "Wird verarbeitet"); --info keeps a contrast of at least 4.5:1 on --info-surface. */
    --info: #1D4ED8;
    --info-surface: #EFF4FF;
    --info-border: #A9C1F5;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    /* Cards lie flat on the page and are set apart by their border; only layers that float above the page (menus,
       dialogs, popovers, toasts) cast --overlay-shadow (#908). */
    --card-shadow: none;
    --overlay-shadow: 0 12px 32px rgba(0, 0, 0, 0.16);
    --accent-focus-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.24);
    --error-focus-shadow: 0 0 0 3px rgba(var(--error-rgb), 0.2);
    /* Radius scale (#908): --radius-sm for small inline elements (badges, status labels, icon buttons, inner chips),
       --card-radius for every surface (cards, fields, menus, dialogs, notices); pills (999px) and circles (50%) only
       where the shape carries meaning. No other radius values. */
    --radius-sm: 6px;
    --card-radius: 10px;
    --field-radius: var(--card-radius);
    /* Spacing follows a 4/8 px rhythm; cards have 24 px padding. */
    --card-padding: 24px;
    /* Buttons are pills. */
    --button-radius: 22px;
}

/* Dark display (#711), chosen per person on the account ("Dunkel", or "System" with a dark device setting). The layout puts
   the brand tokens on a wrapper (.app-brand-scope) and the theme class on the shell, so these values override the inherited
   brand palette; the brand accent stays. --primary turns light, so --accent-on-dark (text on --primary) follows --on-primary.
   Text tokens keep at least 4.5:1 on --page-background, --surface and --field-background. Both blocks declare the same
   tokens (ColorSchemeStylesTests). */
/* --brand-accent-on-dark keeps the brand's accent for dark grounds, which the dark tokens below reassign to --on-primary. */
.app-brand-scope { display: contents; --brand-accent-on-dark: var(--accent-on-dark); }

.app-theme--dark {
    color-scheme: dark;
    --page-background: #131416;
    --surface: #1C1E21;
    --text-primary: #DEDEDB;
    --text-body: #C4C5C7;
    --text-secondary: #A2A3A6;
    --text-muted: #8C8C8C;
    --text-faint: #5C5C5C;
    --field-background: #232529;
    --field-border: #3D4045;
    --card-border: #303236;
    --divider: #2B2D31;
    --sidebar-background: #18191C;
    --message-background: #2A2D31;
    --composer-border: #45484D;
    --error: #F87171;
    --error-text: #FCA5A5;
    --error-rgb: 248, 113, 113;
    --error-surface: #3B1D1D;
    --primary: #ECECEC;
    --primary-hover: #FFFFFF;
    --on-primary: #131416;
    --on-primary-muted: #4A4D52;
    --heading: var(--text-primary);
    --link: var(--text-primary);
    --link-hover: #FFFFFF;
    --accent-on-dark: var(--on-primary);
    --feature-surface: #262A30;
    --on-feature-surface: #F1F1F1;
    --on-feature-surface-muted: #B0B0B0;
    --accent-on-feature-surface: var(--brand-accent-on-dark);
    --notice: #F0C55A;
    --notice-surface: #2F2611;
    --notice-border: #6E5718;
    --success: #74D9A0;
    --success-surface: #12291C;
    --success-border: #2E6A49;
    --info: #9DB8FF;
    --info-surface: #17213A;
    --info-border: #3A5596;
    /* Fine light edge instead of a drop shadow (spec darstellung.md). */
    --card-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
    --overlay-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
    /* Dark-only tokens; components read them with today's value as fallback, so the light display stays unchanged.
       --accent-on-surface is the brand accent as text on page, card and field grounds, lightened just enough to keep
       4.5:1 for every brand. Primary buttons take the brand accent where it works on dark grounds, otherwise white. */
    --accent-on-surface: color-mix(in srgb, var(--brand-accent-on-dark) 85%, #FFFFFF);
    --cta: var(--brand-accent-on-dark);
    --cta-hover: color-mix(in srgb, var(--brand-accent-on-dark) 60%, #FFFFFF);
    --cta-text: var(--on-primary);
    --control-border: #6A6E76;
    --sidebar-action: var(--field-background);
    --sidebar-action-border: var(--field-border);
    --sidebar-action-icon: var(--accent-on-surface);
    --nav-active: var(--message-background);
    --deck-header-background: transparent;
    --generated-surface: rgba(var(--accent-rgb), 0.10);
    --generated-border: rgba(var(--accent-rgb), 0.40);
    --generated-text: var(--accent-on-surface);
    --marker-bottom: -4px;
    --marker-height: 6px;
}

@media (prefers-color-scheme: dark) {
    .app-theme--system {
        color-scheme: dark;
        --page-background: #131416;
        --surface: #1C1E21;
        --text-primary: #DEDEDB;
        --text-body: #C4C5C7;
        --text-secondary: #A2A3A6;
        --text-muted: #8C8C8C;
        --text-faint: #5C5C5C;
        --field-background: #232529;
        --field-border: #3D4045;
        --card-border: #303236;
        --divider: #2B2D31;
        --sidebar-background: #18191C;
        --message-background: #2A2D31;
        --composer-border: #45484D;
        --error: #F87171;
        --error-text: #FCA5A5;
        --error-rgb: 248, 113, 113;
        --error-surface: #3B1D1D;
        --primary: #ECECEC;
        --primary-hover: #FFFFFF;
        --on-primary: #131416;
        --on-primary-muted: #4A4D52;
        --heading: var(--text-primary);
        --link: var(--text-primary);
        --link-hover: #FFFFFF;
        --accent-on-dark: var(--on-primary);
        --feature-surface: #262A30;
        --on-feature-surface: #F1F1F1;
        --on-feature-surface-muted: #B0B0B0;
        --accent-on-feature-surface: var(--brand-accent-on-dark);
        --notice: #F0C55A;
        --notice-surface: #2F2611;
        --notice-border: #6E5718;
        --success: #74D9A0;
        --success-surface: #12291C;
        --success-border: #2E6A49;
        --info: #9DB8FF;
        --info-surface: #17213A;
        --info-border: #3A5596;
        --card-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
        --overlay-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
        /* Dark-only tokens; components read them with today's value as fallback, so the light display stays unchanged.
           --accent-on-surface is the brand accent as text on page, card and field grounds, lightened just enough to keep
           4.5:1 for every brand. Primary buttons take the brand accent where it works on dark grounds, otherwise white. */
        --accent-on-surface: color-mix(in srgb, var(--brand-accent-on-dark) 85%, #FFFFFF);
        --cta: var(--brand-accent-on-dark);
        --cta-hover: color-mix(in srgb, var(--brand-accent-on-dark) 60%, #FFFFFF);
        --cta-text: var(--on-primary);
        --control-border: #6A6E76;
        --sidebar-action: var(--field-background);
        --sidebar-action-border: var(--field-border);
        --sidebar-action-icon: var(--accent-on-surface);
        --nav-active: var(--message-background);
        --deck-header-background: transparent;
        --generated-surface: rgba(var(--accent-rgb), 0.10);
        --generated-border: rgba(var(--accent-rgb), 0.40);
        --generated-text: var(--accent-on-surface);
        --marker-bottom: -4px;
        --marker-height: 6px;
    }
}

/* Ground behind the shell (overscroll on touch devices). */
:root:has(.app-theme--dark) { background-color: #131416; }
@media (prefers-color-scheme: dark) {
    :root:has(.app-theme--system) { background-color: #131416; }
}

.bb-page {
    box-sizing: border-box;
    min-height: 100vh;
    padding: 40px 20px;
    background: var(--page-background);
    color: var(--text-primary);
    font-family: var(--font-family);
}

.bb-card {
    padding: var(--card-padding);
    border: 1px solid var(--card-border);
    border-radius: var(--card-radius);
    background: var(--surface);
    box-shadow: var(--card-shadow);
}

.bb-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--accent-text);
    font-size: calc(11px * var(--font-scale));
    font-weight: 800;
    letter-spacing: 0.08em;
    line-height: 1;
    white-space: nowrap;
}

/* Neutral label for a short qualifier next to text (e.g. "Nur für Admins"); the meaning is in the text, not the color. */
.bb-pill {
    display: inline-block;
    padding: 2px 10px;
    border: 1px solid var(--field-border);
    border-radius: 999px;
    color: var(--text-body);
    font-size: calc(12px * var(--font-scale));
    font-weight: 700;
    white-space: nowrap;
}

.bb-logo {
    width: auto;
    height: 38px;
    border-radius: var(--radius-sm);
    object-fit: contain;
}

.bb-headline {
    margin: 0 0 24px;
    color: var(--text-primary);
    font-size: calc(44px * var(--font-scale));
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.05;
}

.bb-marker {
    position: relative;
    z-index: 0;
    display: inline-block;
    isolation: isolate;
}

.bb-marker::after {
    position: absolute;
    z-index: -1;
    right: -1px;
    bottom: var(--marker-bottom, 6px);
    left: -1px;
    height: var(--marker-height, 12px);
    background: var(--accent);
    content: "";
    opacity: 0.9;
}

.bb-field {
    display: block;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    padding: 11px 14px;
    border: 2px solid var(--field-border);
    border-radius: var(--field-radius);
    outline: none;
    background: var(--field-background);
    color: var(--text-primary);
    font: 400 calc(15px * var(--font-scale))/1.4 var(--font-family);
    transition: border-color 200ms ease, box-shadow 200ms ease;
}

.bb-field:focus {
    border-color: var(--text-primary);
    box-shadow: var(--accent-focus-shadow);
}

.bb-btn-primary,
.bb-btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    box-sizing: border-box;
    padding: 8px 20px;
    border-radius: var(--button-radius);
    cursor: pointer;
    font: 600 calc(15px * var(--font-scale))/1.4 var(--font-family);
    text-decoration: none;
    transition: background 200ms ease, border-color 200ms ease, color 200ms ease;
}

.bb-btn-primary {
    border: 1px solid var(--cta, var(--primary));
    background: var(--cta, var(--primary));
    color: var(--cta-text, var(--on-primary));
}

.bb-btn-primary:hover:not(:disabled) {
    border-color: var(--cta-hover, var(--primary-hover));
    background: var(--cta-hover, var(--primary-hover));
}

/* Outlined in petrol; filled on hover (e.g. "Abmelden"). The dark display draws the outline in a quieter grey. */
.bb-btn-secondary {
    border: 1px solid var(--control-border, var(--primary));
    background: var(--surface);
    color: var(--primary);
}

.bb-btn-secondary:hover:not(:disabled) {
    border-color: var(--primary);
    background: var(--primary);
    color: var(--on-primary);
}

.bb-btn-primary:focus-visible,
.bb-btn-secondary:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 3px;
}

.bb-btn-primary:disabled,
.bb-btn-secondary:disabled,
.bb-field:disabled {
    cursor: wait;
    opacity: 0.72;
}

.bb-alert {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid var(--error);
    border-radius: var(--card-radius);
    background: var(--error-surface);
    color: var(--error-text);
    font-size: calc(13px * var(--font-scale));
    line-height: 1.5;
}

.bb-alert--success {
    border-color: var(--success-border);
    background: var(--success-surface);
    color: var(--success);
}

/* Form that sits inside running text (e.g. the logout button in an alert). */
.bb-inline-form { display: inline; }

/* Submit button that looks like an inline text link; used where an action must be a POST (e.g. logout). */
.bb-link-button {
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    cursor: pointer;
    font: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.bb-link-button:focus-visible {
    outline: 3px solid var(--text-primary);
    outline-offset: 2px;
}

/* Text for screen readers only (e.g. speaker labels in the chat). */
.bb-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* iOS Safari zooms into form fields below 16 px; desktop keeps the 15 px look. */
@media (max-width: 767.98px) {
    .bb-field { font-size: 16px; }
}

/* Icons as files under images/icons, drawn as CSS masks so they take the text color like a glyph; no inline SVG in
   components. Always decorative: the element carries aria-hidden="true", the button its own label. */
.bb-icon {
    display: inline-block;
    flex: none;
    width: 20px;
    height: 20px;
    background-color: currentColor;
    -webkit-mask: var(--bb-icon) center / contain no-repeat;
    mask: var(--bb-icon) center / contain no-repeat;
}
.bb-icon--copy { --bb-icon: url("../images/icons/copy.svg"); }
.bb-icon--arrow-up { --bb-icon: url("../images/icons/arrow-up.svg"); }
.bb-icon--stop { --bb-icon: url("../images/icons/stop.svg"); }
.bb-icon--chevron-left { --bb-icon: url("../images/icons/chevron-left.svg"); }
.bb-icon--new-chat { --bb-icon: url("../images/icons/new-chat.svg"); }
.bb-icon--info { --bb-icon: url("../images/icons/info.svg"); }
.bb-icon--thumb-up { --bb-icon: url("../images/icons/thumb-up.svg"); }
.bb-icon--thumb-down { --bb-icon: url("../images/icons/thumb-down.svg"); }
.bb-icon--alert { --bb-icon: url("../images/icons/alert.svg"); }
.bb-icon--file { --bb-icon: url("../images/icons/file.svg"); }
.bb-icon--close { --bb-icon: url("../images/icons/close.svg"); }
.bb-icon--retry { --bb-icon: url("../images/icons/retry.svg"); }
.bb-icon--search { --bb-icon: url("../images/icons/search.svg"); }
.bb-icon--check { --bb-icon: url("../images/icons/check.svg"); }
.bb-icon--exclamation { --bb-icon: url("../images/icons/exclamation.svg"); }

/* Spinner for a running action, e.g. inside a busy button; takes the text color. Always decorative (aria-hidden): the
   button text or a status message says what is happening. */
.bb-spinner {
    display: inline-block;
    flex: none;
    box-sizing: border-box;
    width: 18px;
    height: 18px;
    border: 3px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: bb-spin 0.9s linear infinite;
}

@keyframes bb-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    .bb-spinner { animation: none; border-right-color: currentColor; opacity: 0.6; }
}

/* Status badge, e.g. "Aktiv" or "Fehlgeschlagen" in lists and headers. The text carries the meaning; the color only
   supports it. Modifiers: --success, --info (in progress), --notice, --error, --neutral. */
.bb-status {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border: 1px solid var(--field-border);
    border-radius: var(--radius-sm);
    background: var(--field-background);
    color: var(--text-body);
    font-size: calc(12px * var(--font-scale));
    font-weight: 700;
    line-height: 1.4;
    white-space: nowrap;
}
.bb-status--success { border-color: var(--success-border); background: var(--success-surface); color: var(--success); }
.bb-status--info { border-color: var(--info-border); background: var(--info-surface); color: var(--info); }
.bb-status--notice { border-color: var(--notice-border); background: var(--notice-surface); color: var(--notice); }
.bb-status--error { border-color: var(--error); background: var(--error-surface); color: var(--error-text); }
.bb-status--neutral { border-color: var(--field-border); background: var(--divider); color: var(--text-body); }

/* Filter chips: toggle buttons with aria-pressed inside a role="group" (.bb-chips). They wrap on wider screens and
   form one swipeable row on smartphones. An optional count sits in .bb-chip__count. */
.bb-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.bb-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 0 16px;
    border: 1px solid var(--field-border);
    border-radius: 999px;
    background: transparent;
    color: var(--text-body);
    font: 600 calc(14px * var(--font-scale))/1.3 var(--font-family);
    white-space: nowrap;
    cursor: pointer;
}
.bb-chip:hover:not(:disabled) { border-color: var(--text-secondary); }
.bb-chip[aria-pressed="true"] {
    border-color: var(--text-body);
    background: var(--text-body);
    color: var(--surface);
}
.bb-chip:focus-visible {
    outline: 3px solid var(--accent-border);
    outline-offset: 2px;
}
.bb-chip:disabled {
    cursor: default;
    opacity: 0.6;
}
.bb-chip__count {
    color: inherit;
    font-weight: 400;
}

@media (max-width: 767.98px) {
    .bb-chips {
        flex-wrap: nowrap;
        overflow-x: auto;
        margin-inline: -4px;
        padding: 4px;
        scrollbar-width: none;
    }
    .bb-chips::-webkit-scrollbar { display: none; }
    .bb-chip { flex: none; }
}

/* Secondary information next to a title, e.g. "512 Chunks · NWB DMS-XML"; --text-secondary keeps 4.5:1 on white. */
.bb-meta {
    color: var(--text-secondary);
    font-size: calc(13px * var(--font-scale));
    line-height: 1.5;
}

/* Identifiers such as source ids and checksums. */
.bb-mono {
    font-family: var(--font-mono);
    font-size: 0.92em;
    overflow-wrap: anywhere;
}

/* Page with a main column and an aside (e.g. details next to a list): side by side from 1024 px, stacked below. */
.bb-split {
    display: grid;
    gap: 20px;
    align-items: start;
}
.bb-split > * { min-width: 0; }
.bb-split__aside {
    display: grid;
    gap: 20px;
}
@media (min-width: 1024px) {
    .bb-split { grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); }
}

/* List without bullets whose entries are separated by a divider, e.g. chunks or import jobs inside a card. */
.bb-rows {
    margin: 0;
    padding: 0;
    list-style: none;
}
.bb-rows > li {
    padding: 16px 0;
    border-bottom: 1px solid var(--divider);
}
.bb-rows > li:last-child { border-bottom: 0; }
