:root {
  --primary: #2b2b33;
  --primary-dark: #17171d;
  --accent: #8a4fbe;
  --accent-soft: #f2eafa;
  --bg: #f5f5f8;
  --card: #ffffff;
  --border: #e3e3ea;
  --border-strong: #d2d2dc;
  --text: #1d1f24;
  --muted: #6b6f78;
  --good: #2e7d4f;
  --warn: #a06a00;
  --bad: #b3372a;
  --shadow: 0 1px 2px rgba(20, 20, 30, 0.04), 0 4px 16px rgba(20, 20, 30, 0.05);
  --shadow-lift: 0 2px 6px rgba(20, 20, 30, 0.08), 0 12px 28px rgba(20, 20, 30, 0.10);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, "Segoe UI Variable Text", Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); }
a:hover { color: var(--accent); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.82rem; margin: 0.25rem 0 0; }

/* ---------- Grundgeruest ---------- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 244px;
  min-width: 244px;
  background: linear-gradient(180deg, #1c1c23 0%, #141419 100%);
  color: #eef1f3;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: white;
  padding: 1.15rem 1.25rem 0.95rem;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  letter-spacing: 0.02em;
}
.sidebar .brand-sub {
  font-size: 0.72rem; font-weight: 500; letter-spacing: 0.06em;
  text-transform: uppercase; color: rgba(255,255,255,0.45); display: block; margin-top: 0.15rem;
}

.sidebar nav { flex: 1; padding: 0.4rem 0 1rem; }

.sidebar .nav-section {
  padding: 1rem 1.25rem 0.35rem;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.38);
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: #d8dce2;
  text-decoration: none;
  padding: 0.5rem 1.25rem;
  font-size: 0.94rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.12s ease, color 0.12s ease;
}
.sidebar nav a svg { width: 17px; height: 17px; flex: none; opacity: 0.75; }
.sidebar nav a:hover { background: rgba(255,255,255,0.07); color: #fff; }
.sidebar nav a.active {
  background: rgba(138,79,190,0.22);
  border-left-color: var(--accent);
  color: #fff;
}
.sidebar nav a.active svg { opacity: 1; }

.sidebar-footer {
  padding: 0.9rem 1.25rem 1.1rem;
  border-top: 1px solid rgba(255,255,255,0.10);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}
.sidebar-footer .user-badge { color: white; line-height: 1.3; }
.sidebar-footer .user-badge span { color: rgba(255,255,255,0.5); font-size: 0.76rem; }
.sidebar-footer a { color: #c9ced6; text-decoration: none; font-size: 0.82rem; white-space: nowrap; }
.sidebar-footer a:hover { color: #fff; text-decoration: underline; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.container {
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 1.75rem 1.75rem 2.5rem;
  flex: 1;
}

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; height: auto; position: static; }
  .sidebar nav { display: flex; flex-wrap: wrap; padding: 0.4rem; }
  .sidebar .nav-section { display: none; }
  .sidebar nav a { border-left: none; border-bottom: 3px solid transparent; padding: 0.5rem 0.8rem; }
  .sidebar nav a.active { border-bottom-color: var(--accent); }
  .container { padding: 1.1rem; }
}

/* ---------- Seitenkopf ---------- */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.35rem;
}
.page-head h1 { margin: 0; }
.page-sub { color: var(--muted); margin: 0.3rem 0 0; font-size: 0.92rem; }
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

h1 { font-size: 1.55rem; margin: 0 0 1.1rem; letter-spacing: -0.01em; }
h2 { font-size: 1.12rem; margin: 0 0 0.8rem; letter-spacing: -0.01em; }
h3 { font-size: 1rem; margin: 0 0 0.5rem; }

