:root {
  --bg: #0e1014;
  --surface: #161920;
  --surface-2: #1d212a;
  --surface-3: #252a35;
  --border: #2a303c;
  --text: #e7e9ef;
  --muted: #8a92a6;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --danger: #ed4245;
  --success: #3ba55d;
  --st-todo: #8a92a6;
  --st-doing: #f0b232;
  --st-review: #a970ff;
  --st-done: #3ba55d;
  --p-low: #6b7280;
  --p-high: #f97316;
  --p-urgent: #ef4444;
  --radius: 10px;
  --shadow: 0 8px 30px rgb(0 0 0 / 0.35);
  --panel-w: 360px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f3f7;
    --surface: #ffffff;
    --surface-2: #f6f7fa;
    --surface-3: #eceef3;
    --border: #dfe2e9;
    --text: #1d2130;
    --muted: #697086;
    --shadow: 0 8px 30px rgb(20 25 40 / 0.12);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 0.9em; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }

input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }

/* ---------- Boutons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-3);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  font-weight: 500;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 50%, transparent); color: var(--danger); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.discord { background: #5865f2; border-color: #5865f2; color: #fff; padding: 11px 20px; font-size: 15px; width: 100%; }
.btn.discord:hover { background: #4752c4; }

.icon-btn {
  display: inline-grid; place-items: center;
  min-width: 32px; height: 32px;
  border: 0; border-radius: 8px;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  position: relative;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* ---------- Page de connexion ---------- */

.auth-page { display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 28px;
  text-align: center;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.auth-card h1 { margin: 8px 0 0; font-size: 24px; }
.auth-card .btn { margin-top: 18px; }
.auth-logo { font-size: 44px; }
.auth-error { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); padding: 8px 12px; border-radius: 8px; width: 100%; }
.id-box { display: block; padding: 10px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; font-size: 16px; user-select: all; margin: 4px 0; }

/* ---------- Structure de l'app ---------- */

body.app { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; white-space: nowrap; }
.toolbar { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.toolbar input[type=search] { width: 240px; min-width: 120px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.online { display: flex; align-items: center; }
.online-user { position: relative; margin-left: -6px; }
.online-user .avatar { border: 2px solid var(--surface); }
.online-user::after {
  content: ""; position: absolute; right: -1px; bottom: -1px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--success); border: 2px solid var(--surface);
}
.online .more { margin-left: 6px; color: var(--muted); font-size: 12px; }

.badge {
  position: absolute; top: -2px; right: -4px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px;
  background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 17px; text-align: center;
}

.avatar { border-radius: 50%; object-fit: cover; flex: none; background: var(--surface-3); display: inline-grid; place-items: center; }
.avatar.sm { width: 22px; height: 22px; font-size: 11px; }
.avatar.md { width: 34px; height: 34px; }

.user-menu { position: relative; }
.me-btn { border: 0; background: none; padding: 0; cursor: pointer; display: block; border-radius: 50%; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
}
.menu-head { padding: 6px 10px 8px; font-weight: 600; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--surface-3); }

.conn-banner { background: var(--st-doing); color: #000; text-align: center; padding: 4px; font-size: 13px; font-weight: 500; }

.layout { flex: 1; display: grid; grid-template-columns: 1fr var(--panel-w); min-height: 0; }
.panel-toggle { font-size: 17px; }
body.panel-closed .layout { grid-template-columns: 1fr 0; }
body.panel-closed .panel { display: none; }

/* ---------- Board ---------- */

.board {
  display: flex; gap: 14px;
  padding: 16px;
  overflow-x: auto;
  min-height: 0;
}

.column {
  flex: 1 0 270px; max-width: 360px;
  display: flex; flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: border-color .15s, background .15s;
}
.column.drag-over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 5%, var(--surface)); }
.col-todo { --st: var(--st-todo); }
.col-doing { --st: var(--st-doing); }
.col-review { --st: var(--st-review); }
.col-done { --st: var(--st-done); }

.column-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 8px 14px; }
.column-head h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; }
.column-head .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--st); }
.column-head .count { color: var(--muted); font-size: 12px; background: var(--surface-3); padding: 0 7px; border-radius: 10px; }
.column-head .add { margin-left: auto; font-size: 18px; }

