/**
 * Styles — ONE Einlagen-Scanner
 * Uses CSS custom properties (tokens) from tokens.css + tokens-{brand}.css
 */

/* ============================================
   BASE
   ============================================ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  /* Use dvh (dynamic viewport height) so browser chrome is excluded on mobile.
     Falls back to svh then vh for older browsers. */
  height: 100svh;
  height: 100dvh;
  font-family: var(--font-family-base);
  -webkit-font-smoothing: antialiased;
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* ============================================
   SHARED FLOW COMPONENTS
   ============================================ */

/* Full-height flex page used by landing, prepare, explain */
.landing-page,
.flow-page {
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  overflow: hidden;
}

/* Slim header with back button */
.flow-header {
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-light);
}

/* Content area — no scroll, fits within viewport */
.flow-content {
  flex: 1;
  padding: 36px 28px 24px;
  overflow: hidden;
}

/* Sticky footer with CTA */
.flow-footer {
  padding: 16px 28px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
}

/* Page title */
.flow-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0 0 28px 0;
}

/* Back button */
.back-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  color: var(--text-primary);
  border-radius: 50%;
  transition: background 0.15s;
  flex-shrink: 0;
}
.back-btn:hover  { background: var(--bg-secondary); }
.back-btn svg    { width: 22px; height: 22px; }

/* ============================================
   BUTTONS
   ============================================ */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-family-base);
  font-size: 15px; font-weight: 600;
  border: none; cursor: pointer; text-decoration: none;
  transition: opacity 0.15s, background 0.15s;
  width: 100%;
}

.btn-primary {
  background: var(--button-bg);
  color: var(--button-text);
  height: 56px;
  border-radius: var(--radius-sm);
}
.btn-primary:hover:not(:disabled) { background: var(--button-hover-bg); }
.btn-primary:disabled {
  background: var(--button-disabled-bg);
  color: var(--button-disabled-text);
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  height: 52px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-light);
}
.btn-secondary:hover { background: var(--bg-tertiary); }

/* ============================================
   FORM ELEMENTS
   ============================================ */

.form-group   { margin-bottom: 20px; }

.form-label {
  display: block;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.form-input {
  width: 100%; height: 52px;
  padding: 0 16px;
  border: 1.5px solid var(--input-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-family-base);
  font-size: 16px;
  background: var(--input-bg);
  color: var(--input-text);
  transition: border-color 0.15s;
}
.form-input:focus { outline: none; border-color: var(--input-border-focus); }
.form-input::placeholder { color: var(--input-placeholder); }
.form-group + .btn, .form-group + a.btn { margin-top: 8px; }

.form-hint {
  font-size: 13px; color: var(--text-tertiary);
  margin-top: 10px; min-height: 1em;
}

/* ============================================
   WELCOME SCREEN (inside .landing-page)
   ============================================ */

.welcome-screen,
.name-screen {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden;
}

.welcome-content {
  flex: 1; padding: 52px 28px 28px;
  display: flex; flex-direction: column; justify-content: center;
}

.welcome-title {
  font-size: 34px; font-weight: 700;
  letter-spacing: -0.03em; line-height: 1.1;
  margin: 0 0 12px 0;
}

.welcome-desc {
  font-size: 16px; color: var(--text-secondary);
  line-height: 1.55; margin-bottom: 20px;
}

.welcome-intro {
  font-size: 14px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-tertiary);
  margin: 0 0 12px 0;
}

.welcome-steps {
  list-style: decimal; padding-left: 20px;
  margin: 0 0 20px 0; display: flex; flex-direction: column; gap: 12px;
}

.welcome-step {
  font-size: 15px; line-height: 1.5; color: var(--text-primary);
  padding-left: 4px;
}

.welcome-duration {
  font-size: 14px; color: var(--text-tertiary);
  margin: 0; font-style: italic;
}

.welcome-footer {
  padding: 20px 28px;
  padding-bottom: max(28px, env(safe-area-inset-bottom));
  flex-shrink: 0;
}

/* Name screen reuses flow-header + flow-content */
.name-screen .flow-header { display: flex; }
.name-screen .flow-content { display: flex; flex-direction: column; }

/* ============================================
   PREPARE PAGE
   ============================================ */

