/* DocuFlow — handgeschriebenes CSS, kein Build-Schritt.
   Palette als Custom Properties; hell ist die Basis, dunkel wird
   darübergelegt. Ein Umschalter setzt data-theme am <html>.
   Die Aufnahmeansicht ist bewusst immer dunkel — eine helle Oberfläche um ein
   Kamerabild blendet und verfälscht die Einschätzung der Belichtung. */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #e9edf1;
  --border: #dbe1e8;
  --border-strong: #c2cad6;
  --text: #151a21;
  --text-muted: #656e7c;
  --text-faint: #949daa;

  --accent: #0d8b7d;
  --accent-hover: #0a7568;
  --accent-soft: #dcf2ee;
  --accent-text: #ffffff;
  --danger: #cf4433;
  --danger-soft: #fbe6e3;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16,20,30,.06), 0 4px 14px rgba(16,20,30,.07);
  --shadow-lift: 0 10px 32px rgba(16,20,30,.22);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116;
    --surface: #161b22;
    --surface-2: #1e242e;
    --border: #262d38;
    --border-strong: #38414f;
    --text: #e7eaf0;
    --text-muted: #99a2b1;
    --text-faint: #6a7383;
    --accent: #2fd4bd;
    --accent-hover: #4ce0cb;
    --accent-soft: #10352f;
    --accent-text: #04211d;
    --danger: #ff6f5e;
    --danger-soft: #3a1c19;
    --shadow: 0 1px 2px rgba(0,0,0,.45), 0 4px 14px rgba(0,0,0,.35);
    --shadow-lift: 0 10px 32px rgba(0,0,0,.6);
  }
}
:root[data-theme="dark"] {
  --bg: #0e1116; --surface: #161b22; --surface-2: #1e242e;
  --border: #262d38; --border-strong: #38414f;
  --text: #e7eaf0; --text-muted: #99a2b1; --text-faint: #6a7383;
  --accent: #2fd4bd; --accent-hover: #4ce0cb; --accent-soft: #10352f;
  --accent-text: #04211d; --danger: #ff6f5e; --danger-soft: #3a1c19;
  --shadow: 0 1px 2px rgba(0,0,0,.45), 0 4px 14px rgba(0,0,0,.35);
  --shadow-lift: 0 10px 32px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }

/* ------------------------------------------------------------------ Gerüst */

.view { display: none; flex-direction: column; height: 100dvh; }
.view.is-active { display: flex; }

.bar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.bar h1 { font-size: 19px; margin: 0; letter-spacing: -.01em; }
.bar .spacer { flex: 1; }
.bar__sub { display: block; font-size: 12px; color: var(--text-muted); font-weight: 400; }

.scroll { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.pad { padding: 16px 14px calc(var(--safe-bottom) + 24px); }

/* ---------------------------------------------------------------- Schalter */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: var(--radius-sm); padding: 9px 14px; cursor: pointer;
  font-size: 15px; font-weight: 500; min-height: 42px;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn--danger:hover { background: var(--danger-soft); }
.btn--icon { padding: 0; width: 42px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
  border-radius: 999px; padding: 7px 14px; font-size: 14px; cursor: pointer;
  min-height: 38px; transition: all .12s;
}
.chip[aria-pressed="true"] {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent);
  font-weight: 600;
}

/* -------------------------------------------------------------- Bibliothek */

