/* Kartenwert - Oberflaeche
   Gestaltungsidee: Sammelalbum bei Nacht. Tiefes Tintenblau als Grund, Karten
   liegen wie in Albumtaschen auf leicht angehobenen Flaechen. Einzige
   Schmuckfarbe ist ein warmes Foil-Gold fuer Werte und Hauptknoepfe; Gruen/Rot
   nur fuer Wertaenderungen. Zahlen tabellarisch, damit Euro-Betraege
   untereinander stehen. Folgt dem Hell/Dunkel-Modus des Handys. */

:root {
  color-scheme: dark;
  --bg: #0e1117;
  --bg-card: #171b23;
  --bg-elev: #1f2430;
  --bg-hover: #252b38;
  --border: #2a303c;
  --text: #eef1f6;
  --dim: #9aa3b2;
  --faint: #6b7385;
  --accent: #f2c14e;
  --accent-strong: #ffd36b;
  --accent-ink: #231a00;
  --good: #3fcf7f;
  --bad: #ff6b6b;
  --holo: linear-gradient(115deg, #f2c14e 0%, #ff8fb1 35%, #7ad7ff 65%, #b6f28d 100%);
  --shadow: 0 6px 20px rgba(0, 0, 0, .35);
  --radius: 12px;
  --radius-sm: 8px;
  --nav-h: 64px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f3f4f7;
    --bg-card: #ffffff;
    --bg-elev: #eef0f4;
    --bg-hover: #e6e9ef;
    --border: #dadee6;
    --text: #141821;
    --dim: #5b6374;
    --faint: #8a91a1;
    --accent: #b7860f;
    --accent-strong: #9a700a;
    --accent-ink: #ffffff;
    --good: #12924c;
    --bad: #cf2e2e;
    --shadow: 0 6px 18px rgba(20, 24, 33, .08);
  }
}
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
img { max-width: 100%; display: block; }
.num { font-variant-numeric: tabular-nums; }
.dim { color: var(--dim); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* --- Kopf ------------------------------------------------------------------ */

header.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; letter-spacing: .01em; }
.brand-mark {
  width: 22px; height: 30px; border-radius: 4px;
  background: var(--holo);
  box-shadow: 4px -3px 0 -1px var(--bg), 4px -3px 0 0 var(--border);
}
header.top .spacer { flex: 1; }
.back {
  border: 0; background: none; color: var(--text); font-size: 15px; padding: 6px 8px 6px 0;
  display: inline-flex; align-items: center; gap: 4px; cursor: pointer;
}

main { max-width: 980px; margin: 0 auto; padding: 16px; }

h1 { font-size: 22px; margin: 0 0 4px; line-height: 1.25; }
h2 { font-size: 17px; margin: 22px 0 10px; }
h3 { font-size: 15px; margin: 0 0 6px; }
p { margin: 0 0 10px; }

/* --- Navigation unten ----------------------------------------------------- */

nav.bottom {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg-card) 94%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
nav.bottom a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--dim); font-size: 11.5px; text-decoration: none;
}
nav.bottom a svg { width: 24px; height: 24px; }
nav.bottom a.active { color: var(--accent); }
nav.bottom a.scan-btn svg {
  width: 30px; height: 30px; padding: 5px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
}

/* --- Flaechen ---------------------------------------------------------- */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.banner {
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  font-size: 14px;
}
.banner.warn { border-color: color-mix(in srgb, var(--bad) 55%, var(--border)); color: var(--text); }
.banner.ok { border-color: color-mix(in srgb, var(--good) 55%, var(--border)); }

/* Wert-Kopf der Sammlung */
.total {
  position: relative;
  overflow: hidden;
  padding: 16px;
}
.total::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--holo); opacity: .9;
}
.total .label { color: var(--dim); font-size: 13px; }
.total .value { font-size: 30px; font-weight: 750; letter-spacing: -.01em; }
.delta { font-size: 13px; font-weight: 600; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }

