:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16181d;
  --muted: #646b78;
  --border: #e1e4ea;
  --grid: #eceef2;
  --accent: #d93a3f;
  --accent-hover: #c02f34;
  --accent-text: #ffffff;
  --accent-soft: #fdeceb;
  --chart-value: #d93a3f;
  --chart-value-area: rgb(217 58 63 / 8%);
  --chart-cost: #3d6fc6;
  --bar: #2a8c86;
  --pos: #17804a;
  --neg: #c0282e;
  --ok-bg: #e8f5ee;
  --ok-text: #17663e;
  --warn-bg: #fff4e0;
  --warn-text: #8a5300;
  --err-bg: #fdeceb;
  --err-text: #a3262b;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #232730;
    --text: #e9ebef;
    --muted: #9aa1ad;
    --border: #2e333d;
    --grid: #262a33;
    --accent: #ef5a5f;
    --accent-hover: #f4777b;
    --accent-text: #1a0607;
    --accent-soft: #3a1f21;
    --chart-value: #e0555a;
    --chart-value-area: rgb(224 85 90 / 12%);
    --chart-cost: #5b87d8;
    --bar: #4fb3ad;
    --pos: #5fd394;
    --neg: #ff8a8e;
    --ok-bg: #16301f;
    --ok-text: #7fd6a3;
    --warn-bg: #352a12;
    --warn-text: #f2c46b;
    --err-bg: #3a1f21;
    --err-text: #f4a3a6;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

/* iOS ab 26.1 färbt die Statusleiste der Home-Bildschirm-App nach dem Seitenhintergrund (black-translucent wird
   ignoriert). Kopfzeile, html und body haben deshalb dieselbe Farbe, sonst entsteht oben ein andersfarbiger Streifen. */
