/* ==========================================================================
   kardan – Dark-Mode Design-System
   ========================================================================== */

:root {
  /* Ebenen & Kontrast – GitHub-Dark-Palette (neutral, grau/schwarz/weiß) */
  --bg: #0d1117;
  --bg-1: #161b22;
  --bg-2: #1c2128;
  --bg-3: #21262d;
  --border: #30363d;
  --border-strong: #3d444d;

  /* Text */
  --fg: #f0f6fc;
  --fg-2: #a8b3c0;
  --fg-3: #8b949e;

  /* Akzente (neutral) */
  --accent: #c9d1d9;
  --accent-2: #8b949e;
  /* Funktionale Farben (nur wo sie Bedeutung haben) */
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --grad: linear-gradient(135deg, #c9d1d9, #8b949e);

  /* UI */
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; }
input, textarea { font: inherit; }
::selection { background: rgba(201, 209, 217, 0.25); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Scrollbars */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #2a313c; border-radius: 6px; border: 1px solid var(--bg); }
*::-webkit-scrollbar-thumb:hover { background: #3d444d; }

#app { display: flex; height: 100vh; height: 100dvh; }
.mobile-only { display: none !important; }
#sidebar-backdrop { display: none; }

/* ==========================================================================
   Sidebar
   ========================================================================== */
#sidebar {
  width: 288px; min-width: 288px;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow-y: auto; padding: 14px 12px;
  gap: 4px;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 10px; }
.side-head h1 {
  margin: 0; font-size: 17px; font-weight: 800; letter-spacing: 0.01em;
  color: var(--fg);
}
/* Logo statt Titel: Bild skalieren, kein Text-Spacing */
.side-head h1.logo { font-size: 0; line-height: 0; }
.side-head h1.logo img { height: 30px; width: auto; display: block; }
.icon-btn {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  display: grid; place-items: center;
  background: transparent; color: var(--fg-2); border: 1px solid transparent;
  cursor: pointer; font-size: 16px; line-height: 1;
  transition: all 0.15s;
}
.icon-btn:hover { background: var(--bg-3); color: var(--fg); border-color: var(--border); }
.icon-btn svg { width: 16px; height: 16px; }

#project-add { display: flex; gap: 6px; padding: 8px 6px; }
#project-add input { flex: 1; min-width: 0; }
#project-add.hidden, .hidden { display: none !important; }

.side-label {
  margin: 14px 6px 6px; font-size: 11px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--fg-3);
  display: flex; align-items: center; justify-content: space-between;
}
.side-label:not(:first-of-type) {
  margin-top: 20px; padding-top: 14px;
  border-top: 1px solid var(--border);
}
.side-label button { background: none; border: none; color: var(--fg-2); cursor: pointer; font-size: 15px; padding: 0 4px; }
.side-label button:hover { color: var(--fg); }

/* Status-Fußzeile (online/offline) – ans untere Ende der Sidebar */
.side-foot {
  margin-top: auto;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 6px 2px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--fg-3);
}
.conn-status { display: flex; align-items: center; gap: 8px; }
.side-logout {
  margin-left: auto; padding: 2px 7px;
  background: transparent; color: var(--fg-3);
  border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; font-size: 11px;
}
.side-logout:hover { color: var(--fg); border-color: var(--border-strong); }
.side-logout:disabled { opacity: 0.55; cursor: wait; }

/* Eingeklappte Sidebar: Logo + Umschalter bleiben sichtbar */
body.sidebar-collapsed #sidebar { width: 42px; min-width: 42px; }
body.sidebar-collapsed #sidebar .side-label,
body.sidebar-collapsed #sidebar #project-list,
body.sidebar-collapsed #sidebar #project-add,
body.sidebar-collapsed #sidebar .side-foot { display: none; }
body.sidebar-collapsed #sidebar .side-nav-item { justify-content: center; padding: 8px 0; }
body.sidebar-collapsed #sidebar .side-nav-item span { display: none; }
body.sidebar-collapsed #sidebar .side-head {
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 2px 0 10px;
}

#sidebar ul { list-style: none; margin: 0; padding: 0; }

/* Projekte + verschachtelte Sessions */
li.project { border-radius: 6px; margin-bottom: 1px; }
li.project.active .p-open { color: var(--fg); font-weight: 700; }
.p-row { display: flex; align-items: center; }
.p-row .p-open {
  flex: 1; min-width: 0; text-align: left; padding: 4px 6px;
  background: none; border: none; color: var(--fg-2);
  font-weight: 500; font-size: 13px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-radius: 6px;
}
.p-row .p-open:hover { color: var(--fg); background: rgba(255, 255, 255, 0.04); }
.p-row .p-del {
  background: none; border: none; color: var(--fg-3);
  cursor: pointer; padding: 0 8px; opacity: 0; transition: opacity 0.15s;
}
li.project:hover .p-del, li.project:focus-within .p-del { opacity: 1; }
.p-row .p-del:hover { color: var(--err); }
/* Chat-Icon: neue Session in diesem Projekt */
.p-row .p-new {
  background: none; border: none; color: var(--fg-3);
  cursor: pointer; padding: 0 6px; opacity: 0; transition: opacity 0.15s;
  display: flex; align-items: center;
}
li.project:hover .p-new, li.project:focus-within .p-new { opacity: 1; }
.p-row .p-new:hover { color: var(--fg); }
.p-row .p-new svg { width: 14px; height: 14px; }

.p-sessions { margin: 0 0 4px; }
/* Spezifität: muss `#sidebar ul { padding: 0 }` überschreiben */
#sidebar .p-sessions { padding-left: 32px; }
.p-sessions li { border-radius: 6px; margin-bottom: 1px; }
.p-sessions li.active .s-name { color: var(--fg); font-weight: 600; }
.p-sessions .s-open {
  display: flex; align-items: center; gap: 6px;
  width: 100%; text-align: left; background: none;
  border: none; color: var(--fg-2); padding: 3px 6px; cursor: pointer; border-radius: 6px;
}
.p-sessions .s-open:hover { color: var(--fg); background: rgba(255, 255, 255, 0.04); }
.s-name {
  flex: 1; min-width: 0; display: block; font-size: 13.5px; font-weight: 500; color: var(--fg-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Spinner neben der aktiven Session (Kenntlichmachung) */
.p-sessions .s-spin {
  width: 10px; height: 10px; border-width: 2px;
  flex-shrink: 0; opacity: 0.9;
}

/* Geplante Aufgaben – Seitenmenüpunkt */
.side-nav-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left;
  background: none; border: none; color: var(--fg-2);
  padding: 8px 10px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 13px; font-weight: 600;
  margin: 2px 0 6px;
}
.side-nav-item:hover { background: var(--bg-3); color: var(--fg); }
.side-nav-item.active { background: var(--bg-3); color: var(--fg); }
.side-nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }

