:root {
  --bg: #f5f6f8; --fg: #1b1f24; --muted: #667085; --card: #fff; --line: #e3e6eb;
  --pri: #1d4ed8; --pri-fg: #fff; --ok: #157f3b; --err: #b42318; --warn: #b54708;
  --ok-bg: #e7f6ec; --err-bg: #fdecea; --warn-bg: #fff4e0;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --fg: #e8eaee; --muted: #9aa3b2; --card: #171a21; --line: #2a2f3a;
    --pri: #4c82f7; --pri-fg: #fff; --ok: #4ade80; --err: #f87171; --warn: #fbbf24;
    --ok-bg: #12301c; --err-bg: #3a1714; --warn-bg: #3a2a0c;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-size: 16px; line-height: 1.45; font-family: var(--font);
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--pri); }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 1.2rem 0 .6rem; }
.card h2:first-child { margin-top: 0; }
.wrap { max-width: 760px; margin: 0 auto; padding: 1rem 16px 3rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.big { font-size: 1.6rem; font-weight: 700; }

/* Kopfzeile */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: calc(.6rem + env(safe-area-inset-top)) 16px .6rem; background: var(--pri); color: var(--pri-fg);
}
.brand { color: inherit; text-decoration: none; font-weight: 700; font-size: 1.1rem; display: inline-flex; align-items: center; gap: .6rem; }
.brand .logo { height: 30px; width: auto; display: block; }
.login-brand { text-align: center; }
.login-brand .logo { max-height: 64px; max-width: 100%; width: auto; display: block; margin: 0 auto .5rem; }
.nav { position: relative; }
.nav summary { list-style: none; cursor: pointer; font-size: 1.6rem; line-height: 1; padding: .2rem .5rem; user-select: none; margin: 0; }
.nav summary::-webkit-details-marker { display: none; }
.nav nav {
  position: absolute; right: 0; top: 2.6rem; min-width: 220px; background: var(--card); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.18); overflow: hidden;
}
.nav nav a, .nav nav button.link {
  display: block; width: 100%; text-align: left; padding: .9rem 1rem; color: var(--fg);
  text-decoration: none; border: 0; border-bottom: 1px solid var(--line); background: none; font: inherit; cursor: pointer;
}
.nav nav form { margin: 0; }

/* Karten und Listen */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin: 0 0 .9rem; }
.card.narrow { max-width: 440px; margin: 2rem auto; }
.link-card { display: block; color: inherit; text-decoration: none; }
.row { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .35rem 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; }
.card > .row + .row { border-top: 1px solid var(--line); }
.scroll { overflow-x: auto; }
.tag { display: inline-block; padding: .05rem .5rem; border-radius: 999px; background: var(--line); font-size: .78rem; vertical-align: middle; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: .8rem 0 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }
form.inline { display: inline; margin: 0; }

/* Formulare */
label { display: block; margin: 0 0 .9rem; font-weight: 600; font-size: .95rem; }
label.check { display: flex; align-items: center; gap: .6rem; font-weight: 400; min-height: 44px; }
input, select, textarea {
  display: block; width: 100%; margin-top: .3rem; padding: .75rem .8rem; font: inherit; color: var(--fg);
  background: var(--bg); border: 1px solid var(--line); border-radius: calc(var(--radius) * .7); min-height: 46px;
}
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; margin: 0; }
input[type="color"] { padding: .2rem; height: 46px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--pri); outline-offset: 1px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 46px; padding: .6rem 1.1rem;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; color: var(--fg);
  background: var(--card); border: 1px solid var(--line); border-radius: calc(var(--radius) * .7);
}
.btn.primary { background: var(--pri); border-color: var(--pri); color: var(--pri-fg); }
.btn.danger { color: var(--err); border-color: var(--err); }
.btn[disabled] { opacity: .55; cursor: default; }
.btn.block { display: flex; width: 100%; }
.bigbtn { min-height: 64px; font-size: 1.1rem; gap: .6rem; }
details > summary { cursor: pointer; margin: .5rem 0 1rem; }

/* Meldungen */
.flash { padding: .8rem 1rem; border-radius: calc(var(--radius) * .7); margin: 0 0 1rem; border: 1px solid; }
.flash.ok { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.flash.error { background: var(--err-bg); border-color: var(--err); color: var(--err); }
.flash.warn { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }

/* Tabellen */
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
pre { overflow-x: auto; padding: .7rem; background: var(--bg); border-radius: 8px; font-size: .85rem; }

/* Dokumentenliste */
.doc { display: block; color: inherit; text-decoration: none; padding: .7rem 0; border-top: 1px solid var(--line); }
.doc:first-of-type { border-top: 0; }
.doc .t { font-weight: 600; }
.pager { display: flex; justify-content: space-between; gap: .6rem; margin-top: .8rem; }

/* Scannen */
.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: .6rem; margin: .8rem 0; }
.page-thumb { position: relative; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--bg); aspect-ratio: 3 / 4; }
.page-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.page-thumb .num { position: absolute; left: 4px; top: 4px; background: rgba(0,0,0,.65); color: #fff; font-size: .75rem; padding: 0 .45rem; border-radius: 999px; }
.page-thumb .x { position: absolute; right: 3px; top: 3px; width: 28px; height: 28px; border: 0; border-radius: 999px; background: rgba(0,0,0,.65); color: #fff; font-size: 1rem; line-height: 1; cursor: pointer; }
.page-thumb .mv { position: absolute; bottom: 3px; display: flex; gap: 3px; right: 3px; }
.page-thumb .mv button { width: 26px; height: 26px; border: 0; border-radius: 6px; background: rgba(0,0,0,.65); color: #fff; cursor: pointer; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.result { text-align: center; }
.result .loc { font-size: 2rem; font-weight: 800; margin: .4rem 0; }
.spinner { display: inline-block; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.editor { position: fixed; inset: 0; z-index: 50; background: #000; color: #fff; display: flex; flex-direction: column; }
.editor[hidden] { display: none; }
.editor .head { padding: calc(.5rem + env(safe-area-inset-top)) 1rem .5rem; text-align: center; font-weight: 600; background: #111; }
.editor .stage { flex: 1; position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; touch-action: none; }
.editor canvas { max-width: 100%; max-height: 100%; touch-action: none; }
.editor .bar { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; padding: .6rem; padding-bottom: calc(.6rem + env(safe-area-inset-bottom)); background: #111; }
.editor .btn { background: #262626; color: #fff; border-color: #3a3a3a; min-height: 44px; }
.editor .btn.primary { background: var(--pri); border-color: var(--pri); color: var(--pri-fg); }
.editor .btn.on { outline: 2px solid var(--pri); }
.editor .busy { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.55); font-size: 1.1rem; gap: .6rem; }
.editor .busy[hidden] { display: none; }

/* Erscheinungsbild-Vorschau */
.swatch { display: inline-block; width: 1.1em; height: 1.1em; border-radius: 4px; vertical-align: -3px; border: 1px solid var(--line); }
.logo-preview { max-height: 64px; max-width: 100%; display: block; margin: .4rem 0; background: var(--bg); padding: .4rem; border-radius: 8px; }
