/* Scanner 2.0 – Design fortgeführt aus v1 (dunkles Anthrazit, Gelb-Akzent,
   Space Grotesk / Inter / IBM Plex Mono), ergänzt um Verarbeitungs-Overlay,
   Update-Hinweis und Debug-Panel. */

:root {
  --safe-top: max(14px, env(safe-area-inset-top));
  --chrome-top: calc(var(--safe-top) + 58px);   /* reservierte Höhe der Kopfleiste */
  --bg: #1A1D1E;
  --surface: #24282A;
  --surface-2: #2C3133;
  --line: #33383A;
  --text: #EDEDED;
  --muted: #8A8F91;
  --accent: #F2B705;
  --accent-dim: #7A5E03;
  --success: #34C77B;
  --danger: #E5484D;
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font-body);
  overscroll-behavior: none;
  user-select: none;
}

.view {
  position: fixed; inset: 0;
  display: none;
  background: var(--bg);
}
.view.active { display: block; }

/* ---------- Top / bottom chrome ---------- */
.top-bar {
  position: absolute; top: 0; left: 0; right: 0;
  height: var(--chrome-top);
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--safe-top) 16px 0;
  background: rgba(26,29,30,0.97);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}
.brand {
  font-family: var(--font-display); font-weight: 700; font-size: 18px;
  letter-spacing: 0.06em;
}
.brand-accent { color: var(--accent); }
.brand-powered {
  font-family: var(--font-mono); font-weight: 500; font-size: 9px;
  letter-spacing: 0.02em; vertical-align: sub; color: var(--muted);
  margin-left: 3px; text-transform: none;
}
.brand-btn {
  -webkit-appearance: none; appearance: none;
  background: none; border: none; padding: 0; margin: 0;
  cursor: pointer; text-align: left; color: inherit; font: inherit;
}
.view-title { font-family: var(--font-mono); font-size: 13px; color: var(--muted); }

.top-bar-actions { display: flex; gap: 10px; }

