/* ---------- Design tokens ---------- */
:root {
  --bg: #f3f5fb;
  --bg-elevated: #ffffff;
  --bg-soft: #eef1fa;
  --border: #e3e7f1;
  --text: #1c2333;
  --text-dim: #6b7284;
  --text-faint: #98a0b3;
  --primary: #4f6df5;
  --primary-dim: #e8ecfe;
  --primary-text: #ffffff;
  --success: #16a34a;
  --success-dim: #dcfce7;
  --warning: #d97706;
  --warning-dim: #fef3c7;
  --danger: #dc2626;
  --danger-dim: #fee2e2;
  --shadow-sm: 0 1px 2px rgba(20, 25, 50, 0.06);
  --shadow-md: 0 8px 24px rgba(20, 25, 50, 0.08);
  --shadow-lg: 0 16px 48px rgba(20, 25, 50, 0.16);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --sidebar-w: 264px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #10131c;
  --bg-elevated: #171b28;
  --bg-soft: #1c2131;
  --border: #262c40;
  --text: #eef1fb;
  --text-dim: #9aa1b8;
  --text-faint: #656d84;
  --primary: #6c85ff;
  --primary-dim: #232a4a;
  --primary-text: #ffffff;
  --success: #34d399;
  --success-dim: #123526;
  --warning: #fbbf24;
  --warning-dim: #3a2c0c;
  --danger: #f87171;
  --danger-dim: #3a1717;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
}
svg { width: 18px; height: 18px; fill: currentColor; flex-shrink: 0; }
button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
input, select, textarea, button { font-family: inherit; font-size: 14px; }

