:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1f2421;
  --muted: #6b716d;
  --line: #e2e0d9;
  --accent: #2f5d50;
  --accent-text: #ffffff;
  --high: #c0392b;
  --low: #9aa09c;
  --ok: #2e8b57;
  --warn: #d9822b;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151816;
    --surface: #1e2220;
    --text: #e7ebe8;
    --muted: #8f9792;
    --line: #2d322f;
    --accent: #5fa38f;
    --accent-text: #0e1211;
    --high: #e5675a;
    --low: #6b716d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--accent); color: var(--accent-text);
}
.bar h1 { margin: 0; font-size: 20px; font-weight: 600; }

.sync {
  display: flex; align-items: center; gap: 6px;
  background: none; border: 0; padding: 6px 4px;
  color: inherit; font-size: 13px; opacity: .9;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent-text); }
.sync[data-state="ok"] .dot { background: #8fe3b0; }
.sync[data-state="pending"] .dot,
.sync[data-state="syncing"] .dot { background: #ffd28a; }
.sync[data-state="syncing"] .dot { animation: pulse 1s infinite; }
.sync[data-state="offline"] .dot { background: #b8bdb9; }
.sync[data-state="error"] .dot { background: #ff9a8f; }
@keyframes pulse { 50% { opacity: .3; } }

main, .login { max-width: 640px; margin: 0 auto; padding: 12px 12px 40px; }

.add { display: flex; gap: 8px; margin-bottom: 12px; }
.add input {
  flex: 1; min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface);
}
.add input:focus, textarea:focus, .login input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.add button {
  width: 48px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-text);
  font-size: 24px; line-height: 1;
}

.list { list-style: none; margin: 0; padding: 0; }
.task {
  display: flex; align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid transparent;
  border-radius: var(--radius);
  margin-bottom: 6px;
}
.task.p1 { border-left-color: var(--high); }
.task.p3 .title { color: var(--muted); }

.check {
  flex: none; width: 48px; height: 48px;
  display: grid; place-items: center;
  background: none; border: 0; padding: 0;
}
.check::before {
  content: ""; width: 20px; height: 20px;
  border: 2px solid var(--muted); border-radius: 50%;
}
.task.p1 .check::before { border-color: var(--high); }
.task.done .check::before {
  border-color: var(--ok); background: var(--ok);
  box-shadow: inset 0 0 0 3px var(--surface);
}

.body {
  flex: 1; min-width: 0;
  text-align: left; background: none; border: 0;
  padding: 13px 12px 13px 0;
}
.title { display: block; overflow-wrap: anywhere; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.note {
  display: block; margin-top: 2px;
  font-size: 13px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.note .chip {
  display: inline-block;
  margin-right: 6px; padding: 1px 6px;
  border: 1px solid currentColor; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .03em;
  opacity: .75; vertical-align: 1px;
}
.note .due { white-space: nowrap; }
.note .due.urgent { color: var(--high); font-weight: 600; }
.task.done .note .due.urgent { color: var(--muted); font-weight: 400; }

.warn {
  margin: 0 0 8px; padding: 8px 12px;
  border: 1px solid var(--line); border-left: 4px solid var(--warn);
  border-radius: var(--radius);
  background: var(--surface); color: var(--muted); font-size: 14px;
}

/* Teintes des projets, une paire clair/sombre par nom. */
:root {
  --c-ardoise: #5b6b7a; --c-sauge: #6d8f73; --c-azur: #3f7fa6;
  --c-prune:   #7d5b86; --c-brique: #a65f4c; --c-ocre: #b08341;
  --c-olive:   #798342; --c-sable:  #9a8467;
}
@media (prefers-color-scheme: dark) {
  :root {
    --c-ardoise: #8fa3b5; --c-sauge: #93bd9a; --c-azur: #6fb0d6;
    --c-prune:   #b189ba; --c-brique: #d68a75; --c-ocre: #ddb06a;
    --c-olive:   #a9b56a; --c-sable:  #c4ad8c;
  }
}
.dot-color {
  display: inline-block; flex: none;
  width: 9px; height: 9px; margin-right: 7px;
  border-radius: 50%; background: var(--muted);
}
.dot-color[data-color="ardoise"] { background: var(--c-ardoise); }
.dot-color[data-color="sauge"]   { background: var(--c-sauge); }
.dot-color[data-color="azur"]    { background: var(--c-azur); }
.dot-color[data-color="prune"]   { background: var(--c-prune); }
.dot-color[data-color="brique"]  { background: var(--c-brique); }
.dot-color[data-color="ocre"]    { background: var(--c-ocre); }
.dot-color[data-color="olive"]   { background: var(--c-olive); }
.dot-color[data-color="sable"]   { background: var(--c-sable); }

/* Bandeau des projets : la liste défile, le bouton de gestion reste visible. */
.chips-row { display: flex; align-items: center; gap: 6px; margin-bottom: 12px; }
.chips {
  flex: 1; min-width: 0;
  display: flex; gap: 6px;
  /* Débord à gauche seulement : à droite, le bouton de gestion prend la place. */
  margin-left: -12px; padding: 2px 0 2px 12px;
  overflow-x: auto; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; flex: none;
  padding: 7px 13px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--text);
  font-size: 14px; white-space: nowrap;
}
.tab.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.tab.on .dot-color { box-shadow: 0 0 0 1px var(--accent-text); }
.tab-count { margin-left: 7px; font-size: 12px; opacity: .65; }
.tab.gear { padding: 7px 11px; font-size: 16px; }

/* Intertitres de groupe */
.group {
  display: flex; align-items: center; gap: 8px;
  margin: 16px 2px 6px;
}
.group:first-child { margin-top: 2px; }
.group-name {
  display: inline-flex; align-items: center;
  background: none; border: 0; padding: 0;
  color: var(--muted); font-size: 13px; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase;
}
.group-count { margin-left: auto; color: var(--muted); font-size: 13px; }

/* Gestion des projets */
.proj { display: flex; align-items: center; gap: 4px; padding: 2px 0; }
.proj.archived .proj-name { color: var(--muted); }
.move {
  flex: none; width: 34px; height: 38px;
  background: none; border: 0; color: var(--muted); font-size: 15px;
}
.move:disabled { opacity: .25; }
.proj-name {
  flex: 1; min-width: 0;
  display: flex; align-items: center;
  padding: 11px 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); text-align: left; overflow-wrap: anywhere;
}
.palette { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 34px; height: 34px; padding: 0;
  border: 2px solid transparent; border-radius: 50%;
  background: var(--muted);
}
.swatch.on { border-color: var(--text); }
.swatch[data-color="ardoise"] { background: var(--c-ardoise); }
.swatch[data-color="sauge"]   { background: var(--c-sauge); }
.swatch[data-color="azur"]    { background: var(--c-azur); }
.swatch[data-color="prune"]   { background: var(--c-prune); }
.swatch[data-color="brique"]  { background: var(--c-brique); }
.swatch[data-color="ocre"]    { background: var(--c-ocre); }
.swatch[data-color="olive"]   { background: var(--c-olive); }
.swatch[data-color="sable"]   { background: var(--c-sable); }

.field { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 14px; }
.field select {
  padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); color: var(--text); font-size: 16px;
}

#projects h2 { margin: 0 0 12px; font-size: 18px; }
#projects #projName {
  width: 100%; padding: 10px 12px; margin-bottom: 12px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); color: var(--text);
}
#projEditForm .palette { margin-bottom: 4px; }

