/* ============================================================
   Sammlung – Oberfläche
   Mobil zuerst. Dunkel/hell folgt der Systemeinstellung.
   ============================================================ */

:root {
  --bg:        #f6f6f8;
  --surface:   #ffffff;
  --surface-2: #eeeef2;
  --line:      #dcdce4;
  --text:      #1b1d24;
  --text-dim:  #6b6f7d;
  --accent:    #4b5fd6;
  --accent-dim:#e6e9fb;
  --ok:        #2e9e63;
  --warn:      #d08a1c;
  --danger:    #cc3b3b;
  --star:      #d9a218;
  --radius:    14px;
  /* Sicherheitsabstände für Geräte mit Kerbe/abgerundeten Ecken.
     Greifen nur, wenn die App vom Home-Bildschirm gestartet wird –
     im Browser sind sie 0. */
  --safe-t:    env(safe-area-inset-top, 0px);
  --safe-b:    env(safe-area-inset-bottom, 0px);
  --topbar-h:  61px;   /* Höhe der Kopfleiste ohne Sicherheitsabstand */
  /* Höhe der eingeblendeten Bildschirmtastatur. Setzt app.js aus
     visualViewport; ohne Tastatur oder auf älteren Geräten bleibt es 0. */
  --tastatur:  0px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #14161c;
    --surface:   #1e2129;
    --surface-2: #272b35;
    --line:      #333846;
    --text:      #e8eaf0;
    --text-dim:  #9aa0b0;
    --accent:    #7b8cf0;
    --accent-dim:#2a3054;
    --ok:        #4cc189;
    --warn:      #e0a63f;
    --danger:    #e56767;
    --star:      #e8b93c;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }
.muted  { color: var(--text-dim); }
.small  { font-size: 13px; }
.error  { color: var(--danger); min-height: 1.2em; font-size: 14px; }

/* ---------- Anmeldung ---------- */
.login {
  position: fixed; inset: 0; display: grid; place-items: center;
  padding: 24px; background: var(--bg); z-index: 50;
}
.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-logo {
  font-size: 40px; width: 76px; height: 76px; margin: 0 auto 14px;
  display: grid; place-items: center; border-radius: 20px;
  background: var(--accent); color: #fff;
}
.login h1 { margin: 0 0 4px; font-size: 26px; }
.login p  { margin: 0 0 26px; }
.login label { display: block; text-align: left; margin-bottom: 14px; font-size: 14px; color: var(--text-dim); }
.login input {
  width: 100%; margin-top: 5px; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
}

/* ---------- Kopfleiste ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; gap: 8px; align-items: center;
  /* Oben Platz für die Kerbe, unten normal.
     (Vorher stand der obere Abstand versehentlich im unteren.) */
  padding: calc(10px + var(--safe-t)) 12px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.search-wrap { position: relative; flex: 1; display: flex; align-items: center; }
.search-icon {
  position: absolute; left: 11px; width: 17px; height: 17px;
  fill: var(--text-dim); pointer-events: none;
}
#search {
  width: 100%; padding: 11px 36px 11px 34px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--surface); color: var(--text);
}
#clearSearch { position: absolute; right: 4px; }

.icon-btn {
  background: none; border: 0; color: var(--text-dim);
  font-size: 17px; padding: 8px 10px; cursor: pointer; border-radius: 9px;
}
#syncBtn { position: relative; width: 40px; height: 40px; }
.dot {
  display: block; width: 11px; height: 11px; border-radius: 50%;
  background: var(--ok); margin: 0 auto;
  transition: background .2s;
}
.dot.pending { background: var(--warn); }
.dot.offline { background: var(--text-dim); }
.dot.syncing { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- Filter ---------- */
.filters {
  display: flex; gap: 7px; overflow-x: auto; padding: 10px 12px;
  scrollbar-width: none; background: var(--bg);
  /* Muss unter der Kopfleiste kleben – die ist auf Geräten mit
     Kerbe höher, deshalb den Sicherheitsabstand mitrechnen. */
  position: sticky; top: calc(var(--topbar-h) + var(--safe-t)); z-index: 19;
  border-bottom: 1px solid var(--line);
}
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 6px 13px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--text-dim); font-size: 13.5px; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Liste ---------- */
main { padding-bottom: calc(84px + var(--safe-b)); }
.list-meta { padding: 12px 16px 6px; font-size: 13px; color: var(--text-dim); }
.list { padding: 0 12px; }

