/* =========================================================================
   Tâches — style
   Les couleurs sont des variables : modifie-les ici pour changer le thème.
   ========================================================================= */

:root {
  --fond: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f0f0f3;
  --trait: #e3e3e8;
  --texte: #1d1d1f;
  --texte-2: #6e6e73;
  --texte-3: #a1a1a6;
  --accent: #0a66d6;
  --accent-doux: rgba(10, 102, 214, 0.12);
  --vert: #2f9e44;
  --rouge: #d93025;
  --encre: #111111;

  --prio-0: #8e44ec; /* Urgent  */
  --prio-1: #e5484d; /* Haute   */
  --prio-2: #f08c00; /* Moyenne */
  --prio-3: #a1a1a6; /* Faible  */

  --rayon: 10px;
  --ombre: 0 8px 30px rgba(0, 0, 0, 0.12);
  --police: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #1c1c1e;
    --surface: #232325;
    --surface-2: #2c2c2e;
    --trait: #38383a;
    --texte: #f5f5f7;
    --texte-2: #a1a1a6;
    --texte-3: #6e6e73;
    --accent: #3d8bfd;
    --accent-doux: rgba(61, 139, 253, 0.18);
    --vert: #40c057;
    --rouge: #ff6b6b;
    --encre: #f2f2f2;
    --ombre: 0 8px 30px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--fond);
  color: var(--texte);
  font-family: var(--police);
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }

/* ---------- Mise en page : trois colonnes, deux, ou une selon la largeur ---------- */

.app {
  display: grid;
  grid-template-columns: 240px 380px 1fr;
  height: 100dvh;
  overflow: hidden;
}

.barre {
  background: var(--surface-2);
  border-right: 1px solid var(--trait);
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 14px) 10px calc(env(safe-area-inset-bottom) + 12px);
  overflow-y: auto;
}

