:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --hover: #f1f5f9;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --ki: #7c3aed;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --panel: #1a1e24; --text: #e5e7eb; --muted: #9ca3af;
    --border: #2b313a; --hover: #232932; --accent: #60a5fa; --accent-soft: #1e3a5f;
    --danger: #f87171; --warn: #fbbf24; --warn-soft: #3b2f12; --ki: #a78bfa; --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.muted { color: var(--muted); }

/* ---------- Anmeldung */
.auth-view {
  position: fixed; inset: 0; z-index: 200; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.auth-card {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 28px 24px; display: flex; flex-direction: column; gap: 12px;
}
.auth-logo { font-size: 40px; text-align: center; }
.auth-card h1 { margin: 0; text-align: center; font-size: 22px; }
.auth-card > p { margin: 0 0 4px; text-align: center; }
.auth-error { color: var(--danger); font-size: 13px; min-height: 0; }
.auth-error:empty { display: none; }
.btn.big { justify-content: center; padding: 10px 14px; font-size: 15px; }
.faceid-block { display: flex; flex-direction: column; gap: 10px; }
.faceid-block .or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.faceid-block .or::before, .faceid-block .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.faceid-btn { font-weight: 600; }
.auth-card .btn.big + .btn.big { margin-top: -2px; }

/* ---------- Kopfzeile */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.logo { font-weight: 650; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 1; min-width: 0; }
.search { flex: 1 0 200px; max-width: 560px; min-width: 0; }
@media (max-width: 1100px) and (min-width: 801px) {
  .topbar .btn-label { display: none; }  /* schmales Fenster: Knöpfe nur mit Symbol, damit die Suche Platz hat */
}
.menu-btn { display: none; }
.btn.camera-btn { display: none; }
.trash-mode .filterbar .check, .trash-mode #sort { display: none; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--panel);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: wait; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; border-radius: 6px;
  padding: 4px 8px; font-size: 16px; line-height: 1; color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.small { font-size: 14px; padding: 2px 6px; }

.user-menu { position: relative; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 210px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.15);
  padding: 4px; display: flex; flex-direction: column;
}
.dropdown button {
  border: 0; background: none; text-align: left; padding: 9px 12px; border-radius: 6px; cursor: pointer;
}
.dropdown button:hover { background: var(--hover); }

/* Tag-Filter neben der Suche */
.tag-filter { position: relative; }
.filter-count {
  background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700;
  padding: 0 6px; margin-left: 4px; line-height: 17px;
}
.tag-drop { left: 0; right: auto; width: 290px; padding: 10px; gap: 8px; max-height: min(480px, 70vh); }
.tag-drop .drop-head { font-size: 12px; font-weight: 600; color: var(--muted); }
.tag-drop .mode-row { display: flex; flex-direction: column; gap: 4px; font-size: 13px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.tag-checks { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.tag-checks label { padding: 6px 6px; border-radius: 6px; font-size: 14px; }
.tag-checks label:hover { background: var(--hover); }
.tag-checks .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--c); flex-shrink: 0; }
.tag-drop .drop-foot { display: flex; justify-content: space-between; gap: 8px; padding-top: 8px; border-top: 1px solid var(--border); }

/* ---------- Layout */
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 270px; flex-shrink: 0; overflow-y: auto; padding: 12px 10px;
  background: var(--panel); border-right: 1px solid var(--border);
}
.sidebar-backdrop { display: none; }
.main { flex: 1; overflow-y: auto; padding: 16px 22px 40px; position: relative; }

.side-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  padding: 10px 6px 6px;
}
.hint { font-size: 12px; color: var(--muted); padding: 4px 6px; margin: 0; }
.ki-status { margin-top: 10px; color: var(--ki); }

/* ---------- Ordnerbaum */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { padding-left: 14px; }
.tree-row {
  display: flex; align-items: center; gap: 4px; padding: 5px 6px; border-radius: 6px;
  cursor: pointer; user-select: none;
}
.tree-row:hover { background: var(--hover); }
.tree-row.active { background: var(--accent-soft); font-weight: 600; }
.tree-row.system .name { font-style: italic; }
.tree-row.drop-target { outline: 2px dashed var(--accent); background: var(--accent-soft); }
.tree-row .twisty { width: 16px; text-align: center; color: var(--muted); font-size: 10px; flex-shrink: 0; }
.tree-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .count { font-size: 12px; color: var(--muted); }

