:root {
  --fond: #f6f7f9;
  --carte: #ffffff;
  --texte: #1f2933;
  --doux: #66727f;
  --trait: #dde2e8;
  --accent: #2f6fdb;
  --fait: #2e8b57;
  --rouge: #d93636;
  --passe: #8a96a3;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #121519;
    --carte: #1c2127;
    --texte: #e6e9ed;
    --doux: #98a3ae;
    --trait: #2c333b;
    --accent: #6b9cf0;
    --fait: #4cb57d;
    --rouge: #f06a6a;
    --passe: #6e7a86;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

/* Connexion */
#ecran-connexion { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
#form-connexion {
  width: min(360px, 100%);
  background: var(--carte);
  border: 1px solid var(--trait);
  border-radius: 12px;
  padding: 24px;
  display: grid;
  gap: 14px;
}
#form-connexion h1 { margin: 0; text-align: center; }
#form-connexion label { display: grid; gap: 4px; color: var(--doux); font-size: 14px; }
#form-connexion input {
  font: inherit; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--trait); background: var(--fond); color: var(--texte);
}
#form-connexion button[type=submit] {
  padding: 11px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600;
}
.erreur { color: var(--rouge); margin: 0; min-height: 1.4em; font-size: 14px; }

/* Journée */
#ecran-jour { max-width: 720px; margin: 0 auto; padding: 0 16px 32px; }
#ecran-jour > header {
  position: sticky; top: 0; z-index: 1;
  background: var(--fond);
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 0 10px;
}
#titre-jour { margin: 0; font-size: 22px; }
#avancement { margin: 2px 0 0; color: var(--doux); font-size: 14px; }
#hors-ligne {
  font-size: 13px; padding: 3px 10px; border-radius: 999px;
  background: var(--passe); color: #fff;
}

.bloc { margin-top: 18px; }
.bloc h2 {
  font-size: 15px; font-weight: 600;
  color: var(--doux); margin: 0 0 6px; display: flex; justify-content: space-between;
}
.bloc ul {
  list-style: none; margin: 0; padding: 0;
  background: var(--carte); border: 1px solid var(--trait); border-radius: 12px; overflow: hidden;
}
.tache {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-top: 1px solid var(--trait);
  min-height: 52px;
}
.tache:first-child { border-top: 0; }
.tache.rouge { box-shadow: inset 4px 0 0 var(--rouge); }
.tache .libelle { flex: 1; }
.tache .heure { color: var(--doux); font-size: 13px; font-variant-numeric: tabular-nums; }
.tache.close .libelle { color: var(--doux); }
.tache.fait .libelle { text-decoration: line-through; }

.case {
  width: 30px; height: 30px; flex: none;
  border: 2px solid var(--trait); border-radius: 8px; background: transparent;
  display: grid; place-items: center; padding: 0;
}
.case svg { width: 18px; height: 18px; visibility: hidden; }
.tache.fait .case { background: var(--fait); border-color: var(--fait); color: #fff; }
.tache.fait .case svg { visibility: visible; }

.choix { display: flex; gap: 6px; flex: none; }
.choix button {
  border: 1px solid var(--trait); background: transparent; border-radius: 8px;
  padding: 6px 10px; font-size: 14px; min-height: 36px;
}
.choix button.actif { color: #fff; border-color: transparent; }
.choix button.actif[data-statut=fait], .choix button.actif[data-statut=oui] { background: var(--fait); }
.choix button.actif[data-statut=pas_besoin], .choix button.actif[data-statut=non] { background: var(--passe); }

footer { margin-top: 28px; display: flex; justify-content: center; gap: 20px; }
.lien { border: 0; background: none; color: var(--accent); font-size: 14px; }

dialog {
  border: 1px solid var(--trait); border-radius: 12px;
  background: var(--carte); color: var(--texte);
  width: min(420px, calc(100% - 32px));
}
dialog h2 { margin-top: 0; font-size: 18px; }
#liste-appareils { list-style: none; padding: 0; margin: 0 0 16px; }
#liste-appareils li {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 0; border-top: 1px solid var(--trait);
}
#liste-appareils small { color: var(--doux); display: block; }
#liste-appareils button, dialog form button {
  border: 1px solid var(--trait); background: transparent; border-radius: 8px; padding: 6px 10px;
}