/* --- Bedienelemente ---------------------------------------------------- */

button, .button {
  font: inherit;
  font-size: 15px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  padding: 10px 14px;
  min-height: 42px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none;
}
button:hover, .button:hover { background: var(--bg-hover); text-decoration: none; }
button.primary, .button.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650;
}
button.primary:hover, .button.primary:hover { background: var(--accent-strong); }
button.danger { color: var(--bad); }
button.small { min-height: 34px; padding: 6px 10px; font-size: 14px; }
button.block, .button.block { width: 100%; }
button:disabled { opacity: .55; cursor: default; }

label.field { display: block; font-size: 13px; color: var(--dim); margin: 10px 0 4px; }
input[type="text"], input[type="password"], input[type="search"], input[type="number"], select, textarea {
  width: 100%;
  font: inherit;
  font-size: 16px;            /* kleiner als 16px zoomt iOS beim Antippen */
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}
textarea { min-height: 70px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--dim);
  border-radius: 999px;
  padding: 6px 12px;
  min-height: 34px;
  font-size: 14px;
}
.chip.active { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); font-weight: 600; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.switch input { width: 46px; height: 28px; accent-color: var(--accent); }

.segmented { display: flex; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; padding: 3px; }
.segmented button {
  flex: 1; border: 0; background: none; min-height: 38px; border-radius: 9px; color: var(--dim);
}
.segmented button.active { background: var(--bg-card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* --- Kartenraster ------------------------------------------------------ */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 12px;
}
.tile {
  display: block;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  text-decoration: none;
  position: relative;
}
.tile:hover { text-decoration: none; background: var(--bg-hover); }
.tile .pic {
  aspect-ratio: 63 / 88;
  border-radius: 7px;
  overflow: hidden;
  background: var(--bg-elev);
}
.tile .pic img { width: 100%; height: 100%; object-fit: cover; }
.tile .name { font-weight: 600; font-size: 14px; margin-top: 7px; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .meta { font-size: 12px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .price { font-weight: 700; font-size: 15px; margin-top: 2px; }
.qty {
  position: absolute; top: 12px; right: 12px;
  background: rgba(0, 0, 0, .72); color: #fff; font-size: 12px; font-weight: 700;
  border-radius: 999px; padding: 1px 8px;
}

/* Trefferliste (Scan/Suche) */
.list { display: flex; flex-direction: column; gap: 10px; }
.hit {
  display: flex; gap: 12px; align-items: center;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px; color: var(--text); text-decoration: none; text-align: left; width: 100%;
  min-height: 0; justify-content: flex-start;
}
.hit:hover { background: var(--bg-hover); text-decoration: none; }
.hit .pic { width: 64px; flex: none; aspect-ratio: 63 / 88; border-radius: 6px; overflow: hidden; background: var(--bg-elev); }
.hit .pic img { width: 100%; height: 100%; object-fit: cover; }
.hit .info { flex: 1; min-width: 0; }
.hit .name { font-weight: 650; line-height: 1.3; }
.hit .meta { font-size: 13px; color: var(--dim); }
.hit .price { font-weight: 700; text-align: right; white-space: nowrap; }
.badge {
  display: inline-block; font-size: 11.5px; font-weight: 600; letter-spacing: .02em;
  border: 1px solid var(--border); border-radius: 999px; padding: 0 7px; color: var(--dim);
  margin-right: 4px; white-space: nowrap;
}
.badge.gold { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }

/* --- Kartendetail ------------------------------------------------------ */

.detail { display: grid; grid-template-columns: minmax(0, 300px) minmax(0, 1fr); gap: 20px; align-items: start; }
.detail .big { border-radius: 14px; overflow: hidden; background: var(--bg-elev); aspect-ratio: 63 / 88; box-shadow: var(--shadow); }
.detail .big img { width: 100%; height: 100%; object-fit: contain; }
.photo-toggle { margin-top: 8px; }

.prices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.prices .p { background: var(--bg-elev); border-radius: 10px; padding: 8px 10px; }
.prices .p .l { font-size: 12px; color: var(--dim); }
.prices .p .v { font-weight: 700; font-size: 16px; }
.headline-price { font-size: 32px; font-weight: 780; letter-spacing: -.01em; line-height: 1.1; }

.chart { width: 100%; height: auto; margin-top: 6px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: color-mix(in srgb, var(--accent) 16%, transparent); }
.chart text { fill: var(--faint); font-size: 11px; font-family: var(--sans); }
.chart .axis { stroke: var(--border); }

.entry { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }
.entry:first-child { border-top: 0; padding-top: 0; margin-top: 0; }

/* --- Scan -------------------------------------------------------------- */

.scan-zone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  min-height: 220px; text-align: center;
  border: 2px dashed var(--border); border-radius: 18px; padding: 24px;
  background: var(--bg-card); cursor: pointer;
}
.scan-zone .icon { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); }
.scan-zone .icon svg { width: 32px; height: 32px; }
.preview { width: 120px; border-radius: 10px; box-shadow: var(--shadow); }

.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite; margin: 8px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Blatt von unten (Formulare) ------------------------------------------ */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .5);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--bg-card); border: 1px solid var(--border); border-bottom: 0;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
.sheet h2 { margin-top: 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
  z-index: 60; background: var(--text); color: var(--bg); border-radius: 999px;
  padding: 9px 16px; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100% - 32px);
}

