:root {
  --fond: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --bord: #dde1e7;
  --texte: #1d2330;
  --texte-2: #5d6676;
  --accent: #3b62d8;
  --accent-doux: #e8eefc;
  --ok: #1f8a4c;
  --ok-doux: #e3f4ea;
  --alerte: #c2410c;
  --alerte-doux: #fdeee6;
  --danger: #c0283a;
  --routine: #7a4fd0;
  --ombre: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  --rayon: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --fond: #13161c; --surface: #1b1f27; --surface-2: #232834; --bord: #313847; --texte: #e6e9ef; --texte-2: #9aa3b2;
    --accent: #7c9cf5; --accent-doux: #222c47; --ok: #4cc283; --ok-doux: #19301f; --alerte: #f08a4b; --alerte-doux: #3a2418;
    --danger: #f06272; --routine: #b294f2; --ombre: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --fond: #13161c; --surface: #1b1f27; --surface-2: #232834; --bord: #313847; --texte: #e6e9ef; --texte-2: #9aa3b2;
  --accent: #7c9cf5; --accent-doux: #222c47; --ok: #4cc283; --ok-doux: #19301f; --alerte: #f08a4b; --alerte-doux: #3a2418;
  --danger: #f06272; --routine: #b294f2; --ombre: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 30%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--fond); color: var(--texte); font: 14px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.cache { display: none !important; }

/* ---------- Mise en page ---------- */
/* dvh : la hauteur visible réelle sur téléphone (sans la barre du navigateur), sinon le menu du bas passe dessous. */
.app { display: grid; grid-template-columns: 210px 1fr; height: 100vh; height: 100dvh; }
.menu { background: var(--surface); border-right: 1px solid var(--bord); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.menu h1 { font-size: 15px; margin: 0 10px 14px; }
.menu button { display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: var(--rayon); }
.menu button:hover { background: var(--surface-2); }
.menu button[aria-current='page'] { background: var(--accent-doux); color: var(--accent); font-weight: 600; }
.menu .touche { color: var(--texte-2); font-size: 11px; }
.menu .compteur { background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; font-weight: 600; }
.principal { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.barre { display: flex; gap: 8px; padding: 12px 20px; border-bottom: 1px solid var(--bord); background: var(--surface); }
.barre input { flex: 1; padding: 9px 12px; border: 1px solid var(--bord); border-radius: var(--rayon); background: var(--fond); }
.barre input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.corps { flex: 1; display: flex; min-height: 0; }
#contenu { flex: 1; overflow-y: auto; padding: 20px 24px 60px; min-width: 0; }
#detail { width: 380px; border-left: 1px solid var(--bord); background: var(--surface); overflow-y: auto; padding: 18px; flex-shrink: 0; }

/* ---------- Éléments communs ---------- */
.entete { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.entete h2 { margin: 0; font-size: 20px; }
.entete .espace { flex: 1; }
.bouton { border: 1px solid var(--bord); background: var(--surface); padding: 5px 11px; border-radius: var(--rayon); white-space: nowrap; }
.bouton:hover { background: var(--surface-2); }
.bouton.principal-b { background: var(--accent); color: #fff; border-color: var(--accent); }
.bouton.danger { color: var(--danger); }
.bouton.petit { padding: 2px 8px; font-size: 12px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--surface-2); color: var(--texte-2); white-space: nowrap; }
.badge.routine { color: var(--routine); }
.badge.haute, .badge.critique { background: var(--alerte-doux); color: var(--alerte); }
.badge.critique { font-weight: 700; }
.vide { color: var(--texte-2); padding: 18px 4px; }
.carte { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); padding: 14px 16px; margin-bottom: 14px; }
.carte h3 { margin: 0 0 10px; font-size: 14px; }
.discret { color: var(--texte-2); font-size: 12px; }

/* Charge du jour */
.charge { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); padding: 12px 16px; margin-bottom: 16px; }
.charge .chiffre { font-size: 18px; font-weight: 650; }
.charge .libelle { font-size: 12px; color: var(--texte-2); }
.jauge { flex: 1; min-width: 160px; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.jauge > div { height: 100%; background: var(--ok); }
.charge.plein .jauge > div { background: var(--alerte); }
.charge.plein .libre .chiffre, .alerte-texte { color: var(--alerte); }

/* Liste de tâches (Ma journée, Inbox…) */
.journee { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }
.creneau-titre { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--texte-2); margin: 16px 0 6px; }
.liste { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); }
/* Les badges et les boutons passent à la ligne plutôt que d'écraser le titre (téléphone, écran étroit). */
.ligne { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 8px 12px; border-top: 1px solid var(--bord); }
.ligne:first-child { border-top: 0; }
.ligne:hover { background: var(--surface-2); }
.ligne.choisie { background: var(--accent-doux); box-shadow: inset 3px 0 var(--accent); }
.ligne .titre { flex: 1 1 160px; min-width: 0; cursor: pointer; overflow-wrap: break-word; }
.ligne.faite .titre { text-decoration: line-through; color: var(--texte-2); }
.ligne.manquee .titre { color: var(--texte-2); font-style: italic; }
.ligne .heure { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--accent); min-width: 40px; }
.ligne .actions { display: flex; flex-wrap: wrap; gap: 4px; opacity: 0; }
.ligne:hover .actions, .ligne.choisie .actions, .ligne:focus-within .actions { opacity: 1; }
.case { width: 18px; height: 18px; accent-color: var(--ok); flex-shrink: 0; cursor: pointer; }
.routine-marque { color: var(--routine); font-size: 13px; }
.suggestions h3 { font-size: 13px; margin: 14px 0 6px; color: var(--texte-2); }
.suggestions h3:first-child { margin-top: 0; }

