:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #dcdfe4;
  --border-strong: #c3c8d0;
  --text: #1c2024;
  --text-muted: #5b6370;
  --accent: #1f5f8b;
  --accent-text: #ffffff;
  --success-bg: #e3f4e8;
  --success-text: #1c6b38;
  --error-bg: #fdeaea;
  --error-text: #9b2020;
  --warn-bg: #fdf3e0;
  --warn-text: #8a5a08;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --surface: #1c2024;
    --surface-2: #22272c;
    --border: #333a41;
    --border-strong: #454e57;
    --text: #e6e9ec;
    --text-muted: #9aa4b0;
    --accent: #5aa7db;
    --accent-text: #0c1116;
    --success-bg: #17301f;
    --success-text: #7fd39b;
    --error-bg: #351a1a;
    --error-text: #f19b9b;
    --warn-bg: #362a13;
    --warn-text: #e5bf72;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); }

/* --- Kopfzeile --- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
  flex-wrap: wrap;
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); letter-spacing: -0.2px; }
.menu-check, .menu-btn { display: none; }
.menu-panel { display: flex; flex: 1; align-items: center; gap: 24px; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a {
  padding: 6px 12px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
}
.topbar nav a:hover { background: var(--surface-2); color: var(--text); }
.topbar nav a.active { background: var(--accent); color: var(--accent-text); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.who { color: var(--text-muted); text-decoration: none; font-size: 14px; }
.who:hover { text-decoration: underline; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 16px 60px; }
.foot {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  text-align: center; color: var(--text-muted); font-size: 13px; padding: 16px 0 24px;
}
.kfk {
  display: inline-flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text-muted);
}
.kfk:hover { color: var(--text); }
.kfk strong { font-weight: 600; }
.kfk img {
  display: block; width: 32px; height: 32px;
  /* Die Schrift im Logo ist dunkelbraun und verschwaende auf dem dunklen
     Untergrund fast. Die weisse Scheibe dahinter nimmt die runde Form des
     Logos auf und wirkt in beiden Farbschemata gleich. */
  background: #fff; border-radius: 50%;
}
.login-wrap .kfk img { width: 40px; height: 40px; }

/* --- Überschriften --- */
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
h1 { font-size: 22px; margin: 0; letter-spacing: -0.3px; }
h2 { font-size: 17px; margin: 0 0 12px; letter-spacing: -0.2px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.sub { color: var(--text-muted); font-size: 14px; margin: 4px 0 0; }

/* --- Karten --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.card.tight { padding: 0; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.stat .n { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; }
.stat .l { color: var(--text-muted); font-size: 13px; }

/* --- Tabellen --- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; padding: 10px 12px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.4px; color: var(--text-muted); border-bottom: 1px solid var(--border);
  background: var(--surface-2); font-weight: 600; white-space: nowrap;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; white-space: nowrap; }
td.nowrap, th.nowrap { white-space: nowrap; }
.table-scroll { overflow-x: auto; }

/* --- Formulare --- */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--text-muted); }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}
textarea { min-height: 90px; resize: vertical; font-family: inherit; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
.field { margin-bottom: 14px; }
.row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.hint { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check label { margin: 0; font-weight: 500; color: var(--text); }
.check input { width: auto; }

/* --- Schaltflächen --- */
.btn {
  display: inline-block; padding: 8px 14px; font: inherit; font-weight: 600; font-size: 14px;
  border-radius: var(--radius); border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text); cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.1); color: var(--accent-text); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--error-text); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--error-bg); border-color: var(--error-text); color: var(--error-text); }
.btn-sm { padding: 4px 9px; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions-end { justify-content: flex-end; }
form.inline { display: inline; }

/* --- Meldungen --- */
.flash {
  padding: 11px 14px; border-radius: var(--radius); margin-bottom: 14px;
  border: 1px solid transparent; font-size: 14px;
}
.flash ul { margin: 6px 0 0; padding-left: 20px; }
.flash-success { background: var(--success-bg); color: var(--success-text); border-color: currentColor; }
.flash-error { background: var(--error-bg); color: var(--error-text); border-color: currentColor; }
.flash-info { background: var(--surface); color: var(--text); border-color: var(--border); }

/* --- Etiketten --- */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid var(--border-strong);
  color: var(--text-muted); white-space: nowrap;
}
.tag-offen { background: var(--surface-2); }
.tag-in_arbeit { background: var(--warn-bg); color: var(--warn-text); border-color: currentColor; }
.tag-teilgeliefert { background: var(--warn-bg); color: var(--warn-text); border-color: currentColor; }
.tag-geliefert, .tag-success { background: var(--success-bg); color: var(--success-text); border-color: currentColor; }
.tag-geplant { background: var(--surface-2); }
.tag-abgelehnt, .tag-storniert, .tag-fehlgeschlagen {
  background: var(--error-bg); color: var(--error-text); border-color: currentColor;
}
.tag-hoch { background: var(--error-bg); color: var(--error-text); border-color: currentColor; }
.overdue { color: var(--error-text); font-weight: 600; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }

