:root {
  --color-bg: #f5f5f4;
  --color-surface: #ffffff;
  --color-border: #ddd;
  --color-primary: #2f6f4f;
  --color-error: #c0392b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: var(--color-bg);
  color: #222;
}

.hidden {
  display: none;
}

.auth-screen {
  max-width: 360px;
  margin: 10vh auto;
  padding: 2rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  text-align: center;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1rem 0;
}

input,
button {
  padding: 0.6rem;
  font-size: 1rem;
  border-radius: 4px;
  border: 1px solid var(--color-border);
}

button {
  background: var(--color-primary);
  color: #fff;
  border: none;
  cursor: pointer;
}

.error {
  color: var(--color-error);
  font-size: 0.9rem;
}

.app-shell header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.app-shell header .brand {
  font-weight: bold;
  cursor: pointer;
}

#group-switcher {
  margin-right: auto;
}

#group-switcher select {
  padding: 0.4rem;
  font-size: 0.95rem;
  border-radius: 4px;
  border: 1px solid var(--color-border);
}

#profil-btn {
  background: transparent;
  color: inherit;
  border: 1px solid var(--color-border);
}

#profil-btn.active {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

main {
  max-width: 960px;
  margin: 2rem auto;
  padding: 0 1rem;
}

#group-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.group-item {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.badge {
  background: var(--color-primary);
  color: #fff;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
}

.empty {
  color: #888;
}

.group-item.active {
  border-color: var(--color-primary);
  box-shadow: inset 4px 0 0 var(--color-primary);
}

/* ============================================================
   LAGERORTE
   ============================================================ */

#lagerorte {
  margin-top: 2rem;
}

select {
  padding: 0.6rem;
  font-size: 1rem;
  border-radius: 4px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.5rem 0;
}

.inline-form input,
.inline-form select {
  flex: 1;
  min-width: 140px;
}

.lagerort-tree,
.lagerort-tree ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.lagerort-tree ul {
  margin-left: 1.25rem;
  border-left: 2px solid var(--color-border);
  padding-left: 0.75rem;
}

.lagerort-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  margin: 0.35rem 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.lagerort-name {
  margin-right: auto;
  font-weight: 500;
}

.lagerort-actions {
  display: flex;
  gap: 0.35rem;
}

.btn-small {
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
}

.btn-secondary {
  background: #6b7280;
}

.btn-danger {
  background: var(--color-error);
}

/* ============================================================
   TABS
   ============================================================ */

#group-content {
  margin-top: 2rem;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: 1rem;
}

.tab {
  background: transparent;
  color: #444;
  border-radius: 4px 4px 0 0;
  margin-bottom: -2px;
  border-bottom: 2px solid transparent;
}

.tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  font-weight: 600;
}

/* ============================================================
   BESTAND & ARTIKEL
   ============================================================ */

.input-narrow {
  flex: 0 1 110px !important;
  min-width: 90px !important;
}

input[readonly] {
  background: var(--color-bg);
  color: #666;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0 0.5rem;
}

.filter-bar > * {
  flex: 1;
  min-width: 160px;
}

.table-wrap {
  overflow-x: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table th {
  font-size: 0.85rem;
  color: #666;
  font-weight: 600;
}

.muted {
  display: block;
  font-size: 0.8rem;
  color: #888;
}

.qty-cell {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.qty {
  min-width: 5.5rem;
  text-align: center;
}

.expired {
  color: var(--color-error);
  font-weight: 600;
}

.row-actions {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
}

/* ============================================================
   WARNUNGEN / ÜBERSICHT
   ============================================================ */

:root {
  --color-warning: #b45309;
  --color-warning-bg: #fef3c7;
}

.tab-badge {
  display: inline-block;
  min-width: 1.3rem;
  padding: 0 0.35rem;
  margin-left: 0.25rem;
  border-radius: 999px;
  background: var(--color-error);
  color: #fff;
  font-size: 0.75rem;
  line-height: 1.3rem;
  text-align: center;
}

.badge-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
  margin-left: 0.35rem;
}

.row-low td {
  background: #fffbeb;
}

.expiring {
  color: var(--color-warning);
  font-weight: 600;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.card {
  padding: 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.card h3 {
  margin-top: 0;
}

.muted-inline {
  font-size: 0.85rem;
  font-weight: normal;
  color: #888;
}

.warning-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.warning-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--color-border);
}

.warning-list li:last-child {
  border-bottom: none;
}

.warning-name {
  font-weight: 600;
}

.warning-detail {
  color: #555;
  font-size: 0.9rem;
  margin-right: auto;
}

/* ============================================================
   INVENTAR, VERLEIH, FOTOS
   ============================================================ */

:root {
  --color-lent: #1d4ed8;
  --color-lent-bg: #dbeafe;
}

.badge-lent {
  background: var(--color-lent-bg);
  color: var(--color-lent);
  margin-left: 0.35rem;
}

.art-tag {
  font-size: 0.75rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  color: #555;
}

.checkbox-label,
.field-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: #555;
}

