:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #1d2329;
  --muted: #66707a;
  --line: #dde2e7;
  --band: #f7f9fb;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --ok: #1e7a45;
  --ok-bg: #e5f4ea;
  --bad: #b3261e;
  --bad-bg: #fbe7e5;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 15px; }
[hidden] { display: none !important; }
h1, h2 { margin: 0 0 .4em; }
h2 { font-size: 1.05rem; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; background: var(--band); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .8em; font-weight: normal; }
.err { color: var(--bad); min-height: 1.2em; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Buttons & Felder */
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px;
  padding: 8px 14px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #b9c2cb; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: .85rem; }
.btn.danger { color: var(--bad); }
input[type=text], input[type=search], input[type=password], input[type=number], select {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.chk { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: .9rem; white-space: nowrap; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); padding: 28px; border-radius: 14px; width: min(360px, 100%);
  display: grid; gap: 12px; box-shadow: 0 2px 16px rgba(0,0,0,.06); }

/* Kopf */
.top { display: flex; align-items: center; gap: 18px; padding: 12px 20px; background: var(--surface);
  border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand-firma { font-size: .8rem; color: var(--muted); }
.brand-inv { font-weight: 650; font-size: 1.05rem; }
.stats { display: flex; gap: 22px; margin-left: auto; flex-wrap: wrap; }
.stat { display: grid; }
.stat b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .75rem; color: var(--muted); }
.stat.warn b { color: var(--bad); }
.user-chip { border: 1px solid var(--line); background: var(--band); border-radius: 999px; padding: 6px 12px;
  font: inherit; cursor: pointer; }

.tabs { display: flex; gap: 4px; padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--line);
  overflow-x: auto; }
.tabs button { border: 0; background: none; font: inherit; padding: 12px 14px; cursor: pointer; color: var(--muted);
  border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.badge { background: var(--bad); color: #fff; border-radius: 999px; padding: 1px 7px; font-size: .75rem; margin-left: 4px; }

.banner { margin: 12px 20px 0; padding: 10px 14px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); }
.view { padding: 18px 20px 40px; }
.intro { max-width: 70ch; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }

/* Scannen */
.scan-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; }
.scan-form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.scan-label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.scan-input { width: 100%; font-size: 1.6rem; padding: 14px 16px; font-family: ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: .04em; border-width: 2px; }
.scan-input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 4px rgba(31,95,139,.15); }
.scan-opts { display: flex; gap: 14px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 8px 12px; font: inherit; cursor: pointer; color: var(--muted); }
.seg button.active { background: var(--accent); color: #fff; }
.seg button[data-mode="-1"].active { background: var(--bad); }
.qty { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .9rem; }
.qty input { width: 76px; }
.qty.big input { width: 120px; font-size: 1.3rem; }

.feedback { margin-top: 16px; border-radius: var(--radius); padding: 22px 22px; border: 2px solid var(--line);
  background: var(--surface); min-height: 150px; transition: background .15s; }
.feedback .fb-title { font-size: 1.45rem; font-weight: 650; line-height: 1.25; }
.feedback .fb-sub { color: var(--muted); margin-top: 6px; }
.feedback .fb-size { display: inline-block; font-size: 2.2rem; font-weight: 750; margin-top: 10px; }
.feedback .fb-count { font-size: 1.05rem; margin-top: 8px; }
.feedback .fb-count b { font-size: 1.6rem; }
.feedback.ok { border-color: var(--ok); background: var(--ok-bg); }
.feedback.minus { border-color: var(--warn); background: var(--warn-bg); }
.feedback.bad { border-color: var(--bad); background: var(--bad-bg); }
.feedback.flash { animation: flash .35s ease-out; }
@keyframes flash { from { transform: scale(1.015); } to { transform: none; } }

.scan-side { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.recent { list-style: none; margin: 0; padding: 0; max-height: 64vh; overflow: auto; }
.recent li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 8px 2px;
  border-bottom: 1px solid var(--line); }
.recent li:last-child { border-bottom: 0; }
.recent .d { font-weight: 700; min-width: 34px; font-variant-numeric: tabular-nums; }
.recent .d.neg { color: var(--bad); }
.recent .t { min-width: 0; }
.recent .t div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent .t .meta { font-size: .78rem; color: var(--muted); }
.recent li.unk .t div:first-child { color: var(--bad); }

/* Bestand */
.filterbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filterbar #fQ { flex: 1 1 260px; }
.listbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 14px 0 8px; flex-wrap: wrap; }
.exports { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.tablewrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
table.list { width: 100%; border-collapse: collapse; background: var(--surface); }
table.list th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
  padding: 9px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
table.list td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tbody tr.row:hover { background: var(--band); cursor: pointer; }
table.list tr.group td { background: #e9eff4; font-weight: 650; color: var(--accent); padding-top: 10px; }
table.list tr.group td.num { color: var(--ink); }
table.list tr.more td { text-align: center; color: var(--muted); padding: 14px; }
.diff-pos { color: var(--ok); font-weight: 600; }
.diff-neg { color: var(--bad); font-weight: 600; }
.ist-zero { color: var(--muted); }
#view-unbekannt table.list, #view-inventur table.list { border: 1px solid var(--line); border-radius: var(--radius); }
.import-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
.import-form #impName { flex: 1 1 240px; }
.status-aktiv { color: var(--ok); font-weight: 600; }
.status-fehler { color: var(--bad); font-weight: 600; }
.status-import { color: var(--warn); font-weight: 600; }

/* Mehrfachauswahl */
.ms { position: relative; }
.ms > button { min-width: 170px; text-align: left; }
.ms > button::after { content: "▾"; float: right; margin-left: 8px; color: var(--muted); }
.ms-panel { position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.12); width: 290px; padding: 8px; }
.ms-panel input[type=search] { width: 100%; margin-bottom: 6px; }
.ms-list { max-height: 300px; overflow: auto; }
.ms-list label { display: flex; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer; }
.ms-list label:hover { background: var(--band); }
.ms-actions { display: flex; justify-content: space-between; padding-top: 6px; border-top: 1px solid var(--line); margin-top: 6px; }

/* Dialoge */
.dlg { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 24px)); box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.dlg::backdrop { background: rgba(20,28,36,.45); }
.dlg-body { padding: 22px; display: grid; gap: 12px; }
.dlg-body input[type=search], .dlg-body input[type=text] { width: 100%; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.as-results { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow: auto; }
.as-results li { padding: 10px 4px; border-bottom: 1px solid var(--line); }
.as-results .sizes { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.as-results .sizes button { min-width: 48px; }
.as-results .sizes button.has-soll { border-color: var(--accent); }

@media (max-width: 860px) {
  .scan-grid { grid-template-columns: 1fr; }
  .stats { margin-left: 0; width: 100%; }
  .hide-sm { display: none; }
  .top, .tabs, .view { padding-left: 16px; padding-right: 16px; }
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14181c; --surface: #1c2126; --ink: #e6eaee; --muted: #98a2ac; --line: #2e353c; --band: #232930;
    --accent: #5aa3d6; --accent-ink: #0d1a24; --ok: #5fcf8e; --ok-bg: #173022; --bad: #ff8a80; --bad-bg: #3a1d1b;
    --warn: #f0c060; --warn-bg: #3a2f14; }
  table.list tr.group td { background: #22303b; }
}