/* --- Filterleiste --- */
.filters {
  display: grid; gap: 10px; align-items: end;
  grid-template-columns: minmax(200px, 2fr) repeat(auto-fit, minmax(140px, 1fr)) auto;
  margin-bottom: 18px;
}
.filters .field { margin: 0; }
/* Das Aufklappen der Filterleiste gibt es nur auf dem Handy (siehe unten). */
.filter-check, .filter-btn { display: none; }

/* --- Verlauf / Bemerkungen --- */
.notes { list-style: none; margin: 0; padding: 0; }
.notes li { padding: 12px 0; border-bottom: 1px solid var(--border); }
.notes li:last-child { border-bottom: none; }
.note-meta { font-size: 12px; color: var(--text-muted); display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }
.note-body { white-space: pre-wrap; }

dl.kv { margin: 0; display: grid; grid-template-columns: minmax(130px, auto) 1fr; gap: 8px 18px; }
dl.kv dt { color: var(--text-muted); font-size: 13px; font-weight: 600; }
dl.kv dd { margin: 0; }
.pre { white-space: pre-wrap; }

/* --- Anfordernde Personen im Formular --- */
.people { display: flex; flex-direction: column; gap: 10px; }
.person {
  display: grid; gap: 10px; align-items: end;
  grid-template-columns: 1fr 1fr 1fr auto;
  padding: 10px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.person .field { margin: 0; }

/* --- Anmeldung --- */
.login-wrap { max-width: 380px; margin: 10vh auto; padding: 0 16px; }
.login-wrap h1 { text-align: center; margin-bottom: 6px; }
.login-wrap .sub { text-align: center; margin-bottom: 22px; }

/* --- Blätterfunktion --- */
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 16px; }

@media (max-width: 760px) {
  .person { grid-template-columns: 1fr; }
  .topbar { padding: 8px 14px; }
  dl.kv { grid-template-columns: 1fr; gap: 2px 0; }
  dl.kv dd { margin-bottom: 10px; }
}

/* --- Anpassungen dieser Anwendung ---------------------------------------
   Die Filterleiste hat hier mehr Felder als in den Schwester-Anwendungen
   (Suche, Gremium, Jahr, von, bis, Sortierung). Mit der gemeinsamen
   Vorgabe landete jedes Feld auf einer eigenen Zeile. */