.empty { text-align: center; color: var(--muted); margin: 32px 0; }

.done-section { margin-top: 20px; }
.done-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }

.link {
  background: none; border: 0; padding: 8px 4px;
  color: var(--muted); font-size: 14px;
}
.link.danger { color: var(--high); }
.link.armed { font-weight: 600; }

.foot { margin-top: 32px; text-align: center; }

.login form { display: flex; flex-direction: column; gap: 10px; margin-top: 40px; }
.login h2 { margin: 0; }
.hint { margin: 0; color: var(--muted); font-size: 14px; }
.login input {
  padding: 12px 14px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface);
}
.primary {
  padding: 11px 18px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-text); font-weight: 600;
}
.error { color: var(--high); min-height: 1.4em; margin: 0; }

dialog {
  width: min(560px, calc(100vw - 24px));
  border: 0; border-radius: 14px; padding: 16px;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
#editForm { display: flex; flex-direction: column; gap: 12px; }
dialog textarea {
  width: 100%; resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg);
}
#editTitle { font-weight: 600; }

.prio { display: flex; gap: 6px; }
.prio label { flex: 1; }
.prio input { position: absolute; opacity: 0; pointer-events: none; }
.prio span {
  display: block; text-align: center;
  padding: 9px 4px;
  border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 14px;
}
.prio input:checked + span { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.prio input[value="1"]:checked + span { background: var(--high); border-color: var(--high); color: #fff; }
.prio input:focus-visible + span { outline: 2px solid var(--accent); }

.actions { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }

@media (hover: hover) {
  .task:hover { border-color: var(--muted); }
  .task.p1:hover { border-left-color: var(--high); }
}
