:root {
  --fond: #11141b;
  --fond2: #171b24;
  --fond3: #1e2430;
  --bord: #2a3140;
  --texte: #e6e9ef;
  --doux: #8d97a8;
  --accent: #6ea8fe;
  --alerte: #ff6b6b;
  --rail: 320px;
  --heure: 56px;   /* hauteur d'une heure */
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  display: flex;
  height: 100vh;
  height: 100dvh;   /* telephone : la barre d'adresse ne rogne plus la grille */
  overflow: hidden;
  background: var(--fond);
  color: var(--texte);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
}

/* ------------------------------------------------------------------ rail */

.rail {
  width: var(--rail);
  flex: 0 0 var(--rail);
  background: var(--fond2);
  border-right: 1px solid var(--bord);
  display: flex;
  flex-direction: column;
  padding: 18px 16px;
  gap: 18px;
  overflow: hidden;
}

.titre-rail { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.fermer-rail { display: none; }   /* seulement dans le tiroir, sur telephone */
.rail h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: .2px; }
.rail h1 span { color: var(--doux); font-weight: 400; }

[hidden] { display: none !important; }   /* sinon .bloc { display:flex } l'emporte */
.bloc { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.bloc.grow { flex: 1; min-height: 0; }

.lab { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--doux); }
.lab-row { display: flex; justify-content: space-between; align-items: center; }

input[type=text] {
  background: var(--fond3);
  border: 1px solid var(--bord);
  border-radius: 8px;
  color: var(--texte);
  padding: 9px 11px;
  font-size: 14px;
  outline: none;
}
input[type=text]:focus { border-color: var(--accent); }

.segmented { display: flex; gap: 4px; background: var(--fond3); padding: 3px; border-radius: 8px; }
.seg {
  flex: 1; border: 0; background: transparent; color: var(--doux);
  padding: 5px 0; border-radius: 6px; cursor: pointer; font-size: 12px;
}
.seg.on { background: var(--bord); color: var(--texte); }