.docs { display: flex; flex-direction: column; gap: 10px; }
.doc {
  display: flex; align-items: center; gap: 13px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 11px; cursor: pointer;
  box-shadow: var(--shadow); text-align: left; width: 100%;
}
.doc:active { transform: scale(.995); }
.doc__thumb {
  width: 50px; height: 66px; flex: 0 0 auto; border-radius: 5px;
  background: var(--surface-2) center/cover no-repeat;
  border: 1px solid var(--border); overflow: hidden;
}
.doc__body { min-width: 0; flex: 1; }
.doc__title {
  font-weight: 600; font-size: 15.5px; margin: 0 0 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.doc__meta { font-size: 13px; color: var(--text-muted); }

.empty { text-align: center; padding: 56px 24px; color: var(--text-muted); }
.empty__mark { font-size: 42px; margin-bottom: 10px; opacity: .8; }
.empty h2 { font-size: 17px; color: var(--text); margin: 0 0 6px; }
.empty p { margin: 0 auto; max-width: 32ch; font-size: 14.5px; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--safe-bottom) + 18px);
  display: flex; align-items: center; gap: 9px;
  background: var(--accent); color: var(--accent-text);
  border: none; border-radius: 999px; padding: 15px 22px;
  font-size: 16px; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow-lift);
}
.fab:active { transform: scale(.96); }

/* ------------------------------------------------------------- Aufnahme */

.capture { background: #000; color: #fff; position: relative; }
.capture__stage { position: relative; flex: 1 1 auto; overflow: hidden; background: #000; }
.capture__stage video { width: 100%; height: 100%; object-fit: cover; display: block; }
.capture__overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.capture__top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 10px) 12px 26px;
  background: linear-gradient(rgba(0,0,0,.6), transparent);
}
.capture__top .btn {
  background: rgba(255,255,255,.14); border-color: transparent; color: #fff;
  backdrop-filter: blur(8px); min-height: 38px; font-size: 14px;
}
.capture__top .btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

.capture__hint {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  z-index: 2; background: rgba(0,0,0,.62); backdrop-filter: blur(8px);
  padding: 8px 15px; border-radius: 999px; font-size: 13.5px; white-space: nowrap;
  transition: opacity .2s;
}
.capture__hint--ready { background: rgba(13,139,125,.9); }

.capture__bottom {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: 16px 26px calc(var(--safe-bottom) + 16px); background: #000; gap: 12px;
}
.capture__side {
  width: 54px; height: 54px; border-radius: 14px; border: 1px solid rgba(255,255,255,.22);
  background: rgba(255,255,255,.08); color: #fff; font-size: 21px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.capture__side small { display: block; font-size: 9px; letter-spacing: .04em; }
.shutter {
  width: 74px; height: 74px; border-radius: 50%; border: 4px solid rgba(255,255,255,.85);
  background: #fff; cursor: pointer; flex: 0 0 auto; padding: 0;
  box-shadow: 0 0 0 3px rgba(0,0,0,.5) inset;
  transition: transform .08s;
}
.shutter:active { transform: scale(.92); }
.shutter[disabled] { opacity: .4; }

.badge-count {
  position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px;
  border-radius: 10px; background: var(--accent); color: var(--accent-text);
  font-size: 11px; font-weight: 700; display: flex; align-items: center;
  justify-content: center; padding: 0 5px;
}

.camera-error {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; padding: 32px;
  text-align: center; color: #dfe4ea; z-index: 3;
}
.camera-error p { max-width: 34ch; font-size: 14.5px; line-height: 1.5; margin: 0; }

/* -------------------------------------------------------------- Zuschnitt */

.crop { background: var(--bg); }
.crop__stage {
  position: relative; flex: 1 1 auto; overflow: hidden;
  background: #14171c; display: flex; align-items: center; justify-content: center;
  touch-action: none;
}
.crop__img { position: absolute; }
.crop__svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.crop__handle {
  position: absolute; width: 46px; height: 46px; margin: -23px 0 0 -23px;
  border-radius: 50%; cursor: grab; touch-action: none; z-index: 3;
}
.crop__handle::after {
  content: ''; position: absolute; inset: 15px; border-radius: 50%;
  background: var(--accent); border: 2.5px solid #fff;
  box-shadow: 0 1px 5px rgba(0,0,0,.5);
}
.crop__handle.is-active::after { inset: 12px; }
.crop__loupe {
  position: absolute; width: 116px; height: 116px; border-radius: 50%;
  border: 3px solid #fff; box-shadow: var(--shadow-lift); z-index: 4;
  display: none; pointer-events: none; overflow: hidden; background: #000;
}
.crop__loupe.is-on { display: block; }
.crop__bottom {
  flex: 0 0 auto; display: flex; gap: 9px; align-items: center;
  padding: 12px 14px calc(var(--safe-bottom) + 12px);
  background: var(--surface); border-top: 1px solid var(--border);
}
.crop__bottom .btn--primary { flex: 1; }

/* ------------------------------------------------------------ Dokumentansicht */

.doc-title {
  width: 100%; border: 1px solid transparent; background: transparent;
  font-size: 19px; font-weight: 600; padding: 5px 8px; margin: -5px -8px;
  border-radius: var(--radius-sm); min-width: 0;
}
.doc-title:focus { outline: none; border-color: var(--accent); background: var(--surface); }

.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 12px; }
.page {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.page img { display: block; width: 100%; aspect-ratio: 3/4; object-fit: contain; background: var(--surface-2); }
.page__no {
  position: absolute; top: 7px; left: 7px; background: rgba(0,0,0,.62); color: #fff;
  font-size: 11.5px; font-weight: 600; border-radius: 6px; padding: 2px 7px;
}
.page__tools { display: flex; border-top: 1px solid var(--border); }
.page__tools button {
  flex: 1; border: none; background: transparent; padding: 9px 0; cursor: pointer;
  color: var(--text-muted); font-size: 15px;
}
.page__tools button:hover { background: var(--surface-2); color: var(--text); }
.page__tools button:disabled { opacity: .3; pointer-events: none; }
.page__tools .is-danger:hover { background: var(--danger-soft); color: var(--danger); }

.section-label {
  font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-faint); margin: 0 0 9px;
}
.stack { display: flex; flex-direction: column; gap: 20px; }

