/* Board-Oberflaeche. Dark/Light per prefers-color-scheme, keine externen Assets. */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --card: #ffffff;
  --line: #dcdfe4;
  --text: #1c2430;
  --muted: #67707c;
  --accent: #2f6feb;
  --p1: #8a94a3;
  --p2: #3d8bfd;
  --p3: #e8912a;
  --p4: #d64545;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 45, .12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1b2027;
    --card: #212832;
    --line: #2e3742;
    --text: #e6eaf0;
    --muted: #98a2b0;
    --accent: #4d8dff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
/* Jede Klassenregel mit `display:` schlaegt sonst die Browser-Regel [hidden]{display:none}.
   Genau daran hing schon das Detail-Panel (stand beim Laden offen) und danach der
   Nutzer-Link (war auch fuer Mitarbeiter sichtbar). Deshalb hier ein Riegel fuer alle. */
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  /* Umbrechen statt ueberlaufen – sonst schiebt der Kopf die ganze Seite seitlich weg,
     und das passiert nicht erst auf dem Handy, sondern schon auf Tablet-Breite. */
  flex-wrap: wrap;
  row-gap: 8px;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.top h1 { margin: 0; font-size: 16px; letter-spacing: .2px; white-space: nowrap; }
/* Erklaerung nur, wenn Platz ist – auf dem Handy weicht sie der Suche. */
.top .tagline { color: var(--muted); font-size: 12px; white-space: nowrap; }

.top input[type=search] { flex: 1; min-width: 0; }
.top #project { max-width: 190px; }
.detail .d-project { gap: 5px; }


input, textarea, select, button {
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
textarea { width: 100%; resize: vertical; }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--p4); }
button.icon { border: 0; background: none; padding: 4px 8px; font-size: 16px; }

/* ── Board ─────────────────────────────────────────────────────────────────── */
.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(270px, 1fr);
  gap: 12px;
  padding: 12px;
  align-items: start;
  overflow-x: auto;              /* Spalten scrollen horizontal, der Body nie */
  min-height: calc(100vh - 56px);
}
.col {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  min-height: 120px;
}
.col.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--panel)); }
.col h2 {
  margin: 2px 4px 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}