.row-item {
  display: flex; gap: 12px; align-items: center;
  padding: 9px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); cursor: pointer;
}
.row-item:active { background: var(--surface-2); }
.cover {
  width: 46px; height: 66px; flex: 0 0 46px; border-radius: 7px;
  object-fit: cover; background: var(--surface-2);
  display: grid; place-items: center; font-size: 20px; color: var(--text-dim);
}
.row-main { min-width: 0; flex: 1; }
.row-title {
  font-weight: 600; font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-sub {
  font-size: 13px; color: var(--text-dim); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-tags { display: flex; gap: 5px; margin-top: 5px; flex-wrap: wrap; }
.tag {
  font-size: 11px; padding: 2px 7px; border-radius: 5px;
  background: var(--surface-2); color: var(--text-dim);
}
.tag.wish   { background: var(--accent-dim); color: var(--accent); }
.tag.lent   { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }
.tag.prio1  { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }

.empty { padding: 60px 30px; text-align: center; color: var(--text-dim); }
.empty-big { font-size: 42px; margin-bottom: 10px; opacity: .5; }

/* ---------- Karten ---------- */
/* --- Hinweisstreifen, z. B. „Zum Home-Bildschirm" --- */
.notice {
  display: flex; align-items: flex-start; gap: 10px;
  margin: 12px 12px 0; padding: 12px 12px 12px 14px;
  background: var(--accent-dim); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--accent) 32%, transparent);
  border-radius: var(--radius);
  font-size: 13.5px; line-height: 1.45;
}
.notice-text { flex: 1; min-width: 0; }
.notice-text b { display: block; margin-bottom: 3px; }
.notice .icon-btn { flex: none; margin: -3px -4px 0 0; }

/* --- Zeilen mit Beschriftung links, Wert rechts (Karte „Speicher") --- */
.kv-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 8px 0; font-size: 14px;
  border-bottom: 1px solid var(--line);
}
.kv-row:last-of-type { border-bottom: 0; }
.badge {
  flex: none; padding: 3px 9px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600;
}
.badge.ok   { background: color-mix(in srgb, var(--ok) 20%, transparent);   color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }

.card {
  margin: 12px; padding: 16px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.card h3 { margin: 0 0 8px; font-size: 15px; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 4px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 12px; }
.stat-num { font-size: 22px; font-weight: 650; }
.stat-lab { font-size: 12px; color: var(--text-dim); }
.bar-row { display: flex; align-items: center; gap: 8px; margin-top: 7px; font-size: 13px; }
.bar-lab { width: 78px; flex: 0 0 78px; color: var(--text-dim); }
.bar { flex: 1; height: 7px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar-num { width: 34px; text-align: right; color: var(--text-dim); }

/* ---------- Knöpfe ---------- */
.btn {
  padding: 11px 16px; font-size: 15px; font-family: inherit;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); color: var(--text); cursor: pointer;
}
.btn:active { opacity: .75; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.wide    { width: 100%; margin-top: 8px; }
.btn.danger-outline { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost   { background: transparent; }
.btn.sm      { padding: 7px 12px; font-size: 13.5px; }

.fab {
  position: fixed; right: 16px; bottom: calc(74px + var(--safe-b));
  width: 54px; height: 54px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 5px 18px rgba(0,0,0,.28); cursor: pointer; z-index: 21;
}

/* ---------- Tableiste ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tab {
  background: none; border: 0; padding: 8px 2px 7px; cursor: pointer;
  color: var(--text-dim); font-size: 11px; font-family: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tab.active { color: var(--accent); }
.tab-icon { font-size: 19px; line-height: 1; }

/* ---------- Scanner ---------- */
.scan-stage {
  position: relative; background: #000; aspect-ratio: 4/3;
  display: grid; place-items: center; overflow: hidden;
}
#video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: absolute; width: 74%; height: 32%;
  border: 2px solid rgba(255,255,255,.85); border-radius: 12px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.35);
}
.scan-hint {
  position: absolute; bottom: 12px; left: 0; right: 0; text-align: center;
  color: #fff; font-size: 13px; text-shadow: 0 1px 4px #000; padding: 0 20px;
}
.scan-controls { padding: 14px 16px; }
.or { text-align: center; color: var(--text-dim); font-size: 12.5px; margin: 14px 0 8px; }
.row { display: flex; gap: 8px; }
.row input {
  flex: 1; padding: 11px 13px; font-size: 16px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface); color: var(--text);
}
.scan-result { padding: 0 12px; }