.colonne-liste {
  background: var(--surface);
  border-right: 1px solid var(--trait);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.colonne-detail {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.voile { display: none; }

/* Tablette (iPad en portrait, petits écrans) : la barre latérale devient un tiroir */
@media (max-width: 1179px) {
  .app { grid-template-columns: 340px 1fr; }
  .barre {
    position: fixed;
    inset: 0 auto 0 0;
    width: 270px;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: var(--ombre);
  }
  body.tiroir-ouvert .barre { transform: translateX(0); }
  body.tiroir-ouvert .voile {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(0, 0, 0, 0.25);
  }
}

/* Téléphone : une seule colonne à la fois */
@media (max-width: 699px) {
  .app { grid-template-columns: 1fr; }
  .colonne-liste { border-right: none; }
  .colonne-detail { display: none; }
  body.vue-detail .colonne-liste { display: none; }
  body.vue-detail .colonne-detail { display: flex; }
}

/* Boutons visibles seulement quand la barre est un tiroir / en vue téléphone */
.seulement-tiroir, .seulement-telephone { display: none !important; }
@media (max-width: 1179px) { .seulement-tiroir { display: inline-flex !important; } }
@media (max-width: 699px) { .seulement-telephone { display: inline-flex !important; } }

/* ---------- Barre latérale ---------- */

.marque {
  font-weight: 700;
  font-size: 20px;
  padding: 4px 10px 14px;
}

.nav {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: none;
  text-align: left;
}
.nav:hover { background: rgba(127, 127, 127, 0.1); }
.nav.actif { background: var(--accent-doux); color: var(--accent); font-weight: 600; }
.nav .ico { color: var(--accent); flex: none; }
.nav .libelle { flex: 1; }
.nav .compte { color: var(--texte-3); font-size: 13px; font-variant-numeric: tabular-nums; }

.titre-groupe {
  margin: 18px 10px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--texte-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.barre-pied {
  margin-top: auto;
  padding-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.barre-pied .nav { font-size: 14px; color: var(--texte-2); }
.barre-pied .nav .ico { color: var(--texte-2); }

/* ---------- En-têtes de colonnes ---------- */

.tete {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 6px;
  min-height: 52px;
}
.tete .espace { flex: 1; }
.tete h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.titre-liste { padding: 0 18px 6px; }

.icone-bouton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--accent);
}
.icone-bouton:hover { background: rgba(127, 127, 127, 0.12); }
.icone-bouton.danger { color: var(--rouge); }

.defile {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(env(safe-area-inset-bottom) + 24px);
}

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

.section-titre {
  padding: 14px 18px 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--texte-2);
}

.ligne {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 1px 8px;
  padding: 9px 10px;
  border-radius: var(--rayon);
  position: relative;
  cursor: pointer;
  user-select: none;
}
.ligne:hover { background: rgba(127, 127, 127, 0.08); }
.ligne.choisie { background: var(--accent); color: #fff; }
.ligne.choisie .ligne-meta, .ligne.choisie .compteur { color: rgba(255, 255, 255, 0.85); }
.ligne.choisie .compteur { background: rgba(255, 255, 255, 0.2); }
.ligne.choisie .chevron, .ligne.choisie .case { color: #fff; }
.ligne.enfant { margin-left: 34px; }

.chevron, .chevron-vide {
  flex: none;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--texte-3);
  padding: 0;
}
.chevron svg { transition: transform 0.15s ease; }
.chevron.ouvert svg { transform: rotate(90deg); }

.pastille {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.prio-0 { background: var(--prio-0); }
.prio-1 { background: var(--prio-1); }
.prio-2 { background: var(--prio-2); }
.prio-3 { background: var(--prio-3); }

.case {
  flex: none;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  padding: 0;
  color: var(--texte-3);
}
.case.faite { color: var(--vert); }

.ligne-texte { flex: 1; min-width: 0; }
.ligne-titre {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ligne-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--texte-2);
}
.ligne-meta span { display: inline-flex; align-items: center; gap: 4px; }
.barre-texte { text-decoration: line-through; opacity: 0.6; }

.compteur {
  flex: none;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--texte-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.groupe-parent {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 8px;
  padding: 10px 18px 6px;
  border: none;
  background: none;
  font-weight: 600;
  text-align: left;
}

/* ---------- États vides ---------- */

.vide {
  height: 100%;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  text-align: center;
  color: var(--texte-2);
}
.vide strong { color: var(--texte); font-size: 17px; }
.vide .ico { color: var(--texte-3); margin-bottom: 6px; }

.bouton {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--trait);
  border-radius: 8px;
  background: var(--surface);
  font-size: 14px;
}
.bouton:hover { background: var(--surface-2); }
.bouton.principal { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.bouton.petit { padding: 5px 10px; font-size: 13px; }
.vide .bouton { margin-top: 12px; }

/* ---------- Page d'une tâche ---------- */

.detail-tete { border-bottom: 1px solid transparent; }
.detail-tete .titre-court {
  flex: 1;
  text-align: center;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page {
  max-width: 780px;
  margin: 0 auto;
  padding: 8px 36px 40px;
}
@media (max-width: 1179px) { .page { padding: 8px 26px 40px; } }
@media (max-width: 699px) { .page { padding: 8px 18px 40px; } .titre-tache { font-size: 23px; } }

.lien-parent {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
}

.titre-tache {
  width: 100%;
  margin: 0 0 18px;
  padding: 0;
  border: none;
  outline: none;
  background: none;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.titre-tache::placeholder { color: var(--texte-3); }

.proprietes {
  display: grid;
  grid-template-columns: 150px 1fr;
  align-items: start;               /* chaque libellé reste en face du début de sa valeur */
  gap: 10px 14px;
  margin-bottom: 24px;
}
@media (max-width: 1179px) { .proprietes { grid-template-columns: 124px 1fr; } }
@media (max-width: 699px) { .proprietes { grid-template-columns: 108px 1fr; } }

.prop-libelle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  color: var(--texte-2);
  font-size: 14px;
}
.prop-valeur {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-height: 32px;
}
.discret { color: var(--texte-2); font-size: 14px; }

select, input[type="datetime-local"] {
  padding: 5px 8px;
  border: 1px solid var(--trait);
  border-radius: 8px;
  background: var(--surface);
  font-size: 14px;
  color: var(--accent);
}
select { padding-right: 24px; }

/* Interrupteur (rappel actif) */
.interrupteur { position: relative; display: inline-block; width: 44px; height: 26px; flex: none; }
.interrupteur input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.interrupteur span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--trait);
  transition: background 0.15s ease;
}
.interrupteur span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease;
}
.interrupteur input:checked + span { background: var(--vert); }
.interrupteur input:checked + span::after { transform: translateX(18px); }

/* Sous-tâches dans la page */
.bloc { margin-bottom: 22px; }
.bloc-titre { margin: 0 0 8px; font-size: 16px; font-weight: 600; }

.sous {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-radius: 8px;
  background: var(--surface);
}
.sous.deplacee { position: relative; z-index: 2; box-shadow: var(--ombre); }
.poignee {
  flex: none;
  color: var(--texte-3);
  cursor: grab;
  touch-action: none;
  padding: 4px 2px;
}
.sous-titre {
  flex: 1;
  min-width: 0;
  padding: 2px 0;
  border: none;
  outline: none;
  background: none;
}
.sous-titre.barre-texte { text-decoration: line-through; }
.badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  color: var(--accent);
}
.badge.retard { color: var(--rouge); }
.ouvrir {
  flex: none;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--texte-3);
}
.ouvrir:hover { background: rgba(127, 127, 127, 0.12); color: var(--texte); }

