:root {
  --bg: #f5f5f7;
  --card: #fff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e5e5ea;
  --accent: #0071e3;
  --red: #e5322d;
  --green: #1a7f37;
  --amber: #b25000;
  --radius: 10px;
  color-scheme: light;
}

* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 12px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; margin-top: 20px; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .5px; }
.error { color: var(--red); min-height: 0; margin: 4px 0; }
.error:empty { display: none; }
.ok { color: var(--green); }
.warn-text { color: var(--amber); font-weight: 600; }

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid #d2d2d7; border-radius: 8px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
label input, label select { margin-top: 4px; color: var(--text); font-size: 14px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); }
label.check input { width: auto; margin: 0; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

button { padding: 8px 14px; border: 1px solid #d2d2d7; border-radius: 8px; background: #fff; cursor: pointer; }
button:hover { background: #fafafa; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: #0077ed; }
button.danger { color: var(--red); border-color: #f3c2c0; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }

.logo { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 10px; background: #2c2c2e; color: #fff; font-weight: 700; font-size: 13px; line-height: 1; }
.logo b { color: #fff; }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 20px; }
.brand h1 { font-size: 20px; margin: 0; }
.brand p { margin: 0; }
.brand.small { margin: 0; }
.brand.small .logo { width: 32px; height: 32px; font-size: 10px; border-radius: 8px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card button { width: 100%; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 10px 24px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
#tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
#tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 8px; color: var(--muted); }
#tabs button.active { background: var(--bg); color: var(--text); font-weight: 600; }
.me { color: var(--muted); display: flex; gap: 12px; align-items: center; }

main { padding: 20px 24px 40px; max-width: 1280px; margin: 0 auto; }

.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { text-align: left; padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--line); background: #fff; }
.stat span { display: block; color: var(--muted); font-size: 13px; }
.stat b { font-size: 26px; }
.stat.available b { color: var(--green); }
.stat.issued b { color: var(--accent); }
.stat.void b { color: var(--muted); }

.banner { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.banner.warn { background: #fff4e5; color: var(--amber); border: 1px solid #ffd8a8; }

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar input { flex: 1; }
.toolbar select { width: 180px; }

.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafafa; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
#codes-body tr[data-id] { cursor: pointer; }
#codes-body tr[data-id]:hover { background: #f9f9fb; }
td.empty { text-align: center; color: var(--muted); padding: 32px; }
tr.inactive td { color: var(--muted); }
.card table th { background: none; }

.pager { display: flex; gap: 12px; align-items: center; justify-content: flex-end; margin-top: 12px; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.available { background: #e6f4ea; color: var(--green); }
.badge.issued { background: #e8f1fd; color: var(--accent); }
.badge.redeemed { background: #f0e8fd; color: #6e3fc7; }
.badge.void { background: #fde8e7; color: var(--red); }
.badge.warn { background: #fff4e5; color: var(--amber); }

dialog { border: 0; border-radius: 14px; padding: 24px; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.dialog-head h2 { margin: 0; }
.dialog-head .close { margin-left: auto; font-size: 18px; color: var(--muted); }
dl { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0 0 16px; }
dt { color: var(--muted); }
dd { margin: 0; word-break: break-word; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.history { list-style: none; padding: 0; margin: 0; max-height: 220px; overflow: auto; }
.history li { padding: 6px 0; border-bottom: 1px solid var(--line); }

#bulk-result ul { padding-left: 18px; max-height: 240px; overflow: auto; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0; transition: .2s; background: #1d1d1f; color: #fff; padding: 10px 18px; border-radius: 10px; pointer-events: none; max-width: calc(100vw - 32px); z-index: 50; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--red); }

/* Tablets */
#tablets-body tr[data-serial], #problems-body tr[data-serial], #archive-body tr[data-serial] { cursor: pointer; }
#tablets-body tr[data-serial]:hover, #problems-body tr[data-serial]:hover, #archive-body tr[data-serial]:hover { background: #f9f9fb; }
#tabs .count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px; background: #fde8e7; color: var(--red); font-size: 11px; font-weight: 700; }
#tabs .count:empty { display: none; }
.stat small { font-size: 13px; color: var(--muted); font-weight: 500; }
.banner.info { background: #eef4fd; color: #1d4e89; border: 1px solid #cfe0f7; }
.badge.p-bad { background: #fde8e7; color: var(--red); }
.badge.p-warn { background: #fff4e5; color: var(--amber); }
.badge.p-info { background: #eef1f5; color: #4a5160; }
.problem-cards { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.problem-card { display: flex; gap: 10px; align-items: baseline; padding: 8px 14px; }
.problem-card b { font-size: 18px; }
.problem-card.p-bad b { color: var(--red); }
.problem-card.p-warn b { color: var(--amber); }
.problem-card.active { outline: 2px solid var(--accent); outline-offset: -1px; }
dialog.wide { width: min(820px, calc(100vw - 32px)); }
table.compact th, table.compact td { padding: 6px 8px; font-size: 13px; }
.picker-results { border: 1px solid var(--line); border-radius: 8px; margin: -6px 0 12px; max-height: 260px; overflow: auto; }
.picker-results button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; }
.picker-results button:last-child { border-bottom: 0; }
.picker-results p { margin: 8px 10px; }
.picked { background: #f5f5f7; border-radius: 8px; padding: 8px 10px; margin-bottom: 12px; }
.picked .warn-text { margin: 6px 0 0; font-weight: 500; }

@media (max-width: 860px) {
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar, main { padding-left: 16px; padding-right: 16px; }
  .toolbar { flex-wrap: wrap; }
  .toolbar select { width: auto; flex: 1; }
  .row { flex-direction: column; gap: 0; }
}

/* Bestand */
th.c, td.c { text-align: center; }
.tick { color: var(--green); font-weight: 700; }
.sources { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-bottom: 14px; font-size: 13px; }
.source b { margin-right: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.chip { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.chip.on { background: #e6f4ea; color: var(--green); }
.chip.off { background: #f2f2f4; color: var(--muted); }
.reg-edit { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 8px; }
.reg-edit label { margin: 0; }
.reg-edit .grow { flex: 1; min-width: 200px; }
.reg-edit button { height: 38px; }
.badge.st-einsatz { background: #e6f4ea; color: var(--green); }
.badge.st-lager { background: #e8f1fd; color: var(--accent); }
.badge.st-reparatur { background: #fff4e5; color: var(--amber); }
.badge.st-verloren { background: #fde8e7; color: var(--red); }
.badge.st-ausgemustert { background: #f2f2f4; color: var(--muted); }
fieldset.segmented { border: 0; padding: 0; margin: 0 0 14px; display: flex; flex-wrap: wrap; gap: 8px; }
fieldset.segmented legend { color: var(--muted); font-size: 13px; margin-bottom: 6px; padding: 0; }
fieldset.segmented label { display: flex; gap: 8px; align-items: center; margin: 0; padding: 8px 12px; border: 1px solid #d2d2d7; border-radius: 8px; color: var(--text); cursor: pointer; }
fieldset.segmented label:has(input:checked) { border-color: var(--accent); background: #e8f1fd; }
fieldset.segmented input { width: auto; margin: 0; }
details summary { cursor: pointer; color: var(--muted); margin: 8px 0; }
#presence-stats { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
