:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1a1d24;
  --muted: #646b78;
  --line: #e2e5ea;
  --accent: #3556d8;
  --accent-hover: #2a46b3;
  --accent-ink: #ffffff;
  --focus: #3556d8;
  --ok-bg: #e3f5ea; --ok-ink: #14652f;
  --info-bg: #e2ecff; --info-ink: #1d44a8;
  --warn-bg: #fff1d6; --warn-ink: #8a5300;
  --bad-bg: #fde4e4; --bad-ink: #a11a1a;
  --mute-bg: #eceef2; --mute-ink: #555c68;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1217;
    --surface: #181c23;
    --text: #e8eaee;
    --muted: #9aa1ae;
    --line: #2a303a;
    --accent: #6f8bff;
    --accent-hover: #8aa0ff;
    --accent-ink: #0d1330;
    --focus: #8aa0ff;
    --ok-bg: #12301f; --ok-ink: #7fdba0;
    --info-bg: #15264d; --info-ink: #9dbaff;
    --warn-bg: #3a2a0c; --warn-ink: #f2c46d;
    --bad-bg: #3d1717; --bad-ink: #ff9f9f;
    --mute-bg: #232830; --mute-ink: #a6adb9;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; line-height: 1.2; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .8rem; margin: 1.25rem 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 .75rem; }
code { background: var(--mute-bg); padding: .1em .35em; border-radius: 4px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Kopfzeile */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1080px; margin: 0 auto; padding: .6rem 1rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); text-decoration: none; }
.nav { display: flex; gap: .25rem; flex: 1; }
.nav a { padding: .45rem .75rem; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a.active { background: var(--mute-bg); color: var(--text); }
.topbar-actions { display: flex; gap: .5rem; align-items: center; }
.topbar-actions form { margin: 0; }

.page { max-width: 1080px; margin: 0 auto; padding: 1rem 1rem 6rem; }
body.centered .page { min-height: 100vh; display: grid; place-items: center; padding-bottom: 1rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: 0 1rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--mute-bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.danger { color: var(--bad-ink); border-color: var(--bad-ink); background: transparent; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary:disabled:hover { background: var(--accent); border-color: var(--accent); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin: 0 0 1rem; }

/* Hinweise */
.flash { padding: .7rem 1rem; border-radius: 10px; margin-bottom: .75rem; font-weight: 500; }
.flash.ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash.warn { background: var(--warn-bg); color: var(--warn-ink); }
.flash.bad { background: var(--bad-bg); color: var(--bad-ink); }

/* Suche und Filter */
.search { display: flex; gap: .5rem; margin-bottom: .75rem; }
.search input[type="search"] { flex: 1; min-width: 0; }
.chips { display: flex; gap: .4rem; overflow-x: auto; padding: .15rem 0 .5rem; scrollbar-width: thin; }
.chip {
  flex: none; display: inline-flex; gap: .4rem; align-items: center; padding: .4rem .8rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); text-decoration: none; font-size: .92rem;
}
.chip span { color: var(--muted); font-size: .82rem; }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.active span { color: inherit; opacity: .85; }
.chips.small .chip { font-size: .85rem; padding: .3rem .65rem; }

.summary { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .92rem; margin: .5rem 0; }

/* Liste */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: grid; grid-template-columns: 6.5rem minmax(0, 2.2fr) minmax(0, 1.3fr) minmax(0, 1.1fr) minmax(0, 1.3fr);
  gap: .75rem; align-items: center; padding: .75rem 1rem; border-top: 1px solid var(--line); color: inherit; text-decoration: none;
}
.row:first-child { border-top: 0; }
a.row:hover { background: var(--mute-bg); }
.row.head { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; background: var(--bg); }
.row small { display: block; color: var(--muted); font-size: .84rem; }
.row strong { font-weight: 600; }
.c-tag { color: var(--muted); }
.c-main strong, .c-serial, .c-freq { overflow-wrap: anywhere; }
.c-status { display: flex; flex-direction: column; gap: .2rem; align-items: flex-start; }

.badge { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.badge.big { font-size: .95rem; padding: .3rem .85rem; }
.badge.ok { background: var(--ok-bg); color: var(--ok-ink); }
.badge.info { background: var(--info-bg); color: var(--info-ink); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge.bad { background: var(--bad-bg); color: var(--bad-ink); }
.badge.mute { background: var(--mute-bg); color: var(--mute-ink); }

.empty { text-align: center; padding: 3rem 1rem; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty h1 { margin-bottom: .5rem; }
.empty .actions { justify-content: center; margin-top: 1rem; }

/* Karten, Formulare */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); margin: 0 0 1rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin: .25rem 0 1rem; }
.page-head .tag { color: var(--muted); margin: 0 0 .15rem; }
.back { display: inline-block; margin-bottom: .5rem; text-decoration: none; color: var(--muted); }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; margin-bottom: 1rem; }
.detail-grid .card { margin: 0; }
.count { color: var(--muted); font-weight: 400; }

label { display: block; font-weight: 600; font-size: .9rem; }
input, select, textarea {
  display: block; width: 100%; min-height: 44px; margin-top: .3rem; padding: .55rem .75rem; font: inherit; font-weight: 400;
  color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}
input[type="radio"] { display: inline; width: auto; min-height: 0; margin: 0; }
input[type="file"] { padding: .5rem; }
textarea { resize: vertical; }
input:disabled, select:disabled { opacity: .6; }
.form fieldset { border: 1px solid var(--line); min-width: 0; }
.form legend { padding: 0 .4rem; font-weight: 700; }
.optional { color: var(--muted); font-weight: 400; font-size: .85rem; margin-left: .35rem; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; }
.stack { display: grid; gap: .9rem; }
.has-error input, .has-error select { border-color: var(--bad-ink); }
.error { display: block; color: var(--bad-ink); font-weight: 500; font-size: .85rem; margin-top: .25rem; }
.hint { display: block; color: var(--muted); font-weight: 400; font-size: .85rem; margin-top: .25rem; }

.savebar {
  position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: .5rem; padding: .75rem 0;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.facts { margin: 0; display: grid; gap: .6rem; }
.facts div { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--line); padding-bottom: .5rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.notes { white-space: pre-wrap; }

.seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr)); gap: .4rem; }
.seg label { margin: 0; position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 .5rem; text-align: center;
  border: 1px solid var(--line); border-radius: 10px; font-weight: 600; cursor: pointer;
}
.seg input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.list.compact { box-shadow: none; }

