:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1c1f24;
  --muted: #5f6773;
  --line: #d9dde3;
  --accent: #2f6fed;
  --error: #b3261e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card: #1d2026;
    --ink: #e8eaee;
    --muted: #a2aab6;
    --line: #2e333c;
    --accent: #6d9bff;
    --error: #ff8a80;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

body.center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  width: min(100%, 380px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
}

h1 { margin: 0 0 4px; font-size: 22px; }
.muted { color: var(--muted); margin: 0 0 20px; }

form { display: grid; gap: 6px; }
label { font-size: 14px; color: var(--muted); margin-top: 10px; }

input {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
}

button {
  margin-top: 20px;
  padding: 11px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}

button:disabled { opacity: .6; cursor: default; }

.error { color: var(--error); margin-top: 16px; }

.details { margin: 16px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }

/* --- Vorgänge, Typen, Chat --------------------------------------------- */

/* Muss vor den Layoutregeln stehen: jedes eigene display: … schlägt sonst die
   Vorgabe des Browsers für [hidden], und Verstecktes bliebe sichtbar. */
[hidden] { display: none !important; }

body.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.topbar .spacer { flex: 1; }

button.ghost {
  margin: 0;
  padding: 6px 10px;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
}

button.ghost:hover { border-color: var(--accent); color: var(--accent); }

.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
}

.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.pane-list { border-right: 1px solid var(--line); background: var(--card); }

.pane-head { display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.pane-head input { flex: 1; padding: 8px 10px; font-size: 15px; }

.new-case { display: grid; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.new-case select, .new-case input {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}
.new-case button { margin: 0; padding: 8px 12px; font-size: 15px; }

.list { flex: 1 1 auto; overflow-y: auto; padding: 6px 0 20px; }

.group { margin-bottom: 4px; }
.group.quiet { opacity: .55; }

.group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 9px 12px 5px;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .04em;
  text-align: left;
  cursor: pointer;
}
.group-head.static { cursor: default; }
.group-head:hover .group-name { color: var(--accent); }
.group-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-hint { margin-left: auto; font-size: 11px; text-transform: none; letter-spacing: 0; opacity: .55; white-space: nowrap; }

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 9px 12px 9px 14px;
  background: transparent;
  border: 0;
  border-left: 3px solid transparent;
  color: var(--ink);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.row:hover { background: var(--bg); }
.row.unread { border-left-color: var(--accent); font-weight: 600; }
.row-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-time { color: var(--muted); font-size: 12px; font-weight: 400; }

.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }

.state {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 5px;
  font-weight: 400;
}