/* Geplante Aufgaben – Übersichtsseite */
#schedules-page {
  flex: 1; display: none; flex-direction: column; min-width: 0;
  background: var(--bg);
}
body.schedules-open main { display: none; }
body.schedules-open #schedules-page { display: flex; }

.schedules-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.schedules-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.schedules-head .spacer { flex: 1; }
.schedules-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
.schedules-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 8px; max-width: 820px;
}
.sched-item { border-radius: var(--radius-sm); }
.sched-card {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.sched-card:hover { border-color: var(--border-strong); background: var(--bg-3); }
.sched-toggle {
  background: none; border: none; color: var(--fg-3);
  cursor: pointer; padding: 2px 0 0; width: 16px; flex-shrink: 0;
  font-size: 11px; line-height: 1;
}
.sched-toggle:hover { color: var(--fg); }
.sched-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.sched-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.sched-name { font-size: 14px; font-weight: 600; color: var(--fg); word-break: break-word; }
.sched-desc {
  font-size: 12.5px; color: var(--fg-2); word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.sched-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.sched-chip {
  display: inline-flex; align-items: center; gap: 5px;
  max-width: 100%;
  padding: 2px 9px; font-size: 11.5px; font-weight: 600; color: var(--fg-2);
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sched-chip svg { width: 12px; height: 12px; flex-shrink: 0; color: var(--fg-3); }
.sched-chip-cron { font-family: var(--mono); }
.sched-chip-off { color: var(--fg-3); border-style: dashed; }
.sched-chip-next svg { color: var(--accent-2); }
.sched-chip-proj { max-width: 220px; }
.sched-chip-pre { color: var(--warn); border-color: rgba(210, 153, 34, 0.35); }
.sched-chip-pre svg { color: var(--warn); }
.sched-chip-tier { color: var(--ok); border-color: rgba(63, 185, 80, 0.35); }
.sched-chip-ret { color: var(--accent-2); border-color: rgba(96, 165, 250, 0.3); }
.sched-chip-graph { color: var(--ok); border-color: rgba(63, 185, 80, 0.35); }
.sched-chip-graph svg { color: var(--ok); }
.sched-status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--fg-2); white-space: nowrap; flex-shrink: 0;
}
.sched-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-3); flex-shrink: 0; }
.sched-status.st-ok .sched-dot { background: var(--ok); }
.sched-status.st-skip .sched-dot { background: var(--warn); }
.sched-status.st-error { color: var(--err); }
.sched-status.st-error .sched-dot { background: var(--err); }
.sched-status.st-none { color: var(--fg-3); font-style: italic; }
.sched-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.sched-actions .sch-run, .sched-actions .sch-edit, .sched-actions .sch-del {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  background: none; border: none; color: var(--fg-3); cursor: pointer;
  border-radius: 6px;
}
.sched-actions svg { width: 15px; height: 15px; }
.sched-actions .sch-run:hover { color: var(--ok); background: rgba(255, 255, 255, 0.06); }
.sched-actions .sch-edit:hover { color: var(--accent-2); background: rgba(255, 255, 255, 0.06); }
.sched-actions .sch-del:hover { color: var(--err); background: rgba(255, 255, 255, 0.06); }
.sched-sessions {
  list-style: none; margin: 0; padding: 6px 0 10px 30px;
  display: flex; flex-direction: column; gap: 2px;
}
.sched-sessions.hidden { display: none; }
.sched-session { list-style: none; }
.ss-open {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left; background: none; border: none;
  color: var(--fg-2); padding: 4px 8px; cursor: pointer; border-radius: 6px;
  font-size: 12.5px; font-family: var(--mono);
}
.ss-open:hover { color: var(--fg); background: rgba(255, 255, 255, 0.05); }
.ss-mark { display: inline-flex; width: 16px; justify-content: center; flex-shrink: 0; }
.ss-mark.ok { color: var(--ok); }
.ss-mark.err { color: var(--err); }
.sched-empty {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 40px 20px; text-align: center; color: var(--fg-3);
}
.sched-empty-title { font-size: 14px; font-weight: 600; color: var(--fg-2); }
.sched-empty-hint { font-size: 12.5px; max-width: 440px; }

/* Skills & Extensions – Übersichtsseite */
#skills-page {
  flex: 1; display: none; flex-direction: column; min-width: 0;
  background: var(--bg);
}
body.skills-open main { display: none; }
body.skills-open #skills-page { display: flex; }
.skills-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.skills-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.skills-head .spacer { flex: 1; }
.skills-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
.skills-group {
  margin: 4px 0 10px; font-size: 12px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--fg-3);
}
.skills-list {
  list-style: none; margin: 0 0 24px; padding: 0;
  display: flex; flex-direction: column; gap: 8px; max-width: 760px;
}
.skill-item {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
}
.skill-name { font-size: 14px; font-weight: 600; color: var(--fg); }
.skill-desc { font-size: 12.5px; color: var(--fg-2); margin-top: 3px; overflow-wrap: break-word; }
.skill-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.skill-src {
  font-size: 11px; font-weight: 700; color: var(--fg-3);
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 8px; flex-shrink: 0;
}
.skill-path {
  font-family: var(--mono); font-size: 11.5px; color: var(--fg-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 480px;
}
.skill-caps { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.cap {
  font-size: 11.5px; font-family: var(--mono); font-weight: 600;
  color: var(--fg-2); background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 8px;
}
.cap-tool { color: var(--ok); }
.cap-cmd { color: var(--accent-2); }

/* Läufe – Übersichtsseite */
#runs-page {
  flex: 1; display: none; flex-direction: column; min-width: 0;
  background: var(--bg);
}
body.runs-open main { display: none; }
body.runs-open #runs-page { display: flex; }
.run-item { display: flex; flex-direction: column; gap: 6px; }
.run-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.run-head .spacer { flex: 1; }
.run-status {
  font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 8px;
  border: 1px solid var(--border); background: var(--bg-3); color: var(--fg-2);
}
.run-running { color: var(--accent-2); }
.run-ok { color: var(--ok); }
.run-skip { color: var(--fg-3); }
.run-error { color: var(--err); }
.run-queued { color: var(--fg-3); }
.run-src, .run-kind {
  font-size: 11px; font-weight: 700; color: var(--fg-3);
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 8px;
}
.run-when { font-size: 11.5px; color: var(--fg-3); }
.run-meta { font-size: 12.5px; color: var(--fg-2); }
.run-out {
  font-family: var(--mono); font-size: 11.5px; color: var(--fg-2);
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 120px; overflow: hidden;
}
.run-actions { display: flex; gap: 8px; }
.run-open {
  font-size: 12px; padding: 3px 10px; cursor: pointer;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--fg-2);
}
.run-open:hover { border-color: var(--fg-2); color: var(--fg); }

