:root {
    --bg: #f6f7f9; --card: #fff; --text: #181c22; --muted: #6b7380; --line: #e4e7ec;
    --primary: #2563eb; --primary-d: #1d4ed8; --err: #c62828; --err-bg: #fdecec;
    --field: #fff; --edge: #cfd4dc; --r: 10px;
}
@media (prefers-color-scheme: dark) {
    :root { --bg: #101318; --card: #181c23; --text: #e8ebf0; --muted: #8b95a5; --line: #272d38; --field: #12161c; --edge: #3a4250; --err: #ff8a80; --err-bg: #2d1a1a; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 1.35rem; margin: 0 0 14px; font-weight: 650; }
h2 { font-size: 1rem; margin: 0; font-weight: 600; }
main { max-width: 960px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left)); }
button, summary { touch-action: manipulation; font: inherit; }

/* Kopfzeile */
.top { background: var(--card); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
.top-in { max-width: 960px; margin: 0 auto; padding: 0 max(16px, env(safe-area-inset-left)); height: 52px; display: flex; align-items: center; gap: 20px; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
nav { display: flex; gap: 4px; flex: 1; }
nav a { padding: 8px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; }
nav a.on { color: var(--text); background: var(--bg); font-weight: 600; }
.logout { margin: 0; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 10px 0 10px 8px; }
.link:hover { color: var(--text); }

/* Formularfelder */
input, textarea { width: 100%; font: inherit; color: var(--text); padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--field); }
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
label { display: block; font-size: .85rem; color: var(--muted); }
label input, label textarea { margin-top: 4px; }
label.check { display: flex; align-items: center; gap: 10px; color: var(--text); min-height: 40px; }
label.check input { width: 18px; height: 18px; margin: 0; flex: none; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 40px; padding: 0 16px; border: 1px solid transparent; border-radius: 8px; background: var(--primary); color: #fff; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--primary-d); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: transparent; color: var(--err); border-color: var(--line); }
.btn.danger:hover { background: var(--err-bg); }
.icon-btn { flex: none; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 8px; background: var(--primary); color: #fff; cursor: pointer; padding: 0; }
.icon-btn:hover { background: var(--primary-d); }
.icon-btn.ghost { background: transparent; color: var(--muted); }
.icon-btn.ghost:hover { background: var(--bg); color: var(--text); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--err-bg); color: var(--err); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* Suche */
.bar { display: flex; gap: 8px; }
.search { flex: 1; min-width: 0; display: flex; gap: 8px; margin: 0; }
.search input { flex: 1; min-width: 0; height: 40px; padding-top: 0; padding-bottom: 0; }
.add span { display: none; }
.count { color: var(--muted); font-size: .85rem; margin: 10px 2px 12px; }

/* Artikelkarten */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; align-items: start; }
.art { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.art header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.art .t { min-width: 0; }
.art header .icon-btn { margin: -6px -6px 0 0; width: 36px; height: 36px; }
.num { display: block; font: .78rem ui-monospace, Menlo, Consolas, monospace; color: var(--muted); overflow-wrap: anywhere; }
.art h2 { overflow-wrap: anywhere; }
.desc { margin: 0; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.art footer { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stock { display: flex; align-items: baseline; gap: 5px; }
.qty { font-size: 1.6rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.unit { font-size: .8rem; color: var(--muted); }
.stock.zero .qty { color: var(--err); }
.move { display: flex; gap: 6px; margin: 0; flex: none; }
.move input { width: 56px; height: 40px; padding: 0 4px; text-align: center; border-color: var(--edge); }
.step { flex: none; box-sizing: border-box; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; border: 1px solid var(--edge); background: var(--field); color: var(--text); font-size: 1.25rem; line-height: 1; cursor: pointer; padding: 0; }
.step:hover { background: var(--bg); }
.step.in { background: var(--primary); border-color: var(--primary); color: #fff; }
.step.in:hover { background: var(--primary-d); }

/* Dialoge */
dialog { border: 0; border-radius: var(--r); padding: 20px; width: min(440px, calc(100vw - 32px)); background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { font-size: 1.1rem; margin-bottom: 2px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.actions .left { margin-right: auto; }
#del { margin: 0; }

/* Benutzer */
.narrow { max-width: 420px; margin-bottom: 24px; }
.sub { margin: 0 0 10px; }
.users { display: flex; flex-direction: column; gap: 10px; }
.urow { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.uname { font-weight: 600; flex: 1 1 140px; }
.uname .num { display: inline; }
.uform { display: flex; gap: 8px; margin: 0; flex: 1 1 360px; }
.uform input { flex: 1; min-width: 0; height: 40px; padding-top: 0; padding-bottom: 0; }
.uform .btn, .btn-spacer { width: 92px; flex: none; padding: 0; }

/* Fußzeile */
.foot { max-width: 960px; margin: 0 auto; padding: 8px max(16px, env(safe-area-inset-left)) 24px; display: flex; justify-content: center; gap: 16px; font-size: .8rem; }
.foot a { color: var(--muted); text-decoration: none; }
.foot a:hover { color: var(--text); text-decoration: underline; }

/* Login */
.login { max-width: 360px; margin: 12vh auto 0; }

.login h1 { text-align: center; }
.login .muted { text-align: center; color: var(--muted); margin: -6px 0 16px; }
.login form { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; }

@media (min-width: 640px) {
    .add span { display: inline; }
    .add { padding: 0 14px; }
}
@media (max-width: 479px) {
    main { padding-top: 12px; }
    .top-in { gap: 8px; }
    .grid { grid-template-columns: 1fr; gap: 10px; }
    .uform { flex-wrap: wrap; }
    .uform input { flex: 1 1 100%; }
    .uform .btn, .btn-spacer { flex: 1; width: auto; }
    .btn-spacer { display: none; }
    dialog { margin: auto auto 0; width: 100%; max-width: none; border-radius: var(--r) var(--r) 0 0; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
}
