:root {
  --bg: #f4f6fa; --card: #ffffff; --text: #16213a; --muted: #5b6577; --line: #dde3ec;
  --primary: #1d4ed8; --primary-text: #ffffff; --danger: #c62828; --ok: #1b8a4c;
  --radius: 14px; --shadow: 0 1px 3px rgba(20, 30, 60, .08);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1420; --card: #1a2131; --text: #e8ecf4; --muted: #9aa5b8; --line: #2b3447; --primary: #4f7cff; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
h3 { font-size: 1rem; margin: 22px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.topbar { position: sticky; top: 0; z-index: 10; display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; height: 56px; padding: 0 8px; padding-top: env(safe-area-inset-top); background: var(--card); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 1.1rem; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#headerRight { display: flex; justify-content: flex-end; }

#view { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }

.iconbtn { width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent; font-size: 1.4rem; line-height: 1; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.iconbtn:hover { background: var(--line); }
.iconbtn.danger { color: var(--danger); }
.iconbtn:disabled { opacity: .3; cursor: default; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); cursor: pointer; font-weight: 600; text-align: center; }
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.big { flex: 1; min-height: 50px; }

.yearbar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-bottom: 16px; }
.yearsel { display: flex; align-items: center; gap: 8px; font-weight: 600; }
select, input[type=text], textarea { font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%; }
.yearsel select { width: auto; }
.stats { color: var(--muted); font-size: .95rem; }
.progress { flex-basis: 100%; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress div { height: 100%; background: var(--ok); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card { display: flex; flex-direction: column; justify-content: center; gap: 4px; min-height: 120px; padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); cursor: pointer; text-align: left; }
.card:hover { border-color: var(--primary); }
.card-icon { font-size: 1.9rem; line-height: 1.2; }
.card-name { font-weight: 600; }
.card-count { color: var(--muted); font-size: .85rem; }
.card-add { border-style: dashed; color: var(--muted); align-items: center; text-align: center; }

.hintbox { margin-top: 20px; padding: 12px 14px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); color: var(--muted); font-size: .95rem; }
details.hintbox { margin: 0 0 14px; }
details.hintbox summary { cursor: pointer; font-weight: 600; color: var(--text); }
details.hintbox p { margin: 8px 0 0; }

.bottombar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; display: flex; gap: 10px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
@media (min-width: 760px) { .bottombar { max-width: 760px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); } }

.doclist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.doclist a { display: grid; grid-template-columns: 64px 1fr 36px; gap: 12px; align-items: center; padding: 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.thumb { width: 64px; height: 80px; border-radius: 8px; overflow: hidden; background: var(--line); display: flex; align-items: center; justify-content: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.pdfbadge { display: inline-block; padding: 3px 7px; border-radius: 6px; background: var(--danger); color: #fff; font-size: .75rem; font-weight: 700; }
.pdfbadge.big { font-size: 1.2rem; padding: 10px 16px; }
.doctitle { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.docsub { color: var(--muted); font-size: .85rem; }
.status { font-size: 1.3rem; color: var(--muted); text-align: center; }
.status.ok { color: var(--ok); font-weight: 700; }

.empty { text-align: center; color: var(--muted); padding: 50px 10px; }
.empty-icon { font-size: 3rem; }

.docform { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 1rem; min-height: 44px; }
label.check input { width: 22px; height: 22px; }
label small { color: var(--muted); }
textarea { resize: vertical; }

.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.page { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.page img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: contain; background: #e9edf3; cursor: zoom-in; }
.page figcaption { display: flex; justify-content: space-between; align-items: center; padding: 6px 6px 6px 12px; font-size: .9rem; color: var(--muted); }
.pagebtns { display: flex; }
.addpage { grid-column: 1 / -1; display: flex; gap: 10px; flex-wrap: wrap; }
.addpage .btn { flex: 1; }
.pdfinfo { text-align: center; padding: 30px 10px; display: flex; flex-direction: column; align-items: center; gap: 12px; }

.settings p { margin: 6px 0 10px; }
.settings .row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
.settings .row .btn { flex: 1 1 220px; }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.muted { color: var(--muted); font-size: .9rem; }

#toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); max-width: 90vw; padding: 10px 16px; background: #222a3a; color: #fff; border-radius: 10px; font-size: .95rem; opacity: 0; pointer-events: none; transition: .25s; z-index: 30; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#busy { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column; gap: 14px; background: rgba(0, 0, 0, .45); color: #fff; z-index: 40; }
#busy.show { display: flex; }
.spinner { width: 36px; height: 36px; border: 4px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(92vw, 420px); background: var(--card); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dlg-form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.dlg-form h2 { font-size: 1.15rem; }
.dlg-form p { margin: 0; color: var(--muted); }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; }
.dlg-actions.column { flex-direction: column; }
.dlg-actions.column .btn { width: 100%; }

.syncline { flex-basis: 100%; font-size: .85rem; color: var(--muted); }
.syncline.pending { color: var(--primary); font-weight: 600; }
ol.steps { margin: 0 0 10px; padding-left: 20px; color: var(--muted); }
ol.steps li { margin: 4px 0; }

/* Scanner */
body.scanning { overflow: hidden; }
#scanner { display: none; position: fixed; inset: 0; z-index: 60; background: #000; color: #fff; flex-direction: column; }
#scanner.show { display: flex; }
#scanner .sc-live, #scanner .sc-review { position: relative; display: flex; flex-direction: column; flex: 1; min-height: 0; }
#scanner.reviewing .sc-live { display: none; }
.sc-top { display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; }
.sc-btn { min-width: 44px; height: 44px; padding: 0 14px; border: 0; border-radius: 22px; background: rgba(255,255,255,.16); color: #fff; font-size: 1rem; cursor: pointer; }
.sc-btn.on { background: #facc15; color: #000; }
.sc-status { flex: 1; text-align: center; font-weight: 600; font-size: .95rem; }
.sc-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.sc-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.sc-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.sc-overlay { pointer-events: none; }
.sc-stage.flash::after { content: ''; position: absolute; inset: 0; background: #fff; animation: scflash .18s ease-out forwards; }
@keyframes scflash { from { opacity: .85; } to { opacity: 0; } }
.sc-prog { height: 4px; background: rgba(255,255,255,.18); }
.sc-prog > div { height: 100%; width: 0; background: #4ade80; transition: width .12s linear; }
.sc-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px calc(14px + env(safe-area-inset-bottom)); }
.sc-shutter { width: 74px; height: 74px; flex: none; border-radius: 50%; border: 5px solid #fff; background: rgba(255,255,255,.25); cursor: pointer; }
.sc-shutter:active { background: #fff; }
.sc-auto { flex: 1; flex-direction: row; align-items: center; gap: 8px; color: #fff; font-size: .95rem; min-height: 44px; }
.sc-auto input { width: 22px; height: 22px; }
.sc-ok { min-width: 120px; height: 48px; padding: 0 18px; border: 0; border-radius: 12px; background: #1d4ed8; color: #fff; font-size: 1rem; font-weight: 700; cursor: pointer; }
.sc-ok:disabled { opacity: .35; }
.sc-bottom .sc-ok { flex: 1; max-width: 160px; }
.sc-bottom > .sc-auto + .sc-shutter + .sc-ok { margin-left: 0; }
.sc-text { height: 48px; padding: 0 16px; border: 0; background: transparent; color: #fff; font-size: 1rem; cursor: pointer; }
.sc-hint { text-align: center; font-size: .85rem; color: rgba(255,255,255,.7); padding: 6px 12px 0; }
.sc-modes { display: flex; gap: 8px; justify-content: center; padding: 10px 12px 0; }
.sc-modes button { padding: 8px 16px; border: 1px solid rgba(255,255,255,.35); border-radius: 18px; background: transparent; color: #fff; font-size: .95rem; cursor: pointer; }
.sc-modes button.on { background: #fff; color: #000; font-weight: 700; }
.sc-review.working::after { content: 'Wird verarbeitet …'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.65); font-weight: 600; }
.setrow { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
