/* FZ-Office – mobile first, hell/dunkel automatisch */
:root {
  --bg: #f4f4f2; --surface: #ffffff; --surface2: #ecebe8; --text: #1b1c1e; --muted: #6b6d72;
  --line: #dedcd7; --accent: #1b1c1e; --accent-text: #fff; --brand: #c8a45a;
  --ok: #2f7d4f; --warn: #b7791f; --bad: #b4382f; --info: #2b6cb0;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --side: 232px; --top: 56px; --tab: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111214; --surface: #1a1b1e; --surface2: #232428; --text: #ececea; --muted: #9a9ca2;
    --line: #2c2d31; --accent: #ececea; --accent-text: #111214; --shadow: none; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }
h1 { font-size: 1.45rem; margin: 0; letter-spacing: -.01em; }
h1 small { color: var(--muted); font-weight: 500; font-size: .9rem; margin-left: .3rem; }
h2 { font-size: 1.02rem; margin: 1.6rem 0 .6rem; }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
.logo { font-family: ui-monospace, "Courier New", monospace; font-weight: 700; }

/* --- Layout --- */
.topbar { position: sticky; top: 0; z-index: 20; height: calc(var(--top) + var(--safe-t)); padding: var(--safe-t) 14px 0;
  display: flex; align-items: center; gap: 12px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px); border-bottom: 1px solid var(--line); }
.brand { text-decoration: none; font-weight: 650; white-space: nowrap; }
.brand .logo { color: var(--brand); }
.topsearch { flex: 1; }
.topsearch input { width: 100%; }
.sidebar { display: none; }
.main { padding: 16px 14px calc(var(--tab) + var(--safe-b) + 24px); max-width: 1280px; margin: 0 auto; }
.main.bare { padding-bottom: 24px; }

.tabbar { position: fixed; inset: auto 0 0 0; z-index: 30; height: calc(var(--tab) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; justify-content: space-around; align-items: center; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line); }
.tabbar a { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; text-decoration: none;
  color: var(--muted); font-size: 11px; padding: 6px 0; }
