:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --border: #e4e7f0;
  --text: #111827;
  --text-2: #4b5563;
  --muted: #8a93a6;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: #d97706;
  --success: #059669;
  --success-soft: #ecfdf5;
  --sidebar: #12141f;
  --sidebar-text: #a7adc2;
  --sidebar-active: #22253a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-lg: 0 20px 50px -12px rgba(16, 24, 40, .25);
  --s-todo: #64748b;
  --s-in_progress: #2563eb;
  --s-review: #d97706;
  --s-done: #059669;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 15px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- Boutons & champs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: #fecaca; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: default; }
.btn svg { width: 16px; height: 16px; }

.input, select.input, textarea.input {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  outline: none; transition: border-color .12s, box-shadow .12s;
}
textarea.input { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, .15); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text-2); }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }
.error-msg { color: var(--danger); background: var(--danger-soft); padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }

/* ---------- Connexion ---------- */
.login {
  min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr;
}
.login-brand {
  background: radial-gradient(1200px 600px at -10% -10%, #4f46e5 0%, #1e1b4b 55%, #0b0b1a 100%);
  color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
}
.login-brand h1 { font-size: 36px; line-height: 1.15; max-width: 460px; margin-top: 48px; }
.login-brand p { color: #c7c9f5; max-width: 440px; line-height: 1.6; font-size: 15px; }
.login-brand ul { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; color: #e0e1ff; }
.login-brand li { display: flex; gap: 10px; align-items: center; }
.login-brand li svg { width: 18px; height: 18px; color: #a5b4fc; flex: none; }
.login-panel { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.login-card { width: 100%; max-width: 400px; }
.login-card h2 { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.login-card form { margin-top: 24px; }
.login-card .btn-primary { width: 100%; justify-content: center; height: 42px; }
.demo-box { margin-top: 28px; border: 1px dashed var(--border); border-radius: var(--radius); padding: 14px; background: var(--surface); }
.demo-box h3 { font-size: 13px; margin-bottom: 4px; }
.demo-accounts { display: grid; gap: 4px; margin-top: 10px; max-height: 240px; overflow: auto; }
.demo-account {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px;
  border: 0; background: none; text-align: left; cursor: pointer; width: 100%;
}
.demo-account:hover { background: var(--surface-2); }
.demo-account .who { flex: 1; min-width: 0; }
.demo-account .who div:first-child { font-weight: 500; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-logo { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; flex: none; }
.brand-logo svg { width: 18px; height: 18px; color: #fff; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-text); padding: 18px 12px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { color: #fff; padding: 4px 8px 18px; }
.sidebar .brand small { display: block; font-weight: 500; font-size: 11px; color: var(--sidebar-text); }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--sidebar-text); font-weight: 500; cursor: pointer;
}
.nav-link:hover { background: var(--sidebar-active); color: #fff; }
.nav-link.active { background: var(--sidebar-active); color: #fff; }
.nav-link svg { width: 18px; height: 18px; flex: none; }
.nav-link .count { margin-left: auto; font-size: 11px; background: #2d3150; color: #d6d9ef; padding: 1px 7px; border-radius: 10px; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #6b7190; padding: 18px 10px 6px; font-weight: 600; }
.nav-dot { width: 9px; height: 9px; border-radius: 3px; flex: none; margin: 0 4.5px; }
.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid #23263a; }
.me-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; cursor: pointer; color: #fff; }
.me-chip:hover { background: var(--sidebar-active); }
.me-chip .meta { min-width: 0; flex: 1; }
.me-chip .meta div:last-child { font-size: 12px; color: var(--sidebar-text); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; display: flex; align-items: center; gap: 12px; padding: 0 28px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.search { position: relative; flex: 1; max-width: 420px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.search input { padding-left: 34px; background: var(--surface-2); border-color: transparent; }
.menu-btn { display: none; }
.content { padding: 28px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 6px 0 0; color: var(--text-2); }

/* ---------- Cartes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-body { padding: 16px; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.kpis { grid-template-columns: repeat(4, 1fr); margin-bottom: 16px; }
.kpi { padding: 16px; }
.kpi .label { color: var(--text-2); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.kpi .label svg { width: 16px; height: 16px; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 8px; letter-spacing: -.02em; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.alert .value { color: var(--danger); }
.dash { grid-template-columns: 1.6fr 1fr; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* ---------- Avatars, badges ---------- */
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  color: #fff; font-size: 11px; font-weight: 600; letter-spacing: .02em;
}
.avatar.sm { width: 22px; height: 22px; font-size: 9px; }
.avatar.lg { width: 40px; height: 40px; font-size: 14px; }
.avatar.empty-av { background: var(--surface-2); color: var(--muted); border: 1px dashed #cbd2e1; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; }
.status-todo { background: #f1f5f9; color: #475569; }
.status-in_progress { background: #eff6ff; color: #1d4ed8; }
.status-review { background: #fffbeb; color: #b45309; }
.status-done { background: #ecfdf5; color: #047857; }
.prio { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 500; }
.prio svg { width: 14px; height: 14px; }
.prio-urgent { color: #dc2626; }
.prio-high { color: #ea580c; }
.prio-medium { color: #2563eb; }
.prio-low { color: #64748b; }
.role-admin { background: #eef0ff; color: #4338ca; }
.role-manager { background: #fdf4ff; color: #a21caf; }
.role-member { background: #f1f5f9; color: #475569; }
.due { font-size: 12px; color: var(--text-2); display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.due svg { width: 13px; height: 13px; }
.due.overdue { color: var(--danger); font-weight: 600; }
.due.soon { color: var(--warning); font-weight: 500; }
.task-key { font-size: 12px; color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Listes de tâches ---------- */
.task-list { list-style: none; margin: 0; padding: 0; }
.task-row {
  display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.task-row:last-child { border-bottom: 0; }
.task-row:hover { background: #fafbff; }
.task-row .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.task-row.is-done .title { color: var(--muted); text-decoration: line-through; }
.check {
  width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid #c3c9d8; background: none; padding: 0; cursor: pointer; flex: none;
  display: grid; place-items: center; color: transparent;
}
.check:hover { border-color: var(--success); color: var(--success); }
.check.on { background: var(--success); border-color: var(--success); color: #fff; }
.check svg { width: 11px; height: 11px; }
.group-title { padding: 10px 16px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); background: var(--surface-2); border-bottom: 1px solid var(--border); display: flex; gap: 8px; }
.group-title.danger { color: var(--danger); }
.project-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); white-space: nowrap; }
.project-tag i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* ---------- Activité ---------- */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); line-height: 1.45; }
.feed li:last-child { border-bottom: 0; }
.feed .text { flex: 1; min-width: 0; color: var(--text-2); }
.feed .text b { color: var(--text); font-weight: 600; }
.feed .text a { cursor: pointer; font-weight: 500; }
.feed .when { font-size: 12px; color: var(--muted); margin-top: 2px; }
.quote { color: var(--text-2); font-style: italic; }

/* ---------- Projets ---------- */
.projects { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.project-card { padding: 18px; cursor: pointer; position: relative; overflow: hidden; transition: border-color .12s, transform .12s; }
.project-card:hover { border-color: #c7cbe0; }
.project-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--c); }
.project-card h3 { font-size: 16px; margin: 6px 0; }
.project-card p { color: var(--text-2); margin: 0 0 16px; line-height: 1.5; font-size: 13px; min-height: 39px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.progress { height: 6px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.progress > div { height: 100%; background: var(--c, var(--primary)); border-radius: 6px; }
.project-stats { display: flex; justify-content: space-between; margin-top: 12px; font-size: 12px; color: var(--text-2); }
.proj-progress-row { display: grid; grid-template-columns: 1fr 120px 42px; align-items: center; gap: 12px; padding: 10px 16px; cursor: pointer; }
.proj-progress-row:hover { background: #fafbff; }
.archived-tag { position: absolute; top: 14px; right: 14px; }

/* ---------- Graphiques simples ---------- */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding: 8px 4px 0; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars .bar > div { width: 100%; max-width: 26px; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.bars .bar > div.zero { background: var(--border); }
.bars .bar span { font-size: 10px; color: var(--muted); }
.bar-x { display: flex; gap: 6px; padding: 6px 4px 0; }
.bar-x span { flex: 1; text-align: center; font-size: 10px; color: var(--muted); }
.workload-row { display: grid; grid-template-columns: 22px 1fr 1.2fr 24px; gap: 10px; align-items: center; padding: 6px 0; font-size: 13px; }
.status-split { display: flex; height: 10px; border-radius: 6px; overflow: hidden; margin: 6px 0 12px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* ---------- Kanban ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .input { width: auto; min-width: 160px; height: 34px; }
.toolbar .search-small { min-width: 220px; }
.board { display: grid; grid-template-columns: repeat(4, minmax(250px, 1fr)); gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.column { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 300px; display: flex; flex-direction: column; transition: background .12s, box-shadow .12s; }
.column.drag-over { background: var(--primary-soft); box-shadow: inset 0 0 0 2px #c7d2fe; }
.column-head { display: flex; align-items: center; gap: 8px; padding: 4px 6px 12px; font-weight: 600; }
.column-head .count { color: var(--muted); font-weight: 500; }
.column-head .dot { width: 9px; height: 9px; border-radius: 50%; }
.column-head .btn { margin-left: auto; }
.column-cards { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.kcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 12px;
  box-shadow: var(--shadow); cursor: grab; transition: box-shadow .12s, border-color .12s;
}
.kcard:hover { border-color: #c7cbe0; box-shadow: 0 4px 12px -4px rgba(16, 24, 40, .12); }
.kcard.dragging { opacity: .5; }
.kcard .title { font-weight: 500; line-height: 1.4; margin: 4px 0 10px; word-wrap: break-word; }
.kcard .meta { display: flex; align-items: center; gap: 10px; }
.kcard .meta .spacer { flex: 1; }
.kcard .comments { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; color: var(--muted); }
.kcard .comments svg { width: 13px; height: 13px; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-2); padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.inactive td { opacity: .55; }
.person { display: flex; align-items: center; gap: 10px; }
.person .n { font-weight: 500; }

/* ---------- Modale ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 18, 35, .45); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow-y: auto;
  animation: fade .12s ease-out;
}
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; animation: pop .15s ease-out; }
.modal.wide { max-width: 940px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; border: 0; background: none; cursor: pointer; display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.99); } }

.task-detail { display: grid; grid-template-columns: 1fr 260px; }
.task-detail .main-col { padding: 20px; min-width: 0; border-right: 1px solid var(--border); }
.task-detail .side-col { padding: 20px; background: #fbfcfe; border-radius: 0 0 14px 0; }
.title-input { font-size: 20px; font-weight: 700; border: 1px solid transparent; border-radius: 8px; padding: 6px 8px; margin: -6px -8px 10px; width: calc(100% + 16px); outline: none; background: none; }
.title-input:hover { background: var(--surface-2); }
.title-input:focus { background: var(--surface); border-color: var(--primary); }
.desc-input { border-color: transparent; background: var(--surface-2); min-height: 110px; }
.section-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 22px 0 10px; }
.prop { margin-bottom: 14px; }
.prop > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.prop .input { height: 34px; }
.prop .static { display: flex; align-items: center; gap: 8px; min-height: 28px; }
.comment { display: flex; gap: 10px; margin-bottom: 14px; }
.comment .bubble { flex: 1; min-width: 0; }
.comment .bubble .who { font-size: 13px; }
.comment .bubble .who b { font-weight: 600; }
.comment .bubble .txt { margin-top: 4px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; background: var(--surface-2); padding: 10px 12px; border-radius: 0 10px 10px 10px; }
.comment-form { display: flex; gap: 10px; align-items: flex-start; }
.comment-form textarea { min-height: 44px; }
.mini-feed { list-style: none; margin: 0; padding: 0; font-size: 13px; color: var(--text-2); }
.mini-feed li { padding: 5px 0; display: flex; gap: 8px; }
.mini-feed li .when { color: var(--muted); margin-left: auto; white-space: nowrap; font-size: 12px; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #111827; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13px; animation: pop .15s ease-out; max-width: 360px; }
.toast.err { background: var(--danger); }

.loading { padding: 60px; text-align: center; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .dash { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .login { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .menu-btn { display: grid; }
  .topbar { padding: 0 16px; }
  .content { padding: 20px 16px; }
  .task-detail { grid-template-columns: 1fr; }
  .task-detail .main-col { border-right: 0; border-bottom: 1px solid var(--border); }
  .task-detail .side-col { border-radius: 0 0 14px 14px; }
  .board { grid-template-columns: repeat(4, 82vw); }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi .value { font-size: 22px; }
  .row { flex-direction: column; gap: 0; }
  .hide-sm { display: none !important; }
}