.ajout {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px 6px 26px;
  color: var(--texte-3);
}
.ajout input {
  flex: 1;
  border: none;
  outline: none;
  background: none;
  padding: 2px 0;
}
.rattacher { margin: 6px 0 0 58px; }
.rattacher select { color: var(--accent); }

.separateur { border: none; border-top: 1px solid var(--trait); margin: 8px 0 18px; }

/* Notes : pas d'encadré, la zone grandit avec le texte */
.notes {
  display: block;
  width: 100%;
  min-height: 60px;
  padding: 0;
  border: none;
  outline: none;
  background: none;
  resize: none;
  overflow: hidden;
  line-height: 1.5;
}
.notes::placeholder { color: var(--texte-3); }

/* Écriture manuscrite */
.manuscrit { margin-top: 18px; }
.outils {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  width: fit-content;
}
.outil {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--texte-2);
}
.outil.actif { background: var(--surface); color: var(--texte); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); }
.outil .point { width: 14px; height: 14px; border-radius: 50%; }
.outils .sep { width: 1px; height: 20px; background: var(--trait); margin: 0 4px; }

.zone-dessin { position: relative; margin-top: 8px; }
.zone-dessin canvas {
  display: block;
  width: 100%;
  touch-action: pan-y; /* le doigt fait défiler, le stylet écrit */
}
.zone-dessin .indication {
  position: absolute;
  top: 10px;
  left: 4px;
  color: var(--texte-3);
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---------- Fenêtre « Nouvelle tâche » ---------- */

.modale {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.3);
}
.modale[hidden] { display: none; }
.modale-carte {
  width: min(480px, 100%);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  padding: 20px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--ombre);
}
.modale-carte h2 { margin: 0 0 14px; font-size: 18px; }
.champ { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; color: var(--texte-2); }
.champ input, .champ textarea, .champ select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--trait);
  border-radius: 8px;
  background: var(--surface);
  color: var(--texte);
  font-size: 15px;
}
.champ textarea { resize: vertical; line-height: 1.45; }
.deux { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ---------- Message temporaire ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  z-index: 60;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #1d1d1f;
  color: #fff;
  font-size: 14px;
  box-shadow: var(--ombre);
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Comptes : écran de connexion et « Mon compte » ---------- */

.ecran-connexion {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px calc(env(safe-area-inset-bottom) + 20px);
  overflow-y: auto;
  background: var(--fond);
}
.ecran-connexion[hidden] { display: none; }
body.deconnecte .app { visibility: hidden; }
.carte-connexion {
  width: min(400px, 100%);
  padding: 28px 24px 22px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--ombre);
  text-align: center;
}
.carte-connexion img { border-radius: 14px; }
.carte-connexion h1 { margin: 8px 0 16px; font-size: 24px; }
.carte-connexion .champ { text-align: left; }
.carte-connexion .champ small { color: var(--texte-3); font-size: 12px; }
.onglets { display: flex; gap: 4px; padding: 3px; margin-bottom: 16px; border-radius: 10px; background: var(--surface-2); }
.onglets button {
  flex: 1;
  padding: 7px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--texte-2);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.onglets button.actif { background: var(--surface); color: var(--texte); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.message-connexion { margin: 0 0 14px; padding: 9px 12px; border-radius: 10px; background: var(--accent-doux); font-size: 14px; text-align: left; }
.bouton.large { width: 100%; padding: 11px; font-size: 16px; margin-top: 4px; }
.petit { font-size: 12px; }
.carte-connexion .petit { margin: 14px 0 0; }

.modale-carte h3 { margin: 0 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--texte-2); }
.ligne-cle { display: flex; gap: 8px; margin-bottom: 8px; }
.ligne-cle input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--trait);
  border-radius: 8px;
  background: var(--surface);
  color: var(--texte);
  font: 13px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.bouton.danger { color: var(--rouge); }
