/* MWS Dashboards — shell + per-dashboard styles. Vanilla CSS; tiny enough
 * that splitting by file isn't worth the import overhead. */

/* Color tokens.
 *
 * theme.js sets <html data-theme="light|dark"> on load; the
 * [data-theme="dark"] block below overrides the light defaults.
 * Browser `color-scheme` is also set so native UI (scrollbars, form
 * controls) follows along without us styling them explicitly. */
:root {
    --fg:           #1a2330;
    --fg-muted:     #5b6675;
    --bg:           #fafbfc;
    --card-bg:      #fff;
    --border:       #e3e6ea;
    --accent:       #144263;
    --accent-light: #6fa3c4;
    --accent-soft:  #eef3f7;
    --status-ok:    #34a853;
    --status-err:   #ea4335;
    --status-warn:  #fbbc04;
    --warn-soft:    #fff8e1;
    --warn-border:  #f6cf6a;
    /* Per-Einkaufsartikel badge tints — distinct semantics:
     *  allergen → red/rose (warning)
     *  customer → teal/blue (informational identifier) */
    --allergen-bg:     #fde7e9;
    --allergen-border: #d97a82;
    --allergen-fg:     #9b2c33;
    --customer-bg:     #e2f0ec;
    --customer-border: #6ba893;
    --customer-fg:     #1f5e4d;
    --code-bg:      #eef0f3;
    --accent-fg:    #fff;
    --accent-hover: #1a527a;
    --bg-soft:      #fafbfc;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --fg:           #e1e6ed;
    --fg-muted:     #97a3b3;
    --bg:           #0f141b;
    --card-bg:      #1a212c;
    --border:       #2a323e;
    --accent:       #4a86ad;
    --accent-light: #b7d3e6;
    --accent-soft:  #1d2a37;
    --status-ok:    #5cbe6f;
    --status-err:   #ef6f63;
    --status-warn:  #f0c252;
    --warn-soft:    #3a2f1c;
    --warn-border:  #8a6e2d;
    --allergen-bg:     #3a1e22;
    --allergen-border: #8a484f;
    --allergen-fg:     #f0a3a8;
    --customer-bg:     #1d2f2a;
    --customer-border: #4a8473;
    --customer-fg:     #9bd0bc;
    --code-bg:      #232a36;
    --accent-fg:    #0f141b;
    --accent-hover: #5e9bc3;
    --bg-soft:      #141a23;
    color-scheme: dark;
}

* { box-sizing: border-box; }

/* One unified focus ring across every interactive element. :focus-visible
 * means it only paints on keyboard nav, not on mouse clicks — keeps the
 * UI quiet for pointer users while keyboard users always know where they
 * are. Components that already paint their own focus state can override
 * with a more specific selector. */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--fg);
    font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
/* Flex column on the body lets header + footer claim their natural
 * heights and gives <main> the remaining vertical real estate. */
body {
    display: flex;
    flex-direction: column;
}

/* ─── shell chrome ────────────────────────────────────────────────────── */

header {
    display: flex;
    align-items: flex-end;
    gap: 1.5rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.5rem 0;
}
header .title-block {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    padding-bottom: .75rem;
}
header h1 {
    margin: 0;
    font-size: 1.3rem;
    color: var(--accent);
    font-weight: 700;
}
header .hint {
    color: var(--fg-muted);
    font-size: .8rem;
}

nav.tabs {
    display: flex;
    gap: .25rem;
    align-items: stretch;
    margin-left: auto;
}
nav.tabs a {
    display: block;
    padding: .5rem 1rem;
    color: var(--fg-muted);
    text-decoration: none;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    font-weight: 500;
    margin-bottom: -1px; /* sit on top of the header bottom border */
}
nav.tabs a:hover {
    background: var(--accent-soft);
    color: var(--fg);
}
nav.tabs a.active {
    background: var(--bg);
    color: var(--accent);
    border-color: var(--border);
    border-bottom: 1px solid var(--bg);
}

/* Theme toggle — segmented control of three icon buttons (Hell, Auto,
 * Dunkel). Sits at the far right of the header, separated from the tab
 * strip. The active state mirrors the saved preference, not the
 * computed theme — Auto is a meta-state independent of the effective
 * light/dark resolution. */
.theme-toggle {
    display: flex;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    align-self: center;
    margin-bottom: .75rem;
}
.theme-toggle .theme-btn {
    background: var(--card-bg);
    color: var(--fg-muted);
    border: none;
    padding: .35rem .55rem;
    font-size: .85rem;
    cursor: pointer;
    min-width: 1.9rem;
    line-height: 1;
}
.theme-toggle .theme-btn + .theme-btn {
    border-left: 1px solid var(--border);
}
.theme-toggle .theme-btn:hover {
    background: var(--accent-soft);
    color: var(--fg);
}
.theme-toggle .theme-btn.active {
    background: var(--accent);
    color: var(--accent-fg);
}

main {
    flex: 1 1 auto;
    min-height: 0;            /* allow children to shrink in flex layout */
    padding: 1rem 1.5rem;
    overflow: hidden;          /* per-section scroll instead of page scroll */
}

