:root {
  --bg: #f4f5f9; --surface: #ffffff; --surface-2: #eef0f6; --border: #e2e5ee;
  --text: #0f172a; --muted: #64748b; --accent: #4f46e5; --accent-2: #6366f1; --accent-soft: #eef2ff;
  --ok: #059669; --warn: #d97706; --danger: #dc2626; --radius: 14px;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020; --surface: #131a2e; --surface-2: #1b2340; --border: #263052;
    --text: #e6e9f2; --muted: #93a0bd; --accent: #818cf8; --accent-2: #a5b4fc; --accent-soft: #1e2550;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); text-decoration: none; }
svg { width: 22px; height: 22px; fill: currentColor; flex: none; }
h1 { font-size: 1.45rem; margin: .2rem 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; }
h3 { font-size: .95rem; margin: 1rem 0 .4rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
[hidden] { display: none !important; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .mono { font-family: ui-monospace, Menlo, monospace; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }

/* Topbar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
  padding: calc(env(safe-area-inset-top, 0px) + .6rem) 1rem .6rem; background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(14px); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand img { width: 30px; height: 30px; }
.search { flex: 1; max-width: 560px; display: flex; align-items: center; gap: .4rem; background: var(--surface-2);
  border-radius: 999px; padding: 0 .9rem; border: 1px solid transparent; }
.search:focus-within { border-color: var(--accent); }
.search svg { width: 18px; color: var(--muted); }
.search input { border: 0; background: transparent; padding: .6rem 0; flex: 1; color: var(--text); font-size: 1rem; outline: none; min-width: 0; }
.sidenav { display: flex; gap: .2rem; }
.sidenav a { padding: .5rem .8rem; border-radius: 10px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.sidenav a.active { background: var(--accent-soft); color: var(--accent); }
@media (max-width: 860px) { .sidenav { display: none; } .brand span { display: none; } }

.view { max-width: 1200px; margin: 0 auto; padding: 1rem 1rem calc(110px + var(--safe-b)); }

/* Bottom nav */
.bottomnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: none; justify-content: space-around; align-items: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px);
  border-top: 1px solid var(--border); padding: .35rem .4rem calc(.35rem + var(--safe-b)); }
.bottomnav a { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: .7rem; padding: .25rem .6rem; min-width: 60px; }
.bottomnav a.active { color: var(--accent); }
.bottomnav .scanbtn { background: var(--accent); color: #fff !important; border-radius: 18px; width: 58px; height: 50px; justify-content: center; min-width: 0; margin-top: -18px; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 45%, transparent); }
.bottomnav .scanbtn svg { width: 28px; height: 28px; }
.bottomnav .badge { position: absolute; top: -2px; right: 10px; }
@media (max-width: 860px) { .bottomnav { display: flex; } }

.badge { background: var(--danger); color: #fff; font-size: .68rem; border-radius: 999px; padding: 1px 6px; font-weight: 700; }
.fab { position: fixed; right: 1.2rem; bottom: calc(1.4rem + var(--safe-b)); z-index: 19; width: 58px; height: 58px; border-radius: 18px;
  border: 0; background: var(--accent); color: #fff; box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 45%, transparent); cursor: pointer; display: grid; place-items: center; }
.fab svg { width: 28px; height: 28px; }
@media (max-width: 860px) { .fab { bottom: calc(80px + var(--safe-b)); } }

/* Ablage-Modus-Leiste */
.filing { position: sticky; top: 58px; z-index: 15; display: flex; gap: .6rem; align-items: center; justify-content: center; flex-wrap: wrap;
  background: linear-gradient(90deg, #4338ca, #6d28d9); color: #fff; padding: .5rem 1rem; font-weight: 600; font-size: .9rem; }
.filing button { background: rgba(255,255,255,.2); color: #fff; border: 0; border-radius: 8px; padding: .25rem .6rem; cursor: pointer; }

/* Buttons & Forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: .6rem 1rem; border-radius: 11px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 42px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary, .fab, .bottomnav .scanbtn { background: #6366f1; border-color: #6366f1; } }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: .35rem .7rem; min-height: 34px; font-size: .85rem; }
.btn svg { width: 18px; height: 18px; }
.btn:disabled { opacity: .5; cursor: default; }
label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin: .7rem 0 .3rem; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: .6rem .75rem; min-height: 42px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
input[type=checkbox] { width: auto; min-height: 0; accent-color: var(--accent); }
input[type=color] { padding: .2rem; width: 54px; }
textarea { min-height: 90px; resize: vertical; }
.check { display: flex; gap: .5rem; align-items: center; font-size: .95rem; color: var(--text); font-weight: 500; margin: .6rem 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }
.card + .card { margin-top: 1rem; }

/* Filterleiste */
.filters { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .4rem; margin-bottom: .6rem; scrollbar-width: none; }
.filters select { width: auto; min-width: 130px; border-radius: 999px; padding: .4rem .8rem; min-height: 36px; font-size: .9rem; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .7rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; }
.stat b { display: block; font-size: 1.4rem; } .stat span { color: var(--muted); font-size: .8rem; }
@media (max-width: 640px) { .stats { grid-template-columns: repeat(2, 1fr); } }

/* Dokument-Grid */
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .9rem; }
@media (max-width: 520px) { .docs { grid-template-columns: repeat(2, 1fr); gap: .6rem; } }
.doc { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; color: var(--text);
  box-shadow: var(--shadow); display: flex; flex-direction: column; transition: transform .12s; }
.doc:hover { transform: translateY(-2px); }
.doc .thumb { aspect-ratio: 3/3.4; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.doc .thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.doc .info { padding: .6rem .7rem .7rem; display: flex; flex-direction: column; gap: .25rem; }
.doc .title { font-weight: 600; font-size: .92rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.doc .meta { font-size: .75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc .new { position: absolute; top: 8px; left: 8px; background: var(--accent); color: #fff; font-size: .68rem; font-weight: 700; padding: 2px 7px; border-radius: 6px; }
.doc .sel { position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; }
.doc.selected { outline: 3px solid var(--accent); }
.state { font-size: .7rem; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.state.error { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.tags { display: flex; flex-wrap: wrap; gap: .25rem; }
.tag { font-size: .7rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; color: #fff; background: var(--c, #0ea5e9); white-space: nowrap; }
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .3rem .7rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-size: .85rem; user-select: none; }
.chip.on { background: var(--c, var(--accent)); color: #fff; border-color: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty svg { width: 56px; height: 56px; opacity: .4; }
.more { display: flex; justify-content: center; margin: 1.2rem 0; }

/* Detailansicht */
.detail { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(300px, 1fr); gap: 1.2rem; align-items: start; }
@media (max-width: 900px) { .detail { grid-template-columns: 1fr; } }
.pages { display: flex; flex-direction: column; gap: .8rem; }
.pages img { width: 100%; max-height: 80vh; object-fit: contain; border-radius: 10px; border: 1px solid var(--border); background: #fff; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin: .6rem 0 0; }
.ocr { white-space: pre-wrap; font-size: .8rem; max-height: 320px; overflow: auto; background: var(--surface-2); padding: .8rem; border-radius: 10px; }
details summary { cursor: pointer; font-weight: 600; padding: .4rem 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .25rem .8rem; font-size: .85rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }

/* Liste */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: .8rem; padding: .75rem .2rem; border-bottom: 1px solid var(--border); color: var(--text); }
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .grow b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 12px; height: 12px; border-radius: 4px; background: var(--c); flex: none; }
.code { font-family: ui-monospace, Menlo, monospace; font-weight: 700; background: var(--surface-2); padding: .15rem .5rem; border-radius: 6px; font-size: .85rem; }

/* Tabs */
.tabs { display: flex; gap: .3rem; overflow-x: auto; margin-bottom: 1rem; border-bottom: 1px solid var(--border); scrollbar-width: none; }
.tabs a { padding: .6rem .9rem; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--accent); border-color: var(--accent); }

/* Scanner */
.scanner { position: relative; border-radius: 18px; overflow: hidden; background: #000; aspect-ratio: 3/4; max-height: 60vh; margin: 0 auto; width: 100%; max-width: 520px; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner .frame { position: absolute; inset: 22% 10%; border: 3px solid rgba(255,255,255,.9); border-radius: 16px; box-shadow: 0 0 0 9999px rgba(0,0,0,.35); }
.scanner .laser { position: absolute; left: 12%; right: 12%; top: 50%; height: 2px; background: #f43f5e; box-shadow: 0 0 12px #f43f5e; animation: laser 1.8s ease-in-out infinite; }
@keyframes laser { 0%,100% { top: 25%; } 50% { top: 75%; } }
.scanhint { text-align: center; margin: .8rem 0; }

/* Login */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth .card { width: 100%; max-width: 400px; padding: 1.8rem; }
.auth .logo { display: flex; align-items: center; gap: .6rem; font-size: 1.4rem; font-weight: 800; margin-bottom: .4rem; }
.auth .logo img { width: 44px; height: 44px; }
.err { color: var(--danger); font-size: .9rem; min-height: 1.2em; margin-top: .6rem; }

/* Upload */
.uploads { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.up { display: flex; gap: .6rem; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .6rem .8rem; }
.up .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; width: 100px; }
.bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.bigdrop { border: 2px dashed var(--border); border-radius: 18px; padding: 2.2rem 1rem; text-align: center; background: var(--surface); }
.bigdrop svg { width: 48px; height: 48px; color: var(--accent); }
.dropzone { position: fixed; inset: 0; z-index: 50; background: color-mix(in srgb, var(--accent) 25%, transparent); display: grid; place-items: center; backdrop-filter: blur(4px); }
.dropzone div { background: var(--surface); padding: 2rem 3rem; border-radius: 18px; font-weight: 700; font-size: 1.2rem; border: 3px dashed var(--accent); }

/* Toast + Dialog */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--safe-b)); z-index: 60; display: flex; flex-direction: column; gap: .4rem; align-items: center; pointer-events: none; }
.toast { background: #111827; color: #fff; padding: .65rem 1rem; border-radius: 12px; font-size: .9rem; box-shadow: var(--shadow); animation: pop .2s ease-out; max-width: 90vw; }
.toast.error { background: var(--danger); }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } }
dialog { border: 0; border-radius: 18px; padding: 1.3rem; background: var(--surface); color: var(--text); width: min(480px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(2,6,23,.55); backdrop-filter: blur(3px); }
.bulkbar { position: sticky; top: 64px; z-index: 14; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; background: var(--accent-soft); border: 1px solid var(--border); border-radius: 12px; padding: .5rem .7rem; margin-bottom: .8rem; }
.bulkbar select { width: auto; min-height: 34px; padding: .3rem .6rem; }

/* Etiketten-Druck */
.labels { display: flex; flex-wrap: wrap; gap: 4mm; }
.labels img { width: 90mm; height: 38mm; border: 1px dashed #bbb; background: #fff; }
@media print {
  body { background: #fff; }
  .topbar, .bottomnav, .fab, .filing, .noprint, .toasts { display: none !important; }
  .view { padding: 0; max-width: none; }
  .labels img { border: 0; break-inside: avoid; }
}
.spin { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: s .8s linear infinite; display: inline-block; }
@keyframes s { to { transform: rotate(360deg); } }

/* v2: Dateityp, Treffer, Fristen */
.thumb { position: relative; }
.ftype { position: absolute; bottom: 6px; left: 6px; font-size: .62rem; font-weight: 800; letter-spacing: .04em; padding: 2px 6px; border-radius: 5px; background: #475569; color: #fff; }
.ftype.inline { position: static; display: inline-block; }
.ftype.t-word { background: #2563eb; } .ftype.t-sheet { background: #16a34a; } .ftype.t-slide { background: #ea580c; }
.snippet { font-size: .78rem; color: var(--muted); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
mark { background: color-mix(in srgb, #facc15 55%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.due { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); width: fit-content; }
.due.soon { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.due.overdue { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.duecard { margin-bottom: 1rem; }
.state.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.searchhelp { margin: -.6rem 0 .6rem; } .searchhelp summary { font-size: .85rem; color: var(--muted); font-weight: 500; }
.filters input[type=date] { width: auto; min-height: 36px; padding: .3rem .6rem; border-radius: 999px; }
.filters label { margin: 0; align-self: center; }

/* v3 */
.sheets { display: flex; flex-direction: column; gap: 1rem; align-items: center; }
.sheets img { width: 100%; max-width: 420px; background: #fff; border: 1px solid var(--border); border-radius: 8px; }
@media print { .sheets img { width: 210mm; max-width: none; height: 297mm; border: 0; border-radius: 0; break-after: page; } @page { margin: 0; } }
ol.small { padding-left: 1.2rem; } ol.small li { margin: .3rem 0; }
code { font-family: ui-monospace, Menlo, monospace; font-size: .85em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; word-break: break-all; }

/* v4: Dokumentscanner */
.pagestrip { display: flex; gap: .6rem; overflow-x: auto; padding: .3rem 0; }
.pg { position: relative; flex: none; width: 110px; height: 150px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--surface); }
.pg img { width: 100%; height: 100%; object-fit: cover; }
.pg span { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: .75rem; padding: 1px 7px; border-radius: 6px; }
.pg button { position: absolute; top: 4px; right: 4px; min-height: 26px; padding: 0 .45rem; }
.pg.add { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem; border: 2px dashed var(--accent); color: var(--accent); cursor: pointer; font: inherit; }
.pg.add b { font-size: 2rem; line-height: 1; } .pg.add span { position: static; background: none; color: inherit; font-size: .8rem; text-align: center; }
.cropwrap { position: relative; margin: 0 auto; max-width: 560px; touch-action: none; user-select: none; }
.cropwrap img { width: 100%; display: block; border-radius: 10px; }
.cropwrap svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.cropwrap polygon { fill: rgba(99,102,241,.18); stroke: #6366f1; stroke-width: 2.5; }
.handle { position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%; background: rgba(255,255,255,.9); border: 3px solid #6366f1; box-shadow: 0 2px 8px rgba(0,0,0,.4); touch-action: none; cursor: grab; }

/* v4 */
.quick { display: flex; gap: .5rem; overflow-x: auto; margin: -.2rem 0 1rem; scrollbar-width: none; }
.quick .btn { white-space: nowrap; }
.askbox { margin-bottom: 1rem; } .answer { white-space: pre-wrap; margin: .8rem 0 .3rem; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; } .codes .code { text-align: center; padding: .4rem; }
.dupbox { background: color-mix(in srgb, var(--warn) 15%, transparent); border-radius: 10px; padding: .6rem .8rem; margin-bottom: .5rem; font-size: .9rem; }
details.contract { margin-top: .8rem; } details.contract summary { font-size: .85rem; color: var(--muted); }
.pgedit { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .6rem; max-height: 60vh; overflow: auto; }
.pgcard { position: relative; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; }
.pgcard img { width: 100%; aspect-ratio: 3/4; object-fit: contain; transition: transform .2s; }
.pgcard.del img { opacity: .25; } .pgcard span { position: absolute; top: 4px; left: 6px; font-size: .7rem; background: rgba(0,0,0,.6); color: #fff; padding: 0 6px; border-radius: 5px; }
.pgbar { display: flex; justify-content: space-between; background: var(--surface-2); }
.pgbar button { flex: 1; border: 0; background: transparent; color: var(--text); padding: .45rem 0; cursor: pointer; font-size: 1rem; }
.pgbar button:disabled { opacity: .3; }

/* v5: Installation */
.installbar { display: flex; align-items: center; gap: .6rem; background: linear-gradient(90deg, #4338ca, #6d28d9); color: #fff; border-radius: 14px; padding: .7rem .9rem; margin-bottom: 1rem; font-size: .9rem; }
.installbar span { flex: 1; } .installbar .btn.ghost { color: #fff; }
.installbar .btn.primary { background: #fff; color: #4338ca; border-color: #fff; }
ol.steps { padding-left: 1.3rem; } ol.steps li { margin: .55rem 0; }
.ico { display: inline-block; border: 1px solid var(--border); border-radius: 6px; padding: 0 .35rem; font-size: .85rem; }
@media (display-mode: standalone) { .topbar { padding-top: calc(env(safe-area-inset-top, 0px) + .6rem); } }
fieldset.mem { border: 1px solid var(--border, #334155); border-radius: 12px; padding: .4rem .8rem .8rem; margin: .8rem 0; }
fieldset.mem legend { font-weight: 700; padding: 0 .3rem; }
