:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --brand: #2563eb;
  --brand-ink: #1d4ed8;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --slate-bg: #f8fafc;
  --red: #dc2626;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 12px rgba(15,23,42,.06);
  --shadow-lg: 0 8px 30px rgba(15,23,42,.18);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  border-radius: 9px;
  padding: 8px 13px;
  font-size: 13.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: .12s;
}
.btn:hover { background: var(--slate-bg); border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(15,23,42,.06); }
.btn.danger { color: var(--red); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.sm { padding: 5px 9px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 500px at 10% -10%, #dbeafe 0%, transparent 60%),
    radial-gradient(1000px 500px at 110% 110%, #e0e7ff 0%, transparent 55%),
    var(--bg);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 34px 30px;
}
.login-logo {
  width: 52px; height: 52px; border-radius: 14px;
  background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 26px;
  margin-bottom: 18px;
}
.login-card h1 { margin: 0 0 4px; font-size: 21px; }
.login-card p.sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field select, .field input, .field textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line-strong); border-radius: 10px;
  background: #fff; color: var(--ink);
}
.field select:focus, .field input:focus, .field textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37,99,235,.14);
}
.login-error { color: var(--red); font-size: 13px; margin: 4px 0 12px; min-height: 16px; }

/* ---------- App shell ---------- */
.topbar {
  height: 58px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px;
  padding: 0 18px;
  position: sticky; top: 0; z-index: 20;
}
.topbar .logo {
  width: 34px; height: 34px; border-radius: 9px; background: var(--brand);
  color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 18px;
}
.topbar .title { font-weight: 700; font-size: 16px; }
.topbar .spacer { flex: 1; }
.topbar .who { display: flex; align-items: center; gap: 9px; font-size: 13.5px; color: var(--muted); }