.filter-bar > .checkbox-label {
  flex: 0 0 auto;
  min-width: 0;
}

.inline-form .field-label {
  flex: 1;
  min-width: 180px;
}

.inline-form .field-label input {
  flex: 1;
  min-width: 0;
}

.global-search {
  margin-bottom: 1.25rem;
}

.global-search input {
  width: 100%;
}

.search-results {
  list-style: none;
  padding: 0.25rem 1rem;
  margin: 0.5rem 0 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.search-results li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.6rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--color-border);
}

.search-results li:last-child {
  border-bottom: none;
}

.inv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 1rem;
}

.inv-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.inv-card.is-lent {
  border-left: 4px solid var(--color-lent);
}

.inv-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.inv-location {
  color: #555;
  font-size: 0.9rem;
}

.inv-lent {
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  background: var(--color-lent-bg);
  color: var(--color-lent);
  font-size: 0.9rem;
}

.inv-details {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.75rem;
  margin: 0;
  font-size: 0.9rem;
}

.inv-details dt {
  color: #777;
}

.inv-details dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.foto-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.foto-thumb {
  position: relative;
  margin: 0;
  width: 72px;
  height: 72px;
}

.foto-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  cursor: zoom-in;
}

.foto-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  background: var(--color-error);
  font-size: 0.9rem;
  line-height: 22px;
}

.foto-add {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border: 2px dashed var(--color-border);
  border-radius: 4px;
  color: #666;
  font-size: 0.8rem;
  cursor: pointer;
}

.foto-add:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.foto-add.busy {
  opacity: 0.5;
  pointer-events: none;
}

.inv-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: auto;
}

.stacked-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--color-border);
}

.stacked-form label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.85rem;
  color: #555;
}

.form-buttons {
  display: flex;
  gap: 0.5rem;
}

#lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.85);
  cursor: zoom-out;
}

#lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  cursor: default;
}

.lightbox-close {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 1rem);
  right: 1rem;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  font-size: 1.5rem;
}

/* ============================================================
   PRÜFEN (Lagerort durchgehen und abhaken)
   ============================================================ */

.pruef-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin: 1rem 0;
}

.pruef-bar select {
  flex: 1;
  min-width: 200px;
}

#pruef-progress {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.pruef-done {
  color: var(--color-primary);
  font-weight: 600;
}

.pruef-group h3 {
  font-size: 1rem;
  margin: 1.25rem 0 0.5rem;
}

.pruef-items {
  list-style: none;
  padding: 0;
  margin: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.pruef-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  border-left: 4px solid transparent;
}

.pruef-row:last-child {
  border-bottom: none;
}

.pruef-row.is-da {
  border-left-color: var(--color-primary);
  opacity: 0.7;
}

.pruef-row.is-fehlt {
  border-left-color: var(--color-error);
  background: #fdecea;
}

.pruef-main {
  flex: 1;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.pruef-name {
  font-weight: 600;
}

.pruef-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.pruef-form-slot {
  flex-basis: 100%;
}

.pruef-form-slot:empty {
  display: none;
}

/* ============================================================
   PROFIL
   ============================================================ */

.profil-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.profil-card {
  margin-bottom: 1rem;
}

.profil-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.profil-grid .profil-card {
  margin-bottom: 0;
}

.profil-card .inline-form {
  margin: 0;
}

.group-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 200px;
}

.group-invite {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.badge-active {
  background: var(--color-bg);
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
}

.welcome {
  text-align: center;
  padding: 2rem 1rem;
}

/* ============================================================
   ARTIKEL-DETAILANSICHT UND QR-CODES
   ============================================================ */

.item-link {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}

.item-link:hover {
  color: var(--color-primary);
}

.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35rem;
  margin: 0.5rem 0;
}

