:root {
  --paper: #f6f3ee;
  --surface: #fffdf9;
  --sunk: #efeae2;
  --ink: #1d1b19;
  --muted: #6b655e;
  --faint: #9a938a;
  --rule: #e2dcd2;
  --accent: #9a3b26;
  --accent-ink: #fffdf9;
  --accent-soft: #f3e3dc;
  --ok: #2f6b45;
  --ok-soft: #e1eee4;
  --warn: #9a6a12;
  --warn-soft: #f6ead0;
  --bad: #a3271f;
  --bad-soft: #f6dedb;
  --shadow: 0 1px 2px rgb(40 30 20 / 6%), 0 6px 20px rgb(40 30 20 / 6%);
  --radius: 16px;
  --nav-h: 72px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #171513;
    --surface: #211e1b;
    --sunk: #2a2622;
    --ink: #f1ece4;
    --muted: #b0a89d;
    --faint: #7d766c;
    --rule: #37322c;
    --accent: #d0684c;
    --accent-ink: #1a0f0b;
    --accent-soft: #3a241d;
    --ok: #7cc495;
    --ok-soft: #1f3326;
    --warn: #e0b057;
    --warn-soft: #3a2f18;
    --bad: #f08a80;
    --bad-soft: #3d201d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.55 "IBM Plex Sans Arabic", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.num, .ltr { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }

/* Shell */
.shell { max-width: 760px; margin: 0 auto; padding: 0 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: center; gap: 12px; padding: calc(18px + env(safe-area-inset-top)) 0 14px; }
.top h1 { font-size: 24px; font-weight: 700; margin: 0; flex: 1; line-height: 1.25; }
.top .sub { color: var(--muted); font-size: 14px; font-weight: 400; display: block; }
.back { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--sunk); display: grid; place-items: center; cursor: pointer; flex: none; }
.back svg { transform: scaleX(-1); }

.nav {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--rule);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-in { max-width: 760px; margin: 0 auto; height: var(--nav-h); display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; }
.nav a, .nav button { display: grid; justify-items: center; gap: 2px; font-size: 12px; color: var(--muted); background: none; border: 0; padding: 6px 0; cursor: pointer; }
.nav a.on { color: var(--accent); font-weight: 600; }
.nav .add { width: 58px; height: 58px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; margin: -22px auto 0; box-shadow: 0 6px 18px rgb(154 59 38 / 35%); }

/* Blocks */
.section { margin: 22px 0 10px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.section h2 { font-size: 15px; font-weight: 600; color: var(--muted); margin: 0; }
.section a, .section button.link { font-size: 14px; color: var(--accent); background: none; border: 0; cursor: pointer; padding: 0; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--rule); }
.pad { padding: 16px; }
.stack > * + * { margin-top: 12px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { padding: 14px 16px; display: block; }
.tile .label { font-size: 13px; color: var(--muted); }
.tile .value { font-size: 24px; font-weight: 700; margin-top: 2px; }
.tile .hint { font-size: 13px; color: var(--faint); }
.tile.accent { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.tile.accent .label, .tile.accent .hint { color: color-mix(in srgb, var(--accent-ink) 80%, transparent); }
.tile.bad .value { color: var(--bad); }

.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.quick button { border: 1px solid var(--rule); background: var(--surface); border-radius: var(--radius); padding: 14px 6px; display: grid; justify-items: center; gap: 6px; cursor: pointer; font-size: 14px; font-weight: 600; box-shadow: var(--shadow); }
.quick button svg { color: var(--accent); }

.chart { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; align-items: end; height: 120px; padding: 6px 4px 0; }
.bar { display: grid; gap: 4px; justify-items: center; height: 100%; align-content: end; }
.bar i { display: block; width: 100%; max-width: 38px; border-radius: 8px 8px 3px 3px; background: var(--sunk); min-height: 4px; }
.bar.now i { background: var(--accent); }
.bar span { font-size: 12px; color: var(--muted); }

/* Lists */
.list { overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--rule); cursor: pointer; min-height: 64px; }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--sunk); }
.row .main { flex: 1; min-width: 0; overflow: hidden; }
.row .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .end { text-align: left; flex: none; }
.row .amt { font-weight: 600; }
.mark { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex: none; background: var(--sunk); color: var(--muted); font-weight: 700; font-size: 15px; }
.mark.rechnung { background: var(--accent-soft); color: var(--accent); }
.mark.quittung { background: var(--ok-soft); color: var(--ok); }
.mark.angebot { background: var(--warn-soft); color: var(--warn); }
.mark.storno { background: var(--bad-soft); color: var(--bad); }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 18px; margin-bottom: 4px; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--sunk); color: var(--muted); white-space: nowrap; }
.badge.open { background: var(--warn-soft); color: var(--warn); }
.badge.overdue, .badge.cancelled, .badge.declined, .badge.failed { background: var(--bad-soft); color: var(--bad); }
.badge.paid, .badge.accepted, .badge.done { background: var(--ok-soft); color: var(--ok); }
.badge.draft { background: var(--sunk); color: var(--muted); border: 1px dashed var(--faint); }
.badge.queued, .badge.printing { background: var(--accent-soft); color: var(--accent); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--rule); background: var(--surface); border-radius: 999px; padding: 7px 14px; white-space: nowrap; cursor: pointer; font-size: 15px; }
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip.add { border-style: dashed; color: var(--accent); border-color: var(--accent); }

