/* ElektroPlan — schlichtes, robustes UI mit grossen Touch-Zielen */
:root {
  --tinte: #16222e;
  --grau: #5b6b78;
  --linie: #d8dfe6;
  --flaeche: #f4f6f8;
  --akzent: #0b64c0;
  --akzent-dunkel: #094e96;
  --warn: #b4231f;
  --ok: #1a7f37;
  --pin: #e8590c;
  --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--tinte);
  background: var(--flaeche);
  font-size: 16px;
  line-height: 1.45;
}
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

.knopf {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--akzent); color: #fff; border: 0; border-radius: var(--radius);
  padding: 12px 20px; font-weight: 600; min-height: 48px;
}
.knopf:hover { background: var(--akzent-dunkel); }
.knopf.zweit { background: #fff; color: var(--akzent); border: 1.5px solid var(--akzent); }
.knopf.zweit:hover { background: #eaf2fb; }
.knopf:disabled { opacity: .5; cursor: default; }

.feld {
  width: 100%; border: 1.5px solid var(--linie); border-radius: var(--radius);
  padding: 12px 14px; background: #fff; min-height: 48px;
}
.feld:focus { outline: 2px solid var(--akzent); outline-offset: 1px; border-color: var(--akzent); }
label.beschriftung { display: block; font-size: 14px; font-weight: 600; color: var(--grau); margin: 0 0 6px; }

/* ---------- Startseite ---------- */
.start-halter { max-width: 660px; margin: 0 auto; padding: 24px 16px 60px; }
.marke { display: flex; align-items: center; gap: 14px; margin: 28px 0 8px; }
.logo-chip {
  background: #0e1418; border-radius: 12px; padding: 10px 14px;
  display: inline-flex; align-items: center; flex: none;
}
.logo-chip img { height: 26px; width: auto; display: block; }
.symbol { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: block; }
.marke h1 { font-size: 30px; margin: 0; letter-spacing: -.02em; }
.untertitel { color: var(--grau); margin: 0 0 28px; font-size: 17px; }

.karte { background: #fff; border: 1px solid var(--linie); border-radius: 14px; padding: 22px; }

#ablage {
  border: 2.5px dashed var(--linie); border-radius: 14px; background: #fff;
  padding: 44px 20px; text-align: center; color: var(--grau);
  transition: border-color .15s, background .15s; cursor: pointer;
}
#ablage.aktiv, #ablage:hover { border-color: var(--akzent); background: #f0f7ff; }
#ablage .gross { font-size: 19px; font-weight: 600; color: var(--tinte); margin: 10px 0 4px; }
#ablage svg { color: var(--akzent); }

.werkzeug-karte {
  margin-top: 14px; display: flex; align-items: center; gap: 16px; justify-content: space-between;
  flex-wrap: wrap;
}
.werkzeug-karte b { display: block; margin-bottom: 4px; }
.werkzeug-karte span { color: var(--grau); font-size: 14.5px; max-width: 52ch; display: block; }
.werkzeug-karte .knopf { flex: none; }

.schritte { display: grid; gap: 14px; margin: 30px 0; }
.schritt { display: flex; gap: 14px; align-items: flex-start; }
.schritt .nummer {
  flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--akzent);
  color: #fff; font-weight: 700; display: grid; place-items: center; font-size: 15px;
}
.schritt b { display: block; }
.schritt span { color: var(--grau); font-size: 15px; }

.fehler { color: var(--warn); font-weight: 600; margin: 12px 0 0; min-height: 1.4em; }
.fusszeile { color: var(--grau); font-size: 13px; text-align: center; margin-top: 48px; }
.fusszeile a { color: var(--grau); }

/* ---------- Projekt-Seite ---------- */
.kopfleiste {
  position: sticky; top: 0; z-index: 30; background: #fff; border-bottom: 1px solid var(--linie);
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; flex-wrap: wrap;
}
.kopfleiste .logo { text-decoration: none; }
.kopfleiste .logo .logo-chip { border-radius: 9px; padding: 7px 10px; }
.kopfleiste .logo img { height: 18px; }
#projektName {
  border: 1px solid transparent; border-radius: 8px; padding: 6px 8px; font-weight: 700;
  font-size: 17px; min-width: 120px; max-width: 40vw; background: transparent;
}
#projektName:hover, #projektName:focus { border-color: var(--linie); background: #fff; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
  border: 0; background: transparent; padding: 10px 14px; border-radius: 8px;
  font-weight: 600; color: var(--grau); min-height: 44px;
}
.tab[aria-selected="true"] { background: var(--akzent); color: #fff; }
.export-knoepfe { display: flex; gap: 8px; }
.export-knoepfe .knopf { padding: 8px 14px; min-height: 44px; }

.inhalt { padding: 0; }
.tab-seite { display: none; }
.tab-seite.aktiv { display: block; }

/* Plan-Ansicht */
.plan-werkzeuge {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #fff;
  border-bottom: 1px solid var(--linie); flex-wrap: wrap;
}
.plan-werkzeuge .hinweis { color: var(--grau); font-size: 14px; margin-left: auto; }
.werkzeug {
  border: 1.5px solid var(--linie); background: #fff; border-radius: 8px;
  min-width: 44px; min-height: 44px; font-size: 18px; font-weight: 700; color: var(--tinte);
}
.werkzeug:hover { border-color: var(--akzent); color: var(--akzent); }
#seitenAnzeige { font-weight: 600; color: var(--grau); font-size: 14px; min-width: 90px; text-align: center; }
#planWahl {
  border: 1.5px solid var(--linie); border-radius: 8px; min-height: 44px; padding: 0 8px;
  background: #fff; font-weight: 600; max-width: 180px;
}