/* Dashboard: Hinweis, Kennzahlen, Gruppen */
.notice {
  padding: .7rem 1rem; border-radius: 10px; margin: 0 0 .75rem; background: var(--info-bg); color: var(--info-ink);
  display: flex; gap: .25rem .75rem; flex-wrap: wrap; align-items: baseline; justify-content: space-between;
}
.notice.warn { background: var(--warn-bg); color: var(--warn-ink); }
.notice a { color: inherit; font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: .6rem; margin-bottom: .75rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .9rem; box-shadow: var(--shadow); }
.stat strong { display: block; font-size: 1.25rem; line-height: 1.2; }
.stat span { color: var(--muted); font-size: .82rem; }
.stat.warn { border-color: var(--warn-ink); }
.stat.warn strong { color: var(--warn-ink); }
.chip.warn:not(.active) { background: var(--warn-bg); border-color: transparent; color: var(--warn-ink); }
.chip.warn:not(.active) span { color: inherit; }
.chips-label { flex: none; align-self: center; color: var(--muted); font-size: .82rem; padding-right: .2rem; }
.missing { color: var(--warn-ink); font-weight: 600; }
.list.headonly { border-bottom-left-radius: 0; border-bottom-right-radius: 0; margin-bottom: 0; border-bottom: 0; }
.list.no-status .row { grid-template-columns: 6.5rem minmax(0, 2.4fr) minmax(0, 1.5fr) minmax(0, 1.2fr); }
details.group { margin-top: 1rem; }
details.group > summary {
  list-style: none; cursor: pointer; display: flex; flex-wrap: wrap; gap: .4rem .75rem; align-items: center;
  padding: .4rem .25rem; font-weight: 700;
}
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::before { content: "▾"; color: var(--muted); width: 1rem; }
details.group:not([open]) > summary::before { content: "▸"; }
.group-title { font-size: 1.05rem; }
.group-value { margin-left: auto; color: var(--muted); font-weight: 400; font-size: .88rem; }

/* Marktpreis: klein und dezent */
.market { display: flex; flex-wrap: wrap; gap: .25rem .6rem; align-items: baseline; margin-top: 1rem; color: var(--muted); font-size: .82rem; }
.market form { margin: 0; }
.market a, .linklike { color: var(--muted); text-decoration: underline; font: inherit; }
.linklike { background: none; border: 0; padding: 0; cursor: pointer; }
.linklike:hover, .market a:hover { color: var(--text); }