/* ---------- Layout ---------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 26px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #7b93ff);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; letter-spacing: .5px;
  box-shadow: var(--shadow-sm);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 11.5px; color: var(--text-faint); }
.brand-text-mobile { font-weight: 700; }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--text-dim); font-size: 14px; font-weight: 500;
  transition: background .15s ease, color .15s ease;
}
.nav-link:hover { background: var(--bg-soft); color: var(--text); }
.nav-link.active { background: var(--primary-dim); color: var(--primary); }
.nav-link svg { opacity: .9; }

.sidebar-footer { display: flex; flex-direction: column; gap: 10px; padding-top: 12px; border-top: 1px solid var(--border); }
.theme-toggle {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 12px; color: var(--text); font-size: 13px; font-weight: 500;
}
.theme-toggle:hover { background: var(--primary-dim); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 2px; }
.user-chip strong { display: block; font-size: 13px; }
.user-chip span { font-size: 11.5px; color: var(--text-faint); }

.avatar {
  --c: #4f6df5;
  width: 34px; height: 34px; border-radius: 50%;
  background: color-mix(in srgb, var(--c) 18%, transparent);
  color: var(--c);
  display: flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 700; flex-shrink: 0;
  border: 1.5px solid color-mix(in srgb, var(--c) 35%, transparent);
}
.avatar.sm { width: 26px; height: 26px; font-size: 10.5px; }
.avatar.lg { width: 52px; height: 52px; font-size: 16px; }

.mobile-bar { display: none; }
.sidebar-overlay { display: none; }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 24px 32px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.topbar-title h1 { margin: 0 0 4px; font-size: 22px; font-weight: 700; }
.topbar-title p { margin: 0; color: var(--text-dim); font-size: 13.5px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 12px; width: 280px;
}
.search-box svg { color: var(--text-faint); width: 16px; height: 16px; }
.search-box input { border: none; outline: none; background: transparent; color: var(--text); width: 100%; }
.search-box input::placeholder { color: var(--text-faint); }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; font-size: 13.5px; transition: all .15s ease; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: var(--primary-text); box-shadow: var(--shadow-sm); }
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--text-dim); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-soft); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-icon-only { padding: 9px; }

.icon-btn {
  background: transparent; border: none; color: var(--text-dim);
  padding: 6px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }

.view-container { padding: 28px 32px 60px; flex: 1; }
.view { display: none; animation: fadein .2s ease; }
.view.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Stat cards ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 26px; }
.stat-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 20px; box-shadow: var(--shadow-sm);
}
.stat-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.stat-icon {
  width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
}
.stat-icon svg { width: 19px; height: 19px; }
.stat-icon.blue { background: var(--primary-dim); color: var(--primary); }
.stat-icon.green { background: var(--success-dim); color: var(--success); }
.stat-icon.amber { background: var(--warning-dim); color: var(--warning); }
.stat-icon.red { background: var(--danger-dim); color: var(--danger); }
.stat-trend { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 20px; }
.stat-trend.up { background: var(--success-dim); color: var(--success); }
.stat-trend.down { background: var(--danger-dim); color: var(--danger); }
.stat-value { font-size: 28px; font-weight: 800; letter-spacing: -.5px; }
.stat-label { font-size: 13px; color: var(--text-dim); margin-top: 2px; }

.dash-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; align-items: start; }
.panel {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 22px; box-shadow: var(--shadow-sm);
}
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.panel-header h3 { margin: 0; font-size: 15.5px; }
.panel-header a, .panel-link { font-size: 13px; color: var(--primary); font-weight: 600; }

.mini-project-row { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.mini-project-row:last-child { border-bottom: none; }
.mini-project-row:hover .mini-project-name { color: var(--primary); }
.dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.mini-project-info { flex: 1; min-width: 0; }
.mini-project-name { font-weight: 600; font-size: 13.5px; transition: color .15s; }
.mini-project-client { font-size: 12px; color: var(--text-faint); }
.mini-progress-wrap { width: 100px; }
.progress-track { height: 6px; background: var(--bg-soft); border-radius: 6px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 6px; transition: width .3s ease; }
.progress-pct { font-size: 11px; color: var(--text-faint); margin-top: 4px; text-align: right; }

.activity-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.activity-item:last-child { border-bottom: none; }
.activity-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.activity-text { font-size: 13px; line-height: 1.5; }
.activity-text b { font-weight: 600; }
.activity-time { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }

.workload-row { display: flex; align-items: center; gap: 12px; padding: 9px 0; }
.workload-name { width: 110px; font-size: 12.5px; font-weight: 600; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workload-bar-track { flex: 1; height: 8px; background: var(--bg-soft); border-radius: 8px; overflow: hidden; }
.workload-bar-fill { height: 100%; border-radius: 8px; background: linear-gradient(90deg, var(--primary), #8ba0ff); }
.workload-count { font-size: 12px; color: var(--text-faint); width: 20px; text-align: right; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.filter-pill {
  padding: 7px 14px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--bg-elevated); font-size: 12.5px; font-weight: 600; color: var(--text-dim);
}
.filter-pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.filter-pill:hover:not(.active) { background: var(--bg-soft); }
.toolbar .spacer { flex: 1; }
.view-toggle { display: flex; background: var(--bg-soft); border-radius: 10px; padding: 3px; border: 1px solid var(--border); }
.view-toggle button { padding: 6px 10px; border: none; background: transparent; border-radius: 7px; color: var(--text-dim); display: flex; }
.view-toggle button.active { background: var(--bg-elevated); color: var(--primary); box-shadow: var(--shadow-sm); }

/* ---------- Project cards ---------- */
.projects-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.project-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 20px; box-shadow: var(--shadow-sm); cursor: pointer; transition: transform .15s ease, box-shadow .15s ease;
  display: flex; flex-direction: column; gap: 14px;
}
.project-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.project-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.project-badge { width: 42px; height: 42px; border-radius: 11px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 15px; flex-shrink: 0; }
.badge {
  font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 20px; text-transform: uppercase; letter-spacing: .3px;
}
.badge-planung { background: var(--bg-soft); color: var(--text-dim); }
.badge-aktiv { background: var(--success-dim); color: var(--success); }
.badge-pausiert { background: var(--warning-dim); color: var(--warning); }
.badge-abgeschlossen { background: var(--primary-dim); color: var(--primary); }
.priority-flag { font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; gap: 4px; }
.priority-hoch { color: var(--danger); }
.priority-mittel { color: var(--warning); }
.priority-niedrig { color: var(--text-faint); }

.project-card h3 { margin: 0; font-size: 16px; }
.project-card .client { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }
.project-desc { font-size: 13px; color: var(--text-dim); line-height: 1.5; flex: 1; }
.project-card-meta { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--text-faint); }
.project-team-avatars { display: flex; }
.project-team-avatars .avatar { margin-left: -8px; border: 2px solid var(--bg-elevated); }
.project-team-avatars .avatar:first-child { margin-left: 0; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-faint); }
.empty-state svg { width: 48px; height: 48px; opacity: .4; margin-bottom: 12px; }
.empty-state h3 { color: var(--text-dim); margin: 0 0 6px; }