.card-list { flex: 1; overflow-y: auto; padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 8px; min-height: 60px; }
.empty { color: var(--muted); font-size: 12px; text-align: center; padding: 18px 0; border: 1px dashed var(--border); border-radius: 8px; }

.card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--st);
  border-radius: 8px;
  padding: 9px 10px;
  cursor: pointer;
  transition: border-color .15s, transform .1s, box-shadow .15s;
}
.card:hover { border-color: var(--muted); border-left-color: var(--st); box-shadow: 0 2px 10px rgb(0 0 0 / .15); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.card.dragging { opacity: .35; }
.drop-placeholder { border: 2px dashed var(--accent); border-radius: 8px; background: color-mix(in srgb, var(--accent) 8%, transparent); flex: none; }

.card-top { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.task-id { color: var(--muted); font-size: 11px; font-family: ui-monospace, Consolas, monospace; }
.prio-tag { font-size: 10px; font-weight: 700; text-transform: uppercase; padding: 1px 6px; border-radius: 4px; letter-spacing: .03em; }
.prio-tag.prio-low { color: var(--p-low); background: color-mix(in srgb, var(--p-low) 15%, transparent); }
.prio-tag.prio-high { color: var(--p-high); background: color-mix(in srgb, var(--p-high) 15%, transparent); }
.prio-tag.prio-urgent { color: #fff; background: var(--p-urgent); }
.card.prio-urgent { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--p-urgent) 40%, transparent); }

.card-title { margin: 0; font-size: 14px; font-weight: 500; word-break: break-word; }
.col-done .card-title { color: var(--muted); }

.labels { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.label {
  font-size: 11px; padding: 1px 7px; border-radius: 10px;
  color: hsl(var(--h) 70% 72%);
  background: hsl(var(--h) 60% 50% / .16);
}
@media (prefers-color-scheme: light) { .label { color: hsl(var(--h) 60% 35%); } }

.card-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); min-height: 22px; }
.due.overdue { color: var(--danger); font-weight: 600; }
.validated { margin-top: 6px; font-size: 11px; color: var(--st-done); }

.quick {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 6px; padding: 2px 8px; font-size: 11px; cursor: pointer;
  opacity: 0; transition: opacity .15s, background .15s;
}
.card:hover .quick, .card:focus-within .quick { opacity: 1; }
.quick:hover { background: var(--surface-3); }
.quick-doing { color: var(--st-doing); }
.quick-review { color: var(--st-review); }
.quick-done { color: var(--st-done); border-color: color-mix(in srgb, var(--st-done) 45%, transparent); }
@media (hover: none) { .quick { opacity: 1; } }

/* ---------- Panneau chat / activité ---------- */

