/* QS-Plattform – schlichtes, ruhiges Interface ohne externe Abhängigkeiten */
:root {
    --bg: #f5f6f4;
    --surface: #ffffff;
    --surface-2: #f0f2ef;
    --line: #dde1dc;
    --text: #1d2521;
    --muted: #5d6b64;
    --accent: #1f6f5c;
    --accent-ink: #ffffff;
    --accent-soft: #e3f0eb;
    --green: #2e7d4f;
    --green-bg: #e2f2e8;
    --yellow: #8a6200;
    --yellow-bg: #fbf0cf;
    --red: #b3261e;
    --red-bg: #fbe3e1;
    --grey: #5d6b64;
    --grey-bg: #eceeeb;
    --radius: 8px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.5; }
a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h1, h2, h3 { overflow-wrap: break-word; hyphens: auto; }
h2 { font-size: 1.2rem; margin: 2rem 0 .75rem; }
h3 { font-size: 1.05rem; margin: 1.5rem 0 .5rem; }
p { margin: .4rem 0 .9rem; }
code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .87rem; }
.inline { display: inline; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.5rem 0; }

/* Kopfzeile */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem; height: 56px; padding: 0 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 600; color: var(--text); text-decoration: none; }
.brand-logo { display: block; max-height: 36px; max-width: 220px; width: auto; height: auto; }
.brand-icon { display: block; width: 32px; height: 32px; border-radius: 8px; object-fit: cover; }
.plain-brand .brand-logo { max-height: 56px; max-width: 280px; }
.brand-mark { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-size: .8rem; letter-spacing: .04em; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: .75rem; font-size: .9rem; }
.nav-toggle { display: none; background: none; border: 1px solid var(--line); border-radius: 6px; padding: .2rem .55rem; font-size: 1.1rem; cursor: pointer; }

/* Rahmen */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: calc(100vh - 56px); }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 1rem .6rem 2rem; overflow-y: auto; position: sticky; top: 56px; height: calc(100vh - 56px); }
.sidebar a { display: block; padding: .38rem .7rem; border-radius: 6px; color: var(--text); text-decoration: none; font-size: .93rem; }
.sidebar a.sub { padding-left: 1.4rem; color: var(--muted); font-size: .88rem; }
.sidebar a:hover { background: var(--surface-2); }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-group { margin: 1.1rem .7rem .3rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.content { padding: 1.75rem 2rem 4rem; max-width: 1240px; width: 100%; min-width: 0; box-sizing: border-box; }
.page-head > div { min-width: 0; max-width: 100%; }

/* Seitenkopf */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.page-head p { margin: .2rem 0 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.breadcrumb { font-size: .87rem; margin-bottom: .4rem; }
.breadcrumb a { color: var(--muted); }

/* Karten und Raster */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1.25rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 1rem; }
.grid > * { min-width: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1.1rem; }
.stat .num { font-size: 1.9rem; font-weight: 650; line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: .88rem; }
.stat.rot .num { color: var(--red); }
.stat.gelb .num { color: var(--yellow); }
.stat.gruen .num { color: var(--green); }
dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.25rem; margin: 0; }
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; }

/* Tabellen */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1.25rem; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: .55rem .8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; font-size: .82rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbf9; }
td.actions { white-space: nowrap; }
.empty { padding: 1.5rem; text-align: center; color: var(--muted); }