/* Neuer-Lauf-Dialog */
#run-modal {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(4, 6, 10, 0.6);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  animation: fade 0.15s ease;
}
#run-modal.hidden { display: none; }
.run-dlg { width: min(560px, 92vw); display: flex; flex-direction: column; }

/* Graphs – Übersichtsseite */
#graphs-page {
  flex: 1; display: none; flex-direction: column; min-width: 0;
  background: var(--bg);
}
body.graphs-open main { display: none; }
body.graphs-open #graphs-page { display: flex; }
.graphs-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.graphs-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.graphs-head .spacer { flex: 1; }
.graphs-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
.graphs-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 8px; max-width: 820px;
}
.graph-item { border-radius: var(--radius-sm); }
.graph-card {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.graph-card:hover { border-color: var(--border-strong); background: var(--bg-3); }
.graph-toggle {
  background: none; border: none; color: var(--fg-3);
  cursor: pointer; padding: 2px 0 0; width: 16px; flex-shrink: 0;
  font-size: 11px; line-height: 1;
}
.graph-toggle:hover { color: var(--fg); }
.graph-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.graph-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.graph-name { font-size: 14px; font-weight: 600; color: var(--fg); word-break: break-word; }
.graph-meta { font-size: 12px; color: var(--fg-3); white-space: nowrap; flex-shrink: 0; }
.graph-desc {
  font-size: 12.5px; color: var(--fg-2); word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.graph-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.graph-actions .gr-del {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  background: none; border: none; color: var(--fg-3); cursor: pointer;
  border-radius: 6px; font-size: 12px;
}
.graph-actions .gr-del:hover { color: var(--err); background: rgba(255, 255, 255, 0.06); }
.graph-body { padding: 8px 0 14px 30px; }
.graph-body.hidden { display: none; }
.graph-canvas-wrap { overflow-x: auto; overflow-y: hidden; padding: 6px 2px; }
.graph-canvas {
  position: relative;
  background-color: var(--bg-1);
  background-image: radial-gradient(circle, var(--border) 1px, transparent 1px);
  background-size: 20px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.graph-canvas svg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  overflow: visible; pointer-events: none;
}
.graph-edge { stroke: var(--border-strong); stroke-width: 1.6; fill: none; }
.graph-arrow { fill: var(--border-strong); }
.gnode {
  position: absolute; box-sizing: border-box;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px;
  cursor: pointer; user-select: none; overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.gnode:hover { border-color: var(--accent); background: var(--bg-3); }
.gnode.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.gnode-head { display: flex; align-items: center; gap: 8px; }
.gnode-kind {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--fg-3); background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 8px; flex-shrink: 0;
}
.gk-prompt { color: var(--accent-2); }
.gk-code { color: var(--ok); }
.gk-shell { color: var(--warn); }
.gk-gate { color: var(--err); }
.gnode-id {
  font-family: var(--mono); font-size: 12px; color: var(--fg); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.gnode-label {
  font-size: 12px; color: var(--fg-2); margin-top: 5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.graph-detail {
  margin-top: 12px;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
}
.graph-detail.hidden { display: none; }
.graph-detail-head { display: flex; align-items: center; gap: 10px; }
.graph-detail-title { font-size: 13px; font-weight: 700; color: var(--fg); word-break: break-word; }
.graph-detail-meta { font-family: var(--mono); font-size: 11.5px; color: var(--fg-3); margin: 2px 0 8px; }
.graph-detail-close {
  margin-left: auto; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; background: none; border: none;
  color: var(--fg-3); cursor: pointer; border-radius: 6px; font-size: 12px;
}
.graph-detail-close:hover { color: var(--fg); background: var(--bg-3); }
.graph-detail-code {
  margin: 0; padding: 10px 12px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 12px; line-height: 1.55;
  color: var(--fg-2); white-space: pre-wrap; word-break: break-word;
  overflow-x: auto; max-height: 360px; overflow-y: auto;
}
.graph-empty {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 40px 20px; text-align: center; color: var(--fg-3);
}
.graph-empty-title { font-size: 14px; font-weight: 600; color: var(--fg-2); }
.graph-empty-hint { font-size: 12.5px; max-width: 440px; }

/* Kanban-Board */
#kanban-page {
  flex: 1; display: none; flex-direction: column; min-width: 0;
  background: var(--bg);
}
body.kanban-open main { display: none; }
body.kanban-open #kanban-page { display: flex; }
.kanban-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.kanban-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.kanban-head .spacer { flex: 1; }
.kanban-board {
  flex: 1; display: flex; padding: 16px 20px;
  overflow-x: auto; align-items: stretch;
}
.kanban-col {
  flex: 1; min-width: 240px; max-width: 440px;
  display: flex; flex-direction: column;
  padding: 0 16px;
  border-left: 1px solid var(--border);
}
.kanban-col:first-child { border-left: none; padding-left: 0; }
.kanban-col-head {
  padding: 4px 0 12px; font-size: 13px; font-weight: 700; color: var(--fg-2);
  display: flex; align-items: center; justify-content: space-between;
}
.kanban-col-count { color: var(--fg-3); font-weight: 500; font-size: 12px; }
.kanban-col-body {
  flex: 1; overflow-y: auto; padding: 2px;
  display: flex; flex-direction: column; gap: 8px;
}
.kanban-col-body.kb-drop-over {
  background: rgba(255, 255, 255, 0.03);
  outline: 2px dashed var(--border-strong);
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}
.kb-card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px;
  display: flex; flex-direction: column; gap: 6px;
  cursor: grab;
}
.kb-card:hover { border-color: var(--border-strong); }
.kb-card:active { cursor: grabbing; }
.kb-card.kb-dragging { opacity: 0.4; }
.kb-title { font-size: 13.5px; font-weight: 600; color: var(--fg); word-break: break-word; }
.kb-desc { font-size: 12px; color: var(--fg-3); white-space: pre-wrap; word-break: break-word; }
.kb-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.kb-proj {
  display: inline-flex; align-items: center; min-width: 0;
  max-width: 200px; padding: 2px 8px;
  font-size: 11.5px; font-weight: 600; color: var(--fg-2);
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kb-proj-none { opacity: 0.55; }
.kb-actions { display: flex; gap: 2px; flex-shrink: 0; }
.kb-actions .kb-session svg { width: 13px; height: 13px; display: block; }
.kb-actions button {
  background: none; border: none; color: var(--fg-3); cursor: pointer;
  padding: 2px 6px; font-size: 12px; border-radius: 4px;
}
.kb-status {
  width: 28px; max-width: 28px; height: 26px; padding: 0;
  color: var(--fg-3); background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 5px; cursor: pointer; text-indent: -999px;
}
.kb-status:hover, .kb-status:focus { width: auto; max-width: 110px; text-indent: 0; color: var(--fg); }
.kb-actions button:hover { color: var(--fg); background: rgba(255, 255, 255, 0.06); }
.kb-actions .kb-del:hover { color: var(--err); }
.kb-actions .kb-session:hover { color: var(--ok); }
.kb-processing {
  font-size: 11.5px; font-weight: 600; color: var(--warn);
  display: flex; align-items: center; gap: 5px;
}
.kb-processing::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: var(--warn); animation: kb-pulse 1.2s ease-in-out infinite;
}
@keyframes kb-pulse { 50% { opacity: 0.25; } }
.kb-card.kb-working { border-color: var(--warn); }
.kb-empty { padding: 24px 0; }

input, textarea {
  background: var(--bg-2); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 7px 10px; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(201, 209, 217, 0.12); }

/* ==========================================================================
   Main / Topbar
   ========================================================================== */
main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
#topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 19, 28, 0.85);
  backdrop-filter: blur(8px);
  font-size: 12.5px;
}
.tb-group { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tb { max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.tb-ico { width: 14px; height: 14px; flex-shrink: 0; color: var(--fg-3); }
.tb.dim { color: var(--fg-2); font-weight: 400; }
.tb-sep { color: var(--fg-3); }
#topbar .spacer { flex: 1; }
.top-btn {
  background: var(--bg-2); color: var(--fg-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 5px 12px; cursor: pointer; font-size: 12px; transition: all 0.15s;
}
.top-btn:hover { color: var(--fg); border-color: var(--border-strong); background: var(--bg-3); }
.top-btn.danger:hover { color: var(--err); border-color: var(--err); }
.top-btn:disabled, .top-btn:disabled:hover {
  opacity: 0.4; cursor: not-allowed; color: var(--fg-3); border-color: var(--border); background: var(--bg-2);
}
.top-btn svg { width: 14px; height: 14px; vertical-align: middle; }

.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; transition: background 0.3s; }
.dot.on { background: var(--ok); box-shadow: 0 0 8px rgba(52, 211, 153, 0.7); }
.dot.off { background: var(--err); }

/* ==========================================================================
   Widgets / Status / Queue
   ========================================================================== */
#widgets {
  border-bottom: 1px dashed var(--border);
  padding: 8px 18px; font-size: 12.5px; color: var(--fg-2);
  background: var(--bg-1);
}
#widgets .wline { white-space: pre-wrap; }
#queue { padding: 4px 18px 0; }
#queue:empty { display: none; }
#queue .q { color: var(--warn); font-size: 12px; }
#statusbar {
  padding: 4px 18px; font-size: 12px; color: var(--fg-3);
  border-top: 1px solid var(--border); min-height: 26px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--bg-1);
}
/* Leere Statuszeile einziehen – sonst klafft zwischen Chat und Toolbar eine Lücke */
#statusbar:empty { display: none; }
#rebuild-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 18px; font-size: 12.5px; font-weight: 600;
  color: var(--fg);
  background: rgba(255, 170, 0, 0.08);
  border-top: 1px solid var(--border);
}
#rebuild-banner .spinner { flex: 0 0 auto; }