.panel {
  display: flex; flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
}
.tabs { display: flex; align-items: center; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.tab-btn { border: 0; background: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { background: var(--surface-3); color: var(--text); }
.close-panel { margin-left: auto; }

.tab { display: none; flex: 1; min-height: 0; flex-direction: column; }
.tab.active { display: flex; }

.messages { flex: 1; overflow-y: auto; padding: 12px 6px 6px; }
.chat-start { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 0 14px; }

.msg { position: relative; display: grid; grid-template-columns: 40px 1fr; gap: 0 8px; padding: 4px 8px; border-radius: 6px; margin-top: 10px; }
.msg.grouped { margin-top: 0; padding-top: 1px; padding-bottom: 1px; }
.msg:hover { background: var(--surface-2); }
.msg-gutter { font-size: 10px; color: var(--muted); text-align: center; padding-top: 3px; visibility: hidden; }
.msg:hover .msg-gutter { visibility: visible; }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg-head time, .comment-head time { color: var(--muted); font-size: 11px; }
.msg-body { min-width: 0; }
.msg-del {
  position: absolute; top: 2px; right: 6px;
  border: 0; background: var(--surface-3); color: var(--muted);
  width: 22px; height: 22px; border-radius: 5px; cursor: pointer; font-size: 11px;
  display: none;
}
.msg:hover .msg-del { display: block; }
.msg-del:hover { color: var(--danger); }

.rich { white-space: pre-wrap; word-break: break-word; }
.mention { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); border-radius: 4px; padding: 0 2px; }
.mention.me { color: var(--st-doing); background: color-mix(in srgb, var(--st-doing) 18%, transparent); }
.task-chip {
  border: 1px solid var(--border); background: var(--surface-3);
  border-radius: 5px; padding: 0 6px; cursor: pointer; font-size: 12px;
  border-left: 3px solid var(--st-todo);
}
.task-chip.st-doing { border-left-color: var(--st-doing); }
.task-chip.st-review { border-left-color: var(--st-review); }
.task-chip.st-done { border-left-color: var(--st-done); }

.typing { min-height: 20px; padding: 0 14px; font-size: 12px; color: var(--muted); font-style: italic; }

.chat-form { display: flex; gap: 8px; padding: 8px 10px 12px; align-items: flex-end; }
.chat-form textarea { flex: 1; resize: none; max-height: 160px; overflow-y: auto; scrollbar-width: thin; }

.activity { list-style: none; margin: 0; padding: 10px; overflow-y: auto; flex: 1; }
.act { display: flex; gap: 10px; padding: 8px 6px; border-bottom: 1px solid var(--border); font-size: 13px; }
.act .avatar { margin-top: 1px; }
.act time { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.act .ok { color: var(--st-done); }
.link { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; text-align: left; }
.link:hover { text-decoration: underline; }

/* ---------- Dialogues ---------- */

.dialog {
  width: min(860px, calc(100vw - 24px));
  max-height: calc(100dvh - 40px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.dialog-sm { width: min(520px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgb(0 0 0 / .55); backdrop-filter: blur(2px); }
.dialog[open] { display: flex; flex-direction: column; }
.task-form { display: flex; flex-direction: column; min-height: 0; flex: 1; }

.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { margin: 0; font-size: 16px; }
.dialog-body { display: grid; grid-template-columns: 1fr 230px; gap: 20px; padding: 18px; overflow-y: auto; min-height: 0; }
.dialog-body.column-body { display: flex; flex-direction: column; gap: 10px; }
.dialog-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }

.task-main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.task-side { display: flex; flex-direction: column; gap: 12px; }
.title-input { font-size: 18px; font-weight: 600; padding: 9px 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.task-meta { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; border-top: 1px solid var(--border); padding-top: 12px; }
.meta-validated { color: var(--st-done); }

.comments h3 { font-size: 13px; margin: 6px 0 10px; }
.comment-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 10px; }
.comment { display: flex; gap: 10px; }
.comment-body { flex: 1; min-width: 0; background: var(--surface-2); border-radius: 8px; padding: 7px 10px; }
.comment-head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 2px; }
.comment-form { display: flex; gap: 8px; align-items: flex-end; }
.comment-form textarea { flex: 1; }

.whitelist-form { display: flex; gap: 8px; flex-wrap: wrap; }
.whitelist-form input { flex: 1 1 140px; }
.whitelist-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; }
.whitelist-list li { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--border); }
.wl-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.wl-info code { color: var(--muted); font-size: 12px; }
.tag { font-size: 11px; color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.avatar.placeholder { color: var(--muted); }

/* ---------- Toasts ---------- */

.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; }
.toast {
  background: var(--surface-3); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 16px; box-shadow: var(--shadow);
  animation: toast-in .2s ease-out; transition: opacity .3s, transform .3s;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.out { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Mobile ---------- */

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .panel {
    position: fixed; inset: 0; z-index: 30;
    display: none;
    border-left: 0;
  }
  body.panel-open-m .panel { display: flex; }
  body.panel-closed .layout { grid-template-columns: 1fr; }

  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  .toolbar { order: 3; flex-basis: 100%; flex-wrap: wrap; }
  .toolbar input[type=search] { flex: 1 1 100%; width: auto; }
  .toolbar select { flex: 1 1 0; min-width: 0; }
  .topbar-right { margin-left: auto; }
  .online { display: none; }

  .board { padding: 12px; scroll-snap-type: x mandatory; }
  .column { flex: 0 0 min(85vw, 320px); scroll-snap-align: start; }

  .dialog-body { grid-template-columns: 1fr; }
}

@media (min-width: 901px) {
  .close-panel { display: none; }
}