.prepare-hero {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 24px;
  background: var(--bg-secondary);
}
.prepare-hero img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  object-position: center 30%;
  display: block;
}

.checklist { list-style: none; padding: 0; margin: 0; }

.checklist-item {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 18px 0; border-bottom: 1px solid var(--border-light);
  font-size: 15px; font-weight: 500; line-height: 1.45;
  color: var(--text-primary);
}
.checklist-item:first-child { padding-top: 0; }
.checklist-item:last-child  { border-bottom: none; }

.checklist-icon {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--bg-secondary); border: 1.5px solid var(--border-light);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 1px;
}
.checklist-icon svg { width: 13px; height: 13px; stroke: var(--text-tertiary); }

/* ============================================
   ORIENTATION LOCK PAGE
   ============================================ */

.orient-content {
  align-items: center; text-align: center; gap: 20px;
  justify-content: center;
  display: flex; flex-direction: column;
}

.orient-icon {
  width: 84px; height: 126px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}

.orient-instruction {
  font-size: 16px; line-height: 1.55;
  color: var(--text-primary); margin: 0; max-width: 300px;
}

.orient-hint {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--bg-secondary); border-radius: var(--radius-md);
  padding: 14px 16px; max-width: 320px; text-align: left;
  font-size: 13px; color: var(--text-secondary); line-height: 1.5;
}

/* ============================================
   EXPLAIN PAGE
   ============================================ */

.explain-content {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start;
  padding: 20px 28px 16px; text-align: center; gap: 16px;
  overflow: hidden;
}

.explain-image {
  flex-shrink: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
}
.explain-image img {
  max-width: 100%; max-height: 40vh;
  width: auto; height: auto;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.10);
  display: block;
}

.explain-title {
  font-size: 20px; font-weight: 700;
  letter-spacing: -0.01em; line-height: 1.3;
  max-width: 300px; margin: 0;
}

.explain-subtitle {
  font-size: 14px; color: var(--text-secondary);
  line-height: 1.5; margin: 0; max-width: 280px;
}

.explain-alt-link {
  display: block;
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: underline;
  text-align: center;
  padding: 4px 0;
}

/* ============================================
   CAPTURE PAGE
   ============================================ */

body.capture { overflow: hidden; background: #000; }

.capture-page {
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--bg-primary);
}

/* Header: back + centred label + spacer */
.capture-header {
  height: 56px; background: var(--bg-primary);
  display: flex; align-items: center;
  padding: 0 8px; flex-shrink: 0;
  position: relative; z-index: 30;
  border-bottom: 1px solid var(--border-light);
}

.capture-label {
  position: absolute; left: 50%; transform: translateX(-50%);
  font-size: 15px; font-weight: 600;
  letter-spacing: -0.01em; color: var(--text-primary);
  pointer-events: none;
}

.capture-header-spacer { width: 40px; flex-shrink: 0; }

/* Camera fills remaining height */
.camera-area {
  flex: 1; position: relative;
  background: #0a0a0a; overflow: hidden;
}

#video {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  transform-origin: center center;
  object-fit: contain;
}
@media (orientation: portrait)  { #video { width: 100vw; height: auto; } }
@media (orientation: landscape) { #video { width: auto; height: 100%; } }

/* Overlay wrapper (libelle canvas + guide image) */
#overlay-wrapper {
  position: absolute; inset: 0;
  overflow: hidden;
  pointer-events: none; z-index: 3;
  /* Flexbox centers the guide image reliably regardless of image load timing */
  display: flex;
  align-items: center;
  justify-content: center;
}

#overlay-image {
  /* Flex item — parent handles centering; no absolute positioning needed */
  position: relative;
  width: 100%; height: auto;
  pointer-events: none;
  z-index: 1;
  opacity: 0.3;
}

#overlay {
  /* Canvas covers entire wrapper via absolute positioning over the flex item */
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none; z-index: 2;
}

/* Floating status pill */
.status-pill {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--status-bg);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: 10px 22px; border-radius: var(--radius-full);
  font-size: 14px; font-weight: 500; color: var(--status-text);
  white-space: nowrap; max-width: calc(100% - 40px);
  text-align: center; z-index: 20; pointer-events: none;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.2);
}

/* Controls strip below camera */
.capture-controls {
  background: var(--bg-primary);
  padding: 14px 28px;
  padding-bottom: max(18px, env(safe-area-inset-bottom));
  flex-shrink: 0;
}

