:root {
  --bg: #f3f6f8;
  --card: #ffffff;
  --text: #14212b;
  --muted: #5b6b78;
  --line: #d7e0e6;
  --brand: #0b6e8f;
  --brand-d: #084e68;
  --on-brand: #ffffff;
  --ok: #1f8a4c;
  --bad: #c0392b;
  --na: #6b7280;
  --st: #c2410c;
  --ib: #0b6e8f;
  --wa: #2f855a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(10, 30, 45, .06), 0 4px 14px rgba(10, 30, 45, .05);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e161c;
    --card: #17222b;
    --text: #e8eef2;
    --muted: #93a5b3;
    --line: #2a3a46;
    --brand: #2a8db3;
    --brand-d: #0a3a4e;
    --ok: #35a566;
    --bad: #e0584a;
    --na: #7b8794;
    --st: #e2703a;
    --ib: #2a8db3;
    --wa: #46a577;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
a { color: inherit; text-decoration: none; }

.wrap { max-width: 780px; margin: 0 auto; padding: 0 16px; }
.has-bar .wrap { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.no-bar .wrap { padding-bottom: 40px; }

/* ---------- Kopfzeile ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand-d); color: #fff;
  padding-top: env(safe-area-inset-top);
}
.top-in {
  max-width: 780px; margin: 0 auto; padding: 10px 12px 10px 8px;
  display: flex; align-items: center; gap: 8px; min-height: 56px;
}
.top h1 { font-size: 18px; font-weight: 700; }
.top small { display: block; opacity: .75; font-size: 12px; font-weight: 400; margin-top: 2px; }
.top .grow { flex: 1; min-width: 0; }
.top .grow > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .pad-l { padding-left: 8px; }
.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: inline-grid; place-items: center;
  border: 0; background: transparent; color: inherit; border-radius: 12px; cursor: pointer;
}
.icon-btn:active { background: rgba(255, 255, 255, .14); }
.ic-w { display: inline-grid; place-items: center; line-height: 0; }
.save-state { font-size: 12px; opacity: .8; white-space: nowrap; }

/* ---------- Startseite ---------- */
.lead { margin: 20px 0 10px; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.new-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 620px) { .new-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .new-grid { grid-template-columns: repeat(4, 1fr); } }
.hist-i { padding: 8px 0; border-bottom: 1px solid var(--line, #e3e6ea); font-size: 14px }
.hist-i:last-child { border-bottom: 0 }
.new-card {
  display: flex; align-items: center; gap: 14px; text-align: left;
  padding: 16px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); cursor: pointer; min-height: 84px;
}
@media (min-width: 620px) { .new-card { flex-direction: column; align-items: flex-start; gap: 10px; } }
.new-card:active { transform: scale(.985); }
.new-card .disc {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: #fff; background: var(--c);
}
.new-card strong { display: block; font-size: 18px; }
.new-card span.d { display: block; color: var(--muted); font-size: 14px; }

.tools { display: flex; gap: 8px; align-items: center; margin: 22px 0 10px; flex-wrap: wrap; }
.tools input[type=search] {
  flex: 1 1 180px; min-height: 44px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card);
}
.chips { display: flex; gap: 6px; }
.chip {
  min-height: 44px; padding: 0 14px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--muted); font-weight: 600;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }

.list { display: grid; gap: 10px; }
.rc {
  display: block; background: var(--card); border: 1px solid var(--line);
  border-left: 5px solid var(--c); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
}
.rc:active { background: color-mix(in srgb, var(--card) 92%, var(--brand)); }
.rc-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.rc-k { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc-d { font-size: 13px; color: var(--muted); white-space: nowrap; }
.rc-b { display: flex; gap: 8px; align-items: center; margin-top: 6px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: color-mix(in srgb, var(--c, var(--brand)) 15%, transparent); color: var(--c, var(--brand));
}
.pill.done { --c: var(--ok); }
.pill.draft { --c: #b7791f; }
.empty { color: var(--muted); text-align: center; padding: 28px 8px; }
.foot-note { color: var(--muted); font-size: 13px; text-align: center; margin: 26px 0 0; }

/* ---------- Formular ---------- */
.banner {
  margin: 14px 0 0; padding: 10px 14px; border-radius: 12px; font-size: 14px;
  background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); font-weight: 600;
}
.type-tag { color: #fff; background: var(--c); padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; margin-right: 6px; }

details.sec {
  margin: 14px 0 0; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
details.sec > summary {
  list-style: none; display: flex; align-items: center; gap: 10px; cursor: pointer;
  padding: 14px 16px; min-height: 54px; font-weight: 700; font-size: 17px;
}
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary .sec-t { flex: 1; }
details.sec > summary .chev { transition: transform .15s; color: var(--muted); }
details.sec[open] > summary .chev { transform: rotate(90deg); }
details.sec[open] > summary { border-bottom: 1px solid var(--line); }
.cnt { font-size: 12px; font-weight: 700; color: var(--muted); background: color-mix(in srgb, var(--muted) 14%, transparent); padding: 2px 8px; border-radius: 999px; }
.cnt.has-bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.cnt.all-ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.sec-body { padding: 14px 16px 16px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.field { min-width: 0; }
.field.w2 { grid-column: 1 / -1; }
label, .lbl { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.req { color: var(--bad); font-style: normal; margin-left: 3px; }
input[type=text], input[type=tel], input[type=number], input[type=date], input[type=time], input[type=email], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); outline: none; appearance: none; -webkit-appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent); }
.invalid input, .invalid select, .invalid textarea { border-color: var(--bad); }
.invalid > label, .invalid > .lbl { color: var(--bad); }
.inp-wrap { position: relative; }
.inp-wrap input { padding-right: 52px; }
.unit { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }
.computed {
  min-height: 46px; display: flex; align-items: center; padding: 10px 12px; border-radius: 10px;
  background: color-mix(in srgb, var(--brand) 10%, transparent); font-weight: 700; color: var(--brand);
}

.seg { display: flex; gap: 6px; }
.seg-b {
  flex: 1; min-height: 46px; padding: 0 8px; border-radius: 10px; cursor: pointer; font-weight: 700;
  border: 1px solid var(--line); background: var(--bg); color: var(--muted);
}
.seg-b.on { color: #fff; border-color: transparent; background: var(--brand); }
.seg-b.on.s-ok { background: var(--ok); }
.seg-b.on.s-bad { background: var(--bad); }
.seg-b.on.s-na { background: var(--na); }

.checks { display: block; }
.checks-head { display: flex; justify-content: flex-end; margin-bottom: 4px; }
.chk { padding: 10px 0; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.chk:first-of-type { border-top: 0; }
.chk-l { font-size: 15px; }
@media (min-width: 620px) {
  .chk { grid-template-columns: 1fr 240px; align-items: center; }
}

.btn {
  min-height: 48px; padding: 0 18px; border-radius: 12px; cursor: pointer; font-weight: 700;
  border: 1px solid var(--line); background: var(--card);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:active { filter: brightness(.94); }

/* Material */
.mat-row {
  display: grid; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line);
  grid-template-columns: 1fr 84px 70px 44px;
  grid-template-areas: "bez bez bez del" "art menge einh einh";
}
.mat-row:first-child { border-top: 0; padding-top: 0; }
.mat-row .m-bez { grid-area: bez; }
.mat-row .m-art { grid-area: art; }
.mat-row .m-menge { grid-area: menge; }
.mat-row .m-einh { grid-area: einh; }
.mat-row .m-del { grid-area: del; align-self: center; color: var(--bad); }
.mat-row input { min-height: 44px; padding: 8px 10px; }
.mat-add { margin-top: 10px; }

/* Fotos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 10px; }
.ph { position: relative; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg); }
.ph img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.ph input { border: 0; border-top: 1px solid var(--line); border-radius: 0; min-height: 40px; font-size: 14px; }
.ph button {
  position: absolute; top: 6px; right: 6px; width: 34px; height: 34px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, .6); color: #fff; font-size: 20px; line-height: 1; cursor: pointer;
}

/* Unterschrift */
.sig-box { margin-top: 14px; }
.sig-box:first-child { margin-top: 0; }
.sig-wrap { position: relative; border: 1px dashed var(--muted); border-radius: 12px; background: #fff; }
canvas.sig { display: block; width: 100%; height: auto; aspect-ratio: 700 / 220; touch-action: none; cursor: crosshair; }
.sig-hint { position: absolute; left: 14px; bottom: 8px; font-size: 12px; color: #8896a2; pointer-events: none; }
.sig-clear { position: absolute; right: 8px; top: 8px; }

/* Unterer Balken */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.bar-in { max-width: 780px; margin: 0 auto; display: flex; gap: 10px; }
.bar .btn { flex: 1; }

.actions { display: grid; gap: 10px; margin-top: 22px; }
@media (min-width: 620px) { .actions { grid-template-columns: repeat(3, 1fr); } }

#toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: #1c2a34; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); opacity: 0; pointer-events: none; transition: .2s; z-index: 50; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Synchronisation, Login, Dialog ---------- */
.sync {
  display: flex; align-items: center; gap: 10px; margin: 14px 0 0; padding: 10px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; font-size: 14px;
}
.sync .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--na); flex: none; }
.sync.ok .dot { background: var(--ok); }
.sync.warn .dot { background: #d69e2e; }
.sync.bad .dot { background: var(--bad); }
.sync .txt { flex: 1; min-width: 0; }
.sync .btn { min-height: 38px; padding: 0 12px; font-size: 14px; }

.login { max-width: 420px; margin: 0 auto; padding: 28px 16px; }
.login .logo-big { display: block; max-height: 72px; max-width: 220px; margin: 8px auto 18px; object-fit: contain; }
.login h2 { text-align: center; margin-bottom: 4px; }
.login p.sub { text-align: center; color: var(--muted); margin: 0 0 22px; }
.login .field { margin-bottom: 14px; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; margin: 4px 0 12px; }

.logo-prev { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.logo-prev .box { min-width: 120px; min-height: 64px; padding: 8px; border: 1px dashed var(--line); border-radius: 12px; background: #fff; display: grid; place-items: center; color: #8896a2; font-size: 13px; }
.logo-prev img { max-height: 60px; max-width: 200px; display: block; }

dialog.dlg { border: 0; border-radius: 16px; padding: 0; width: min(440px, calc(100% - 24px)); background: var(--card); color: var(--text); box-shadow: 0 12px 48px rgba(0, 0, 0, .35); }
dialog.dlg::backdrop { background: rgba(0, 0, 0, .5); }
.dlg-in { padding: 18px; display: grid; gap: 14px; }
.dlg-in h2 { font-size: 18px; }
.dlg-row { display: flex; gap: 10px; }
.dlg-row .btn { flex: 1; }
.chk-line { display: flex; gap: 10px; align-items: center; font-size: 15px; font-weight: 400; color: var(--text); }
.chk-line input { width: 22px; height: 22px; accent-color: var(--brand); }

@media print {
  html, body { background: #fff !important; }
  .no-print, .top, .bar, #toast { display: none !important; }
  .wrap { max-width: none; padding: 0 !important; }
}

/* Kundenvorschläge & Termine */
.suggest { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-height: 280px; overflow: auto; }
.suggest[hidden] { display: none; }
.suggest button { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; color: var(--text); font: inherit; }
.suggest button span { display: block; font-size: 13px; color: var(--muted); }
.termine { margin-bottom: 18px; }
.t-day { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 12px 0 6px; }
.t-item { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--c, var(--brand)); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; color: var(--text); font: inherit; }
.t-item.done { opacity: .6; }
.t-time { font-weight: 700; min-width: 48px; font-variant-numeric: tabular-nums; }
.t-time small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.t-main { flex: 1; min-width: 0; }
.t-main strong, .t-main small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-main small { color: var(--muted); font-size: 13px; }
.t-ok { color: var(--ok); font-size: 20px; font-weight: 700; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.kv span { color: var(--muted); font-size: 13px; }