.badge {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

.footnote { font-size: 12px; padding: 0 12px 10px; margin: 0; }

.detail-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.detail-head h2 { margin: 0; font-size: 18px; }
.detail-head p { margin: 3px 0 0; }
.detail-head > div:first-child { flex: 1; min-width: 0; }
.detail-actions { display: flex; gap: 8px; }

.messages { flex: 1 1 auto; overflow-y: auto; padding: 14px 18px; display: flex; flex-direction: column; gap: 10px; }

.message {
  max-width: min(680px, 90%);
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}
.message.own { align-self: flex-end; border-color: var(--accent); }
.message-head { display: flex; gap: 10px; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.message-head .sender { font-weight: 600; }
.message-body { white-space: pre-wrap; word-break: break-word; }
.message-file { margin-top: 6px; font-size: 12px; color: var(--muted); font-family: ui-monospace, monospace; }

.composer { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); flex: 0 0 auto; }
.composer textarea {
  flex: 1;
  resize: none;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}
.composer button { margin: 0; padding: 9px 16px; }

.empty { padding: 18px 14px; }

.banner {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  margin: 0;
  padding: 9px 16px;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid var(--error);
}

.narrow-only { display: none; }

/* Am Handy nur eine Spalte, und darin weniger: keine Zeitspalte, keine
   Kanalhinweise, keine Zählerzeile. Der Zurück-Weg ersetzt die zweite Spalte. */
@media (max-width: 767px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .wide-only { display: none !important; }
  .narrow-only { display: inline-flex; }
  body[data-pane="list"] .pane-detail { display: none; }
  body[data-pane="detail"] .pane-list { display: none; }
  .pane-list { border-right: 0; }
  .detail-head { padding: 12px 14px; }
  .messages { padding: 12px 14px; }
  .message { max-width: 100%; }
  .composer { padding: 10px 14px; }
  .group-head { text-transform: none; font-size: 14px; letter-spacing: 0; }
}

/* --- Aufgaben ------------------------------------------------------------ */

/* Die Reiter rollen in sich, statt die Kopfleiste zu sprengen. Gemessen bei
   375 Pixeln: mit fünf Reitern wäre die Leiste 590 Pixel breit, und "Abmelden"
   läge außerhalb des Bildes - erreichbar über nichts, weil body.app nicht
   waagerecht rollt. */
.tabs { display: flex; gap: 4px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
button.tab { flex: 0 0 auto; }

button.tab {
  margin: 0;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
}
button.tab:hover { color: var(--accent); }
body[data-view="tasks"] #tab-tasks,
body[data-view="cases"] #tab-cases,
body[data-view="agents"] #tab-agents,
body[data-view="wiki"] #tab-wiki,
body[data-view="settings"] #tab-settings {
  color: var(--ink);
  border-color: var(--line);
  background: var(--bg);
}

/* Die Einstellungen sind kein Listen-und-Detail-Bild: es gibt nichts
   auszuwählen. Deshalb fällt die linke Spalte hier ganz weg - am Rechner wie
   am Handy dieselbe eine Spalte. */
body[data-view="settings"] .layout { grid-template-columns: minmax(0, 1fr); }
body[data-view="settings"] .pane-list { display: none; }

body[data-view="tasks"] #new-case,
body[data-view="wiki"] #new-case,
body[data-view="agents"] #new-case { display: none; }
body[data-view="cases"] #new-task,
body[data-view="wiki"] #new-task,
body[data-view="agents"] #new-task { display: none; }
body[data-view="tasks"] #new-agent,
body[data-view="wiki"] #new-agent,
body[data-view="cases"] #new-agent { display: none; }

.new-entry { display: grid; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.new-entry select, .new-entry input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}
.new-entry button { margin: 0; padding: 8px 12px; font-size: 15px; }
.new-entry-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.new-entry-row label { display: grid; gap: 2px; margin: 0; font-size: 12px; }

.divider {
  padding: 10px 12px 4px 14px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}

.task-row.running { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.task-row[data-bucket="3"] { opacity: .72; }
.running-state { border-color: var(--accent); color: var(--accent); }
.urgent-state { border-color: var(--error); color: var(--error); }

.case-detail { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

.task-detail { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 14px 18px 30px; }
.task-detail .details { margin: 0 0 18px; }
.task-detail .block { margin-bottom: 20px; }
.task-detail h3 {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.import-note {
  margin: 0 0 14px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--error);
  border-radius: 8px;
  font-size: 13px;
  color: var(--muted);
}

.prose { white-space: pre-wrap; word-break: break-word; }

/* Der einmalige Schlüssel: absichtlich der auffälligste Kasten der Oberfläche.
   Er ist nach dem Verlassen der Ansicht weg. */
.key-once {
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.key-once h3 { margin: 0 0 4px; }
.key-once p { margin: 0 0 8px; padding: 0; }
.key-value {
  display: block;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-family: ui-monospace, monospace;
  font-size: 13px;
  word-break: break-all;
  user-select: all;
}

.agent-row { flex-wrap: wrap; }
.agent-row .row-note { flex-basis: 100%; font-size: 12px; color: var(--muted); font-weight: 400; }
.agent-row.revoked { opacity: .5; }
.revoke {
  margin: 0;
  padding: 2px 8px;
  font-size: 12px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
}
.revoke:hover { color: var(--error); border-color: var(--error); }

/* --- Einstellungen ------------------------------------------------------- */

.settings .block { max-width: 620px; }
.settings .footnote { padding: 0; }
.settings code { font-family: ui-monospace, monospace; font-size: 13px; }

.settings-form { max-width: 380px; margin-bottom: 8px; }
.settings-form label { display: grid; gap: 3px; margin-top: 10px; font-size: 13px; }
.settings-form input {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}
.settings-form button { margin-top: 14px; padding: 9px 14px; font-size: 15px; }

.settings-done {
  margin: 8px 0 0;
  padding: 8px 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  font-size: 13px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.device-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.device-row.revoked { opacity: .5; }
.device-row .row-note { flex-basis: 100%; font-size: 12px; color: var(--muted); }

.time-entry { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; padding: 3px 0; }
.time-entry.total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; font-weight: 600; }

.wiki-link { display: flex; flex-direction: column; padding: 4px 0; font-size: 14px; }
.wiki-path { font-size: 12px; font-family: ui-monospace, monospace; word-break: break-all; }

.note {
  padding: 8px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}

.note-form { display: flex; gap: 8px; margin-top: 8px; }
.note-form textarea {
  flex: 1;
  resize: vertical;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}
.note-form button { margin: 0; padding: 9px 16px; }

/* Am Handy fällt Inhalt weg, nicht nur Breite: keine Zeiten-Liste, keine
   Wichtigkeits- und Schätzspalte, keine Trennlinie, keine Gruppenzahlen. */
@media (max-width: 767px) {
  .new-entry-row { grid-template-columns: 1fr; }
  .task-detail { padding: 12px 14px 24px; }
  .details { grid-template-columns: 1fr; gap: 0 0; }
  .details dt { margin-top: 8px; font-size: 12px; }
  button.tab { padding: 6px 10px; font-size: 14px; }
}

/* --- Wiki ---------------------------------------------------------------- */

/* Die Breite der ersten beiden Spalten steht genau einmal. Ordnerzeile und
   Dateizeile greifen beide darauf zu; zwei getrennte Zahlen wären zwei Stellen,
   an denen die Flucht der Symbole wieder verloren geht. */
:root {
  --wiki-lead-width: 18px;
  --wiki-icon-width: 22px;
}

.wiki-tree { padding: 4px 0 16px; }

/* Drei Spalten, in jeder Zeile dieselben: Aufklapppfeil oder Platzhalter,
   Symbol, Name. Der Platzhalter ist der Punkt - ohne ihn rutschte das
   Dateisymbol in die erste Spalte und stünde links vom Ordnersymbol darüber. */
.wiki-row {
  display: grid;
  grid-template-columns: var(--wiki-lead-width) var(--wiki-icon-width) minmax(0, 1fr);
  align-items: center;
  gap: 5px;
  padding: 2px 10px 2px calc(10px + var(--depth, 0) * 14px);
  border-left: 3px solid transparent;
}
.wiki-row:hover { background: var(--bg); }
.wiki-row.is-current {
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.wiki-lead { display: block; width: var(--wiki-lead-width); height: 22px; }
.wiki-spacer { visibility: hidden; }

button.wiki-toggle {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 22px;
  text-align: center;
  cursor: pointer;
  transition: transform .12s ease;
}
button.wiki-toggle.is-open { transform: rotate(90deg); }
button.wiki-toggle:hover { color: var(--accent); }

.wiki-icon {
  width: var(--wiki-icon-width);
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--muted);
}
.wiki-icon.is-folder { color: #d79a2b; }
.wiki-icon.is-html { color: var(--accent); }

.wiki-label {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  color: var(--ink);
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
}
.wiki-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wiki-excerpt {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Zeichen für „dieser Ordner hat eine README". Zurückhaltend: ein Hinweis,
   kein Zustand - es darf den Ordnernamen nicht überstrahlen. */
.wiki-readme-mark { color: var(--muted); font-size: 11px; opacity: .8; }

.wiki-detail { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.wiki-page { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 14px 18px 30px; }
.wiki-plain {
  margin: 0;
  font: 13px/1.55 ui-monospace, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}
.wiki-image { display: block; max-width: 100%; margin: 0 auto; border-radius: 8px; }
.wiki-frame {
  width: 100%;
  height: calc(100dvh - 190px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.wiki-editor { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; padding: 12px 18px 16px; gap: 8px; }
.wiki-editor textarea {
  flex: 1 1 auto;
  min-height: 200px;
  resize: none;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font: 14px/1.6 ui-monospace, monospace;
}
.wiki-editor-actions { display: flex; gap: 8px; align-items: center; }
.wiki-editor-actions button { margin: 0; padding: 8px 14px; font-size: 15px; }

/* Ein Konflikt ist kein Hinweis, der nach sechs Sekunden verschwindet: Er steht,
   bis Stefan ihn behandelt hat - und der eingetippte Text bleibt daneben. */
.wiki-editor-note { display: grid; gap: 8px; font-size: 13px; color: var(--muted); }
.wiki-editor-note.conflict {
  padding: 10px 12px;
  border: 1px solid var(--error);
  border-left-width: 3px;
  border-radius: 8px;
  color: var(--error);
}
.wiki-editor-note .conflict-view {
  max-height: 220px;
  overflow: auto;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  color: var(--ink);
}
.wiki-editor-note button { margin: 0; padding: 5px 10px; font-size: 13px; justify-self: start; }

/* Am Handy Baum oder Seite, nie beides - der Zurück-Weg oben führt aus der
   Seite zurück in den Baum. Der Rahmen für HTML wird flacher, weil ihn sonst
   die Kopfzeile aus dem Bild schiebt. */
@media (max-width: 767px) {
  .wiki-page { padding: 12px 14px 24px; }
  .wiki-editor { padding: 10px 14px 14px; }
  .wiki-frame { height: calc(100dvh - 150px); }
  .wiki-row { padding-left: calc(8px + var(--depth, 0) * 12px); }
  .wiki-excerpt { display: none; }
}
