/* FilmCheckApp — Lager-taugliches UI
   Designprinzipien:
   - Alles groß, hoher Kontrast, für Werker mit Arbeitshandschuhen
   - Volle Fläche für Scan-Kamera
   - Signalfarben (grün/rot/gelb) riesig und eindeutig
   - System-Fonts → schnelle Ladezeit, keine externen Fonts
*/

:root {
  --brand:  #0d4b9e;
  --brand-dark: #0a3a7a;
  --green:  #1b7f30;
  --green-bg: #e6f4ea;
  --red:    #c62828;
  --red-bg: #fdecea;
  --yellow: #f9a825;
  --yellow-bg: #fff7e0;
  --bg:     #f5f6f8;
  --ink:    #17242e;
  --muted:  #5e6b78;
  --line:   #dfe3e8;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.35;
  min-height: 100vh;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- TOP BAR ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--brand);
  color: white;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.3px;
}
.brand .logo { font-size: 22px; }
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-name {
  font-size: 13px;
  opacity: 0.95;
  font-weight: 500;
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-name.hidden { display: none; }
.btn-logout {
  background: rgba(255,255,255,.15);
  border: 0;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.btn-logout.hidden { display: none; }
.btn-logout:active { background: rgba(255,255,255,.3); }
.step-indicator {
  font-size: 13px;
  opacity: 0.9;
  background: rgba(255,255,255,.15);
  padding: 4px 10px;
  border-radius: 20px;
}

/* ---------- LOGIN ---------- */
#screen-login { justify-content: center; align-items: center; }
.login-wrap {
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  background: white;
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.login-wrap .screen-title { margin-top: 0; text-align: center; }
.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 18px;
}
.login-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}
.login-form input {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 16px;
}
.login-form input:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
}
.login-error {
  background: var(--red-bg);
  color: var(--red);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
}
.login-error.hidden { display: none; }

/* ---------- SCREEN ---------- */
.screen {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.screen.hidden { display: none; }
.screen-title {
  font-size: 22px;
  margin: 4px 0 0;
  font-weight: 600;
}
.screen-hint {
  font-size: 14px;
  color: var(--muted);
  margin: 0;
}
.screen-hint code {
  background: #edf0f3;
  padding: 1px 6px;
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 13px;
}

/* ---------- SCANNER ---------- */
.scanner-wrap {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  max-height: 50vh;    /* verhindert dass html5-qrcode die Seite sprengt */
  box-shadow: var(--shadow);
}
.scanner-video {
  width: 100%;
  height: 100%;
  display: block;
  position: relative;
}
/* html5-qrcode injiziert ein <video> direkt in den Container — wir zwingen es korrekt zu rendern */
.scanner-video video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  display: block;
}
/* Das eingebaute Border-Highlight von html5-qrcode ausblenden */
#qr-shaded-region { display: none !important; }

/* Debug-Overlay: zeigt erkannte Codes, die nicht zum Format passen */
.scan-debug {
  position: absolute;
  left: 8px; right: 8px; bottom: 8px;
  padding: 8px 12px;
  background: rgba(0,0,0,.75);
  color: #ffe082;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 12px;
  border-radius: 8px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
  word-break: break-all;
}
.scan-debug.visible { opacity: 1; }
/* Weißer Rahmen passend zum schmalen Scan-Streifen (ca. 18% Höhe, 95% Breite) */
.scanner-overlay {
  position: absolute;
  left: 2.5%;
  right: 2.5%;
  top: 41%;
  bottom: 41%;
  border: 2px solid rgba(255,255,255,.9);
  border-radius: 6px;
  pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.35);
}

/* Rote Ziel-Linie in der Mitte — wie bei Industrie-Handscannern */
.scanner-wrap::after {
  content: '';
  position: absolute;
  left: 5%;
  right: 5%;
  top: 50%;
  height: 2px;
  background: rgba(255, 40, 40, 0.95);
  box-shadow: 0 0 6px rgba(255, 40, 40, 0.8);
  transform: translateY(-1px);
  pointer-events: none;
  z-index: 5;
}

/* ---------- BOM-LIST ---------- */
.material-info {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 14px;
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.material-info .label { color: var(--muted); font-size: 13px; }
.material-info .material-code {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-weight: 700;
  font-size: 17px;
}

.bom-list {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.bom-list .bom-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
}
.bom-list .bom-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.bom-list .bom-row:last-child { border-bottom: 0; }
.bom-list .bom-row .descr { color: var(--muted); font-size: 12px; }
.bom-list .bom-row .code {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-weight: 600;
  font-size: 13px;
}
.bom-list .bom-row .qty {
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- MANUAL INPUT ---------- */
.manual-input details { font-size: 14px; }
.manual-input summary {
  color: var(--brand);
  cursor: pointer;
  padding: 6px 0;
}
.manual-input form {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.manual-input input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 16px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
}
.manual-input button {
  padding: 12px 18px;
  background: var(--brand);
  color: white;
  border: 0;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- RESULT ---------- */
#screen-result { justify-content: center; }

.result-card {
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  box-shadow: var(--shadow);
  color: white;
  margin: 0 auto;
  width: 100%;
}
.result-card.green  { background: var(--green); }
.result-card.red    { background: var(--red); }
.result-card.yellow { background: var(--yellow); color: #3b2c00; }

.result-icon {
  font-size: 96px;
  line-height: 1;
  margin-bottom: 8px;
}
.result-title {
  font-size: 32px;
  margin: 0;
  font-weight: 800;
  letter-spacing: 0.5px;
}
.result-subtitle {
  font-size: 16px;
  margin: 6px 0 18px;
  opacity: 0.95;
}

.result-detail {
  background: rgba(255,255,255,.16);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: left;
  font-size: 14px;
}
.result-card.yellow .result-detail { background: rgba(0,0,0,.08); }
.result-detail .row {
  display: flex;
  gap: 8px;
  padding: 3px 0;
}
.result-detail .row.hidden { display: none; }
.result-detail .k { min-width: 120px; opacity: 0.9; }
.result-detail .v {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-weight: 600;
  word-break: break-all;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

/* ---------- BUTTONS ---------- */
.btn-primary, .btn-secondary {
  padding: 16px;
  border-radius: var(--radius);
  border: 0;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  min-height: 56px; /* gut mit Arbeitshandschuhen bedienbar */
}
.btn-primary {
  background: var(--brand);
  color: white;
}
.btn-primary:active { background: var(--brand-dark); }

.btn-secondary {
  background: white;
  color: var(--brand);
  border: 2px solid var(--brand);
}

/* ---------- FOOTER ---------- */
.footer {
  text-align: center;
  padding: 12px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--line);
  background: white;
}
.footer a { color: var(--brand); text-decoration: none; }

/* ---------- ACCESSIBILITY / SHAKE ---------- */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.result-card.red { animation: shake 0.3s ease-in-out; }