/* Aktive Subagents – kompakter, hierarchischer Baum am unteren Chatrand */
#subagent-panel {
  flex: 0 0 auto;
  max-height: min(34vh, 330px);
  overflow: auto;
  padding: 8px 18px 10px;
  background:
    linear-gradient(180deg, rgba(201, 209, 217, 0.035), transparent 42px),
    var(--bg-1);
  border-top: 1px solid var(--border);
  box-shadow: 0 -10px 28px rgba(0, 0, 0, 0.16);
}
.sa-tree { width: min(880px, 100%); }
.sa-root {
  position: relative;
  width: fit-content; max-width: 100%; min-height: 31px;
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 8px;
  color: var(--fg); background: var(--bg-2);
  border: 1px solid var(--border-strong); border-radius: 8px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.2);
}
.sa-root-icon {
  position: relative; width: 20px; height: 18px; flex: 0 0 20px;
}
.sa-root-icon::before, .sa-root-icon::after {
  content: ""; position: absolute; height: 1px; background: var(--accent-2);
  transform-origin: left center; left: 5px; top: 5px; width: 11px;
}
.sa-root-icon::before { transform: rotate(31deg); }
.sa-root-icon::after { transform: rotate(89deg); width: 8px; }
.sa-root-icon i {
  position: absolute; z-index: 1; width: 5px; height: 5px; border-radius: 50%;
  background: var(--fg-2); box-shadow: 0 0 0 2px var(--bg-2);
}
.sa-root-icon i:nth-child(1) { left: 2px; top: 2px; background: var(--ok); animation: sa-pulse 1.35s ease-in-out infinite; }
.sa-root-icon i:nth-child(2) { right: 1px; top: 8px; }
.sa-root-icon i:nth-child(3) { left: 3px; bottom: 0; }
.sa-root-name { font-size: 12px; font-weight: 750; white-space: nowrap; }
.sa-root-meta { color: var(--fg-2); font-size: 11.5px; white-space: nowrap; }
.sa-mode {
  color: var(--fg-3); font: 600 10px/1 var(--mono); text-transform: uppercase;
  border-left: 1px solid var(--border); padding-left: 8px; white-space: nowrap;
}
.sa-children { position: relative; padding-top: 3px; }
.sa-children::before {
  content: ""; position: absolute; left: 10px; top: -2px; bottom: 17px;
  border-left: 1px solid var(--border-strong);
}
.sa-branch {
  position: relative;
  margin-top: 5px;
  margin-left: calc(12px + var(--sa-indent));
  max-width: 740px;
}
.sa-branch::before {
  content: ""; position: absolute; left: -20px; top: 16px; width: 16px;
  border-top: 1px solid var(--border-strong);
}
.sa-branch::after {
  content: ""; position: absolute; left: -20px; top: -6px; height: 22px;
  border-left: 1px solid var(--border-strong);
}
.sa-node {
  background: rgba(28, 33, 40, 0.88); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
  transition: border-color 0.15s, background 0.15s;
}
.sa-node:hover { border-color: var(--border-strong); background: var(--bg-2); }
.sa-node[open] { border-color: var(--border-strong); background: var(--bg-2); }
.sa-node summary {
  min-height: 31px; display: flex; align-items: center; gap: 8px;
  padding: 4px 9px; cursor: pointer; list-style: none; min-width: 0;
}
.sa-node summary::-webkit-details-marker { display: none; }
.sa-state {
  width: 7px; height: 7px; border-radius: 50%; flex: 0 0 7px;
  background: var(--fg-3); box-shadow: 0 0 0 3px rgba(139, 148, 158, 0.08);
}
.sa-active .sa-state { background: var(--warn); animation: sa-pulse 1.2s ease-in-out infinite; }
.sa-waiting .sa-state { background: var(--fg-3); opacity: 0.65; }
.sa-done .sa-state { background: var(--ok); }
.sa-error .sa-state { background: var(--err); }
@keyframes sa-pulse { 50% { opacity: 0.38; box-shadow: 0 0 0 5px rgba(210, 153, 34, 0.08); } }
.sa-name {
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--fg); font: 700 12px/1.3 var(--mono);
}
.sa-step {
  min-width: 18px; height: 17px; display: inline-grid; place-items: center;
  padding: 0 5px; color: var(--fg-3); background: var(--bg-3);
  border: 1px solid var(--border); border-radius: 999px; font: 700 9px/1 var(--mono);
}
.sa-action {
  flex: 1; min-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--fg-2); font-size: 11.5px;
}
.sa-chevron { color: var(--fg-3); font-size: 13px; transition: transform 0.15s; }
.sa-node[open] .sa-chevron { transform: rotate(180deg); }
.sa-detail {
  padding: 8px 10px 9px 32px; border-top: 1px solid var(--border);
  display: grid; gap: 7px;
}
.sa-detail-row { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 9px; align-items: start; }
.sa-detail-row > span {
  color: var(--fg-3); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}