/* Shutter button */
.shutter-btn {
  display: block; width: 100%; height: 60px;
  background: var(--shutter-bg-inactive);
  color: var(--shutter-text-inactive, var(--state-disabled-text));
  border: none; border-radius: 30px;
  font-family: var(--font-family-base);
  font-size: 15px; font-weight: 600; letter-spacing: 0.02em;
  cursor: not-allowed;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}
.shutter-btn.ready {
  background: var(--button-bg);
  color: var(--button-text);
  cursor: pointer;
  box-shadow: var(--shutter-shadow-ready);
}
.shutter-btn.ready:hover  { background: var(--button-hover-bg); }
.shutter-btn.ready:active { transform: scale(0.98); }

/* Landscape warning */
.orientation-overlay { display: none; }
@media screen and (orientation: landscape) {
  .orientation-overlay {
    display: flex; position: fixed; inset: 0;
    justify-content: center; align-items: center;
    background: var(--overlay-semi); z-index: var(--z-overlay);
    text-align: center; padding: var(--space-lg);
  }
  .overlay-box {
    color: var(--color-primary);
    font-size: var(--font-size-lg); font-weight: var(--font-weight-semibold);
  }
}

/* ============================================
   iOS PERMISSION MODAL
   ============================================ */

.ios-modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  display: none; align-items: flex-end;
  padding: 16px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.ios-modal-card {
  background: var(--bg-primary);
  border-radius: 20px;
  padding: 32px 28px;
  width: 100%; text-align: center;
}

.ios-modal-icon {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--bg-secondary);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 18px;
}
.ios-modal-icon svg { width: 26px; height: 26px; stroke: var(--text-primary); }

.ios-modal-title { font-size: 19px; font-weight: 700; margin-bottom: 10px; }

.ios-modal-text  {
  font-size: 15px; color: var(--text-secondary);
  line-height: 1.5; margin-bottom: 24px;
}

.ios-modal-skip {
  display: block; width: 100%;
  background: none; border: none;
  font-family: var(--font-family-base); font-size: 14px;
  color: var(--text-tertiary); cursor: pointer;
  padding: 12px 0 0;
}
.ios-modal-skip:hover { color: var(--text-primary); }

/* ============================================
   SUCCESS FLASH (between photos)
   ============================================ */

.success-flash {
  position: fixed; inset: 0;
  background: var(--bg-primary); z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.2s ease;
  pointer-events: none;
}
.success-flash svg { width: 72px; height: 72px; stroke: var(--color-success); }
.success-flash--visible { opacity: 1; }
.success-flash--out     { opacity: 0; }

/* ============================================
   PREVIEW PAGE
   ============================================ */

body.preview {
  min-height: 100vh; display: flex;
  align-items: center; justify-content: center;
  padding: var(--space-md);
}

.preview-page {
  width: 100%; max-width: 400px;
}

.preview-card { text-align: center; }

.preview-title {
  font-size: 22px; font-weight: 700;
  letter-spacing: -0.02em; margin-bottom: 12px;
}

.preview-status {
  font-size: 15px; color: var(--text-secondary);
  min-height: 3em; line-height: 1.5; margin-bottom: 28px;
}

.preview-image {
  max-width: 100%; border-radius: var(--radius-md);
  margin-bottom: 28px; box-shadow: var(--shadow-lg);
}

.loading-spinner {
  width: 36px; height: 36px;
  border: 2.5px solid var(--border-light);
  border-top-color: var(--color-primary);
  border-radius: 50%; margin: 0 auto 28px;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================
   COMPLETE PAGE
   ============================================ */

body.complete {
  min-height: 100vh; display: flex;
  align-items: center; justify-content: center;
  padding: var(--space-md);
}

.complete-page { width: 100%; max-width: 400px; }

.complete-card { text-align: center; }

.complete-checkmark {
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--color-success);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
}
.complete-checkmark svg { width: 28px; height: 28px; stroke: #fff; }

.complete-title {
  font-size: 24px; font-weight: 700;
  letter-spacing: -0.02em; margin-bottom: 10px;
}

.complete-message {
  font-size: 15px; color: var(--text-secondary);
  line-height: 1.55; margin-bottom: 28px;
}