/* Ampel */
.badge { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.badge-gruen { background: var(--green-bg); color: var(--green); }
.badge-gelb { background: var(--yellow-bg); color: var(--yellow); }
.badge-rot { background: var(--red-bg); color: var(--red); }
.badge-grau, .badge-neutral { background: var(--grey-bg); color: var(--grey); }
.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; margin-right: .35rem; vertical-align: middle; }
.dot-gruen { background: var(--green); } .dot-gelb { background: #d39e00; } .dot-rot { background: var(--red); } .dot-grau { background: #9aa59f; }

/* Formulare */
form.stack { max-width: 760px; }
.field { margin-bottom: .9rem; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
.field small { display: block; color: var(--muted); font-size: .82rem; margin-top: .2rem; }
.field-check label { font-weight: 400; display: flex; gap: .5rem; align-items: flex-start; }
.field-check label input[type=checkbox] { margin-top: .22em; }
.req { color: var(--red); }
/* Einheitliche Höhe für alle einzeiligen Eingaben, Auswahlfelder, Dateifelder und Buttons */
:root { --control-h: 2.375rem; }
input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=submit]):not([type=button]):not([type=reset]):not([type=image]):not([type=range]):not([type=color]), select, textarea {
    box-sizing: border-box; width: 100%; margin: 0; padding: 0 .65rem; border: 1px solid #c5ccc6; border-radius: 6px; background-color: #fff; font: inherit; font-size: .95rem; color: inherit;
}
input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=submit]):not([type=button]):not([type=reset]):not([type=image]):not([type=range]):not([type=color]), select {
    height: var(--control-h); line-height: calc(var(--control-h) - 2px);
}
textarea { padding: .45rem .65rem; line-height: 1.45; min-height: var(--control-h); }
/* Datum/Zeit: Browser-Innenabstände entfernen (Chrome, Safari/iOS) */
input::-webkit-datetime-edit, input::-webkit-datetime-edit-fields-wrapper { padding: 0; }
input::-webkit-date-and-time-value { text-align: left; min-height: calc(var(--control-h) - 2px); }
input::-webkit-calendar-picker-indicator { margin: 0; padding: 0; cursor: pointer; }
/* Auswahlfelder: eigener Pfeil, damit Safari die Höhe übernimmt */
select { -webkit-appearance: none; appearance: none; padding-right: 2rem; text-overflow: ellipsis;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%235d6b64' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right .7rem center; background-size: 12px 8px; }
select[multiple], select[size]:not([size="1"]) { height: auto; line-height: 1.45; padding: .3rem .4rem; background-image: none; }
/* Dateifeld: Auswahl-Button innerhalb der gleichen Höhe */
input[type=file] { padding: 0 .4rem 0 0; line-height: calc(var(--control-h) - 2px); cursor: pointer; }
input[type=file]::file-selector-button { height: calc(var(--control-h) - 2px); margin: 0 .75rem 0 0; padding: 0 .85rem; border: 0; border-right: 1px solid #c5ccc6; border-radius: 5px 0 0 5px; background: var(--surface-2); color: var(--text); font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer; }
input[type=file]::-webkit-file-upload-button { height: calc(var(--control-h) - 2px); margin: 0 .75rem 0 0; padding: 0 .85rem; border: 0; border-right: 1px solid #c5ccc6; background: var(--surface-2); font: inherit; font-size: .88rem; font-weight: 600; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 3px solid rgba(31, 111, 92, .3); outline-offset: 1px; border-color: var(--accent); }
textarea { resize: vertical; }
input[type=checkbox], input[type=radio] { width: 1.05rem; height: 1.05rem; margin: 0; flex: none; accent-color: var(--accent); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 1rem; }
/* Felder einer Zeile bündig: Beschriftung, Eingabe und Hinweis liegen je in einer gemeinsamen Zeile,
   auch wenn eine Beschriftung umbricht oder nur ein Feld einen Hinweis hat */
@supports (grid-template-rows: subgrid) {
    .form-row > .field { display: grid; grid-row: span 3; grid-template-rows: subgrid; row-gap: 0; align-content: start; }
    .form-row > .field > label { align-self: end; }
    .form-row > .field-check > label { grid-row: 2; align-self: center; min-height: var(--control-h); margin: 0; }
    .form-row > .field-check > small { grid-row: 3; }
    .form-row > :not(.field) { grid-row: span 3; align-self: end; margin-bottom: .9rem; }
}
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem .2rem; margin: 0 0 1rem; }
legend { font-weight: 600; padding: 0 .35rem; }

/* Buttons */
.btn, button.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; box-sizing: border-box; height: var(--control-h); line-height: 1.1; white-space: nowrap; padding: 0 .95rem; border-radius: 6px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 600; font-size: .92rem; text-decoration: none; cursor: pointer; }
.btn:hover { filter: brightness(1.07); }
.btn-secondary, button.btn-secondary { background: var(--surface); color: var(--accent); }
.btn-danger, button.btn-danger { background: var(--surface); color: var(--red); border-color: #e2b4b0; }
.btn-small, button.btn-small, a.btn-small { height: var(--control-h); padding: 0 .75rem; font-size: .86rem; }
.btn-link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }

/* Meldungen */
.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.flash-success { background: var(--green-bg); border-color: #b7dcc4; color: #1d5a37; }
.flash-error { background: var(--red-bg); border-color: #efbab5; color: #8c1d17; }
.flash-info { background: var(--accent-soft); border-color: #bcd9cf; color: #17503f; }
.notice { background: var(--surface-2); border-left: 4px solid var(--accent); padding: .75rem 1rem; border-radius: 0 var(--radius) var(--radius) 0; margin: 1rem 0; }
.notice.warn { border-left-color: #d39e00; background: var(--yellow-bg); }
.secret-box { font-family: var(--mono); background: var(--surface-2); border: 1px dashed var(--accent); padding: .75rem 1rem; border-radius: 6px; word-break: break-all; }

/* Details */
details { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem 1rem; margin-bottom: 1rem; }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: .75rem; }

/* Tabs/Filter */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; flex: 1 1 12rem; max-width: 22rem; }
.filters a { padding: .3rem .7rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); text-decoration: none; color: var(--text); font-size: .87rem; }
.filters a.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Einfache Seiten (Anmeldung, Einrichtung, Peer) */
body.plain { display: grid; place-items: start center; padding: 6vh 1rem; }
.plain-box { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 1.75rem; }
.plain-box.wide { max-width: 1000px; }
.plain-brand { margin-bottom: 1.25rem; }
/* Wiederholbare Zeilen */
fieldset.repeat { border: 0; padding: 0; margin: 0 0 1rem; min-width: 0; }
fieldset.repeat legend { padding: 0; margin-bottom: .3rem; font-weight: 600; font-size: .92rem; }
.repeat-rows { display: grid; gap: .45rem; margin-bottom: .5rem; }
.repeat-row { display: flex; gap: .5rem; align-items: center; }
.repeat-row input { flex: 1; min-width: 0; }
.repeat-remove { flex: none; display: inline-grid; place-items: center; width: var(--control-h); height: var(--control-h); box-sizing: border-box; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--muted); font-size: 1.25rem; line-height: 1; cursor: pointer; }
.repeat-remove:hover { color: var(--red); border-color: #e2b4b0; background: var(--red-bg); }
fieldset.repeat > small { display: block; margin-top: .4rem; color: var(--muted); font-size: .85rem; }

/* Erscheinungsbild */
#erscheinungsbild { margin-top: 2rem; scroll-margin-top: 72px; }
.brand-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1.25rem; }
.brand-slot { min-width: 0; }
.brand-preview { display: grid; place-items: center; height: 96px; margin-bottom: .75rem; border: 1px dashed var(--line); border-radius: var(--radius); background: var(--surface-2); padding: .75rem; }
.brand-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.brand-preview-icon img { width: 64px; height: 64px; border-radius: 14px; }
.brand-preview-favicon img { width: 32px; height: 32px; }

/* Fehlerseiten */
.error-box { max-width: 560px; margin: 2rem auto; text-align: center; }
.plain-box .error-box { margin: .5rem auto 0; }
.error-code { display: inline-block; min-width: 4.5rem; padding: .3rem .9rem; margin-bottom: .75rem; border-radius: 999px; background: var(--red-bg); color: var(--red); font-weight: 700; font-size: 1.05rem; letter-spacing: .06em; font-variant-numeric: tabular-nums; }
.error-code.soft { background: var(--grey-bg); color: var(--grey); }
.error-box h1 { margin: 0 0 .5rem; font-size: 1.45rem; }
.error-box p { margin: 0 0 .75rem; color: var(--muted); }
.error-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; margin-top: 1.25rem; }
.error-ref { display: inline-block; margin-top: .25rem; font-family: var(--mono); font-size: .85rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: .15rem .5rem; color: var(--text); }
.error-detail { text-align: left; white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: .78rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: .75rem; max-height: 50vh; overflow: auto; margin-top: 1rem; }
.qr img { width: 200px; height: 200px; image-rendering: pixelated; border: 1px solid var(--line); border-radius: 6px; }

