/* Kundensicht - Stil (Auftrag 1.7.6) */
:root {
  --primary: #E30613;
  --text: #1F2937;
  --muted: #6B7280;
  --border: #E5E7EB;
  --bg: #F9FAFB;
  --card: #FFFFFF;
  --erledigt: #10B981;
  --geplant: #3B82F6;
  --offen: #F59E0B;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--text); }
a:hover { color: var(--primary); }

/* Kopf */
.kopf {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--card);
  border-top: 4px solid var(--primary);
  border-bottom: 1px solid var(--border);
}
.kopf-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.marke {
  font-weight: 700;
  font-size: 1.15rem;
  text-decoration: none;
  color: var(--text);
}
.untertitel { color: var(--muted); }
.kopf .spacer { flex: 1; }

.knopf {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
}
.knopf:hover { border-color: var(--text); }
.knopf-primaer {
  background: var(--primary);
  border-color: var(--primary);
  color: #FFFFFF;
}
.knopf-primaer:hover { filter: brightness(0.92); border-color: var(--primary); }

/* Inhalt */
main {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}
h1 { font-size: 1.5rem; margin: 8px 0 16px; }
h2 { font-size: 1.15rem; margin: 24px 0 8px; color: var(--muted); }

.zurueck { display: inline-block; margin-bottom: 8px; color: var(--muted); }