.sa-detail p, .sa-detail pre { margin: 0; color: var(--fg-2); font-size: 11px; line-height: 1.45; }
.sa-detail p { white-space: pre-wrap; overflow-wrap: anywhere; }
.sa-detail pre {
  max-height: 120px; overflow: auto; padding: 6px 8px;
  background: var(--bg-1); border: 1px solid var(--border); border-radius: 6px;
  font-family: var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
}
.sa-usage { color: var(--fg-3); font: 10.5px/1.4 var(--mono); padding-left: 93px; }
.sa-error {
  color: var(--err); font: 11px/1.4 var(--mono); white-space: pre-wrap;
  padding: 6px 8px; background: rgba(248, 81, 73, 0.06); border-radius: 6px;
}
.sa-starting { margin: 7px 0 0 30px; color: var(--fg-3); font-size: 11.5px; }

/* ==========================================================================
   Chat
   ========================================================================== */
#chat { flex: 1; overflow-y: auto; padding: 30px 18px 8px; }
.msg { margin-bottom: 22px; max-width: 92%; }
.msg.user { margin-left: auto; }
/* Lesbarkeit: Textblöcke auf ~760px begrenzen, Tool-Blöcke dürfen volle Breite behalten */
.msg.user .bubble, .msg.assistant .atext { max-width: 760px; }
.msg.assistant { max-width: 100%; }

.bubble {
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: 14px 14px 4px 14px;
  padding: 11px 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}
.msg.user .bubble p, .msg.user .bubble ul, .msg.user .bubble h2, .msg.user .bubble h3, .msg.user .bubble h4 { margin: 0 0 8px; }
.msg.user .bubble p:last-child { margin-bottom: 0; }

.msg.assistant .atext { white-space: normal; overflow-wrap: break-word; }
.msg.assistant .atext p, .md-h { margin: 0 0 8px; }
.msg.assistant .atext p:last-child { margin-bottom: 0; }
.msg.assistant .atext ul { margin: 4px 0 8px; padding-left: 22px; }
.msg.assistant .atext li { margin-bottom: 3px; }
.msg.assistant blockquote {
  margin: 8px 0; padding: 4px 12px;
  border-left: 3px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 0 6px 6px 0; color: var(--fg-2);
}
.msg.assistant hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.msg.assistant a { color: var(--fg-2); text-decoration: underline; text-underline-offset: 2px; }
.msg.assistant a:hover { color: var(--fg); }

code {
  background: var(--bg-3); padding: 1.5px 6px; border-radius: 5px;
  font-family: var(--mono); font-size: 0.86em; color: var(--fg);
}
pre.code {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
  overflow-x: auto; font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
  margin: 8px 0;
}

/* Markdown-Tabellen */
.md-table-wrap { overflow-x: auto; margin: 8px 0; border-radius: var(--radius-sm); }
table.md-table {
  border-collapse: collapse; font-size: 13px; width: 100%;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden;
}
.md-table th, .md-table td {
  border: 1px solid var(--border); padding: 7px 12px; text-align: left;
  vertical-align: top;
}
.md-table th {
  background: var(--bg-3); font-weight: 700; color: var(--fg);
  white-space: nowrap;
}
.md-table tbody tr:nth-child(even) td { background: rgba(255, 255, 255, 0.02); }
.md-table td.al-center { text-align: center; }
.md-table td.al-right { text-align: right; }

/* Thinking */
details.thinking { margin: 6px 0; }
details.thinking summary {
  color: var(--fg-3); cursor: pointer; font-size: 12px;
  user-select: none; display: inline-flex; align-items: center; gap: 6px;
}
details.thinking summary::before { content: "🧠"; font-size: 11px; opacity: 0.8; }
details.thinking pre {
  background: var(--bg-2); border-left: 2px solid #30363d;
  padding: 10px 12px; border-radius: 0 8px 8px 0;
  white-space: pre-wrap; font-size: 12.5px; color: var(--fg-3); font-family: var(--mono);
  margin-top: 6px;
}