.tabbar a i { font-style: normal; font-size: 20px; line-height: 1.1; }
.tabbar a.on { color: var(--text); }
.tabbar .fab { flex: 0 0 auto; width: 52px; height: 52px; border-radius: 50%; background: var(--accent); color: var(--accent-text);
  justify-content: center; margin-top: -18px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.tabbar .fab i { font-size: 26px; }
.count { position: absolute; top: 2px; left: calc(50% + 6px); background: var(--bad); color: #fff; font-size: 10px; font-weight: 700;
  border-radius: 9px; padding: 0 5px; min-width: 16px; text-align: center; }

/* Mobile-Drawer (Mehr) */
body.nav-open .sidebar { display: flex; position: fixed; z-index: 40; inset: 0 30% 0 0; max-width: 300px; padding-top: calc(var(--safe-t) + 16px);
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }

@media (min-width: 900px) {
  .tabbar { display: none; }
  .sidebar { display: flex; position: fixed; top: calc(var(--top) + var(--safe-t)); bottom: 0; left: 0; width: var(--side); }
  body.nav-open .sidebar { position: fixed; inset: calc(var(--top) + var(--safe-t)) auto 0 0; box-shadow: none; padding-top: 12px; }
  .main { margin-left: var(--side); padding: 24px 32px 48px; max-width: none; }
  .topsearch { max-width: 520px; }
}
.sidebar { flex-direction: column; gap: 2px; padding: 12px 10px; background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto; }
.sidebar a { position: relative; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; text-decoration: none; color: var(--muted); }
.sidebar a i { font-style: normal; width: 20px; text-align: center; }
.sidebar a.on, .sidebar a:hover { background: var(--surface2); color: var(--text); }
.sidebar .count { position: static; margin-left: auto; }
.navsep { margin: 14px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.navfoot { margin-top: auto; padding: 12px 10px 4px; border-top: 1px solid var(--line); display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

/* --- Elemente --- */
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.pagehead .actions { display: flex; gap: 8px; }
.doc-title { overflow-wrap: anywhere; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-weight: 550; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.linkbtn { background: none; border: 0; padding: 0; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; text-align: left; }
input, select, textarea { font: inherit; font-size: 16px; /* kein iOS-Zoom */ color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; min-height: 40px; width: 100%; }
input[type=checkbox] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
input[type=color] { padding: 2px; width: 60px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 60%, transparent); outline-offset: 1px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { color: var(--text); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
label.check.small { font-size: 12px; color: var(--muted); }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 12px; min-width: 0; }
.stack { display: grid; gap: 12px; }
.narrow { max-width: 560px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inline { display: inline; }
.hint { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 12px 0; }
.badge.ro { font-size: 11px; padding: 3px 8px; border-radius: 6px; background: var(--surface2); color: var(--muted); white-space: nowrap; }
.small { font-size: 12px; color: var(--muted); }
.hide-sm { display: none; }
@media (min-width: 700px) { .hide-sm { display: table-cell; } }

.messages { display: grid; gap: 8px; margin-bottom: 14px; }
.msg { padding: 10px 12px; border-radius: 10px; background: var(--surface); border-left: 4px solid var(--info); font-size: 14px; }
.msg.success { border-color: var(--ok); } .msg.warning { border-color: var(--warn); } .msg.error { border-color: var(--bad); }

.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 6px; background: var(--surface2); color: var(--muted); }
.pill.ok, .pill.done { color: var(--ok); } .pill.failed { color: var(--bad); } .pill.processing, .pill.running, .pill.pending { color: var(--warn); }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 20px; margin: 0 3px 3px 0;
  color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); border: 1px solid color-mix(in srgb, var(--c) 35%, transparent); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-decoration: none; display: grid; box-shadow: var(--shadow); }
.stat b { font-size: 1.6rem; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: 12px; }
.stat.warn b { color: var(--warn); }
.roadmap ul { color: var(--muted); padding-left: 18px; }

/* Karten */
.cards { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 700px) { .cards { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); } }
.card { position: relative; display: grid; grid-template-columns: 64px 1fr; gap: 12px; padding: 10px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.inbox { border-left: 3px solid var(--brand); }
.card .thumb { width: 64px; height: 84px; border-radius: 6px; overflow: hidden; background: var(--surface2); display: flex; align-items: center; justify-content: center; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.card .ph { font-size: 24px; color: var(--muted); }
.card .body { text-decoration: none; min-width: 0; }
.card h3 { margin: 0 0 2px; font-size: 14.5px; font-weight: 620; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .meta { margin: 0 0 4px; font-size: 12px; color: var(--muted); }
.card .tags { margin: 0; }
.card .sel { position: absolute; top: 8px; right: 8px; }

/* Filter + Sammelaktion */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.filters input[type=search] { grid-column: 1 / -1; }
@media (min-width: 900px) { .filters { grid-template-columns: 2fr repeat(4, 1fr) auto auto; } .filters input[type=search] { grid-column: auto; } }
.bulk { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.bulk select { width: auto; flex: 1 1 160px; }
.selall { display: flex; align-items: center; gap: 6px; color: var(--text); }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 18px; color: var(--muted); }

/* Upload */
.upload { display: grid; gap: 14px; max-width: 640px; }
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px 14px; text-align: center; background: var(--surface); }
.dropzone.over { border-color: var(--brand); }
.dropzone .big { margin: 0 0 12px; color: var(--muted); }
.pickrow { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.picked { list-style: none; padding: 0; margin: 12px 0 0; text-align: left; font-size: 13px; }
.picked li { padding: 4px 0; border-bottom: 1px solid var(--line); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chips legend, .chips .lbl { width: 100%; font-size: 13px; color: var(--muted); margin-bottom: 2px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 20px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 13px; }
.chip input { width: 16px; height: 16px; }
.chip:has(input:checked) { border-color: var(--accent); background: var(--surface2); }

/* Detail */
.detail { display: grid; gap: 16px; }
@media (min-width: 1100px) { .detail { grid-template-columns: minmax(0, 1.3fr) minmax(360px, 1fr); align-items: start; } .preview { position: sticky; top: calc(var(--top) + 16px); } }
.preview { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.preview img { display: block; width: 100%; max-height: 70vh; object-fit: contain; background: #fff; }
.preview iframe.pdf { display: block; width: 100%; height: calc(100vh - 150px); border: 0; background: #fff; }
.preview a.show-touch { display: grid; gap: 0; text-decoration: none; }
.preview a.show-touch .btn { border-radius: 0; border-width: 1px 0 0; }
.show-touch { display: none !important; }
@media (hover: none), (max-width: 899px) { .hide-touch { display: none !important; } .show-touch { display: grid !important; } }
.meta-panel { display: grid; gap: 4px; min-width: 0; }
.meta-panel h2 { margin-top: 1.2rem; }
.metaform, .fieldsform, .noteform { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.noteform { display: grid; gap: 8px; }
.fieldrow { display: grid; gap: 2px; }
.fieldrow small { font-weight: 400; }
.note { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-top: 6px; }
.note p { margin: 0 0 4px; } .note small { color: var(--muted); }
.infobox { margin-top: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.infobox summary { cursor: pointer; font-weight: 600; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.history { list-style: none; padding: 0; font-size: 12px; display: grid; gap: 6px; }
.history code { display: block; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
pre.ocr, pre.log { white-space: pre-wrap; font: 12px/1.4 ui-monospace, Menlo, monospace; max-height: 420px; overflow: auto; background: var(--surface2); padding: 10px; border-radius: 8px; }
.danger-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; margin-top: 14px; }
.danger-row form { display: flex; gap: 8px; }
.danger-row select { width: auto; }
progress { width: 100%; height: 8px; accent-color: var(--brand); }

/* Tabellen */
.tbl { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface2); }
.tbl tr.bad td { background: color-mix(in srgb, var(--bad) 7%, transparent); }
.seg { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 12px; }
.seg a { padding: 7px 12px; border-radius: 9px; text-decoration: none; color: var(--muted); white-space: nowrap; background: var(--surface); border: 1px solid var(--line); }
.seg a.on { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }

/* Login */
body.login { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: min(360px, 92vw); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 26px; box-shadow: var(--shadow); }
.login-card form { display: grid; gap: 12px; }
.login-brand { font-size: 1.4rem; font-weight: 650; margin-bottom: 18px; text-align: center; }
.login-brand .logo { color: var(--brand); }

/* --- Buchhaltung --- */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 12px; }
.tbl.num td, .tbl.num th { white-space: nowrap; }
.tbl.num td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.small-tbl { font-size: 12.5px; }
.small-tbl td, .small-tbl th { padding: 6px 8px; }
.tbl tr.sum td { background: var(--surface2); }
td.neg { color: var(--bad); } td.pos { color: var(--ok); }
.blist { display: grid; gap: 6px; }
.brow { display: grid; grid-template-columns: 52px 1fr auto; grid-template-areas: "d m a" "d f a"; gap: 2px 10px; align-items: center;
  padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; text-decoration: none; border-left: 3px solid var(--line); }
.brow.E { border-left-color: var(--ok); } .brow.A { border-left-color: var(--bad); }
.bdate { grid-area: d; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.bmain { grid-area: m; min-width: 0; display: grid; }
.bmain b { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bmain small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bflags { grid-area: f; display: flex; gap: 4px; }
.bamt { grid-area: a; text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; display: grid; }
.bamt small { font-weight: 400; color: var(--muted); font-size: 11px; }
.brow.E .bamt { color: var(--ok); }
@media (min-width: 900px) { .brow { grid-template-columns: 70px 1fr auto 130px; grid-template-areas: "d m f a"; } }
.cand { display: grid; gap: 6px; margin-bottom: 12px; }
.suggest { background: color-mix(in srgb, var(--brand) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--brand) 45%, var(--line)); border-radius: var(--radius); padding: 14px; margin-top: 12px; }
.suggest h2 { margin-top: 0; }
.suggest .kv { margin-bottom: 10px; }
.docactions { justify-content: flex-start; margin: 8px 0; } .docactions form { display: inline; }

/* --- Kanban --- */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 82vw); gap: 12px; overflow-x: auto;
  scroll-snap-type: x mandatory; padding-bottom: 12px; -webkit-overflow-scrolling: touch; }
@media (min-width: 900px) { .kanban { grid-auto-columns: minmax(230px, 1fr); scroll-snap-type: none; } }
.kcol { scroll-snap-align: start; background: var(--surface2); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; min-height: 200px; }
.kcol.done { opacity: .75; }
.kcol h3 { margin: 2px 4px 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kcol h3 small { float: right; }
.klist { display: grid; gap: 8px; flex: 1; align-content: start; min-height: 60px; }
.kcard { display: grid; gap: 3px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-decoration: none; box-shadow: var(--shadow); touch-action: manipulation; }
.kcard b { font-size: 14px; font-weight: 600; }
.kcard small { color: var(--muted); font-size: 12px; }
.kcard .prog { color: var(--brand); }
.sortable-ghost { opacity: .35; } .sortable-chosen { box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.checklist { display: grid; gap: 4px; }
.chk { width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; font: inherit; color: var(--text); cursor: pointer; }
.chk.done { color: var(--muted); text-decoration: line-through; }
.lines { display: grid; gap: 10px; }
.chips button.chip { cursor: pointer; font: inherit; font-size: 13px; }
.detail > * { min-width: 0; }
.row2 > * { min-width: 0; }
input, select, textarea { min-width: 0; max-width: 100%; }
@media (max-width: 600px) { .tbl.num th, .tbl.num td { padding: 8px 6px; font-size: 13px; } }