footer {
    flex: 0 0 auto;
    padding: .65rem 1.5rem;
    color: var(--fg-muted);
    font-size: .95rem;
    border-top: 1px solid var(--border);
    background: var(--card-bg);
}
/* Status line is the "lade …" / "N Treffer" feedback at the bottom-
 * left. Bumped from .8rem to a comfortable 1rem and made bold +
 * higher-contrast colours on customer request — the previous size
 * blended into the chrome and a user scanning the table for results
 * had no peripheral signal that a fetch was in progress. */
.status        { color: var(--fg);         font-weight: 600; font-size: 1rem; }
.status.ok     { color: var(--status-ok);  font-weight: 600; }
.status.error  { color: var(--status-err); font-weight: 600; }
.status.loading{ color: var(--status-warn);font-weight: 600; }

.empty {
    color: var(--fg-muted);
    text-align: center;
    padding: 4rem 1rem;
}

/* Full-page replacement shown by shell.js when /api/* returns 401.
   Deliberately minimal — body is wiped, no header, no navigation.
   Users return to MWS to re-mint a session. */
.auth-required {
    max-width: 32rem;
    margin: 6rem auto;
    padding: 0 1rem;
    color: var(--fg);
}
.auth-required h1 {
    font-size: 1.5rem;
    margin: 0 0 .75rem;
}
.auth-required p {
    color: var(--fg-muted);
    line-height: 1.5;
}

/* ─── per-dashboard primitives ────────────────────────────────────────── */

.page {
    display: grid;
    /* minmax(0, 1fr) — without the explicit 0 floor, the chart column
     * inherits min-content from the ECharts canvas inside (which has
     * stale inline width attributes between resize()s). That floor
     * pushes the 280 px sidebar past the page's right edge, where
     * `main { overflow: hidden }` clips it. The 0 lets the column
     * actually shrink and the sidebar stay anchored. */
    grid-template-columns: minmax(0, 1fr) 280px;
    grid-template-rows: auto 1fr;  /* header row natural, charts/filters fill */
    height: 100%;
    gap: 1rem;
    min-height: 0;
}

.page-header {
    grid-column: 1 / -1;
    grid-row: 1;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}
.page-header h2 {
    margin: 0 0 .1em 0;
    color: var(--accent);
    font-size: 1.15rem;
}
.page-header .color-by {
    margin-left: auto;
    display: flex;
    flex-direction: column;
    gap: .2rem;
    font-size: .8rem;
    color: var(--fg-muted);
}
.page-header .color-by select {
    font: inherit;
    padding: .35rem .5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card-bg);
    color: var(--fg);
    min-width: 160px;
}
.page-header .hint {
    color: var(--fg-muted);
    font-size: .85rem;
}
.page-header code {
    background: var(--code-bg);
    padding: .05em .35em;
    border-radius: 3px;
    font-size: .85em;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem;
    /* Flex column so the .chart inside can flex:1 and fill remaining space. */
    display: flex;
    flex-direction: column;
    min-height: 0;
    /* As a grid item, default min-width is `auto` (= min-content), which
     * inherits the ECharts canvas's last-rendered width. That refuses
     * to shrink, so when the viewport narrows, the card overflows its
     * cell instead of compressing — and the sidebar drops off the page.
     * min-width: 0 lets the cell take whatever width the grid gives. */
    min-width: 0;
}
.card h3 {
    margin: 0 0 .75rem 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent);
    flex: 0 0 auto;
}

.charts {
    grid-column: 1;
    grid-row: 2;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    min-height: 0;
    /* Let the grid container shrink below its children's min-content
     * (the canvas widths). Otherwise it would push past the page's
     * right edge and clip the sidebar. */
    min-width: 0;
}
.chart {
    width: 100%;
    flex: 1 1 auto;
    min-height: 280px;  /* floor so the chart stays usable on shorter screens */
    /* Same min-width: 0 reasoning as on .card — without it the flex
     * item floors at the canvas's intrinsic width and refuses to
     * shrink with its container. */
    min-width: 0;
}

.filters {
    grid-column: 2;
    grid-row: 2;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
    /* Scroll the sidebar independently when filters + legend are taller
     * than the viewport. Charts beside it keep their full height. */
    overflow-y: auto;
    min-height: 0;
}
.filters h3 {
    margin: 0 0 .25rem 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent);
}
.filters label {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    font-size: .85rem;
    color: var(--fg-muted);
}
.filters select,
.filters input {
    font: inherit;
    padding: .4rem .5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card-bg);
    color: var(--fg);
}
/* Range filter (von / bis) — two compact number inputs side by side
 * with a hint line below showing the data's actual min/max. */
