:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1c2733;
  --muted: #6b7885;
  --line: #dce2e8;
  --brand: #2563eb;
  --brand-ink: #ffffff;
  --offen: #d97706;
  --bestellt: #2563eb;
  --erledigt: #16a34a;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
}
body.center { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .75rem 1rem;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar strong { font-size: 1.05rem; }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.topbar nav a { padding: .4rem .7rem; border-radius: 8px; }
.topbar nav a:hover { background: var(--bg); text-decoration: none; }
.topbar .whoami { color: var(--muted); font-size: .85rem; padding: .4rem .3rem; align-self: center; }

.readonly-hint {
  background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412;
  padding: .6rem .9rem; border-radius: 8px; margin: 0 0 .8rem; font-size: .9rem;
}

/* Cards & forms */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.1rem; margin: 1rem auto; max-width: 640px;
}
.card h2 { margin: 0 0 .8rem; font-size: 1.1rem; }
label { display: block; margin: .6rem 0; font-weight: 600; font-size: .9rem; color: var(--muted); }
input {
  display: block; width: 100%; margin-top: .3rem;
  padding: .65rem .7rem; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
input[readonly] { background: #f0f3f6; color: var(--ink); }
input:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }

button {
  font: inherit; font-weight: 600; cursor: pointer;
  padding: .65rem 1rem; border: none; border-radius: 8px;
  background: var(--brand); color: var(--brand-ink);
}
button:hover { filter: brightness(1.05); }
button:disabled { opacity: .6; cursor: default; }
button.secondary { background: #eef2f6; color: var(--ink); border: 1px solid var(--line); }
.row { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .6rem; }
.row button { flex: 1 1 auto; }

.error { color: var(--danger); font-weight: 600; margin: .2rem 0 .6rem; }
.success { color: var(--erledigt); font-weight: 600; margin: .2rem 0 .6rem; }
select {
  display: block; width: 100%; margin-top: .3rem;
  padding: .65rem .7rem; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}

.date-filter { display: flex; gap: .5rem; align-items: end; flex-wrap: wrap; }
.date-filter label { margin: 0; display: flex; flex-direction: column; gap: .2rem; }
.date-filter input[type=date] { margin: 0; }
.hint { color: var(--muted); font-size: .85rem; margin: .2rem 0 .8rem; }
.muted { color: var(--muted); }
code { background: #eef2f6; padding: .05rem .3rem; border-radius: 4px; font-size: .85em; }

/* Login */
.login { max-width: 340px; width: 100%; }
.login h1 { margin: 0 0 1rem; font-size: 1.35rem; text-align: center; }
.login button { width: 100%; margin-top: .8rem; }

/* Scan */
.scan { max-width: 640px; margin: 0 auto; padding: 1rem; }
#reader { width: 100%; max-width: 420px; margin: 0 auto; border-radius: var(--radius); overflow: hidden; }
#scan-controls { display: flex; justify-content: center; gap: .6rem; margin: .8rem 0; }
.recent-list { list-style: none; padding: 0; margin: .5rem 0; }
.recent-list li {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: .6rem .8rem; margin-bottom: .4rem; display: flex; flex-direction: column;
}
.recent-list .meta { color: var(--muted); font-size: .85rem; }

/* Dashboard */
.dashboard { max-width: 1400px; margin: 0 auto; padding: 1rem; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.filters { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip {
  background: #eef2f6; color: var(--ink); border: 1px solid var(--line);
  padding: .45rem .9rem; border-radius: 999px; font-size: .9rem;
}
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.toolbar-right { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.toolbar-right input[type=search] { width: 220px; margin: 0; }
.btn-link { background: #eef2f6; color: var(--ink); border: 1px solid var(--line); padding: .5rem .8rem; border-radius: 8px; white-space: nowrap; }
.btn-link.danger { background: #fdecec; color: var(--danger); border-color: #f3c4c4; }
.actions { display: inline-flex; gap: .4rem; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table.items { width: 100%; border-collapse: collapse; }
table.items th, table.items td { padding: .6rem .8rem; text-align: left; border-bottom: 1px solid var(--line); overflow-wrap: break-word; }
table.items th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; position: sticky; top: 0; white-space: nowrap; }
table.items td.produkt { font-weight: 600; }
table.items td.num, table.items td.date { white-space: nowrap; }
table.items td.date { color: var(--muted); font-size: .85rem; }
tr.st-erledigt td.produkt { text-decoration: line-through; color: var(--muted); }

.status-btn, .status-badge { color: #fff; padding: .35rem .7rem; border-radius: 999px; font-size: .82rem; display: inline-block; white-space: nowrap; }
.status-badge { cursor: default; }
.badge-offen { background: var(--offen); }
.badge-bestellt { background: var(--bestellt); }
.badge-erledigt { background: var(--erledigt); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%);
  background: #1c2733; color: #fff; padding: .7rem 1.1rem; border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); z-index: 20; font-weight: 600;
}
.toast-error { background: var(--danger); }

/* Etiketten */
.labels { max-width: 900px; margin: 0 auto; padding: 1rem; }
.label-sheet { display: flex; flex-wrap: wrap; gap: .5rem; }
.label-card {
  position: relative; width: 200px; padding: .6rem; text-align: center;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
}
.label-card img { width: 150px; height: 150px; }
.label-text { display: flex; flex-direction: column; margin-top: .3rem; }
.label-text .l-name { font-weight: 700; font-size: .9rem; }
.label-text .l-loc { font-size: 1rem; font-weight: 700; }
.label-text .l-sku { color: var(--muted); font-size: .8rem; }
.label-del {
  position: absolute; top: 2px; right: 2px; width: 24px; height: 24px; padding: 0;
  background: var(--danger); border-radius: 50%; line-height: 1;
}

/* Responsive: schmale Bildschirme -> Tabellenzeilen als gestapelte Karten */
@media (max-width: 860px) {
  .table-wrap { overflow: visible; border: none; background: transparent; box-shadow: none; }
  table.items thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.items tr {
    display: block; background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
    margin-bottom: .7rem; padding: .3rem .2rem;
  }
  table.items td {
    display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
    border: none; border-bottom: 1px solid var(--line); padding: .5rem .8rem; text-align: right;
  }
  table.items tr td:last-child { border-bottom: none; }
  table.items td::before {
    content: attr(data-label);
    font-size: .72rem; text-transform: uppercase; letter-spacing: .03em;
    color: var(--muted); font-weight: 700; text-align: left; flex: 0 0 auto;
  }
  table.items td.produkt { font-size: 1.1rem; }
  table.items td:empty { display: none; }        /* leere Felder weglassen */
  table.items td.num, table.items td.date { white-space: normal; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-right { justify-content: space-between; }
  .toolbar-right input[type=search] { flex: 1 1 auto; width: auto; }
}

@media print {
  .no-print, .topbar { display: none !important; }
  body { background: #fff; }
  .labels { padding: 0; max-width: none; }
  .label-card { border: 1px solid #000; page-break-inside: avoid; }
  .label-del { display: none; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a; --card: #1a222c; --ink: #e6edf3; --muted: #9aa7b4;
    --line: #2b3641; --brand: #3b82f6;
  }
  input, select { background: #0f141a; color: var(--ink); }
  input[readonly] { background: #131a22; }
  table.items th { background: #1f2831; }
  .chip, .btn-link, button.secondary { background: #22303d; }
  .btn-link.danger { background: #3a2020; color: #f4a6a6; border-color: #5c2e2e; }
  .label-card, .label-card img { background: #fff; }
  .label-text .l-name, .label-text .l-loc { color: #111; }
}