.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: inline-grid; place-items: center;
  color: #fff; font-size: 11.5px; font-weight: 700; flex: none;
}
.avatar.lg { width: 30px; height: 30px; font-size: 12.5px; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 4px; align-items: center;
  padding: 12px 18px 0;
  overflow-x: auto;
}
.tab {
  border: 1px solid transparent;
  background: transparent;
  padding: 9px 15px;
  border-radius: 10px 10px 0 0;
  font-size: 14px; font-weight: 600; color: var(--muted);
  white-space: nowrap;
  display: flex; align-items: center; gap: 8px;
}
.tab:hover { background: rgba(15,23,42,.05); color: var(--ink); }
.tab.active { background: var(--panel); color: var(--ink); border-color: var(--line); border-bottom-color: var(--panel); }
.tab .count {
  font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px;
  background: var(--line); color: var(--muted);
}
.tab.active .count.done { background: var(--green-bg); color: var(--green); }
.tab .mini-bar { width: 42px; height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.tab .mini-bar > i { display: block; height: 100%; background: var(--green); }

/* ---------- Board ---------- */
.board-head {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.board-head h2 { margin: 0; font-size: 18px; }
.board-head .meta { color: var(--muted); font-size: 13px; }
.progress {
  height: 8px; width: 220px; border-radius: 5px; background: var(--line); overflow: hidden;
}
.progress > i { display: block; height: 100%; background: linear-gradient(90deg,#22c55e,#16a34a); transition: width .3s; }

.legend { display: flex; gap: 14px; align-items: center; color: var(--muted); font-size: 12.5px; flex-wrap: wrap; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px; vertical-align: -1px; }

.canvas-wrap { position: relative; overflow: auto; padding: 26px; }
.canvas { position: relative; }
.threads { position: absolute; top: 0; left: 0; pointer-events: none; overflow: visible; z-index: 1; }

/* ---------- Task tile ---------- */
.tile {
  position: absolute; z-index: 2;
  width: 232px; min-height: 118px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 5px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 13px 11px;
  display: flex; flex-direction: column; gap: 8px;
  transition: box-shadow .15s, transform .15s, border-color .15s;
}
.tile:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.tile.s-offen { border-left-color: var(--line-strong); }
.tile.s-in_arbeit { border-left-color: var(--amber); background: linear-gradient(0deg,#fffdf7,#fff); }
.tile.s-erledigt { border-left-color: var(--green); background: linear-gradient(0deg,#f4fdf7,#fff); }
/* fehlende Voraussetzungen -> rötlich */
.tile.blocked { border-left-color: var(--red); background: linear-gradient(0deg,#fff5f5,#fff); border-color: #fecaca; }
/* startklar -> blau, deutlich abgesetzt von grün=erledigt */
.tile.ready.s-offen {
  border-left-color: var(--brand); border-color: #bfdbfe;
  background: linear-gradient(0deg,#eff6ff,#fff);
  box-shadow: 0 0 0 1px rgba(37,99,235,.10), var(--shadow);
}

.tile .t-flag {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 4px; width: max-content;
}
.tile .t-flag.blocked { background: #fee2e2; color: #b91c1c; }
.tile .t-flag.ready { background: var(--brand); color: #fff; letter-spacing: .02em; }

/* Drag-Griff */
.tile .t-handle {
  position: absolute; top: 6px; right: 8px; z-index: 3;
  cursor: grab; color: var(--line-strong); font-size: 14px; line-height: 1;
  padding: 2px 4px; border-radius: 5px; opacity: 0; transition: opacity .12s;
  user-select: none;
}
.tile:hover .t-handle { opacity: 1; }
.tile .t-handle:hover { color: var(--muted); background: var(--slate-bg); }
.tile .t-handle:active { cursor: grabbing; }
.tile.dragging { opacity: .4; }
/* Einfüge-Anzeige (wohin die Kachel beim Loslassen springt) */
.drop-indicator {
  position: absolute; z-index: 4; width: 232px; height: 4px;
  background: var(--brand); border-radius: 3px; pointer-events: none;
  box-shadow: 0 0 0 4px rgba(37,99,235,.18);
}
.drop-indicator::before, .drop-indicator::after {
  content: ""; position: absolute; top: -3px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--brand);
}
.drop-indicator::before { left: -4px; }
.drop-indicator::after { right: -4px; }

.tile .t-title {
  font-size: 14px; font-weight: 700; line-height: 1.25; padding-right: 22px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tile.s-erledigt .t-title { color: #166534; }
.tile .t-row { display: flex; align-items: center; gap: 8px; margin-top: auto; }
.tile .t-status {
  font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 5px;
}
.t-status.offen { background: var(--slate-bg); color: var(--muted); border: 1px solid var(--line); }
.t-status.in_arbeit { background: var(--amber-bg); color: #92400e; }
.t-status.erledigt { background: var(--green-bg); color: #166534; }
.tile .t-done-at { font-size: 11px; color: var(--green); font-weight: 600; }
.tile .t-last-ticket {
  font-size: 11.5px; color: var(--muted); background: var(--slate-bg);
  border: 1px solid var(--line); border-radius: 7px; padding: 3px 7px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile .t-tickets {
  font-size: 11px; font-weight: 700; color: var(--muted);
  background: var(--slate-bg); border: 1px solid var(--line);
  border-radius: 999px; padding: 2px 7px;
}
.tile .t-assignee { margin-left: auto; }
.tile .add-assignee {
  width: 26px; height: 26px; border-radius: 50%; border: 1.5px dashed var(--line-strong);
  color: var(--muted); background: #fff; font-size: 15px; line-height: 1; display: grid; place-items: center;
}
.tile .add-assignee:hover { border-color: var(--brand); color: var(--brand); }

/* ---------- Overview ---------- */
.overview { padding: 22px; display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.ov-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.ov-card h3 { margin: 0 0 3px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.ov-card .ov-meta { color: var(--muted); font-size: 12.5px; margin-bottom: 12px; }
.ov-pct { font-size: 13px; font-weight: 700; margin-left: auto; color: var(--green); }
.ov-next { font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.ov-next b { color: var(--ink); }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; background: var(--slate-bg);
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; margin: 3px 4px 0 0; }
.chip.blocked { opacity: .6; }

/* ---------- Personenansicht ---------- */
.person-card.me { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(37,99,235,.12), var(--shadow); }
.person-card.unassigned { border-style: dashed; border-color: var(--line-strong); background: #fffdf9; }
.person-card h3 { align-items: center; }
.person-counts { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.pc { font-size: 11.5px; font-weight: 700; padding: 2px 9px; border-radius: 999px; }
.pc-arbeit { background: var(--amber-bg); color: #92400e; }
.pc-ready { background: #dbeafe; color: var(--brand-ink); }
.pc-block { background: #fee2e2; color: #b91c1c; }
.pc-done { background: var(--green-bg); color: #166534; }
.ptask-list { display: flex; flex-direction: column; gap: 5px; max-height: 340px; overflow: auto; }
.ptask { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; transition: .1s; }
.ptask:hover { background: var(--slate-bg); border-color: var(--line-strong); }
.ptask-loc { font-size: 11px; font-weight: 700; color: var(--muted); background: var(--slate-bg); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; flex: none; min-width: 62px; text-align: center; }
.ptask-title { flex: 1; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ptask-title.done { color: var(--muted); text-decoration: line-through; font-weight: 500; }
.ptask .t-status { flex: none; }
.mini-flag { flex: none; font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px; white-space: nowrap; }
.mini-flag.ready { background: var(--brand); color: #fff; }
.mini-flag.blocked { background: #fee2e2; color: #b91c1c; }

/* ---------- Modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: grid; place-items: center; z-index: 100; padding: 20px;
  animation: fade .12s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--panel); border-radius: 18px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 480px; max-height: 88vh; overflow: auto;
  animation: pop .14s ease;
}
.modal.wide { max-width: 640px; }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: .6; } }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-head .x { margin-left: auto; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

.status-picker { display: flex; gap: 8px; }
.status-picker button {
  flex: 1; padding: 10px; border-radius: 10px; border: 1.5px solid var(--line-strong);
  background: #fff; font-weight: 600; font-size: 13px;
}
.status-picker button.sel.offen { border-color: var(--muted); background: var(--slate-bg); }
.status-picker button.sel.in_arbeit { border-color: var(--amber); background: var(--amber-bg); color: #92400e; }
.status-picker button.sel.erledigt { border-color: var(--green); background: var(--green-bg); color: #166534; }

.assignee-list { display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow: auto; }
.assignee-opt { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; border: 1px solid transparent; }
.assignee-opt:hover { background: var(--slate-bg); }
.assignee-opt.sel { border-color: var(--brand); background: #eff6ff; }

.dep-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.dep-check { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; }

.list-row { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: none; }
.list-row .grow { flex: 1; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13.5px; box-shadow: var(--shadow-lg); z-index: 200; animation: fade .15s;
}
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---------- Arbeitstickets ---------- */
.ticket-add { display: flex; gap: 8px; }
.ticket-add input { flex: 1; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 9px; }
.ticket-add input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37,99,235,.14); }
.ticket-add .btn { flex: none; white-space: nowrap; }
.ticket-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow: auto; }
.ticket-item { display: flex; gap: 10px; align-items: flex-start; padding: 9px 10px; background: var(--slate-bg); border: 1px solid var(--line); border-radius: 10px; }
.ticket-badge { width: 26px; height: 26px; border-radius: 7px; color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; flex: none; }
.ticket-body { flex: 1; min-width: 0; }
.ticket-meta { font-size: 11.5px; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
.ticket-text { font-size: 13.5px; line-height: 1.35; white-space: pre-wrap; word-break: break-word; }
.ticket-item > .btn { flex: none; padding: 4px 7px; }
.ticket-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; align-items: center; }
.file-chip { display: inline-flex; align-items: center; gap: 2px; background: #fff; border: 1px solid var(--line-strong); border-radius: 7px; font-size: 12px; overflow: hidden; }
.file-open { padding: 4px 8px; cursor: pointer; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--brand-ink); font-weight: 600; }
.file-open:hover { background: #eff6ff; }
.file-x { border: none; background: transparent; color: var(--muted); padding: 4px 7px; font-size: 12px; cursor: pointer; }
.file-x:hover { color: var(--red); background: #fef2f2; }
.add-file { font-size: 12px; padding: 4px 8px; }