/* ---------- Karten & Raster ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.3rem;
  margin-bottom: 1.15rem;
  box-shadow: var(--shadow);
}
.card h2 { display: flex; align-items: center; gap: 0.5rem; }

.grid { display: grid; gap: 1.15rem; }
.grid > .card { margin-bottom: 0; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid + .grid, .grid + .card { margin-top: 1.15rem; }

/* ---------- Tabellen ---------- */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.62rem 0.55rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th {
  color: var(--muted); font-weight: 600; font-size: 0.74rem;
  text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-strong); white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td, table tr:hover td { background: #fafafc; }
td.num, th.num { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; margin: 0 -0.3rem; padding: 0 0.3rem; }
.row-actions { white-space: nowrap; }

/* Aktionsspalte klebt am rechten Rand.
   Die Terminliste ist breiter als der Bildschirm; ohne das stuenden
   "Erledigt" und "Loeschen" ausserhalb des Sichtbereichs und waeren nur nach
   seitlichem Scrollen erreichbar - also praktisch nicht. */
.table-wrap td.aktionen, .table-wrap th.aktionen {
  position: sticky;
  right: 0;
  background: var(--card);
  white-space: nowrap;
  box-shadow: -8px 0 8px -8px rgba(0, 0, 0, 0.28);
}
tbody tr:hover td.aktionen, table tr:hover td.aktionen { background: #fafafc; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: var(--primary);
  color: white;
  border: 1px solid transparent;
  padding: 0.6rem 1.05rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  min-height: 42px;
  line-height: 1.25;
  transition: background 0.12s ease, box-shadow 0.12s ease, transform 0.06s ease;
}
.btn:hover { background: var(--primary-dark); color: white; }
.btn:active { transform: translateY(1px); }
.btn.accent { background: var(--accent); }
.btn.accent:hover { background: #7a41ab; }
.btn.secondary { background: #ffffff; color: var(--text); border-color: var(--border-strong); }
.btn.secondary:hover { background: #f4f4f7; color: var(--text); }
.btn.danger { background: var(--bad); }
.btn.danger:hover { background: #972e23; }
.btn.small { padding: 0.35rem 0.7rem; font-size: 0.84rem; min-height: 32px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

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

label { display: block; font-weight: 600; margin: 0.75rem 0 0.25rem; font-size: 0.86rem; }
input, select, textarea {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.97rem;
  font-family: inherit;
  background: white;
  color: var(--text);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(138,79,190,0.15);
}
input[type="checkbox"] { width: auto; }
textarea { min-height: 74px; resize: vertical; }
form .row { display: flex; gap: 1rem; flex-wrap: wrap; }
form .row > div { flex: 1; min-width: 165px; }
.form-actions { margin-top: 1.15rem; display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.stack-form { margin-top: 0.7rem; max-width: 420px; }

/* Aufklapp-Bereiche (Bearbeiten-Formulare in Tabellen) */
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary { margin-bottom: 0.3rem; }

/* ---------- Badges ---------- */

.badge {
  display: inline-block; padding: 0.12rem 0.55rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600; white-space: nowrap;
}
.badge.good { background: #e4f3ea; color: var(--good); }
.badge.warn { background: #fbf1dc; color: var(--warn); }
.badge.bad { background: #fbe6e2; color: var(--bad); }
.badge.neutral { background: #ececf1; color: var(--muted); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- Kennzahlen ---------- */

.kpi { text-align: center; padding: 1.15rem 1rem; }
.kpi .value { font-size: 1.7rem; font-weight: 700; color: var(--primary-dark); letter-spacing: -0.02em; }
.kpi .value.good { color: var(--good); }
.kpi .value.bad { color: var(--bad); }
.kpi .value.accent { color: var(--accent); }
.kpi .label { color: var(--muted); font-size: 0.82rem; margin-top: 0.2rem; }

/* ---------- Meldungen ---------- */

.flash {
  padding: 0.75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem;
  font-size: 0.93rem; border: 1px solid transparent;
}
.flash.error { background: #fbe6e2; border-color: #f2cec8; color: var(--bad); }
.flash.success { background: #e4f3ea; border-color: #c9e6d5; color: var(--good); }
.flash.warn { background: #fbf1dc; border-color: #efdfba; color: var(--warn); }

.empty { color: var(--muted); text-align: center; padding: 1.4rem 0; }

.tag-row { display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0.4rem 0; }

.toolbar {
  display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1.1rem;
}
.toolbar form { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; }
.toolbar label { margin: 0; }

/* ---------- Kanban ---------- */

.kanban-board { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 1rem; align-items: start; }
.kanban-col { background: #ececf1; border-radius: var(--radius); padding: 0.8rem; }
.kanban-col h3 { margin: 0.2rem 0.25rem 0.75rem; font-size: 0.92rem; }
.kanban-card {
  background: white; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.7rem 0.8rem; margin-bottom: 0.6rem; box-shadow: var(--shadow);
}
.kanban-card .title { font-weight: 600; }
.kanban-card .meta { color: var(--muted); font-size: 0.82rem; margin-top: 0.2rem; }

/* ---------- Balkendiagramme ---------- */

.bar-row { display: flex; align-items: center; gap: 0.7rem; margin: 0.3rem 0; }
.bar-row .bar-label { width: 130px; min-width: 130px; font-size: 0.84rem; color: var(--muted); text-align: right; }
.bar-row .bar-track { flex: 1; background: #ececf1; border-radius: 999px; height: 20px; overflow: hidden; }
.bar-row .bar-fill { background: var(--accent); height: 100%; border-radius: 999px; min-width: 2px; transition: width 0.3s ease; }
.bar-row .bar-fill.income { background: var(--good); }
.bar-row .bar-fill.expense { background: var(--bad); }
.bar-row .bar-value { font-size: 0.84rem; white-space: nowrap; min-width: 90px; text-align: right; }

/* ---------- Login ---------- */

.login-wrap { display: flex; justify-content: center; padding-top: 8vh; }
.login-card { max-width: 390px; width: 100%; text-align: left; box-shadow: var(--shadow-lift); }

/* ---------- Abschnitts-Reiter ---------- */

.section-tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.section-tabs a {
  text-decoration: none; padding: 0.42rem 0.9rem; border-radius: 999px;
  border: 1px solid var(--border-strong); background: white; color: var(--text); font-size: 0.88rem;
}
.section-tabs a:hover { border-color: var(--accent); color: var(--accent); }
.section-tabs a.active { background: var(--primary-dark); color: white; border-color: var(--primary-dark); }

/* ---------- Kanban-Kartenvorschau ---------- */
/* Bildet das PDF-Layout nach (Karte 100 x 60 mm), damit vor dem Druck
   sichtbar ist, was auf dem Papier landet. */

.cards-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; position: sticky; top: 0.6rem; z-index: 5;
}

.kanban-print-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1rem; margin-top: 1.15rem;
}

.kb-card {
  position: relative; display: flex; flex-direction: column;
  aspect-ratio: 100 / 60; background: var(--card); cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  overflow: hidden; box-shadow: var(--shadow); transition: box-shadow .15s, opacity .15s;
}
.kb-card:hover { box-shadow: var(--shadow-lift); }
/* Abgewählte Karte blasser - auf einen Blick sichtbar, was gedruckt wird.
   Gesteuert über die Klasse .is-off statt über :has(input:checked): Chrome
   erneuert die :has()-Auswertung nicht zuverlässig, wenn `checked` per
   JavaScript gesetzt wird (Knöpfe "Alle"/"Keine"). */
.kb-card.is-off { opacity: 0.42; filter: saturate(0.25); }

.kb-check {
  position: absolute; top: 0.55rem; right: 0.55rem; width: 20px; height: 20px;
  border-radius: 5px; border: 2px solid rgba(255,255,255,0.85); background: transparent;
}
.kb-card:not(.is-off) .kb-check { background: white; border-color: white; }
.kb-card:not(.is-off) .kb-check::after {
  content: ""; position: absolute; left: 5px; top: 1px;
  width: 6px; height: 11px; border: solid var(--accent);
  border-width: 0 2.5px 2.5px 0; transform: rotate(45deg);
}

.kb-head {
  background: var(--accent); color: white; padding: 0.4rem 0.7rem;
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
}
.kb-brand { font-weight: 700; font-size: 0.74rem; letter-spacing: 0.12em; }
.kb-loc {
  font-weight: 700; font-size: 0.76rem; margin-right: 1.6rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.kb-body { flex: 1; padding: 0.6rem 0.7rem 0.2rem; min-width: 0; position: relative; }

/* QR rechts in einer eigenen Spalte - der Text links endet davor, damit nie
   Schrift über dem Code liegt (das war beim alten Strichcode das Problem). */
.kb-qr {
  position: absolute; top: 0.5rem; right: 0.7rem; width: 27%;
  display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
}
.kb-qr svg { width: 100%; height: auto; display: block; }
.kb-qr span {
  font-family: "Consolas", "SF Mono", monospace; font-size: 0.6rem;
  color: var(--muted); letter-spacing: 0.02em;
}
/* Platz für die QR-Spalte freihalten */
.kb-name, .kb-cat, .kb-row, .kb-supplier { padding-right: 30%; }
.kb-name {
  font-weight: 700; font-size: 1.02rem; line-height: 1.2;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kb-cat { color: var(--muted); font-size: 0.75rem; margin-top: 0.1rem; }

.kb-row { display: flex; gap: 0.7rem; margin-top: 0.5rem; align-items: stretch; }
.kb-qty {
  background: #f0f0f4; border-radius: 6px; padding: 0.3rem 0.55rem;
  min-width: 104px; display: flex; flex-direction: column; justify-content: center;
}
.kb-qty strong { font-size: 1.05rem; line-height: 1.1; }
.kb-fields { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; flex: 1; }
.kb-fields b, .kb-supplier b {
  display: block; font-size: 0.8rem; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.kb-label {
  display: block; font-size: 0.58rem; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--muted);
}
.kb-supplier { margin-top: 0.45rem; }

.kb-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.35rem 0.7rem 0.5rem; border-top: 1px dashed var(--border-strong);
  font-size: 0.72rem; color: var(--muted);
}
.kb-barcode { font-family: "Consolas", "SF Mono", monospace; letter-spacing: 0.05em; }

@media (max-width: 700px) {
  .kanban-print-grid { grid-template-columns: 1fr; }
  .cards-bar { position: static; }
}

/* ---------- Scan-Station: Modus-Umschalter und Kamera ---------- */

.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin-bottom: 0.9rem; }
.mode {
  display: flex; align-items: center; gap: 0.6rem; cursor: pointer; margin: 0;
  border: 2px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 0.6rem 0.7rem; background: var(--card); font-weight: 400;
}
.mode input { display: none; }
.mode small { color: var(--muted); }
.mode.active { border-color: var(--accent); background: var(--accent-soft); }
.mode-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.mode-dot.bad { background: var(--bad); }
.mode-dot.good { background: var(--good); }

.scan-view {
  position: relative; background: #101014; border-radius: var(--radius-sm);
  overflow: hidden; aspect-ratio: 4 / 3;
}
.scan-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Quadratischer Rahmen - der QR-Code ist quadratisch */
.scan-frame {
  position: absolute; top: 10%; bottom: 10%; aspect-ratio: 1 / 1;
  left: 50%; transform: translateX(-50%);
  border: 2px solid rgba(255,255,255,0.85); border-radius: 6px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.35);
}
#scanner:not(.laeuft) .scan-frame { display: none; }
/* Kurze Pause nach einem Treffer: Bild abdunkeln, damit sichtbar ist,
   dass gebucht wird - danach laeuft die Kamera von selbst weiter. */
#scanner.pause .scan-view video { filter: brightness(0.45) grayscale(0.6); }
#scanner.pause .scan-frame { border-color: var(--good); border-width: 3px; }

/* Charge/Haltbarkeit nur im VOLL-Modus */
.voll-felder { transition: opacity .15s; }
.voll-felder.aus { display: none; }

.scan-log { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; }
.scan-log li {
  padding: 0.4rem 0.6rem; border-left: 3px solid var(--border-strong);
  font-size: 0.86rem; margin-bottom: 0.3rem; background: #f7f7fa; border-radius: 0 6px 6px 0;
}
.scan-log li.gut { border-left-color: var(--good); }
.scan-log li.schlecht { border-left-color: var(--bad); color: var(--bad); }

.scan-status { margin: 0.6rem 0 0; font-size: 0.88rem; color: var(--muted); }
.scan-status.good { color: var(--good); font-weight: 600; }
.scan-status.bad { color: var(--bad); font-weight: 600; }

/* ---------- Dialogfenster (z.B. nach dem Beleg-Upload) ---------- */

.dialog-backdrop {
  display: flex; align-items: flex-start; justify-content: center;
  padding: 2.5rem 0; min-height: 60vh;
}
.dialog { max-width: 560px; width: 100%; box-shadow: var(--shadow-lift); }
.dialog h1 { margin: 0 0 0.3rem; font-size: 1.3rem; color: var(--good); }
.dialog table { margin-top: 0.9rem; }
.dialog-filename {
  margin-top: 1rem; padding: 0.7rem 0.8rem;
  background: var(--accent-soft); border-radius: var(--radius-sm);
}
.dialog-filename code { font-size: 0.86rem; word-break: break-all; }

/* ---------- Speicherort auf dem eigenen Rechner ---------- */

.folder-box {
  display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap;
  padding: 0.8rem 0.9rem; margin: 1rem 0 0;
  background: var(--accent-soft); border-radius: var(--radius-sm);
}
.folder-box .folder-icon { font-size: 1.3rem; line-height: 1; }
.folder-box .folder-text { flex: 1 1 14rem; min-width: 0; }
.folder-box .folder-text strong { word-break: break-word; }
.folder-box .folder-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.folder-name { font-weight: 600; }

/* ---------- Kurzmeldungen beim Speichern ---------- */

.toast-host {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 60;
  display: flex; flex-direction: column; gap: 0.5rem;
  max-width: min(26rem, calc(100vw - 2rem));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--card); color: var(--text);
  border: 1px solid var(--border-strong); border-left-width: 4px;
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lift);
  padding: 0.65rem 0.85rem; font-size: 0.88rem; word-break: break-word;
  white-space: pre-line;   /* Erfolgsmeldung steht auf drei Zeilen */
}
.toast-ok { border-left-color: var(--good); }
.toast-bad { border-left-color: var(--bad); color: var(--bad); }
.toast-wait { border-left-color: var(--accent); color: var(--muted); }
.toast-info { border-left-color: var(--border-strong); }

footer { text-align: center; color: var(--muted); padding: 1.8rem; font-size: 0.82rem; }

@media print {
  .sidebar, footer, .toolbar, .page-actions, .no-print, .toast-host { display: none !important; }
  .main { display: block; }
  .card { border: none; box-shadow: none; }
  body { background: white; }
}

/* ---------- Kanban-Karten am Board: anklickbar, Zustand auf einen Blick ---------- */

.kbb-row {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.7rem 0; border-bottom: 1px solid var(--border);
}
.kbb-row:last-child { border-bottom: none; }
.kbb-info { flex: 1 1 18rem; min-width: 0; line-height: 1.35; }
.kbb-info span { display: block; font-size: 0.82rem; }
.kbb-cards { display: flex; gap: 0.45rem; flex-wrap: wrap; }
.kbb-cards form { margin: 0; }
.kbb-count { font-size: 0.82rem; color: var(--muted); white-space: nowrap; min-width: 5.5rem; text-align: right; }
.kbb-count.warn { color: var(--bad); font-weight: 600; }

/* Die Kachel ist der Knopf - Farbe traegt die Aussage, die Schrift bestaetigt sie
   (Farbe allein reicht bei Rot/Gruen nicht fuer alle Augen). */
.kbb-chip {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 3.4rem; min-height: 3.4rem; gap: 0.1rem;
  border: 2px solid transparent; border-radius: var(--radius-sm);
  font-family: inherit; font-weight: 700; cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.kbb-chip:hover { box-shadow: var(--shadow-lift); }
.kbb-chip:active { transform: translateY(1px); }
.kbb-chip:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.kbb-chip-no { font-size: 1.05rem; line-height: 1; }
.kbb-chip-state { font-size: 0.58rem; letter-spacing: 0.08em; }

.kbb-chip.voll { background: #e4f3ea; border-color: var(--good); color: var(--good); }
.kbb-chip.voll:hover { background: #d5ecdf; }
.kbb-chip.leer { background: #fbe6e2; border-color: var(--bad); color: var(--bad); }
.kbb-chip.leer:hover { background: #f7d8d2; }

@media (prefers-reduced-motion: reduce) {
  .kbb-chip { transition: none; }
}

/* ---------- Motive & Vorlagen: Galerie statt Dateinamenliste ---------- */

.vorlagen-galerie {
  display: grid; gap: 0.9rem; margin-top: 0.9rem;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.vorlage {
  margin: 0; border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden; background: var(--card); display: flex; flex-direction: column;
}
.vorlage > a {
  display: flex; align-items: center; justify-content: center;
  aspect-ratio: 1 / 1; background: #f4f4f7; overflow: hidden;
}
.vorlage img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vorlage-symbol { font-size: 2.6rem; opacity: 0.5; }
.vorlage figcaption {
  padding: 0.5rem 0.6rem 0.6rem; font-size: 0.84rem; line-height: 1.35;
  display: flex; flex-direction: column; gap: 0.15rem;
}
.vorlage figcaption strong { word-break: break-word; }
.vorlage figcaption .muted { font-size: 0.76rem; }
.vorlage-aktionen { display: flex; gap: 0.35rem; margin-top: 0.35rem; flex-wrap: wrap; }
.vorlage-aktionen form { margin: 0; }