/* ---------- Kanban board ---------- */
.board-project-select { margin-bottom: 20px; }
.board-project-select select {
  padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text); font-weight: 600; min-width: 280px;
}
.kanban { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; align-items: start; }
.kanban-col {
  background: var(--bg-soft); border-radius: var(--radius-md); padding: 14px;
  min-height: 200px; border: 1px solid var(--border);
}
.kanban-col.drag-over { outline: 2px dashed var(--primary); outline-offset: -4px; background: var(--primary-dim); }
.kanban-col-header { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 14px; }
.kanban-col-title { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--text-dim); }
.kanban-count { background: var(--bg-elevated); border-radius: 20px; font-size: 11.5px; padding: 2px 8px; color: var(--text-faint); font-weight: 700; }
.kanban-col-dot { width: 9px; height: 9px; border-radius: 50%; }
.dot-todo { background: #94a3b8; }
.dot-progress { background: #3b82f6; }
.dot-review { background: #f59e0b; }
.dot-done { background: #22c55e; }

.task-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 13px 14px; margin-bottom: 10px; cursor: grab; box-shadow: var(--shadow-sm);
  transition: transform .12s ease, box-shadow .12s ease;
}
.task-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.task-card.dragging { opacity: .4; }
.task-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.task-priority-dot { width: 7px; height: 7px; border-radius: 50%; }
.task-card h4 { margin: 0 0 8px; font-size: 13.5px; font-weight: 600; line-height: 1.4; }
.task-card-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.task-due { font-size: 11.5px; color: var(--text-faint); display: flex; align-items: center; gap: 4px; }
.task-due.overdue { color: var(--danger); font-weight: 700; }
.task-due svg { width: 12px; height: 12px; }
.task-project-tag { font-size: 10.5px; color: var(--text-faint); background: var(--bg-soft); padding: 2px 7px; border-radius: 6px; margin-bottom: 6px; display: inline-block; }
.add-task-btn {
  width: 100%; padding: 9px; border: 1.5px dashed var(--border); border-radius: var(--radius-sm);
  background: transparent; color: var(--text-faint); font-size: 12.5px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 4px;
}
.add-task-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-dim); }

/* ---------- Project detail header (on board view) ---------- */
.project-detail-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 20px 22px; margin-bottom: 20px;
}
.project-detail-left { display: flex; align-items: center; gap: 16px; }
.project-detail-stats { display: flex; gap: 24px; }
.pd-stat { text-align: center; }
.pd-stat strong { display: block; font-size: 18px; }
.pd-stat span { font-size: 11px; color: var(--text-faint); }

/* ---------- Team grid ---------- */
.team-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.team-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 22px; text-align: center; box-shadow: var(--shadow-sm);
}
.team-card .avatar { margin: 0 auto 12px; }
.team-card h3 { margin: 0 0 2px; font-size: 15px; }
.team-card .role { font-size: 12.5px; color: var(--text-faint); margin-bottom: 14px; }
.team-card-stats { display: flex; justify-content: center; gap: 20px; border-top: 1px solid var(--border); padding-top: 14px; }
.team-card-stats div strong { display: block; font-size: 16px; }
.team-card-stats div span { font-size: 11px; color: var(--text-faint); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 13, 25, .55); backdrop-filter: blur(2px);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-backdrop.open { display: flex; animation: fadein .15s ease; }
.modal {
  background: var(--bg-elevated); border-radius: var(--radius-lg); width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); border: 1px solid var(--border);
}
.modal-sm { max-width: 400px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-elevated); }
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 22px; }
.form-row { margin-bottom: 15px; display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: 12.5px; font-weight: 600; color: var(--text-dim); }
.form-row input, .form-row select, .form-row textarea {
  padding: 10px 12px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); outline: none; resize: vertical;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { border-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-footer { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.modal-footer .spacer { flex: 1; }

.chip-select { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-option {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 20px;
  border: 1.5px solid var(--border); font-size: 12.5px; font-weight: 600; color: var(--text-dim);
}
.chip-option.selected { border-color: var(--primary); background: var(--primary-dim); color: var(--primary); }
.color-select { display: flex; gap: 10px; }
.color-swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.color-swatch.selected { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg-elevated); }

/* ---------- Toasts ---------- */
.toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 12px;
  padding: 13px 18px; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px;
  font-size: 13.5px; font-weight: 600; animation: toast-in .2s ease; min-width: 240px;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
  .projects-grid { grid-template-columns: repeat(2, 1fr); }
  .team-grid { grid-template-columns: repeat(2, 1fr); }
  .kanban { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 60; transform: translateX(-100%);
    transition: transform .25s ease; width: 260px;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 55; }
  .sidebar-overlay.open { display: block; }
  .mobile-bar {
    display: flex; align-items: center; gap: 14px; padding: 14px 18px;
    border-bottom: 1px solid var(--border); background: var(--bg-elevated); position: sticky; top: 0; z-index: 20;
  }
  .mobile-bar button { background: transparent; border: none; color: var(--text); padding: 4px; }
  .topbar { flex-wrap: wrap; padding: 18px; }
  .search-box { width: 100%; order: 3; }
  .view-container { padding: 18px; }
  .stats-grid { grid-template-columns: 1fr; }
  .projects-grid { grid-template-columns: 1fr; }
  .team-grid { grid-template-columns: 1fr; }
  .kanban { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