.icon-btn {
  position: relative;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(36,40,42,0.8);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:disabled { opacity: 0.35; }
.icon-btn.active { background: var(--accent); color: #1A1D1E; border-color: var(--accent); }
.tray-count {
  position: absolute; top: -4px; right: -4px;
  background: var(--accent); color: #1A1D1E;
  font-family: var(--font-mono); font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}

.text-btn {
  background: none; border: none; color: var(--text);
  font-family: var(--font-body); font-size: 15px; font-weight: 500;
  padding: 6px 4px;
}
.text-btn.accent { color: var(--accent); font-weight: 600; }

.mode-toggle {
  display: flex; gap: 2px;
  background: rgba(36,40,42,0.85);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 3px;
}
.mode-opt {
  border: none; background: none; color: var(--muted);
  font-family: var(--font-mono); font-size: 11.5px; letter-spacing: 0.02em;
  padding: 7px 12px; border-radius: 16px;
}
.mode-opt.active { background: var(--accent); color: #1A1D1E; font-weight: 600; }

/* ---------- Start-Ansicht ---------- */
.start-wrap {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  gap: 16px; padding: calc(var(--chrome-top) + 7vh) 24px 24px;
  text-align: center;
}
.start-brand {
  font-family: var(--font-display); font-weight: 700; font-size: 40px;
  letter-spacing: 0.06em; margin-bottom: 4px;
}
.start-sub {
  font-family: var(--font-body); color: var(--muted); font-size: 14.5px;
  max-width: 280px; margin: 0 0 18px;
}
.start-btn {
  width: 100%; max-width: 320px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 15px 18px; border-radius: 12px;
  font-family: var(--font-body); font-weight: 600; font-size: 15px;
  border: 1px solid var(--line);
}
.start-btn.primary { background: var(--accent); color: #1A1D1E; border: none; }
.start-btn.secondary { background: var(--surface); color: var(--text); }

/* ---------- Scanner-Illustration auf dem Startbildschirm ---------- */
.start-art {
  width: min(74vw, 310px);
  height: auto;
  margin-top: 5vh;
  flex-shrink: 1;
  min-height: 0;
}
/* dezenter Scan-Balken, der über das Papier wandert */
.start-art .scan-beam {
  animation: scan-sweep 3.4s ease-in-out infinite alternate;
}
@keyframes scan-sweep {
  from { transform: translateX(0); }
  to   { transform: translateX(106px); }
}
@media (prefers-reduced-motion: reduce) {
  .start-art .scan-beam { animation: none; }
}
/* auf sehr kleinen Bildschirmen lieber Platz für die Knöpfe lassen */
@media (max-height: 620px) {
  .start-art { display: none; }
}

.engine-status {
  font-family: var(--font-mono); font-size: 11.5px; color: var(--muted);
  margin-top: 6px;
}

/* ---------- Einstellungen ---------- */
.settings-body {
  position: absolute; top: var(--chrome-top); bottom: 0; left: 0; right: 0;
  overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
}
.settings-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.settings-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.settings-label {
  font-family: var(--font-mono); font-size: 11.5px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.settings-value { font-size: 14px; font-weight: 500; text-align: right; }
.settings-actions-row { display: flex; justify-content: flex-end; gap: 20px; }
.danger-text { color: var(--danger); background: none; border: none; }
.settings-version {
  margin-top: 8px; text-align: center;
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
  padding: 10px;
}

/* ---------- Info / Anleitung ---------- */
.info-body {
  position: absolute; top: var(--chrome-top); bottom: 0; left: 0; right: 0;
  overflow-y: auto; padding: 20px 18px;
}
.info-intro { color: var(--muted); font-size: 13.5px; line-height: 1.5; margin: 0 0 20px; }
.info-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 20px; }
.info-steps li { display: flex; gap: 14px; align-items: flex-start; }
.info-num {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #1A1D1E;
  font-family: var(--font-mono); font-weight: 700; font-size: 12.5px;
  display: flex; align-items: center; justify-content: center;
}
.info-steps strong { display: block; font-size: 14.5px; margin-bottom: 3px; }
.info-steps p { margin: 0; font-size: 13.5px; color: var(--muted); line-height: 1.45; }

/* ---------- Drive-Browser: Cards (untereinander, Vorschaubild rechts) ---------- */
.drive-card-grid {
  display: flex; flex-direction: column; gap: 10px;
  padding: 12px 14px max(14px, env(safe-area-inset-bottom));
}
.drive-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px;
  display: flex; flex-direction: row; align-items: center; gap: 12px;
}
.drive-card-main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.drive-card-thumb {
  width: 54px; height: 70px; flex-shrink: 0;
  object-fit: cover; object-position: top;
  border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface-2);
}
.drive-card:active { background: var(--surface-2); }
.drive-card-icon { color: var(--accent); display: flex; }
.drive-card.is-folder .drive-card-icon { color: var(--accent); }
.drive-card:not(.is-folder) .drive-card-icon { color: var(--muted); }
.drive-card-name {
  font-size: 13.5px; font-weight: 500; line-height: 1.3;
  overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  word-break: break-word;
}
.drive-card-date {
  font-family: var(--font-mono); font-size: 10.5px; color: var(--muted);
}

/* ---------- Inline-Ladeanzeige (Listen, Vorschauen) ---------- */
.inline-loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 40px 18px;
  font-family: var(--font-mono); font-size: 12.5px; color: var(--muted);
}

/* ---------- Drehen-Button in der Zuschnitt-Ansicht ---------- */
.crop-rotate-btn {
  position: absolute; right: 16px;
  bottom: max(76px, calc(env(safe-area-inset-bottom) + 60px));
  z-index: 6;
  width: 52px; height: 52px;
}

/* ---------- Seiten-Vorschau (Ablage) ---------- */
.page-viewer {
  position: fixed; inset: 0; z-index: 50;
  background: #0d0f10;
  display: flex; flex-direction: column;
}
.page-viewer-body {
  position: absolute; top: var(--chrome-top); bottom: 0; left: 0; right: 0;
  overflow: auto;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 8px;
}
.page-viewer-body img { max-width: 100%; height: auto; }

/* ---------- Ordner-Browser ---------- */
.folder-list {
  position: absolute; top: var(--chrome-top); bottom: 0; left: 0; right: 0;
  overflow-y: auto;
}
.folder-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  font-size: 14.5px;
}
.folder-item.up { color: var(--muted); }
.folder-item .folder-icon { flex-shrink: 0; color: var(--accent); display: flex; }
.file-row-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-empty, .folder-loading {
  padding: 28px 18px; color: var(--muted);
  font-family: var(--font-mono); font-size: 13px; text-align: center;
}

/* ---------- Datei-Vorschau ---------- */
.file-preview-body {
  position: absolute; top: var(--chrome-top); bottom: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: center;
  background: #0d0f10;
}
.file-preview-body img { max-width: 100%; max-height: 100%; object-fit: contain; }

.pdf-viewer { width: 100%; height: 100%; display: flex; flex-direction: column; }
.pdf-canvas-wrap {
  flex: 1; overflow: auto; background: #525659;
  display: flex; align-items: flex-start; justify-content: center; padding: 12px;
}
.pdf-canvas-wrap canvas { box-shadow: 0 2px 10px rgba(0,0,0,0.4); }
.pdf-pager {
  display: flex; align-items: center; justify-content: center; gap: 18px;
  padding: 10px; background: var(--surface); border-top: 1px solid var(--line);
}
.pdf-page-info { font-family: var(--font-mono); font-size: 13px; color: var(--muted); min-width: 60px; text-align: center; }