/* Tableau (Ma semaine) */
.jour-groupe { margin-bottom: 18px; }
.jour-entete { display: flex; align-items: baseline; gap: 12px; margin: 0 0 6px; }
.jour-entete h3 { margin: 0; font-size: 15px; }
.jour-entete.aujourdhui h3 { color: var(--accent); }
.jour-entete.plein .resume { color: var(--alerte); font-weight: 600; }
.tableau-boite { overflow-x: auto; width: fit-content; max-width: 100%; background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); }
.jour-groupe.depot .tableau-boite { outline: 2px dashed var(--accent); }
/* Largeurs fixées par les <col> (réglables à la souris) : le contenu ne les fait pas bouger. */
table.tableau { border-collapse: collapse; table-layout: fixed; }
.tableau th { position: relative; text-align: left; font-size: 11px; font-weight: 600; color: var(--texte-2); padding: 6px 12px 6px 8px; border-bottom: 1px solid var(--bord); background: var(--surface-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tableau td { padding: 3px 6px; border-top: 1px solid var(--bord); vertical-align: middle; overflow: hidden; }
.poignee { position: absolute; top: 0; right: 0; width: 12px; height: 100%; cursor: col-resize; touch-action: none; border-right: 2px solid transparent; }
.poignee:hover, body.redimension .poignee { border-right-color: var(--accent); }
body.redimension { cursor: col-resize; user-select: none; }
.tableau tr:first-child td { border-top: 0; }
.tableau tr.faite .c-titre { text-decoration: line-through; color: var(--texte-2); }
.tableau tr.choisie td { background: var(--accent-doux); }
.tableau tr[draggable='true'] { cursor: grab; }
.tableau input, .tableau select { border: 1px solid transparent; background: transparent; padding: 3px 4px; border-radius: 5px; width: 100%; }
.tableau input:hover, .tableau select:hover { border-color: var(--bord); }
.tableau input:focus, .tableau select:focus { border-color: var(--accent); outline: none; background: var(--surface); }
.tableau tfoot td { font-size: 12px; color: var(--texte-2); background: var(--surface-2); padding: 6px 8px; }
.ajout-ligne input { border: 1px dashed var(--bord) !important; }
.filtres { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.filtres select { padding: 3px 6px; border: 1px solid var(--bord); border-radius: 6px; background: var(--surface); }
details.colonnes summary { cursor: pointer; }
details.colonnes > div { position: absolute; background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); padding: 8px 12px; box-shadow: var(--ombre); z-index: 5; display: grid; gap: 4px; }

/* Formulaires (détail, routine, réglages) */
.champ { display: grid; gap: 4px; margin-bottom: 10px; }
.champ > span { font-size: 12px; color: var(--texte-2); }
.champ input, .champ select, .champ textarea { padding: 6px 8px; border: 1px solid var(--bord); border-radius: 6px; background: var(--fond); width: 100%; }
.champ textarea { min-height: 90px; resize: vertical; }
.deux { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.jours-choix { display: flex; gap: 4px; flex-wrap: wrap; }
.jours-choix label { border: 1px solid var(--bord); border-radius: 6px; padding: 3px 8px; cursor: pointer; user-select: none; }
.jours-choix input { display: none; }
.jours-choix label:has(input:checked) { background: var(--accent); color: #fff; border-color: var(--accent); }
.etape { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.etape span { flex: 1; }
.etape.faite span { text-decoration: line-through; color: var(--texte-2); }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--bord); }
.fermer { float: right; border: 0; background: none; font-size: 20px; line-height: 1; color: var(--texte-2); }
.inline { display: flex; gap: 6px; align-items: center; }
.inline input { padding: 4px 8px; border: 1px solid var(--bord); border-radius: 6px; background: var(--fond); }

/* Message en bas d'écran */
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--texte); color: var(--fond); padding: 10px 16px; border-radius: var(--rayon); box-shadow: var(--ombre); display: flex; gap: 14px; align-items: center; z-index: 20; max-width: min(92vw, 640px); }
#toast button { background: none; border: 0; color: var(--accent-doux); font-weight: 600; text-decoration: underline; }
#toast .alerte-texte { color: #ffb38a; }

/* Connexion */
.connexion { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.connexion form { background: var(--surface); border: 1px solid var(--bord); border-radius: 12px; padding: 28px; width: min(360px, 100%); box-shadow: var(--ombre); }
.connexion h1 { font-size: 18px; margin: 0 0 18px; }
.erreur { color: var(--danger); min-height: 20px; margin: 8px 0; }

/* ---------- Téléphone ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .menu { grid-row: 2; flex-direction: row; overflow-x: auto; border-right: 0; border-top: 1px solid var(--bord); padding: 6px; }
  .menu h1, .menu .touche { display: none; }
  .menu button { width: auto; flex-direction: column; gap: 0; font-size: 12px; padding: 6px 10px; }
  .barre { padding: 10px 12px; }
  #contenu { padding: 14px 16px 40px; }
  .journee { grid-template-columns: 1fr; }
  #detail { position: fixed; inset: 0; width: auto; z-index: 15; }
  .ligne .actions { opacity: 1; }
}
#recherche { flex: 0 1 200px; }
#envoyer { width: 100%; }
.tableau .c-titre .inline { width: 100%; }
.tableau .c-titre .inline input { flex: 1; min-width: 0; }

/* ---------- Barre de filtres, tri et vues ---------- */
.barre-filtres { padding: 10px 12px; }
.barre-ligne { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.barre-ligne select { padding: 4px 6px; border: 1px solid var(--bord); border-radius: 6px; background: var(--surface); }
.recherche-vue { padding: 5px 10px; border: 1px solid var(--bord); border-radius: var(--rayon); background: var(--fond); min-width: 220px; }
.recherche-vue:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.bouton.actif, .bouton[aria-expanded='true'] { background: var(--accent-doux); color: var(--accent); border-color: var(--accent); font-weight: 600; }
.panneau { margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--bord); display: grid; gap: 16px; }
.panneau h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--texte-2); }
.rapides { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px 18px; }
.rapide-titre { font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.puces { display: flex; flex-wrap: wrap; gap: 4px; }
.puce { border: 1px solid var(--bord); background: var(--surface); border-radius: 14px; padding: 2px 10px; font-size: 12px; display: inline-flex; gap: 6px; align-items: center; }
.puce:hover { border-color: var(--accent); }
.puce.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.puce .compte { opacity: .7; font-size: 11px; }
.regle { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.regle select, .regle input { padding: 4px 6px; border: 1px solid var(--bord); border-radius: 6px; background: var(--fond); }
.regle-lien { min-width: 58px; }
.vue-ligne { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; flex-wrap: wrap; }
.th-texte.triable { cursor: pointer; }
.th-texte.triable:hover { color: var(--texte); text-decoration: underline; }
.th-texte .sens { color: var(--accent); font-weight: 700; }
details.colonnes { position: relative; }
.manquee-marque { color: var(--alerte); font-weight: 700; padding-left: 4px; }
.tableau tr.manquee .c-titre input { color: var(--texte-2); font-style: italic; }
