:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #1b1f24;
  --muted: #5d6673;
  --border: #d9dee5;
  --accent: #1f3a5f;
  --accent-2: #2f5d93;
  --accent-text: #ffffff;
  --warn-bg: #fff4d6;
  --warn: #8a5a00;
  --ok: #1d7a46;
  --danger: #b3261e;
  --lock: #5b4bb7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --surface: #1a1f25; --surface-2: #232a32; --text: #e7eaee; --muted: #9aa4b1;
    --border: #2f3842; --accent: #7fb0ea; --accent-2: #9cc3f0; --accent-text: #0e1a2a;
    --warn-bg: #3a2f12; --warn: #f0c46b; --ok: #6fcf97; --danger: #ff8a80; --lock: #b3a8ff;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
}
a { color: var(--accent-2); }
h1 { font-size: 1.35rem; margin: .2rem 0 .8rem; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* Kopfzeile */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
  padding: .55rem 16px; padding-top: calc(.55rem + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); text-decoration: none; }
.topnav { display: flex; gap: .2rem; margin-left: auto; overflow-x: auto; }
.topnav a { padding: .4rem .7rem; border-radius: 8px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.topnav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
@media (max-width: 560px) { .topnav a[data-nav="new"] { display: none; } .brand span { display: none; } }

main { max-width: 1180px; margin: 0 auto; padding: 16px; outline: none; }

/* Bedienelemente */
button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: .5rem .9rem; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; gap: .4rem; min-height: 40px;
}
button:hover, .btn:hover { border-color: var(--accent-2); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--danger); }
button.link { border: none; background: none; padding: 0 .2rem; min-height: auto; color: var(--accent-2); }
button:disabled { opacity: .55; cursor: default; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: .5rem .6rem; width: 100%; min-height: 40px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
.check { display: flex; align-items: center; gap: .5rem; color: var(--text); font-size: 1rem; }
.check input { width: auto; min-height: auto; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 160px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .8rem 1rem; }
.grid-form .wide { grid-column: 1 / -1; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 1rem; }

/* Übersicht */
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .8rem; }
.toolbar .search { flex: 1 1 260px; }
.toolbar select { flex: 0 1 170px; width: auto; }
.stats { display: flex; gap: 1.2rem; flex-wrap: wrap; margin: .2rem 0 1rem; color: var(--muted); font-size: .9rem; }
.stats b { color: var(--text); font-size: 1.05rem; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button { border: none; border-radius: 0; min-height: 38px; }
.segmented button.on { background: var(--surface-2); font-weight: 600; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  color: inherit; text-decoration: none; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.tile:hover { border-color: var(--accent-2); }
.tile .img { aspect-ratio: 16/10; width: 100%; object-fit: contain; background: var(--surface-2); display: block; }
.tile .img.noimg { display: grid; place-items: center; color: var(--muted); font-size: .8rem; }
.tile .body { padding: .6rem .7rem .7rem; display: flex; flex-direction: column; gap: .15rem; }
.tile .no { font-size: .8rem; color: var(--muted); }
.tile .name { font-weight: 600; line-height: 1.25; }
.tags { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .3rem; }
.tag { font-size: .75rem; padding: .05rem .45rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.status-wunsch { background: #e6f0ff; color: #1f4f99; }
.tag.status-verkauft { background: #f2e6e6; color: #8a2c2c; }
@media (prefers-color-scheme: dark) {
  .tag.status-wunsch { background: #1d2b44; color: #9cc3f0; }
  .tag.status-verkauft { background: #3a2222; color: #f0a0a0; }
}

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.list { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.list th, table.list td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: var(--surface-2); }
table.list img { width: 64px; height: 40px; object-fit: contain; background: var(--surface-2); border-radius: 4px; display: block; }
table.list td.num { text-align: right; white-space: nowrap; }

.filters { display: contents; }
.only-mobile { display: none; }
@media (max-width: 640px) {
  .only-mobile { display: inline-flex; }
  .toolbar .search { flex: 1 1 60%; }
  .filters { display: none; }
  .filters.open { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; width: 100%; }
  .filters.open select { width: 100%; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile .name { font-size: .92rem; }
  .stats { gap: .3rem 1rem; }
}

/* Erfassen */
.scan-box { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; max-width: 560px; }
.scan-box video { width: 100%; display: block; max-height: 60vh; object-fit: cover; }
.scan-box .aim { position: absolute; left: 10%; right: 10%; top: 40%; height: 20%; border: 2px solid rgba(255,255,255,.85); border-radius: 8px; box-shadow: 0 0 0 999px rgba(0,0,0,.25); }
.candidates { display: grid; gap: 12px; }
.candidate { display: grid; grid-template-columns: 200px 1fr; gap: 16px; }
@media (max-width: 640px) { .candidate { grid-template-columns: 1fr; } }
.candidate img { width: 100%; aspect-ratio: 16/10; object-fit: contain; background: var(--surface-2); border-radius: 8px; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: 0; }
dl.facts dt { color: var(--muted); font-size: .88rem; }
dl.facts dd { margin: 0; }
.msg { padding: .6rem .8rem; border-radius: 8px; background: var(--surface-2); margin: .5rem 0; font-size: .92rem; }
.msg.warn { background: var(--warn-bg); color: var(--warn); }
.msg.err { background: #fde8e7; color: var(--danger); }
@media (prefers-color-scheme: dark) { .msg.err { background: #3b1e1c; } }
.steps { display: flex; gap: .4rem; margin-bottom: 1rem; font-size: .85rem; color: var(--muted); flex-wrap: wrap; }
.steps span.on { color: var(--text); font-weight: 600; }

/* Detail */
.detail-head { display: flex; gap: 1rem; align-items: start; flex-wrap: wrap; }
.detail-head .title { flex: 1 1 320px; }
.gallery { display: grid; grid-template-columns: 1fr; gap: 8px; }
.gallery .main { width: 100%; aspect-ratio: 16/10; object-fit: contain; background: var(--surface-2); border-radius: var(--radius); }
.thumbs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.thumbs button { padding: 0; border-radius: 6px; min-height: auto; position: relative; flex: 0 0 auto; }
.thumbs img { width: 84px; height: 54px; object-fit: contain; background: var(--surface-2); border-radius: 6px; display: block; }
.thumbs button.on { outline: 2px solid var(--accent-2); }
.two-col { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }
.field-row { display: grid; grid-template-columns: 170px 1fr; gap: .6rem; padding: .35rem 0; border-bottom: 1px dashed var(--border); align-items: center; }
.field-row:last-child { border-bottom: none; }
.field-row .k { color: var(--muted); font-size: .88rem; }
.field-row .v { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
@media (max-width: 480px) { .field-row { grid-template-columns: 1fr; gap: .1rem; } }
.badge { font-size: .7rem; padding: .05rem .4rem; border-radius: 99px; white-space: nowrap; }
.badge.lock { background: color-mix(in srgb, var(--lock) 15%, transparent); color: var(--lock); }
.badge.unconf { background: var(--warn-bg); color: var(--warn); }
.positions input, .positions select { min-height: 34px; padding: .3rem .4rem; }
.positions td { padding: .3rem .4rem; }
.photos { display: flex; gap: 8px; flex-wrap: wrap; }
.photos figure { margin: 0; position: relative; }
.photos img { width: 120px; height: 90px; object-fit: cover; border-radius: 6px; display: block; }
.photos .del { position: absolute; top: 4px; right: 4px; min-height: 26px; padding: 0 .45rem; font-size: .8rem; }

/* Sonstiges */
.fab { position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); width: 58px; height: 58px;
  border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: 32px; line-height: 56px;
  text-align: center; text-decoration: none; box-shadow: 0 4px 14px rgba(0,0,0,.25); z-index: 30; }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: .6rem 1rem; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: 90vw; }
#toast.show { opacity: .95; }
.login { max-width: 360px; margin: 10vh auto; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent-2); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent-2); transition: width .3s; }