.filters fieldset.range-filter {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: .35rem .6rem .5rem;
    margin: 0;
    color: var(--fg-muted);
    font-size: .85rem;
}
.filters fieldset.range-filter legend {
    padding: 0 .35rem;
    font-size: .8rem;
}
.filters fieldset.range-filter .range-row {
    display: flex;
    gap: .5rem;
}
.filters fieldset.range-filter .range-row label {
    flex: 1;
}
.filters fieldset.range-filter input[type="number"] {
    width: 100%;
    padding: .25rem .35rem;
}
.filters fieldset.range-filter .range-hint {
    margin-top: .35rem;
    font-size: .72rem;
    opacity: .8;
}
/* Portionspreis distribution strip — inline SVG painted by the
 * dashboard JS from the server-supplied 20-bin histogram. Bars
 * inside the active von/bis range get the accent fill; bars
 * outside fade to muted. Stretches to the fieldset width via
 * preserveAspectRatio="none" on the <svg>. */
.filters fieldset.range-filter .price-histogram {
    display: block;
    width: 100%;
    height: 44px;
    margin: .25rem 0 .5rem;
    background: var(--bg-soft);
    border-radius: 3px;
}
.filters fieldset.range-filter .price-bin {
    fill: var(--fg-muted);
    opacity: .35;
}
.filters fieldset.range-filter .price-bin.in-range {
    fill: var(--accent);
    opacity: .9;
}
/* Checkbox-style filter rows: row layout instead of stacked, native
 * checkbox sizing instead of the padded input look above. */
.filters label.checkbox-filter {
    flex-direction: row;
    align-items: center;
    gap: .5rem;
    cursor: pointer;
}
.filters label.checkbox-filter input[type="checkbox"] {
    padding: 0;
    margin: 0;
    width: 1rem;
    height: 1rem;
    flex: 0 0 auto;
    cursor: pointer;
}

/* ─── MultiSelect widget ──────────────────────────────────────────────── */
.ms { position: relative; }
.ms-details > summary {
    list-style: none;
    cursor: pointer;
    padding: .4rem .5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card-bg);
    color: var(--fg);
    display: flex;
    align-items: center;
    user-select: none;
    font-size: .85rem;
}
.ms-details > summary::-webkit-details-marker { display: none; }
.ms-details > summary::after {
    content: '▾';
    margin-left: auto;
    color: var(--fg-muted);
    font-size: .8em;
}
.ms-details[open] > summary {
    border-color: var(--accent);
    background: var(--accent-soft);
}
.ms-summary.has-selection { color: var(--accent); font-weight: 500; }
.ms-panel {
    position: absolute;
    z-index: 20;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 6px 14px rgba(20, 35, 60, .12);
    padding: .5rem;
    display: flex;
    flex-direction: column;
    gap: .35rem;
}
/* When the toggle sits low in the viewport the widget flips upward, so the
 * popover anchors to the summary's top edge instead of its bottom. */
.ms-panel.ms-panel-up {
    top: auto;
    bottom: calc(100% + 4px);
    box-shadow: 0 -6px 14px rgba(20, 35, 60, .12);
}
/* Empty-state notice shown in place of the list when no options match. */
.ms-empty {
    padding: .6rem .4rem;
    text-align: center;
    color: var(--fg-muted);
    font-size: .85rem;
    border: 1px dashed var(--border);
    border-radius: 4px;
    background: var(--bg-soft);
}
.ms-search { padding: .3rem .5rem !important; font-size: .85rem; }
.ms-list {
    overflow-y: auto;
    max-height: 220px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-soft);
}
/* .ms-row is a <label>, and `.filters label` (specificity 0,1,1) sets
 * flex-direction:column to stack a filter's title above its input. We need
 * to beat that specificity here — `label.ms-row` is (0,1,1) too and wins
 * by virtue of being later in the stylesheet. */
label.ms-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: .4rem;
    padding: .2rem .4rem;
    font-size: .85rem;
    color: var(--fg);
    cursor: pointer;
}
label.ms-row:hover { background: var(--accent-soft); }
label.ms-row input[type=checkbox] { flex: 0 0 auto; margin: 0; }
label.ms-row span {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ms-actions { display: flex; justify-content: flex-end; }
.ms-actions button {
    margin: 0;
    padding: .25rem .55rem;
    background: transparent;
    color: var(--fg-muted);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: .8rem;
    cursor: pointer;
}
.ms-actions button:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

/* Scoped to specific filter-bar buttons only — a bare `.filters
 * button` would also style every MultiSelect Clear button inside the
 * sidebar, then `.ms-actions button` needed !important to fight back.
 * Keying off the data-action attribute frees us from the specificity
 * arms race without touching the markup. */
.filters button[data-action="reload"],
.filters button[data-action="reset"] {
    margin-top: .5rem;
    padding: .5rem .75rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: .85rem;
}
/* Reload = primary action (solid) — the user's "I want to see fresh
 * data" instinct. Reset = secondary (outline) since it discards work. */
.filters button[data-action="reload"] {
    border: 1px solid var(--accent);
    background: var(--accent);
    color: var(--accent-fg);
}
.filters button[data-action="reload"]:hover { background: var(--accent-hover); }
.filters button[data-action="reset"] {
    border: 1px solid var(--accent);
    background: transparent;
    color: var(--accent);
}
.filters button[data-action="reset"]:hover { background: var(--accent-soft); }

/* ─── Sidebar legend ──────────────────────────────────────────────────── */
/* Shared legend used by both charts — replaces per-chart legends so the
 * bars get the full chart width. Each row is a clickable button; the
 * `.off` modifier dims it when the series is currently hidden. */
.legend {
    margin-top: .5rem;
    padding-top: .5rem;
    border-top: 1px dashed var(--border);
    display: flex;
    flex-direction: column;
    gap: .35rem;
}
.legend h3 {
    margin: 0 0 .25rem 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent);
}
.legend-rows {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    max-height: 280px;
    overflow-y: auto;
    padding-right: 4px;
}
/* Shared layout for legend rows — works for both <div> (LMS Overview's
 * informational legend) and <button> (Einkaufswert's clickable
 * series-toggle legend). Button-only behaviors (hover background,
 * cursor, .off dim state) are scoped to button.legend-row below. */