/* Tablet-Erfassung */
.tile-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .75rem; }
.tile { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; text-decoration: none; color: var(--text); }
.tile:hover { border-color: var(--accent); }
.tile strong { display: block; margin-bottom: .2rem; }

@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { display: none; position: fixed; inset: 56px 0 0 0; z-index: 20; height: auto; }
    .sidebar.open { display: block; }
    .nav-toggle { display: inline-block; }
    .content { padding: 1.25rem 1rem 3rem; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .topbar-user .muted { display: none; }
}

@media print {
    .topbar, .sidebar, .actions, .btn { display: none !important; }
    .shell { display: block; }
    body { background: #fff; }
}

/* Mitarbeiterdokumente */
.inline-details { display: inline-flex; align-items: center; box-sizing: border-box; min-height: var(--control-h); vertical-align: top; padding: 0 .65rem; margin: 0 .5rem 0 0; }
.inline-details:not([open]) { height: var(--control-h); }
.inline-details[open] { display: block; height: auto; padding: .45rem .65rem; margin: 0 0 .5rem; max-width: 360px; }
.inline-details summary { font-weight: 500; font-size: .84rem; color: var(--accent); line-height: 1.1; }
tr.muted td { color: var(--muted); }
.auth-foot { margin: 1.25rem 0 0; }

/* Gültiges Dokument mit Freigabe */
.doc-current { border-left: 4px solid var(--green); }
.doc-current.overdue { border-left-color: var(--red); }
.doc-current-head { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; align-items: flex-start; }
.doc-current-head > div { min-width: 0; }
.doc-extend[open] { max-width: 420px; }
.notice.retired { background: var(--grey-bg); border-color: var(--line); color: var(--text); display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; }

/* Text-Dokumente (Markdown) */
.doc-current.draft { border-left-color: var(--yellow); }
.doc-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.doc-actions .inline-details { margin: 0; }
.doc-new { margin: .5rem 0 1rem; }
.md-input { font-family: var(--mono); font-size: .9rem; line-height: 1.55; min-height: 50vh; }
.md-body { max-width: 860px; line-height: 1.6; }
.md-body h1 { font-size: 1.5rem; margin: .25rem 0 1rem; }
.md-body h2 { font-size: 1.2rem; margin: 1.6rem 0 .5rem; color: var(--accent); }
.md-body h3 { font-size: 1.02rem; margin: 1.2rem 0 .4rem; }
.md-body p, .md-body ul, .md-body ol { margin: 0 0 .8rem; }
.md-body li { margin-bottom: .25rem; }
.md-body table { width: 100%; border-collapse: collapse; margin: .5rem 0 1rem; font-size: .92rem; }
.md-body th, .md-body td { border: 1px solid var(--line); padding: .4rem .6rem; text-align: left; vertical-align: top; }
.md-body th { background: var(--surface-2); }
.md-body blockquote { margin: .5rem 0 1rem; padding: .4rem .9rem; border-left: 3px solid var(--accent); background: var(--accent-soft); }
.md-body code { font-size: .88em; }
@media print { .md-body { border: 0; padding: 0; } }

/* Gruppierte Formularfelder (z. B. je Kühlschrank Ist/Min/Max) */
fieldset.field-group { border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .9rem .1rem; margin: 0 0 1rem; }
fieldset.field-group legend { padding: 0 .35rem; font-weight: 600; font-size: .92rem; color: var(--accent); }
fieldset.field-group .form-row { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }

/* Schmale Bildschirme: lange Beschriftungen dürfen umbrechen, Mindesthöhe bleibt */
@media (max-width: 600px) {
    .btn, button.btn, .btn-small, button.btn-small, a.btn-small { white-space: normal; height: auto; min-height: var(--control-h); padding: .35rem .85rem; text-align: center; }
}

/* Unterschrift */
.sign-form { max-width: 760px; }
.signature-pad { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; margin: 1rem 0; }
.signature-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .5rem; }
.signature-pad canvas { display: block; width: 100%; height: 220px; border: 1px dashed #9aa7a0; border-radius: 6px; background: #fff; touch-action: none; cursor: crosshair; }
.signature-error { color: var(--red); margin: .5rem 0 0; }
.nav-count { display: inline-block; min-width: 1.4em; padding: 0 .4em; margin-left: .35em; border-radius: 1em; background: var(--red); color: #fff; font-size: .8em; text-align: center; line-height: 1.5; }
@media (max-width: 600px) { .signature-pad canvas { height: 180px; } }
.sign-text { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: .75rem; max-height: 50vh; overflow: auto; }
.sign-text > :last-child { margin-bottom: 0; }
.doc-sign-actions { margin: .75rem 0 1rem; }
