/* Grundregeln (in der eigenständigen Version nötig) */
:root { color-scheme: light; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
body { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* Layout: schmale Arbeitsspalte, Kennzahlen oben, darunter vier Reiter (Erfassen, Einträge, Monate, Kunden). */
:root {
  --bg: #F1F4F2;
  --surface: #FFFFFF;
  --ink: #1B2622;
  --muted: #5B6862;
  --line: #D6DEDA;
  --accent: #1E6B5A;
  --accent-ink: #FFFFFF;
  --accent-soft: #DCEBE6;
  --warn: #A34A00;
  --warn-soft: #FBE9D6;
  --crit: #B3261E;
  --font-display: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-body: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111715; --surface: #19211E; --ink: #E7EDEA; --muted: #93A19B; --line: #2B3733;
    --accent: #5CC4AB; --accent-ink: #0B1A15; --accent-soft: #1F3A33;
    --warn: #E9A25C; --warn-soft: #3A2A18; --crit: #F28B84;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111715; --surface: #19211E; --ink: #E7EDEA; --muted: #93A19B; --line: #2B3733;
  --accent: #5CC4AB; --accent-ink: #0B1A15; --accent-soft: #1F3A33;
  --warn: #E9A25C; --warn-soft: #3A2A18; --crit: #F28B84;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 15px; line-height: 1.5;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 20px 56px;
}
.wrap { max-width: 1040px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.eyebrow { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
h1 { font-family: var(--font-display); font-size: 34px; line-height: 1.1; margin: 2px 0 0; font-weight: 700; letter-spacing: -.01em; text-wrap: balance; }
h2 { font-family: var(--font-display); font-size: 21px; margin: 0; font-weight: 600; text-wrap: balance; }
h3 { font-size: 13px; margin: 0; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 8px 14px; min-height: 40px; font-weight: 500; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn[disabled] { opacity: .55; cursor: default; }
.linkbtn { border: 0; background: none; padding: 2px 0; color: var(--accent); font-weight: 500; text-align: left; text-decoration: underline; text-underline-offset: 3px; }
.linkbtn.danger { color: var(--crit); }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; min-width: 0; }
.stat .n { font-family: var(--font-display); font-size: 30px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 13px; color: var(--muted); }

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tab { border: 0; background: none; padding: 10px 14px; font-weight: 500; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 18px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.section { display: flex; flex-direction: column; gap: 16px; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }

form { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 13px; font-weight: 600; }
.c2 { grid-column: span 2; } .c3 { grid-column: span 3; } .c4 { grid-column: span 4; } .c6 { grid-column: span 6; }
input, select, textarea { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
textarea { min-height: 64px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.mono { font-family: var(--font-mono); font-size: 14px; }
.actions { grid-column: span 6; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
#status { font-size: 14px; color: var(--accent); min-height: 21px; }
#status.err { color: var(--crit); }
.banner { border: 1px solid var(--warn); background: var(--warn-soft); color: var(--ink); border-radius: 8px; padding: 12px 14px; }

.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.nr { font-family: var(--font-mono); font-size: 13px; white-space: nowrap; }
tfoot td { border-top: 2px solid var(--line); font-weight: 600; }
.pill { display: inline-block; border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px; font-size: 13px; background: var(--bg); }
.pill.warn { border-color: var(--warn); color: var(--warn); background: var(--warn-soft); }
.note { display: block; font-size: 13px; color: var(--muted); margin-top: 3px; }
.track { background: var(--accent-soft); border-radius: 3px; height: 8px; min-width: 70px; }
.fill { background: var(--accent); height: 100%; border-radius: 3px; }
.barcell { display: grid; grid-template-columns: 2.5ch minmax(70px, 1fr); gap: 8px; align-items: center; font-variant-numeric: tabular-nums; }
.barcell .v { text-align: right; }
.zero { color: var(--muted); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filters input[type="search"] { max-width: 320px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); border-radius: 999px; padding: 3px 6px 3px 12px; font-size: 14px; }
.chip button { border: 0; background: none; font-size: 16px; line-height: 1; padding: 2px 6px; }
.twocol { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.mini { display: flex; flex-direction: column; gap: 10px; }
.mini .row { display: grid; grid-template-columns: minmax(0, 1fr) 90px 3.5ch; gap: 10px; align-items: center; }
.mini .row span:first-child { overflow-wrap: anywhere; }
.empty { border: 1px dashed var(--line); border-radius: 8px; padding: 28px 18px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-family: var(--font-display); font-size: 18px; margin-bottom: 4px; }

.positions { grid-column: span 6; display: flex; flex-direction: column; gap: 10px; }
.poslist { display: flex; flex-direction: column; gap: 10px; }
.posrow { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 4fr) minmax(0, 1.3fr) auto; gap: 10px; align-items: end; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.posrow .field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.posrow input { background: var(--surface); }
.pd { min-height: 40px; }
.pos { display: grid; grid-template-columns: minmax(7ch, auto) minmax(0, 1fr) auto; gap: 8px; padding: 1px 0; }
.pos .nr { font-family: var(--font-mono); font-size: 13px; }
.pos .q { font-variant-numeric: tabular-nums; white-space: nowrap; }
.hint { font-size: 13px; color: var(--warn); margin-top: 2px; }
.ksform { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) auto; gap: 14px; align-items: end; }
.ksact { display: flex; flex-wrap: wrap; gap: 10px; }
#ks-status { font-size: 14px; color: var(--accent); min-height: 21px; }
#ks-status.err { color: var(--crit); }
#ks-suche { max-width: 320px; }

.testnote { font-size: 13px; color: var(--muted); border: 1px dashed var(--line); border-radius: 8px; padding: 8px 12px; }
.imgbox { grid-column: span 6; display: flex; flex-direction: column; gap: 10px; }
.imgbox { border: 2px dashed var(--line); border-radius: 8px; padding: 14px; transition: border-color .15s, background-color .15s; }
.imgbox.over { border-color: var(--accent); background: var(--accent-soft); }
.dzhint { font-size: 14px; color: var(--muted); }
.imgbox.over .dzhint { color: var(--ink); font-weight: 600; }
.imgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.imgs:empty { display: none; }
.thumb { position: relative; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--bg); }
.thumb img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.thumb .rm { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; min-height: 0; padding: 0; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); line-height: 1; font-size: 16px; }
.thumb .cap { font-size: 12px; color: var(--muted); padding: 4px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.imgbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
#img-status { font-size: 14px; color: var(--muted); }
#img-status.err { color: var(--crit); }
.after { display: inline-flex; gap: 10px; align-items: center; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(18px + env(safe-area-inset-bottom, 0px)); max-width: min(92vw, 520px); background: var(--ink); color: var(--bg); border-radius: 8px; padding: 10px 16px; font-size: 14px; z-index: 20; }
.toast.err { background: var(--crit); color: #fff; }
.note b { font-weight: 600; }
.acts { display: flex; flex-wrap: wrap; gap: 4px 14px; min-width: 190px; }
@media (max-width: 720px) {
  h1 { font-size: 28px; }
  .posrow { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .posrow .pn { order: 1; } .posrow .pq { order: 2; }
  .posrow .pa { order: 3; grid-column: 1 / -1; }
  .posrow .pd { order: 4; grid-column: 1 / -1; }
  .stat .n { font-size: 24px; }
  .c2, .c3, .c4 { grid-column: span 6; }
  .c2.half, .c3.half { grid-column: span 3; }
  .twocol { grid-template-columns: 1fr; }
  .ksform { grid-template-columns: 1fr; }
  .card { padding: 14px; }
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.stack td { border: 0; padding: 3px 0; display: flex; gap: 10px; justify-content: space-between; text-align: right; }
  table.stack td::before { content: attr(data-l); color: var(--muted); font-size: 13px; text-align: left; flex: none; }
  table.stack td.wide { display: block; text-align: left; }
  table.stack td.wide::before { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.who { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.who .me { font-weight: 600; }
.who .me small { font-weight: 400; color: var(--muted); }
a.btn { display: inline-flex; align-items: center; text-decoration: none; color: inherit; }
input[type="checkbox"] { width: auto; min-height: 0; accent-color: var(--accent); }
.chk { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; min-height: 40px; }
.usform { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; align-items: end; }
.usact { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.pwform { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; align-items: end; max-width: 760px; }
#us-status, #kt-status, #as-status { font-size: 14px; color: var(--accent); min-height: 21px; }
#us-status.err, #kt-status.err, #as-status.err { color: var(--crit); }
.login { min-height: 70vh; display: grid; place-items: center; }
.login .card { width: min(100%, 380px); }
.login form { display: flex; flex-direction: column; gap: 14px; }
#lg-err { color: var(--crit); font-size: 14px; min-height: 21px; }
@media (max-width: 720px) {
  .usform, .pwform { grid-template-columns: 1fr; }
}