.hinweis {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.fehlertext { color: var(--primary); }
.lade { color: var(--muted); }

/* Rollout-Karten */
.rollout-liste { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.rollout-karte {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-decoration: none;
  color: var(--text);
}
.rollout-karte:hover, .rollout-karte:focus { border-color: var(--primary); color: var(--text); }
.rollout-karte .titel { font-weight: 600; font-size: 1.05rem; }
.rollout-karte .zeitraum { color: var(--muted); font-size: 0.9rem; }
.zaehler { display: flex; gap: 16px; flex-wrap: wrap; margin: 8px 0; font-size: 0.95rem; }
.zaehler span::before {
  content: "";
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}
.zaehler .z-erledigt::before { background: var(--erledigt); }
.zaehler .z-geplant::before { background: var(--geplant); }
.zaehler .z-offen::before { background: var(--offen); }

.balken {
  display: flex;
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  background: var(--border);
}
.balken .b-erledigt { background: var(--erledigt); }
.balken .b-geplant { background: var(--geplant); }
.balken .b-offen { background: var(--offen); }
.fortschritt { font-size: 0.9rem; color: var(--muted); margin-top: 6px; }

/* Filterzeile */
.werkzeuge {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}
.werkzeuge input[type="search"], .werkzeuge select {
  font: inherit;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
}
.werkzeuge input[type="search"] { flex: 1; min-width: 220px; }
.werkzeuge select { max-width: 100%; min-width: 0; }
.werkzeuge #kw { flex: 0 1 auto; text-overflow: ellipsis; }
.werkzeuge .treffer { color: var(--muted); margin-left: auto; }

/* Tabelle */
.tabelle-rahmen {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td.umbruch { white-space: normal; }
tbody tr:last-child td { border-bottom: none; }
th { background: var(--bg); font-weight: 600; font-size: 0.9rem; }
th button {
  font: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--text);
}
th button:hover { color: var(--primary); }
th[aria-sort="ascending"] button::after { content: " \25B2"; font-size: 0.75em; }
th[aria-sort="descending"] button::after { content: " \25BC"; font-size: 0.75em; }

tr.gruppe th {
  background: var(--bg);
  border-top: 2px solid var(--border);
  font-size: 0.95rem;
  padding-top: 12px;
}

.status {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #FFFFFF;
}
.status-erledigt { background: var(--erledigt); }
.status-geplant { background: var(--geplant); }
.status-offen { background: var(--offen); color: var(--text); }

/* Anmeldung */
.anmelde-karte {
  max-width: 400px;
  margin: 40px auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.anmelde-karte label { display: block; margin: 12px 0 4px; font-weight: 600; }
.anmelde-karte input {
  width: 100%;
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.anmelde-karte .knopf-primaer { width: 100%; margin-top: 16px; padding: 10px; }
.anmelde-karte .fehlertext { min-height: 1.5em; margin: 12px 0 0; }

/* Fuss */
.fuss {
  border-top: 1px solid var(--border);
  background: var(--card);
}
.fuss-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 0.9rem;
  color: var(--muted);
}
.fuss a { color: var(--muted); }

/* ---- Stufe 2 ------------------------------------------------------------- */
.karte {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.aktionen { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
a.knopf { display: inline-block; text-decoration: none; }

/* Filialliste: Zeile antippbar */
#filialen tbody tr[data-id] { cursor: pointer; }
#filialen tbody tr[data-id]:hover td { background: var(--bg); }
#filialen td a.filial-link { color: inherit; }

.feiertag {
  display: block;
  font-size: 0.8rem;
  color: #92400E;
  white-space: normal;
}
.feiertag::before { content: "\25C6  "; font-size: 0.7em; }

/* Kennzahlen (A15) */
.kennzahlen { margin-bottom: 16px; }
.kennzahlen h2 { margin-top: 0; }
.kz-raster { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.kz {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.kz .kz-wert { display: block; font-size: 1.4rem; font-weight: 700; }
.kz .kz-name { display: block; color: var(--muted); font-size: 0.85rem; }
.kz .kz-detail { display: block; color: var(--muted); font-size: 0.8rem; }

/* Filialdetail (A6, A7) */
.kopfdaten, .leistung-daten {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 16px;
  margin: 0;
}
.kopfdaten dt, .leistung-daten dt { color: var(--muted); }
.kopfdaten dd, .leistung-daten dd { margin: 0; overflow-wrap: anywhere; }
.leistungen { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.leistung-kopf { display: flex; gap: 12px; align-items: baseline; justify-content: space-between; flex-wrap: wrap; margin-bottom: 8px; }
.leistung-name { font-size: 1.05rem; }
.bemerkung { margin: 8px 0 0; font-style: italic; }
.anweisung { margin-top: 8px; }
.anweisung summary { cursor: pointer; color: var(--muted); }
.anweisung p { white-space: pre-line; margin: 6px 0 0; }
.ohne-foto { color: var(--muted); font-size: 0.9rem; margin: 10px 0 0; }
.vorschau { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.vorschau-bild {
  position: relative;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: zoom-in;
  overflow: hidden;
  width: 120px;
  height: 120px;
}
.vorschau-bild img { display: block; width: 120px; height: 120px; object-fit: cover; }
.vorschau-bild:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.vorschau-typ {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: rgba(31, 41, 55, 0.75);
  color: #FFFFFF;
  font-size: 0.75rem;
  padding: 2px 6px;
  text-align: left;
}

/* Grossansicht */
html.lb-offen, html.lb-offen body { overflow: hidden; }
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(17, 24, 39, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox[hidden] { display: none; }
.lb-figur {
  margin: 0;
  max-width: calc(100vw - 112px);
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  touch-action: pan-y pinch-zoom;
  user-select: none;
}
.lb-bild { max-width: 100%; max-height: calc(100vh - 80px); object-fit: contain; background: #374151; }
.lb-leiste { display: flex; gap: 16px; justify-content: space-between; width: 100%; color: #F9FAFB; padding: 8px 4px; font-size: 0.95rem; }
.lb-zaehler { white-space: nowrap; color: #D1D5DB; }
.lb-knopf {
  position: absolute;
  font: inherit;
  font-size: 2rem;
  line-height: 1;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #FFFFFF;
  cursor: pointer;
}
.lb-knopf:hover, .lb-knopf:focus-visible { background: rgba(255, 255, 255, 0.3); }
.lb-zurueck { left: 8px; top: 50%; transform: translateY(-50%); }
.lb-weiter { right: 8px; top: 50%; transform: translateY(-50%); }
.lb-schliessen { right: 8px; top: 8px; }

@media (max-width: 639px) {
  .lb-figur { max-width: 100vw; }
  .lb-zurueck, .lb-weiter { top: auto; bottom: 8px; transform: none; }
  .lb-bild { max-height: calc(100vh - 140px); }
  .kopfdaten, .leistung-daten { grid-template-columns: 1fr; }
  .kopfdaten dd, .leistung-daten dd { margin-bottom: 6px; }
  .kz-raster { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Telefon: eine Spalte, Liste als Karten */
@media (max-width: 639px) {
  .kopf .untertitel { display: none; }
  .kopf-inner { flex-wrap: nowrap; }
  .marke { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .rollout-liste { grid-template-columns: 1fr; }
  .werkzeuge input[type="search"] { min-width: 100%; }
  .werkzeuge #kw { flex: 1 1 100%; width: 100%; }
  .werkzeuge .treffer { margin-left: 0; width: 100%; }
  .tabelle-rahmen { background: transparent; border: none; overflow: visible; }
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tr {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 6px 0;
  }
  td { border-bottom: none; padding: 3px 12px; white-space: normal; }
  tr.gruppe { background: transparent; border: none; margin: 16px 0 6px; padding: 0; }
  tr.gruppe th { display: block; background: transparent; border: none; padding: 0; }
  td::before {
    content: attr(data-label);
    display: inline-block;
    min-width: 7.5em;
    color: var(--muted);
    font-size: 0.85rem;
  }
}
