/* ==========================================================================
   TS TODO — feuille de style
   Palette « encre et papier bleuté » ; la seule audace : le titre qui se
   remplit d'encre au fil des tâches terminées.
   ========================================================================== */

@property --progression {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 0%;
}

/* --- Thème ----------------------------------------------------------------
   Chaque couleur est déclarée une seule fois : light-dark(clair, sombre).
   color-scheme décide laquelle s'applique : le système par défaut, ou le
   choix mémorisé par scripts/theme.js via l'attribut data-theme. */

:root {
  color-scheme: light dark;

  --fond: light-dark(#e9edf5, #0f1426);
  --surface: light-dark(#ffffff, #182038);
  --surface-douce: light-dark(#f3f5fa, #1e2742);
  --encre: light-dark(#18203a, #e8ecf8);
  --encre-douce: light-dark(#5b6482, #98a1bf);
  --trait: light-dark(#d5dbe8, #2b3554);
  --accent: light-dark(#2f4bdb, #7d92ff);
  --accent-encre: light-dark(#ffffff, #0f1426);
  --titre-vide: light-dark(#c9d1e4, #2b3554);
  --haute: light-dark(#d93f4c, #ff7a84);
  --moyenne: light-dark(#c98a00, #f0b73a);
  --basse: light-dark(#2e8a65, #5cc79c);
  --couleur-ombre: light-dark(rgb(24 32 58 / 0.18), rgb(0 0 0 / 0.6));

  --ombre: 0 1px 2px rgb(24 32 58 / 0.06), 0 14px 36px -14px var(--couleur-ombre);
  --rayon-grand: 22px;
  --rayon: 12px;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237a83a3' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E");

  --police-titre: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --police-texte: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
}

:root[data-theme="clair"] {
  color-scheme: light;
}

:root[data-theme="sombre"] {
  color-scheme: dark;
}

/* --- Base ---------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--fond);
  color: var(--encre);
  font-family: var(--police-texte);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
}

.visuellement-cache {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

[hidden] {
  display: none !important;
}

svg {
  width: 1.25em;
  height: 1.25em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Menus déroulants (tri, statut) */
.menu {
  padding: 6px 28px 6px 10px;
  border: 1px solid var(--trait);
  background: var(--surface) var(--chevron) no-repeat right 9px center / 13px;
  font-size: 0.875rem;
  appearance: none;
  cursor: pointer;
}

/* --- Mise en page -------------------------------------------------------- */

.app {
  width: min(680px, 100% - 32px);
  margin: clamp(32px, 9vh, 96px) auto 120px;
}

/* --- En-tête : le titre se remplit selon la progression ------------------ */

.entete {
  margin-bottom: 28px;
}

.entete-ligne {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.titre {
  padding-bottom: 0.06em;
  font-family: var(--police-titre);
  font-weight: 800;
  font-size: clamp(3.5rem, 15vw, 6.5rem);
  line-height: 0.88;
  letter-spacing: -0.045em;
  background: linear-gradient(
    90deg,
    var(--accent) var(--progression),
    var(--titre-vide) var(--progression)
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  transition: --progression 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}

.resume {
  margin-top: 14px;
  color: var(--encre-douce);
  font-size: 1.0625rem;
}

/* Les deux icônes sont superposées ; light-dark() rend visible celle qui convient. */
.bouton-icone {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-top: 6px;
  border: 1px solid var(--trait);
  border-radius: 50%;
  background: var(--surface);
  color: var(--encre-douce);
  transition:
    color 0.2s,
    border-color 0.2s;
}

.bouton-icone svg {
  grid-area: 1 / 1;
}

.icone-lune {
  stroke: light-dark(currentColor, transparent);
}

.icone-soleil {
  stroke: light-dark(transparent, currentColor);
}

.bouton-icone:hover {
  color: var(--encre);
  border-color: var(--encre-douce);
}

/* --- Formulaire ---------------------------------------------------------- */

.formulaire {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--surface);
  border-radius: var(--rayon-grand);
  box-shadow: var(--ombre);
}

#champ-tache {
  height: 48px;
  padding: 0 14px;
  border: none;
  border-radius: var(--rayon);
  background: transparent;
  font-size: 1.0625rem;
}

#champ-tache::placeholder {
  color: var(--encre-douce);
}

#champ-tache:focus-visible {
  outline: none;
  background: var(--surface-douce);
}

#champ-tache[aria-invalid="true"] {
  background: color-mix(in srgb, var(--haute) 10%, transparent);
}

.choix-priorite {
  display: flex;
  gap: 2px;
  min-width: 0;
  padding: 3px;
  border: none;
  border-radius: var(--rayon);
  background: var(--surface-douce);
}

.pastille-choix {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 9px;
  color: var(--encre-douce);
  font-size: 0.875rem;
  cursor: pointer;
  user-select: none;
  transition:
    background 0.15s,
    color 0.15s;
}

.pastille-choix::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--couleur-priorite);
}

.pastille-choix input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.pastille-choix:hover {
  color: var(--encre);
}

.pastille-choix:has(input:checked) {
  background: var(--surface);
  color: var(--encre);
  font-weight: 700;
  box-shadow: 0 1px 3px rgb(24 32 58 / 0.12);
}

.pastille-choix:has(input:focus-visible) {
  outline: 2.5px solid var(--accent);
  outline-offset: 1px;
}

[data-priorite="haute"] {
  --couleur-priorite: var(--haute);
}

[data-priorite="moyenne"] {
  --couleur-priorite: var(--moyenne);
}

[data-priorite="basse"] {
  --couleur-priorite: var(--basse);
}

.bouton-principal {
  height: 48px;
  padding: 0 22px;
  border: none;
  border-radius: var(--rayon);
  background: var(--accent);
  color: var(--accent-encre);
  font-weight: 700;
  transition:
    filter 0.15s,
    transform 0.1s;
}

.bouton-principal:hover {
  filter: brightness(1.08);
}

.bouton-principal:active {
  transform: scale(0.97);
}

.message-erreur {
  grid-column: 1 / -1;
  padding: 0 14px;
  color: var(--haute);
  font-size: 0.875rem;
}

.message-erreur:empty {
  display: none;
}

/* --- Filtres et tri ------------------------------------------------------ */

.barre-outils {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 32px 0 12px;
}

.filtres {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.filtres button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--encre-douce);
  font-size: 0.9375rem;
  transition:
    background 0.15s,
    color 0.15s;
}

.filtres button:hover {
  color: var(--encre);
  background: var(--surface-douce);
}

.filtres button[aria-pressed="true"] {
  background: var(--encre);
  color: var(--fond);
  font-weight: 700;
}

.compte {
  font-variant-numeric: tabular-nums;
  font-size: 0.8125rem;
  opacity: 0.7;
}

.tri .menu {
  padding-block: 7px;
  padding-left: 12px;
  border-radius: 999px;
  color: var(--encre-douce);
}

/* --- Liste --------------------------------------------------------------- */

.liste {
  list-style: none;
  background: var(--surface);
  border-radius: var(--rayon-grand);
  box-shadow: var(--ombre);
  overflow: hidden;
}

.liste:empty {
  display: none;
}

.tache {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 14px;
  padding: 14px 14px 14px 22px;
}

.tache + .tache {
  border-top: 1px solid var(--trait);
}

/* Liseré de priorité sur le bord gauche */
.tache::before {
  content: "";
  position: absolute;
  left: 0;
  top: 14px;
  bottom: 14px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--couleur-priorite);
}

.tache.nouvelle {
  animation: arrivee 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes arrivee {
  from {
    opacity: 0;
    transform: translateY(-6px);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
  }
}

.case {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 2px solid var(--trait);
  border-radius: 50%;
  background: transparent;
  color: transparent;
  transition:
    background 0.2s,
    border-color 0.2s,
    color 0.2s;
}

.case svg {
  width: 16px;
  height: 16px;
  stroke-width: 3;
}

.case:hover {
  border-color: var(--accent);
  color: color-mix(in srgb, var(--accent) 45%, transparent);
}

.tache[data-statut="en cours"] .case {
  border-color: var(--moyenne);
  border-style: dashed;
}

.case[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-encre);
}

.corps {
  min-width: 0;
}

.tache-titre {
  display: block;
  font-size: 1.0625rem;
  overflow-wrap: anywhere;
  border-radius: 4px;
  cursor: text;
}

.tache[data-statut="terminée"] .tache-titre {
  color: var(--encre-douce);
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}

.edition-titre {
  width: 100%;
  padding: 2px 6px;
  margin: -3px -7px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--surface-douce);
  font-size: 1.0625rem;
}

.edition-titre:focus-visible {
  outline: none;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin-top: 3px;
  color: var(--encre-douce);
  font-size: 0.8125rem;
}

.badge-priorite {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 0;
  border: none;
  background: none;
  color: var(--encre-douce);
}

.badge-priorite::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--couleur-priorite);
}

.badge-priorite:hover {
  color: var(--encre);
  text-decoration: underline;
}

.select-statut {
  border-radius: 8px;
}

.tache[data-statut="en cours"] .select-statut {
  border-color: color-mix(in srgb, var(--moyenne) 60%, transparent);
  background-color: color-mix(in srgb, var(--moyenne) 12%, var(--surface));
}

.supprimer {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--encre-douce);
  opacity: 0;
  transition:
    opacity 0.15s,
    color 0.15s,
    background 0.15s;
}

.tache:hover .supprimer,
.supprimer:focus-visible {
  opacity: 1;
}

.supprimer:hover {
  color: var(--haute);
  background: color-mix(in srgb, var(--haute) 12%, transparent);
}

/* Sur écran tactile (pas de survol), la corbeille reste visible. */
@media (hover: none) {
  .supprimer {
    opacity: 1;
  }
}

/* --- État vide, pied, notification -------------------------------------- */

.vide {
  padding: 48px 24px;
  border: 2px dashed var(--trait);
  border-radius: var(--rayon-grand);
  color: var(--encre-douce);
  text-align: center;
}

.pied {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  padding: 0 4px;
  color: var(--encre-douce);
  font-size: 0.8125rem;
}

kbd {
  padding: 1px 6px;
  border: 1px solid var(--trait);
  border-bottom-width: 2px;
  border-radius: 5px;
  font-family: inherit;
  font-size: 0.75rem;
}

.bouton-texte {
  flex: none;
  padding: 6px 10px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--encre-douce);
  font-size: 0.875rem;
}