.legend-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: .45rem;
    margin: 0;
    padding: .2rem .35rem;
    background: transparent;
    color: var(--fg);
    border: 1px solid transparent;
    border-radius: 4px;
    font-size: .82rem;
    text-align: left;
    width: 100%;
}
button.legend-row {
    cursor: pointer;
}
button.legend-row:hover {
    background: var(--accent-soft);
}
button.legend-row.off { opacity: .45; }
button.legend-row.off .legend-swatch {
    background-color: transparent !important;
    border: 1px solid var(--fg-muted);
}
/* The currently-hovered series (chart-side) mirrors here as bold +
 * a subtle background. Paired with scrollIntoView({block:'nearest'})
 * on the JS side so the active entry never disappears below the
 * fold when there are many series. */
button.legend-row.active {
    font-weight: 700;
    background: var(--accent-soft);
}
.legend-swatch {
    flex: 0 0 12px;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
}
.legend-label {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Middle breakpoint — viewport wide enough for a right-hand sidebar but
 * too narrow for two charts side-by-side with a comfortable 12-month
 * axis. Stack the two charts vertically inside their column and split
 * the available height between them (1fr 1fr) so they fill the viewport
 * without an inner scrollbar. Filter sidebar stays on the right. */
@media (max-width: 1700px) and (min-width: 1101px) {
    .charts {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
    }
    /* Drop the usual 280 px floor: when the chart row is the constraint
     * (short viewport, two stacked rows), the floor would force overflow
     * and an inner scrollbar. The card's min-height: 0 already opts in
     * to shrink-to-fit; the chart just needs to follow suit. */
    .chart {
        min-height: 0;
    }
}

@media (max-width: 1100px) {
    /* On narrow viewports drop the chart "fill all the height" trick:
     * the page becomes naturally scrolling, each section takes its
     * intrinsic size. */
    main     { overflow: visible; }
    .page    { height: auto; grid-template-columns: 1fr; grid-template-rows: none; }
    .page-header, .charts, .filters, .rezepturen-content { grid-column: 1; grid-row: auto; }
    .charts  { grid-template-columns: 1fr; overflow-y: visible; }
    .filters { order: -1; overflow-y: visible; }
    .chart   { height: 380px; flex: 0 0 auto; }
    .rezepturen-table-wrap { max-height: none; overflow: visible; }
    header   { flex-direction: column; align-items: stretch; }
    nav.tabs { margin-left: 0; }
}

/* ─── Rezepturen dashboard (table) ────────────────────────────────────── */
.rezepturen-content {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    gap: .75rem;
    min-height: 0;
    min-width: 0;
}
.rezepturen-table-wrap {
    flex: 1 1 auto;
    overflow: auto;       /* both axes — table is wide and rows can exceed viewport */
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    min-height: 0;
}
.rezepturen-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .85rem;
    /* Fixed layout pins column widths to the <colgroup> defs so the
     * colspan-6 drill-down row can't reflow the columns. Without it
     * the rows jump sideways every time a row expands or collapses. */
    table-layout: fixed;
}
.rezepturen-table .col-name        { width: auto;  }
.rezepturen-table .col-costcenters { width: 10rem; }
.rezepturen-table .col-status      { width: 7rem;  }
.rezepturen-table .col-version     { width: 5rem;  }
.rezepturen-table .col-date        { width: 7rem;  }
.rezepturen-table .col-catalog     { width: 12rem; }
.rezepturen-table .col-group       { width: 12rem; }
.rezepturen-table .col-price       { width: 8rem;  }
.rezepturen-table .price-cell      { text-align: right; font-variant-numeric: tabular-nums; }
/* ── Rechnungskontrolle: table-level styling ───────────────────────── */
.rechnungen .rezepturen-table .col-status        { width: 7rem;   }
/* Widths sized to fit the German header text without ellipsis:
 *   "Kostenstelle", "Lieferdatum", "Lieferschein", "Gesamt netto",
 *   "Gesamt brutto". The supplier column stays `auto` and absorbs
 *   the slack — long supplier names like "Chefs Culinar
 *   Vollsortiment" still ellipsize gracefully in their wider cell. */