html { background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }
h2 { font-size: 1.05rem; margin: 0; }
h3 { font-size: 0.9rem; margin: 0 0 8px; color: var(--muted); font-weight: 600; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 0.9em; }
.muted { color: var(--muted); }
.center { text-align: center; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn-text { color: var(--warn-text); }
[hidden] { display: none !important; }

/* --- Kopfzeile ------------------------------------------------------------ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px 20px;
  flex-wrap: wrap;
  padding: 10px max(20px, env(safe-area-inset-right)) 10px max(20px, env(safe-area-inset-left));
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; }
.logo { width: 24px; height: 24px; }
.brand-name { font-weight: 700; font-size: 1.1rem; letter-spacing: -0.01em; white-space: nowrap; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 550;
  white-space: nowrap;
}
.tabs a:hover { background: var(--surface-2); color: var(--text); }
.tabs a.active { background: var(--accent-soft); color: var(--accent); }
/* Symbole nur in der Leiste unten auf dem Handy */
.tabs svg { display: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}
.chip[data-state="ok"]::before { content: "● "; color: var(--pos); }
.chip[data-state="stale"] { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.chip[data-state="error"] { background: var(--err-bg); color: var(--err-text); border-color: transparent; }
.banner { padding: 10px 20px; font-weight: 550; }
.banner[data-state="stale"] { background: var(--warn-bg); color: var(--warn-text); }
.banner[data-state="error"] { background: var(--err-bg); color: var(--err-text); }
.banner.update { background: var(--ok-bg); color: var(--ok-text); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.btn.small { padding: 3px 10px; font-size: 0.82rem; }

main { max-width: 1240px; margin: 0 auto; padding: 20px; }
.footer { max-width: 1240px; margin: 0 auto; padding: 8px 20px calc(32px + env(safe-area-inset-bottom)); font-size: 0.8rem; }
.urls { margin: 4px 0 10px; padding-left: 18px; }
.urls code { user-select: all; font-size: 0.95em; }
.ok-note { color: var(--ok-text); font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 16px;
  min-width: 0;
}
.card > h2 { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head.wrap { flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 > .card { margin-bottom: 16px; }
.empty { text-align: center; padding: 40px 20px; }
.empty h2 { margin-bottom: 8px; }

/* --- Konto & Abgleich ------------------------------------------------------ */
.chips { display: flex; gap: 6px; margin-left: auto; }
.chip.sync[data-state="ok"]::before { content: "☁︎ "; }
.chip.sync[data-state="busy"]::before { content: "☁︎ "; }
.chip.sync[data-state="pending"] { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.chip.sync[data-state="error"] { background: var(--err-bg); color: var(--err-text); border-color: transparent; }
.chip.sync[data-state="off"] { color: var(--accent); }
.account .login-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.account .login-row p { flex-basis: 100%; margin: 0 0 4px; }
.account .login-row input { flex: 1; min-width: 200px; }
.account-line { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-bottom: 10px; }

/* --- Hinweise (Sicherung, Home-Bildschirm) und Laden ---------------------- */
.loading { text-align: center; color: var(--muted); padding: 48px 16px; }
.loading::before {
  content: "";
  display: block;
  width: 28px;
  height: 28px;
  margin: 0 auto 12px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loading::before { animation: none; } }
.notice {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.9rem;
}
.notice > div { flex: 1; }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.notice .close { flex-shrink: 0; }

/* --- Sammlung: Gesamtwert, Aktionen, Kacheln ------------------------------ */
.p-head { text-align: center; margin: 4px 0 16px; }
.p-value { font-size: 2.4rem; font-weight: 750; letter-spacing: -0.02em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.p-profit { font-weight: 600; font-variant-numeric: tabular-nums; }
.p-source { font-size: 0.78rem; margin-top: 2px; }
.p-actions { display: flex; justify-content: center; gap: 28px; margin-bottom: 18px; }
.p-act {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
}
.p-act svg {
  width: 48px;
  height: 48px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  fill: none;
  stroke: var(--text);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.p-act:hover svg { border-color: var(--accent); stroke: var(--accent); }
.p-tools { display: flex; gap: 8px; margin-bottom: 6px; }
.p-tools input { flex: 1; }
.p-tools select { flex: 0 1 auto; max-width: 42%; }
.p-count { font-size: 0.82rem; margin: 0 2px 10px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.tile {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  padding: 10px;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.tile:hover { border-color: var(--accent); }
.t-name {
  font-weight: 650;
  line-height: 1.25;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.t-sub { font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-tags { display: flex; flex-wrap: wrap; gap: 4px; }
/* Menge links, Wert rechts, Gewinn darunter in eigener Zeile (auf schmalen Kacheln sonst umbrochen) */
.t-foot { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: baseline; gap: 0 6px; margin-top: auto; padding-top: 6px; font-variant-numeric: tabular-nums; }
.t-foot b { justify-self: end; font-size: 1.05rem; }
.t-foot small { grid-column: 1 / -1; justify-self: end; font-size: 0.78rem; font-weight: 600; white-space: nowrap; }

/* Großes Bild: Karte ganz sichtbar, Sealed als Set-Logo mit Produktart */
.art {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  aspect-ratio: 1;
  margin-bottom: 6px;
  padding: 8px;
  border: 0;
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
}
.art img { display: block; width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.art.placeholder img.art-logo { height: auto; max-height: 55%; width: 85%; }
.art.placeholder b { text-align: center; overflow-wrap: anywhere; }
.art.placeholder small { font-size: 0.75rem; font-weight: 600; color: var(--muted); text-align: center; }
button.art { cursor: zoom-in; }

/* --- Detailansicht (Dialog) ----------------------------------------------- */
.detail {
  width: min(720px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 20px 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px rgb(0 0 0 / 25%);
}
.detail::backdrop { background: rgb(0 0 0 / 45%); }
.dt-bar { position: sticky; top: 0; z-index: 1; display: flex; justify-content: flex-end; margin: 0 -20px; padding: 8px 12px 4px; background: var(--surface); }
.dt-art .art { aspect-ratio: auto; height: min(40vh, 340px); margin-bottom: 14px; }
.dt-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.dt-name { min-width: 0; }
.dt-name h2 { font-size: 1.25rem; overflow-wrap: anywhere; }
#dt-sub { font-size: 0.88rem; margin-top: 2px; }
.dt-value { display: grid; justify-items: end; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.dt-value b { font-size: 1.4rem; }
.dt-value small { font-size: 0.82rem; font-weight: 600; }
.dt-cm { width: 100%; }
.dt-section { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.dt-section h3 { margin: 0; font-size: 1rem; color: var(--text); }
.dt-section > h3 { margin-bottom: 10px; }
.dt-section .card-head { margin-bottom: 10px; }
.dt-price-grid { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 2px 12px; font-variant-numeric: tabular-nums; }
.dt-price-grid .basis { font-weight: 700; color: var(--text); }
.dt-stand { font-size: 0.78rem; margin: 8px 0 0; }
.dt-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.dt-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.dt-i-main { display: grid; min-width: 0; }
.dt-i-main small { font-size: 0.8rem; overflow-wrap: anywhere; }
.qty { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.qty button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}
.qty button:hover { border-color: var(--accent); color: var(--accent); }
.dt-i-val { display: grid; justify-items: end; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.dt-i-val small { font-size: 0.8rem; font-weight: 600; }

/* --- Kennzahlen ----------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 18px;
  min-width: 0;
}
.kpi-label { color: var(--muted); font-size: 0.85rem; font-weight: 550; }
.kpi-value { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin: 2px 0; }
.kpi.hero .kpi-value { font-size: 2.2rem; }
.kpi-sub { color: var(--muted); font-size: 0.82rem; }

/* --- Diagramm ------------------------------------------------------------- */
.chart { position: relative; min-height: 220px; }
.chart svg { display: block; touch-action: pan-y; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.value { stroke: var(--chart-value); }
.chart .line.cost { stroke: var(--chart-cost); stroke-dasharray: 5 4; }
.chart .area { fill: var(--chart-value-area); }
.chart .cross-line { stroke: var(--muted); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .dot.value { fill: var(--chart-value); }
.chart .dot.cost { fill: var(--chart-cost); }
.chart-empty { display: grid; place-content: center; min-height: 200px; text-align: center; padding: 0 20px; }
.chart-empty p { max-width: 420px; margin: 6px auto 0; font-size: 0.88rem; }
.tip {
  position: absolute;
  top: 6px;
  transform: translateX(-50%);
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgb(0 0 0 / 12%);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.82rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.legend { display: flex; gap: 12px; font-size: 0.82rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.swatch { display: inline-block; width: 14px; height: 0; border-top: 2px solid; margin-right: 4px; vertical-align: middle; }
.swatch.value { border-color: var(--chart-value); }
.swatch.cost { border-color: var(--chart-cost); border-top-style: dashed; }

/* --- Aufteilung ----------------------------------------------------------- */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.seg button {
  border: 0;
  background: none;
  font: inherit;
  font-size: 0.82rem;
  padding: 4px 10px;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
}
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; align-items: center; gap: 10px; font-size: 0.88rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; }
.bar { height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-value small { color: var(--muted); margin-left: 6px; display: inline-block; min-width: 3.2em; }

/* --- Top-Listen ----------------------------------------------------------- */
.toplist { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.link-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: none;
  padding: 4px 6px;
  border-radius: 8px;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.link-row:hover { background: var(--surface-2); }
.tl-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-val { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tl-val small, td small { display: block; font-weight: 400; font-size: 0.78rem; }
td small { color: var(--muted); }
td.pos small, td.neg small, .tl-val small { color: inherit; opacity: 0.85; }

/* --- Tabelle -------------------------------------------------------------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
input, select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
}
input:focus, select:focus, button:focus-visible, tr:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#f-text { width: 240px; }
.table-wrap { overflow-x: auto; margin: 0 -18px; }
table.items { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.items th {
  text-align: left;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.items td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.items th:first-child, .items td:first-child { padding-left: 18px; }
.items th:last-child, .items td:last-child { padding-right: 18px; }
.items tbody tr[data-edit] { cursor: pointer; }
.items tbody tr[data-edit]:hover { background: var(--surface-2); }
.items .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.items .strong { font-weight: 650; }
.items tr.total td { border-bottom: 0; border-top: 2px solid var(--border); }
.c-thumb { width: 52px; }
.c-name { overflow-wrap: anywhere; }
.c-set { font-size: 0.82rem; }

.code {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 650;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.tag.grade { background: var(--ok-bg); color: var(--ok-text); }
.tag.warn { background: var(--warn-bg); color: var(--warn-text); }

/* --- Bilder --------------------------------------------------------------- */
.thumb {
  display: block;
  width: 52px;
  aspect-ratio: 5 / 7;
  padding: 0;
  border: 0;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-2);
  cursor: zoom-in;
  flex-shrink: 0;
}
.thumb.small { width: 34px; border-radius: 4px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.placeholder {
  display: grid;
  place-items: center;
  align-content: center;
  padding: 3px;
  font-size: 0.62rem;
  line-height: 1.15;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  cursor: default;
}
.thumb.placeholder small { display: block; margin-top: 2px; font-weight: 650; color: var(--text); overflow-wrap: anywhere; }
.thumb.small.placeholder small { display: none; }
.thumb.small.placeholder { font-size: 0.5rem; }
.zoom { padding: 0; border: 0; background: none; max-width: 92vw; }
.zoom::backdrop { background: rgb(0 0 0 / 70%); }
.zoom img { display: block; max-height: 88vh; max-width: 92vw; border-radius: 14px; }

/* --- Suche ---------------------------------------------------------------- */
.search-label { display: block; font-weight: 650; margin-bottom: 6px; }
#q { width: 100%; font-size: 1.1rem; padding: 10px 14px; }
.hint { font-size: 0.85rem; margin: 8px 0 0; }
.search-status { margin: 0 4px 10px; font-size: 0.88rem; }
.results { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.result {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.result .thumb { width: 64px; }
.result.exact { border-color: var(--accent); }
.result.exact .code { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.r-main { min-width: 0; }
.r-name { overflow-wrap: anywhere; }
.r-prices { display: flex; gap: 14px; flex-wrap: wrap; align-items: baseline; margin-top: 4px; font-size: 0.9rem; }
.price { font-weight: 650; font-variant-numeric: tabular-nums; }
.price small { font-weight: 400; color: var(--muted); }
.owned { font-size: 0.8rem; color: var(--ok-text); margin-top: 3px; }
.r-actions { display: flex; flex-direction: column; gap: 6px; }

/* --- Scanner (Aufbau aus dem Ankauf-Rechner) ------------------------------ */
.search-row { display: flex; gap: 8px; }
.search-row #q { flex: 1; }
.scan-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.scan-btn:hover { border-color: var(--accent); color: var(--accent); }
.scanner {
  width: min(640px, 100vw);
  max-width: 100vw;
  max-height: 100dvh;
  overflow-y: auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
.scanner::backdrop { background: rgb(0 0 0 / 70%); }
.scan-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.scan-view { position: relative; aspect-ratio: 4 / 3; overflow: hidden; border-radius: 10px; background: #000; }
.scan-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Rahmen für Kürzel und Nummer unten links auf der Karte, außen abgedunkelt. Klein, damit man die Karte nah hält */
.scan-frame {
  position: absolute;
  left: 18%;
  right: 18%;
  top: 40%;
  height: 20%;
  border: 2px solid #fff;
  border-radius: 8px;
  box-shadow: 0 0 0 100vmax rgb(0 0 0 / 45%);
}
.scan-hint { margin: 10px 0 4px; font-size: 0.85rem; color: var(--muted); }
.scan-camera-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 0.85rem; color: var(--muted); }
.scan-camera-row select { flex: 1; min-width: 0; padding: 4px 6px; }
.scan-note { margin: 0 0 8px; padding: 6px 10px; font-size: 0.82rem; border-radius: 8px; background: var(--warn-bg); color: var(--warn-text); }
.scan-status { margin: 0 0 8px; font-size: 0.9rem; font-weight: 600; }
.scan-status.ok { color: var(--ok-text); }
.scan-status.warn { color: var(--warn-text); }
.scan-tech { margin: -4px 0 8px; font: 0.75rem/1.4 ui-monospace, Menlo, monospace; color: var(--muted); overflow-wrap: anywhere; }
/* Technische Angabe (Kamera-ID, Bildgröße) nur bei Problemen, sonst verwirrt sie */
.scan-status:not(.warn) + .scan-tech { display: none !important; }
.scan-result { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.scan-several { font-size: 0.85rem; color: var(--muted); }
.scan-item {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
}
.scan-item .thumb { width: 48px; }
.scan-main { min-width: 0; overflow-wrap: anywhere; }
.scan-side { display: grid; justify-items: end; gap: 6px; }
.scan-side .price { white-space: nowrap; }
.scan-buttons { display: flex; gap: 6px; }
.scan-added { margin-top: 2px; font-size: 0.8rem; font-weight: 600; color: var(--ok-text); }
.scan-lang { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 0.78rem; color: var(--muted); }
.scan-lang select { padding: 2px 6px; font-weight: 600; }
.scan-lang.default { color: var(--warn-text); font-weight: 600; }
.scan-lang.default select { border-color: var(--warn-text); }
.scan-ask { margin: 0 0 12px; font-size: 0.88rem; }
.scan-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.scan-photo { position: relative; }
.scan-photo input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
@media (max-width: 560px) {
  .scan-btn span { display: none; }
  .scanner { border-radius: 0; width: 100vw; height: 100dvh; }
  .scan-item { grid-template-columns: 44px minmax(0, 1fr); }
  .scan-item .thumb { width: 44px; }
  .scan-side { grid-column: 1 / -1; grid-auto-flow: column; justify-content: space-between; align-items: center; }
}

/* --- Knöpfe --------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: none; }
.btn.danger { color: var(--neg); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- Einstellungen -------------------------------------------------------- */
.field { display: grid; gap: 4px; margin-bottom: 14px; }
.field > span { font-weight: 600; font-size: 0.88rem; }
.field small { font-size: 0.8rem; }
.check { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 14px; cursor: pointer; }
.check input { margin-top: 3px; padding: 0; width: 18px; height: 18px; flex-shrink: 0; accent-color: var(--accent); }
.check small { font-size: 0.8rem; }
.factor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.factor { display: grid; grid-template-columns: 1fr 64px auto; align-items: center; gap: 6px; margin-bottom: 6px; font-size: 0.86rem; }
.factor input { padding: 4px 6px; text-align: right; }
.factor input:disabled { opacity: 0.5; }

/* --- Formular (Dialog) ---------------------------------------------------- */
.editor {
  width: min(640px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px rgb(0 0 0 / 25%);
}
.editor::backdrop { background: rgb(0 0 0 / 45%); }
.editor form { padding: 18px 20px; }
.editor-head { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: start; margin-bottom: 16px; }
.editor-head .thumb { width: 72px; }
.ed-title { font-weight: 700; font-size: 1.1rem; overflow-wrap: anywhere; }
#ed-sub { font-size: 0.88rem; margin: 2px 0 4px; }
#ed-cm { font-size: 0.88rem; }
.ed-added { font-size: 0.8rem; margin-bottom: 4px; }
.nowrap { white-space: nowrap; }
.close { border: 0; background: none; font-size: 1.6rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.editor-grid .field { margin-bottom: 12px; }
.wide { grid-column: 1 / -1; }
.ed-preview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 4px 0 16px;
  font-variant-numeric: tabular-nums;
}
.ed-preview > div { display: grid; }
.ed-preview b { font-size: 1.15rem; }
.ed-preview small { font-size: 0.78rem; }
.editor-actions { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }

.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  max-width: calc(100vw - 32px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 550;
  box-shadow: 0 8px 24px rgb(0 0 0 / 20%);
}
.toast[data-kind="err"] { background: var(--err-text); color: var(--surface); }
.toast[data-kind="warn"] { background: var(--warn-text); color: var(--surface); }

/* --- Schmale Bildschirme -------------------------------------------------- */
@media (max-width: 1000px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi.hero, .kpi:last-child { grid-column: 1 / -1; }
  .grid-2 { grid-template-columns: 1fr; gap: 0; }
}

@media (max-width: 720px) {
  main { padding: 12px 16px; }
  .topbar { padding: calc(8px + env(safe-area-inset-top)) 16px 8px; gap: 6px 10px; }
  /* iOS zoomt bei Feldern unter 16 px beim Antippen in die Seite */
  input, select { font-size: 16px; }
  /* Bereiche als Leiste unten, wie bei Apps üblich (Daumen). Die Seite bekommt unten Platz dafür */
  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
    padding: 6px max(8px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    background: var(--surface);
    border-top: 1px solid var(--border);
  }
  .tabs a { display: grid; justify-items: center; gap: 2px; padding: 4px 0; font-size: 0.7rem; }
  .tabs a.active { background: none; }
  .tabs svg { display: block; width: 24px; height: 24px; }
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .chips { margin-left: auto; }
  .p-value { font-size: 2.1rem; }
  .p-actions { gap: 22px; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tile { padding: 8px; }
  .detail { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border: 0; border-radius: 0; padding: 0 16px calc(20px + env(safe-area-inset-bottom)); }
  .dt-bar { margin: 0 -16px; padding-top: calc(6px + env(safe-area-inset-top)); }
  .dt-item { grid-template-columns: auto minmax(0, 1fr) auto; }
  .dt-i-main { grid-column: 1 / -1; }
  .banner, .footer { padding-left: 16px; padding-right: 16px; }
  .card { padding: 14px; }
  .kpis { gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi-value { font-size: 1.3rem; }
  .kpi.hero .kpi-value { font-size: 1.9rem; }
  .filters, #f-text { width: 100%; }
  .filters select { flex: 1; }

  /* Tabelle als Karten: Bild + Name oben, Werte als Raster darunter */
  .table-wrap { margin: 0; overflow: visible; }
  .items thead { display: none; }
  .items, .items tbody { display: block; }
  .items tbody tr {
    display: grid;
    grid-template-columns: 40px 1fr 1fr 1fr;
    gap: 2px 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }
  .items td { display: block; border: 0; padding: 0 !important; }
  .items td.c-thumb { grid-row: 1 / span 4; width: auto; } /* Bild belegt Spalte 1, Werte fließen in Spalte 2–4 */
  .items td.c-card { grid-column: 2 / -1; }
  .items td[data-label] { text-align: left; font-size: 0.85rem; }
  .items td[data-label]::before { content: attr(data-label); display: block; font-size: 0.7rem; color: var(--muted); font-weight: 400; }
  .items tr.total td:empty { display: none; }
  .items tr.total td:nth-child(2) { grid-column: 1 / -1; }

  .result { grid-template-columns: auto 1fr; }
  .r-actions { grid-column: 1 / -1; flex-direction: row; }
  .r-actions .btn { flex: 1; }
  .editor form { padding: 14px; }
  .editor-grid { grid-template-columns: 1fr; }
  .ed-preview { grid-template-columns: 1fr 1fr; }
  .factor-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: minmax(80px, 30%) 1fr auto; }
}