/* Bilder */
.c-main { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.c-text { min-width: 0; }
.thumb {
  flex: none; width: 48px; height: 48px; object-fit: contain; background: #fff;
  border: 1px solid var(--line); border-radius: 8px;
}
.thumb.ph { background: var(--mute-bg); }
.stack-cards { display: grid; gap: 1rem; }
.image-card .hero {
  display: block; width: 100%; max-height: 320px; object-fit: contain; background: #fff;
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: .75rem;
}
.image-card .hero.ph { height: 160px; display: grid; place-items: center; background: var(--mute-bg); color: var(--muted); }
.image-card .actions form { margin: 0; }
.danger-zone { margin-top: 2rem; text-align: right; }

.login { width: min(22rem, 100%); display: grid; gap: 1rem; justify-items: center; text-align: center; }
.login label, .login .flash { width: 100%; text-align: left; }

/* Etiketten */
.labels { display: flex; flex-wrap: wrap; gap: 8px; }
.label {
  width: 60mm; height: 30mm; background: #fff; color: #000; border: 1px dashed #aaa; padding: 2mm;
  display: grid; grid-template-columns: 24mm 1fr; gap: 2mm; align-items: center; overflow: hidden; break-inside: avoid;
}
.label .qr { width: 24mm; height: 24mm; }
.label .qr svg { width: 100%; height: 100%; display: block; }
.label-text { display: grid; gap: .5mm; min-width: 0; font-size: 7pt; line-height: 1.15; }
.label-text strong { font-size: 10pt; }
.l-title { font-weight: 700; font-size: 8pt; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.l-line { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* Papierkorb */
.trash-row { grid-template-columns: 6.5rem minmax(0, 1fr) auto; }
.trash-actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
.trash-actions form { margin: 0; }

/* Bericht (Versicherung) */
.report { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; overflow-x: auto; }
.report-head h1 { font-size: 1.25rem; }
.report-head p { color: var(--muted); margin: .25rem 0 1rem; }
.report table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.report th, .report td { padding: .4rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.report th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.report .num { text-align: right; white-space: nowrap; }
.report .ref { color: var(--muted); font-size: .82rem; }
.report td:first-child { white-space: nowrap; }
.report tfoot td { font-weight: 700; border-top: 2px solid var(--text); border-bottom: 0; }
.report .missing { color: var(--warn-ink); font-weight: 600; }
.report-notes { color: var(--muted); font-size: .82rem; margin: 1rem 0 0; }

/* Etiketten und Bericht haben verschiedene Druckformate (benannte Seiten). */
@page label { size: 60mm 30mm; margin: 0; }
@page report { size: A4 landscape; margin: 12mm; }

@media print {
  body { background: #fff; color: #000; }
  .topbar, .no-print, .flash { display: none !important; }
  .page { padding: 0; max-width: none; }
  .labels { display: block; page: label; }
  .label { border: 0; margin: 0; page-break-after: always; }
  .report { page: report; border: 0; padding: 0; overflow: visible; background: #fff; }
  .report th, .report td { border-bottom: 1px solid #999; color: #000; }
  .report .ref, .report-notes, .report-head p { color: #444; }
  .report .missing { color: #000; font-weight: 700; }
  .report tr { page-break-inside: avoid; }
}

/* Mobil */
@media (max-width: 760px) {
  .nav { order: 3; flex-basis: 100%; }
  .topbar-inner { gap: .5rem; }
  .brand { flex: 1; }
  .detail-grid, .grid { grid-template-columns: 1fr; }
  .row.head { display: none; }
  .row {
    grid-template-columns: 1fr auto; grid-template-areas: "main status" "tag tag" "serial freq";
    gap: .25rem .75rem; padding: .8rem 1rem;
  }
  .c-main { grid-area: main; }
  .c-status { grid-area: status; align-items: flex-end; text-align: right; }
  .c-tag { grid-area: tag; font-size: .8rem; }
  .c-serial { grid-area: serial; font-size: .82rem; }
  .c-freq { grid-area: freq; font-size: .82rem; text-align: right; }
  .c-serial::before, .c-freq::before { content: attr(data-label) " "; color: var(--muted); }
  .page-head { flex-direction: column; }
  .search .btn { display: none; }
  .nav { flex-wrap: wrap; }
  .list.headonly { display: none; }
  .list.no-status .row { grid-template-columns: 1fr 1fr; grid-template-areas: "main main" "tag tag" "serial freq"; }
  .trash-row { grid-template-columns: 1fr; grid-template-areas: none; }
  .trash-row .c-tag, .trash-row .c-main, .trash-row .trash-actions { grid-area: auto; }
  .trash-actions { justify-content: flex-start; }
}