.rechnungen .rezepturen-table .col-cctr          { width: 8.5rem;  }
.rechnungen .rezepturen-table .col-kdnr          { width: 7rem;    }
.rechnungen .rezepturen-table .col-supplier      { width: auto;    }
.rechnungen .rezepturen-table .col-date          { width: 9rem;    }
.rechnungen .rezepturen-table .col-lieferschein  { width: 8rem;    }
.rechnungen .rezepturen-table .col-positions     { width: 4rem;    }
.rechnungen .rezepturen-table .col-amount        { width: 10rem;   }
/* Also let header text ellipsize so an oversized header doesn't break
 * the fixed layout; data cells already do this via the shared tbody rule. */
.rechnungen .rezepturen-table thead th {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Status pill — complete=green, uncomplete=amber, other=neutral. */
.status.status-complete   { background: var(--customer-bg); color: var(--customer-fg); }
.status.status-uncomplete { background: var(--warn-soft);   color: var(--warn-border); }
.status.status-other      { background: var(--code-bg);     color: var(--fg-muted); }

/* Date-range preset buttons — small inline pills under the von/bis. */
.filters .date-presets {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem;
    margin-top: .35rem;
}
.filters .date-presets button {
    flex: 1 1 auto;
    padding: .2rem .35rem;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--fg-muted);
    border-radius: 3px;
    cursor: pointer;
    font-size: .72rem;
}
.filters .date-presets button:hover {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: var(--accent);
}

/* Footer totals row — sticky-looking band at the bottom of the table. */
.rezepturen-table tfoot.lf-totals-foot td {
    border-top: 2px solid var(--border);
    padding: .55rem .65rem;
    background: var(--bg-soft);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.rezepturen-table tfoot.lf-totals-foot td.lf-totals-label {
    text-align: right;
    color: var(--fg-muted);
}

/* Position-level Reklamation icon (⚠) sits next to the Einkaufsartikel name. */
.lf-complaint-icon {
    color: var(--status-err);
    margin-right: .3rem;
    cursor: help;
}

/* ── Rechnungskontrolle: per-position table inside the drill-down ─────
 * Fixed-width columns so the four numeric cells sit under the main
 * row's right-aligned price columns; the Einkaufsartikel name column
 * takes the remainder. The detail-row td override below also tightens
 * its left padding so the drill-down doesn't get pushed off to the right. */
.rechnungen tr.rec-detail-row td {
    padding: .35rem .65rem .65rem .65rem;
}
.lf-pos-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .85rem;
    table-layout: fixed;
}
.lf-pos-table col.lf-col-name  { width: auto;   }
/* qty cells carry "150 Päckchen" / "120 Stück" — 8rem clipped the
 * longer German unit names with an ellipsis. 10rem fits every label
 * the units table currently emits (Päckchen / Umkarton / Container). */