/* Tool-Aufrufe & Ergebnisse */
details.toolcall, details.toolresult, details.toolact {
  margin: 6px 0; background: var(--bg-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden;
}
details.toolcall summary, details.toolresult summary, details.toolact summary {
  padding: 7px 12px; cursor: pointer; font-size: 12.5px;
  display: flex; align-items: center; gap: 7px;
  font-family: var(--mono);
}
details.toolcall summary { color: var(--fg-2); }
details.toolresult summary { color: var(--fg-2); }
details.toolact summary { color: var(--fg-2); }
details[open] summary { border-bottom: 1px solid var(--border); background: rgba(255,255,255,0.02); }
details.toolcall pre, details.toolresult pre {
  margin: 0; padding: 10px 12px;
  white-space: pre-wrap; font-size: 12px; font-family: var(--mono);
  color: var(--fg-2); max-height: 340px; overflow-y: auto; line-height: 1.55;
}
.tool-ico { opacity: 0.85; font-size: 12px; }
.tool-preview {
  color: var(--fg-3); margin-left: auto; font-size: 11px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%;
}
.md-gap { height: 8px; }
.err-tag { color: var(--err); font-weight: 700; }

/* Streaming */
.msg.assistant.streaming .cur {
  display: inline-block; width: 7px; height: 15px;
  margin-left: 3px; vertical-align: -2px;
  background: var(--accent); border-radius: 2px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.busy {
  color: var(--fg-2); font-size: 13px; padding: 4px 0;
  display: flex; align-items: center; gap: 8px;
}
.busy .dots { display: inline-flex; gap: 3px; }
.busy .dots span {
  width: 5px; height: 5px; border-radius: 50%; background: var(--fg-2);
  animation: bounce 1.2s infinite;
}
.busy .dots span:nth-child(2) { animation-delay: 0.15s; }
.busy .dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }

.muted { color: var(--fg-3); font-size: 12.5px; }
.center { text-align: center; padding: 60px 0; }

.empty-hint {
  max-width: 420px; margin: 80px auto; text-align: center; color: var(--fg-3);
}
.empty-hint h3 { color: var(--fg-2); margin: 0 0 8px; font-size: 16px; }

/* ==========================================================================
   Handlungspunkte (dezent einklappbar)
   ========================================================================== */
/* Aktivitäts-Zeile: reiner Text-Abschnitt mit passendem SVG-Icon. */
.spinner {
  display: inline-block;
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.activity {
  display: flex; align-items: center; gap: 7px;
  margin: 8px 0 2px;
  font-size: 12.5px; color: var(--fg-3);
  min-width: 0;
}
.activity .act-text {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.activity .act-ico {
  width: 14px; height: 14px; flex-shrink: 0; color: var(--fg-3);
}
.activity.live { color: var(--fg-2); }
.activity.live .act-ico { color: var(--accent); }
.act-ico.pulse { animation: actpulse 1.4s ease-in-out infinite; }
@keyframes actpulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ==========================================================================
   Eingabe + Feature-Leiste (eine zusammenhängende Fläche)
   ========================================================================== */
.composer {
  background: var(--bg-1);
  border-top: 1px solid var(--border);
  position: relative;
}
/* Innerhalb der Composer-Fläche: Bedienelemente flach, ohne Rahmen */
.composer .tool-btn {
  background: transparent; border: none; color: var(--fg-3);
}
.composer .tool-btn:hover {
  background: rgba(255, 255, 255, 0.06); border: none; color: var(--fg);
}
.composer .tool-btn:disabled,
.composer .tool-btn:disabled:hover {
  opacity: 0.4;
  background: transparent;
  color: var(--fg-3);
  cursor: not-allowed;
}
.composer-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 2px 16px 12px;
}
.composer-bar .spacer { flex: 1; }
.model-select {
  color: var(--fg-2);
  background: transparent; border: none;
  padding: 7px 6px; font-size: 12.5px; font-weight: 600; cursor: pointer;
  max-width: 220px;
  transition: color 0.15s;
}
.model-select:hover { color: var(--fg); }
.tool-btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--bg-2); color: var(--fg-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 7px; cursor: pointer; font-size: 12.5px; font-weight: 600;
  transition: all 0.15s;
}
.tool-btn svg { width: 17px; height: 17px; }
.tool-btn:hover { color: var(--fg); border-color: var(--border-strong); background: var(--bg-3); }
.tool-btn.active { color: var(--fg); border-color: var(--border-strong); background: rgba(255, 255, 255, 0.06); }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px;
  display: inline-grid; place-items: center;
  background: var(--accent); color: #0d1117;
  border-radius: 999px; font-size: 11px; font-weight: 800;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.25);
}

/* ==========================================================================
   Diff-Chip (oben rechts über dem Chat, grün = neu, rot = entfernt)
   ========================================================================== */
#diff-chip {
  position: absolute;
  top: 60px; right: 16px;
  z-index: 35;
  width: min(520px, calc(100% - 32px));
  background: var(--bg-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  max-height: min(62vh, 560px);
  animation: chip-in 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
#diff-chip.hidden { display: none; }
@keyframes chip-in { from { transform: translateY(-8px); opacity: 0; } }

.diff-chip-head {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.diff-chip-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--fg-2);
  cursor: pointer; padding: 4px; border-radius: 6px;
  transition: background 0.15s;
}
.diff-chip-toggle:hover { background: var(--bg-3); color: var(--fg); }
.diff-chip-toggle svg { width: 16px; height: 16px; transition: transform 0.15s; }
#diff-chip:not(.collapsed) .diff-chip-toggle svg { transform: rotate(180deg); }

.diff-chip-stats { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; }
.diff-chip-stats .dstat-add { color: var(--ok); font-weight: 700; font-family: var(--mono); }
.diff-chip-stats .dstat-del { color: var(--err); font-weight: 700; font-family: var(--mono); }
.diff-chip-stats .dstat-files { color: var(--fg-3); }

#diff-chip.collapsed .diff-chip-head { border-bottom: none; }
#diff-chip.collapsed #diff-meta,
#diff-chip.collapsed #diff-list { display: none; }

.diff-meta { padding: 8px 14px 0; font-size: 12px; color: var(--fg-3); }
.diff-list { flex: 1; overflow-y: auto; padding: 10px 12px; }

