:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --primary: #1f6feb;
  --primary-dark: #1a5fcc;
  --text: #1a2230;
  --muted: #6b7685;
  --border: #e1e6ee;
  --ok: #1a9e5f;
  --warn: #e6a000;
  --danger: #d83b3b;
  --shadow: 0 2px 10px rgba(20,40,80,.08);
  --radius: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
}
.hidden { display: none !important; }

/* ---------------- Login ---------------- */
#view-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #1f6feb 0%, #14387a 100%);
  padding: 20px;
}
.login-box {
  background: var(--card);
  border-radius: 16px;
  padding: 34px 26px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
  text-align: center;
}
.brand { display: flex; align-items: center; justify-content: center; gap: 8px; }
.brand h1 { margin: 0; font-size: 32px; letter-spacing: 2px; }
.logo { font-size: 26px; }
.subtitle { color: var(--muted); margin: 4px 0 22px; font-size: 14px; }
#login-form { display: flex; flex-direction: column; gap: 12px; }
.error { color: var(--danger); font-size: 14px; min-height: 18px; margin: 4px 0 0; }

/* ---------------- App shell ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  background: var(--primary); color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 600; letter-spacing: .5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .logo { font-size: 20px; }
.spacer { flex: 1; }
.icon-btn {
  background: rgba(255,255,255,.15); border: none; color: #fff;
  width: 38px; height: 38px; border-radius: 9px; font-size: 19px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: rgba(255,255,255,.3); }
.icon-btn svg { width: 21px; height: 21px; fill: none; stroke: #fff;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#btn-bio-login { display: flex; align-items: center; justify-content: center; gap: 8px; }
.bio-ico { font-size: 18px; }

main { padding: 14px; max-width: 1100px; margin: 0 auto; padding-bottom: 90px; }

/* ---------------- Buttons / inputs ---------------- */
button { font-family: inherit; }
.btn-primary, .btn-secondary, .btn-danger {
  border: none; border-radius: 10px; padding: 13px 16px; font-size: 16px;
  font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: #eef1f6; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-small { padding: 8px 12px; font-size: 14px; border-radius: 8px; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer;
  font-size: 14px; padding: 4px; }

input, select, textarea {
  width: 100%; padding: 12px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 16px; background: #fff; color: var(--text);
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 4px; font-weight: 600; }
.field { margin-bottom: 12px; }
.quick-check { display: inline-flex; align-items: center; gap: 6px; margin-top: 5px;
  font-size: 12.5px; color: var(--muted); font-weight: 600; cursor: pointer; }
.quick-check input { width: auto; margin: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Pflichtfeld-/Hinweis-Text unter Feldern */
.field-hint { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.muted-hint { color: var(--muted); font-size: 13px; }

/* Suchfeld über der Projektliste */
.search-box { margin-bottom: 12px; }
.search-box input { width: 100%; }

/* Dokument-Matrix (Projekt-Übersicht) */
.matrix-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border);
  border-radius: 12px; background: var(--card); }
