:root {
  --bg: #f4f2ef; --surface: #ffffff; --surface-2: #f8f6f3; --line: #e3ded7; --line-strong: #cfc8be;
  --text: #1f1b17; --muted: #6d655c; --accent: #d7263d; --accent-ink: #ffffff; --accent-soft: #fde8eb;
  --ok: #1e7a46; --ok-soft: #e3f4ea; --warn: #9a5b00; --warn-soft: #fff3dc; --bad: #b3261e; --bad-soft: #fde8e6;
  --info: #1f5f99; --info-soft: #e5effa; --shadow: 0 1px 2px rgba(40,30,20,.06), 0 4px 16px rgba(40,30,20,.05);
  --radius: 12px; --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161412; --surface: #201d1a; --surface-2: #272320; --line: #36312c; --line-strong: #4a433c;
    --text: #f1ece6; --muted: #a59b90; --accent: #ef4f63; --accent-ink: #fff; --accent-soft: #3d1c21;
    --ok: #5ccf8b; --ok-soft: #173225; --warn: #f0b04a; --warn-soft: #3a2c13; --bad: #ff7a6e; --bad-soft: #3d1d1a;
    --info: #78b3ec; --info-soft: #172b3f; --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overflow-x: hidden; }
a { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; } .mono { font-family: var(--mono); }
.error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 24px; } h2 { font-size: 18px; } h3 { font-size: 16px; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; height: 60px;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; white-space: nowrap; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text small { font-weight: 500; color: var(--muted); font-size: 12px; }
.brand-mark { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; }
.brand-mark.big { width: 52px; height: 52px; font-size: 24px; border-radius: 14px; margin-bottom: 14px; }
.global-scan { flex: 1; max-width: 520px; margin-left: auto; }
.global-scan input { width: 100%; }
.user { display: flex; align-items: center; gap: 10px; white-space: nowrap; color: var(--muted); font-size: 13px; }
.icon-btn.menu-toggle { display: none; }
.sidenav { position: fixed; top: 60px; bottom: 0; left: 0; width: 228px; padding: 14px 10px; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--line); z-index: 15; }
.sidenav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; text-decoration: none;
  color: var(--text); font-weight: 500; }
.sidenav a span { width: 20px; text-align: center; color: var(--muted); }
.sidenav a:hover { background: var(--surface-2); }
.sidenav a.active { background: var(--accent-soft); color: var(--accent); }
.sidenav a.active span { color: var(--accent); }
.nav-sep { height: 1px; background: var(--line); margin: 10px 6px; }
.badge { margin-left: auto; min-width: 22px; padding: 1px 7px; border-radius: 99px; background: var(--bad); color: #fff;
  font-size: 12px; text-align: center; font-weight: 700; }