.resultats {
  list-style: none; margin: 0; padding: 4px;
  background: var(--fond3); border: 1px solid var(--bord); border-radius: 8px;
  max-height: 260px; overflow: auto;
}
.resultats li { padding: 7px 9px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.resultats li:hover, .resultats li.actif { background: var(--bord); }
.resultats li small { display: block; color: var(--doux); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.resultats .rien { color: var(--doux); cursor: default; }

.matieres { list-style: none; margin: 0; padding: 0; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.matiere {
  display: flex; align-items: center; gap: 9px;
  background: var(--fond3); border: 1px solid var(--bord);
  border-radius: 8px; padding: 8px 9px;
}
.matiere.off { opacity: .42; }
.matiere.perdue .txt small { color: var(--alerte); }
.pastille { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.matiere .txt { flex: 1; min-width: 0; }
.matiere .txt b { display: block; font-size: 12.5px; font-weight: 600; }
.matiere .txt small { display: block; color: var(--doux); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.matiere button { background: none; border: 0; color: var(--doux); cursor: pointer; font-size: 14px; padding: 2px 4px; border-radius: 4px; }
.matiere button:hover { color: var(--texte); background: var(--bord); }

/* ------------------------------------------------- dossiers (UE, ordinateur) */

.lab-row .liens { display: flex; gap: 10px; }
.dossier { display: flex; flex-direction: column; gap: 6px; }
.tete-dossier {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--fond2); border: 1px solid var(--bord); border-radius: 8px; padding: 7px 9px;
}
.tete-dossier:hover { background: var(--fond3); }
.tete-dossier b { flex: 1; min-width: 0; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tete-dossier .fleche { color: var(--doux); font-size: 10px; transition: transform .15s ease; }
.dossier.ferme .tete-dossier .fleche { transform: rotate(-90deg); }
.tete-dossier .compte { color: var(--doux); font-size: 11px; }
.tete-dossier button { background: none; border: 0; color: var(--doux); cursor: pointer; font-size: 14px; padding: 2px 4px; border-radius: 4px; }
.tete-dossier button:hover { color: var(--texte); background: var(--bord); }
.tete-dossier .oeil { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; padding: 0; }
.nom-dossier { flex: 1; min-width: 0; padding: 4px 6px; font-size: 12.5px; }

.dans-dossier { list-style: none; margin: 0; padding: 0 0 0 14px; display: flex; flex-direction: column; gap: 6px; border-left: 1px solid var(--bord); margin-left: 8px; }
.dossier.ferme .dans-dossier { display: none; }
.vide-dossier, .hors-dossier { color: var(--doux); font-size: 11px; padding: 7px 9px; border: 1px dashed var(--bord); border-radius: 8px; text-align: center; }

/* cible de depot pendant un glisser-deposer */
.tete-dossier.survol, .dans-dossier.survol, .hors-dossier.survol { border-color: var(--accent); background: rgba(110, 168, 254, .1); }
.dans-dossier.survol { border-left-color: var(--accent); }
.matiere.glissee { opacity: .4; }
.matiere[draggable=true] { cursor: grab; }
.matiere .oeil { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; padding: 0; border-radius: 6px; }
.matiere .oeil svg { display: block; }
.matiere:not(.off) .oeil { color: var(--accent); }
.matiere .oeil:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.vide { color: var(--doux); font-size: 12.5px; margin: 4px 0 0; }
.lien { background: none; border: 0; color: var(--doux); cursor: pointer; font-size: 11px; text-decoration: underline; padding: 0; }

.actions { gap: 8px; }
.case { display: flex; gap: 8px; align-items: flex-start; font-size: 11.5px; color: var(--doux); cursor: pointer; line-height: 1.35; }
.case input { margin: 1px 0 0; accent-color: var(--accent); flex: 0 0 auto; cursor: pointer; }
.case b { color: var(--texte); font-weight: 600; }
.btn {
  background: var(--accent); color: #0b1020; border: 0; border-radius: 8px;
  padding: 9px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: default; filter: none; }
.btn.ghost { background: transparent; border: 1px solid var(--bord); color: var(--texte); font-weight: 500; }
.btn.mini { padding: 5px 10px; font-size: 12px; }
.btn.mini .icone { display: none; }   /* remplace le texte sur telephone */

/* ---------------------------------------------------------------- compte */

.compte { gap: 6px; }
.compte .vide { margin: 0; font-size: 11.5px; }
.btn.google {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  background: var(--fond3); color: var(--texte); border: 1px solid var(--bord); font-weight: 500;
}
.btn.google:hover { background: var(--bord); filter: none; }
.btn.google svg { flex: 0 0 auto; }
.profil {
  display: flex; align-items: center; gap: 9px;
  background: var(--fond3); border: 1px solid var(--bord); border-radius: 8px; padding: 7px 9px;
}
.profil .avatar { width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto; object-fit: cover; }
.profil .avatar.initiale {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #0b1020; font-size: 12px; font-weight: 700;
}
.profil .txt { flex: 1; min-width: 0; }
.profil .txt b { display: block; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profil .txt small { display: block; color: var(--doux); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profil .lien { flex: 0 0 auto; }

/* ------------------------------------------------------------------ vue */

.vue { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.barre {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--bord); gap: 16px;
}
.nav { display: flex; align-items: center; gap: 10px; }
.rond.menu { display: none; font-size: 15px; }   /* ouvre le tiroir, sur telephone */
.rond {
  width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--bord);
  background: var(--fond2); color: var(--texte); cursor: pointer; font-size: 16px; line-height: 1;
}
.rond:hover { background: var(--fond3); }
.periode { min-width: 240px; }
.periode strong { display: block; font-size: 15px; }
.periode span { color: var(--doux); font-size: 12px; }
.etat { color: var(--doux); font-size: 12px; }

.alerte {
  margin: 12px 20px 0; padding: 10px 14px; border-radius: 8px;
  background: rgba(255, 107, 107, .12); border: 1px solid rgba(255, 107, 107, .4);
  color: #ffd0d0; font-size: 13px;
}
.alerte b { color: #fff; }
.alerte.douce { background: var(--fond3); border-color: var(--bord); }
.alerte.douce b { color: var(--texte); }
.alerte .note { color: var(--doux); font-style: italic; }
.alerte ul { margin: 6px 0 0; padding-left: 18px; }

/* ------------------------------------------------- barre de jours (mobile) */

.rangee-jours { display: flex; align-items: center; gap: 8px; padding: 10px 10px 0; }
.rangee-jours .rond { flex: 0 0 auto; }
.jours { display: flex; gap: 6px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.jours::-webkit-scrollbar { display: none; }
.jour-chip {
  flex: 1 1 0; min-width: 40px; padding: 7px 4px; border-radius: 10px; cursor: pointer;
  background: var(--fond2); border: 1px solid var(--bord); color: var(--doux);
  font-size: 11px; text-align: center; line-height: 1.2;
}
.jour-chip b { display: block; color: var(--texte); font-size: 13px; font-weight: 600; text-transform: capitalize; }
.jour-chip.on { background: var(--accent); border-color: var(--accent); color: #0b1020; }
.jour-chip.on b { color: #0b1020; }
.jour-chip.today:not(.on) b { color: var(--accent); }
.jour-chip .pastilles { display: flex; gap: 3px; justify-content: center; margin-top: 4px; height: 5px; }
.jour-chip .pt { width: 5px; height: 5px; border-radius: 50%; }
.jour-chip .pt.conflit { background: var(--alerte); }

/* ---------------------------------------------------------------- grille */

.grille { flex: 1; overflow: auto; padding: 14px 20px 28px; }
.placeholder { color: var(--doux); padding: 40px 0; text-align: center; }
.placeholder h2 { color: var(--texte); font-size: 17px; margin: 0 0 6px; }
.placeholder p { margin: 0 0 14px; font-size: 13px; }
.placeholder .btn.google { display: inline-flex; margin: 0 auto; }

.tableau { display: grid; grid-template-columns: 56px repeat(var(--jours), minmax(120px, 1fr)); gap: 0; min-width: 100%; }

.entete { position: sticky; top: 0; z-index: 3; background: var(--fond); padding-bottom: 6px; }
.entete .jour { font-size: 12px; color: var(--doux); text-align: center; padding: 4px 0; border-bottom: 1px solid var(--bord); }
.entete .jour b { display: block; color: var(--texte); font-size: 13px; font-weight: 600; text-transform: capitalize; }
.entete .jour.today b { color: var(--accent); }

/* La 1re etiquette (translateY(-50%)) deborde au-dessus de la colonne :
   on decale toute la rangee pour qu'elle ne passe pas sous l'en-tete collant. */
.colheures, .colonne { margin-top: 9px; }
.colheures { position: relative; }
.colheures .h {
  position: absolute; right: 8px; transform: translateY(-50%);
  font-size: 11px; color: var(--doux);
}

.colonne { position: relative; border-left: 1px solid var(--bord); }
.colonne:last-child { border-right: 1px solid var(--bord); }
.colonne.week-end { background: rgba(255,255,255,.014); }
.ligne { position: absolute; left: 0; right: 0; border-top: 1px solid var(--bord); }
.ligne.demi { border-top-style: dotted; opacity: .45; }

.cours {
  position: absolute; border-radius: 6px; padding: 5px 7px; overflow: hidden;
  font-size: 11.5px; cursor: pointer; border-left: 3px solid;
  /* fond opaque : la teinte de la matiere posee sur le fond de la page, sinon
     les lignes d'heures traversent le titre du cours */
  background-color: var(--fond);
  background-image: linear-gradient(var(--c-fond), var(--c-fond));
  border-color: var(--c-vif);
  color: #f2f5fa;
}
.cours:hover { filter: brightness(1.15); z-index: 2; }
.cours .h { font-weight: 600; font-size: 10.5px; opacity: .85; }
.cours .t { font-weight: 600; margin: 1px 0; line-height: 1.25; }
.cours .d { color: rgba(255,255,255,.72); line-height: 1.3; }
.cours.conflit { outline: 2px solid var(--alerte); outline-offset: -2px; }
.cours.annule { opacity: .5; text-decoration: line-through; }
.badge-conflit {
  position: absolute; top: 3px; right: 4px; font-size: 10px;
  background: var(--alerte); color: #2a0000; border-radius: 4px; padding: 0 4px; font-weight: 700;
}

/* ---------------------------------------------------------------- modale */

.modale { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
/* sans cette regle, le display:flex ci-dessus l'emporte sur le display:none
   du navigateur et l'attribut hidden ne ferme plus rien */
.modale[hidden] { display: none; }
.modale-fond { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.modale-boite {
  position: relative; background: var(--fond2); border: 1px solid var(--bord);
  border-radius: 12px; padding: 22px; max-width: 640px; width: calc(100% - 40px);
  max-height: 80vh; overflow: auto;
}
.fermer { position: absolute; top: 10px; right: 12px; background: none; border: 0; color: var(--doux); font-size: 22px; cursor: pointer; }
.modale h2 { margin: 0 0 4px; font-size: 17px; }
.modale h3 { margin: 18px 0 6px; font-size: 13px; color: var(--doux); text-transform: uppercase; letter-spacing: .06em; }
.modale dl { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin: 12px 0 0; font-size: 13px; }
.modale dt { color: var(--doux); }
.modale dd { margin: 0; }
.liste-conflits { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.liste-conflits li {
  background: var(--fond3); border: 1px solid var(--bord); border-left: 3px solid var(--alerte);
  border-radius: 8px; padding: 9px 11px; font-size: 12.5px; cursor: pointer;
}
.liste-conflits li:hover { border-color: var(--accent); }
.liste-conflits .quand { color: var(--doux); font-size: 11.5px; margin-bottom: 3px; }
.liste-conflits .paire { display: flex; flex-direction: column; gap: 2px; }

/* ------------------------------------------------- comparer combinaisons */

.matrice-boite { overflow-x: auto; margin: 6px 0 2px; }
.matrice { border-collapse: separate; border-spacing: 2px; font-size: 12px; }
.matrice th, .matrice td { padding: 0; }
.matrice th.coin { width: 1px; }
.matrice th.num {
  width: 26px; height: 22px; color: var(--doux); font-weight: 500; font-size: 11px;
}
.matrice th.tete {
  text-align: left; font-weight: 500; white-space: nowrap;
  padding-right: 10px; max-width: 230px; overflow: hidden;
}
.matrice th.tete .pastille { display: inline-block; margin-right: 6px; vertical-align: middle; }
.matrice th.tete .n { color: var(--doux); margin-right: 5px; }
.matrice th.tete .nm { vertical-align: middle; }
.matrice td {
  width: 26px; height: 26px; text-align: center; border-radius: 5px;
  font-size: 11px; font-weight: 600; cursor: default;
}
.matrice td.ok { background: rgba(77, 212, 165, .14); color: #4dd4a5; }
.matrice td.ko { background: rgba(255, 107, 107, .18); color: #ff9d9d; }
.matrice td.diag { background: var(--fond3); color: var(--bord); }

.combis { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.combis li {
  background: var(--fond3); border: 1px solid var(--bord); border-radius: 8px;
  padding: 9px 11px;
}
.combis li > b { font-size: 12px; color: var(--doux); font-weight: 600; }
.combis .jetons { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 0; }
.combis .jeton {
  font-size: 11.5px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--c-vif); color: var(--texte);
  background: color-mix(in srgb, var(--c-vif) 16%, transparent);
}
.combis .exclus { font-size: 11px; color: var(--doux); margin-top: 6px; }
.combis .lien { margin-top: 6px; }

/* ======================================================= petits ecrans */
/* Sous 1000 px (tablette, telephone) : la barre laterale passe en tiroir, la
   grille recupere ses 320 px et la semaine entiere tient a l'ecran. */

@media (max-width: 1000px) {
  body { display: block; }

  .rail {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    width: min(88vw, 340px); flex-basis: auto;
    transform: translateX(-100%);
    transition: transform .22s ease;
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
    overflow-y: auto;
    box-shadow: 0 0 24px rgba(0, 0, 0, .5);
  }
  .rail.ouvert { transform: none; }
  .fermer-rail { display: block; }
  .voile { position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .55); }

  .vue { height: 100dvh; }
  .rond.menu { display: block; }
}

/* ================================================================ mobile */
/* Sous 760 px (telephone) : la grille se limite a un seul jour — sept colonnes
   y seraient illisibles — et l'interface se resserre. */

@media (max-width: 760px) {
  :root { --heure: 64px; }   /* une seule colonne : on peut aerer */

  /* cibles tactiles d'au moins 44 px, l'en-tete etait trop serre au doigt */
  .barre { flex-direction: column; align-items: stretch; gap: 2px; padding: 8px 10px; }
  .nav { gap: 10px; }
  .periode { min-width: 0; flex: 1; text-align: center; }
  .periode strong { font-size: 15px; }
  .periode span { font-size: 12px; white-space: nowrap; }
  .etat { font-size: 11px; text-align: center; min-height: 13px; }
  .rond { width: 44px; height: 44px; flex: 0 0 auto; font-size: 20px; }
  /* meme pastille ronde que ☰ : le pave bleu deborde de la barre et attirait
     l'oeil plus que la semaine affichee */
  .btn.mini {
    width: 44px; height: 44px; padding: 0; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--fond2); border: 1px solid var(--bord); color: var(--texte);
  }
  .btn.mini:hover { background: var(--fond3); filter: none; }
  .btn.mini .texte { display: none; }
  .btn.mini .icone { display: block; }

  .rangee-jours { padding: 8px 10px 0; }
  .jour-chip { min-width: 42px; padding: 9px 3px; font-size: 12px; }
  .jour-chip b { font-size: 14px; }

  .alerte { margin: 10px 12px 0; padding: 9px 11px; font-size: 12.5px; }
  /* detail replie par defaut : un appui sur le titre l'ouvre */
  .alerte ul { display: none; }
  .alerte.ouvert ul { display: block; }
  .alerte b.repliable { display: flex; justify-content: space-between; gap: 8px; cursor: pointer; }
  .alerte .fleche { transition: transform .15s ease; }
  .alerte.ouvert .fleche { transform: rotate(180deg); }
  .grille { padding: 10px 12px calc(20px + env(safe-area-inset-bottom)); }

  /* un seul jour : la colonne prend toute la largeur, plus de defilement lateral */
  .tableau { grid-template-columns: 44px 1fr; min-width: 0; }
  .colheures .h { right: 6px; font-size: 10.5px; }
  .cours { font-size: 12px; padding: 5px 8px; }
  .cours .h { font-size: 11px; }
  .cours .d { font-size: 11px; }

  /* 16 px : en dessous, iOS zoome automatiquement a la mise au point */
  input[type=text] { font-size: 16px; }
  .seg { padding: 8px 0; font-size: 13px; }
  .matiere { padding: 10px 9px; }
  .matiere .oeil, .matiere button { width: 32px; height: 32px; }
  .resultats li { padding: 10px 8px; }

  /* fenetres de detail en plein ecran */
  .modale-boite {
    width: 100%; max-width: none; height: 100dvh; max-height: none;
    border-radius: 0; border: 0; padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
  }
  .fermer { font-size: 30px; top: 6px; right: 10px; padding: 4px 10px; }
  .modale h2 { font-size: 16px; padding-right: 40px; }
  .modale dl { grid-template-columns: 92px 1fr; font-size: 12.5px; }
  .liste-conflits li { padding: 11px; }
}

/* ecrans tres etroits : on gagne la place du reste */
@media (max-width: 380px) {
  .tableau { grid-template-columns: 38px 1fr; }
  .jour-chip { min-width: 38px; }
  .rangee-jours { gap: 6px; padding: 8px 8px 0; }
  .btn.mini { width: 42px; height: 42px; }
}