.actionbar {
  flex: 0 0 auto; display: flex; gap: 9px;
  padding: 11px 14px calc(var(--safe-bottom) + 11px);
  background: var(--surface); border-top: 1px solid var(--border);
}
.actionbar .btn { flex: 1; }

/* ----------------------------------------------------------------- Sonstiges */

.sheet {
  position: fixed; inset: 0; z-index: 40; display: none;
  align-items: center; justify-content: center; padding: 22px;
  background: rgba(10,13,18,.55); backdrop-filter: blur(3px);
}
.sheet.is-open { display: flex; }
.sheet__box {
  background: var(--surface); border-radius: var(--radius); padding: 20px;
  max-width: 380px; width: 100%; box-shadow: var(--shadow-lift);
}
.sheet__box h2 { margin: 0 0 8px; font-size: 17px; }
.sheet__box p { margin: 0 0 18px; color: var(--text-muted); font-size: 14.5px; }
.sheet__row { display: flex; gap: 9px; justify-content: flex-end; }

.busy {
  position: fixed; inset: 0; z-index: 50; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 15px;
  background: rgba(10,13,18,.6); backdrop-filter: blur(3px); color: #fff;
}
.busy.is-on { display: flex; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.25); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .btn:active, .fab:active, .shutter:active { transform: none; }
}

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 84px);
  transform: translateX(-50%) translateY(14px); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 17px;
  border-radius: 999px; font-size: 14px; box-shadow: var(--shadow-lift);
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.is-on { opacity: 1; transform: translateX(-50%) translateY(0); }

.viewer {
  position: fixed; inset: 0; z-index: 45; display: none;
  background: rgba(8,10,14,.94); align-items: center; justify-content: center;
}
.viewer.is-open { display: flex; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer__close {
  position: absolute; top: calc(var(--safe-top) + 12px); right: 14px;
  background: rgba(255,255,255,.15); color: #fff; border: none;
  width: 40px; height: 40px; border-radius: 50%; font-size: 20px; cursor: pointer;
}

.hint { font-size: 13.5px; color: var(--text-muted); margin: 9px 0 0; }
.hint code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

.camera-error__mark { font-size: 34px; }
.bar__mid { font-size: 15px; font-weight: 600; }