#qr-sheet {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.6);
  overflow-y: auto;
  padding: 2rem 1rem;
}

.qr-sheet-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
  background: var(--color-surface);
  border-radius: 8px;
}

.qr-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.qr-hint {
  margin: 0.5rem 0 1rem;
}

.qr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 1rem;
}

.qr-label {
  margin: 0;
  padding: 0.75rem;
  border: 1px dashed var(--color-border);
  border-radius: 6px;
  text-align: center;
  break-inside: avoid;
}

.qr-label svg {
  width: 100%;
  max-width: 160px;
  height: auto;
}

.qr-label figcaption {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.85rem;
  word-break: break-word;
}

.qr-label figcaption span {
  color: #555;
  font-size: 0.75rem;
}

/* Beim Drucken nur das Etikettenblatt ausgeben */
@media print {
  body:has(#qr-sheet) > *:not(#qr-sheet) {
    display: none !important;
  }

  #qr-sheet {
    position: static;
    background: none;
    padding: 0;
    overflow: visible;
  }

  .qr-sheet-inner {
    max-width: none;
    padding: 0;
  }

  .qr-toolbar,
  .qr-hint {
    display: none;
  }

  .qr-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5cm;
  }

  .qr-label {
    border-color: #999;
  }
}

/* ============================================================
   ETIKETTEN-DESIGNER (Lagerorte)
   ============================================================ */

[hidden] {
  display: none !important;
}

#label-designer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.6);
  padding: 1.5rem 1rem;
  overflow-y: auto;
}

.ld-panel {
  display: flex;
  flex-wrap: wrap;
  max-width: 1150px;
  min-height: calc(100vh - 3rem);
  margin: 0 auto;
  background: var(--color-surface);
  border-radius: 10px;
  overflow: hidden;
}

.ld-controls {
  flex: 0 0 300px;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1.25rem;
  border-right: 1px solid var(--color-border);
}

.ld-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ld-head h2 {
  margin: 0;
  font-size: 1.2rem;
}

.ld-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-weight: 600;
  font-size: 0.9rem;
}

.ld-field select,
.ld-field input {
  font-weight: normal;
}

.ld-field input[type="number"] {
  flex: none;
  width: 6rem;
}

.ld-field .muted {
  font-weight: normal;
  font-size: 0.8rem;
}

.ld-options {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem 0.75rem;
}

.ld-options legend {
  font-weight: 600;
  font-size: 0.9rem;
}

