:root {
  --red: #C0392B;
  --red-dark: #9e2f22;
  --bg: #f4f3f1;
  --card-bg: #ffffff;
  --text: #222;
  --muted: #777;
  --border: #e2e0dd;
  --green: #2e7d32;
  --green-bg: #eaf6ea;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
body { padding-bottom: env(safe-area-inset-bottom); }

#top-bar {
  background: var(--red); color: #fff; padding: 14px 16px calc(14px + env(safe-area-inset-top));
  padding-top: calc(14px + env(safe-area-inset-top));
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
#top-bar h1 { margin: 0; font-size: 18px; font-weight: 600; }
#top-bar .icon-btn { background: rgba(255,255,255,0.15); color: #fff; flex: 0 0 auto; }

.dashboard { display: flex; gap: 8px; overflow-x: auto; padding: 10px 12px; background: var(--red-dark); }
.dashboard .chip { flex: 0 0 auto; background: rgba(255,255,255,0.12); color: #fff; border-radius: 10px;
  padding: 6px 12px; font-size: 12px; min-width: 86px; }
.dashboard .chip b { display: block; font-size: 15px; }

.toolbar { display: flex; gap: 8px; padding: 10px 12px; }
.toolbar input[type="search"] { flex: 1; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  font-size: 15px; background: #fff; }
.icon-btn { border: none; background: #fff; border-radius: 10px; width: 42px; height: 42px; font-size: 18px;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 2px rgba(0,0,0,0.1); }
.icon-btn.danger { color: #c0392b; }

.filter-panel { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 12px 10px 12px; }
.filter-panel.hidden { display: none; }
.filter-panel label { font-size: 11px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; flex: 1 1 120px; }
.filter-panel select { padding: 8px; border-radius: 8px; border: 1px solid var(--border); font-size: 14px; }
.filter-panel button { flex: 1 1 100%; padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: #fff; }

.item-list { padding: 4px 12px 90px 12px; display: flex; flex-direction: column; gap: 8px; }
.item-card { background: var(--card-bg); border-radius: var(--radius); padding: 12px 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.item-card .row1 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.item-card .nr { color: var(--muted); font-size: 12px; }
.item-card .geraet { font-weight: 600; font-size: 15px; }
.item-card .status-badge { font-size: 11px; padding: 3px 8px; border-radius: 20px; background: #eee; color: #555; white-space: nowrap; }
.item-card .status-badge.verkauft { background: var(--green-bg); color: var(--green); }
.item-card .defekt { color: var(--muted); font-size: 13px; margin-top: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-card .row2 { display: flex; gap: 14px; margin-top: 6px; font-size: 12px; color: #555; }
.item-card .row2 b { color: var(--text); }

.view.hidden { display: none; }

.detail-header { position: sticky; top: 0; z-index: 20; background: var(--red); color: #fff;
  display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 10px 10px 10px; }
.detail-header #detail-title { flex: 1; font-weight: 600; font-size: 16px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-header .icon-btn { background: rgba(255,255,255,0.15); color: #fff; }
.detail-header .icon-btn.danger { color: #ffd1cc; }

.sections { padding: 10px 12px 120px 12px; }
.section { background: var(--card-bg); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.section > .section-head { padding: 13px 14px; font-weight: 600; font-size: 14.5px; display: flex;
  justify-content: space-between; align-items: center; background: #fbfaf9; }
.section > .section-body { padding: 4px 14px 14px 14px; display: none; }
.section.open > .section-body { display: block; }
.section .caret { transition: transform 0.15s; color: var(--muted); }
.section.open .caret { transform: rotate(180deg); }

.field { margin: 10px 0; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.field input[type="text"], .field input[type="number"], .field input[type="date"],
.field select, .field textarea {
  width: 100%; padding: 10px 11px; border-radius: 10px; border: 1px solid var(--border);
  font-size: 15px; background: #fff; font-family: inherit;
}
.field textarea { resize: vertical; min-height: 60px; }

.track-status-row { display: flex; align-items: center; gap: 8px; background: #fbfaf9;
  border: 1px dashed var(--border); border-radius: 10px; padding: 9px 11px; }
.track-status-row span { flex: 1; font-size: 13.5px; }
.track-refresh-btn { flex: 0 0 auto; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; font-size: 12.5px; }
.track-refresh-btn:disabled { opacity: 0.5; }

.checklist { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px 10px; margin: 6px 0 14px 0; }
.check-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 14px; }
.check-item input { width: 19px; height: 19px; }

.summary-box { background: #fbfaf9; border: 1px dashed var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.summary-box .line { display: flex; justify-content: space-between; font-size: 13.5px; padding: 3px 0; }
.summary-box .line.total { font-weight: 700; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 7px; }

.photos-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.photo-thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #eee; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb .del { position: absolute; top: 3px; right: 3px; background: rgba(0,0,0,0.55); color: #fff;
  border: none; border-radius: 50%; width: 22px; height: 22px; font-size: 12px; line-height: 1; }
.upload-btn { display: inline-block; padding: 10px 14px; border-radius: 10px; background: #efefef; font-size: 14px;
  border: 1px dashed var(--muted); text-align: center; }
.upload-row { display: flex; gap: 8px; margin: 10px 0; }

.save-bar { position: fixed; bottom: 0; left: 0; right: 0; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 60%, transparent); z-index: 15; }
.primary-btn { width: 100%; padding: 14px; border: none; border-radius: 12px; background: var(--red); color: #fff;
  font-size: 16px; font-weight: 600; box-shadow: 0 2px 8px rgba(192,57,43,0.4); }

.fab { position: fixed; right: 18px; bottom: calc(20px + env(safe-area-inset-bottom)); width: 56px; height: 56px;
  border-radius: 50%; background: var(--red); color: #fff; font-size: 28px; border: none;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25); z-index: 15; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.9); z-index: 50; display: flex;
  align-items: center; justify-content: center; }
.lightbox.hidden { display: none; }
.lightbox img { max-width: 94%; max-height: 90%; border-radius: 6px; }
.lightbox .icon-btn { position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 14px; }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #222; color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 13.5px; z-index: 60; max-width: 86%; text-align: center; }
.toast.hidden { display: none; }

.empty-hint { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 14px; }

a.akte-link { display: block; text-align: center; padding: 10px; color: var(--red); font-size: 13.5px; }

/* ---- Lagerbestand ---- */
.inventory-summary { padding: 10px 14px 0 14px; color: var(--muted); font-size: 13px; }
.inventory-list { padding: 8px 12px 90px 12px; }
.inventory-category { font-weight: 700; font-size: 12.5px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.03em; margin: 16px 4px 6px 4px; }
.inventory-category:first-child { margin-top: 4px; }
.inventory-row { background: var(--card-bg); border-radius: var(--radius); padding: 10px 12px;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); margin-bottom: 8px; }
.inventory-row.low { border: 1px solid #e3a7a1; background: #fdf3f2; }
.inventory-row .inv-info { flex: 1; min-width: 0; }
.inventory-row .inv-name { font-weight: 600; font-size: 14.5px; }
.inventory-row .inv-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.inventory-row .inv-meta.low-text { color: #b00000; }
.inventory-row .inv-controls { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.inv-stepper { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; font-size: 17px; line-height: 1; }
.inv-count { min-width: 24px; text-align: center; font-weight: 700; font-size: 15px; }
.inv-edit-btn { width: 32px; height: 32px; font-size: 13px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 55;
  display: flex; align-items: flex-end; justify-content: center; }
.modal.hidden { display: none; }
.modal-box { background: #fff; width: 100%; max-width: 480px; border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 86vh; overflow-y: auto; }
.modal-box h3 { margin: 0 0 8px 0; font-size: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; align-items: center; }
.modal-actions .primary-btn { flex: 1; }
.modal-actions #inventory-cancel-btn { flex: 0 0 auto; padding: 0 14px; height: 42px; border-radius: 10px;
  border: 1px solid var(--border); background: #fff; font-size: 14px; }