.diff-file { margin-bottom: 6px; }
.diff-row {
  width: 100%; display: flex; align-items: center; gap: 10px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px;
  cursor: pointer; color: var(--fg); text-align: left;
  transition: all 0.15s;
}
.diff-row:hover { border-color: var(--border-strong); background: var(--bg-3); }
.diff-status {
  flex-shrink: 0; font-size: 11px; font-weight: 700;
  border-radius: 999px; padding: 2px 9px;
}
.diff-status.st-modified { color: var(--warn); background: rgba(251, 191, 36, 0.12); border: 1px solid rgba(251, 191, 36, 0.35); }
.diff-status.st-added, .diff-status.st-untracked, .diff-status.st-session { color: var(--ok); background: rgba(52, 211, 153, 0.12); border: 1px solid rgba(52, 211, 153, 0.35); }
.diff-status.st-deleted { color: var(--err); background: rgba(248, 113, 113, 0.12); border: 1px solid rgba(248, 113, 113, 0.35); }
.diff-status.st-renamed, .diff-status.st-copied { color: var(--accent-2); background: rgba(139, 148, 158, 0.12); border: 1px solid rgba(139, 148, 158, 0.35); }
.diff-path {
  font-family: var(--mono); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.diff-body {
  background: var(--bg-2);
  border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  padding: 8px 10px;
  max-height: 60vh; overflow-y: auto;
  font-family: var(--mono); font-size: 11.5px; line-height: 1.5;
}
.diff-body .d-add { color: var(--ok); background: rgba(52, 211, 153, 0.08); white-space: pre-wrap; }
.diff-body .d-del { color: var(--err); background: rgba(248, 113, 113, 0.08); white-space: pre-wrap; }
.diff-body .d-hunk { color: var(--fg-2); font-weight: 600; }
.diff-body .d-meta { color: var(--fg-3); }
.diff-body .d-plain { color: var(--fg-2); white-space: pre-wrap; }

/* Syntax-Highlighting im Diff */
.tok-kw { color: #c792ea; font-weight: 600; }
.tok-str { color: #a5d6a7; }
.tok-num { color: #f78c6c; }
.tok-fn { color: #82aaff; }
.tok-type { color: #ffcb6b; }
.tok-com { color: #5f6f87; font-style: italic; }

/* Befehls-Autovervollständigung */
#cmd-suggest {
  position: absolute; bottom: 100%; left: 0; right: 0;
  margin-bottom: 6px;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 260px; overflow-y: auto;
  z-index: 30;
  display: flex; flex-direction: column;
}
.cs-item {
  display: flex; align-items: baseline; gap: 10px;
  width: 100%; text-align: left;
  background: none; border: none;
  color: var(--fg-2); cursor: pointer;
  padding: 8px 12px; font-size: 12.5px;
}
.cs-item:hover, .cs-item.sel { background: var(--bg-3); color: var(--fg); }
.cs-name { font-family: var(--mono); font-weight: 600; flex-shrink: 0; }
.cs-desc {
  color: var(--fg-3); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ==========================================================================
   Eingabezeile
   ========================================================================== */
#inputbar {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px 16px 2px;
}
#inputbar.drag { outline: 2px dashed var(--border-strong); outline-offset: -6px; border-radius: var(--radius); }
#btn-attach { flex-shrink: 0; }
#attachments {
  flex-basis: 100%;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
#attachments:empty { display: none; }
.atch {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 3px 6px 3px 3px;
  font-size: 12px; color: var(--fg-2); max-width: 240px;
}
.atch img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; display: block; flex-shrink: 0; }
.atch .atch-doc { width: 34px; height: 34px; display: grid; place-items: center; font-size: 16px; flex-shrink: 0; }
.atch .atch-name {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0; flex: 1;
}
.atch .atch-x {
  background: none; border: none; color: var(--fg-3); cursor: pointer;
  padding: 0 4px; font-size: 12px; flex-shrink: 0;
}
.atch .atch-x:hover { color: var(--err); }
#inputbar textarea {
  width: 100%; resize: none; max-height: 200px;
  background: transparent; border: none; box-shadow: none;
  border-radius: 0; padding: 6px 2px;
  line-height: 1.5;
}
/* Kein Rahmen/Outline beim Fokussieren des Eingabefelds */
#inputbar textarea:focus,
#inputbar textarea:focus-visible {
  outline: none;
  border: none;
  box-shadow: none;
}
.composer:focus-within {
  border-top-color: var(--accent-2);
  box-shadow: inset 0 1px 0 rgba(201, 209, 217, 0.18);
}
#inputbar textarea::placeholder { color: #6e7681; }
#btn-send {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #0d1117;
  border: none; border-radius: 12px; padding: 10px 16px; min-width: 44px;
  font-weight: 700; cursor: pointer; transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
}
#btn-send svg { width: 16px; height: 16px; display: block; }
#btn-send:hover { transform: translateY(-1px); filter: brightness(1.08); }
#btn-send:active { transform: translateY(0); }
#btn-send:disabled { opacity: 0.55; cursor: wait; transform: none; }

/* ==========================================================================
   Login
   ========================================================================== */
.login-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(4, 6, 10, 0.82);
  backdrop-filter: blur(5px);
}
.login-overlay.hidden { display: none; }
.login-card {
  width: min(340px, 100%); padding: 22px;
  display: flex; flex-direction: column;
  background: var(--bg-2); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.login-card h2 { margin: 0 0 16px; font-size: 18px; }
.login-card label { margin: 8px 0 4px; color: var(--fg-2); font-size: 12.5px; font-weight: 600; }
.login-card button {
  margin-top: 16px; padding: 8px 14px;
  background: var(--accent); color: var(--bg);
  border: none; border-radius: var(--radius-sm);
  cursor: pointer; font-weight: 700;
}
.login-card button:disabled { opacity: 0.55; cursor: wait; }
.login-error { margin: 10px 0 0; color: var(--err); font-size: 12.5px; }

/* ==========================================================================
   Dialoge (Extension-UI)
   ========================================================================== */
#modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4, 6, 10, 0.6);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  animation: fade 0.15s ease;
}
#modal.hidden { display: none; }
@keyframes fade { from { opacity: 0; } }
.dlg {
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: 16px; padding: 22px;
  width: min(540px, 92vw); max-height: 82vh; overflow-y: auto;
  box-shadow: var(--shadow);
  animation: pop 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

/* Verzeichnis-Browser (Projekt-Picker über die Web-UI) */
/* Geplanter Trigger (Editor) */

#browse-modal {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(4, 6, 10, 0.6);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  animation: fade 0.15s ease;
}
#browse-modal.hidden { display: none; }
.browse { width: min(560px, 92vw); display: flex; flex-direction: column; overflow-y: auto; }
.browse-path {
  padding: 8px 12px; font-family: var(--mono); font-size: 12.5px;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 10px;
  word-break: break-all; color: var(--fg-2);
}
.browse-list {
  flex: 1; overflow-y: auto; max-height: 42vh; min-height: 120px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-1);
}
.browse-dir {
  display: flex; align-items: center; gap: 8px; width: 100%;
  text-align: left; padding: 7px 12px; background: none; border: none;
  color: var(--fg-2); cursor: pointer; font-size: 13px;
}
.browse-dir:hover { background: var(--bg-3); color: var(--fg); }
.browse-empty { padding: 20px 0; }
.browse-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.browse-actions .spacer { flex: 1; }

