:root {
    --ink: #1e2430;
    --muted: #78808f;
    --line: #e4e6ea;
    --line-dark: #d3d6dc;
    --bg: #f4f5f7;
    --panel: #ffffff;
    --bad: #d0342c;
    --bad-bg: #fdeceb;
    --ok: #1e8a4c;
    --ok-bg: #eaf7ef;
    --warn: #b3660b;
    --warn-bg: #fdf1e0;
    --accent: #3457d5;
    --accent-bg: #eef1fd;
    --radius: 10px;
    --radius-sm: 7px;
    /* Lesespalte im Detailbereich: verhindert, dass Pruefpunkt und Status auf
       grossen Monitoren meterweit auseinanderlaufen. */
    --content-max: 820px;
    --shadow: 0 1px 2px rgba(20,24,34,.04), 0 1px 8px rgba(20,24,34,.05);
    --shadow-md: 0 4px 16px rgba(20,24,34,.08);
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; }
  body {
    margin: 0;
    font-family: "Inter", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
  }
  button {
    font-family: inherit;
    font-size: 15px;
    cursor: pointer;
  }

  /* ---------- App shell ---------- */
  .app { display: flex; flex-direction: column; height: 100vh; }

  header.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
    flex-wrap: wrap;
    gap: 10px;
  }
  .brand { display: flex; align-items: baseline; gap: 8px; }
  .brand b { font-size: 20px; letter-spacing: -0.02em; }
  .brand span { font-size: 13px; color: var(--muted); }

  .modeswitch {
    display: flex;
    background: #eceef2;
    padding: 3px;
    border-radius: var(--radius-sm);
    gap: 2px;
  }
  .modeswitch button {
    padding: 6px 14px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--muted);
    font-weight: 500;
    transition: background .12s ease, color .12s ease;
  }
  .modeswitch button.active { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }

  .topactions { display: flex; gap: 8px; }
  .btn {
    padding: 9px 16px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--ink);
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: background .12s ease, border-color .12s ease;
  }
  .btn:hover { background: #f7f8fa; border-color: #ccd0d8; }
  .btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
  .btn.primary:hover { background: #2c48b8; }
  .btn.ghost { border-color: transparent; color: var(--muted); background: transparent; }
  .btn.ghost:hover { background: #f0f1f4; }
  .btn:disabled { opacity: .4; cursor: default; }

  /* ---------- status strip ---------- */
  .statusbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
    gap: 8px;
  }
  .pills { display: flex; gap: 6px; flex-wrap: wrap; }
  .pill {
    padding: 7px 15px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--muted);
    font-size: 14px;
    border-radius: 999px;
    font-weight: 500;
    transition: background .12s ease, color .12s ease;
  }
  .pill.active { background: var(--ink); color: #fff; border-color: var(--ink); }

  .batchbar {
    display: none;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: var(--muted);
  }
  .batchbar.show { display: flex; }

  /* ---------- main split view ---------- */
  main { flex: 1; overflow: hidden; }
  .view { display: none; height: 100%; }
  .view.active { display: flex; }

  .list-pane {
    width: 360px;
    min-width: 300px;
    border-right: 1px solid var(--line);
    overflow-y: auto;
    background: var(--panel);
    padding: 8px;
  }
  .list-item {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 13px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 3px;
  }
  .list-item:hover { background: #f5f6f8; }
  .list-item.selected { background: var(--accent-bg); }
  .list-item input[type=checkbox] { margin-top: 4px; width: 17px; height: 17px; accent-color: var(--accent); }
  .li-body { flex: 1; cursor: pointer; }
  .li-title { font-weight: 600; font-size: 15px; }
  .li-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
  .li-badge {
    display: inline-block;
    margin-top: 6px;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 9px;
    background: var(--bad-bg);
    color: var(--bad);
    border-radius: 999px;
  }
  .li-empty-note {
    padding: 14px 16px;
    font-size: 14px;
    color: var(--muted);
  }

  .detail-pane { flex: 1; overflow-y: auto; padding: 24px 32px; }
  /* Alles im Detailbereich bleibt in einer Lesespalte. Sonst wandert der Status
     auf breiten Monitoren ans andere Ende des Bildschirms. */
  .detail-header,
  .checkrow,
  .okgroup,
  .okgroup-body,
  .detail-footer { max-width: var(--content-max); }
  .detail-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 18px; flex-wrap: wrap; gap: 8px;}
  .detail-header h2 { margin: 0; font-size: 24px; letter-spacing: -0.01em; }
  .detail-header .sub { font-size: 14px; color: var(--muted); margin-top: 3px; }
  .detail-counts { font-size: 14px; color: var(--muted); font-weight: 500; }

  .checkrow {
    border: 1px solid var(--line);
    background: var(--panel);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
  }
  .checkrow.bad { border-left: 3px solid var(--bad); }
  .cr-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
  .cr-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 5px 11px;
    border-radius: 999px;
    color: var(--bad);
    background: var(--bad-bg);
    flex-shrink: 0;
  }
  .cr-status::before {
    content: '';
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--bad);
  }
  .cr-title { font-weight: 600; font-size: 17px; }

  .thumbstrip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; }
  .thumbstrip img {
    height: 84px;
    width: 112px;
    object-fit: cover;
    border-radius: 7px;
    border: 1px solid var(--line);
    flex-shrink: 0;
    cursor: zoom-in;
    transition: transform .1s ease;
  }
  .thumbstrip img:hover { transform: scale(1.03); box-shadow: var(--shadow-md); }

  .cr-comment {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fafbfc;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    min-height: 44px;
  }
  .cr-comment:focus { outline: none; border-color: var(--accent); background: #fff; }

  .okgroup {
    border: 1px solid var(--line);
    background: var(--panel);
    border-radius: var(--radius);
    padding: 13px 16px;
    font-size: 15px;
    color: var(--muted);
    cursor: pointer;
    margin-bottom: 10px;
    font-weight: 600;
  }
  .okgroup:hover { background: #f9fafb; }
  .okgroup .toggle-icon { font-weight: 600; margin-right: 8px; }
  .okgroup-body {
    display: none;
    margin: -4px 0 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    overflow: hidden;
  }
  .okgroup-body.open { display: block; }
  .okgroup.open-parent { color: var(--ink); }

  /* Eine Zeile = ein Pruefpunkt. Status als Badge direkt am Ende derselben
     Zeile, nicht am rechten Bildschirmrand. */
  .ok-line { padding: 12px 16px; border-top: 1px solid var(--line); font-size: 16px; }
  .ok-line:first-child { border-top: none; }
  .ok-line:nth-child(odd) { background: #fbfbfc; }
  .ok-line:hover { background: #f5f6f8; }
  .ok-line-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
  }
  .ok-line .thumbstrip { padding: 10px 0 2px; }
  .ok-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--ok);
    background: var(--ok-bg);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 5px 11px;
    border-radius: 999px;
    flex-shrink: 0;
  }
  .ok-tag::before {
    content: '';
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--ok);
  }

  .detail-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
  }
  .btn.warn { border-color: #f3c6c3; color: var(--bad); background: var(--bad-bg); }
  .btn.warn:hover { background: #fbdcda; }

  /* ---------- Sichtungslauf ---------- */
  .sicht-view { flex-direction: column; align-items: center; justify-content: center; gap: 14px; width: 100%; padding: 20px; }
  .sicht-progress { font-size: 12px; color: var(--muted); }
  .sicht-frame {
    position: relative;
    width: min(560px, 90vw);
    height: min(420px, 55vh);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    cursor: zoom-in;
  }
  .sicht-frame img {
    max-width: 100%;
    max-height: 100%;
    pointer-events: none;
  }
  .sicht-zoomtag {
    position: absolute; bottom: 10px; right: 10px;
    font-size: 10px; background: rgba(255,255,255,.85); color: var(--ink); border: 1px solid var(--line); padding: 4px 9px; border-radius: 999px;
  }
  .sicht-meta { font-size: 13px; text-align: center; color: var(--muted); }
  .sicht-meta b { display: block; font-size: 15px; color: var(--ink); margin-bottom: 2px; }
  .sicht-buttons { display: flex; justify-content: center; gap: 14px; width: 100%; }
  .sicht-buttons button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 28px;
    font-size: 14px;
    font-weight: 600;
    border: 1px solid var(--line);
    background: var(--panel);
    min-width: 150px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
  .sicht-buttons button.ok { border-color: #b7e3c6; color: var(--ok); background: var(--ok-bg); }
  .sicht-buttons button.ok:hover { background: #dcf3e3; }
  .sicht-buttons button.bad { border-color: #f3c6c3; color: var(--bad); background: var(--bad-bg); }
  .sicht-buttons button.bad:hover { background: #fbdcda; }

  .sicht-reasons { display: none; gap: 6px; flex-wrap: wrap; justify-content: center; max-width: 480px; }
  .sicht-reasons.show { display: flex; }
  .sicht-reasons button {
    font-size: 11px;
    padding: 6px 12px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--muted);
    border-radius: 999px;
  }
  .sicht-reasons button:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
  .sicht-reasons button.picked { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }

  .sicht-comment {
    display: block;
    width: min(420px, 90vw);
    margin: 0 auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fafbfc;
    padding: 8px 10px;
    font-family: inherit;
    font-size: 12px;
    resize: vertical;
    min-height: 40px;
  }
  .sicht-comment:focus { outline: none; border-color: var(--accent); background: #fff; }

  .sicht-hint { font-size: 11px; color: var(--muted); text-align: center; max-width: 460px; }
  kbd {
    border: 1px solid var(--line);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 1px 6px;
    font-family: inherit;
    font-size: 10px;
    background: #fff;
    color: var(--muted);
  }

  .sicht-summary { width: min(560px, 90vw); }
  .sicht-summary h3 { margin: 0 0 10px; font-size: 15px; }
  .sicht-summary .sr {
    display: flex; justify-content: space-between; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 6px; font-size: 12px; background: var(--panel);
  }

  /* ---------- lightbox ---------- */
  .lightbox {
    display: none;
    position: fixed; inset: 0;
    background: rgba(244, 245, 247, .88);
    backdrop-filter: blur(28px) saturate(160%);
    -webkit-backdrop-filter: blur(28px) saturate(160%);
    z-index: 50;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }
  .lightbox.show { display: flex; }
  .lightbox .lb-stage {
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: 96vw;
    max-height: 90vh;
    /* Kein overflow:hidden. Die Buehne ist nur so gross wie das ungezoomte
       Bild - mit Clipping waere jedes Hineinzoomen auf diesen Ausschnitt
       beschnitten, statt ueber den Bildschirm zu wachsen. */
    overflow: visible;
  }
  .lightbox img {
    /* Vorschau in natuerlicher Groesse, nach unten und oben begrenzt: kleine
       Fotos werden lesbar hochgezogen, grosse passen noch auf den Schirm. */
    min-width: min(640px, 88vw);
    max-width: 92vw;
    max-height: 90vh;
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    user-select: none;
    -webkit-user-drag: none;
  }
  .lightbox .lb-close {
    position: absolute; top: 18px; right: 22px;
    color: var(--ink); font-size: 13px; border: 1px solid var(--line); border-radius: var(--radius-sm);
    background: rgba(255,255,255,.7); padding: 7px 13px;
  }
  .lightbox .lb-close:hover { background: #fff; }
  .lightbox .lb-hint { position: absolute; bottom: 18px; color: var(--muted); font-size: 11px; }
  .lightbox .lb-nav {
    flex-shrink: 0;
    width: 46px;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ink);
    font-size: 24px;
    line-height: 1;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: rgba(255,255,255,.7);
  }
  .lightbox .lb-nav:hover { background: #fff; }
  .lightbox .lb-counter {
    position: absolute; top: 18px; left: 50%; transform: translateX(-50%);
    color: var(--ink); font-size: 12px; background: rgba(255,255,255,.7);
    padding: 4px 11px; border-radius: 999px;
  }

  /* ---------- modal ---------- */
  .modal-overlay {
    display: none;
    position: fixed; inset: 0; background: rgba(15,17,23,.45);
    align-items: center; justify-content: center; z-index: 60;
  }
  .modal-overlay.show { display: flex; }
  .modal {
    background: #fff; border: 1px solid var(--line);
    border-radius: 14px;
    width: 380px; padding: 20px;
    box-shadow: var(--shadow-md);
  }
  .modal h3 { margin: 0 0 10px; font-size: 15px; }
  .modal p { font-size: 12px; color: var(--muted); line-height: 1.5; }
  .modal .modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
  .modal .fake-link { font-size: 11px; background: #f4f5f7; border-radius: var(--radius-sm); border: 1px solid var(--line); padding: 9px 10px; word-break: break-all; margin: 12px 0; color: var(--muted); }
  .modal .timer { font-size: 11px; color: var(--warn); font-weight: 500; }
  .modal-comment {
    display: block;
    width: 100%;
    margin-top: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fafbfc;
    padding: 8px 10px;
    font-family: inherit;
    font-size: 12px;
    resize: vertical;
    min-height: 60px;
  }
  .modal-comment:focus { outline: none; border-color: var(--accent); background: #fff; }

  .month-tabs {
    display: flex;
    gap: 2px;
    margin-top: 12px;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
  }
  .month-tab {
    padding: 7px 9px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .month-tab.active { color: var(--ink); border-bottom-color: var(--accent); }
  .month-tab .month-dot {
    display: inline-block;
    background: var(--warn-bg); color: var(--warn);
    font-size: 10px; font-weight: 700;
    border-radius: 999px; padding: 1px 6px;
    margin-left: 3px;
  }

  .kw-list { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; max-height: 320px; overflow-y: auto; }
  .kw-row {
    display: flex; align-items: center; justify-content: space-between;
    border: 1px solid var(--line); border-radius: var(--radius-sm);
    padding: 10px 12px;
  }
  .kw-row.current { border-color: var(--accent); background: var(--accent-bg); }
  .kw-left { display: flex; flex-direction: column; gap: 2px; }
  .kw-label { font-size: 13px; font-weight: 600; }
  .kw-sub { font-size: 11px; color: var(--muted); }
  .kw-status {
    font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
    padding: 3px 8px; border-radius: 999px;
  }
  .kw-status.done { color: var(--ok); background: var(--ok-bg); }
  .kw-status.pending { color: var(--warn); background: var(--warn-bg); }
  .kw-row .kw-action { display: flex; align-items: center; gap: 8px; }
  .kw-row .btn { padding: 5px 10px; font-size: 11px; }

  .draftmark {
    position: fixed; bottom: 10px; left: 12px; font-size: 10px; color: #b6bac2; letter-spacing: .04em;
  }

/* Begruendung des Technikers - Kontext, nicht bearbeitbar */
.cr-reason {
  margin: 10px 0 12px;
  padding: 11px 14px;
  background: #f6f4ef;
  border-left: 3px solid #c9a227;
  border-radius: 4px;
  font-size: 15px;
  line-height: 1.5;
  color: #4a453c;
}
.cr-reason b {
  display: block;
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #8a8272;
  margin-bottom: 3px;
  font-weight: 600;
}

/* Umschalter OK <-> nicht OK. Bewusst kleiner als die Knoepfe im Fuss - die
   Zeile soll weiter vom Pruefpunkt handeln und nicht vom Knopf. Die Farben
   sind dieselben wie im Sichtungslauf. */
.cr-actions,
.ok-line-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.btn.umschalter {
  padding: 6px 12px;
  font-size: 14px;
}
.btn.umschalter.nach-ok { border-color: #b7e3c6; color: var(--ok); background: var(--ok-bg); }
.btn.umschalter.nach-ok:hover:not(:disabled) { background: #dcf3e3; border-color: #93d3ab; }
.btn.umschalter.nach-bad { border-color: #f3c6c3; color: var(--bad); background: var(--bad-bg); }
.btn.umschalter.nach-bad:hover:not(:disabled) { background: #fbdcda; border-color: #eda8a3; }

/* Fehlermeldung an der betroffenen Zeile statt in einem Dialog: der Nutzer
   sieht sofort, welcher Punkt nicht durchgegangen ist. */
.cr-fehler,
.nt-fehler {
  display: none;
  font-size: 14px;
  color: var(--bad);
}
.cr-fehler.show,
.nt-fehler.show { display: inline; }

/* Die Begruendung wird nach dem Wechsel nachgereicht, deshalb steht das Feld
   unter dem Umschalter und nicht davor. */
.cr-grund,
.nt-grund {
  display: block;
  width: 100%;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fafbfc;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  min-height: 44px;
}
.cr-grund:focus,
.nt-grund:focus { outline: none; border-color: var(--accent); background: #fff; }

/* Technikerseite: dort ist der Umschalter am Telefon der Hauptknopf der Karte
   und darf die volle Breite nehmen. Die Farbe folgt dem aktuellen Zustand. */
.nt-card .nt-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.nt-card .btn.umschalter {
  flex: 1 1 auto;
  border-color: #b7e3c6;
  color: var(--ok);
  background: var(--ok-bg);
}
.nt-card .btn.umschalter[data-wert="ok"] {
  border-color: #f3c6c3;
  color: var(--bad);
  background: var(--bad-bg);
}