/* Forms */
label.f { display: block; }
label.f > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 5px; }
.in, select.in, textarea.in {
  width: 100%; min-height: 50px; padding: 11px 14px; border-radius: 12px;
  border: 1px solid var(--rule); background: var(--surface); outline: none;
}
textarea.in { min-height: 84px; resize: vertical; }
.in:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 2fr; gap: 12px; }
.search { position: relative; }
.search svg { position: absolute; top: 50%; right: 14px; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search .in { padding-right: 44px; }
.toggle { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--rule); border-radius: 12px; background: var(--surface); cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.toggle .main { flex: 1; }
.toggle small { display: block; color: var(--muted); font-size: 13px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--sunk); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: none; border-radius: 9px; padding: 9px 4px; cursor: pointer; font-size: 15px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

/* Items editor */
.item { padding: 14px 16px; border-bottom: 1px solid var(--rule); }
.item:last-of-type { border-bottom: 0; }
.item-top { display: flex; gap: 8px; align-items: flex-start; }
.item-top .in { flex: 1; }
.item-bottom { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.stepper { display: flex; align-items: center; border: 1px solid var(--rule); border-radius: 12px; overflow: hidden; background: var(--surface); flex: none; }
.stepper button { width: 42px; height: 46px; border: 0; background: var(--sunk); cursor: pointer; font-size: 20px; }
.stepper input { width: 52px; height: 46px; border: 0; text-align: center; background: none; outline: none; }
.price { position: relative; flex: 1; }
.price .in { padding-left: 34px; text-align: left; direction: ltr; }
.price::after { content: "€"; position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.line-sum { min-width: 86px; text-align: left; font-weight: 600; flex: none; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: none; color: var(--faint); cursor: pointer; display: grid; place-items: center; flex: none; }
.icon-btn:hover { background: var(--sunk); color: var(--ink); }
.icon-btn.on { color: var(--warn); }

.totals { padding: 16px; display: grid; gap: 6px; }
.totals .r { display: flex; justify-content: space-between; color: var(--muted); }
.totals .r.big { color: var(--ink); font-size: 22px; font-weight: 700; border-top: 1px solid var(--rule); padding-top: 10px; margin-top: 4px; }

/* Buttons */
.btn { min-height: 52px; border-radius: 14px; border: 1px solid var(--rule); background: var(--surface); padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.dark { background: var(--ink); color: var(--paper); border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: none; color: var(--accent); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions .wide { grid-column: 1 / -1; }
.sticky-bar { position: sticky; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); z-index: 5; margin-top: 18px; display: grid; gap: 10px; }
.sticky-bar .btn { box-shadow: 0 8px 24px rgb(40 30 20 / 18%); }

.notice { border-radius: 12px; padding: 12px 14px; font-size: 15px; background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }

.preview { width: 100%; display: block; border-radius: 10px; background: #fff; box-shadow: var(--shadow); border: 1px solid var(--rule); min-height: 300px; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 15px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; text-align: left; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.pill.on i { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }

/* Sheet */
.scrim { position: fixed; inset: 0; background: rgb(20 15 10 / 45%); z-index: 40; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; padding: 10px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 88vh; overflow: auto; animation: up .2s ease; }
.sheet .grip { width: 40px; height: 5px; border-radius: 3px; background: var(--rule); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 4px; font-size: 20px; }
.sheet p { margin: 0 0 14px; color: var(--muted); }
.type-pick { display: grid; gap: 10px; }
.type-pick button { display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: 14px; border: 1px solid var(--rule); background: var(--paper); cursor: pointer; text-align: right; }
.type-pick button b { display: block; }
.type-pick button small { color: var(--muted); font-size: 14px; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@media (min-width: 700px) { .scrim { align-items: center; } .sheet { border-radius: 22px; } }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--paper); padding: 11px 18px; border-radius: 12px; font-size: 15px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--bad); color: #fff; }

/* PIN */
.pin { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.pin-box { width: 100%; max-width: 340px; text-align: center; }
.pin-box img { width: 72px; height: 72px; border-radius: 18px; }
.pin-box h1 { font-size: 24px; margin: 14px 0 2px; }
.pin-box p { color: var(--muted); margin: 0 0 22px; }
.dots { display: flex; justify-content: center; gap: 14px; margin-bottom: 26px; height: 16px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--faint); }
.dots i.on { background: var(--ink); border-color: var(--ink); }
.dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; direction: ltr; }
.keys button { height: 68px; border-radius: 18px; border: 1px solid var(--rule); background: var(--surface); font-size: 26px; font-weight: 500; cursor: pointer; }
.keys button:active { background: var(--sunk); }
.keys button.fn { background: none; border-color: transparent; font-size: 16px; color: var(--muted); }

.muted { color: var(--muted); }
.small { font-size: 14px; }
.right { text-align: left; }
code.tok { display: block; direction: ltr; text-align: left; background: var(--sunk); padding: 10px 12px; border-radius: 10px; font-size: 13px; word-break: break-all; }
.hide { display: none !important; }

@media (min-width: 640px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
}

/* Inputs must be allowed to shrink inside grids and flex rows, or the page scrolls sideways on phones. */
.in, .grid2 > *, .grid3 > *, .price, .item-top > *, .stepper input { min-width: 0; }
input[type="date"].in { display: block; -webkit-appearance: none; appearance: none; text-align: right; }
.price { min-width: 92px; }
.shell { overflow-x: clip; }
.stepper button { width: 38px; }
.stepper input { width: 40px; }
.price .in { padding-left: 28px; padding-right: 10px; }
.price::after { left: 11px; }
.line-sum { min-width: 74px; }

.price.need .in { border-color: var(--warn); background: var(--warn-soft); }
.price.need .in::placeholder { color: var(--warn); }
.svc-row { gap: 8px; padding: 10px 12px; }
a.notice { color: var(--warn); font-weight: 600; }
