:root {
  --bg: #0e1116;
  --bg-2: #151a21;
  --panel: rgba(22, 27, 34, 0.92);
  --panel-brd: rgba(255, 255, 255, 0.09);
  --txt: #e8edf3;
  --muted: #93a1b1;
  --accent: #f0b429;
  --accent-ink: #1a1200;
  --danger: #d9534f;
  --radius: 14px;
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

/* [hidden] muss jedes display der Klasse schlagen */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(1200px 820px at 50% 26%, #1c2531 0%, #12171e 45%, #0b0e13 100%);
  color: var(--txt);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app { position: fixed; inset: 0; }
#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Topbar ---------- */
.topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 12px;
  background: linear-gradient(to bottom, rgba(14, 17, 22, 0.92), rgba(14, 17, 22, 0));
  pointer-events: none;
}
.topbar .ident { pointer-events: auto; }
.topbar .tools { display: flex; gap: 8px; margin-inline-start: auto; pointer-events: auto; }
.line1 { display: flex; align-items: baseline; gap: 8px; }
.code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px; letter-spacing: 0.08em;
  color: var(--accent);
  border: 1px solid rgba(240, 180, 41, 0.45);
  border-radius: 6px; padding: 2px 6px;
}
.rev { font-size: 11px; color: var(--muted); }
h1 { font-size: 19px; line-height: 1.15; margin: 6px 0 2px; font-weight: 650; }
.machine { margin: 0; font-size: 12px; color: var(--muted); }

.icon-btn {
  min-width: 44px; min-height: 44px;
  display: grid; place-items: center;
  background: var(--panel); color: var(--txt);
  border: 1px solid var(--panel-brd); border-radius: 12px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  backdrop-filter: blur(8px);
}
.icon-btn:active { transform: scale(0.97); }
.icon-btn:disabled { opacity: 0.4; cursor: default; }

.chip-demo {
  position: absolute; right: 16px; top: calc(env(safe-area-inset-top, 0px) + 74px);
  font-size: 10px; letter-spacing: 0.14em; font-weight: 700;
  color: #ffd479; border: 1px dashed rgba(240, 180, 41, 0.5);
  border-radius: 6px; padding: 3px 6px; opacity: 0.85;
}

/* ---------- Startansicht ---------- */
.welcome {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 72px 24px; text-align: center;
  pointer-events: none;
}
.welcome h1 { margin: 0; font-size: clamp(26px, 6vw, 38px); }
.welcome p { margin: 12px 0 24px; color: var(--muted); font-size: 15px; line-height: 1.5; }
.scan-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 48px; padding: 0 20px; pointer-events: auto;
  color: var(--accent-ink); background: var(--accent); border: 0; border-radius: 11px;
  font: inherit; font-size: 15px; font-weight: 650; cursor: pointer;
}
.scan-btn:disabled { opacity: 0.55; cursor: default; }
.scan-btn:focus-visible { outline: 2px solid var(--txt); outline-offset: 4px; }

/* ---------- Hint (verschwindet bei erster Interaktion) ---------- */
.hint {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 148px);
  background: rgba(14, 17, 22, 0.82); color: var(--txt);
  border: 1px solid var(--panel-brd); border-radius: 999px;
  padding: 9px 16px; font-size: 13px; white-space: nowrap;
  backdrop-filter: blur(8px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.hint.gone { opacity: 0; transform: translate(-50%, 8px); pointer-events: none; }

/* ---------- Loader ---------- */
.loader {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center;
  gap: 14px; background: var(--bg); z-index: 40;
}
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.15); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader p { margin: 0; font-size: 13px; color: var(--muted); }

.model-fallback {
  position: absolute; top: calc(env(safe-area-inset-top, 0px) + 98px);
  left: 16px; right: 16px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
}
.model-fallback p { margin: 0; font-size: 14px; color: var(--muted); }

/* ---------- Teil-Karte ---------- */
.card {
  position: absolute; left: 12px; right: 12px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 132px);
  background: var(--panel); border: 1px solid var(--panel-brd);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px 12px;
  backdrop-filter: blur(14px);
  animation: rise 0.22s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.card-close {
  position: absolute; right: 8px; top: 6px;
  background: none; border: 0; color: var(--muted);
  font-size: 24px; line-height: 1; padding: 8px 10px; cursor: pointer;
}
.card-head { display: flex; gap: 12px; align-items: flex-start; padding-right: 26px; }
.pos {
  flex: 0 0 auto; min-width: 34px; height: 34px;
  display: grid; place-items: center;
  background: rgba(240, 180, 41, 0.14); color: var(--accent);
  border: 1px solid rgba(240, 180, 41, 0.35); border-radius: 9px;
  font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums;
}
.card h2 { font-size: 16px; margin: 2px 0 2px; font-weight: 640; line-height: 1.25; }
#card-id { margin: 0; font-size: 11px; }