.bouton-texte:hover:not(:disabled) {
  color: var(--haute);
  background: color-mix(in srgb, var(--haute) 10%, transparent);
}

.bouton-texte:disabled {
  opacity: 0.45;
  cursor: default;
}

.notification {
  position: fixed;
  left: 50%;
  bottom: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: calc(100% - 32px);
  padding: 10px 10px 10px 18px;
  border-radius: 14px;
  background: var(--encre);
  color: var(--fond);
  box-shadow: 0 12px 32px -8px rgb(0 0 0 / 0.4);
  transform: translateX(-50%);
  animation: apparition-notification 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

#notification-texte {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#notification-action {
  flex: none;
  padding: 6px 12px;
  border: none;
  border-radius: 8px;
  background: color-mix(in srgb, var(--fond) 16%, transparent);
  color: inherit;
  font-weight: 700;
}

#notification-action:hover {
  background: color-mix(in srgb, var(--fond) 26%, transparent);
}

@keyframes apparition-notification {
  from {
    opacity: 0;
    transform: translate(-50%, 12px);
  }
}

/* --- Petits écrans ------------------------------------------------------- */

@media (max-width: 600px) {
  .formulaire {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  #champ-tache {
    grid-column: 1 / -1;
  }

  .choix-priorite {
    justify-self: start;
  }

  .pastille-choix {
    padding: 8px;
  }

  .barre-outils {
    flex-direction: column;
    align-items: stretch;
  }

  .filtres {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    margin: 0 -4px;
    padding: 2px 4px;
  }

  .filtres button {
    flex: none;
    padding: 7px 10px;
  }

  .tri {
    align-self: flex-end;
  }

  .tache {
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "case corps supprimer"
      ".    statut statut";
    row-gap: 10px;
  }

  .case {
    grid-area: case;
  }

  .corps {
    grid-area: corps;
  }

  .supprimer {
    grid-area: supprimer;
  }

  .select-statut {
    grid-area: statut;
    justify-self: start;
  }

  .astuce {
    display: none;
  }

  .pied {
    justify-content: flex-end;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