.lf-pos-table col.lf-col-qty   { width: 10rem;  }
.lf-pos-table col.lf-col-price { width: 11rem;  }
.lf-pos-table thead th {
    text-align: left;
    padding: .35rem .65rem;
    border-bottom: 1px solid var(--border);
    color: var(--fg-muted);
    font-weight: 600;
    font-size: .8rem;
}
.lf-pos-table tbody td {
    padding: .35rem .65rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.lf-pos-table tbody tr:last-child td { border-bottom: none; }
.lf-pos-table th.lf-price,
.lf-pos-table td.lf-price {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
/* Liefermenge + Inhalt cells carry text + number ("10 Karton",
 * "150 Päckchen"). Right-aligning the values felt offset against
 * the short "Inhalt" header — long cell values reached well past
 * the header's left edge. Left-anchor instead so the header sits
 * directly above each row's leftmost character, matching the
 * Einkaufsartikel column's read direction. */
.lf-pos-table th.lf-qty,
.lf-pos-table td.lf-qty {
    text-align: left;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.lf-pos-table .lf-pi-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* Paid-vs-expected colour coding on the Einzelpreis Basismengeneinheit cell.
 * Red = paid more (or position complained), green = paid less, neutral
 * for "ok" or "unknown". */
.lf-pos-table .lf-price.price-high {
    color: var(--status-err);
    font-weight: 600;
}
.lf-pos-table .lf-price.price-low {
    color: var(--status-ok);
    font-weight: 600;
}
.lf-pos-table .lf-price.price-unknown {
    color: var(--fg-muted);
    font-style: italic;
}

/* Lieferungen list: gesamt-netto/brutto cells right-aligned tabular */
.rezepturen-table .lf-price {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Incomplete Portionspreis — at least one Rezeptartikel lacks a
 * priced Einkaufsartikel under the active mandator scope, so the
 * displayed value is understated. */
.rezepturen-table .price-cell.price-incomplete {
    color: var(--status-err);
    font-weight: 500;
    cursor: help;
}
.rezepturen-table .price-cell.price-incomplete::after {
    content: ' ⚠';
    font-size: .85em;
}
.rezepturen-table thead th {
    position: sticky;
    top: 0;
    background: var(--card-bg);
    z-index: 1;
    text-align: left;
    padding: .55rem .65rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: var(--fg-muted);
    /* The first header sits inside an overflow:auto wrap; without
     * this border-image trick the bottom border vanishes once the
     * thead becomes "stuck" because sticky elements don't paint
     * their border over the scrolling rows. */
    box-shadow: 0 1px 0 var(--border);
    user-select: none;
}
.rezepturen-table thead th[data-sort-key] {
    cursor: pointer;
}
.rezepturen-table thead th[data-sort-key]:hover {
    color: var(--fg);
}
/* Arrow indicator appended via ::after so the column width doesn't
 * jump when sort changes — the empty pseudo always reserves a slot. */
.rezepturen-table thead th[data-sort-key]::after {
    content: '⇅';
    margin-left: .3rem;
    opacity: .25;
    font-size: .85em;
}
.rezepturen-table thead th.sorted { color: var(--accent); }
.rezepturen-table thead th.sorted.asc::after  { content: '↑'; opacity: 1; }
.rezepturen-table thead th.sorted.desc::after { content: '↓'; opacity: 1; }
.rezepturen-table tbody td {
    padding: .45rem .65rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.rezepturen-table tbody tr:hover { background: var(--accent-soft); }
/* Fixed col widths + long recipe names = truncate with ellipsis.
 * The full name is still readable via the row's drill-down. */
.rezepturen-table .rec-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.rezepturen-table tbody td:not(.rec-detail-cell):not(.costcenters-cell) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* Costcenters column flex-wraps inside its cell — the row grows
 * vertically rather than truncating, since the badges are the
 * point of the column. */
.rezepturen-table td.costcenters-cell {
    white-space: normal;
    line-height: 1.4;
}
.cust-badge {
    display: inline-block;
    margin: 0 .2rem .2rem 0;
    padding: 0 .35rem;
    border: 1px solid var(--customer-border);
    border-radius: 3px;
    background: var(--customer-bg);
    color: var(--customer-fg);
    font-size: .72rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    cursor: help;
}
.cc-badge {
    display: inline-block;
    margin: 0 .2rem .2rem 0;
    padding: 0 .35rem;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: .72rem;
    cursor: help;
}
/* Declaration-state icon before the allergen list:
 *  ✓ = supplier answered yes/no for every allergen
 *  ? = some answered, some still unknown
 *  ✗ = supplier hasn't declared anything
 * Colors match status semantics: green/amber/red. */
.allergen-decl {
    display: inline-block;
    margin: 0 .35rem .2rem 0;
    width: 1rem;
    text-align: center;
    font-size: .85rem;
    font-weight: 600;
    cursor: help;
}
.allergen-decl.decl-complete { color: var(--status-ok); }
.allergen-decl.decl-partial  { color: var(--status-warn); }
.allergen-decl.decl-none     { color: var(--status-err); }

.allergen-badge {
    display: inline-block;
    margin: 0 .2rem .2rem 0;
    padding: 0 .3rem;
    border: 1px solid var(--allergen-border);
    border-radius: 3px;
    background: var(--allergen-bg);
    color: var(--allergen-fg);
    font-size: .72rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    cursor: help;
}
.rezepturen-table .rec-num {
    display: inline-block;
    margin-right: .35rem;
    padding: 0 .35rem;
    border-radius: 3px;
    background: var(--code-bg);
    color: var(--fg-muted);
    font-size: .75rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.rezepturen-table .names-cell {
    max-width: 28rem;
    /* Don't wrap each ingredient name in the middle — wrap only at the
     * separators. The "+N" badge sits at the end. */
    white-space: normal;
    word-break: normal;
}
.rezepturen-table .names-cell .more {
    display: inline-block;
    margin-left: .25rem;
    padding: 0 .35rem;
    border-radius: 3px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: .72rem;
    font-weight: 600;
}
.rezepturen-table .empty-row {
    padding: 2rem;
    text-align: center;
    color: var(--fg-muted);
}
.rezepturen-table .muted { color: var(--fg-muted); }
.rezepturen-table .status {
    display: inline-block;
    padding: .1rem .4rem;
    border-radius: 3px;
    font-size: .72rem;
    font-weight: 600;
}
/* Four-state status pill: freigegeben (released + valid) is green;
 * abgelaufen (was released, validity expired — can be re-released) is
 * orange; vollständig (complete draft, never released) is amber;
 * unvollständig (incomplete draft) is a softer amber-grey to read as
 * "earlier in the workflow". */
.rezepturen-table .status-freigegeben     { background: rgba(52,168,83,.15);  color: var(--status-ok); }
.rezepturen-table .status-abgelaufen      { background: rgba(217,119,6,.18);  color: #a04f00; }
.rezepturen-table .status-vollstaendig    { background: rgba(251,188,4,.18);  color: #8a6700; }
.rezepturen-table .status-unvollstaendig  { background: rgba(91,102,117,.15); color: var(--fg-muted); }
:root[data-theme="dark"] .rezepturen-table .status-vollstaendig { color: var(--status-warn); }
:root[data-theme="dark"] .rezepturen-table .status-abgelaufen   { color: #f59f4a; }
.rezepturen-table .badge {
    display: inline-block;
    margin-left: .35rem;
    padding: .05rem .35rem;
    border-radius: 3px;
    font-size: .7rem;
    font-weight: 600;
}
.rezepturen-table .badge-teil   { background: var(--accent-soft); color: var(--accent); }
/* Grund and Teil are independent: a recipe can wear both badges
 * (a Grundrezeptur is also a Teilrezeptur if anyone references it).
 * Grund gets the warmer accent so it stands out from the Teil pill. */
.rezepturen-table .badge-grund  { background: var(--warn-soft); color: var(--warn-border); }
.rezepturen-table .badge-locked { background: transparent; }

/* Inline drill-down: each .rec-row is a clickable header; clicking
 * inserts a .rec-detail-row right after it with the ingredient
 * breakdown. The rec-toggle caret rotates to indicate state. */
.rezepturen-table tbody tr.rec-row { cursor: pointer; }
.rezepturen-table tbody tr.rec-row.expanded { background: var(--accent-soft); }
.rezepturen-table .rec-toggle {
    display: inline-block;
    width: 1rem;
    margin-right: .15rem;
    color: var(--fg-muted);
    transition: transform .12s ease;
}
.rezepturen-table tr.rec-row.expanded .rec-toggle {
    transform: rotate(90deg);
    color: var(--accent);
}
/* `> td` (direct child only) so the chunky 2rem/1rem padding lands on
 * the rec-detail wrapper cell, not on the inner lf-pos-table's td.lf-qty
 * and td.lf-price cells — those would otherwise inherit the same
 * left-pad and slide ~19px to the right of their headers (worst on the
 * Inhalt column, where the short German header sits noticeably left
 * of its much wider cell values). */
.rezepturen-table tr.rec-detail-row > td {
    background: var(--bg-soft);
    padding: .65rem 1rem .85rem 2rem;
    border-bottom: 1px solid var(--border);
}
.rec-detail-cell {
    /* TD is a table cell; the grid lives on the inner wrapper to dodge
     * browser quirks with display: grid on <td>. */
}
/* Single-column stack. Using grid (rather than plain flow) so the
 * structure stays consistent — easy to swap back to multi-column if
 * needed by changing grid-template-columns. */
.rec-detail-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: .75rem;
}
.rec-detail-block {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    break-inside: avoid;
}
/* Rezeptartikel without any linked Einkaufsartikel — flagged at all
 * times (not only when the filter toggle is on) so the user can spot
 * incomplete recipes at a glance. Mandator-aware: when a mandator
 * filter is active the highlight reflects that mandator's scope. */
.rec-detail-block.missing-purchaseitems {
    background: var(--warn-soft);
    border-left: 3px solid var(--warn-border);
    padding: .35rem .5rem;
    border-radius: 4px;
    margin-left: -.5rem;
}
.rec-detail-block.sub-recipe .ing-head {
    color: var(--accent);
    font-style: italic;
}
/* Sub-recipe block is collapsed by default; clicking the head
 * expands the nested ingredients inline. */
.rec-detail-block.sub-recipe .sub-recipe-head {
    cursor: pointer;
    user-select: none;
}
.rec-detail-block.sub-recipe .sub-recipe-head:hover {
    color: var(--accent-hover);
}
.rec-detail-block.sub-recipe .sub-toggle {
    display: inline-block;
    transition: transform .12s ease;
    color: var(--fg-muted);
}
.rec-detail-block.sub-recipe.expanded .sub-toggle {
    transform: rotate(90deg);
    color: var(--accent);
}
/* Nested body: indent + left accent so it visually nests under the
 * head. Works for arbitrary depth via the recursive renderDetail call. */
.rec-detail-block.sub-recipe .sub-recipe-body {
    margin-top: .35rem;
    margin-left: 1rem;
    padding-left: .75rem;
    border-left: 2px solid var(--accent-soft);
}
.rec-detail-block.sub-recipe .sub-recipe-body .rec-detail-grid {
    /* Tighter spacing inside a nested grid since indent already
     * separates it from the parent. */
    gap: .5rem;
}

/* "Wird verwendet in N Rezepturen" panel sits ABOVE the ingredient
 * grid in the expanded detail row. Mirrors the sub-recipe head visual
 * language (chevron + soft accent on hover) so it reads as the same
 * kind of inline lazy expand. Hidden entirely when used_in_count = 0
 * (renderUsedInPanel returns ''). */
.rec-used-in {
    margin-bottom: .6rem;
    padding: .35rem .5rem;
    background: var(--bg);
    border-left: 3px solid var(--accent-soft);
    border-radius: 3px;
}
.rec-used-in-head {
    cursor: pointer;
    user-select: none;
    font-weight: 500;
    color: var(--accent);
}
.rec-used-in-head:hover { color: var(--accent-hover); }
.rec-used-in-toggle {
    display: inline-block;
    margin-right: .3rem;
    transition: transform .12s ease;
    color: var(--fg-muted);
}
.rec-used-in.expanded .rec-used-in-toggle {
    transform: rotate(90deg);
    color: var(--accent);
}
.rec-used-in-body { margin-top: .35rem; }
.rec-used-in-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: 1fr;
    gap: .15rem;
}
.rec-used-in-item {
    padding: .2rem .35rem;
    font-size: .85rem;
    display: flex;
    align-items: center;
    gap: .35rem;
}
.rec-used-in-item:hover { background: var(--bg-soft); }
.rec-used-in-depth {
    color: var(--fg-muted);
    font-family: var(--font-mono, monospace);
    font-size: .8rem;
    width: 2.5rem;
    display: inline-block;
    text-align: left;
}
.ing-head {
    font-weight: 500;
    font-size: .85rem;
}
.ing-purchaseitems {
    margin: 0;
    padding-left: 1.25rem;
    color: var(--fg-muted);
    font-size: .8rem;
}
/* Each Einkaufsartikel row stays on ONE line: name on the left
 * (truncating with ellipsis when long), badges right-aligned. No
 * wrap — badges never break to a second line. */
.ing-purchaseitems li {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: nowrap;
    margin: .15rem 0;
    min-width: 0;
}
.ing-purchaseitems .pi-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ing-purchaseitems .pi-meta {
    display: inline-flex;
    flex-wrap: nowrap;
    gap: 0;
    align-items: center;
    margin-left: auto;
    flex: 0 0 auto;
}
.cust-badge.cust-more {
    font-style: italic;
    font-family: inherit;
}
/* Heart marker for is_favorite (is_default=1) purchaseitems. Pinned
 * to the same row as the name via inline-block. */
.pi-fav {
    color: #e2444a;
    margin-right: .3rem;
    font-size: .9em;
}
.ing-empty {
    color: var(--fg-muted);
    font-size: .8rem;
    font-style: italic;
    padding-left: 1.25rem;
}
.rec-detail-loading, .rec-detail-empty, .rec-detail-err {
    color: var(--fg-muted);
    font-style: italic;
    padding: .25rem 0;
}
.rec-detail-err { color: var(--status-err); }

.rezepturen-pager {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: .5rem 0;
}
.rezepturen-pager button {
    padding: .35rem .75rem;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--fg);
    border-radius: 4px;
    cursor: pointer;
    font-size: .85rem;
}
.rezepturen-pager button:hover:not([disabled]) { background: var(--accent-soft); }
.rezepturen-pager button[disabled] { opacity: .4; cursor: default; }
.rezepturen-pager .pager-info { color: var(--fg-muted); font-size: .85rem; }

.rezepturen-export {
    flex: 0 0 auto;
    display: flex;
    justify-content: flex-end;
    padding: 0 0 .25rem 0;
}
.rezepturen-export button {
    padding: .3rem .7rem;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--fg-muted);
    border-radius: 4px;
    cursor: pointer;
    font-size: .8rem;
}
.rezepturen-export button:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

/* ─── LMS Übersicht dashboard ───────────────────────────────────────── */
/* Six-widget composite arranged like the legacy reporting workbook:
 * row 1 = donut + daily line, row 2 = hourly stack + two KPI panels.
 * The filter sidebar shares the .page grid with .overview-grid so the
 * vertical extent matches the rest of the dashboard family. */
.lms-overview > .overview-grid {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0;
    min-width: 0;
}
.overview-row {
    display: grid;
    gap: 1rem;
    flex: 1 1 0;
    min-height: 280px;
}
/* Row 1: narrow donut (1) + wider daily line (2). */
.overview-row-1 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
/* Row 2: wide hourly stack + two compact KPI cards. */
.overview-row-2 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); }

.lms-overview .card h3 {
    margin: 0 0 .55rem 0;
    font-size: .95rem;
    font-weight: 600;
    color: var(--accent);
}
.lms-overview .card h3 .subtle {
    color: var(--fg-muted);
    font-weight: 400;
    font-size: .85rem;
    margin-left: .25rem;
}

/* KPI text block above the small line charts (Verspätung, Dauer). */
.lms-overview .kpi-block {
    padding: .15rem 0 .35rem 0;
}
.lms-overview .kpi-line {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--fg);
    line-height: 1.1;
}
.lms-overview .kpi-sub {
    font-size: .75rem;
    color: var(--fg-muted);
    margin-top: .15rem;
}

/* Filter sidebar overrides — the LMS Übersicht filters include native
 * date and select inputs alongside MultiSelects, so the sidebar
 * widens slightly and we restore typical native-control sizing. */
.lms-overview ~ .filters input[type="date"],
.lms-overview ~ .filters select {
    width: 100%;
    padding: .35rem .5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card-bg);
    color: var(--fg);
    font-size: .85rem;
}

/* Below ~1100 px the row grid collapses to a stacked single-column
 * layout so the cards stay readable on narrow viewports. The filter
 * sidebar moves above the content via the existing media query. */
@media (max-width: 1100px) {
    .lms-overview > .overview-grid { grid-row: auto; }
    .overview-row-1,
    .overview-row-2 {
        grid-template-columns: 1fr;
    }
    .overview-row { min-height: 0; }
    .lms-overview .card { height: 320px; }
}
