:root {
  --lime: #8DC63F; --lime-d: #6FA22B; --lime-soft: #EEF6E2;
  --ink: #2A2A2A; --ink2: #1F1F1F; --ash: #6B6B6B; --mist: #E8E8E8;
  --paper: #FAFAF8; --card: #FFFFFF; --warn: #B4531A; --warn-soft: #FBEDE3; --danger: #B3261E;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --head: "Montserrat", "Segoe UI Semibold", "Inter", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #EDEDEA; --ink2: #FFFFFF; --ash: #A3A39E; --mist: #34342F;
    --paper: #171716; --card: #21211F; --lime-soft: #26321A; --warn-soft: #3A2618;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.5 var(--font); -webkit-text-size-adjust: 100%; }
h1, h2, h3 { font-family: var(--head); line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- Grundgerüst ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: #2A2A2A; color: #fff; }
.topbar img { width: 36px; height: 36px; background: #fff; border-radius: 50%; padding: 2px; }
.topbar .title { font-family: var(--head); font-weight: 700; font-size: 1rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title small { display: block; font: 400 .72rem var(--font); color: #BDBDB8; }
.topbar button { background: transparent; border: 1px solid #555; color: #fff; border-radius: 10px; padding: 6px 10px; cursor: pointer; }
.topbar .back { border: none; font-size: 1.35rem; padding: 2px 8px; }
main { max-width: 980px; margin: 0 auto; padding: 16px 16px 120px; }
.savestate { font-size: .75rem; color: #BDBDB8; white-space: nowrap; }
.savestate.err { color: #FFB38A; }

.card { background: var(--card); border: 1px solid var(--mist); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 640px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.muted { color: var(--ash); font-size: .88rem; }
.spacer { flex: 1; }

/* ---------- Formulare ---------- */
label.f { display: block; font-size: .8rem; font-weight: 600; color: var(--ash); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
input[type=text], input[type=date], input[type=number], input[type=email], input[type=tel], input[type=password], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--mist); border-radius: 10px; background: var(--paper); min-height: 44px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--lime); outline-offset: 1px; border-color: transparent; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px;
  border-radius: 12px; border: 1px solid var(--mist); background: var(--card); cursor: pointer; font-weight: 600; text-decoration: none; }
.btn.primary { background: var(--lime); border-color: var(--lime); color: #1F1F1F; }
.btn.dark { background: #2A2A2A; color: #fff; border-color: #2A2A2A; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: .85rem; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.fab { position: fixed; right: 18px; bottom: max(18px, env(safe-area-inset-bottom)); z-index: 30; border-radius: 999px; padding: 14px 20px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); }

/* Chips / Checkboxen */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.chip span { display: inline-flex; align-items: center; min-height: 38px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--mist); background: var(--paper); font-size: .9rem; user-select: none; }
.chip input:checked + span { background: var(--lime); border-color: var(--lime); color: #1F1F1F; font-weight: 600; }
.chip input:focus-visible + span { outline: 2px solid var(--ink); }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; cursor: pointer; }
.check input { width: 24px; height: 24px; accent-color: var(--lime-d); flex: none; margin: 0; }
.check.big { font-weight: 600; }

/* Skala 0–10 */
.scale { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; }
.scale .chip span { justify-content: center; min-width: 0; width: 100%; padding: 6px 0; border-radius: 8px; }

/* ---------- Liste ---------- */
.search { display: flex; gap: 10px; margin-bottom: 14px; }
.clients { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.ccard { display: flex; gap: 12px; align-items: center; text-decoration: none; padding: 12px; margin: 0; }
.avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; background: var(--lime-soft); display: grid; place-items: center;
  font-family: var(--head); font-weight: 700; color: var(--lime-d); flex: none; }
.avatar.lg { width: 96px; height: 96px; font-size: 1.6rem; }
.ccard .meta { min-width: 0; }
.ccard .name { font-weight: 700; }
.progress { height: 6px; background: var(--mist); border-radius: 99px; overflow: hidden; margin-top: 6px; width: 140px; max-width: 100%; }
.progress i { display: block; height: 100%; background: var(--lime); }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--mist); color: var(--ink); vertical-align: middle; }
.badge.lime { background: var(--lime); color: #1F1F1F; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* Tabs */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 14px; padding: 0 16px; scrollbar-width: none; }
.tabs a { flex: none; padding: 8px 14px; border-radius: 999px; text-decoration: none; border: 1px solid var(--mist); background: var(--card); font-weight: 600; font-size: .9rem; }
.tabs a.on { background: #2A2A2A; color: #fff; border-color: #2A2A2A; }

/* Tabellen */
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th, .tbl td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--mist); vertical-align: top; }
.tbl th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ash); }
.tblwrap { overflow-x: auto; }
.st-integriert { color: var(--lime-d); font-weight: 700; }
.st-offen { color: var(--warn); font-weight: 700; }

/* Reflexkarten */
.rcard { padding: 0; overflow: hidden; }
.rhead { display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer; }
.rhead .nr { width: 34px; height: 34px; border-radius: 10px; background: var(--lime-soft); color: var(--lime-d); font-weight: 800; display: grid; place-items: center; flex: none; }
.rhead .rn { font-weight: 700; flex: 1; min-width: 0; }
.rhead .rn small { display: block; font-weight: 400; color: var(--ash); font-size: .8rem; }
.rbody { padding: 0 14px 14px; border-top: 1px solid var(--mist); }
.rcard.collapsed .rbody { display: none; }
.rcard.done { border-color: var(--lime); }
.rcard.done .nr { background: var(--lime); color: #1F1F1F; }
.sec { padding-top: 12px; }
.sec > .lbl { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ash); margin-bottom: 6px; }
.hint { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 8px 10px; font-size: .85rem; margin-top: 10px; }
.sub { margin-left: 34px; }
.affs { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.affs button { text-align: left; border: 1px dashed var(--mist); background: transparent; border-radius: 10px; padding: 8px 10px; cursor: pointer; font-size: .9rem; }
.affs button:hover { border-color: var(--lime); }

/* Unterschrift */
.sigwrap { border: 2px dashed var(--mist); border-radius: 12px; background: #fff; position: relative; touch-action: none; }
.sigwrap canvas { width: 100%; height: 180px; display: block; touch-action: none; cursor: crosshair; }
.sigwrap .line { position: absolute; left: 16px; right: 16px; bottom: 40px; border-bottom: 1px solid #ccc; pointer-events: none; }
.sigimg { max-width: 260px; height: auto; border-bottom: 1px solid var(--ink); }

/* Vertrag */
.vertrag { background: #fff; color: #2A2A2A; padding: 22px; border-radius: var(--radius); border: 1px solid var(--mist); font-size: .95rem; }
.vertrag h1 { font-size: 1.4rem; margin-bottom: 0; }
.vertrag h2 { font-size: 1rem; margin-top: 1.2em; }
.vertrag .v-sub { color: #6B6B6B; margin-top: 2px; }
.vertrag .v-party { margin-left: 12px; }
.vertrag .v-version { color: #6B6B6B; font-size: .8rem; margin-top: 2em; }

.login { max-width: 380px; margin: 12vh auto; text-align: center; }
.login img { width: 120px; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #2A2A2A; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 50; max-width: 90vw; }
.empty { text-align: center; padding: 40px 10px; color: var(--ash); }
svg.spark { width: 100%; height: 70px; }

/* ---------- Druck ---------- */
.printonly { display: none; }
@media print {
  @page { size: A4; margin: 16mm 14mm; }
  html, body { background: #fff !important; color: #2A2A2A !important; font-size: 10.5pt; }
  .topbar, .fab, .noprint, .tabs { display: none !important; }
  .printonly { display: block; }
  main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: none; padding: 0; }
  .vertrag { border: none; padding: 0; }
  .pagebreak { page-break-before: always; }
  .tbl th, .tbl td { padding: 5px 4px; }
  .rcard, tr { break-inside: avoid; }
}
.printhead { display: flex; align-items: center; gap: 12px; border-bottom: 2pt solid var(--lime); padding-bottom: 8px; margin-bottom: 16px; }
.printhead img { width: 54px; }
.printhead .t { font-family: var(--head); font-weight: 700; }

@media (max-width: 640px) { .tbl.mx th:nth-child(5), .tbl.mx td:nth-child(5), .tbl.mx th:nth-child(6), .tbl.mx td:nth-child(6) { display: none; } }
