/* Kipfer ScanApp - Layout und Bildschirme. Farben, Schriften und Grundkomponenten
   kommen aus ds.css (Industry-Designsystem); hier nur, was die App zusaetzlich braucht. */

:root {
  --ink-dim: var(--color-neutral-600);
  --ink-mid: var(--color-neutral-700);
  --field: var(--color-accent-900);
  --on-field: #f2f2f3;
  --on-field-dim: rgba(242, 242, 243, .72);
  --ok: #2f7d4f;
  --ok-bg: #e3f1e8;
  --err: #b3261e;
  --err-bg: #fbe9e7;
  --staging: #d7261e;
  --tap: 48px;
}

html, body { height: 100%; }
body { overflow: hidden; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
.ic { flex: none; }

#app { height: 100dvh; display: flex; flex-direction: column; }

/* Scan-Puffer: fokussierbar, aber unsichtbar. display:none wuerde den Fokus verhindern. */
#scanbuf { position: fixed; left: -1000px; top: 0; width: 10px; height: 10px; opacity: 0; border: 0; padding: 0; }

/* ── Staging-Markierung ─────────────────────────────────────────────── */
#env-frame { display: none; }
html[data-env="staging"] #env-frame {
  display: block; position: fixed; inset: 0; z-index: 1000; pointer-events: none;
  border: 6px solid var(--staging);
}
html[data-env="staging"] #app { padding: 6px 6px 6px; }
.env-ribbon {
  flex: none; background: var(--staging); color: #fff; text-align: center;
  font-family: var(--font-heading); font-weight: 600; font-size: 12px; letter-spacing: .2em;
  text-transform: uppercase; padding: 2px 0 4px; margin: -6px -6px 0;
}