.dok-matrix { border-collapse: collapse; width: 100%; font-size: 13px; }
.dok-matrix th, .dok-matrix td { border-bottom: 1px solid var(--border); padding: 8px 6px; text-align: center; }
.dok-matrix thead th { position: sticky; top: 0; background: var(--bg, #f4f6f8); color: var(--muted);
  font-weight: 700; font-size: 12px; white-space: nowrap; }
.dok-matrix th.anlage-col, .dok-matrix td.anlage-cell { text-align: left; min-width: 150px; position: sticky; left: 0;
  background: var(--card); z-index: 1; }
.dok-matrix tr:last-child td { border-bottom: none; }
.anlage-cell { cursor: pointer; }
.anlage-cell:hover { background: var(--hover, #eef2f5); }
.anlage-name { font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.anlage-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.dok-cell { cursor: pointer; min-width: 52px; vertical-align: middle; }
.dok-cell:hover { background: var(--hover, #eef2f5); }
.dok-add { color: var(--muted); font-size: 18px; opacity: .5; }
.dok-foreign { opacity: .5; }
.dok-chip { display: inline-block; padding: 2px 7px; border-radius: 10px; font-size: 11px; font-weight: 600;
  margin: 1px; white-space: nowrap; }
.dok-chip.st-open { background: #e6e8eb; color: #555; }
.dok-chip.st-prog { background: #fff0d6; color: #9a6700; }
.dok-chip.st-done { background: #d8f5dd; color: #1a7f37; }

/* Dokument-Modal: Zeilen */
.dok-row { border: 1px solid var(--border); border-radius: 10px; padding: 8px; margin-bottom: 8px; }
.dok-row .dok-titel { width: 100%; margin-bottom: 6px; }
.dok-row2 { display: flex; gap: 6px; align-items: center; }
.dok-row2 .dok-status { flex: 1; }
.dok-row2 .dok-datum { flex: 1; }
.dok-row2 .dok-del { color: var(--danger); flex: none; padding: 4px 8px; }

/* PDF-Export: Unterobjekt-Auswahl */
.uo-checks { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.uo-check { display: flex; align-items: center; gap: 9px; padding: 7px 4px; cursor: pointer;
  font-size: 14px; border-bottom: 1px solid var(--border); }
.uo-check:last-child { border-bottom: none; }
.uo-check input { width: auto; margin: 0; flex: none; }

/* ---------------- Cards / lists ---------------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 12px;
}
.list-item {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; margin-bottom: 10px; cursor: pointer;
  display: flex; align-items: center; gap: 12px;
}
.list-item:active { background: #f7f9fc; }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 600; font-size: 17px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .li-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.badge { background: #eef1f6; color: var(--muted); border-radius: 20px;
  padding: 3px 10px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.chev { color: var(--muted); font-size: 22px; }

.section-head { display: flex; align-items: center; justify-content: space-between;
  margin: 4px 2px 12px; }
.section-head h2 { font-size: 16px; margin: 0; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; }

/* #Block2: Umschalter Messprotokolle / Erstprüfung */
.coll-tabs { display: flex; gap: 6px; margin: 2px 2px 14px; }
.coll-tab { flex: 1; padding: 9px 8px; border: 1px solid var(--border); background: var(--card, #fff);
  color: var(--muted); border-radius: 10px; font-size: 13px; font-weight: 600; cursor: pointer; }
.coll-tab.active { background: var(--accent, #1b6ec2); color: #fff; border-color: var(--accent, #1b6ec2); }

/* #Block2: „Strom einschalten"-Protokoll (Erstprüfung) */
.strom-box { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin: 0 2px 14px;
  background: var(--card, #fff); }
.strom-box.on { border-color: #2e9e5b; background: #eaf7ef; }
.strom-title { font-weight: 600; font-size: 14px; }
.strom-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* Protokoll Kopf */
.proto-head { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 16px; }
.proto-head .ph-objekt { font-size: 20px; font-weight: 700; }
.proto-head .ph-meta { color: var(--muted); font-size: 14px; margin-top: 4px;
  display: flex; flex-wrap: wrap; gap: 4px 16px; }

/* Messung-Karte */
.messung {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 12px; overflow: hidden;
}
.messung-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; cursor: pointer; }
.messung-head .m-num { background: var(--primary); color: #fff; width: 30px; height: 30px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0; }
.messung-head .m-title { flex: 1; min-width: 0; }
.messung-head .m-t1 { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.messung-head .m-t2 { color: var(--muted); font-size: 13px; }
.messung-body { padding: 0 16px 16px; border-top: 1px solid var(--border); }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; margin-top: 12px; }
.kv .k { font-size: 12px; color: var(--muted); }
.kv .v { font-weight: 600; }
.kv .full { grid-column: 1 / -1; }
.m-thumb { margin-top: 12px; }
.m-thumb img { max-width: 100%; border-radius: 10px; border: 1px solid var(--border); }
.m-actions { display: flex; gap: 8px; margin-top: 14px; }

/* group heading in form */
.form-group-title { font-size: 13px; font-weight: 700; color: var(--primary);
  text-transform: uppercase; letter-spacing: .5px; margin: 18px 0 8px; }

/* image input preview */
.img-pick { display: flex; flex-direction: column; gap: 10px; }
.img-preview { max-width: 100%; border-radius: 10px; border: 1px solid var(--border); }

/* table view (PC) */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); }
table.mtable { border-collapse: collapse; width: 100%; font-size: 13px; white-space: nowrap; }
table.mtable th, table.mtable td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
table.mtable th { background: #f0f3f8; color: var(--muted); font-weight: 600; position: sticky; top: 0; }
table.mtable tr:hover td { background: #f7f9fc; }

.view-toggle { display: flex; gap: 6px; }
.view-toggle button { background: #eef1f6; border: none; padding: 7px 12px; border-radius: 8px;
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); }
.view-toggle button.active { background: var(--primary); color: #fff; }

/* FAB */
.fab {
  position: fixed; right: 18px; bottom: 18px; z-index: 25;
  width: 60px; height: 60px; border-radius: 50%; border: none;
  background: var(--primary); color: #fff; font-size: 32px; line-height: 1;
  box-shadow: 0 6px 20px rgba(31,111,235,.45); cursor: pointer;
}
.fab:active { background: var(--primary-dark); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,25,45,.5); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
.modal {
  background: var(--card); width: 100%; max-width: 560px;
  border-radius: 18px 18px 0 0; padding: 20px; max-height: 92vh; overflow-y: auto;
  box-shadow: 0 -6px 30px rgba(0,0,0,.25);
}
.modal h2 { margin: 0 0 16px; font-size: 20px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; position: sticky; bottom: 0;
  background: var(--card); padding-top: 12px; }
.modal-actions button { flex: 1; }

@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: 18px; }
}

/* Toast */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: #222d3d; color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; z-index: 100; box-shadow: 0 4px 16px rgba(0,0,0,.3);
  max-width: 90%; text-align: center;
}
.toast.err { background: var(--danger); }

.role-pill { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 700;
  text-transform: uppercase; }
.role-admin { background: #fde7e7; color: var(--danger); }
.role-kontrolleur { background: #e3f0ff; color: var(--primary); }
.role-projektleiter { background: #e7f6ec; color: #1a7f43; }
.role-monteur { background: #fdf0e0; color: #b06a1a; }

/* Sync */
.dot-dirty { color: var(--warn); font-size: 12px; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
#btn-sync.spin svg { animation: spin .8s linear infinite; }
.sync-warn { background: #fff6e0; border: 1px solid #f0d48a; color: #7a5b00;
  border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.sync-summary { display: flex; gap: 16px; flex-wrap: wrap; background: #f0f3f8;
  border-radius: 10px; padding: 10px 12px; font-weight: 600; font-size: 14px; margin: 4px 0 10px; }
.sy-down { color: var(--ok); font-weight: 700; }
.sy-up { color: var(--primary); font-weight: 700; }
.sync-list { list-style: none; padding: 0; margin: 0 0 8px; max-height: 220px; overflow-y: auto; }
.sync-list li { padding: 7px 4px; border-bottom: 1px solid var(--border); font-size: 14px; }
.sync-list em { color: var(--muted); font-style: normal; }
.conflict { border: 1px solid #f0d48a; border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.cf-title { font-weight: 700; }
.cf-info { color: var(--muted); font-size: 13px; margin: 2px 0 8px; }
.cf-choice { display: flex; gap: 16px; flex-wrap: wrap; font-size: 14px; }
.cf-choice label { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--text); }
.cf-choice input { width: auto; }

/* Unterobjekte */
.uo-section { margin-bottom: 18px; }
.uo-head { display: flex; align-items: center; gap: 10px; padding: 6px 4px 10px; }
.uo-main { flex: 1; min-width: 0; }
.uo-title { font-size: 17px; font-weight: 700; }
.uo-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.uo-edit { flex-shrink: 0; }
.uo-add { width: 100%; margin-top: 2px; }

/* Messpunkt-Nummer in Listen */
.list-item .m-num { background: var(--primary); color: #fff; width: 28px; height: 28px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0; }
.badge-warn { background: #fdeccd; color: #9a6b00; }

/* Mängel */
.mangel-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 10px; border-left: 3px solid var(--warn); }
.mangel-head { display: flex; align-items: center; gap: 10px; }
.mangel-text { flex: 1; font-weight: 600; }
.mangel-fotos { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.mangel-fotos img { width: 80px; height: 80px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.mangel-fotos.edit { margin: 4px 0 10px; }
.mf-thumb { position: relative; }
.mf-thumb img { width: 80px; height: 80px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.mf-rm { position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%;
  border: none; background: var(--danger); color: #fff; font-size: 15px; line-height: 1; cursor: pointer; }

/* Sperre / Lock */
.lock-tag { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 20px;
  background: #fdeccd; color: #9a6b00; white-space: nowrap; }
.lock-tag.held { background: #e3f0ff; color: var(--primary); }
.lock-bar { margin-top: 10px; font-size: 13px; font-weight: 600; padding: 8px 10px; border-radius: 8px;
  background: #fff6e0; color: #7a5b00; }
.lock-bar.held { background: #e3f0ff; color: var(--primary); }
.lock-screen { text-align: center; padding: 50px 20px 30px; }
.lock-ico { font-size: 56px; }
.lock-title { font-size: 22px; font-weight: 700; margin: 6px 0; }
.lock-text { color: var(--muted); font-size: 15px; line-height: 1.6; }
.log-list { max-height: 60vh; overflow-y: auto; }
.log-row { padding: 9px 4px; border-bottom: 1px solid var(--border); }
.log-act { font-weight: 600; font-size: 14px; }
.log-meta { color: var(--muted); font-size: 12.5px; margin-top: 1px; }

/* ---------------- Druckansicht / PDF-Export ---------------- */
/* Off-screen gerendert, damit Bilder geladen werden; im Druck sichtbar. */
#print-root { position: fixed; left: -10000px; top: 0; width: 280mm; background: #fff; color: #000; }
.pr-title { font-size: 16pt; font-weight: 700; }
.pr-sub { font-size: 10pt; color: #333; margin: 2px 0 10px; }
.pr-table { width: 100%; border-collapse: collapse; font-size: 7pt; }
.pr-table th, .pr-table td { border: 1px solid #888; padding: 2px 3px; text-align: left; vertical-align: top; }
.pr-table th { background: #eee; }
.pr-table td.pr-bilder { width: 3.3cm; white-space: normal; }
.pr-img3 { width: 3cm; height: 3cm; object-fit: contain; margin: 1px; vertical-align: top; }
.pr-mangel { border: 1px solid #888; border-radius: 4px; padding: 7px 9px; margin-bottom: 9px; page-break-inside: avoid; }
.pr-mnr { font-weight: 700; font-size: 12pt; }
.pr-mpath { font-size: 9pt; color: #444; margin: 2px 0; }
.pr-mtext { font-size: 11pt; margin: 5px 0; white-space: pre-wrap; }
.pr-mfotos { display: flex; flex-wrap: wrap; gap: 3mm; }
.pr-img6 { width: 6cm; height: 6cm; object-fit: contain; border: 1px solid #ccc; }

@media print {
  body * { visibility: hidden; }
  #print-root, #print-root * { visibility: visible; }
  #print-root { position: absolute; left: 0; top: 0; width: auto; }
}
