:root {
  color-scheme: light;
  --brand: #e87722;
  --brand-dark: #c25a00;
  --brand-soft: #fdf0e6;
  --text: #1c1c1c;
  --muted: #6b6b6b;
  --line: #dcdcdc;
  --bg: #f5f5f3;
  --card: #ffffff;
  --danger: #c62828;
  --ok: #2e7d32;
  --radius: 12px;
  --tap: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
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, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* --- Kopfzeile --- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 16px 8px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.logo { height: 32px; }
.topbar-title { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.net { background: #555; color: #fff; font-size: 13px; padding: 2px 10px; border-radius: 99px; }

main { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(110px + var(--safe-bottom)); }

/* --- Bausteine --- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 2px rgb(0 0 0 / .06); }
h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 14px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field > span .req { color: var(--danger); }
input[type=text], input[type=password], input[type=email], input[type=date], input[type=time], textarea {
  width: 100%; min-height: var(--tap);
  padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px;
  font: inherit; font-size: 16px; /* >=16px verhindert Zoom auf iOS */
  background: #fff; color: var(--text);
  appearance: none;
}
textarea { resize: vertical; min-height: 120px; }
textarea.big { min-height: 220px; }
input:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.invalid { border-color: var(--danger) !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 20px; border: 0; border-radius: 10px;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  background: #ececec; color: var(--text);
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:active { background: var(--brand-dark); }
.btn.ghost { background: transparent; color: var(--brand-dark); padding: 0 8px; }
.btn.danger { background: transparent; color: var(--danger); }
.btn.block { width: 100%; }
.btn.big { min-height: 64px; font-size: 18px; }
.btn:disabled { opacity: .5; }

/* Auswahl-Chips (Radio/Checkbox) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-flex; align-items: center; min-height: var(--tap); min-width: 64px; justify-content: center;
  padding: 0 16px; border: 1.5px solid var(--line); border-radius: 99px; background: #fff;
  font-weight: 500; cursor: pointer; user-select: none;
}
.chip input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip input:focus-visible + span { box-shadow: 0 0 0 3px var(--brand-soft); }

.switch { display: flex; align-items: flex-start; gap: 12px; min-height: var(--tap); padding: 8px 0; cursor: pointer; }
.switch input { width: 24px; height: 24px; margin: 2px 0 0; accent-color: var(--brand); flex: none; }

.inline { display: flex; gap: 10px; align-items: flex-end; }
.inline > * { flex: 1; }
.unit { position: relative; }
.unit input { padding-right: 44px; }
.unit::after { content: attr(data-unit); position: absolute; right: 14px; bottom: 13px; color: var(--muted); }

/* --- Schritt-Navigation --- */
.steps { display: flex; gap: 6px; overflow-x: auto; margin: -4px -16px 14px; padding: 4px 16px; scrollbar-width: none; }
.steps::-webkit-scrollbar { display: none; }
.steps button {
  flex: none; border: 0; background: #e6e6e3; color: var(--muted);
  border-radius: 99px; padding: 8px 14px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.steps button.done { background: var(--brand-soft); color: var(--brand-dark); }
.steps button.active { background: var(--brand); color: #fff; }

.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; gap: 10px; justify-content: center;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: rgb(255 255 255 / .96); border-top: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.bottombar .btn { flex: 1; max-width: 360px; }

/* --- Wiederholbare Zeilen (Material, Zeiten) --- */
.rowcard { border: 1.5px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; position: relative; }
.rowcard .remove { position: absolute; top: 4px; right: 4px; min-height: 40px; }
.rowcard .rowtitle { font-weight: 600; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid-mat { display: grid; grid-template-columns: 90px 1fr; gap: 0 10px; }
.grid-mat > :last-child { grid-column: 1 / -1; }
.zeit-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.hours { display: flex; gap: 8px; font-size: 14px; }
.hours div { flex: 1; background: var(--bg); border-radius: 8px; padding: 6px 8px; text-align: center; }
.hours b { display: block; font-size: 17px; }

/* --- Liste --- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .actions { display: flex; flex: none; }
@media (max-width: 520px) {
  .list li:has(.actions) { flex-wrap: wrap; }
  .list li:has(.actions) .grow { flex-basis: 100%; }
  .list .actions { width: 100%; justify-content: space-between; margin: -6px -8px 0; }
}
.badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.warn { background: #fff3e0; color: var(--brand-dark); }
.badge.err { background: #fdecea; color: var(--danger); }
.badge.ok { background: #e8f5e9; color: var(--ok); }

/* --- Fotos --- */
.fotos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.fotos:empty { display: none; }
.foto { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--bg); }
.foto img { width: 100%; height: 100%; object-fit: cover; display: block; }
.remove-foto {
  position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border: 0; border-radius: 50%;
  background: rgb(0 0 0 / .6); color: #fff; font-size: 15px; cursor: pointer;
}
label.btn { cursor: pointer; white-space: nowrap; }
.foto-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
@media (max-width: 400px) { .foto-actions { grid-template-columns: 1fr; } }

/* --- Demo --- */
.demo-chip { background: var(--brand-dark); }
.card.demo { border: 2px dashed var(--brand); }

/* --- Unterschrift --- */
.sig-wrap { position: relative; border: 1.5px dashed #bbb; border-radius: 10px; background: #fff; }
.sig-wrap canvas { display: block; width: 100%; height: 200px; touch-action: none; color: #0b2a6b; }
.sig-wrap .baseline { position: absolute; left: 20px; right: 20px; bottom: 44px; border-top: 1px solid #ccc; pointer-events: none; }
.sig-wrap .hint { position: absolute; left: 20px; bottom: 18px; font-size: 13px; color: var(--muted); pointer-events: none; }
.sig-actions { display: flex; justify-content: space-between; margin-top: 6px; }
.sig-full { position: fixed; inset: 0; z-index: 50; background: #fff; display: flex; flex-direction: column; padding: calc(12px + env(safe-area-inset-top, 0px)) 16px calc(12px + var(--safe-bottom)); }
.sig-full .sig-wrap { flex: 1; display: flex; }
.sig-full .sig-wrap canvas { height: auto; flex: 1; }
.rotate-hint { display: none; text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 8px; }
@media (orientation: portrait) and (max-width: 600px) { .sig-full .rotate-hint { display: block; } }

.summary dt { font-size: 13px; color: var(--muted); margin-top: 8px; }
.summary dd { margin: 0; white-space: pre-line; }
.errors { background: #fdecea; color: var(--danger); border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; }
.errors button { color: var(--danger); text-decoration: underline; background: none; border: 0; font: inherit; padding: 0; cursor: pointer; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%) translateY(20px);
  background: #222; color: #fff; padding: 12px 18px; border-radius: 10px; max-width: calc(100% - 32px);
  opacity: 0; pointer-events: none; transition: .2s; z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

.login { max-width: 400px; margin: 8vh auto 0; }

/* Tablet: mehr Breite, Felder nebeneinander */
@media (min-width: 820px) {
  main { max-width: 900px; padding-top: 24px; }
  .wide-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
  .grid-mat { grid-template-columns: 100px 1fr 220px; }
  .grid-mat > :last-child { grid-column: auto; }
  .zeit-row { display: grid; grid-template-columns: 1.3fr .8fr 1fr 1fr; gap: 0 10px; }
  .sig-wrap canvas { height: 260px; }
}
