:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #6b7686;
  --line: #dde2e9;
  --brand: #1f3a5f;
  --brand-2: #2c5282;
  --green: #2e9d4f;
  --yellow: #e0b100;
  --red: #d42a2a;
  --grey: #8a94a3;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: none;
}
a { color: var(--brand-2); text-decoration: none; }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0; display: flex; align-items: center; gap: .4rem; }
h3 { font-size: .95rem; margin: 1.2rem 0 .5rem; color: var(--brand); }
code { background: #eef1f5; padding: 0 .3em; border-radius: 4px; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .6rem;
  padding: calc(.55rem + var(--safe-top)) .8rem .55rem;
  background: var(--brand); color: #fff;
}
.topbar a, .topbar button { color: #fff; }
.topbar-title { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .back { font-size: 2rem; line-height: 1; padding: 0 .3rem; }
.topbar .logo { font-weight: 800; background: #fff; color: var(--brand); border-radius: 6px; padding: .1rem .35rem; }
.topbar .icon { font-size: 1.2rem; padding: .2rem; }
.topbar .sync { background: rgba(255,255,255,.18); border: 0; border-radius: 99px; padding: .2rem .6rem; font-size: .85rem; }
.topbar .sync.busy { animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .4; } }
.net { width: 10px; height: 10px; border-radius: 50%; }
.net.on { background: #4ade80; }
.net.off { background: #f87171; }
.offline-banner { background: #fff3cd; color: #6b5200; text-align: center; font-size: .85rem; padding: .3rem; }

.container { max-width: 900px; margin: 0 auto; padding: .8rem .8rem calc(6rem + var(--safe-bottom)); }

.card {
  display: block; background: var(--card); border-radius: var(--radius);
  padding: .9rem 1rem; margin-bottom: .75rem; box-shadow: 0 1px 2px rgba(20,30,50,.08);
  color: inherit;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.inset { background: #f7f9fb; border-radius: 8px; padding: .7rem; margin-bottom: .7rem; }
.row { display: flex; gap: .7rem; flex-wrap: wrap; }
.row > label { flex: 1 1 140px; }
.row.center { align-items: center; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }
.center-text { text-align: center; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .7rem; }
.actions { display: flex; gap: .5rem; justify-content: flex-end; align-items: center; margin-top: .8rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-line; }
.error { color: var(--red); }
.ok { color: var(--green); }
.lock { color: #7a4b00; }

/* ---------- Formulare ---------- */
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .6rem; }
label > input, label > select, label > textarea { margin-top: .2rem; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; /* verhindert Zoom auf iOS */
  color: var(--text); background: #fff;
  border: 1px solid var(--line); border-radius: 8px; padding: .55rem .65rem;
}
textarea { resize: vertical; }
input[type=checkbox] { width: auto; margin: 0 .4rem 0 0; transform: scale(1.2); }
.check { display: flex; align-items: center; color: var(--text); }
.toolbar select, .toolbar input { width: auto; }
.toolbar input.grow { width: 100%; }

button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  font: inherit; font-size: .95rem; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 8px; padding: .55rem .9rem; min-height: 44px;
}
button:disabled, .button.disabled { opacity: .45; cursor: default; }
button.primary, .button.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
button.danger { color: var(--red); border-color: #f1c4c4; }
button.block { width: 100%; margin-bottom: .5rem; }
button.link { border: 0; background: none; color: var(--brand-2); padding: .3rem .4rem; min-height: 0; }
button.link.danger { color: var(--red); }

/* ---------- Listen ---------- */
.list-item { display: flex; align-items: center; gap: .7rem; padding: .7rem 0; border-top: 1px solid var(--line); color: inherit; }
.card.list-item { border-top: 0; padding: .8rem 1rem; }
section .list-item:first-of-type { border-top: 0; }
.title { font-weight: 600; }
.badge { display: inline-block; font-size: .75rem; background: #eef1f5; color: var(--muted); border-radius: 99px; padding: .05rem .5rem; margin-right: .25rem; }
.badge.note { background: #fff3cd; color: #6b5200; }
.offline-flag { color: var(--green); font-size: .8rem; }
.menu-buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
.facts dt { color: var(--muted); font-size: .85rem; }
.facts dd { margin: 0; }
.status { font-size: .8rem; border-radius: 99px; padding: .15rem .6rem; background: #eef1f5; white-space: nowrap; }
.st-vor_ort { background: #dbeafe; }
.st-nachbearbeitung { background: #fef3c7; }
.st-abgeschlossen, .st-versendet { background: #dcfce7; }
.status-select { width: auto; }

.tabs { display: flex; gap: .3rem; margin-bottom: .7rem; overflow-x: auto; }
.tabs button { flex: 1; border-radius: 99px; white-space: nowrap; }
.tabs button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.chip-btn { min-height: 34px; padding: .2rem .7rem; border-radius: 99px; }
.chip-btn.on { border-color: var(--brand-2); background: #e8eef7; }

/* ---------- Prioritäten ---------- */
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin: 0 .25rem 0 .5rem; vertical-align: -1px; }
.dot.big { width: 18px; height: 18px; flex: none; margin: 0; }
.green { --c: var(--green); }
.yellow { --c: var(--yellow); }
.red { --c: var(--red); }
.blue { --c: #3b82c4; }
.dot.green, .dot.yellow, .dot.red, .dot.blue { background: var(--c); }
.prio-summary { font-weight: 600; margin-top: .2rem; }
.prio-buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; }
.prio { flex-direction: column; border: 2px solid var(--c); color: var(--text); padding: .5rem .3rem; min-height: 70px; }
.prio b { font-size: 1.3rem; color: var(--c); }
.prio span { font-size: .8rem; font-weight: 600; line-height: 1.2; text-align: center; }
.prio small { font-size: .65rem; line-height: 1.15; text-align: center; opacity: .85; }
.prio.on { background: var(--c); color: #fff; }
.prio.on b { color: #fff; }
.prio.yellow.on { color: #2b2100; }
.prio.yellow.on b { color: #2b2100; }

/* ---------- Mängel ---------- */
.defect { display: flex; align-items: center; gap: .7rem; }
.defect.pending { border: 1px dashed var(--yellow); }
.defect .num { font-weight: 800; font-size: 1.1rem; min-width: 2ch; text-align: center; color: var(--brand); }
.defect .thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; flex: none; background: #eef1f5; }
.defect .thumb.empty { display: flex; align-items: center; justify-content: center; opacity: .5; }
.defect .desc { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pending-box { background: #fffbea; }
.num-input { width: 5rem; display: inline-block; padding: .2rem .4rem; }

.fab {
  position: fixed; right: 1rem; bottom: calc(1rem + var(--safe-bottom)); z-index: 15;
  background: var(--red); color: #fff; font-weight: 700; font-size: 1.05rem;
  border-radius: 99px; padding: .9rem 1.3rem; box-shadow: 0 4px 14px rgba(0,0,0,.25);
}

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .5rem; }
.photo { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: #eef1f5; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-actions { position: absolute; right: 0; bottom: 0; display: flex; }
.photo-actions button { min-height: 36px; padding: .2rem .5rem; border-radius: 0; background: rgba(255,255,255,.9); border: 0; }
.photo-flag { position: absolute; left: .3rem; top: .2rem; }
.photo.add { display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 1.8rem; color: var(--brand-2); border: 2px dashed #b9c4d3; margin: 0; cursor: pointer; }
.photo.add span { font-size: .8rem; }

.sticky-actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; gap: .5rem; padding: .6rem .8rem calc(.6rem + var(--safe-bottom));
  background: rgba(243,245,248,.96); border-top: 1px solid var(--line);
}
.sticky-actions button { margin: 0; }

/* ---------- Plan ---------- */
.plan-viewer {
  position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  background: #e5e9ef; border-radius: 8px; border: 1px solid var(--line);
}
.plan-layer { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.plan-layer img { display: block; max-width: none; pointer-events: none; background: #fff; }
.pin {
  position: absolute; transform-origin: 50% 100%;
  min-width: 30px; height: 30px; padding: 0 6px; border-radius: 15px 15px 15px 2px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800; color: #fff; background: var(--grey);
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: pointer;
}
.pin-green { background: var(--green); }
.pin-yellow { background: var(--yellow); color: #2b2100; }
.pin-red { background: var(--red); }
.pin-blue { background: #3b82c4; }
.pin-active { background: #7c3aed; pointer-events: none; }
.plan-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.plan-tools { position: absolute; right: .5rem; top: .5rem; display: flex; flex-direction: column; gap: .3rem; }
.plan-tools button { width: 40px; height: 40px; min-height: 0; padding: 0; font-size: 1.2rem; background: rgba(255,255,255,.92); }
.plan-hint { position: absolute; left: .5rem; bottom: .5rem; font-size: .75rem; background: rgba(255,255,255,.85); border-radius: 6px; padding: .15rem .4rem; }

/* ---------- Foto markieren ---------- */
.annotator { position: fixed; inset: 0; z-index: 50; background: #111; display: flex; flex-direction: column; padding-top: var(--safe-top); padding-bottom: var(--safe-bottom); }
.annotator-bar { display: flex; flex-wrap: wrap; gap: .4rem; padding: .5rem; align-items: center; background: #1c1c1c; }
.annotator-bar button { background: #2b2b2b; color: #fff; border-color: #444; }
.annotator-bar button.on { background: var(--brand-2); border-color: var(--brand-2); }
.annotator-bar button.primary { background: var(--green); border-color: var(--green); }
.annotator-bar .swatch { width: 40px; padding: 0; }
.annotator-bar .swatch.on { outline: 3px solid #fff; }
.annotator-bar .sep { width: .6rem; }
.annotator-canvas { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.annotator-canvas canvas { touch-action: none; }

/* ---------- Bauteilauswahl / Katalog ---------- */
.chips { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.chip { background: #e8eef7; border-radius: 99px; padding: .2rem .3rem .2rem .7rem; font-size: .85rem; display: inline-flex; align-items: center; }
.chip button { min-height: 0; border: 0; background: none; padding: 0 .4rem; font-size: 1rem; }
.picker-list { border: 1px solid var(--line); border-radius: 8px; margin-top: .5rem; max-height: 50vh; overflow-y: auto; padding: .4rem; }
.picker-row { display: flex; align-items: center; gap: .3rem; color: var(--text); font-size: .95rem; padding: .35rem .5rem; margin: 0; border-radius: 6px; }
.picker-row:hover { background: #f3f5f8; }
.cat-row { display: flex; align-items: center; gap: .5rem; padding: .35rem 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.cat-row .code { min-width: 3.5rem; flex: none; }
.cat-row .grow { overflow-wrap: break-word; hyphens: auto; }
.cat-row button.link { flex: none; font-size: 1.05rem; }
.cat-row input, .cat-row select { width: auto; }
.code-input { max-width: 6rem; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: .4rem .3rem; border-top: 1px solid var(--line); }
.table select { width: auto; padding: .2rem; }

/* ---------- Login / Toasts ---------- */
.login { max-width: 380px; margin: 12vh auto 0; padding: 1.5rem; }
.toasts { position: fixed; left: 0; right: 0; bottom: calc(5rem + var(--safe-bottom)); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: .4rem; pointer-events: none; }
.toast { background: #333; color: #fff; padding: .55rem 1rem; border-radius: 8px; max-width: 90vw; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.toast.error { background: var(--red); }
.toast.ok { background: var(--green); }

@media (min-width: 700px) {
  .container { padding-top: 1.2rem; }
  .defect .thumb { width: 80px; height: 80px; }
}
.picker-head { position: sticky; top: -0.4rem; background: var(--brand); color: #fff; font-size: .8rem; font-weight: 600; padding: .3rem .5rem; border-radius: 6px; margin: .4rem 0 .2rem; z-index: 1; }
.picker-row.group { font-weight: 600; }

.deadline { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin-top: .5rem; }
.deadline-input { width: 7rem; }
.mb { margin-bottom: .5rem; }
.badge.warn { background: #fde8e8; color: #9b1c1c; }
.warn-list { margin: 0 0 .8rem; padding-left: 1rem; color: #7a4b00; }
.doc-flags { display: flex; gap: .3rem; flex-wrap: wrap; }
.doc-flags button { min-height: 30px; padding: .1rem .5rem; font-size: .75rem; border-radius: 99px; }
.doc-flags button.on { background: #e8eef7; border-color: var(--brand-2); }
.clamp { max-height: 6.5em; overflow: hidden; }