.verdict {
  padding: 16px; border-radius: var(--radius); margin-bottom: 12px;
  border: 1px solid var(--line); background: var(--surface);
}
.verdict.have { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, var(--surface)); }
.verdict.want { border-color: var(--accent); background: var(--accent-dim); }
.verdict-head { font-size: 17px; font-weight: 650; margin-bottom: 4px; }

/* ---------- Formularblatt ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet-body {
  /* Um die Tastaturhöhe angehoben: iOS legt die Tastatur über die Seite,
     ohne das Fenster zu verkleinern – die unteren Felder lägen sonst
     darunter und wären beim Tippen nicht zu sehen. */
  position: absolute; left: 0; right: 0; bottom: var(--tastatur);
  max-height: calc(92vh - var(--tastatur)); overflow-y: auto;
  /* Am Ende der Liste nicht die Seite dahinter mitziehen – sonst
     wackelt beim Zuziehen der ganze Hintergrund mit. */
  overscroll-behavior: contain;
  background: var(--bg); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(26px + var(--safe-b));
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: .4; } }
.sheet-handle {
  width: 38px; height: 4px; border-radius: 3px; background: var(--line);
  margin: 4px auto 14px;
  /* Der Strich ist der sichtbare Hinweis auf die Ziehgeste. Der Griff
     selbst reagiert auf der ganzen Blattbreite, nicht nur hier. */
}
.sheet h2 { margin: 0 0 4px; font-size: 19px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; font-size: 16px; font-family: inherit;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
}
.field textarea { min-height: 74px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 .field { margin-bottom: 0; }

.detail-head { display: flex; gap: 14px; margin-bottom: 16px; }
.detail-cover {
  width: 92px; height: 132px; flex: 0 0 92px; border-radius: 10px;
  object-fit: cover; background: var(--surface-2);
  display: grid; place-items: center; font-size: 32px; color: var(--text-dim);
}
.detail-facts { margin: 14px 0; }
.fact { display: flex; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.fact-k { width: 118px; flex: 0 0 118px; color: var(--text-dim); }
.fact-v { flex: 1; }
.sheet-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.sheet-actions .btn { flex: 1; min-width: 120px; }

.cand {
  display: flex; gap: 11px; align-items: center; padding: 9px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--surface); margin-bottom: 8px; cursor: pointer;
}
.cand:active { background: var(--surface-2); }
.cand img, .cand .cover { width: 40px; height: 58px; flex: 0 0 40px; }

.stars { display: flex; gap: 3px; font-size: 19px; color: var(--line); }
.stars .on { color: var(--star); }

/* ---------- Hinweis ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + var(--safe-b));
  transform: translate(-50%, 14px);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 22px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .22s; z-index: 60;
  max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) {
  .list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 8px; }
  .row-item { margin-bottom: 0; }
  main { max-width: 1080px; margin: 0 auto; }
  .sheet-body { max-width: 620px; margin: 0 auto; border-radius: 18px; bottom: 4vh; max-height: 88vh; }
}