.orderbox {
  margin-top: 12px; padding: 10px 12px;
  background: rgba(240, 180, 41, 0.08);
  border: 1px solid rgba(240, 180, 41, 0.28); border-radius: 11px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.orderbox-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: #d8c48c; width: 100%; }
.order {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 22px; letter-spacing: 0.02em; color: #ffd985; flex: 1 1 auto;
  user-select: all;
}
.order.missing { color: var(--muted); font-size: 17px; }
.note { margin: 10px 0 0; font-size: 12.5px; color: #c7d2de; border-left: 2px solid var(--accent); padding-left: 9px; }
.card-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; }

.ghost-btn {
  background: transparent; color: var(--txt);
  border: 1px solid var(--panel-brd); border-radius: 9px;
  padding: 9px 12px; font-size: 12.5px; cursor: pointer; min-height: 40px;
}
.ghost-btn:active { background: rgba(255, 255, 255, 0.06); }

/* ---------- Dock ---------- */
.dock {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(env(safe-area-inset-bottom, 0px) + 12px);
  background: linear-gradient(to top, rgba(14, 17, 22, 0.96), rgba(14, 17, 22, 0.55) 70%, rgba(14, 17, 22, 0));
  display: grid; gap: 10px;
}
.slider-row { display: flex; align-items: center; gap: 12px; }
.slider-row label { font-size: 12.5px; color: var(--muted); min-width: 64px; }
output { font-size: 12.5px; color: var(--txt); min-width: 42px; text-align: right; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  flex: 1; height: 34px; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(to right, var(--accent) var(--fill, 0%), rgba(255, 255, 255, 0.16) var(--fill, 0%));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 26px; height: 26px; margin-top: -10px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.16); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }

.btn-row { display: flex; gap: 10px; }
.btn {
  flex: 1; min-height: 46px; border-radius: 11px; cursor: pointer;
  background: rgba(255, 255, 255, 0.07); color: var(--txt);
  border: 1px solid var(--panel-brd); font-size: 13.5px; font-weight: 550;
}
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:active:not(:disabled) { background: rgba(255, 255, 255, 0.13); }

/* ---------- Stückliste ---------- */
.sheet {
  position: absolute; inset: auto 0 0 0;
  max-height: 78%;
  background: var(--bg-2); border-top: 1px solid var(--panel-brd);
  border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
  padding: 14px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
  display: flex; flex-direction: column; gap: 10px;
  animation: rise 0.24s ease; z-index: 30;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet h2 { font-size: 15px; margin: 0; font-weight: 640; }
#search {
  width: 100%; min-height: 44px; padding: 10px 12px;
  background: rgba(255, 255, 255, 0.06); color: var(--txt);
  border: 1px solid var(--panel-brd); border-radius: 10px; font-size: 14px;
}
#search::placeholder { color: var(--muted); }
.partlist { list-style: none; margin: 0; padding: 0 4px 0 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.partlist li {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  cursor: pointer; min-height: 48px;
}
.partlist li:hover { background: rgba(255, 255, 255, 0.04); }
.partlist .lbl { flex: 1; font-size: 13.5px; line-height: 1.3; }
.partlist .no {
  font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; color: #ffd985;
  white-space: nowrap; padding-right: 10px;
}
.partlist .no.missing { color: var(--muted); }

/* ---------- QR-Scanner ---------- */
.scanner {
  width: min(460px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  padding: 16px;
  background: var(--bg-2);
  color: var(--txt);
  border: 1px solid var(--panel-brd);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.scanner::backdrop { background: rgba(0, 0, 0, 0.66); }
.scanner h2 { margin: 0; font-size: 16px; }
.scanner video {
  display: block;
  width: 100%;
  max-height: 52dvh;
  margin-top: 12px;
  background: var(--bg);
  border-radius: 9px;
  object-fit: contain;
}
.scanner p { margin: 12px 0 0; font-size: 14px; color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 200px);
  transform: translateX(-50%);
  background: rgba(240, 180, 41, 0.95); color: var(--accent-ink);
  font-size: 13px; font-weight: 600; padding: 10px 16px; border-radius: 999px;
  box-shadow: var(--shadow); z-index: 50;
}

/* ---------- Desktop ---------- */
@media (min-width: 820px) {
  .card { left: auto; right: 20px; bottom: 128px; width: 380px; }
  .dock { padding-left: 24px; padding-right: 24px; }
  .slider-row { max-width: 620px; }
  .btn-row { max-width: 620px; }
  .sheet { left: auto; right: 20px; bottom: 128px; width: 420px; max-height: 62%; border-radius: 16px; border: 1px solid var(--panel-brd); }
  .hint { bottom: 128px; }
  h1 { font-size: 22px; }
}
