:root {
  --bg: #f6f4f0;
  --card: #ffffff;
  --text: #1d1b19;
  --muted: #6f6a63;
  --line: #e6e1d9;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe9;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --ok: #2f6f5e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 24px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514;
    --card: #211f1d;
    --text: #f1eee9;
    --muted: #a39d94;
    --line: #36322e;
    --accent: #6fbfa6;
    --accent-ink: #0f1f1a;
    --accent-soft: #23362f;
    --danger: #ff8a80;
    --danger-soft: #3a2422;
    --ok: #6fbfa6;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.wrap {
  max-width: 640px; margin: 0 auto;
  padding: calc(32px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px))
           calc(64px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
button, .btn, label, a { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.wrap.wide { max-width: 1200px; }
h1 { font-size: 1.9rem; line-height: 1.2; margin: 0 0 6px; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-top: 20px;
}

label.field { display: block; font-weight: 600; margin-bottom: 6px; }
input[type=text], input[type=password] {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
input:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.big { width: 100%; padding: 16px; font-size: 1.1rem; }

/* Upload */
.drop {
  margin-top: 20px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--card);
  padding: 36px 20px;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .icon { width: 56px; height: 56px; margin: 0 auto 12px; color: var(--accent); }
.drop p { margin-top: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.summary { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 24px; flex-wrap: wrap; }
.queue { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.queue li {
  display: grid; grid-template-columns: 52px 1fr auto; gap: 12px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px 8px 8px;
}
.queue .pv { width: 52px; height: 52px; border-radius: 8px; background: var(--bg) center/cover no-repeat; }
.queue .name { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue .msg { font-size: .8rem; color: var(--muted); }
.queue .bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.queue .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.queue .state { font-size: 1.2rem; width: 24px; text-align: center; }
.queue li.done .msg { color: var(--ok); }
.queue li.error .msg { color: var(--danger); }
.queue li.error .bar i { background: var(--danger); }
.thanks { text-align: center; padding: 24px; }
.thanks strong { display: block; font-size: 1.3rem; margin-bottom: 4px; }

/* Admin */
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.stats { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 8px; }
.stats b { display: block; font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.share { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: center; }
.share .qr { background: #fff; padding: 12px; border-radius: 10px; width: 184px; height: 184px; }
.share .qr img, .share .qr canvas { display: block; width: 160px !important; height: 160px !important; }
.linkrow { display: flex; gap: 8px; margin: 8px 0 12px; }
.linkrow input { flex: 1; min-width: 0; font-family: ui-monospace, Consolas, monospace; font-size: .9rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 560px) { .share { grid-template-columns: 1fr; justify-items: center; text-align: center; } .actions { justify-content: center; } }

.toolbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--bg); padding: 12px 0; margin-top: 20px; border-bottom: 1px solid var(--line);
}
.toolbar .count { margin-right: auto; font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-top: 16px; }
.tile {
  position: relative; background: var(--card); border: 2px solid var(--line); border-radius: 12px; overflow: hidden;
}
.tile.sel { border-color: var(--accent); }
.tile .img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--bg); cursor: zoom-in; border: 0; padding: 0; }
.tile .img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .pick { position: absolute; top: 0; left: 0; z-index: 2; width: 48px; height: 48px; display: grid; place-items: center; cursor: pointer; }
.tile .check { width: 24px; height: 24px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.tile .info { padding: 8px 10px; font-size: .8rem; }
.tile .info .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.tile .info .m { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .tools { display: flex; border-top: 1px solid var(--line); }
.tile .tools a, .tile .tools button {
  flex: 1; text-align: center; padding: 8px; font: inherit; font-size: .85rem; background: none; border: 0; color: var(--text); cursor: pointer; text-decoration: none;
}
.tile .tools button { color: var(--danger); border-left: 1px solid var(--line); }
.tile .tools a:hover { background: var(--accent-soft); }
.tile .tools button:hover { background: var(--danger-soft); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

.notice { padding: 12px 16px; border-radius: 10px; margin-top: 16px; background: var(--accent-soft); }
.notice.err { background: var(--danger-soft); color: var(--danger); }

.login { max-width: 380px; margin: 12vh auto 0; }
.login form { display: grid; gap: 12px; }

/* Lightbox */
.lb {
  position: fixed; inset: 0; height: 100vh; height: 100dvh; background: rgba(10,10,10,.94); z-index: 50;
  display: grid; grid-template-rows: auto 1fr;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
.lb[hidden] { display: none; }
.lb header { display: flex; gap: 8px; align-items: center; padding: 12px 16px; color: #fff; flex-wrap: wrap; }
.lb .stage { touch-action: pan-y pinch-zoom; }
.lb header .title { margin-right: auto; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }
.lb .stage { position: relative; display: flex; align-items: center; justify-content: center; min-height: 0; padding: 0 56px 16px; }
.lb .stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lb .nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.12); color: #fff; border: 0; width: 44px; height: 64px; border-radius: 10px; font-size: 1.6rem; cursor: pointer; }
.lb .nav.prev { left: 6px; } .lb .nav.next { right: 6px; }
.lb .btn { background: rgba(255,255,255,.1); color: #fff; border-color: transparent; }
.lb .btn.danger { color: #ff9b93; }

/* Kurz- und Langtexte für Buttons */
.sm { display: none; }

/* Handy */
.cam { display: none; margin-top: 10px; }
@media (pointer: coarse) { .cam { display: flex; } }

@media (max-width: 640px) {
  h1 { font-size: 1.6rem; }
  .wrap { padding-top: calc(20px + env(safe-area-inset-top, 0px)); }
  .card { padding: 16px; }
  .drop { padding: 24px 16px; }
  .queue li { grid-template-columns: 44px 1fr auto; }
  .queue .pv { width: 44px; height: 44px; }

  .lg { display: none; }
  .sm { display: inline; }

  /* Verwaltung: Werkzeugleiste unten am Bildschirmrand */
  .wrap.wide { padding-bottom: calc(150px + env(safe-area-inset-bottom, 0px)); }
  .stats { gap: 16px; }
  .stats b { font-size: 1.2rem; }
  .actions .btn { flex: 1 1 auto; }
  .toolbar {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; z-index: 20; margin: 0;
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
    padding: 10px max(12px, env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
    background: var(--card); border-top: 1px solid var(--line); border-bottom: 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,.08);
  }
  .toolbar .count { grid-column: 1 / 3; align-self: center; margin: 0; }
  .toolbar .btn { padding: 11px 6px; font-size: .9rem; white-space: normal; line-height: 1.2; }
  .toolbar #reload { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 12px; }
  .tile .info { padding: 6px 8px; }
  .tile .tools a, .tile .tools button { padding: 10px 4px; }

  .lb header { padding: 10px 12px; }
  .lb header .title { flex-basis: 100%; max-width: none; order: -1; margin: 0 0 2px; }
  .lb header .btn { flex: 1; }
  .lb .stage { padding: 0 0 12px; }
}
@media (pointer: coarse) { .lb .nav { display: none; } }

/* Druckansicht: nur die QR-Karte */
.print-card { display: none; }
@media print {
  body { background: #fff; color: #000; }
  .wrap > *:not(.print-card), .lb { display: none !important; }
  .print-card { display: block; text-align: center; padding-top: 10vh; }
  .print-card h1 { font-size: 2.6rem; }
  .print-card p { font-size: 1.3rem; }
  .print-card .pqr { display: inline-block; margin: 32px 0 20px; }
  .print-card .pqr img, .print-card .pqr canvas { width: 9cm !important; height: 9cm !important; }
  .print-card .url { font-family: ui-monospace, Consolas, monospace; font-size: 1rem; word-break: break-all; }
}
