:root {
  color-scheme: light;
  --bg: #f4f2ec;
  --surface: #fffefa;
  --surface-2: #ebe8df;
  --line: #d9d5c9;
  --ink: #1d1f26;
  --ink-2: #565a66;
  --ink-3: #6f7380;
  --accent: #9a6400;
  --accent-ink: #ffffff;
  --accent-soft: #f7e7bd;
  --loan: #b93a22;
  --loan-soft: #fbe3dc;
  --ok: #2c7a4b;
  --shadow: 0 10px 40px rgb(30 30 40 / .18);
  --radius: 8px;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  --sans: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #14161c; --surface: #1c1f27; --surface-2: #272b35; --line: #333845;
    --ink: #eeece6; --ink-2: #b4b6bf; --ink-3: #9396a3;
    --accent: #f2b705; --accent-ink: #1d1a0d; --accent-soft: #3d3313;
    --loan: #ff8a70; --loan-soft: #46241d; --ok: #6fd09a;
    --shadow: 0 10px 40px rgb(0 0 0 / .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14161c; --surface: #1c1f27; --surface-2: #272b35; --line: #333845;
  --ink: #eeece6; --ink-2: #b4b6bf; --ink-3: #9396a3;
  --accent: #f2b705; --accent-ink: #1d1a0d; --accent-soft: #3d3313;
  --loan: #ff8a70; --loan-soft: #46241d; --ok: #6fd09a;
  --shadow: 0 10px 40px rgb(0 0 0 / .5);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 var(--sans); overflow-x: hidden;
}
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 13px; }
p { margin: 0; }
a { color: inherit; }
img { display: block; max-width: 100%; }
.sprite { position: absolute; }
.icon {
  width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 12px; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* Bedienelemente */
button, input, select, textarea { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 38px; padding: 0 13px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; text-decoration: none; white-space: nowrap;
  font-size: 14px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--loan); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.icon-only { width: 38px; padding: 0; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn.is-on { background: var(--accent-soft); border-color: var(--accent); }

input[type="text"], input[type="search"], input[type="number"], input[type="date"],
input[type="password"], input:not([type]), select, textarea {
  width: 100%; min-height: 38px; padding: 7px 10px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface);
}
textarea { resize: vertical; min-height: 84px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
label.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
label.field > span { font-size: 12.5px; color: var(--ink-2); }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field-grid .wide { grid-column: 1 / -1; }

/* Rahmen */
.shell { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px;
  height: 56px; padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; }
.brand img { width: 26px; height: 26px; }
.nav { display: flex; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 7px; padding: 7px 11px; border-radius: var(--radius);
  text-decoration: none; color: var(--ink-2); font-size: 14px;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.nav .count {
  min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--loan-soft); color: var(--loan);
  font: 600 11px/18px var(--sans); text-align: center;
}
.content { flex: 1; width: 100%; max-width: 1560px; margin: 0 auto; padding: 22px 20px 40px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }

/* Sammlung */
.collection { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 24px; align-items: start; }
.filters {
  position: sticky; top: 76px; max-height: calc(100dvh - 92px); overflow-y: auto;
  padding-right: 6px; scrollbar-width: thin;
}
.filters-head { display: flex; align-items: center; justify-content: space-between; min-height: 32px; margin-bottom: 4px; }
.filter-group { border-top: 1px solid var(--line); padding: 8px 0; }
.filter-group summary { cursor: pointer; font-weight: 600; font-size: 13.5px; padding: 3px 0; list-style-position: outside; }
.filter-group .opts { display: flex; flex-direction: column; gap: 1px; margin-top: 5px; max-height: 240px; overflow-y: auto; }
.opt { display: flex; align-items: center; gap: 8px; padding: 3px 2px; font-size: 14px; cursor: pointer; border-radius: 5px; }
.opt:hover { background: var(--surface-2); }
.opt .n { margin-left: auto; color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.year-range { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.search { position: relative; flex: 1 1 260px; min-width: 0; }
.search .icon { position: absolute; left: 11px; top: 10px; color: var(--ink-3); }
.search input { padding-left: 36px; }
.sort-select { width: auto; flex: 0 1 190px; }
.segmented { display: flex; }
.segmented .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.segmented .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; margin-left: -1px; }
.filter-toggle { display: none; }

.result-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 34px; margin-bottom: 12px; font-size: 14px; }
.result-line strong { font-variant-numeric: tabular-nums; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 5px 2px 9px; border-radius: 13px;
  background: var(--accent-soft); border: 0; cursor: pointer; font-size: 13px; color: var(--ink);
}
.chip .icon { width: 13px; height: 13px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 20px 16px; }
.tile { display: block; padding: 0; border: 0; background: none; text-align: left; cursor: pointer; min-width: 0; }
.tile:hover .cover { transform: translateY(-3px); box-shadow: 0 8px 18px rgb(0 0 0 / .28); }
.cover {
  position: relative; aspect-ratio: 5 / 7; border-radius: 6px; overflow: hidden; background: var(--surface-2);
  box-shadow: 0 1px 3px rgb(0 0 0 / .25); transition: transform .14s ease, box-shadow .14s ease;
}
.cover img { width: 100%; height: 100%; object-fit: contain; }
.placeholder {
  height: 100%; display: flex; flex-direction: column; justify-content: space-between; gap: 8px;
  padding: 12px 11px; color: #fff; background: hsl(var(--hue) 38% 27%);
  border-left: 9px solid hsl(var(--hue) 45% 18%);
}
.placeholder b { font-size: 15px; line-height: 1.2; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.placeholder span { font-family: var(--mono); font-size: 10.5px; opacity: .8; text-transform: uppercase; letter-spacing: .05em; }
.fav-mark { position: absolute; top: 7px; right: 7px; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: rgb(0 0 0 / .6); color: #ffcf33; }
.fav-mark .icon { width: 14px; height: 14px; fill: currentColor; }
.ribbon {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 8px; background: rgb(150 35 15 / .94); color: #fff;
  font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile-title { margin-top: 8px; font-weight: 600; font-size: 14px; line-height: 1.25; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile-sub { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); background: var(--surface-2); white-space: nowrap; }
th, td { padding: 8px 12px; border-bottom: 1px solid var(--line); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mini-cover { width: 34px; height: 46px; border-radius: 3px; overflow: hidden; background: var(--surface-2); flex: none; }
.mini-cover img { width: 100%; height: 100%; object-fit: contain; }
.mini-cover .placeholder { padding: 0; border-left-width: 4px; }
.mini-cover .placeholder > * { display: none; }
.mini-cover.landscape { width: 52px; height: 34px; display: grid; place-items: center; color: var(--ink-3); }
.mini-cover.landscape img { object-fit: cover; }
.mini-cover.landscape .icon { width: 20px; height: 20px; }

.empty { padding: 56px 20px; text-align: center; color: var(--ink-2); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty h2 { margin-bottom: 6px; color: var(--ink); }
.empty .btn { margin-top: 14px; }
.sentinel { height: 1px; }

/* Dialoge */
dialog {
  color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 0; box-shadow: var(--shadow); max-width: min(760px, calc(100vw - 32px)); width: 100%;
  max-height: calc(100dvh - 40px);
}
dialog::backdrop { background: rgb(10 11 15 / .55); }
dialog.side {
  margin: 0 0 0 auto; height: 100dvh; max-height: 100dvh; max-width: min(620px, 100vw); border-radius: 0;
  border-width: 0 0 0 1px;
}
dialog.small { max-width: min(420px, calc(100vw - 32px)); }
dialog[open] { display: flex; flex-direction: column; overflow: hidden; }
.dlg { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 13px 18px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { flex: 1; min-width: 0; }
.dlg-body { flex: 1; overflow-y: auto; padding: 18px; min-height: 0; }
.dlg-foot { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 18px; border-top: 1px solid var(--line); }
.form-layout { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 20px; }
.form-section + .form-section { margin-top: 20px; }
.form-section h3 { margin-bottom: 10px; color: var(--ink-2); font-family: var(--mono); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; }
.dropzone {
  display: block; position: relative; aspect-ratio: 5 / 7; border: 1.5px dashed var(--line); border-radius: 8px;
  overflow: hidden; cursor: pointer; background: var(--surface-2);
}
.dropzone.landscape { aspect-ratio: 4 / 3; }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone img { width: 100%; height: 100%; object-fit: contain; }
.dropzone .hint { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 7px; align-items: center; justify-content: center; padding: 10px; text-align: center; font-size: 13px; color: var(--ink-2); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.stars { display: flex; gap: 1px; }
.stars button { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; border: 0; background: none; cursor: pointer; color: var(--ink-3); }
.stars button.on { color: var(--accent); }
.stars button.on .icon { fill: currentColor; }
.stars .icon { width: 22px; height: 22px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 38px; cursor: pointer; }

.detail-top { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 18px; margin-bottom: 18px; }
.detail-top h2 { font-size: 22px; margin-bottom: 4px; overflow-wrap: anywhere; }
.badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.badge { padding: 1px 8px; border-radius: 4px; background: var(--surface-2); font-size: 12.5px; }
.badge.lent { background: var(--loan-soft); color: var(--loan); font-weight: 600; }
.badge.ok { color: var(--ok); }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; margin: 0; }
.facts dt { font-size: 12px; color: var(--ink-3); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts .wide { grid-column: 1 / -1; white-space: pre-wrap; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-top: 16px; }
.panel h3 { font-size: 14px; margin-bottom: 10px; }
.panel.lent { border-color: var(--loan); background: var(--loan-soft); }
.loan-now { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.loan-now .who { flex: 1 1 200px; }
.loan-now strong { font-size: 16px; }
.history { list-style: none; margin: 12px 0 0; padding: 0; font-size: 13.500px; }
.history li { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-top: 1px solid var(--line); }
.history .btn { min-height: 28px; width: 28px; }
.pick-list { list-style: none; margin: 8px 0 0; padding: 0; font-size: 13.5px; }
.pick-list li { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); }
.pick-list .spacer { min-width: 0; overflow-wrap: anywhere; }
.pick-list .btn { flex: none; }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(340px, 100%); display: flex; flex-direction: column; gap: 12px; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.login .brand { font-size: 20px; margin-bottom: 6px; }
.error-text { color: var(--loan); font-size: 14px; }

/* Konsolen und Verleih */
.console-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; margin-bottom: 32px; }
.console-card {
  display: flex; flex-direction: column; padding: 0; overflow: hidden; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.console-card:hover { border-color: var(--accent); }
.console-card .pic { aspect-ratio: 16 / 10; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; color: var(--ink-3); }
.console-card .pic img { width: 100%; height: 100%; object-fit: cover; }
.console-card .pic .icon { width: 44px; height: 44px; stroke-width: 1.2; }
.console-card .info { padding: 10px 12px; }
.console-card strong { display: block; overflow-wrap: anywhere; }
.section-title { display: flex; align-items: center; gap: 10px; margin: 8px 0 12px; }
.row-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row-title b { display: block; font-weight: 600; }
.overdue { color: var(--loan); font-weight: 600; }

/* Statistik */
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 22px; }
.stat { padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.stat b { display: block; font-size: 25px; line-height: 1.2; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat span { color: var(--ink-2); font-size: 13px; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); gap: 16px; align-items: start; }
.chart { padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.chart h2 { font-size: 15px; margin-bottom: 12px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 38%) minmax(0, 1fr) 34px; gap: 10px; align-items: center; padding: 3px 0; font-size: 13.5px; }
.bar-row.money { grid-template-columns: minmax(70px, 30%) minmax(0, 1fr) 104px; }
.bar-row .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .track { height: 12px; }
.bar-row .fill { height: 100%; min-width: 3px; background: var(--accent); border-radius: 0 4px 4px 0; }
.bar-row .value { text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* Daten */
.data-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.card { padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card h2 { margin-bottom: 6px; }
.card > p { color: var(--ink-2); margin-bottom: 12px; font-size: 14px; }
.card .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.card.wide { grid-column: 1 / -1; }
.file-drop { display: block; padding: 28px 16px; text-align: center; border: 1.5px dashed var(--line); border-radius: var(--radius); cursor: pointer; color: var(--ink-2); }
.file-drop.drag { border-color: var(--accent); background: var(--accent-soft); }
.file-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.radio-row { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; font-size: 14px; }
.radio-row label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.import-summary { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 10px; }
.import-table { max-height: 380px; overflow: auto; }
.action-create { color: var(--ok); font-weight: 600; }
.action-update { color: var(--accent); font-weight: 600; }
.action-error { color: var(--loan); font-weight: 600; }

#toasts { position: fixed; z-index: 100; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast { padding: 10px 14px; border-radius: var(--radius); background: var(--ink); color: var(--bg); box-shadow: var(--shadow); font-size: 14px; }
.toast.error { background: var(--loan); color: #fff; }

@media (max-width: 900px) {
  body { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
  .topbar { padding: 0 16px; height: 50px; }
  .topbar .nav {
    position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; justify-content: space-around; gap: 0;
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line);
  }
  .nav a { position: relative; flex-direction: column; gap: 1px; padding: 4px 8px; font-size: 11px; flex: 1; }
  .nav .count { position: absolute; top: 0; left: 55%; }
  .content { padding: 16px 16px 28px; }
  .collection { grid-template-columns: minmax(0, 1fr); }
  .filter-toggle { display: inline-flex; }
  .filters {
    display: none; position: fixed; z-index: 30; inset: 0; top: 0; max-height: none; padding: 16px;
    background: var(--bg);
  }
  .filters.open { display: block; padding-bottom: 90px; }
  .filter-group .opts { max-height: none; }
  .sort-select { flex: 1 1 130px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 16px 12px; }
  dialog, dialog.side { max-width: 100vw; width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; border: 0; }
  dialog.small { height: auto; max-height: calc(100dvh - 32px); margin: auto; width: calc(100vw - 32px); border-radius: 12px; }
  .form-layout, .detail-top { grid-template-columns: minmax(0, 1fr); }
  .form-layout .dropzone, .detail-top .cover { width: 150px; }
  #toasts { bottom: 76px; }
}
@media (max-width: 420px) {
  .field-grid { gap: 10px; }
  .hide-narrow { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