#planRahmen { overflow: auto; height: calc(100dvh - 118px); background: #8a97a3; touch-action: pan-x pan-y; }
#planBuehne { position: relative; margin: 16px auto; width: max-content; box-shadow: 0 4px 18px rgba(0,0,0,.35); }
#planCanvas { display: block; background: #fff; }
#pinEbene { position: absolute; inset: 0; cursor: crosshair; }

#wegEbene { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#wegEbene .weg { fill: none; stroke: var(--pin); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
#wegEbene .weg.aktiv { stroke: var(--akzent); stroke-dasharray: 8 5; opacity: 1; }
#wegEbene .wegpunkt { fill: #fff; stroke: var(--akzent); stroke-width: 2.5; }
#wegEbene .messlinie { stroke: #0f7a3d; stroke-width: 2.5; stroke-dasharray: 4 5; }
#wegEbene .messpunkt { fill: #0f7a3d; }
#wegEbene .messtext { fill: #0f7a3d; font: 700 14px system-ui, sans-serif; paint-order: stroke; stroke: #fff; stroke-width: 4; }
#planBuehne.modus-zeichnen .pin, #planBuehne.modus-massstab .pin { pointer-events: none; opacity: .45; }
#planBuehne.modus-zeichnen #pinEbene, #planBuehne.modus-massstab #pinEbene { cursor: copy; }

#zeichenLeiste {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 35;
  display: flex; align-items: center; gap: 8px; background: #fff;
  border: 1px solid var(--linie); border-radius: 14px; padding: 8px 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,.22); max-width: calc(100vw - 20px);
}
#zeichenLeiste[hidden] { display: none; }
#zeichenLeiste .knopf { display: inline-flex; align-items: center; gap: 7px; padding: 8px 16px; min-height: 44px; }
#zeichenLeiste .symbol { width: 18px; height: 18px; }
#zeichenLaenge { font-weight: 700; min-width: 72px; text-align: center; white-space: nowrap; }
#zeichenStil { font-size: 14px; padding: 0 12px; }

#massstabSheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; display: none;
  background: #fff; border-radius: 18px 18px 0 0; box-shadow: 0 -6px 30px rgba(0,0,0,.25);
  max-height: 88dvh; overflow: auto; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-width: 720px; margin: 0 auto;
}
#massstabSheet.offen { display: block; }
#massstabSheet h2 { margin: 0 0 8px; font-size: 19px; }
.foto-bereich { margin-top: 16px; }
.foto-gitter { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.foto-thumb { position: relative; width: 76px; height: 76px; border-radius: 10px; overflow: hidden; border: 1px solid var(--linie); }
.foto-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.foto-thumb button {
  position: absolute; top: 2px; right: 2px; width: 24px; height: 24px; border: 0; border-radius: 50%;
  background: rgba(22, 34, 46, .75); color: #fff; font-size: 13px; line-height: 1; display: grid; place-items: center;
}
.weg-aktionen { margin-top: 16px; }
.weg-aktionen .knopf { display: inline-flex; align-items: center; gap: 8px; }
.weg-aktionen .symbol { width: 18px; height: 18px; }
table.daten input[type="text"].auto-laenge { color: var(--akzent); font-weight: 600; }

.pin {
  position: absolute; transform: translate(-50%, -100%);
  background: var(--pin); color: #fff; font-weight: 700; font-size: 13px;
  min-width: 26px; height: 26px; padding: 0 6px; border-radius: 13px 13px 13px 2px;
  display: grid; place-items: center; cursor: pointer; border: 2px solid #fff;
  box-shadow: 0 1px 5px rgba(0,0,0,.4);
}
.pin:hover { background: var(--akzent); }

/* Bottom-Sheet */
#schleier {
  position: fixed; inset: 0; background: rgba(10, 20, 30, .45); z-index: 40; display: none;
}
#schleier.offen { display: block; }
#erfassung {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; display: none;
  background: #fff; border-radius: 18px 18px 0 0; box-shadow: 0 -6px 30px rgba(0,0,0,.25);
  max-height: 88dvh; overflow: auto; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-width: 720px; margin: 0 auto;
}
#erfassung.offen { display: block; }
#erfassung h2 { margin: 0 0 14px; font-size: 19px; }
.formular-gitter { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.formular-gitter .breit { grid-column: 1 / -1; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--linie); background: #fff; border-radius: 999px;
  padding: 9px 16px; font-weight: 600; min-height: 44px;
}
.chip[aria-pressed="true"] { background: var(--akzent); border-color: var(--akzent); color: #fff; }
.sheet-aktionen { display: flex; gap: 10px; margin-top: 18px; }
.sheet-aktionen .knopf { flex: 1; }
.knopf.loeschen { background: #fff; color: var(--warn); border: 1.5px solid var(--warn); flex: 0 0 auto; }
.knopf.loeschen:hover { background: #fdf0ef; }

/* KI-Vorschläge */
.werkzeug.ki { font-size: 14px; color: var(--akzent); border-color: var(--akzent); display: inline-flex; align-items: center; gap: 7px; padding: 0 12px; }
.werkzeug.ki:disabled { opacity: .6; }
.werkzeug.ki .symbol { width: 17px; height: 17px; }
.symbole-link {
  display: inline-flex; align-items: center; font-size: 14px; font-weight: 600;
  text-decoration: none; padding: 0 12px;
}
#symbolePopup {
  position: fixed; inset: 4dvh 4vw; z-index: 45; background: var(--flaeche);
  border-radius: 16px; box-shadow: 0 10px 50px rgba(0,0,0,.4); display: flex; flex-direction: column;
  overflow: hidden;
}
#symbolePopup[hidden] { display: none; }
#symbolePopup .popup-kopf {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--linie);
}
#symboleRahmen { flex: 1; border: 0; width: 100%; }
@media (max-width: 700px) { #symbolePopup { inset: 0; border-radius: 0; } }
.pin.vorschau { background: #fff; color: var(--akzent); border: 2px dashed var(--akzent); box-shadow: none; }
#kiSheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; display: none;
  background: #fff; border-radius: 18px 18px 0 0; box-shadow: 0 -6px 30px rgba(0,0,0,.25);
  max-height: 88dvh; overflow: auto; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-width: 720px; margin: 0 auto;
}
#kiSheet.offen { display: block; }
#kiSheet h2 { margin: 0 0 8px; font-size: 19px; }
.ki-hinweis { color: var(--grau); font-size: 14px; margin: 0 0 14px; }
.ki-eintrag {
  display: flex; align-items: center; gap: 12px; border: 1px solid var(--linie);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 8px;
}
.ki-eintrag input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--akzent); flex: none; }
.ki-eintrag .nrchip {
  flex: none; background: var(--flaeche); border-radius: 999px; padding: 3px 10px;
  font-weight: 700; font-size: 13px; color: var(--grau);
}
.ki-eintrag .beschreibung b { display: block; }
.ki-eintrag .beschreibung span { color: var(--grau); font-size: 14px; }
.ki-eintrag .ohne-pin { margin-left: auto; color: var(--grau); font-size: 12px; flex: none; }