.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--p2);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  cursor: grab;
}
.card:last-child { margin-bottom: 0; }
.card.dragging { opacity: .45; }
.card .subject { display: block; word-break: break-word; }
.card .meta { margin-top: 6px; display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.card[data-priority="1"] { border-left-color: var(--p1); }
.card[data-priority="2"] { border-left-color: var(--p2); }
.card[data-priority="3"] { border-left-color: var(--p3); }
.card[data-priority="4"] { border-left-color: var(--p4); }

.badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge.feature { border-color: var(--accent); color: var(--accent); }
.card select.move { margin-left: auto; padding: 2px 4px; font-size: 12px; }

/* ── Detail-Panel ──────────────────────────────────────────────────────────── */
.detail {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(460px, 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px rgba(0, 0, 0, .18);
  z-index: 10;
}
.detail h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 6px 0 0; }
.detail-head { display: flex; align-items: center; justify-content: space-between; }
.detail .id { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.d-subject { font-size: 16px; font-weight: 600; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 110px; }

.notes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.notes li { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.notes time { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.notes p { margin: 0; white-space: pre-wrap; word-break: break-word; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: 999px;
  z-index: 20;
}

.empty { color: var(--muted); font-size: 13px; padding: 6px 4px; }

/* ── Anmeldung + Nutzerverwaltung (server-gerenderte Seiten) ───────────────── */
body.centered {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 20px;
}
.card.auth {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.card.auth .brand {
  margin: 0 0 2px;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
.card.auth h1 { margin: 0 0 6px; font-size: 20px; }
.card.auth .step { margin: 14px 0 2px; font-size: 15px; }
.card.auth .sub { margin: 0 0 16px; color: var(--muted); font-size: 14px; line-height: 1.4; }
.card.auth .sub strong { color: var(--text); font-weight: 600; }
.card.auth form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
label input, label select { font-size: 15px; color: var(--text); }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
.links { margin: 14px 0 0; font-size: 14px; }
a { color: var(--accent); }

.note {
  margin: 0 0 14px;
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 14px;
  border: 1px solid var(--line);
}
.note.error { border-color: var(--p4); color: var(--p4); }
.note.ok { border-color: var(--accent); color: var(--accent); }

.top .spacer { flex: 1; }
.btn, .top a.btn {
  display: inline-block;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
}
.btn:hover { border-color: var(--accent); }
form.inline { display: inline-block; }   /* inline-block: Aussenabstaende wirken auch vertikal */

.page-body { padding: 14px; display: flex; flex-direction: column; gap: 14px; max-width: 900px; }
.page-body h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 8px 0 0; }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
.muted { color: var(--muted); font-size: 12px; }
/* Die Zelle bleibt eine Tabellenzelle (sonst verrutschen Zeilentrenner und Spalten);
   der Abstand kommt ueber die Kinder. */
td.actions > * { margin: 0 6px 6px 0; vertical-align: middle; }
td.actions > *:last-child { margin-right: 0; }
th:last-child, td.actions { white-space: nowrap; }
.badge.ok { border-color: var(--accent); color: var(--accent); }
.projects-pick {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.projects-pick .pick-label {
  width: 100%;
  font-size: 13px;
  color: var(--muted);
}
.projects-pick .pick { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.projects-pick .pick select { padding: 4px 6px; font-size: 13px; }

form.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

@media (max-width: 700px) {
  .board { grid-auto-columns: 86vw; }
  .card { cursor: default; }   /* auf Touch wird ueber das Dropdown verschoben */
}

/* Handy: der Kopf hat mehr Elemente als Platz. Statt zu ueberlaufen (und damit die ganze
   Seite seitlich zu verschieben) bricht er um: Titel + Projekt, darunter die Suche,
   darunter die Knoepfe. */
@media (max-width: 900px) {
  .top { padding: 10px 12px; }
  .top .tagline { display: none; }
  .top h1 { font-size: 15px; }
  .top #project { flex: 1 1 140px; max-width: none; }
  .top input[type=search] { order: 5; flex: 1 1 100%; }
  .top > button,
  .top > a.btn,
  .top > form.inline { order: 6; }
  .top > button,
  .top > a.btn,
  .top > form.inline > button { padding: 7px 9px; font-size: 13px; }
  .top .spacer { display: none; }
  .board { min-height: auto; }
  .page-body { padding: 12px; }
}

/* Handy: Tabellen als Bloecke statt seitlich scrollend. Sonst liegt ausgerechnet die
   Aktions-Spalte ausserhalb des Bildschirms und man kommt an Sperren/Loeschen nicht heran. */
@media (max-width: 700px) {
  .tablewrap { overflow-x: visible; }
  .tablewrap table,
  .tablewrap tbody,
  .tablewrap tr,
  .tablewrap td { display: block; width: 100%; }
  .tablewrap thead { display: none; }
  .tablewrap tr {
    padding: 12px;
    border-bottom: 1px solid var(--line);
  }
  .tablewrap tr:last-child { border-bottom: 0; }
  .tablewrap td {
    border: 0;
    padding: 2px 0;
  }
  .tablewrap td.actions {
    white-space: normal;
    padding-top: 8px;
  }
  .tablewrap td:empty { display: none; }
}

/* ── Wiki ──────────────────────────────────────────────────────────────────── */
.wiki-body {
  display: grid;
  grid-template-columns: minmax(200px, 260px) 1fr;
  gap: 14px;
  padding: 14px;
  align-items: start;
}
.tree {
  position: sticky;
  top: 70px;                     /* unter dem klebenden Kopf */
  max-height: calc(100vh - 90px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 6px;
}
.tree ul { list-style: none; margin: 0; padding: 0 0 0 14px; }
.tree > ul { padding-left: 0; }
.tree-row { display: flex; align-items: center; gap: 2px; border-radius: 6px; }
.tree-row:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.tree-row.active { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.tree-row.active > .tree-title { font-weight: 600; }
.tree .twisty {
  flex: none;
  width: 20px;
  padding: 2px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  text-align: center;
}
.tree .tree-title {
  flex: 1;
  min-width: 0;
  padding: 5px 6px 5px 0;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  word-break: break-word;
}

.page {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  min-height: calc(100vh - 90px);
}
.page-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; justify-content: space-between; }
.page-head h2 { margin: 0; font-size: 22px; word-break: break-word; }
.page-head .row { display: flex; gap: 6px; flex-wrap: wrap; }
/* Die globale Regel `.row > * { flex: 1; min-width: 110px }` (fuers Ticket-Panel gedacht)
   zoege hier alle Knoepfe auf dieselbe Breite – die beiden Pfeile stuenden dann als zwei
   fast leere Flaechen herum. Im Kopf der Wiki-Seite behaelt jeder Knopf seine Breite. */
.page-head .row > * { flex: 0 0 auto; min-width: 0; }
.page-head .row > .icon { padding: 6px 9px; }
.page .meta { color: var(--muted); font-size: 12px; margin: 4px 0 14px; }
.page .empty { color: var(--muted); }
.page .d-subject { width: 100%; font-size: 20px; font-weight: 600; margin-bottom: 10px; }
.page .e-parent { max-width: 380px; margin-bottom: 10px; }
.page .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
/* Aus demselben Grund wie oben: Knoepfe in ihrer natuerlichen Breite, der Hinweistext
   (z. B. „zwischenzeitlich geändert") nimmt den Rest der Zeile. */
.page .row > button { flex: 0 0 auto; min-width: 0; }
.page .row > .meta { flex: 1; margin: 0; }

.editor { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: stretch; }
.editor textarea {
  min-height: 60vh;
  font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
}
.editor .md {
  overflow: auto;
  max-height: 70vh;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px 14px;
}

/* Gerendertes Markdown. Bewusst enger gefuehrt als die Grundschrift der App: hier stehen
   laengere Texte, und Zeilen ueber ~80 Zeichen liest niemand gern. */
.md { max-width: 78ch; word-break: break-word; }
.md > :first-child { margin-top: 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 1.4em 0 .4em; line-height: 1.25; }
.md h1 { font-size: 24px; }
.md h2 { font-size: 20px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.md h3 { font-size: 17px; }
.md h4, .md h5, .md h6 { font-size: 15px; }
.md p { margin: .7em 0; }
.md ul, .md ol { margin: .7em 0; padding-left: 1.5em; }
.md li { margin: .25em 0; }
.md code {
  font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}
.md pre {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;                /* langer Code scrollt in sich, nie die Seite */
}
.md pre code { background: none; border: 0; padding: 0; }
.md blockquote {
  margin: .8em 0;
  padding: 2px 14px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.4em 0; }
.md table { display: block; overflow-x: auto; width: auto; margin: .8em 0; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; }
.md th { background: var(--bg); text-transform: none; letter-spacing: 0; font-size: 13px; }
.md tr:last-child td { border-bottom: 1px solid var(--line); }

/* Schmal: Baum ueber den Inhalt, Editor und Vorschau untereinander. */
@media (max-width: 900px) {
  .wiki-body { grid-template-columns: 1fr; }
  .tree { position: static; max-height: 40vh; }
  .page { min-height: 0; }
  .editor { grid-template-columns: 1fr; }
  .editor textarea { min-height: 40vh; }
  .editor .md { max-height: 40vh; }
}

/* ── Wiki: Werkzeugleiste ──────────────────────────────────────────────────── */
.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-bottom: 8px;
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.tools-gruppe { display: flex; gap: 4px; }
/* Trenner zwischen den Gruppen – zeigt, was zusammengehoert, ohne extra Markup. */
.tools-gruppe + .tools-gruppe { border-left: 1px solid var(--line); padding-left: 10px; }
.tools button {
  flex: 0 0 auto;
  min-width: 34px;
  padding: 5px 8px;
  font-size: 13px;
  line-height: 1.2;
  background: var(--card);
}
.tools button:active { background: color-mix(in srgb, var(--accent) 18%, var(--card)); }
.tools .ruf { border-left-width: 3px; }
.tools .ruf.hinweis { border-left-color: var(--accent); }
.tools .ruf.warnung { border-left-color: var(--p3); }
.tools .ruf.achtung { border-left-color: var(--p4); }

/* ── Wiki: Hinweisbloecke ──────────────────────────────────────────────────── */
.md .callout {
  margin: .9em 0;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  background: var(--bg);
}
.md .callout > :first-child { margin-top: 0; }
.md .callout > :last-child { margin-bottom: 0; }
.md .callout-kopf {
  margin: 0 0 .4em;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: .02em;
}
.md .callout.hinweis { border-left-color: var(--accent); }
.md .callout.hinweis .callout-kopf { color: var(--accent); }
.md .callout.warnung { border-left-color: var(--p3); }
.md .callout.warnung .callout-kopf { color: var(--p3); }
.md .callout.achtung { border-left-color: var(--p4); }
.md .callout.achtung .callout-kopf { color: var(--p4); }

@media (max-width: 900px) {
  /* Auf dem Handy zaehlt jede Zeile Hoehe: Gruppen duerfen umbrechen, ohne Trennstriche. */
  .tools { gap: 4px; }
  .tools-gruppe + .tools-gruppe { border-left: 0; padding-left: 0; }
}
