:root {
  --brand: #13447C;
  --brand-2: #1d5ea8;
  --brand-soft: #e7eef7;
  --bg: #f2f4f7;
  --card: #ffffff;
  --text: #1b2430;
  --muted: #677283;
  --line: #e1e5ea;
  --bad: #c62828;
  --bad-soft: #fdecec;
  --ok: #2e7d32;
  --ok-soft: #e8f5e9;
  --warn: #ef8f00;
  --warn-soft: #fff4e0;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
/* Kein Zoom bei schnellem Doppeltippen (iOS); Zoomen mit zwei Fingern bleibt möglich */
html, button, input, textarea, select, a, label { touch-action: manipulation; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; font-size: 16px; color: var(--text); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand); color: #fff;
  padding: calc(var(--safe-top) + 8px) 12px 10px;
  display: flex; align-items: center; gap: 8px; min-height: 52px;
}
.topbar h1 { font-size: 17px; font-weight: 600; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { display: block; font-size: 12px; font-weight: 400; opacity: .8; }
.topbar .tb-btn {
  background: rgba(255,255,255,.14); border: 0; color: #fff; border-radius: 10px;
  padding: 8px 12px; font-size: 15px; display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0;
}
.topbar .tb-btn:active { background: rgba(255,255,255,.3); }
.topbar img.logo { width: 32px; height: 32px; border-radius: 50%; background: #fff; }

/* ---------- Layout ---------- */
.page { padding: 14px 14px calc(var(--safe-bottom) + 110px); max-width: 760px; margin: 0 auto; }
.page.no-tabs { padding-bottom: calc(var(--safe-bottom) + 40px); }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(16,24,40,.05); }
#nd-kunde { scroll-margin-top: calc(var(--safe-top) + 72px); }
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.mt { margin-top: 12px; }
.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600;
  background: var(--brand); color: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; cursor: pointer;
}
.btn:active { filter: brightness(.9); }
.btn.block { width: 100%; }
.btn.secondary { background: var(--brand-soft); color: var(--brand); }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.ok { background: var(--ok); }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn[disabled] { opacity: .5; }
.btn-col { display: grid; gap: 10px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > label, .lbl { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.input, textarea.input, select.input {
  width: 100%; border: 1px solid var(--line); background: #fbfcfd; border-radius: 10px; padding: 11px 12px; outline: none;
  -webkit-appearance: none; appearance: none;
}
textarea.input { min-height: 84px; resize: vertical; }
.input:focus { border-color: var(--brand-2); background: #fff; box-shadow: 0 0 0 3px rgba(29,94,168,.12); }
.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1; }

/* ---------- Segmented / chips ---------- */
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  flex: 1 1 0; min-width: 72px; min-height: 44px; border-radius: 10px; border: 1.5px solid var(--line);
  background: #fff; font-weight: 600; font-size: 15px; padding: 8px 10px;
}
.seg.vertical { flex-direction: column; }
.seg.vertical button { text-align: left; font-weight: 500; flex: none; }
.seg button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.seg button.on.bad { background: var(--bad); border-color: var(--bad); }
.seg button.on.good { background: var(--ok); border-color: var(--ok); }
.seg button.on.neutral { background: #5b6675; border-color: #5b6675; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 12px; font-size: 14px; min-height: 38px;
}
.chips.compact button { min-width: 48px; font-weight: 600; }
.chips button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.chips button.on.bad { background: var(--bad); border-color: var(--bad); }

/* ---------- Section nav ---------- */
.secnav {
  position: sticky; top: calc(var(--safe-top) + 52px); z-index: 15; background: var(--bg);
  display: flex; gap: 6px; overflow-x: auto; padding: 10px 14px; scrollbar-width: none;
  border-bottom: 1px solid var(--line);
}
.secnav::-webkit-scrollbar { display: none; }
.secnav button {
  flex-shrink: 0; border: 0; background: #fff; border-radius: 999px; padding: 7px 12px; font-size: 13.5px; font-weight: 600;
  color: var(--muted); display: inline-flex; align-items: center; gap: 6px; box-shadow: 0 0 0 1px var(--line) inset;
}
.secnav button.on { background: var(--brand); color: #fff; box-shadow: none; }
.secnav .cnt { font-size: 11.5px; font-weight: 600; opacity: .8; }
.secnav .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); }
.secnav .done { color: var(--ok); }
.secnav button.on .done { color: #b9f6ca; }

.sec-title { font-size: 20px; font-weight: 700; margin: 4px 2px 12px; color: var(--text); }

/* ---------- Question card ---------- */
.q { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; border-left: 4px solid transparent; box-shadow: 0 1px 2px rgba(16,24,40,.05); }
.q.answered { border-left-color: var(--ok); }
.q.is-bad { border-left-color: var(--bad); }
.q-label { font-weight: 600; margin-bottom: 10px; font-size: 15.5px; }
.q-label .req { color: var(--bad); }
.q-tools { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.q-tools button {
  border: 0; background: var(--bg); color: var(--muted); border-radius: 8px; padding: 6px 10px; font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 4px;
}
.q-tools button.has { color: var(--brand); background: var(--brand-soft); }
.q-tools button.mangel { color: var(--bad); background: var(--bad-soft); }
.q-note { margin-top: 10px; }
.hint-bad {
  margin-top: 10px; background: var(--bad-soft); color: var(--bad); border-radius: 10px; padding: 10px 12px; font-size: 14px;
  display: flex; align-items: center; gap: 10px;
}
.hint-bad .grow { font-weight: 600; }
.hint-bad button { border: 0; background: var(--bad); color: #fff; border-radius: 8px; padding: 8px 10px; font-weight: 600; font-size: 13.5px; flex-shrink: 0; }

.mchip {
  display: flex; align-items: center; gap: 8px; margin-top: 8px; padding: 8px 10px; border-radius: 10px;
  background: #fafbfc; border: 1px solid var(--line); font-size: 14px; width: 100%; text-align: left;
}
.mchip .nr { font-weight: 700; color: var(--bad); flex-shrink: 0; }
.mchip .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.badge.gering { background: var(--ok-soft); color: var(--ok); }
.badge.mittel { background: var(--warn-soft); color: #b46a00; }
.badge.hoch { background: var(--bad-soft); color: var(--bad); }
.badge.offen { background: var(--warn-soft); color: #b46a00; }
.badge.abgeschlossen, .badge.behoben { background: var(--ok-soft); color: var(--ok); }
.badge.vor { background: var(--brand-soft); color: var(--brand); }

/* ---------- Photos ---------- */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 10px; }
.thumbs.captioned { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.thumb { position: relative; border-radius: 10px; overflow: hidden; background: #dde2e8; }
.thumb img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.thumb input { width: 100%; border: 0; border-top: 1px solid var(--line); padding: 8px; font-size: 16px; outline: none; background: #fff; }
.add-photo {
  border: 2px dashed #c3cbd5; background: #fafbfc; border-radius: 10px; aspect-ratio: 4/3; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; gap: 4px;
}
.add-photo .ico { font-size: 26px; line-height: 1; }

/* ---------- Bottom tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: rgba(255,255,255,.96);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); display: flex; padding: 6px 6px calc(var(--safe-bottom) + 6px);
}
.tabs button {
  flex: 1; border: 0; background: none; padding: 6px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11.5px; font-weight: 600; color: var(--muted); position: relative;
}
.tabs button .ico { font-size: 21px; line-height: 1.1; }
.tabs button.on { color: var(--brand); }
.tabs .pill { position: absolute; top: 0; left: calc(50% + 8px); background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 6px; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--safe-bottom) + 76px); z-index: 25;
  background: var(--bad); color: #fff; border: 0; border-radius: 999px; padding: 14px 18px; font-weight: 700; font-size: 15px;
  box-shadow: 0 6px 18px rgba(198,40,40,.35); display: flex; align-items: center; gap: 6px;
}

.pager { display: flex; gap: 10px; margin-top: 16px; }
.pager .btn { flex: 1; }

/* ---------- List ---------- */
.search { position: relative; margin-bottom: 12px; }
.list-item {
  background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; display: flex; gap: 12px; align-items: center;
  box-shadow: 0 1px 2px rgba(16,24,40,.05); width: 100%; border: 0; text-align: left;
}
.list-item .ttl { font-weight: 650; font-size: 16px; }
.list-item .meta { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.tpl .tag, .list-item .tag { font-size: 11.5px; font-weight: 700; color: var(--brand); background: var(--brand-soft); padding: 3px 7px; border-radius: 6px; }
.list-item .more { border: 0; background: var(--bg); border-radius: 10px; width: 38px; height: 38px; font-size: 18px; flex-shrink: 0; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty .big { font-size: 46px; }
.group-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 4px 8px; }

.tpl {
  display: block; width: 100%; text-align: left; border: 2px solid var(--line); background: #fff; border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
}
.tpl.on { border-color: var(--brand); background: var(--brand-soft); }
.tpl .ttl { font-weight: 700; }
.tpl .meta { color: var(--muted); font-size: 13.5px; margin-top: 2px; }

/* ---------- Mängel ---------- */
.mangel-card { background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; display: flex; gap: 12px; width: 100%; border: 0; text-align: left; box-shadow: 0 1px 2px rgba(16,24,40,.05); }
.mangel-card .nr { font-weight: 800; color: var(--bad); font-size: 15px; min-width: 32px; }
.mangel-card.behoben { opacity: .65; }
.mangel-card.behoben .nr { color: var(--ok); }
.mangel-card .t { font-weight: 600; }
.mangel-card .meta { font-size: 13px; color: var(--muted); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.mangel-card img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.summary div { border-radius: 12px; padding: 10px; text-align: center; }
.summary b { display: block; font-size: 24px; }
.summary .gering { background: var(--ok-soft); color: var(--ok); }
.summary .mittel { background: var(--warn-soft); color: #b46a00; }
.summary .hoch { background: var(--bad-soft); color: var(--bad); }

/* ---------- Sheet (modal) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(15,23,35,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  background: var(--bg); width: 100%; max-width: 760px; max-height: calc(100% - var(--safe-top) - 24px); border-radius: 18px 18px 0 0;
  display: flex; flex-direction: column; animation: up .2s ease-out; overflow: hidden;
}
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; background: #fff; border-bottom: 1px solid var(--line); }
.sheet-head h3 { margin: 0; flex: 1; font-size: 17px; text-align: center; }
.sheet-head button { border: 0; background: none; color: var(--brand); font-weight: 600; font-size: 16px; padding: 6px 4px; min-width: 70px; }
.sheet-head button.primary { font-weight: 700; text-align: right; }
.sheet-head button:first-child { text-align: left; }
.sheet-body { overflow-y: auto; padding: 14px 14px calc(var(--safe-bottom) + 20px); -webkit-overflow-scrolling: touch; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.viewer { position: fixed; inset: 0; background: #000; z-index: 60; display: flex; flex-direction: column; }
.viewer img { flex: 1; object-fit: contain; width: 100%; min-height: 0; }
.viewer .bar { display: flex; justify-content: space-between; padding: calc(var(--safe-top) + 10px) 14px 10px; }
.viewer .bar.bottom { padding: 10px 14px calc(var(--safe-bottom) + 14px); }
.viewer button { background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 10px; padding: 10px 14px; font-weight: 600; }

/* ---------- Signature ---------- */
.sig-wrap { border: 1.5px dashed #b9c2cd; border-radius: 12px; background: #fff; position: relative; touch-action: none; }
.sig-wrap canvas { display: block; width: 100%; height: 170px; touch-action: none; }
.sig-wrap .ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #b3bcc7; pointer-events: none; font-size: 14px; }
.sig-img { max-width: 100%; height: 90px; object-fit: contain; display: block; background: #fff; border-radius: 10px; border: 1px solid var(--line); padding: 6px; }

/* ---------- Misc ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 90px); transform: translateX(-50%) translateY(20px);
  background: #1b2430; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14.5px; font-weight: 500; z-index: 80;
  opacity: 0; pointer-events: none; transition: all .2s; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--ok); border-radius: 99px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.notice { background: var(--warn-soft); color: #7a4a00; border-radius: 12px; padding: 12px; font-size: 14px; margin-bottom: 12px; }
.notice.info { background: var(--brand-soft); color: var(--brand); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; }
.check input { width: 22px; height: 22px; margin: 0; flex-shrink: 0; accent-color: var(--brand); }
.export-btn { display: flex; align-items: center; gap: 12px; text-align: left; justify-content: flex-start; }
.export-btn .ico { font-size: 22px; }
.export-btn small { display: block; font-weight: 400; opacity: .75; font-size: 12.5px; }
.busy { position: fixed; inset: 0; background: rgba(255,255,255,.7); z-index: 90; display: flex; align-items: center; justify-content: center; font-weight: 600; color: var(--brand); }

/* ---------- Pipedrive ---------- */
.pd-results { margin-top: 6px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.pd-results:empty { display: none; }
.pd-results button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: #fff; padding: 10px 12px; }
.pd-results button:last-child { border-bottom: 0; }
.pd-results button:active { background: var(--brand-soft); }
.pd-results .n { font-weight: 600; }
.pd-results .a { font-size: 13px; color: var(--muted); margin-top: 1px; }
.pd-linked { display: flex; align-items: center; gap: 8px; background: var(--ok-soft); color: var(--ok); border-radius: 10px; padding: 6px 6px 6px 12px; font-size: 14px; font-weight: 600; margin-bottom: 12px; }

/* ---------- Anmeldung ---------- */
.login { max-width: 420px; margin: 0 auto; padding: calc(var(--safe-top) + 40px) 16px calc(var(--safe-bottom) + 30px); text-align: center; }
.login .card { text-align: left; }
.login-logo { width: 96px; height: 96px; border-radius: 50%; background: #fff; box-shadow: 0 4px 16px rgba(19,68,124,.18); }
.login h1 { font-size: 24px; margin: 14px 0 20px; color: var(--brand); }
.login-err { color: var(--bad); font-size: 14px; font-weight: 600; min-height: 20px; margin-bottom: 8px; }

/* Abgleich mit dem Server */
.sync-ok { color: #2e7d32; }
.sync-err { color: #c62828; font-weight: 600; }
#sync-ind { font-size: 13px; white-space: nowrap; }