@keyframes pop { from { transform: scale(0.95); opacity: 0; } }
.dlg h3 {
  margin: 0 0 12px; font-size: 16px;
  color: var(--fg);
}
.dlg-sect {
  margin: 16px 0 8px; padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--fg-3);
}
.dlg-sect:first-of-type { margin-top: 2px; padding-top: 0; border-top: none; }
.dlg p { margin: 0 0 14px; color: var(--fg-2); }
.dlg .dlg-hint { font-size: 12px; line-height: 1.55; color: var(--fg-3); }
.dlg.onboarding ol { margin: 0 0 16px; padding-left: 22px; color: var(--fg-2); line-height: 1.7; }
.dlg.onboarding code { font-size: 11px; overflow-wrap: anywhere; color: var(--accent-2); }
.dlg input, .dlg textarea, .dlg select { width: 100%; margin-bottom: 12px; }
.dlg label { display: block; margin-bottom: 4px; color: var(--fg-2); font-size: 12.5px; font-weight: 600; }
.dlg label.check { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-weight: 400; cursor: pointer; }
.dlg input[type="checkbox"] { width: auto; margin-bottom: 0; }
.dlg-btns { display: flex; gap: 8px; justify-content: flex-end; }
.dlg-btns button, .dlg-list button {
  background: var(--bg-3); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 18px; cursor: pointer; transition: all 0.15s;
}
.dlg-btns button:hover, .dlg-list button:hover { border-color: var(--fg-2); color: var(--fg); }
.dlg-btns button.danger { color: var(--err); }
.dlg-btns button:disabled { opacity: 0.55; cursor: wait; }
.dlg-list { display: flex; flex-direction: column; gap: 6px; }
.dlg-list button { text-align: left; }
.tree-pre {
  margin: 8px 0; padding: 12px 14px;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-family: var(--mono); font-size: 12px;
  white-space: pre; overflow: auto; max-height: 60vh;
}

.project-empty { padding: 12px 8px; color: var(--fg-3); font-size: 12px; line-height: 1.5; }
.project-empty button { width: 100%; margin-top: 8px; }

/* ==========================================================================
   Toasts
   ========================================================================== */
#toasts {
  position: fixed; bottom: 18px; right: 18px; z-index: 60;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.toast {
  background: var(--bg-2); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent-2);
  border-radius: 10px; padding: 11px 16px; max-width: 380px;
  box-shadow: var(--shadow); font-size: 13px; color: var(--fg);
  animation: slide-in 0.2s ease; cursor: pointer;
}
@keyframes slide-in { from { transform: translateX(20px); opacity: 0; } }
.toast.warning { border-left-color: var(--warn); }
.toast.error { border-left-color: var(--err); }
.toast.info { border-left-color: var(--accent-2); }

/* Einheitliche Lade-/Fehlerzustände */
.load-error {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 28px 18px; color: var(--fg-2); text-align: center;
  border: 1px dashed rgba(248, 81, 73, 0.45); border-radius: var(--radius-sm);
  background: rgba(248, 81, 73, 0.04);
}
.load-error strong { color: var(--err); }
.retry-btn {
  margin-top: 4px; padding: 6px 12px; color: var(--fg);
  background: var(--bg-3); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); cursor: pointer;
}
.sessions-loading { display: flex; align-items: center; gap: 7px; padding: 6px; }
.session-error { color: var(--err); font-size: 12px; padding: 6px; overflow-wrap: anywhere; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 760px) {
  .mobile-only { display: inline-flex !important; }
  #sidebar {
    position: fixed; z-index: 70; inset: 0 auto 0 0;
    width: min(86vw, 320px); min-width: 0;
    box-shadow: 18px 0 50px rgba(0, 0, 0, 0.55);
    transform: translateX(0); transition: transform 0.2s ease;
  }
  body.sidebar-collapsed #sidebar {
    width: min(86vw, 320px); min-width: 0;
    transform: translateX(-105%);
  }
  body.sidebar-collapsed #sidebar .side-label,
  body.sidebar-collapsed #sidebar #project-list,
  body.sidebar-collapsed #sidebar #project-add,
  body.sidebar-collapsed #sidebar .side-foot { display: initial; }
  body.sidebar-collapsed #sidebar .side-foot { display: flex; }
  body.sidebar-collapsed #sidebar .side-nav-item { justify-content: flex-start; padding: 8px 10px; }
  body.sidebar-collapsed #sidebar .side-nav-item span { display: inline; }
  body.sidebar-collapsed #sidebar .side-head { flex-direction: row; justify-content: space-between; padding: 2px 6px 10px; }
  #sidebar-backdrop:not(.hidden) {
    display: block; position: fixed; inset: 0; z-index: 65;
    background: rgba(0, 0, 0, 0.58); backdrop-filter: blur(2px);
  }
  #topbar { padding: 8px 10px; gap: 7px; }
  #btn-compact { display: none; }
  .tb-group { flex: 1; }
  .tb { max-width: 44vw; }
  #chat { padding: 20px 12px 6px; }
  .msg { max-width: 96%; margin-bottom: 18px; }
  #subagent-panel { max-height: min(42dvh, 300px); padding: 7px 10px 8px; }
  .sa-root { width: 100%; }
  .sa-root-meta { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .sa-mode { display: none; }
  .sa-branch { margin-left: min(calc(8px + var(--sa-indent)), 104px); }
  .sa-name { max-width: 104px; }
  .sa-action { min-width: 50px; }
  .sa-detail { padding-left: 10px; }
  .sa-detail-row { grid-template-columns: 1fr; gap: 3px; }
  .sa-usage { padding-left: 0; }
  .composer-bar { padding: 2px 10px max(10px, env(safe-area-inset-bottom)); }
  #inputbar { padding: 10px 12px 2px; }
  .model-select { max-width: 48vw; }
  .schedules-head, .skills-head, .graphs-head, .kanban-head {
    flex-wrap: wrap; padding: 10px 12px; gap: 7px;
  }
  .schedules-body, .skills-body, .graphs-body { padding: 12px; }
  .sched-card, .graph-card { padding: 10px; }
  .sched-top, .graph-top { align-items: flex-start; flex-direction: column; gap: 4px; }
  .sched-actions { flex-direction: column; }
  .graph-body { padding-left: 0; }
  .kanban-board { gap: 12px; padding: 12px; scroll-snap-type: x mandatory; }
  .kanban-col {
    min-width: min(86vw, 340px); max-width: min(86vw, 340px);
    padding: 0 10px; scroll-snap-align: start;
  }
  #toasts { left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); align-items: stretch; }
  .toast { max-width: none; }
  .dlg { width: calc(100vw - 24px); max-height: calc(100dvh - 24px); padding: 18px; }
  .p-row .p-new, .p-row .p-del { opacity: 1; min-width: 40px; min-height: 40px; justify-content: center; }
  .p-row .p-open, .p-sessions .s-open { min-height: 40px; }
  .icon-btn, .tool-btn, .kb-actions button { min-width: 40px; min-height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