/* ── Kopf ───────────────────────────────────────────────────────────── */
.hdr {
  flex: none; display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-bottom: 1px solid var(--color-divider); background: var(--color-bg);
}
.hdr-title { flex: 1; min-width: 0; }
.hdr-title b { display: block; font-family: var(--font-heading); font-weight: 600; font-size: 20px; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hdr-title small { display: block; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sq { width: 44px; height: 44px; padding: 0; flex: none; }

.body { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.body::-webkit-scrollbar { width: 0; }
.pad { padding: 14px; }
.foot {
  flex: none; display: flex; gap: 8px; padding: 10px 14px 12px;
  border-top: 1px solid var(--color-divider); background: var(--color-bg);
}

/* ── Bausteine ──────────────────────────────────────────────────────── */
.kicker { font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--color-accent); }
.muted { color: var(--ink-dim); }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.h-cond { font-family: var(--font-heading); font-weight: 600; line-height: 1.08; }
.section-label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-dim); margin: 18px 0 8px;
}
.section-label span:nth-child(2) { font-size: 11px; letter-spacing: 0; text-transform: none; font-variant-numeric: tabular-nums; }
.bp { position: relative; border: 1px solid var(--color-divider); }
.btn-primary.bp { border-color: var(--color-accent); }
/* Registrierungsmarken wie .blueprint im Designsystem, auch fuer die dunklen Felder. */
.bp > .corner, .field-card > .corner {
  position: absolute; width: 11px; height: 11px; pointer-events: none;
  color: color-mix(in srgb, var(--color-text) 55%, transparent);
}
.bp > .corner::before, .bp > .corner::after,
.field-card > .corner::before, .field-card > .corner::after { content: ""; position: absolute; background: currentColor; }
.bp > .corner::before, .field-card > .corner::before { left: 5px; top: 0; width: 1px; height: 100%; }
.bp > .corner::after, .field-card > .corner::after { top: 5px; left: 0; width: 100%; height: 1px; }
.bp > .corner.tl, .field-card > .corner.tl { top: -6px; left: -6px; }
.bp > .corner.tr, .field-card > .corner.tr { top: -6px; right: -6px; }
.bp > .corner.bl, .field-card > .corner.bl { bottom: -6px; left: -6px; }
.bp > .corner.br, .field-card > .corner.br { bottom: -6px; right: -6px; }
.btn-lg { height: 52px; font-size: 16px; letter-spacing: .03em; }
.btn-md { height: var(--tap); font-size: 15px; }
.btn-danger { color: var(--err); }
.grow { flex: 1; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.tag-ok { background: var(--ok-bg); color: var(--ok); }
.tag-warn { background: #fff1d6; color: #7a4b00; }
.tag-err { background: var(--err-bg); color: var(--err); }
.empty { text-align: center; padding: 40px 20px; color: var(--ink-dim); }
.empty .ic { margin: 0 auto 10px; display: block; color: var(--color-accent); }

/* Dunkles Feld (Aufforderung) */
.field-card { position: relative; padding: 14px; background: var(--field); border: 1px solid var(--field); color: var(--on-field); }
.field-card > .corner { color: rgba(242, 242, 243, .6); }
.field-card .kicker { color: var(--color-accent-400); }
.field-card .prompt { font-family: var(--font-heading); font-weight: 600; font-size: 28px; line-height: 1.05; margin-top: 2px; }
.field-card .hint { font-size: 13px; color: var(--on-field-dim); margin-top: 4px; line-height: 1.35; }
.field-card .btn { color: var(--on-field); border-color: rgba(242, 242, 243, .35); }
.field-card .btn:active { background: rgba(242, 242, 243, .12); }
.field-card .btn-accent { background: var(--color-accent); border-color: var(--color-accent); }
.scanwin {
  position: relative; height: 92px; margin-top: 12px; border: 1px solid rgba(148, 188, 227, .45);
  overflow: hidden; display: grid; place-items: center; text-align: center; padding: 0 12px;
}
.scanwin::before {
  content: ""; position: absolute; left: 0; top: 0; width: 100%; height: 2px;
  background: linear-gradient(90deg, transparent, var(--color-accent-400), transparent);
  animation: scanline 2.1s ease-in-out infinite alternate;
}
.scanwin .code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 17px; letter-spacing: .05em; word-break: break-all; }
.scanwin .bars { height: 22px; margin: 6px auto 0; width: 150px; opacity: .8;
  background: repeating-linear-gradient(90deg, #f2f2f3 0 2px, transparent 2px 5px, #f2f2f3 5px 6px, transparent 6px 10px); }
@keyframes scanline { from { transform: translateY(0); } to { transform: translateY(90px); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes flashOk { from { box-shadow: inset 0 0 0 4px var(--ok); } to { box-shadow: inset 0 0 0 0 transparent; } }
@keyframes flashErr { from { box-shadow: inset 0 0 0 4px var(--err); } to { box-shadow: inset 0 0 0 0 transparent; } }
.flash-ok { animation: flashOk .6s ease-out; }
.flash-err { animation: flashErr .8s ease-out; }

/* ── Login ─────────────────────────────────────────────────────────── */
.login { padding: 28px 22px 20px; display: flex; flex-direction: column; min-height: 100%; }
.brand { padding: 16px; margin-bottom: 22px; }
.brand .title { font-family: var(--font-heading); font-weight: 600; font-size: 38px; line-height: .95; margin-top: 4px; }
.pin-dots { display: flex; gap: 8px; }
.pin-dot { flex: 1; height: 50px; display: grid; place-items: center; font-family: var(--font-heading); font-weight: 600; font-size: 26px; }
.pin-dot.on { border-color: var(--color-accent); color: var(--color-accent-700); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.keypad .btn { height: 54px; font-size: 22px; font-variant-numeric: tabular-nums; }
.login select.input { min-height: 50px; font-size: 17px; }

/* ── Start ─────────────────────────────────────────────────────────── */
.me { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.avatar { width: 44px; height: 44px; display: grid; place-items: center; font-family: var(--font-heading); font-weight: 600; font-size: 17px; flex: none; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  position: relative; min-height: 124px; padding: 12px; display: flex; flex-direction: column; align-items: flex-start;
  text-align: left; background: transparent; border: 1px solid var(--color-divider); cursor: pointer;
}
.tile:active { background: color-mix(in srgb, var(--color-accent) 10%, transparent); }
.tile .ic { color: var(--color-accent); }
.tile b { margin-top: auto; font-family: var(--font-heading); font-weight: 600; font-size: 19px; line-height: 1.05; }
.tile small { font-size: 11px; color: var(--ink-dim); line-height: 1.3; margin-top: 2px; }
.tile .badge {
  position: absolute; top: 10px; right: 10px; min-width: 28px; height: 24px; padding: 0 7px;
  display: grid; place-items: center; font-family: var(--font-heading); font-weight: 600; font-size: 15px;
  background: var(--color-accent); color: var(--color-bg); font-variant-numeric: tabular-nums;
}
.tile .badge.zero { background: transparent; color: var(--ink-dim); border: 1px solid var(--color-divider); }
.tile.wide { grid-column: 1 / -1; min-height: 84px; flex-direction: row; align-items: center; gap: 12px; background: var(--field); color: var(--on-field); border-color: var(--field); }
.tile.wide .ic { color: var(--color-accent-400); }
.tile.wide b { margin: 0; font-size: 22px; }
.tile.wide small { color: var(--on-field-dim); }
.tile.wide > .corner { color: rgba(242, 242, 243, .6); }

/* ── Listen ─────────────────────────────────────────────────────────── */
.doc {
  position: relative; width: 100%; display: block; text-align: left; padding: 12px; margin-bottom: 12px;
  background: transparent; border: 1px solid var(--color-divider); cursor: pointer;
}
.doc:active { background: color-mix(in srgb, var(--color-text) 6%, transparent); }
.doc .ref { font-family: var(--font-heading); font-weight: 600; font-size: 19px; }
.doc .partner { font-size: 14px; color: var(--color-neutral-800); margin-top: 1px; }
.doc .meta { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; font-size: 11.5px; color: var(--ink-dim); }
.bar { height: 3px; background: rgba(29, 31, 32, .1); margin-top: 10px; }
.bar > i { display: block; height: 100%; background: var(--color-accent); }

/* ── Scan-Vorgang ───────────────────────────────────────────────────── */
.unit {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 8px;
  background: transparent; border: 1px solid var(--color-divider); text-align: left; cursor: pointer;
}
.unit.done { background: color-mix(in srgb, var(--ok) 6%, transparent); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.unit.active { border-color: var(--color-accent); box-shadow: inset 3px 0 0 var(--color-accent); }
.unit .mark {
  width: 30px; height: 30px; flex: none; display: grid; place-items: center;
  border: 1px solid var(--color-divider); color: var(--ink-dim);
}
.unit.done .mark { background: var(--ok); border-color: var(--ok); color: #fff; }
.unit .name { font-size: 14.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unit .sub { font-size: 11.5px; color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unit .qty { font-family: var(--font-heading); font-weight: 600; font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.content-list { margin: 10px 0 0; padding: 0; list-style: none; border-top: 1px solid rgba(242, 242, 243, .18); }
.content-list li { display: flex; gap: 8px; padding: 6px 0; border-bottom: 1px solid rgba(242, 242, 243, .12); font-size: 13px; }
.content-list li span:first-child { flex: 1; min-width: 0; }
.content-list li b { font-family: var(--font-heading); font-weight: 600; font-size: 15px; white-space: nowrap; }
.content-list.light { border-top-color: var(--color-divider); }
.content-list.light li { border-bottom-color: color-mix(in srgb, var(--color-text) 8%, transparent); }

/* ── Info ──────────────────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--color-divider); border: 1px solid var(--color-divider); margin-top: 12px; }
.stats > div { background: var(--color-bg); padding: 8px 6px; text-align: center; }
.stats b { display: block; font-family: var(--font-heading); font-weight: 600; font-size: 22px; line-height: 1; font-variant-numeric: tabular-nums; word-break: break-word; }
.stats small { font-size: 9.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-dim); }
.table td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }
.table td { vertical-align: top; }

/* ── Overlays ──────────────────────────────────────────────────────── */
.backdrop { position: fixed; inset: 0; z-index: 500; background: rgba(29, 31, 32, .55); display: grid; place-items: center; padding: 20px; animation: fadeIn .14s ease; }
.backdrop.sheet { place-items: end stretch; padding: 0; }
.dlg { position: relative; width: min(420px, 100%); background: var(--color-bg); border: 1px solid var(--color-divider); padding: 16px; box-shadow: var(--shadow-lg); }
.dlg.err { border-color: var(--err); }
.dlg.err .dlg-icon { background: var(--err); }
.dlg.ok .dlg-icon { background: var(--ok); }
.dlg-icon { width: 30px; height: 30px; display: grid; place-items: center; background: var(--color-accent); color: #fff; }
.dlg-title { font-family: var(--font-heading); font-weight: 600; font-size: 24px; line-height: 1.08; margin-top: 8px; }
.dlg-body { font-size: 14px; line-height: 1.45; margin-top: 6px; color: var(--color-neutral-800); white-space: pre-line; }
.dlg-code { margin-top: 10px; padding: 6px 8px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: var(--color-surface); word-break: break-all; }
.dlg-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.sheet-box { background: var(--color-bg); border-top: 1px solid rgba(29, 31, 32, .2); padding: 16px 14px 20px; animation: sheetUp .2s ease-out; max-height: 85dvh; overflow-y: auto; }

.toast {
  position: fixed; left: 14px; right: 14px; bottom: 84px; z-index: 600; padding: 12px 14px;
  display: flex; align-items: center; gap: 10px; background: var(--field); color: var(--on-field);
  font-size: 14px; animation: fadeIn .15s ease; box-shadow: var(--shadow-md);
}
.toast.ok { background: var(--ok); }
.busy { position: fixed; inset: 0; z-index: 700; display: grid; place-items: center; background: rgba(242, 242, 243, .55); }
.spinner { width: 34px; height: 34px; border: 3px solid var(--color-accent-300); border-top-color: var(--color-accent-700); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