/* ---------- Zuschnitt & Feinschliff ---------- */
.crop-wrap, .edit-wrap {
  position: absolute; top: var(--chrome-top); bottom: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: center; background: #0d0f10;
}
.edit-wrap { bottom: 232px; }
#cropCanvas { max-width: 100%; max-height: 100%; touch-action: none; }
#editCanvas { max-width: 100%; max-height: 100%; }

.crop-hint {
  position: absolute; left: 16px; right: 84px;
  bottom: max(18px, env(safe-area-inset-bottom));
  text-align: center;
  font-family: var(--font-mono); font-size: 12px; color: var(--accent);
  background: rgba(26,29,30,0.85); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 12px;
  z-index: 6;
}

.edit-busy {
  position: absolute; top: 12px; right: 16px;
  z-index: 6;
}

.edit-controls {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(26,29,30,0.92);
  border-top: 1px solid var(--line);
  padding: 14px 18px max(18px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
  z-index: 5;
}
.edit-controls .mode-toggle { align-self: center; }
.slider-row { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.slider-row span { width: 78px; flex-shrink: 0; font-family: var(--font-mono); font-size: 11.5px; }
.slider-row input[type=range] { flex: 1; accent-color: var(--accent); }
.toggle-row { display: flex; gap: 22px; justify-content: center; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.checkbox-row input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
.checkbox-row input[type=checkbox]:disabled { opacity: 0.4; }
#btnRotate { align-self: center; }

/* ---------- Dokumentenablage ---------- */
.tray-grid {
  position: absolute; top: var(--chrome-top); bottom: 190px; left: 0; right: 0;
  overflow-y: auto;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  padding: 10px 16px;
}
.tray-item {
  position: relative; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--line); background: var(--surface);
  aspect-ratio: 3/4;
}
.tray-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tray-item .page-no {
  position: absolute; bottom: 4px; left: 6px;
  font-family: var(--font-mono); font-size: 10px; color: var(--text);
  background: rgba(0,0,0,0.5); padding: 1px 5px; border-radius: 4px;
}
.tray-item .del-btn {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,0.55); color: var(--text); border: none;
  font-size: 13px; line-height: 1;
}

.tray-actions {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 14px 18px max(18px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px;
}
.doc-name-input {
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text); border-radius: 8px; padding: 10px 12px;
  font-family: var(--font-body); font-size: 14px;
  user-select: text;
}
.primary-btn {
  background: var(--accent); color: #1A1D1E; border: none;
  border-radius: 8px; padding: 13px; font-weight: 700; font-size: 14.5px;
  font-family: var(--font-body);
}
.primary-btn:disabled { background: var(--surface-2); color: var(--muted); }
.upload-status { font-family: var(--font-mono); font-size: 12px; color: var(--muted); min-height: 16px; }
.upload-status.ok { color: var(--success); }
.upload-status.err { color: var(--danger); }

/* ---------- Anleitung-Modal (Google Drive verbinden) ---------- */
.guide-modal {
  position: fixed; inset: 0; z-index: 52;
  background: var(--bg);
}
.guide-body {
  position: absolute; top: var(--chrome-top); bottom: 0; left: 0; right: 0;
  overflow-y: auto;
  padding: 18px 18px max(24px, env(safe-area-inset-bottom));
}
.guide-intro {
  margin: 0 0 22px; color: var(--muted); font-size: 13.5px; line-height: 1.5;
}
.guide-step { margin-bottom: 28px; }
.guide-step-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.guide-step-head p { margin: 2px 0 0; font-size: 14px; line-height: 1.45; }
.guide-step img {
  display: block; width: 100%; max-width: 400px; margin: 0 auto;
  border: 1px solid var(--line); border-radius: 12px;
}

/* ---------- Auswahl-Modal (Ablage) ---------- */
.action-sheet-backdrop {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(13,15,16,0.6);
  display: flex; align-items: flex-end; justify-content: center;
}
.action-sheet {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line); border-bottom: none;
  border-radius: 14px 14px 0 0;
  padding: 14px 16px max(16px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
}
.action-sheet-title {
  text-align: center; font-family: var(--font-mono); font-size: 12px;
  color: var(--muted); padding-bottom: 4px;
}
.action-sheet-btn {
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text); border-radius: 10px;
  padding: 13px; font-family: var(--font-body); font-size: 15px; font-weight: 500;
}
.action-sheet-btn.danger { color: var(--danger); }
.action-sheet-btn.cancel { background: none; border: none; color: var(--muted); margin-top: 2px; }

/* ---------- Teilen-Button in der Datei-Vorschau ---------- */
.share-fab {
  position: absolute; right: 16px;
  bottom: max(76px, calc(env(safe-area-inset-bottom) + 64px));
  width: 52px; height: 52px;
  background: var(--accent); color: #1A1D1E; border-color: var(--accent);
  z-index: 6;
}