table.users { width: 100%; border-collapse: collapse; }
table.users td { padding: 9px 6px; border-top: 1px solid var(--border); vertical-align: middle; }

.empty { text-align: center; color: var(--dim); padding: 36px 12px; }
.empty .big-icon { font-size: 40px; margin-bottom: 6px; }

.install-hint {
  position: fixed; left: 12px; right: 12px; z-index: 40;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
  font-size: 13.5px; box-shadow: var(--shadow);
}

/* Anmeldung */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }

@media (max-width: 640px) {
  main { padding: 12px; }
  .detail { grid-template-columns: 1fr; }
  .detail .big { max-width: 300px; margin: 0 auto; width: 100%; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .prices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 900px) {
  nav.bottom { left: 50%; transform: translateX(-50%); bottom: 14px; width: 520px; border: 1px solid var(--border);
    border-radius: 18px; height: var(--nav-h); padding-bottom: 0; box-shadow: var(--shadow); }
  body { padding-bottom: calc(var(--nav-h) + 40px); }
}

/* --- Treffer nach Kategorien (aufklappbar) ------------------------------- */

.groups { display: flex; flex-direction: column; gap: 10px; }
.group {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.group-head {
  width: 100%;
  display: flex; align-items: center; gap: 12px;
  background: none; border: 0; border-radius: 0;
  padding: 10px 12px; min-height: 60px;
  text-align: left; justify-content: flex-start;
}
.group-head:hover { background: var(--bg-hover); }
.group-head .grow { display: flex; flex-direction: column; min-width: 0; }
.group-head .title { font-weight: 650; line-height: 1.3; }
.group-head .sub { font-size: 12.5px; color: var(--dim); }
.group-head .thumbs { display: flex; flex: none; padding-left: 8px; }
.group-head .thumbs img {
  width: 28px; height: 39px; object-fit: cover; border-radius: 4px;
  margin-left: -10px; border: 2px solid var(--bg-card); background: var(--bg-elev);
}
.group-head .chev { flex: none; color: var(--dim); transition: transform .18s ease; }
.group.open .group-head .chev { transform: rotate(90deg); }
.group .list { padding: 0 8px 8px; }
.group .hit { background: var(--bg-elev); border-color: transparent; }
.group .hit:hover { background: var(--bg-hover); }
.hit .price { font-size: 14.5px; }