/* Notifications */
.actions { display: flex; align-items: center; gap: 8px; }
.icone {
  width: 40px; height: 40px; border-radius: 10px; padding: 8px;
  border: 1px solid var(--trait); background: var(--carte);
}
.icone svg { width: 100%; height: 100%; }
.icone.en-pause { color: var(--passe); }
#bandeau-pause {
  margin: 0 0 4px; padding: 8px 12px; border-radius: 8px; font-size: 14px;
  background: var(--carte); border: 1px solid var(--trait); color: var(--doux);
}
#dialogue-notifs h3 { font-size: 15px; margin: 20px 0 6px; }
#dialogue-notifs p { margin: 0 0 10px; color: var(--doux); font-size: 14px; }
#dialogue-notifs button {
  border: 1px solid var(--trait); background: transparent; border-radius: 8px; padding: 8px 12px; margin: 0 6px 6px 0;
}
#dialogue-notifs button.principal { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
#dialogue-notifs button.lien { border: 0; padding-left: 0; color: var(--accent); }
.pause-heure { display: inline-flex; gap: 6px; align-items: start; }
.pause-heure input {
  font: inherit; padding: 6px 8px; border-radius: 8px; height: 40px;
  border: 1px solid var(--trait); background: var(--fond); color: var(--texte);
}