/* ---------- Tags */
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 6px; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 550; border: 1px solid transparent; white-space: nowrap;
  background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c);
}
.tag-list .tag { cursor: pointer; }
.tag.on { background: var(--c); color: #fff; }
.tag .edit, .tag .x { cursor: pointer; opacity: .6; font-size: 11px; padding: 0 2px; }
.tag .edit:hover, .tag .x:hover { opacity: 1; }
.tag.off { background: transparent; border-color: var(--border); color: var(--muted); cursor: pointer; }
.tag.suggested { box-shadow: 0 0 0 2px color-mix(in srgb, var(--ki) 45%, transparent); }

/* ---------- Werkzeugleiste */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.crumbs { font-size: 18px; font-weight: 600; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.crumbs a { color: var(--muted); cursor: pointer; text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep { color: var(--muted); font-weight: 400; }
.toolbar-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.filterbar { display: flex; align-items: center; gap: 14px; margin: 12px 0 16px; flex-wrap: wrap; }
.filterbar select { width: auto; }
.active-filters { flex: 1; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { width: auto; flex-shrink: 0; }

/* ---------- Kacheln */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
#folderGrid:not(:empty) { margin-bottom: 18px; }
.folder-tile {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.folder-tile:hover { border-color: var(--accent); }
.folder-tile.drop-target { outline: 2px dashed var(--accent); background: var(--accent-soft); }
.folder-tile .ico { font-size: 22px; }
.folder-tile .name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-tile .sub { font-size: 12px; color: var(--muted); }
.folder-tags { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.folder-tags .tag { font-size: 10px; padding: 0 6px; }

.doc-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; cursor: pointer; display: flex; flex-direction: column; position: relative;
}
.doc-card:hover { border-color: var(--accent); }
.doc-card.dragging { opacity: .5; }
.card-actions {
  position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s;
}
.doc-card:hover .card-actions { opacity: 1; }
.card-actions button {
  border: 1px solid var(--border); background: var(--panel); border-radius: 7px; cursor: pointer;
  padding: 4px 7px; font-size: 13px; line-height: 1; box-shadow: var(--shadow);
}
.card-actions button:hover { background: var(--hover); }
.card-actions .del:hover { color: var(--danger); }
.thumb {
  height: 150px; background: var(--hover); display: flex; align-items: center; justify-content: center;
  overflow: hidden; border-bottom: 1px solid var(--border);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; background: #fff; }
.thumb .filetype {
  font-weight: 700; font-size: 13px; color: #fff; background: #dc2626; padding: 10px 12px;
  border-radius: 6px; letter-spacing: .05em;
}
.thumb .filetype.other { background: #6b7280; }
.doc-info { padding: 9px 11px 11px; display: flex; flex-direction: column; gap: 5px; }
.doc-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-tags { display: flex; flex-wrap: wrap; gap: 4px; }

.empty { text-align: center; padding: 60px 20px; color: var(--text); }
.empty-icon { font-size: 44px; }
.empty p { margin: 6px 0; }

.drop-overlay {
  display: none; position: fixed; inset: 0; background: color-mix(in srgb, var(--accent) 18%, transparent);
  border: 3px dashed var(--accent); z-index: 50; align-items: center; justify-content: center; text-align: center;
  font-size: 22px; font-weight: 600; color: var(--accent); pointer-events: none; padding: 20px;
}
.drop-overlay.show { display: flex; }

/* ---------- Dialoge */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--panel); color: var(--text);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(15, 23, 42, .45); }
.small-dialog { width: min(480px, calc(100vw - 32px)); }
.small-dialog form { padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
h2 { margin: 0; font-size: 17px; }
h3 { margin: 0; font-size: 15px; }
.form-head { display: flex; justify-content: space-between; align-items: center; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; color: var(--text); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; color: var(--muted); }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tag-editor { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag-editor input { width: 140px; padding: 3px 8px; font-size: 12px; border-radius: 999px; }

.doc-dialog { width: min(1240px, calc(100vw - 32px)); height: min(880px, calc(100vh - 32px)); }
.doc-view { display: flex; height: 100%; }
.preview { flex: 1; background: #525659; display: flex; align-items: center; justify-content: center; min-width: 0; }
.preview iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.preview .no-preview { color: #e5e7eb; text-align: center; }
.preview-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #525659; }
.preview-wrap .preview { flex: 1; min-height: 0; }
.preview-nav {
  display: flex; align-items: center; justify-content: center; gap: 12px; padding: 8px;
  color: #e5e7eb; font-size: 13px; background: #3f4245;
}
.preview-nav .btn { color: var(--text); min-width: 34px; justify-content: center; }
.preview-nav span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* Seiten als Bilder untereinander (funktioniert auch auf dem iPhone mit allen Seiten) */
.preview-wrap { position: relative; }
.preview.pages { display: block; overflow-y: auto; padding: 14px; text-align: center; }
.preview.pages img {
  display: block; width: 100%; max-width: 900px; max-height: none; margin: 0 auto 14px; background: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,.35); cursor: zoom-in;
}
.preview.pages .no-preview { padding-top: 40%; }
.enlarge-btn {
  position: absolute; top: 10px; right: 14px; border: 0; border-radius: 8px; padding: 6px 12px; cursor: pointer;
  background: rgba(17,24,39,.75); color: #fff; font-size: 13px;
}
.enlarge-btn:hover { background: rgba(17,24,39,.95); }

.viewer-dialog { width: 100vw; height: 100dvh; max-width: 100vw; max-height: 100dvh; margin: 0; border: 0; border-radius: 0;
  background: #2b2d30; color: #fff; }
.viewer-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  background: #1f2023; position: sticky; top: 0; z-index: 1;
}
.viewer-head span { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-head .btn { color: var(--text); }
.viewer-body { height: calc(100% - 52px); overflow-y: auto; padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.viewer-body img { display: block; width: 100%; max-width: 1200px; margin: 0 auto 18px; background: #fff; box-shadow: 0 4px 16px rgba(0,0,0,.5); }
.viewer-body .page-no { text-align: center; color: #9ca3af; font-size: 12px; margin: -10px 0 18px; }

.confirm-dialog p { margin: 0; color: var(--muted); white-space: pre-line; }
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-fill:hover { filter: brightness(1.08); }

/* Ziel beim Einsortieren */
.target-box {
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; background: var(--hover);
  display: flex; flex-direction: column; gap: 6px; font-size: 13px;
}
.target-box .t-row { display: flex; flex-direction: column; gap: 1px; }
.target-box .t-path { font-weight: 650; }
.target-box .t-path.system { color: var(--warn); }
.target-box .t-why { font-size: 12px; color: var(--muted); }
.target-box .t-row + .t-row { border-top: 1px dashed var(--border); padding-top: 6px; }

/* Papierkorb */
.trash-info { font-size: 13px; color: var(--muted); }
.doc-card.trashed .thumb { filter: grayscale(.6); opacity: .8; }
.card-actions.always { opacity: 1; }
.card-actions .restore:hover { color: #16a34a; }

/* Vergleich bei Dubletten */
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; width: 100%; height: 100%; }
.compare > div { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.compare .cmp-label {
  background: #3f4245; color: #fff; font-size: 12px; font-weight: 600; padding: 6px 10px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.compare .cmp-label.old { background: var(--warn); }
.compare .cmp-body { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; }

.doc-form {
  width: 380px; flex-shrink: 0; display: flex; flex-direction: column; border-left: 1px solid var(--border); min-height: 0;
}
.doc-form .form-head { padding: 14px 18px 8px; }
.form-body { flex: 1; overflow-y: auto; padding: 4px 18px 14px; display: flex; flex-direction: column; gap: 12px; }
.form-actions.sticky {
  padding: 12px 18px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--panel);
}
.tool-row { display: flex; flex-wrap: wrap; gap: 6px; }
.meta { font-size: 12px; color: var(--muted); line-height: 1.6; word-break: break-word; }

.detected {
  font-size: 11px; font-weight: 600; color: var(--ki); background: color-mix(in srgb, var(--ki) 12%, transparent);
  padding: 1px 7px; border-radius: 999px; margin-left: 4px;
}
label .detected { align-self: flex-start; margin: 0; }
.analyze-status { font-size: 13px; color: var(--muted); }
.analyze-status:empty { display: none; }
.analyze-status.busy::before {
  content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: -2px;
  border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.ocr-text summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.ocr-text pre {
  white-space: pre-wrap; word-break: break-word; font-size: 12px; max-height: 220px; overflow-y: auto;
  background: var(--hover); padding: 8px 10px; border-radius: 8px; margin: 6px 0 0;
}

/* Dubletten-Hinweis */
.dup-box {
  border: 1px solid color-mix(in srgb, var(--warn) 50%, var(--border)); background: var(--warn-soft);
  border-radius: 10px; padding: 10px 12px; font-size: 13px; display: flex; flex-direction: column; gap: 8px;
}
.dup-box b { color: var(--warn); }
.dup-box .dup-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.dup-box.decided { background: var(--hover); border-color: var(--border); }

/* Ordnerwahl mit Vorschlägen */
.folder-pick { display: flex; gap: 6px; }
.folder-pick select { flex: 1; min-width: 0; }
.suggest-box {
  margin-top: 8px; border: 1px solid color-mix(in srgb, var(--ki) 30%, var(--border)); border-radius: 8px;
  background: color-mix(in srgb, var(--ki) 5%, transparent); padding: 6px 8px;
}
.suggest-title { font-size: 12px; font-weight: 600; color: var(--ki); margin-bottom: 4px; }
.sugg-row { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; padding: 4px 0; font-size: 13px; }
.sugg-row + .sugg-row { border-top: 1px solid var(--border); }
.sugg-row .check { flex: 1 1 100%; color: var(--text); font-weight: 500; }
.sugg-row.main .check { font-weight: 650; }
.sugg-role { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.sugg-tags { font-size: 12px; color: var(--muted); padding-left: 22px; }
.badge { font-size: 11px; font-weight: 600; color: #fff; background: var(--accent); padding: 1px 7px; border-radius: 999px; }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0; }
.link-btn:hover { text-decoration: underline; }
.extra-folders { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 9px;
  border-radius: 999px; background: var(--hover); border: 1px solid var(--border);
}
.chip .x { cursor: pointer; opacity: .6; padding: 0 2px; }
.chip .x:hover { opacity: 1; }
.add-extra { font-size: 12px; padding: 3px 8px; width: auto; max-width: 100%; color: var(--muted); }

.file-list { list-style: none; margin: 0; padding: 4px; max-height: 190px; overflow-y: auto; font-size: 13px;
  border: 1px solid var(--border); border-radius: 8px; }
.file-list:empty { display: none; }
.file-list li { cursor: pointer; padding: 5px 6px; border-radius: 6px; display: flex; flex-direction: column; }
.file-list li:hover { background: var(--hover); }
.file-list li.active { background: var(--accent-soft); }
.file-list li.skipped { opacity: .5; text-decoration: line-through; }
.file-list li .target { font-size: 12px; color: var(--muted); }

.color-row { display: flex; gap: 6px; }
.color-row button {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; background: var(--c);
}
.color-row button.sel { border-color: var(--text); }

/* Rechte */
.perm-box { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; max-height: 300px; overflow-y: auto; }
.perm-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 13px; }
.perm-row .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.perm-row select { width: auto; padding: 3px 6px; font-size: 12px; }
.perm-row .inherit { font-size: 11px; color: var(--muted); }
.perm-row.granted .pname { font-weight: 600; }
.readonly-badge {
  font-size: 11px; font-weight: 600; color: var(--muted); background: var(--hover); border: 1px solid var(--border);
  padding: 1px 8px; border-radius: 999px; vertical-align: 2px; margin-left: 6px;
}
.doc-form.readonly input, .doc-form.readonly textarea { background: var(--hover); }
.search-banner { display: flex; align-items: center; gap: 8px; }

/* Benutzerverwaltung */
.users-dialog { width: min(560px, calc(100vw - 32px)); }
.users-inner { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; max-height: calc(100vh - 64px); overflow-y: auto; }
.user-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 10px; }
.user-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; flex-wrap: wrap; }
.user-list li + li { border-top: 1px solid var(--border); }
.user-list .who { flex: 1; min-width: 140px; }
.user-list .who small { color: var(--muted); display: block; }
.user-list .inactive { opacity: .5; }
.user-form { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--border); padding-top: 14px; }

.toast {
  position: fixed; bottom: max(20px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%) translateY(20px);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0;
  transition: all .2s; pointer-events: none; z-index: 300; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }

/* ---------- Touch-Geräte: Aktionen immer sichtbar */
@media (hover: none) {
  .card-actions { opacity: 1; }
}

/* ---------- Tags verwalten */
.side-manage-btn { margin-top: 6px; width: 100%; justify-content: center; }
.tags-tools { display: flex; gap: 8px; align-items: center; }
.tags-tools input { flex: 1; }
.tags-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 58dvh; overflow-y: auto; }
.tags-list li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 10px; flex-wrap: wrap; }
.tags-list li > input[type="checkbox"] { width: 18px; height: 18px; }
.tag-swatch { width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--border); background: var(--c); cursor: pointer; padding: 0; flex-shrink: 0; }
.tag-name-input { flex: 1; min-width: 120px; padding: 6px 8px; }
.tag-count { color: var(--muted); font-size: 12.5px; min-width: 52px; }

/* ---------- Import aus Paperless */
.import-groups { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 50dvh; overflow-y: auto; }
.import-groups li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; }
.import-groups .g-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.import-groups .g-count { color: var(--muted); font-size: 13px; white-space: nowrap; }
.import-groups li.done { opacity: .55; }
.import-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.import-cmd { font-family: ui-monospace, Consolas, monospace; font-size: 12px; background: var(--hover); border-radius: 8px; padding: 8px 10px; overflow-x: auto; white-space: pre; }

/* ---------- Info-Dialog */
.info-body { display: flex; flex-direction: column; gap: 10px; max-height: 70dvh; overflow-y: auto; }
.info-section { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.info-section summary { cursor: pointer; font-weight: 600; font-size: 14px; padding: 2px 0; }
.info-table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 13.5px; }
.info-table th { text-align: left; font-weight: 500; color: var(--muted); width: 38%; padding: 4px 10px 4px 0; vertical-align: top; }
.info-table td { padding: 4px 0; overflow-wrap: anywhere; }
.info-table tr + tr th, .info-table tr + tr td { border-top: 1px solid var(--border); }
.info-map { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 2px; }

/* ---------- Familienfoto */
.logo { position: relative; display: flex; align-items: center; gap: 8px; overflow: visible; }
.logo-text { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.family-photo {
  width: 40px; height: 40px; border-radius: 12px; border: 0; padding: 0; background: transparent;
  font-size: 22px; flex-shrink: 0; display: grid; place-items: center; overflow: hidden; cursor: default;
}
.family-photo.clickable { cursor: pointer; }
.family-photo.clickable:not(.has-photo) { background: var(--hover); border: 1px dashed var(--border); font-size: 18px; }
.family-photo.has-photo { box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--border); }
.family-photo img { width: 100%; height: 100%; object-fit: cover; }
.family-menu { left: 0; right: auto; top: 46px; min-width: 220px; }
.auth-logo.photo { font-size: 0; margin: -6px auto 4px; width: 100%; }
.auth-logo.photo img {
  width: 100%; max-height: 220px; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 14px;
  box-shadow: 0 4px 18px rgba(0,0,0,.15); display: block;
}
.family-big { display: block; max-width: 100%; max-height: calc(100dvh - 120px); margin: 0 auto; border-radius: 10px; }

/* ---------- Hochladen Datei für Datei */
.upload-step { font-size: 15px; font-weight: 500; color: var(--muted); }
.doc-form .form-body > * { flex-shrink: 0; }  /* Dateiliste nicht zusammendrücken */
.step-info { font-size: 13px; background: var(--accent-soft); border-radius: 8px; padding: 8px 10px; }
.form-actions.sticky { flex-wrap: wrap; }

/* ---------- Profilfotos */
.avatar {
  width: var(--s); height: var(--s); border-radius: 50%; object-fit: cover; flex-shrink: 0; display: inline-grid;
  place-items: center; vertical-align: middle; background: var(--hover);
}
.avatar.initials {
  background: hsl(var(--h) 55% 46%); color: #fff; font-weight: 700; font-size: calc(var(--s) * .4); line-height: 1;
}
#userAvatar { display: inline-flex; }
.user-btn { gap: 6px; }
.avatar-btn { position: relative; border: 0; background: none; padding: 0; cursor: pointer; border-radius: 50%; }
.avatar-btn .cam {
  position: absolute; right: -4px; bottom: -4px; font-size: 12px; background: var(--panel); border-radius: 50%;
  width: 20px; height: 20px; display: grid; place-items: center; box-shadow: var(--shadow);
}
.profile-photo { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.profile-photo-actions { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; flex: 1; min-width: 180px; }

/* ---------- Verlauf */
.last-change { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 11.5px; color: var(--muted); min-width: 0; }
.last-change span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-box summary { cursor: pointer; font-weight: 600; font-size: 14px; padding: 4px 0; }
.history { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; max-height: 280px; overflow-y: auto; }
.history li { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; }
.history .h-body { min-width: 0; flex: 1; }
.history .h-when { color: var(--muted); font-size: 12px; margin-left: 4px; white-space: nowrap; }
.history .h-details { color: var(--muted); font-size: 12.5px; margin-top: 2px; overflow-wrap: anywhere; }

/* ---------- Drucken / Teilen */
.share-tools { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.share-tools span { flex: 1; }
.share-pages {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px;
  max-height: 55dvh; overflow-y: auto; padding: 4px;
}
.share-page {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer;
  border: 2px solid var(--accent); border-radius: 10px; padding: 6px; background: var(--panel); transition: opacity .15s;
}
.share-page.off { border-color: var(--border); opacity: .45; }
.share-page img { width: 100%; aspect-ratio: 1 / 1.414; object-fit: contain; background: #fff; border-radius: 4px; }
.share-page input { position: absolute; top: 10px; left: 10px; width: 22px; height: 22px; accent-color: var(--accent); }
.share-page .num { font-size: 12px; color: var(--muted); }
#printArea { display: none; }
@media print {
  body > *:not(#printArea) { display: none !important; }
  dialog, dialog::backdrop { display: none !important; }
  #printArea { display: block !important; }
  #printArea img { display: block; width: 100%; height: auto; max-height: 100vh; object-fit: contain; page-break-after: always; break-after: page; }
  #printArea img:last-child { page-break-after: auto; break-after: auto; }
  @page { margin: 8mm; }
}

/* ---------- farbige Ordnersymbole */
.fico { width: 1.25em; height: 1.25em; vertical-align: -0.25em; flex-shrink: 0; }
.fico path { fill: var(--c); }
.fico path.lid { fill: color-mix(in srgb, var(--c) 82%, #fff); }
.folder-tile .ico .fico { width: 30px; height: 30px; }
.crumb-folder { display: inline-flex; align-items: center; gap: 5px; }

/* ---------- Farbwähler */
.color-picker { --pick: #2563eb; --hue: red; display: flex; flex-direction: column; gap: 10px; }
.cp-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cp-preview {
  width: 44px; height: 44px; border-radius: 10px; background: var(--pick); border: 1px solid var(--border);
  display: grid; place-items: center; font-size: 9px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.5);
}
.cp-hex { width: 104px; font-family: ui-monospace, Consolas, monospace; text-transform: uppercase; }
.cp-sys { position: relative; overflow: hidden; cursor: pointer; }
.cp-sys input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; border: 0; padding: 0; }
.cp-default.on { background: var(--accent-soft); border-color: var(--accent); }
.cp-sv {
  position: relative; height: 220px; border-radius: 10px; cursor: crosshair; touch-action: none;
  background: linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, var(--hue));
  border: 1px solid var(--border); outline-offset: 2px;
}
.cp-knob {
  position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; pointer-events: none;
  border: 3px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.4), 0 2px 6px rgba(0,0,0,.35); background: var(--pick);
}
.color-picker input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 18px; border-radius: 9px; margin: 0;
  border: 1px solid var(--border); background: #ccc; padding: 0;
}
.color-picker input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 24px; height: 24px; border-radius: 50%; background: #fff;
  border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.45), 0 1px 4px rgba(0,0,0,.35); cursor: pointer;
}
.color-picker input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.45), 0 1px 4px rgba(0,0,0,.35); cursor: pointer;
}
.cp-hue, .color-picker [data-ch="hh"] { background: linear-gradient(90deg, #f00, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00) !important; }
.cp-mixer { border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; }
.cp-mixer summary { cursor: pointer; font-weight: 600; font-size: 14px; padding: 4px 0; }
.cp-mixer[open] summary { margin-bottom: 6px; }
.cp-row { display: grid; grid-template-columns: 78px 1fr 62px; align-items: center; gap: 8px; margin: 6px 0; font-size: 13px; }
.cp-row input[type="number"] { width: 62px; padding: 4px 6px; }
.cp-swatches { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; }
.cp-swatches button {
  aspect-ratio: 1; border-radius: 7px; border: 2px solid transparent; background: var(--c); cursor: pointer; padding: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12);
}
.cp-swatches button.sel { border-color: var(--text); transform: scale(1.08); }
.cp-label { font-size: 12px; color: var(--muted); margin-bottom: -4px; }
#promptDialog { max-height: calc(100dvh - 24px); overflow-y: auto; }

/* ---------- KI: alle Dokumente prüfen */
.ki-review-btn { margin-top: 6px; width: 100%; justify-content: center; color: var(--ki); }
.wide-dialog { width: min(760px, calc(100vw - 32px)); }
.ki-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 60dvh; overflow-y: auto; }
.ki-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); }
.ki-item > input { margin-top: 4px; width: 18px; height: 18px; flex-shrink: 0; }
.ki-thumb { width: 52px; height: 66px; flex-shrink: 0; border-radius: 6px; overflow: hidden; background: var(--hover); display: grid; place-items: center; }
.ki-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ki-thumb .filetype { font-size: 11px; }
.ki-body { min-width: 0; display: flex; flex-direction: column; gap: 3px; font-size: 14px; }
.ki-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ki-body .t-why { font-size: 12px; color: var(--muted); }
.ki-tags { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 13px; }

/* ---------- Scanner */
dialog.scan-dialog {
  width: 100vw; height: 100dvh; max-width: 100vw; max-height: 100dvh; margin: 0; padding: 0; border: 0; border-radius: 0;
  background: #000; color: #fff; display: none; flex-direction: column;
}
dialog.scan-dialog[open] { display: flex; }
.scan-stage { position: relative; flex: 1; overflow: hidden; min-height: 0; }
.scan-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.scan-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.scan-flash.go { animation: scanflash .35s ease-out; }
@keyframes scanflash { from { opacity: .8; } to { opacity: 0; } }
.scan-status {
  position: absolute; left: 50%; top: max(14px, env(safe-area-inset-top)); transform: translateX(-50%);
  background: rgba(0,0,0,.6); padding: 8px 14px; border-radius: 20px; font-size: 15px; white-space: nowrap;
  max-width: calc(100vw - 24px); overflow: hidden; text-overflow: ellipsis; backdrop-filter: blur(6px);
}
.scan-status.found { background: rgba(37,99,235,.85); }
.scan-status.done { background: rgba(22,163,74,.88); }
.scan-strip { display: flex; gap: 8px; padding: 8px 12px 0; overflow-x: auto; min-height: 0; }
.scan-strip:empty { display: none; }
.scan-thumb { position: relative; flex-shrink: 0; width: 54px; height: 72px; border-radius: 6px; overflow: hidden; background: #222; }
.scan-thumb img { width: 100%; height: 100%; object-fit: cover; }
.scan-thumb .num { position: absolute; left: 3px; bottom: 2px; font-size: 11px; font-weight: 700; text-shadow: 0 1px 2px #000; }
.scan-thumb button {
  position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.7); color: #fff; font-size: 11px; cursor: pointer; padding: 0;
}
.scan-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.scan-bar .btn:not(.primary) { background: #222; color: #fff; border-color: #444; }
.scan-bar select { background: #222; color: #fff; border-color: #444; max-width: 120px; }
.scan-auto, .scan-auto span { color: #fff; }
.scan-shutter {
  width: 68px; height: 68px; border-radius: 50%; border: 4px solid #fff; background: #fff; flex-shrink: 0;
  box-shadow: inset 0 0 0 3px #000; cursor: pointer;
}
.scan-shutter:active { transform: scale(.93); }
.scan-status.warn { background: rgba(217,119,6,.9); }

/* ---------- Ecken-Editor (Zuschneiden) */
.crop-head { padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); text-align: center; font-size: 15px; }
.crop-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 18px; overflow: hidden; }
.crop-wrap { position: relative; display: inline-block; max-width: 100%; max-height: 100%; touch-action: none; }
.crop-wrap img { display: block; max-width: calc(100vw - 36px); max-height: calc(100dvh - 190px); user-select: none; -webkit-user-drag: none; }
.crop-wrap svg { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }
.crop-wrap polygon { fill: rgba(59,130,246,.18); stroke: #3b82f6; stroke-width: 2.5; }
.crop-handle {
  position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; touch-action: none; cursor: grab;
  background: radial-gradient(circle, #fff 0 7px, #3b82f6 8px 11px, rgba(59,130,246,.25) 12px);
}
.crop-handle:active { cursor: grabbing; transform: scale(1.15); }
.crop-bar { justify-content: center; flex-wrap: wrap; }

/* ---------- Handy */
@media (max-width: 800px) {
  body { font-size: 15px; }
  input, select, textarea { font-size: 16px; } /* verhindert Zoom beim Tippen auf dem iPhone */
  .menu-btn { display: block; font-size: 20px; }
  .btn.camera-btn { display: inline-flex; }
  .folder-up-btn, .logo-text { display: none; }
  .logo { flex-shrink: 0; }
  .family-photo { width: 36px; height: 36px; border-radius: 50%; }
  .family-photo:not(.has-photo):not(.clickable) { display: none; }
  .btn-label { display: none; }
  .topbar { gap: 6px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); }
  .topbar .btn { padding: 8px 11px; font-size: 16px; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 80; width: min(300px, 85vw); transform: translateX(-100%);
    transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.2);
    padding-top: max(12px, env(safe-area-inset-top)); padding-bottom: env(safe-area-inset-bottom);
  }
  .sidebar.open { transform: none; }
  .sidebar.open + .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.35); }
  .tree-row { padding: 8px 6px; }
  .main { padding: 12px 12px 40px; padding-bottom: max(40px, env(safe-area-inset-bottom)); }
  .crumbs { font-size: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .thumb { height: 120px; }
  .filterbar { gap: 8px; }

  dialog.doc-dialog { width: 100vw; height: 100dvh; max-width: 100vw; max-height: 100dvh; margin: 0; border-radius: 0; border: 0; }
  .doc-view { flex-direction: column; }
  .preview, .preview-wrap { flex: none; height: 38dvh; }
  .doc-form { width: 100%; flex: 1; border-left: 0; border-top: 1px solid var(--border); }
  .doc-form .form-head { padding-top: 10px; }
  .compare { grid-template-columns: 1fr 1fr; }
  .small-dialog { width: calc(100vw - 20px); }
  .tag-filter { position: static; }
  .tag-drop { position: fixed; left: 10px; right: 10px; top: calc(env(safe-area-inset-top) + 56px); width: auto; }
  .tag-editor input { width: 120px; }
  .cp-sv { height: 200px; }
  .scan-bar { flex-wrap: wrap; justify-content: center; }
  .scan-bar .scan-shutter { order: -1; width: 100%; max-width: 68px; margin: 0 calc(50% - 34px); }
  .wide-dialog { width: calc(100vw - 20px); }

  /* ----- Handy: oben Menü + Foto + Suche + Tags, unten feste Knopfleiste ----- */
  .menu-btn {
    width: 46px; height: 46px; padding: 0; display: grid; place-items: center; flex-shrink: 0;
    border: 1px solid var(--border); border-radius: 12px; background: var(--hover); color: var(--text);
  }
  .burger { display: grid; gap: 5px; width: 22px; }
  .burger i { display: block; height: 3px; border-radius: 2px; background: currentColor; }
  .topbar { gap: 8px; }
  .search { flex: 1 1 auto; min-width: 0; }
  .search input { height: 42px; }
  .top-actions {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 90; display: flex; justify-content: space-around; align-items: flex-end;
    gap: 4px; padding: 6px 8px; padding-bottom: max(8px, env(safe-area-inset-bottom));
    background: var(--panel); border-top: 1px solid var(--border); box-shadow: 0 -4px 16px rgba(0,0,0,.08);
  }
  .top-actions > .btn, .top-actions .user-btn {
    flex-direction: column; gap: 2px; border: 0; background: transparent; padding: 4px 6px; min-width: 62px;
    font-size: 22px; line-height: 1; color: var(--text);
  }
  .top-actions .btn-label { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }
  .top-actions .user-btn #userName { display: none; }
  .top-actions .bar-label { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }
  .top-actions #uploadBtn {
    order: 2; width: 58px; height: 58px; min-width: 58px; border-radius: 50%; margin-top: -24px; justify-content: center;
    background: var(--accent); color: #fff; font-size: 30px; box-shadow: 0 6px 16px rgba(37,99,235,.4);
  }
  .top-actions #uploadBtn .btn-label { display: none; }
  .top-actions #scanBtn { order: 0; }
  .top-actions #cameraBtn { order: 1; }
  .top-actions .user-menu { order: 3; }
  .top-actions .dropdown { top: auto; bottom: calc(100% + 10px); right: 0; }
  .main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(92px + env(safe-area-inset-bottom)); }
}

/* ---------- Desktop: etwas größer */
.bar-label { display: none; }
@media (min-width: 801px) {
  .top-actions { display: flex; align-items: center; gap: 10px; }
  body { font-size: 15px; }
  .topbar { padding: 12px 20px; gap: 12px; }
  .topbar .btn { padding: 9px 16px; font-size: 15px; }
  .search input { height: 42px; font-size: 15px; }
  .logo { font-size: 18px; }
  .family-photo { width: 46px; height: 46px; }
  .tree-row { padding: 7px 8px; }
  .doc-title { font-size: 15px; }
}