.ld-orte-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ld-orte {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0.5rem;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.ld-orte li {
  padding-block: 0.15rem;
}

.ld-hint {
  font-size: 0.8rem;
  margin: 0;
}

.ld-preview {
  flex: 1;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 1.5rem;
  background: #e7e5e4;
  overflow-x: auto;
}

/* Eine Druckseite (Bogen bzw. Etikett), auf dem Bildschirm verkleinert dargestellt */
.label-page {
  position: relative;
  flex: 0 0 auto;
  background: #fff;
  overflow: hidden;
  zoom: var(--preview-zoom, 1);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

/* --- Das Etikett selbst. Größen relativ zum Etikett: --lw/--lh = 1 % der Breite/Höhe in mm
   (setzt view.js; bewusst keine Container-Einheiten, die im Druck nicht zuverlässig sind) --- */

.label {
  position: absolute;
  box-sizing: border-box;
  display: flex;
  overflow: hidden;
  background: #fff;
  color: #111827;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* Etikettenkanten nur in der Vorschau andeuten */
.label-page.is-sheet .label {
  outline: 1px dashed #d6d3d1;
  outline-offset: -1px;
  border-radius: 2mm;
}

.label-band {
  flex: 0 0 max(1.6mm, calc(var(--lw) * 2.4));
  background: var(--accent);
}

.label-qr {
  flex: 0 0 auto;
  align-self: center;
  height: min(100%, calc(var(--lw) * 42));
  aspect-ratio: 1;
  padding: calc(var(--lh) * 8) calc(var(--lh) * 6) calc(var(--lh) * 8) calc(var(--lh) * 8);
  box-sizing: border-box;
}

.label-qr svg {
  display: block;
  width: 100%;
  height: 100%;
}

.label-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: calc(var(--lh) * 2.5);
  padding: calc(var(--lh) * 9) calc(var(--lh) * 7) calc(var(--lh) * 7) calc(var(--lh) * 2);
  overflow: hidden;
}

.label-path {
  flex: none;
  font-size: min(calc(var(--lh) * 8.5), calc(var(--lw) * 3.6));
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.label-name {
  flex: none;
  font-size: min(calc(var(--lh) * 21), var(--name-max));
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.01em;
  overflow-wrap: break-word;
  hyphens: manual;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.label-inhalt {
  min-height: 0;
  font-size: min(calc(var(--lh) * 7.5), calc(var(--lw) * 3.2));
  line-height: 1.3;
  color: #4b5563;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.label-footer {
  flex: none;
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1mm;
  padding-top: calc(var(--lh) * 2);
  border-top: 0.25mm solid #e5e7eb;
  font-size: min(calc(var(--lh) * 6.5), calc(var(--lw) * 2.7));
  color: #6b7280;
  white-space: nowrap;
}

.label-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6mm;
  font-weight: 700;
  color: var(--accent);
}

.label-brand svg {
  width: 1.2em;
  height: 1.2em;
}

/* Sehr flache Etiketten (z. B. 62 × 29 mm): nur Pfad, Name und QR-Code */
.label.is-compact .label-footer,
.label.is-compact .label-inhalt {
  display: none;
}

.label.is-compact .label-name {
  font-size: min(calc(var(--lh) * 26), var(--name-max));
}

/* Hochformat (A6): Farbband oben, großer QR-Code, Text zentriert darunter */
.label.is-portrait {
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.label.is-portrait .label-band {
  flex: 0 0 calc(var(--lw) * 3.5);
  align-self: stretch;
}

.label.is-portrait .label-qr {
  align-self: center;
  height: auto;
  width: calc(var(--lw) * 62);
  padding: calc(var(--lw) * 8) 0 calc(var(--lw) * 4);
}

.label.is-portrait .label-text {
  align-self: stretch;
  align-items: center;
  gap: calc(var(--lw) * 1.5);
  padding: calc(var(--lw) * 2) calc(var(--lw) * 8) calc(var(--lw) * 6);
}

.label.is-portrait .label-path {
  flex: none;
  font-size: calc(var(--lw) * 4.5);
}

.label.is-portrait .label-name {
  font-size: min(calc(var(--lw) * 12), var(--name-max));
}

.label.is-portrait .label-inhalt {
  font-size: calc(var(--lw) * 4.2);
  -webkit-line-clamp: 4;
}

.label.is-portrait .label-footer {
  align-self: stretch;
  font-size: calc(var(--lw) * 3);
  padding-top: calc(var(--lw) * 2);
}

/* Drucken: nur die Etikettenseiten, in Originalgröße */
@media print {
  body:has(#label-designer) {
    margin: 0;
    background: #fff;
  }

  body:has(#label-designer) > *:not(#label-designer) {
    display: none !important;
  }

  #label-designer {
    position: static;
    padding: 0;
    background: none;
    overflow: visible;
  }

  .ld-panel {
    display: block;
    max-width: none;
    min-height: 0;
    border-radius: 0;
  }

  .ld-controls {
    display: none !important;
  }

  .ld-preview {
    display: block;
    padding: 0;
    background: none;
    overflow: visible;
  }

  .label-page {
    zoom: 1 !important;
    box-shadow: none;
    break-after: page;
  }

  .label-page:last-child {
    break-after: auto;
  }

  .label-page.is-sheet .label {
    outline: none;
  }
}

/* ============================================================
   HINZUFÜGEN-FORMULARE (aufklappbar)
   ============================================================ */

.add-panel {
  margin: 0.5rem 0;
}

.add-panel > summary {
  display: inline-block;
  padding: 0.35rem 0;
  color: var(--color-primary);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.add-panel > summary::-webkit-details-marker {
  display: none;
}

.add-panel[open] > summary {
  color: #555;
}

.tab-icon {
  display: none;
}

/* ============================================================
   ETIKETTENFARBE PRO LAGERORT
   ============================================================ */

.farb-punkt {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  margin-right: 0.45rem;
  border-radius: 50%;
  vertical-align: -0.05rem;
  background: var(--dot);
}

/* Punkt in der Option „wie übergeordnet“ */
.swatch-auto .farb-punkt {
  margin-right: 0.35rem;
  vertical-align: -0.1rem;
}

/* --- Ein-/Ausklappen im Lagerort-Baum --- */

.tree-toggle,
.tree-toggle-spacer {
  flex: none;
  width: 1.6rem;
  min-height: 0;
}

.tree-toggle {
  height: 1.6rem;
  padding: 0;
  border-radius: 4px;
  background: transparent;
  color: #555;
  font-size: 0.95rem;
  line-height: 1;
}

.tree-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tree-toggle svg {
  width: 1.15rem;
  height: 1.15rem;
  transition: transform 0.15s;
}

/* zugeklappt: Pfeil zeigt nach rechts */
.tree-toggle.is-zu svg {
  transform: rotate(-90deg);
}

.tree-toggle:hover {
  background: var(--color-bg);
  color: var(--color-primary);
}

.lagerort-row .lagerort-name .muted-inline {
  margin-left: 0.35rem;
}

.farb-wahl {
  flex: 1 1 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  padding: 0.4rem 0.6rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.farb-wahl legend {
  font-size: 0.85rem;
  color: #555;
}

.swatch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.swatch input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.swatch > span {
  display: inline-block;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  background: var(--swatch);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--color-border);
}

.swatch-auto > span {
  width: auto;
  height: 1.9rem;
  padding: 0 0.7rem;
  border-radius: 999px;
  background: var(--color-bg);
  font-size: 0.8rem;
  line-height: 1.75rem;
  color: #555;
}

.swatch input[type="radio"]:checked + span,
.swatch-custom input[type="radio"]:checked + input[type="color"] {
  box-shadow: 0 0 0 2.5px #111827;
}

.swatch input[type="radio"]:focus-visible + span {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.swatch-custom input[type="color"] {
  width: 1.9rem;
  height: 1.9rem;
  min-width: 0 !important;
  flex: none !important;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--color-border);
  cursor: pointer;
  overflow: hidden;
}

.swatch-custom input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.swatch-custom input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
}

/* ============================================================
   MOBILE ANSICHT (≤ 720 px; Breakpoint auch in view.js → isMobile)
   ============================================================ */

@media (max-width: 720px) {
  /* 16 px verhindert das automatische Hineinzoomen von iOS in Eingabefelder */
  input,
  select,
  button {
    font-size: 16px;
  }

  button {
    min-height: 42px;
  }

  .btn-small {
    min-height: 38px;
    padding: 0.4rem 0.75rem;
    font-size: 0.9rem;
  }

  .auth-screen {
    margin: 6vh 1rem;
    padding: 1.5rem 1.25rem;
  }

  /* --- Kopfzeile kompakt --- */

  .app-shell header {
    gap: 0.5rem;
    padding: calc(env(safe-area-inset-top, 0px) + 0.6rem) 0.75rem 0.6rem;
  }

  .brand-text,
  #current-username {
    display: none;
  }

  .app-shell header .brand {
    font-size: 1.4rem;
  }

  #group-switcher {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #group-switcher select {
    width: 100%;
    font-size: 16px;
  }

  #profil-btn {
    flex: none;
    width: 42px;
    padding: 0;
    font-size: 1.2rem;
  }

  main {
    margin: 0.75rem auto;
    padding: 0 0.75rem calc(80px + env(safe-area-inset-bottom, 0px));
  }

  h2 {
    font-size: 1.3rem;
  }

  #group-content {
    margin-top: 0;
  }

  /* --- Tabs als Navigationsleiste unten --- */

  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0;
    margin: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--color-surface);
    border-bottom: none;
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
  }

  .tab {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    min-height: 58px;
    margin: 0;
    padding: 0.45rem 0 0.35rem;
    border-radius: 0;
    border-bottom: none;
    border-top: 3px solid transparent;
    font-size: 0.68rem;
    color: #666;
  }

  .tab.active {
    border-top-color: var(--color-primary);
    background: #eef6f1;
  }

  .tab-icon {
    display: block;
    font-size: 1.3rem;
    line-height: 1;
  }

  .tab-badge {
    position: absolute;
    top: 3px;
    left: 56%;
    min-width: 1.15rem;
    margin: 0;
    padding: 0 0.3rem;
    font-size: 0.65rem;
    line-height: 1.15rem;
  }

  /* --- Formulare untereinander --- */

  .inline-form {
    flex-direction: column;
    align-items: stretch;
  }

  .inline-form input,
  .inline-form select,
  .inline-form .field-label,
  .inline-form .input-narrow {
    flex: none !important;
    width: 100%;
    min-width: 0 !important;
  }

  .inline-form .field-label {
    justify-content: space-between;
  }

  .inline-form .farb-wahl input[type="color"] {
    width: 2.4rem !important;
  }

  .swatch > span,
  .swatch-custom input[type="color"] {
    width: 2.4rem;
    height: 2.4rem;
  }

  .inline-form .field-label input {
    flex: 1 !important;
    width: auto;
  }

  .add-panel {
    padding: 0.25rem 0.75rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
  }

  .add-panel > summary {
    display: block;
    padding: 0.6rem 0;
  }

  .filter-bar > * {
    flex: 1 1 100%;
    min-width: 0;
  }

  .filter-bar > .checkbox-label {
    flex: 1 1 100%;
  }

  /* --- Tabellen als Karten --- */

  .table-wrap {
    overflow: visible;
    background: none;
    border: none;
  }

  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
  }

  .data-table thead {
    display: none;
  }

  .data-table tr {
    margin-bottom: 0.6rem;
    padding: 0.65rem 0.85rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
  }

  .data-table tr.row-low {
    background: #fffbeb;
  }

  .row-low td {
    background: none;
  }

  .data-table td {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0;
    border: none;
    white-space: normal;
  }

  .data-table td:empty {
    display: none;
  }

  .data-table td:first-child {
    font-size: 1.05rem;
    font-weight: 600;
    padding-bottom: 0.4rem;
  }

  .data-table td:first-child .muted {
    flex-basis: 100%;
    font-weight: normal;
  }

  .data-table td[data-label]::before {
    content: attr(data-label);
    margin-right: auto;
    font-size: 0.85rem;
    font-weight: normal;
    color: #888;
  }

  .data-table td.row-actions {
    justify-content: flex-end;
    padding-top: 0.5rem;
  }

  .qty {
    min-width: 4.5rem;
  }

  /* --- Lagerorte --- */

  .lagerort-tree ul {
    margin-left: 0.4rem;
    padding-left: 0.5rem;
  }

  .lagerort-name {
    flex: 1 1 0;
  }

  .tree-toggle {
    width: 2.2rem;
    height: 2.2rem;
    min-height: 0;
    font-size: 1.1rem;
  }

  .lagerort-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    width: 100%;
  }

  .lagerort-actions .btn-small {
    padding: 0.35rem 0.2rem;
    font-size: 0.78rem;
  }

  /* --- Inventar, Übersicht --- */

  .inv-actions button {
    flex: 1 1 auto;
  }

  .warning-list li .btn-small {
    margin-left: auto;
  }

  /* --- Prüfen: Fortschritt bleibt oben sichtbar, große Knöpfe --- */

  .pruef-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: 0 -0.75rem 0.5rem;
    padding: 0.6rem 0.75rem;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
  }

  .pruef-bar select {
    flex: 1 1 100%;
    min-width: 0;
  }

  .pruef-row {
    padding: 0.75rem;
  }

  .pruef-actions {
    width: 100%;
  }

  .pruef-actions button {
    flex: 1 1 auto;
  }

  /* --- Profil, Detailansicht --- */

  .group-invite {
    flex: 1 1 100%;
  }

  #logout-btn {
    margin-top: 0.75rem;
  }

  .profil-head .row-actions {
    flex-wrap: wrap;
  }

  /* --- Overlays bildschirmfüllend --- */

  #qr-sheet,
  #label-designer {
    padding: 0;
  }

  .qr-sheet-inner,
  .ld-panel {
    min-height: 100vh;
    border-radius: 0;
  }

  .ld-controls {
    flex: 1 1 100%;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }

  .ld-preview {
    min-width: 0;
    padding: 1rem 0.5rem;
  }

  .qr-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Desktop: Tabellenzellen bleiben echte Zellen (display: flex auf <td> verschiebt die Zeilenlinien) */
@media (min-width: 721px) {
  .data-table td.qty-cell,
  .data-table td.row-actions {
    display: table-cell;
    vertical-align: middle;
  }

  .data-table td.qty-cell > * + * {
    margin-left: 0.4rem;
  }

  .data-table td.qty-cell .qty {
    display: inline-block;
  }

  .data-table td.row-actions {
    text-align: right;
  }

  .data-table td.row-actions > * + * {
    margin-left: 0.35rem;
  }
}