/* Tabellen (Kabelliste + Protokoll) */
.tabellen-halter { padding: 14px; overflow-x: auto; }
table.daten { border-collapse: collapse; background: #fff; width: 100%; min-width: 760px; border: 1px solid var(--linie); border-radius: 10px; }
table.daten th {
  text-align: left; font-size: 13px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--grau); padding: 10px 10px; border-bottom: 2px solid var(--linie); background: #fafbfc;
  position: sticky; top: 0;
}
table.daten td { border-bottom: 1px solid var(--linie); padding: 4px 6px; }
table.daten tr:last-child td { border-bottom: 0; }
table.daten input[type="text"] {
  width: 100%; border: 1px solid var(--linie); border-radius: 6px; padding: 9px 8px;
  background: #fbfcfd; min-width: 70px;
}
table.daten input[type="text"]::placeholder { color: #a8b4bf; }
table.daten input[type="text"]:hover { border-color: var(--grau); }
table.daten input[type="text"]:focus { border-color: var(--akzent); background: #fff; outline: 2px solid var(--akzent); outline-offset: -1px; }
table.daten .nr { font-weight: 700; text-align: center; width: 46px; color: var(--grau); }
table.daten .pin-spalte { text-align: center; width: 54px; }
.pin-knopf { border: 0; background: transparent; font-size: 17px; }
.pin-knopf.hat-pin { color: var(--pin); }
.pin-knopf.ohne { color: var(--linie); }
.zeile-loeschen { border: 0; background: transparent; color: var(--grau); font-size: 17px; width: 40px; height: 40px; border-radius: 8px; }
.zeile-loeschen:hover { color: var(--warn); background: #fdf0ef; }
.io-haken { width: 22px; height: 22px; accent-color: var(--ok); }

.listen-aktionen { display: flex; gap: 10px; padding: 0 14px 20px; flex-wrap: wrap; }
.leer-hinweis { color: var(--grau); text-align: center; padding: 40px 20px; }

/* Protokoll-Kopf */
.kopf-gitter { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; padding: 14px; }
.kopf-gitter .feld-gruppe { background: #fff; border: 1px solid var(--linie); border-radius: 10px; padding: 10px 12px; }
.kopf-gitter label { display: block; font-size: 12px; font-weight: 700; color: var(--grau); text-transform: uppercase; letter-spacing: .03em; }
.kopf-gitter input, .kopf-gitter select {
  width: 100%; border: 1px solid var(--linie); border-radius: 8px; padding: 8px 10px;
  margin-top: 6px; font-size: 16px; outline: none; background: #fbfcfd;
}
.kopf-gitter input::placeholder { color: #a8b4bf; }
.kopf-gitter input:focus, .kopf-gitter select:focus { border-color: var(--akzent); background: #fff; }
.pruef-haken .erklaerung { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 13px; color: var(--grau); margin-top: 4px; display: block; }
.pruef-haken .haken-zeile {
  display: flex; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0;
  font-size: 14px; font-weight: 500; color: var(--tinte); margin-top: 6px;
}
.pruef-haken .haken-zeile input { width: auto; }
table.daten input.grenzwert-warnung { color: var(--warn); font-weight: 700; }

.speicher-status { font-size: 13px; color: var(--grau); min-width: 80px; text-align: right; }
.speicher-status.fehler { color: var(--warn); font-weight: 700; }

/* Read-only-Ansicht (/a/<leseId>) */
body.nur-lesen .pin { pointer-events: none; }
body.nur-lesen #pinEbene { cursor: default; }
body.nur-lesen .zeile-loeschen, body.nur-lesen .pin-knopf { visibility: hidden; }

/* Auf grossen Bildschirmen: Dialoge mittig statt als Bottom-Sheet */
@media (min-width: 720px) {
  #erfassung, #massstabSheet, #kiSheet {
    bottom: auto; top: 50%; left: 50%; right: auto;
    transform: translate(-50%, -50%);
    border-radius: 18px; width: min(680px, 92vw); max-height: 90dvh;
    padding: 22px 24px 20px;
  }
}
.sheet-zu {
  position: absolute; top: 14px; right: 14px; border: 0; background: transparent;
  color: var(--grau); width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center;
}
.sheet-zu:hover { background: var(--flaeche); color: var(--tinte); }
#erfassung { position: fixed; }

@media (max-width: 700px) {
  .tabs { order: 5; width: 100%; margin-left: 0; }
  .tab { flex: 1; padding: 10px 6px; }
  .formular-gitter { grid-template-columns: 1fr; }
  #planRahmen { height: calc(100dvh - 168px); }
}