.bouton.petit { padding: 4px 8px; font-size: 12px; }
.liste-comptes { display: flex; flex-direction: column; gap: 8px; }
.compte-ligne { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border: 1px solid var(--trait); border-radius: 10px; color: var(--texte); font-size: 14px; }
.compte-ligne span { flex: 1; min-width: 0; }
.compte-ligne small { color: var(--texte-3); }
.nav .libelle small { color: var(--texte-2); font-size: 12px; }

/* ---------- Assignation ---------- */
.ligne-meta .assigne { color: var(--accent); font-weight: 500; }
.ligne.choisie .ligne-meta .assigne { color: inherit; }

/* ---------- Équipes, pôles, assignés ---------- */
.assignes, .choix-poles { display: flex; flex-wrap: wrap; gap: 6px; }
.choix-poles { flex-direction: column; gap: 8px; }
.groupe-poles { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; border: 0; }
.groupe-poles legend { width: 100%; padding: 0 0 4px; font-size: 12px; color: var(--texte-2); text-align: left; }
.puce {
  display: inline-flex;
  align-items: center;
  padding: 5px 11px;
  border: 1px solid var(--trait);
  border-radius: 999px;
  background: var(--surface);
  color: var(--texte);
  font-size: 13px;
  position: relative;
  cursor: pointer;
  user-select: none;
}
.puce input { position: absolute; opacity: 0; pointer-events: none; }
.puce.cochee { border-color: var(--accent); background: var(--accent-doux); color: var(--accent); font-weight: 600; }
.puce:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.champ.verrouille { opacity: 0.55; pointer-events: none; }
.ajout select {
  max-width: 45%;
  padding: 3px 6px;
  border: 1px solid var(--trait);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent);
  font-size: 13px;
}
.badge.qui { color: var(--accent); }

/* Sous-tâches dans la fenêtre de création */
#lignes-sous { display: flex; flex-direction: column; gap: 6px; }
.ligne-creation { display: grid; grid-template-columns: 1fr auto auto 32px; gap: 6px; align-items: center; }
.ligne-creation input, .ligne-creation select {
  min-width: 0;
  padding: 8px 9px;
  border: 1px solid var(--trait);
  border-radius: 8px;
  background: var(--surface);
  color: var(--texte);
  font-size: 14px;
}
.ligne-creation select { max-width: 150px; color: var(--accent); }
.ligne-creation [hidden] { display: none; }
.ligne-creation .st-pole { min-width: 0; font-size: 12px; color: var(--texte-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 90px; }
#pole-calcule { color: var(--texte-2); font-size: 12px; }
.ligne-creation .st-suppr { width: 32px; height: 32px; color: var(--texte-3); }
.ajout-ligne { align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; color: var(--accent); }
@media (max-width: 560px) {
  .ligne-creation { grid-template-columns: 1fr 1fr 32px; }
  .ligne-creation .st-titre { grid-column: 1 / -1; }
}

/* Tri dans un pôle */
.tete .tri {
  padding: 5px 8px;
  border: 1px solid var(--trait);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent);
  font-size: 13px;
}