.badge.soft { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.badge:empty { display: none; }
.view { margin-left: 228px; padding: 24px 28px 80px; max-width: 1280px; }

@media (max-width: 900px) {
  .scanbox input { font-size: 18px; }
  .global-scan { min-width: 0; }
  .icon-btn.menu-toggle { display: inline-grid; }
  .sidenav { transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidenav.open { transform: none; }
  .view { margin-left: 0; padding: 16px 16px 80px; }
  .user span, .brand-text small { display: none; }
  .brand-text { display: none; }
}

/* Controls */
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 9px; padding: 9px 11px; min-height: 40px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 80px; width: 100%; resize: vertical; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
label input, label select, label textarea { font-weight: 400; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; min-height: 40px;
  border-radius: 9px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font: 600 14px var(--font); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { width: 40px; height: 40px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); cursor: pointer; font-size: 18px; display: inline-grid; place-items: center; }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }

/* Cards & grid */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid > .card + .card, .stack > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.grid.k4 { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.grid.two { grid-template-columns: 1.3fr 1fr; align-items: start; }
@media (max-width: 1000px) { .grid.two { grid-template-columns: 1fr; } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 0; }
.kpi { display: block; text-decoration: none; }
.kpi .v { font-size: 30px; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi.alert { border-color: var(--bad); background: var(--bad-soft); }
.kpi.alert .v { color: var(--bad); }
.kpi.warn { border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); background: var(--warn-soft); }
.kpi:hover { border-color: var(--line-strong); }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input[type=search] { flex: 1; min-width: 200px; }

/* Lager-Matrix: Größen-Spalte bleibt beim Wischen stehen */
.matrix th:first-child, .matrix td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.matrix th:first-child { background: var(--surface-2); z-index: 2; }

/* Handy: Tabellen als Karten, Filter untereinander, Kennzahlen zweispaltig */
@media (max-width: 640px) {
  /* iPhone zoomt bei Eingabefeldern unter 16px automatisch hinein – Seite wird dann breiter als der Bildschirm */
  input, select, textarea { font-size: 16px; }
  h1 { font-size: 21px; }
  .card { padding: 14px; }
  .grid.k4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi .v { font-size: 26px; }
  .filters > * { flex: 1 1 100%; min-width: 0; max-width: 100%; }
  .view table:not(.matrix), .view table:not(.matrix) tbody { display: block; }
  .view table:not(.matrix) thead { display: none; }
  .view table:not(.matrix) tr { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line); }
  .view table:not(.matrix) tr:last-child { border-bottom: 0; }
  .view table:not(.matrix) td { display: block; position: relative; padding: 3px 0 3px 38%; border: 0; text-align: left; min-height: 24px; }
  .view table:not(.matrix) td[data-label=""], .view table:not(.matrix) td:not([data-label]) { padding-left: 0; }
  .view table:not(.matrix) td[data-label]::before { content: attr(data-label); position: absolute; left: 0; top: 5px; width: 35%;
    color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; overflow: hidden; text-overflow: ellipsis; }
  .view table:not(.matrix) td.cell-empty { display: none; }
  .view table:not(.matrix) td.empty { padding: 30px 0; text-align: center; }
  .view table:not(.matrix) .pill { white-space: normal; border-radius: 8px; }
  .view table:not(.matrix) td input:not([type=checkbox]), .view table:not(.matrix) td select { width: 100%; }
  .matrix th, .matrix td { padding: 8px; }
}

/* Pills */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 650;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.warnings { display: flex; flex-wrap: wrap; gap: 6px; }

/* Theke */
.modes { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.mode { padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font: 600 14px var(--font); color: var(--text); }
.mode.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.scanbox { display: flex; gap: 10px; }
.scanbox input { flex: 1; min-width: 0; font-size: 22px; font-family: var(--mono); min-height: 58px; padding: 10px 16px; letter-spacing: .04em; }
.scanbox .btn { min-height: 58px; font-size: 16px; }
.scan-hint { margin: 10px 2px 0; }
.mode-target { margin-top: 14px; padding: 12px 14px; border-radius: 10px; background: var(--info-soft); color: var(--info); font-weight: 600; }
.mode-target.need { background: var(--warn-soft); color: var(--warn); }
#thekeResult .card { margin-top: 16px; }
.scanlog { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.scanrow { display: grid; grid-template-columns: 28px 1fr auto; gap: 12px; align-items: center; padding: 11px 14px;
  border-radius: 10px; background: var(--surface); border: 1px solid var(--line); animation: pop .25s ease; }
.scanrow.ok { border-left: 4px solid var(--ok); }
.scanrow.bad { border-left: 4px solid var(--bad); background: var(--bad-soft); }
.scanrow.warn { border-left: 4px solid var(--warn); }
.scanrow .ico { font-size: 18px; text-align: center; }
@keyframes pop { from { transform: translateY(-4px); opacity: 0; } }

.item-card .title { font-size: 20px; font-weight: 700; }
.item-card .barcode { font-family: var(--mono); font-size: 15px; color: var(--muted); }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px 18px; margin: 16px 0; }
.facts div b { display: block; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.facts div span { font-size: 15px; font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--line); position: relative; font-size: 14px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--line-strong); }
.timeline li.florix::before { background: var(--info); }
.timeline .when { color: var(--muted); font-size: 12px; }

/* Lager matrix */
.matrix td.cell { text-align: center; font-variant-numeric: tabular-nums; }
.matrix td.cell.low { background: var(--bad-soft); color: var(--bad); font-weight: 700; }
.minput { width: 64px; min-height: 32px; padding: 4px 6px; text-align: center; }

/* Soll */
.soll { display: flex; flex-wrap: wrap; gap: 6px; }

/* Modal & toasts */
.modal { position: fixed; inset: 0; background: rgba(20,15,10,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--surface); border-radius: 16px; padding: 22px; width: min(560px, 100%); max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-card .row.end { margin-top: 18px; }
/* Kamera-Scanner als Vollbild-Overlay (scanner.js) */
html.scan-open, html.scan-open body { overflow: hidden; }
.scan-overlay { position: fixed; inset: 0; z-index: 70; background: #000; color: #fff; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.scan-top { display: flex; align-items: center; gap: 12px; padding: 10px 12px; }
.scan-title { flex: 1; text-align: center; font-weight: 700; font-size: 16px; }
.scan-round { width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.16); color: #fff;
  font-size: 18px; cursor: pointer; display: inline-grid; place-items: center; }
.scan-round.on { background: #ffd54a; color: #000; }
.scan-top::after { content: ""; width: 44px; }
.scan-top:has(#camTorch:not(.hidden))::after { display: none; }
.scan-stage { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.scan-stage #cameraReader { width: 100%; max-width: 720px; border: 0 !important; }
.scan-stage #cameraReader video { display: block; }
#qr-shaded-region { border-color: rgba(0,0,0,.6) !important; }
#qr-shaded-region::after { content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: #ff3b30;
  box-shadow: 0 0 10px 2px rgba(255,59,48,.7); animation: scanline 1.6s ease-in-out infinite alternate; }
@keyframes scanline { from { transform: translateY(-28px); opacity: .65; } to { transform: translateY(28px); opacity: 1; } }
.scan-stage.hit::before { content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none;
  box-shadow: inset 0 0 0 6px #34c759; animation: hitflash .5s ease-out forwards; }
@keyframes hitflash { to { opacity: 0; } }
.scan-msg { position: absolute; left: 16px; right: 16px; top: 50%; transform: translateY(-50%); margin: 0; padding: 16px;
  border-radius: 12px; background: rgba(255,255,255,.12); text-align: center; line-height: 1.45; }
.scan-hint { text-align: center; font-size: 14px; color: rgba(255,255,255,.8); padding: 10px 16px 0; }
.scan-last { margin: 10px 16px 0; padding: 10px 14px; border-radius: 10px; background: rgba(255,255,255,.16); text-align: center; animation: pop .2s; }
.scan-last div { font-size: 13px; opacity: .9; margin-top: 2px; }
.scan-last.ok { background: #1e7a46; } .scan-last.warn { background: #9a5b00; } .scan-last.bad { background: #b3261e; }
/* Rückfragen und Meldungen erscheinen über dem Kamerabild */
#modal { z-index: 80; }
.toasts { z-index: 90; }
.scan-bottom { display: flex; flex-direction: column; gap: 10px; padding: 12px 16px 16px; }
.scan-zoom { flex-direction: row; align-items: center; gap: 10px; color: #fff; font-size: 18px; font-weight: 700; }
.scan-zoom input { flex: 1; min-height: auto; padding: 0; accent-color: #fff; background: transparent; border: 0; }
.scan-manual { display: flex; gap: 8px; }
.scan-manual input { flex: 1; min-width: 0; font-size: 18px; font-family: var(--mono); min-height: 50px; border-radius: 12px;
  border: 0; background: rgba(255,255,255,.14); color: #fff; padding: 10px 14px; }
.scan-manual input::placeholder { color: rgba(255,255,255,.6); font-family: var(--font); }
.scan-manual input:focus { outline: 2px solid #fff; }
.scan-ok { min-width: 64px; border: 0; border-radius: 12px; background: #fff; color: #000; font: 700 16px var(--font); cursor: pointer; }
.scan-photo { flex-direction: row; justify-content: center; align-items: center; min-height: 46px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,.35); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer; }
.scan-photo-msg { text-align: center; font-size: 13px; color: #ffd54a; }
.scan-photo-msg:empty { display: none; }

/* Kamera-Knopf im Suchfeld der Kopfzeile */
.global-scan { position: relative; }
.global-scan input { padding-right: 46px; }
.scan-btn { position: absolute; right: 3px; top: 50%; transform: translateY(-50%); width: 38px; height: 34px; border: 0; border-radius: 7px;
  background: var(--accent); color: var(--accent-ink); cursor: pointer; display: inline-grid; place-items: center; padding: 0; }
.scan-btn svg { width: 22px; height: 22px; }
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; width: min(480px, calc(100% - 32px)); }
.toast { padding: 12px 16px; border-radius: 10px; background: var(--text); color: var(--bg); font-weight: 600; box-shadow: var(--shadow); animation: pop .2s; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); padding: 32px; border-radius: 18px; border: 1px solid var(--line);
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 0; }
.login-card p { margin: 0 0 6px; }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.callout { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.callout.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.callout.bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.callout ul { margin: 6px 0 0; padding-left: 20px; }
.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--text); }
.check input { min-height: auto; width: 18px; height: 18px; }
details summary { cursor: pointer; font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }

/* Druck: Ausgabebeleg */
.print-only { display: none; }
@media print {
  .topbar, .sidenav, .no-print, .toasts { display: none !important; }
  .view { margin: 0; padding: 0; max-width: none; }
  .print-only { display: block; }
  .card { box-shadow: none; border: 0; padding: 0; }
  html, body { background: #fff !important; color: #000; font-size: 12pt; }
  .table-wrap { border: 0; }
  th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sign { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 60px; }
  .sign div { border-top: 1px solid #000; padding-top: 4px; font-size: 10pt; }
}

/* Wareneingang: Größen-Auswahl */
.sizes { display: flex; gap: 6px; flex-wrap: wrap; }
.mode.size { min-width: 72px; }

/* Branding Freiwillige Feuerwehr Münster: dunkle Kopfleiste mit roter Kante wie feuerwehr-muenster.com */
:root { --brand-dark: #303030; }
.topbar { background: var(--brand-dark); border-bottom: 3px solid var(--accent); color: #fff; }
.topbar .brand { color: #fff; }
.topbar .brand-text small { color: rgba(255,255,255,.72); }
.topbar .icon-btn { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.22); color: #fff; }
.topbar .user { color: rgba(255,255,255,.72); }
.topbar .link { color: #fff; }
.topbar .global-scan input { border-color: transparent; }
.login { background: linear-gradient(var(--brand-dark) 0 34vh, var(--accent) 34vh calc(34vh + 4px), var(--bg) calc(34vh + 4px)); }
.login-card h1 + p { font-weight: 600; }
/* Feuerwehr-Abzeichen (rund, mit Gemeindewappen) */
.brand-mark.logo { display: inline-block; flex: none; width: 40px; height: 40px; padding: 0; background: none; border: 0; border-radius: 50%; }
.brand-mark.logo img { display: block; width: 100%; height: 100%; }
.brand-mark.logo.big { width: 116px; height: 116px; margin: -74px auto 6px; filter: drop-shadow(0 4px 10px rgba(0,0,0,.25)); }
.login-card { text-align: center; }
.login-card label { text-align: left; }