.filters { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.filters .field:first-child { grid-column: span 2; }
.filters .actions { grid-column: 1 / -1; }

/* "Ansehen" und "Speichern" gehoeren nebeneinander, nicht untereinander. */
td .actions { flex-wrap: nowrap; }

/* Lange Dokumenttitel duerfen umbrechen, der Dateiname darunter auch. */
td .muted.small { word-break: break-word; }

@media (max-width: 760px) {
  .filters .field:first-child { grid-column: 1 / -1; }
}

/* --- Betrachter: die Datei mit einer Leiste darueber --------------------
   Die Hoehe haengt am Sichtfenster, nicht am Inhalt: der Rahmen soll den
   Bildschirm fuellen, ohne dass die Seite dahinter mitrollt - sonst rollt
   man abwechselnd die Seite und die Datei darin. */
.betrachter { padding: 0; overflow: hidden; }
.betrachter-rahmen {
  display: block; width: 100%; height: 78vh; min-height: 420px;
  border: 0; background: var(--surface-2);
}
.betrachter-titel { font-size: 18px; overflow-wrap: anywhere; }
.betrachter-leiste { flex-wrap: wrap; }
.betrachter-tipp { display: none; }

/* Auf Telefon und Tablet keine Vorschau. Die Browser dort zeigen eine PDF
   nicht eingebettet, sondern einen grauen Platzhalter mit einem eigenen
   "Oeffnen" - ein halber Bildschirm ohne Inhalt und ein zweiter Knopf, der
   dasselbe tut wie der in der Leiste.

   Entschieden wird das am Eingabegeraet, nicht an der Fensterbreite: ein
   schmales Fenster auf dem PC zeigt die Vorschau durchaus, ein breites
   Tablet nicht. "hover: none" und "pointer: coarse" zusammen treffen Finger
   und schliessen den PC mit Maus aus, auch den mit Beruehrungsbildschirm. */
@media (hover: none) and (pointer: coarse) {
  .betrachter { display: none; }
  .betrachter-rahmen-hinweis { display: none; }
  .betrachter-tipp { display: block; }
}

/* --- Handy ---------------------------------------------------------------
   Unterhalb von 760px ist die Seite nicht dieselbe Seite mit schmaleren
   Spalten, sondern anders aufgebaut:

   * die Navigation steckt hinter "Menü" (Ankreuzfeld, kein JavaScript),
   * die Filterleiste steckt hinter "Suchen & filtern"; wonach gerade
     gefiltert wird, steht auf der Schaltflaeche,
   * die Tabellen werden zu Karten: die Kopfzeile faellt weg, jede Zeile
     wird ein Block, und jede Zelle traegt ihre Spaltenueberschrift als
     data-label vor dem Wert. Die Zelle mit "cell-main" steht dabei oben,
     unabhaengig von ihrer Stelle in der Tabelle - in der Dokumentliste
     steht in der Tabelle das Datum vorn, auf dem Handy gehoert der Titel
     nach oben.

   Auf dem PC greift nichts davon; dort bleibt es bei den Tabellen. */
@media (max-width: 760px) {

  /* --- Kopfzeile mit Menü --- */
  .topbar {
    position: sticky; top: 0; z-index: 20;
    gap: 12px; padding: 8px 14px; min-height: 52px;
  }
  .brand { flex: 1; font-size: 15px; }
  .menu-check {
    /* Sichtbar im Sinne von display, nur unsichtbar im Sinne von Pixeln:
       display:none (die Vorgabe fuer den PC weiter oben) naehme dem Feld
       den Tastaturfokus, und das Menü liesse sich nur noch antippen. */
    display: block;
    position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none;
  }
  .menu-btn {
    display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
    margin: 0; padding: 8px 12px; font-size: 14px; font-weight: 600;
    color: var(--text); border: 1px solid var(--border-strong);
    border-radius: var(--radius); background: var(--surface-2);
  }
  .menu-check:focus-visible + .menu-btn { outline: 2px solid var(--accent); outline-offset: 2px; }
  .menu-icon {
    width: 16px; height: 2px; background: currentColor; position: relative;
  }
  .menu-icon::before, .menu-icon::after {
    content: ""; position: absolute; left: 0; width: 16px; height: 2px;
    background: currentColor;
  }
  .menu-icon::before { top: -5px; }
  .menu-icon::after { top: 5px; }
  .menu-check:checked + .menu-btn { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

  .menu-panel { display: none; }
  .menu-check:checked ~ .menu-panel {
    display: flex; flex-direction: column; align-items: stretch;
    /* flex-basis: 100% statt width: 100%. Ein Flex-Element schrumpft
       lieber, als in die naechste Zeile zu rutschen: mit width: 100% passte
       die Leiste zwischen etwa 600 und 760 Pixeln gerade noch neben die
       Marke und wurde dort zu einer schmalen Spalte am rechten Rand, statt
       darunter zu stehen. flex-shrink: 0 laesst ihr diese Wahl nicht. */
    flex: 1 0 100%;
    gap: 6px; padding-bottom: 4px;
  }
  .topbar nav { flex-direction: column; gap: 2px; }
  .topbar nav a { padding: 11px 12px; }
  .topbar-right {
    justify-content: space-between;
    border-top: 1px solid var(--border); padding-top: 8px;
  }

  /* --- Flaeche --- */
  .wrap { padding: 16px 14px 48px; }
  /* Zwei Spalten zu je 150 plus Abstand passen auf einem 320 Pixel breiten
     Bildschirm nicht mehr - die Seite wurde dort ueberbreit. */
  .stats { grid-template-columns: repeat(auto-fit, minmax(125px, 1fr)); }
  /* Dasselbe eine Nummer groesser: minmax(320px, 1fr) ist eine Untergrenze,
     keine Bitte - bleiben nur 305 Pixel, ragt die Karte trotzdem 320 breit
     hinaus. Unter 760 Pixeln gehoert hier ohnehin eine Spalte hin. */
  .grid-2 { grid-template-columns: 1fr; }
  h1 { font-size: 20px; }
  .page-head { gap: 10px; margin-bottom: 14px; }
  .page-head > .actions { width: 100%; }
  .page-head > .actions .btn, .page-head > .actions form { flex: 1; }
  .page-head > .actions form .btn { width: 100%; }
  .card { padding: 14px; }

  /* --- Filterleiste hinter einer Schaltflaeche --- */
  .filter-check {
    /* display:block aus demselben Grund wie bei .menu-check. */
    display: block;
    position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none;
  }
  .filter-btn {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    margin: 0 0 14px; padding: 11px 14px; cursor: pointer;
    font-size: 14px; font-weight: 600; color: var(--text);
    background: var(--surface); border: 1px solid var(--border-strong);
    border-radius: var(--radius);
  }
  .filter-check:focus-visible + .filter-btn { outline: 2px solid var(--accent); outline-offset: 2px; }
  .filter-btn::after { content: "▾"; color: var(--text-muted); }
  /* Was gerade gefiltert wird, steht auf der Schaltflaeche - die Leiste
     selbst bleibt auch mit gesetztem Filter zugeklappt, sonst liegen nach
     jeder Suche neun Felder zwischen Schaltflaeche und Treffern. */
  .filter-btn-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .filter-aktiv { font-size: 12px; font-weight: 500; color: var(--accent); overflow-wrap: anywhere; }
  .filter-check:checked + .filter-btn { margin-bottom: 10px; }
  .filter-check:checked + .filter-btn::after { content: "▴"; }
  .filters { display: none; }
  .filter-check:checked ~ .filters { display: grid; grid-template-columns: 1fr; }
  .filters .actions .btn { flex: 1; text-align: center; }

  /* --- Eingabefelder: groessere Ziele, und 16px verhindert, dass iOS
         beim Antippen in das Feld hineinzoomt. --- */
  input[type=text], input[type=email], input[type=password], input[type=date],
  input[type=datetime-local], input[type=search], select, textarea {
    font-size: 16px; padding: 10px 12px;
  }
  .btn { padding: 10px 14px; }
  .btn-sm { padding: 8px 12px; font-size: 14px; }

  /* --- Tabellen werden Karten --- */
  .table-scroll { overflow-x: visible; }
  table, tbody, tr, td { display: block; width: auto; }
  thead { display: none; }
  tbody tr {
    display: flex; flex-direction: column; gap: 3px;
    padding: 14px; border-bottom: 1px solid var(--border);
  }
  tbody tr:hover { background: transparent; }
  tbody td { border: none; padding: 0; }
  tbody td[data-label]::before {
    content: attr(data-label) ": ";
    color: var(--text-muted); font-weight: 600; font-size: 12px;
  }
  /* Zellen, in denen nur ein Gedankenstrich steht, weglassen - auf dem
     Handy ist "Amt: –" nur Zeile ohne Aussage. Die Vorlage setzt die
     Klasse, wenn der Wert fehlt. */
  tbody td.leer { display: none; }
  tbody td.cell-main { order: -1; font-size: 15px; margin-bottom: 2px; }
  tbody td.cell-main::before { content: none; }
  tbody td.cell-actions { margin-top: 10px; }
  .cell-actions .actions { justify-content: stretch; flex-wrap: nowrap; }
  .cell-actions .btn, .cell-actions form { flex: 1; }
  .cell-actions .btn { text-align: center; }
  .cell-actions form .btn { width: 100%; }
  td.num, th.num, td.nowrap, th.nowrap { text-align: left; white-space: normal; }

  /* Lange Pfade und Dateinamen duerfen umbrechen, statt die Seite zu
     verbreitern. */
  code, .pre, .note-body { overflow-wrap: anywhere; }

  /* --- Betrachter --- */
  .betrachter-rahmen { height: 68vh; min-height: 300px; }
  /* Vier Schaltflaechen in einer Reihe waeren auf 390 Pixeln zu schmal.
     Der Selektor nennt .page-head mit, damit er die allgemeine Regel
     ".page-head > .actions .btn { flex: 1 }" von oben schlaegt - sonst
     brechen sie 3+1 um statt 2+2. */
  .page-head > .betrachter-leiste .btn { flex: 1 1 46%; }

  /* --- Blaettern --- */
  .pager { flex-wrap: wrap; }
  .pager .btn { flex: 1 1 40%; text-align: center; }
  .pager .small { flex: 1 0 100%; text-align: center; order: -1; margin-bottom: 4px; }
}
