:root {
  color-scheme: light;
  --bg: #EEF1F5;
  --surface: #FFFFFF;
  --head: #E3E8EF;
  --ink: #18202E;
  --muted: #5B6576;
  --line: #D6DCE5;
  --accent: #1F6F8B;
  --accent-ink: #FFFFFF;
  --dirty: #FFE9A8;
  --dirty-mark: #C98A00;
  --error: #B42318;
  --error-bg: #FDECEA;
  --ok: #1E7F4F;
  --focus: #1F6F8B;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #141922;
    --surface: #1B212C;
    --head: #222A36;
    --ink: #E6EAF0;
    --muted: #97A1B2;
    --line: #2C3442;
    --accent: #4FB3D4;
    --accent-ink: #0E1A20;
    --dirty: #4A3B10;
    --dirty-mark: #E5B53A;
    --error: #F28B82;
    --error-bg: #3A1D1B;
    --ok: #5CC28A;
    --focus: #4FB3D4;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  font: 14px/1.4 "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}
button, input, select { font: inherit; color: inherit; }

.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.logo { height: 52px; width: auto; display: block; }
.brand picture + div { padding-left: 14px; border-left: 1px solid var(--line); }
.bar h1 { margin: 0; font-size: 18px; font-weight: 600; }
.bar p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.user { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }

.toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--bg);
}
.toolbar input[type=search] {
  width: 280px; max-width: 100%; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
}
#counts { color: var(--muted); font-size: 13px; }
.actions { margin-left: auto; display: flex; gap: 8px; }
button {
  padding: 7px 14px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface);
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 500; }
button.link { border: 0; background: none; padding: 0; text-decoration: underline; color: var(--muted); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

main { flex: 1; overflow: auto; position: relative; }
table { border-collapse: separate; border-spacing: 0; table-layout: fixed; background: var(--surface); }
th, td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0; height: 40px; }
th {
  position: sticky; top: 0; z-index: 2; background: var(--head);
  text-align: center; font-weight: 500; font-size: 13px;
}
th button {
  width: 100%; height: 100%; border: 0; border-radius: 0; background: none;
  text-align: center; padding: 6px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
th .sort { color: var(--muted); margin-left: 4px; }
th.has-filter button:first-child { padding-left: 34px; padding-right: 34px; } /* place de l'icône filtre, titre centré */
.filter-btn {
  position: absolute; top: 50%; right: 8px; transform: translateY(-50%);
  width: 24px; height: 24px; padding: 0; display: grid; place-items: center;
  border: 0; border-radius: 4px; background: none; color: var(--muted);
}
.filter-btn:hover { background: var(--line); }
.filter-btn.on { color: var(--accent-ink); background: var(--accent); }

.filter-pop {
  position: fixed; z-index: 20; min-width: 220px; max-width: 320px; max-height: 60vh; overflow: auto;
  padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgb(0 0 0 / .18); font-size: 13px;
}
.filter-actions { display: flex; gap: 12px; padding: 4px 8px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.filter-pop label { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 4px; cursor: pointer; }
.filter-pop label:hover { background: var(--bg); }
.filter-pop .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.filter-pop .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-pop .n { color: var(--muted); }

/* Poignée de redimensionnement : glisser pour changer la largeur, double-clic pour revenir à la largeur par défaut */
.resizer {
  position: absolute; top: 0; right: -4px; width: 8px; height: 100%;
  cursor: col-resize; z-index: 4; touch-action: none;
}
.resizer::after {
  content: ""; position: absolute; top: 25%; bottom: 25%; left: 3px; width: 2px;
  border-radius: 1px; background: transparent;
}
th:hover .resizer::after, .resizer.active::after { background: var(--muted); }
body.resizing { cursor: col-resize; user-select: none; }

td { position: relative; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
td.ro { padding: 0 8px; color: var(--muted); }
td.t-id { padding: 0 8px; }
td.t-id a { color: var(--accent); text-decoration: none; font-weight: 500; }
td.t-id a:hover { text-decoration: underline; }
/* Colonnes centrées par défaut ; align: "left" dans config.js pour aligner à gauche (ex. Sujet) */
td { text-align: center; }
.cell-input { text-align: center; text-align-last: center; }
th.align-left, th.align-left button, td.align-left, td.align-left .cell-input { text-align: left; text-align-last: left; }

/* Date vide : affiche « N/A » au repos, le sélecteur de date reprend la main au focus */
td.t-date.empty:not(:focus-within) .cell-input { color: transparent; }
/* Valeur colorée (états Azure DevOps) : fond teinté et pastille */
td.tagged { background: color-mix(in srgb, var(--tag) 16%, var(--surface)); }
td.tagged .cell-input { padding-left: 26px; }
td.tagged::after {
  content: ""; position: absolute; left: 10px; top: 50%; width: 10px; height: 10px; margin-top: -5px;
  border-radius: 50%; background: var(--tag); pointer-events: none;
}

td.t-date.empty:not(:focus-within)::after {
  content: "N/A"; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  color: var(--muted); pointer-events: none;
}

.cell-input {
  width: 100%; height: 100%; padding: 0 8px;
  border: 0; border-radius: 0; background: transparent; outline: none;
}
.cell-input:focus { box-shadow: inset 0 0 0 2px var(--focus); background: var(--surface); }
select.cell-input { cursor: pointer; }

td.dirty { background: var(--dirty); }
td.dirty::before {
  content: ""; position: absolute; top: 0; right: 0;
  border-style: solid; border-width: 0 8px 8px 0;
  border-color: transparent var(--dirty-mark) transparent transparent;
}
tr.is-error td:first-child { box-shadow: inset 3px 0 0 var(--error); }
tr.is-error td.dirty { box-shadow: inset 0 0 0 2px var(--error); background: var(--error-bg); }
td.invalid { box-shadow: inset 0 0 0 2px var(--error); }

/* Enregistrement en cours : les cellules modifiées pulsent */
tr.is-saving td.dirty { animation: saving 1s ease-in-out infinite; }
@keyframes saving { 50% { background: color-mix(in srgb, var(--dirty) 45%, var(--surface)); } }
/* Enregistré : éclair vert qui s'estompe */
td.flash { animation: saved 1.6s ease-out; }
@keyframes saved {
  0%, 25% { background: color-mix(in srgb, var(--ok) 35%, var(--surface)); box-shadow: inset 0 0 0 2px var(--ok); }
  100% { box-shadow: inset 0 0 0 2px transparent; }
}
@media (prefers-reduced-motion: reduce) {
  tr.is-saving td.dirty { animation: none; }
  td.flash { animation-duration: .01s; }
}
main.busy table { pointer-events: none; opacity: .7; }

#empty { padding: 48px 20px; color: var(--muted); max-width: 640px; }
#empty strong { color: var(--ink); display: block; margin-bottom: 6px; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(12px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 6px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
@media (max-width: 720px) {
  .actions { margin-left: 0; width: 100%; }
  .actions button { flex: 1; }
}

/* Menu contextuel (clic droit sur une date) */
.ctx-menu { min-width: 0; padding: 4px; }
.ctx-menu button {
  display: block; width: 100%; text-align: left; border: 0; border-radius: 4px;
  background: none; padding: 7px 10px; white-space: nowrap;
}
.ctx-menu button:hover:not(:disabled), .ctx-menu button:focus-visible { background: var(--bg); }

/* Champ inexistant sur le type du work item (ex. date « Month » sur un PBI) */
td.no-field { background: repeating-linear-gradient(135deg, transparent 0 6px, var(--bg) 6px 12px); text-align: center; }

/* Case à cocher de la barre d'outils */
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; user-select: none; }
.toggle input { margin: 0; accent-color: var(--accent); }

/* Valeur colorée en lecture seule (colonne État) : texte plein, pas grisé */
td.ro.tagged { color: var(--ink); font-weight: 500; }

/* Colonne calculée (État) : main au survol, l'explication s'affiche en infobulle */
td.computed { cursor: pointer; }

/* Infobulle rapide (colonne État) */
.tip {
  position: fixed; z-index: 30; max-width: 320px; padding: 8px 10px; pointer-events: none;
  background: var(--ink); color: var(--bg); border-radius: 6px; font-size: 12.5px; line-height: 1.45;
  box-shadow: 0 6px 18px rgb(0 0 0 / .2);
}
.tip strong { display: block; font-weight: 600; margin-bottom: 2px; }
