:root {
  --accent: #b45309;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, white);
  --accent-ink: color-mix(in srgb, var(--accent) 75%, black);
  --bg: #f6f4f0;
  --surface: #ffffff;
  --line: #e7e3dc;
  --ink: #1c1917;
  --ink-2: #57534e;
  --ink-3: #a8a29e;
  --ok: #15803d; --ok-soft: #dcfce7;
  --warn: #a16207; --warn-soft: #fef3c7;
  --bad: #b91c1c; --bad-soft: #fee2e2;
  --info: #1d4ed8; --info-soft: #dbeafe;
  --r: 12px; --r-sm: 8px;
  --nav-h: 64px;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
  padding-top: env(safe-area-inset-top);
}
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 14px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
a { color: var(--accent-ink); }
.muted { color: var(--ink-2); } .small { font-size: 13px; } .tiny { font-size: 12px; color: var(--ink-3); }
.mono { font-variant-numeric: tabular-nums; }
.right { text-align: right; } .grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

/* ── Shell ── */
#app { min-height: 100%; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface);
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; min-height: 56px;
}
.topbar .title { font-weight: 700; font-size: 17px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 14px; }
main { padding: 16px 14px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 1000px; margin: 0 auto; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface);
  border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a, .sidenav a {
  text-decoration: none; color: var(--ink-3); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; font-size: 11px; font-weight: 600; height: var(--nav-h);
}
.bottomnav a.active { color: var(--accent); }
.sidenav { display: none; }

@media (min-width: 900px) {
  .bottomnav { display: none; }
  .sidenav {
    display: flex; flex-direction: column; gap: 2px; position: fixed; top: 0; bottom: 0; left: 0; width: 230px;
    background: #1c1917; padding: 18px 12px; z-index: 30;
  }
  .sidenav .brand { color: #fff; padding: 4px 8px 20px; }
  .sidenav a { flex-direction: row; justify-content: flex-start; gap: 12px; height: 42px; padding: 0 12px; font-size: 14px; color: #d6d3d1; border-radius: 8px; }
  .sidenav a:hover { background: #292524; }
  .sidenav a.active { background: var(--accent); color: #fff; }
  .sidenav .spacer { flex: 1; }
  .sidenav .who { color: #a8a29e; font-size: 12px; padding: 8px 12px; }
  .topbar, main { margin-left: 230px; }
  main { padding: 24px 28px 40px; }
  .topbar { padding: 12px 28px; }
  .topbar .menu-only { display: none; }
}

/* ── Cards / lists ── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.card + .card { margin-top: 12px; }
.card > h3:first-child { margin-bottom: 12px; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; text-decoration: none; color: inherit; }
.item:last-child { border-bottom: 0; }
.item:hover { background: #faf9f7; }
.item .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .s { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; flex-shrink: 0; font-weight: 700; font-size: 13px; }
.empty { padding: 36px 16px; text-align: center; color: var(--ink-3); }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.stat .n { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--ink-2); }

.quick { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.quick button { height: 76px; flex-direction: column; font-size: 14px; }

/* ── Badges / chips ── */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.b-offen { background: var(--warn-soft); color: var(--warn); }
.b-verrechnet, .b-bezahlt { background: var(--ok-soft); color: var(--ok); }
.b-versendet { background: var(--info-soft); color: var(--info); }
.b-storniert { background: #e7e5e4; color: var(--ink-2); }
.b-ueberfaellig { background: var(--bad-soft); color: var(--bad); }
.b-type { background: #f5f5f4; color: var(--ink-2); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; white-space: nowrap; cursor: pointer; color: var(--ink-2); }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ── Forms ── */
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff; border: 1px solid #d6d3d1;
  border-radius: var(--r-sm); padding: 10px 12px; min-height: 42px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 84px; resize: vertical; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
input[type=color] { padding: 2px; height: 42px; }
.check { display: flex; gap: 10px; align-items: center; font-size: 14px; font-weight: 500; color: var(--ink); margin: 8px 0; }
.field { margin-bottom: 12px; }
.seg { display: inline-flex; background: #f5f5f4; border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; min-height: 34px; padding: 0 14px; font-weight: 600; color: var(--ink-2); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

button, .btn {
  font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: var(--r-sm); border: 1px solid #d6d3d1; background: #fff;
  color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap;
}
button:active { transform: scale(.98); }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.danger { color: var(--bad); border-color: #fecaca; background: #fff; }
.ghost { border-color: transparent; background: transparent; }
.icon-btn { width: 40px; padding: 0; }
.block { width: 100%; }
.actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (min-width: 700px) { .actions { display: flex; flex-wrap: wrap; } }
.sticky-actions { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 8px; display: flex; gap: 8px; z-index: 5; }
.sticky-actions button { flex: 1; }
@media (min-width: 900px) { .sticky-actions { bottom: 0; } }
svg.i { width: 20px; height: 20px; flex-shrink: 0; }

/* ── Editor ── */
.line { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px; background: #fcfbfa; }
.line + .line { margin-top: 10px; }
.line .head { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.line .num { width: 26px; height: 26px; border-radius: 6px; background: var(--ink); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex-shrink: 0; margin-top: 8px; }
.line .lt { font-weight: 700; font-variant-numeric: tabular-nums; }
.line .fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (min-width: 700px) { .line .fields { grid-template-columns: 90px 100px 120px 110px minmax(0, 1fr); } }
.line .fields label { font-size: 11px; }
.totals { font-variant-numeric: tabular-nums; }
.totals .tr { display: flex; justify-content: space-between; padding: 3px 0; font-size: 14px; color: var(--ink-2); }
.totals .tr.big { font-size: 19px; font-weight: 800; color: var(--ink); border-top: 2px solid var(--accent); margin-top: 6px; padding-top: 8px; }

.picker { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--r-sm); margin-top: 8px; background: #fff; }
.picker .item { padding: 10px 12px; }
.custcard { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border: 1px solid var(--accent); background: var(--accent-soft); border-radius: var(--r-sm); }

.sig { border: 2px dashed #d6d3d1; border-radius: var(--r-sm); background: #fff; position: relative; touch-action: none; }
.sig canvas { display: block; width: 100%; height: 190px; touch-action: none; }
.sig .hint { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-3); pointer-events: none; font-size: 14px; }
.sig .baseline { position: absolute; left: 20px; right: 20px; bottom: 40px; border-bottom: 1px solid #e7e5e4; pointer-events: none; }

/* ── Modal / toast ── */
.modal-bg { position: fixed; inset: 0; background: rgba(28,25,23,.5); z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-width: 620px; max-height: 92vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); animation: up .22s ease; }
@media (min-width: 700px) { .modal-bg { align-items: center; } .modal { border-radius: 16px; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal .mh { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600; z-index: 200; max-width: 90vw; text-align: center; }
.toast.err { background: var(--bad); }

/* ── Login ── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: #1c1917; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login .brand { justify-content: center; font-size: 20px; margin-bottom: 18px; }

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 16px; scrollbar-width: none; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; color: var(--ink-2); padding: 0 12px; }
.tabs button.on { color: var(--accent-ink); border-bottom-color: var(--accent); }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--ink-2); } .kv dd { margin: 0; font-weight: 600; }
.ph { font-family: ui-monospace, monospace; font-size: 12px; background: #f5f5f4; padding: 1px 5px; border-radius: 4px; }

/* Feinschliff schmale Bildschirme */
.quick button, .actions button, .actions .btn { white-space: normal; text-align: center; line-height: 1.2; padding: 6px 10px; }
.quick button { font-size: 13px; }
.bottomnav a span { font-size: 10px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.nowrap { white-space: nowrap; }