/* Mode du jour */
.puce {
  margin-top: 6px; padding: 3px 10px; border-radius: 999px; font-size: 13px;
  border: 1px solid var(--trait); background: var(--carte); color: var(--doux);
}
#choix-mode {
  background: var(--carte); border: 1px solid var(--trait); border-radius: 12px;
  padding: 12px; margin-top: 6px;
}
#choix-mode h2 { margin: 0 0 8px; font-size: 15px; }
.modes { display: grid; gap: 8px; }
.modes button {
  text-align: left; padding: 12px; border-radius: 10px; min-height: 48px;
  border: 1px solid var(--trait); background: var(--fond);
}
.modes button.actif { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
#message-jour:empty { display: none; }
#message-jour { margin-top: 8px; }

/* Blocs passés, reportées, jour « pas chez moi » */
.bloc.passe h2 { cursor: pointer; }
.bloc.passe h2 span:first-child::after { content: " ▸"; }
.bloc.passe h2[aria-expanded="true"] span:first-child::after { content: " ▾"; }
.origine { display: block; color: var(--doux); font-size: 12px; text-decoration: none; }
.tache.secondaire { opacity: .55; }
.retour {
  display: flex; align-items: center; gap: 12px; margin-bottom: 8px; color: var(--doux); font-size: 14px;
}
.retour .principal {
  border: 0; border-radius: 10px; padding: 10px 16px; background: var(--accent); color: #fff; font-weight: 600;
}

/* Statistiques */
#ecran-stats { max-width: 720px; margin: 0 auto; padding: 0 16px 32px; }
#ecran-stats > header { padding: 12px 0 4px; }
#ecran-stats > header .lien { padding: 4px 0; font-size: 15px; }
#ecran-stats h1 { margin: 4px 0 0; font-size: 22px; }
#ecran-stats h2 { font-size: 15px; font-weight: 600; color: var(--doux); margin: 24px 0 8px; }
#stats-message:empty { display: none; }
.tuiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.tuile {
  background: var(--carte); border: 1px solid var(--trait); border-radius: 12px; padding: 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.tuile .valeur { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tuile .nom { font-size: 12px; color: var(--doux); line-height: 1.3; }
.graphique { background: var(--carte); border: 1px solid var(--trait); border-radius: 12px; padding: 4px 12px 10px; margin-top: 16px; }
.graphique h2 { margin-top: 10px; }
#detail-jour { margin: 0 0 8px; font-size: 14px; min-height: 1.4em; }
#barres {
  height: 120px; display: flex; align-items: flex-end; gap: 2px; padding-right: 40px;
  border-bottom: 1px solid var(--trait);
  background-image: linear-gradient(var(--trait) 1px, transparent 1px);
  background-size: calc(100% - 40px) 50%; background-repeat: repeat-y; background-position: 0 0;
}
.barre {
  flex: 1; height: 100%; display: flex; align-items: flex-end; padding: 0;
  border: 0; background: transparent; cursor: pointer;
}
.barre span { display: block; width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.barre.partiel span { opacity: .45; }
.barre.avant { cursor: default; }
.barre.avant span { display: none; }
.zone-barres { position: relative; }
.graduation {
  position: absolute; right: 0; transform: translateY(-50%); padding-left: 4px;
  font-size: 11px; color: var(--doux); background: var(--carte); line-height: 1;
}
.barre.non-suivi span { background: transparent; border: 1px dashed var(--passe); border-bottom: 0; height: 6px; }
.barre.choisie span { outline: 2px solid var(--texte); outline-offset: 1px; }
.axe { display: flex; justify-content: space-between; font-size: 12px; color: var(--doux); margin-top: 4px; }
.note { font-size: 13px; color: var(--doux); margin: 0 0 8px; }
#table-taches {
  width: 100%; border-collapse: collapse; font-size: 14px;
  background: var(--carte); border: 1px solid var(--trait); border-radius: 12px; overflow: hidden;
}
#table-taches th, #table-taches td { padding: 8px 6px; border-top: 1px solid var(--trait); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
#table-taches td:first-child { white-space: normal; }
#table-taches th:first-child, #table-taches td:first-child { text-align: left; padding-left: 10px; }
#table-taches thead th { border-top: 0; color: var(--doux); font-weight: 600; font-size: 13px; }
#table-taches tr.titre-bloc td { background: var(--fond); color: var(--doux); font-weight: 600; font-size: 13px; }
#table-taches td.rouge { box-shadow: inset 4px 0 0 var(--rouge); }
#table-taches .meilleure { color: var(--doux); font-size: 12px; }
@media (max-width: 420px) {
  .tuile .valeur { font-size: 20px; }
  #table-taches { font-size: 13px; }
  #table-taches th, #table-taches td { padding: 7px 4px; }
}

/* Édition de la routine */
#ecran-edition { max-width: 720px; margin: 0 auto; padding: 0 16px 32px; }
#ecran-edition > header { padding: 12px 0 4px; }
#ecran-edition > header .lien { padding: 4px 0; font-size: 15px; }
#ecran-edition h1 { margin: 4px 0 8px; font-size: 22px; }
#edition-message:empty, #tache-message:empty { display: none; }
.ligne-edition { display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 12px; border-top: 1px solid var(--trait); min-height: 52px; }
.ligne-edition:first-child { border-top: 0; }
.ligne-edition.rouge { box-shadow: inset 4px 0 0 var(--rouge); }
.ligne-edition .ouvrir { flex: 1; text-align: left; border: 0; background: none; padding: 4px 0; }
.ligne-edition .ouvrir small { display: block; color: var(--doux); font-size: 12px; }
.fleche { width: 36px; height: 36px; border: 1px solid var(--trait); border-radius: 8px; background: transparent; flex: none; }
.fleche:disabled { opacity: .3; cursor: default; }
.ajouter { margin-top: 8px; border: 1px dashed var(--trait); background: transparent; border-radius: 10px; padding: 10px; width: 100%; color: var(--accent); }
#dialogue-tache { width: min(520px, calc(100% - 32px)); }
#form-tache h2 { margin: 0 0 12px; }
.champ { display: grid; gap: 4px; font-size: 13px; color: var(--doux); margin-bottom: 10px; }
.champ input, .champ select, fieldset select, .minutes input {
  font: inherit; font-size: 15px; color: var(--texte); background: var(--fond);
  border: 1px solid var(--trait); border-radius: 8px; padding: 8px 10px; min-height: 40px; width: 100%;
}
.deux-colonnes { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
fieldset { border: 1px solid var(--trait); border-radius: 10px; margin: 0 0 10px; padding: 6px 10px 10px; }
legend { font-size: 13px; color: var(--doux); padding: 0 4px; }
.minutes { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--doux); }
.minutes input { width: 80px; }
.coche { display: flex; gap: 8px; align-items: center; font-size: 14px; margin: 8px 0; }
.coche input { width: 18px; height: 18px; }
.actions-dialogue { display: flex; gap: 8px; margin-top: 14px; align-items: center; }
.actions-dialogue span { flex: 1; }
.actions-dialogue button { border: 1px solid var(--trait); background: transparent; border-radius: 8px; padding: 9px 14px; }
.actions-dialogue .principal { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.actions-dialogue .danger { color: var(--rouge); border-color: transparent; padding-left: 0; }
@media (max-width: 420px) { .deux-colonnes { grid-template-columns: 1fr; } }