/* Dezent roter Löschen-Button links neben dem Teilen-Button */
.delete-fab {
  position: absolute; right: 82px;
  bottom: max(76px, calc(env(safe-area-inset-bottom) + 64px));
  width: 52px; height: 52px;
  background: var(--surface); color: var(--danger);
  border: 1px solid rgba(229,72,77,0.55);
  z-index: 6;
}

/* Kleines ✕ am rechten Rand jeder Datei-Zeile */
.drive-card .card-del-btn {
  flex-shrink: 0;
  width: 28px; height: 28px; border-radius: 50%;
  background: rgba(13,15,16,0.65); color: var(--muted);
  border: 1px solid var(--line);
  font-size: 13px; line-height: 1; padding: 0;
}
.drive-card .card-del-btn:active { color: var(--danger); border-color: var(--danger); }

/* ---------- Upload-Fortschritt ---------- */
.upload-progress {
  height: 4px; border-radius: 2px; overflow: hidden;
  background: var(--surface-2);
  position: relative;
}
.upload-progress-bar {
  position: absolute; top: 0; bottom: 0; width: 34%;
  border-radius: 2px; background: var(--accent);
  animation: progress-slide 1.1s ease-in-out infinite;
}
@keyframes progress-slide {
  0% { left: -34%; }
  100% { left: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .upload-progress-bar { animation-duration: 2.2s; }
}

/* ---------- Impressum / Info ---------- */
.settings-imprint {
  text-align: center; color: var(--muted);
  font-size: 11.5px; line-height: 1.55;
  padding: 0 10px 20px;
}
.settings-imprint p { margin: 0 0 12px; }
.settings-imprint a { color: var(--muted); }
.imprint-block strong { color: var(--muted); font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; }

.info-privacy {
  margin-top: 26px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  font-size: 13px; color: var(--muted); line-height: 1.5;
}
.info-privacy strong { color: var(--text); }
.info-privacy p { margin: 8px 0 0; }

/* ---------- Banner ---------- */
.drive-banner {
  position: fixed; left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom));
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; z-index: 20;
}
.update-banner {
  bottom: auto; top: calc(var(--chrome-top) + 10px);
  border-color: var(--accent-dim);
  z-index: 40;
}

/* ---------- Verarbeitungs-Overlay ---------- */
.processing-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(13,15,16,0.6);
  display: flex; align-items: center; justify-content: center;
}
.processing-card {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 22px 28px;
  font-family: var(--font-mono); font-size: 13px; color: var(--text);
  max-width: 84%;
  text-align: center;
}

.spinner {
  width: 26px; height: 26px; flex-shrink: 0;
  border-radius: 50%;
  border: 3px solid var(--surface-2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 1.6s; }
}

/* ---------- Eigene Dialoge (statt Browser-Popups) ---------- */
.dialog-backdrop {
  position: fixed; inset: 0; z-index: 95;
  background: rgba(13,15,16,0.65);
  display: flex; align-items: center; justify-content: center;
  padding: 28px;
}
.dialog-card {
  width: 100%; max-width: 340px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 20px 18px 14px;
}
.dialog-title {
  font-family: var(--font-display); font-weight: 700; font-size: 16px;
  margin-bottom: 8px;
}
.dialog-message { font-size: 14px; line-height: 1.5; color: var(--text); word-break: break-word; }
.dialog-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px;
}
.dialog-btn {
  background: none; border: none; border-radius: 8px;
  padding: 10px 14px; font-family: var(--font-body);
  font-size: 14.5px; font-weight: 600; color: var(--muted);
}
.dialog-btn.ok { background: var(--accent); color: #1A1D1E; }
.dialog-btn.ok.danger { background: var(--danger); color: #fff; }
.dialog-btn.hidden { display: none; }

/* ---------- Zurück-Geste-Hinweis ---------- */
.back-hint {
  position: fixed; left: 24px; right: 24px;
  bottom: max(90px, calc(env(safe-area-inset-bottom) + 78px));
  z-index: 90;
  text-align: center;
  background: var(--surface); border: 1px solid var(--accent-dim);
  border-radius: 10px; padding: 11px 14px;
  font-family: var(--font-mono); font-size: 12px; color: var(--text);
  pointer-events: none;
}

/* ---------- Debug-Panel ---------- */
.debug-panel {
  position: fixed; inset: 0; z-index: 80;
  background: #0d0f10;
  display: flex; flex-direction: column;
}
.debug-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono); font-size: 12px; color: var(--muted);
}
.debug-panel pre {
  flex: 1; overflow: auto; margin: 0;
  padding: 12px 14px max(12px, env(safe-area-inset-bottom));
  font-family: var(--font-mono); font-size: 10.5px; line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap; word-break: break-word;
  user-select: text;
}

.hidden { display: none !important; }
