:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1b1f24; --muted: #6b7280; --line: #e3e6ea;
  --accent: #1f5fbf; --accent-bg: #e8f0fc; --danger: #b42318; --ok: #157347; --warn: #b7791f;
  --chip: #eef0f3; --chip-on: #1b1f24; --chip-on-text: #fff;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1216; --panel: #171b21; --text: #e6e8eb; --muted: #9aa3ad; --line: #2a3038; --accent: #7aa7ff; --accent-bg: #1c2a44; --chip: #232932; --chip-on: #e6e8eb; --chip-on-text: #0f1216; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
button, input { font: inherit; color: inherit; }
.muted { color: var(--muted); font-weight: normal; }
.inline { display: inline; }

.top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 17px; }
.status { flex: 1; color: var(--muted); font-size: 13px; }
.status.err { color: var(--danger); }
.top-actions { display: flex; gap: 8px; align-items: center; }

.btn { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 6px 12px; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

.filters { display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 10px 16px; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { background: var(--chip); border: 0; border-radius: 999px; padding: 3px 10px; cursor: pointer; font-size: 12.5px; }
.chip.on { background: var(--chip-on); color: var(--chip-on-text); }
.chip .n { opacity: .6; margin-left: 4px; }
#search { flex: 1; min-width: 220px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }

.bulk { display: flex; gap: 8px; align-items: center; padding: 8px 16px; background: var(--accent-bg); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }

main { padding: 0 16px 40px; overflow-x: auto; }
.grid { width: 100%; min-width: 1180px; table-layout: fixed; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.grid th, .grid td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; overflow: hidden; text-overflow: ellipsis; }
.grid th { font-size: 12px; color: var(--muted); font-weight: 600; cursor: pointer; user-select: none; white-space: nowrap; background: var(--panel); }
.grid th.sorted::after { content: " ▾"; }
.grid th.sorted.asc::after { content: " ▴"; }
.grid tr.item { cursor: pointer; }
.grid tr.item:hover { background: var(--bg); }
.grid tr.item.unread .c-subject { font-weight: 600; }
.grid tr.item.selected { background: var(--accent-bg); }
.c-check { width: 28px; }
.c-src { width: 46px; white-space: nowrap; }
.c-src .src + .src { margin-left: 2px; }
.c-date { width: 92px; white-space: nowrap; color: var(--muted); }
.c-from { width: 170px; white-space: nowrap; }
.c-subject { white-space: nowrap; }
.c-theme, .c-role { width: 110px; white-space: nowrap; }
.c-prio { width: 56px; }
.c-min { width: 44px; text-align: right; color: var(--muted); }
.c-due { width: 130px; white-space: nowrap; font-size: 12.5px; }
.c-actions { width: 190px; white-space: nowrap; text-align: right; overflow: visible; }
tr.detail td { overflow: visible; white-space: normal; }
.c-actions .btn { margin-left: 3px; }

.tag { display: inline-block; padding: 1px 7px; border-radius: 4px; font-size: 11.5px; background: var(--chip); }
.tag.prio-hoch { background: #fde2e1; color: #8a1c13; }
.tag.prio-mittel { background: #fff1d6; color: #7a4e00; }
.tag.prio-niedrig { background: #e3f1e8; color: #1d5c37; }
@media (prefers-color-scheme: dark) {
  .tag.prio-hoch { background: #4a1d1a; color: #ffb4ad; }
  .tag.prio-mittel { background: #4a3410; color: #ffd38a; }
  .tag.prio-niedrig { background: #15351f; color: #9fe0b5; }
}
.tag.role-bearbeiter { background: var(--accent-bg); color: var(--accent); }
.src { display: inline-block; width: 18px; height: 18px; line-height: 18px; text-align: center; border-radius: 4px; font-size: 11px; font-weight: 700; color: #fff; }
.src.mail { background: #2b6cb0; }
.src.monday { background: #ff3d57; }
.due-over { color: var(--danger); font-weight: 600; }
.due-today { color: var(--warn); font-weight: 600; }

tr.detail td { background: var(--bg); padding: 12px 16px 14px 44px; cursor: default; }
.detail-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
.detail h4 { margin: 0 0 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.detail p { margin: 0 0 10px; }
.detail .preview { white-space: pre-wrap; max-height: 260px; overflow: auto; font-size: 13px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 8px; }
.detail .links a { margin-right: 12px; color: var(--accent); }
.note-form { display: grid; gap: 6px; }
.note-form input, .note-form textarea, .note-form select { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.note-form textarea { min-height: 60px; resize: vertical; }
.note-row { display: flex; gap: 6px; align-items: center; }
.note-row label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.classify { display: flex; gap: 6px; flex-wrap: wrap; }
.classify select { width: auto; }

.empty { text-align: center; color: var(--muted); padding: 40px; }

dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); max-width: 640px; width: 90vw; padding: 0; }
dialog::backdrop { background: rgba(0,0,0,.4); }
.dlg { padding: 18px 20px; }
.dlg h2 { margin: 0 0 12px; font-size: 16px; }
.dlg h3 { margin: 14px 0 4px; font-size: 13px; color: var(--muted); }
.dlg .row { display: flex; gap: 8px; align-items: center; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
#prompt-input { width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.rules { list-style: none; padding: 0; margin: 0; }
.rules li { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.rules button { background: none; border: 0; color: var(--danger); cursor: pointer; }
.log { font-size: 11.5px; max-height: 160px; overflow: auto; background: var(--bg); padding: 8px; border-radius: 6px; }

.login-body { display: grid; place-items: center; min-height: 100vh; }
.login { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 24px; width: 320px; display: grid; gap: 10px; }
.login label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.login input { padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.login-error { color: var(--danger); margin: 0; min-height: 1em; }

@media (max-width: 700px) {
  .grid { min-width: 760px; }
  .c-theme, .c-role, .c-min, .c-from { display: none; }
}

/* ---- Vorgänge, GitHub, Zeitleiste ---- */
.src.github { background: #24292f; }
.src.case { background: transparent; color: var(--text); font-size: 13px; }
.sources .n { font-size: 11px; color: var(--muted); margin-right: 4px; }
.grid tr.case { cursor: pointer; background: color-mix(in srgb, var(--accent-bg) 45%, var(--panel)); }
.grid tr.case:hover { background: var(--accent-bg); }
.grid tr.case.open td { border-bottom-color: transparent; }
.grid tr.item.child td { background: var(--bg); }
.grid tr.item.child .c-subject { padding-left: 18px; }
.grid tr.item.open .c-subject { font-weight: 600; }
.badge { display: inline-block; background: var(--accent); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 11px; vertical-align: middle; }
.timeline { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow: auto; }
.timeline li { padding: 3px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.timeline .src { width: 15px; height: 15px; line-height: 15px; font-size: 10px; }
.checklist { list-style: none; margin: 0 0 6px; padding: 0; }
.checklist li { display: flex; justify-content: space-between; padding: 2px 0; }
.checklist .done { text-decoration: line-through; color: var(--muted); }
.checklist .x { background: none; border: 0; color: var(--muted); cursor: pointer; }
.case-select, .dlg select, #case-title { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.dlg label { display: block; font-size: 12px; color: var(--muted); }
.comments .comment { border-top: 1px solid var(--line); padding: 6px 0; font-size: 13px; white-space: pre-wrap; max-height: 160px; overflow: auto; }
.note-row select { width: auto; }

/* ---- KPI-Kacheln ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; padding: 12px 16px 2px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.kpi-n { font-size: 24px; font-weight: 700; line-height: 1.1; }
.kpi-l { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.alert { border-color: var(--danger); }
.kpi.alert .kpi-n { color: var(--danger); }

/* ---- Zu prüfen, Schritte ---- */
.btn.accept { background: var(--ok); }
.tag.stage { background: #e9e3ff; color: #3b2a8a; }
@media (prefers-color-scheme: dark) { .tag.stage { background: #2b2250; color: #cfc2ff; } }
.kpi.clickable { cursor: pointer; }
.kpi.clickable:hover { border-color: var(--accent); }
#set-stages { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); }
