/*
 * Accueil (professeur, élève, visiteur) et page de connexion — refonte du 18/10/2026.
 * Direction : clair d'abord ; l'anthracite seulement pour le héros ; vert, ambre, rouge et bleu
 * uniquement quand ils portent un état ; un zéro sans action reste gris.
 * Chargé par {% block extra_css %} de home.html et accounts/login.html. Préfixe : home-.
 */

.home { --ds-radius: 0.75rem; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); max-width: 80rem; margin-inline: auto; gap: var(--space-6) var(--space-4); }
.home > * { grid-column: 1 / -1; }
.home h1, .home h2, .home h3, .home p { margin: 0; }
.home-section { display: grid; min-width: 0; align-content: start; gap: var(--space-3); }
.home-section > h2, .home-section > .ds-section-header h2 { font-size: clamp(1.2rem, 1.05rem + 0.5vw, 1.45rem); font-weight: 750; }
.home-quiet { color: var(--muted); }
/* Lien isolé d'en-tête de section : cible de 44 px de haut. */
.home-section > .ds-section-header > a { display: inline-flex; min-height: 2.75rem; align-items: center; }
small.home-quiet { font-size: 0.875rem; font-weight: 600; }

/* ---------- Héros (le seul bloc anthracite de la page) ---------- */
.home-hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(min(100%, 20rem), 36rem); align-items: end; gap: var(--space-4) var(--space-8); padding: clamp(1.25rem, 3vw, 1.75rem); color: #fff; background: var(--chrome); border-radius: 0.75rem; }
.home-hero h1 { color: #fff; font-weight: 750; }
.home-hero__intro { display: grid; min-width: 0; gap: var(--space-2); }
.home-hero__eyebrow { color: #c3cad3; font-size: 0.875rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.home-hero__lead { color: #dfe4ea; }
.home-hero__stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(7.25rem, 1fr)); gap: var(--space-2); }
.home-stat { display: flex; min-height: 4.75rem; padding: var(--space-2) var(--space-3); flex-direction: column; justify-content: center; color: #fff; border: 1px solid rgb(255 255 255 / 18%); border-radius: 0.5rem; text-decoration: none; transition: background-color 120ms ease, border-color 120ms ease; }
.home-stat strong { font-size: clamp(1.8rem, 1.5rem + 1vw, 2.3rem); font-weight: 750; line-height: 1.05; font-variant-numeric: tabular-nums; }
.home-stat span { color: #c3cad3; font-size: 0.875rem; line-height: 1.3; }
.home-stat:hover { background: rgb(255 255 255 / 8%); border-color: rgb(255 255 255 / 40%); }
/* Zéro sans action : gris discret (6.9:1 sur l'anthracite). */
.home-stat--zero strong { color: #9aa4af; font-weight: 650; }
/* Ambre sur le chiffre seulement : une bordure orange se confondrait avec le halo du focus. */
.home-stat--warning strong { color: #ffd27a; }
/* Sur l'anthracite, le trait encre du focus global disparaît : trait blanc, halo orange conservé. */
.home-hero a:focus-visible { outline-color: #fff; }
/* Cinq chiffres-clés (professeur : + « inactifs > 7 j ») : colonne des chiffres plus large, une ligne. */
@media (min-width: 72.01rem) {
  .home-hero:has(.home-hero__stats > :nth-child(5)) { grid-template-columns: minmax(0, 1fr) minmax(min(100%, 20rem), 42rem); }
  .home-hero__stats:has(> :nth-child(5)) { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
@media (max-width: 72rem) {
  .home-hero:has(.home-hero__stats > :nth-child(5)) { grid-template-columns: 1fr; align-items: start; }
}

/* ---------- Panneaux, colonnes, listes horodatées ---------- */
.home-panel { display: grid; min-width: 0; align-content: start; gap: var(--space-3); padding: var(--space-4); background: var(--surface); border: 1px solid var(--ds-line); border-radius: 0.75rem; box-shadow: var(--ds-shadow); }
.home-panel h3 { font-size: 1.05rem; font-weight: 700; }
.home-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); gap: var(--space-4); }
.home-agenda { display: grid; margin: 0; padding: 0; gap: var(--space-2); list-style: none; }
.home-agenda li { display: grid; grid-template-columns: minmax(3.25rem, auto) minmax(0, 1fr); align-items: baseline; gap: var(--space-3); padding-top: var(--space-2); border-top: 1px solid var(--ds-line); }
.home-agenda li:first-child { padding-top: 0; border-top: 0; }
.home-agenda time { font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; }
.home-agenda .ds-badge { margin-left: var(--space-1); }
.home-items { display: grid; margin: 0; padding-left: 1.2rem; gap: var(--space-2); }
.home-item { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--ds-line); }
.home-item:first-child { padding-top: 0; border-top: 0; }
.home-item h3 { font-size: 1rem; }
.home-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.home-actions form { margin: 0; }
.home-empty { justify-items: start; text-align: left; }
.home-empty .button { margin-top: var(--space-2); }

/* ---------- Tuiles d'état (À surveiller, notes et médailles) ---------- */
.home-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr)); gap: var(--space-3); }
.home-tiles--compact { grid-template-columns: repeat(auto-fit, minmax(9rem, 13rem)); }
.home-tile { display: grid; min-height: 5.5rem; padding: var(--space-3) var(--space-4); align-content: center; gap: 0.15rem; color: var(--ink); background: var(--surface); border: 1px solid var(--ds-line); border-left: 0.3rem solid var(--ds-line-strong); border-radius: 0.75rem; box-shadow: var(--ds-shadow); text-decoration: none; transition: border-color 120ms ease; }
.home-tile strong { font-size: 1.9rem; font-weight: 750; line-height: 1.05; font-variant-numeric: tabular-nums; }
.home-tile span { color: var(--muted); font-size: 0.92rem; }
.home-tile:hover { border-color: var(--primary); }
.home-tile--zero, .home-tile--unknown { background: var(--ds-subtle); border-left-color: var(--ds-line); box-shadow: none; }
.home-tile--zero strong, .home-tile--unknown strong { color: var(--muted); font-weight: 650; }
.home-tile--danger { border-left-color: var(--danger); }
.home-tile--danger strong { color: var(--danger); }
.home-tile--warning { border-left-color: #b7791f; }
.home-tile--warning strong { color: #8a5a00; }
.home-clear { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); background: var(--surface); border: 1px solid var(--ds-line); border-radius: 0.75rem; }
.home-clear__mark { display: grid; width: 2.25rem; height: 2.25rem; flex: none; place-items: center; color: #0b5c36; background: #e3f5ec; border-radius: 50%; font-weight: 800; }
.home-clear__title { font-weight: 700; }

/* ---------- Professeur : en direct, présence, raccourcis ---------- */
.home-live-card .ds-card__foot { justify-content: flex-end; }
.home-live-card__class { color: var(--ds-ink-soft); }
.home-presence { display: flex; flex-wrap: wrap; gap: var(--space-3) var(--space-6); }
.home-shortcuts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 9rem), 1fr)); gap: var(--space-2); }
.home-shortcut { display: flex; min-height: 3rem; padding: var(--space-2) var(--space-3); align-items: center; gap: var(--space-2); color: var(--ink); background: var(--surface); border: 1px solid var(--ds-line); border-radius: 0.5rem; font-weight: 650; text-decoration: none; transition: border-color 120ms ease; }
.home-shortcut:hover { border-color: var(--primary); color: var(--primary-hover); }
.home-shortcut strong { font-size: 1.25rem; line-height: 1; font-variant-numeric: tabular-nums; }
.home-recent > summary { font-weight: 650; cursor: pointer; }
.home-recent[open] > summary { margin-bottom: var(--space-2); }

/* ---------- Professeur : panneau « Présence » (préfixe home-presence-) ----------
   Récence de la dernière activité authentifiée : pastille ET libellé, jamais la couleur seule.
   Vert = en ligne ; bleu-gris = connecté aujourd'hui, hier ou il y a 2 à 3 jours ; ambre dès 4 jours ;
   rouge dès 8 jours ; trait pointillé creux = jamais connecté. */
.home-presence-panel { gap: var(--space-4); }
.home-presence-headline { font-size: 1.05rem; font-weight: 650; }
.home-presence-dist, .home-presence-follow, .home-presence-byclass { display: grid; min-width: 0; align-content: start; gap: var(--space-3); }
.home-presence-dist h3, .home-presence-follow h3, .home-presence-byclass h3 { display: flex; align-items: center; gap: var(--space-2); }

.home-presence-bar { height: 1.5rem; overflow: hidden; background: var(--ds-neutral-bg); border: 1px solid var(--ds-line); border-radius: 0.5rem; animation: home-presence-fill 700ms ease-out both; }
.home-presence-bar svg { display: block; width: 100%; height: 100%; }
.home-presence-seg { stroke: #fff; stroke-width: 2px; vector-effect: non-scaling-stroke; cursor: pointer; }
.home-presence-seg--online { fill: #2f9e67; }
.home-presence-seg--today { fill: #2f4f6f; }
.home-presence-seg--yesterday { fill: #5879a0; }
.home-presence-seg--days_2_3 { fill: #7a96b3; }
.home-presence-seg--days_4_7 { fill: #b7791f; }
.home-presence-seg--over_7 { fill: #b42318; }
.home-presence-seg--never { fill: #e6e9ed; stroke: #6b7580; stroke-dasharray: 5 4; }

.home-presence-legend { display: flex; flex-wrap: wrap; margin: 0; padding: 0; gap: var(--space-2); list-style: none; }
.home-presence-chip { display: inline-flex; min-height: 2.75rem; padding: 0.25rem 0.85rem; align-items: center; gap: 0.5rem; color: var(--ink); background: var(--surface); border: 1px solid var(--ds-line-strong); border-radius: 999px; font: inherit; font-weight: 600; cursor: pointer; transition: border-color 120ms ease; }
.home-presence-chip strong { font-variant-numeric: tabular-nums; }
.home-presence-chip:hover { border-color: var(--primary); }
.home-presence-chip--zero { color: var(--muted); background: var(--ds-subtle); }
.home-presence-chip--zero strong { font-weight: 600; }

.home-presence-dot { position: relative; display: inline-block; width: 0.7rem; height: 0.7rem; flex: none; background: #8b95a1; border-radius: 50%; }
.home-presence-dot--online, .home-presence-dot--online::after { background: #2f9e67; }
.home-presence-dot--online::after { position: absolute; inset: 0; border-radius: 50%; animation: home-presence-pulse 2.4s ease-out infinite; content: ""; }
.home-presence-dot--today { background: #2f4f6f; }
.home-presence-dot--yesterday { background: #5879a0; }
.home-presence-dot--days_2_3 { background: #7a96b3; }
.home-presence-dot--days_4_7 { background: #b7791f; }
.home-presence-dot--over_7 { background: #b42318; }
.home-presence-dot--never { background: transparent; border: 2px dashed #6b7580; }

.home-presence-cols { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-6) var(--space-8); }
.home-presence-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); align-items: start; gap: var(--space-3); }
.home-presence-group { display: grid; min-width: 0; align-content: start; gap: var(--space-2); padding: var(--space-3); background: var(--surface); border: 1px solid var(--ds-line); border-left: 0.3rem solid #b7791f; border-radius: 0.5rem; }
.home-presence-group h4 { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0 var(--space-2); margin: 0; font-size: 1rem; font-weight: 700; }
.home-presence-group h4 .home-quiet { font-size: 0.875rem; font-weight: 600; }
.home-presence-group > .button { justify-self: start; }
.home-presence-list { display: grid; margin: 0; padding: 0; gap: 0; list-style: none; }
.home-presence-list li { display: flex; flex-wrap: wrap; min-height: 2rem; align-items: center; justify-content: space-between; gap: 0 var(--space-3); border-top: 1px solid var(--ds-line); }
.home-presence-list li:first-child { border-top: 0; }
.home-presence-name { display: inline-flex; align-items: center; gap: 0.5rem; }
.home-presence-ago { display: inline-flex; margin-left: auto; align-items: center; gap: 0.4rem; color: var(--ds-ink-soft); font-size: 0.875rem; font-weight: 650; }

.home-presence-classes { display: grid; margin: 0; padding: 0; gap: var(--space-3); list-style: none; }
.home-presence-class { display: grid; gap: 0.3rem; }
.home-presence-class__head { display: flex; justify-content: space-between; gap: var(--space-3); font-weight: 650; }
.home-presence-class__head > :last-child { color: var(--ds-ink-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.home-presence-class .ds-progress { height: 0.75rem; animation: home-presence-fill 700ms ease-out both; }
.home-presence-class .ds-progress::-webkit-progress-value { background: #2f4f6f; }
.home-presence-class .ds-progress::-moz-progress-bar { background: #2f4f6f; }
.home-presence-class__late { color: #704004; font-size: 0.875rem; font-weight: 650; }

/* Fenêtre « Présence des élèves ». */
.home-presence-dialog { width: min(96vw, 62rem); max-width: none; max-height: 90vh; padding: 0; overflow: auto; color: var(--ink); background: var(--surface); border: 1px solid var(--ds-line-strong); border-radius: 0.75rem; box-shadow: 0 1rem 3rem rgb(0 0 0 / 35%); }
.home-presence-dialog::backdrop { background: rgb(9 15 28 / 72%); }
.home-presence-dialog__body { display: grid; padding: 0 clamp(1rem, 3vw, 1.5rem) clamp(1rem, 3vw, 1.5rem); gap: var(--space-3); }
.home-presence-dialog__head { position: sticky; z-index: 2; top: 0; padding-block: clamp(0.75rem, 2vw, 1rem); background: var(--surface); border-bottom: 1px solid var(--ds-line); }
.home-presence-filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); gap: var(--space-3); }
.home-presence-filters label { display: grid; gap: 0.25rem; font-weight: 650; }
.home-presence-filters :is(input, select) { width: 100%; min-height: 2.75rem; padding: 0.55rem 0.65rem; color: var(--ink); background: var(--surface); border: 1px solid #75808d; border-radius: 0.3rem; font: inherit; font-weight: 400; }
.home-presence-table th, .home-presence-table td { vertical-align: middle; }
.home-presence-table td small { display: block; }
.home-presence-status { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 650; }

@keyframes home-presence-fill { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes home-presence-pulse { 0% { opacity: 0.55; transform: scale(1); } 70%, 100% { opacity: 0; transform: scale(2.6); } }
@media (prefers-reduced-motion: reduce) {
  .home-presence-bar, .home-presence-class .ds-progress, .home-presence-dot--online::after { animation: none; }
  .home-presence-dot--online::after { display: none; }
}
@media (min-width: 48rem) {
  .home-presence-cols { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
}
@media (max-width: 40rem) {
  .home-presence-list li { min-height: 2.75rem; }
  .home-presence-list a { display: inline-flex; min-height: 2.75rem; align-items: center; }
  .home-presence-dialog { width: 100vw; max-height: 100vh; border-radius: 0; }
  .home-presence-table th[scope="row"] { display: block; padding-bottom: 0; font-size: 1.05rem; }
  .home-presence-table td { align-items: center; }
  .home-presence-table tbody tr:not(:last-child) { border-bottom: 1px solid var(--ds-line-strong); }
}

/* ---------- Élève : carte « Maintenant » ---------- */
.home-now { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--space-4); padding: var(--space-4) clamp(1rem, 2.5vw, 1.5rem); background: var(--surface); border: 1px solid var(--ds-line); border-left: 0.35rem solid var(--primary); border-radius: 0.75rem; box-shadow: var(--ds-shadow); }
.home-now__body { display: grid; min-width: 0; gap: var(--space-1); }
.home-now__body h3 { font-size: clamp(1.1rem, 1rem + 0.4vw, 1.3rem); font-weight: 750; }
.home-now__kicker { color: var(--muted); font-size: 0.875rem; font-weight: 700; }
.home-now > .button { min-height: 3rem; padding-inline: 1.4rem; font-size: 1.05rem; }
.home-now--done { border-left-color: #2f9e67; }
.home-now--pause { background: #fff8e1; border-left-color: #b7791f; }
.home-now--next { border-left-color: var(--ds-line-strong); }
.home-state { font-weight: 650; }
.home-state--done { color: #0b5c36; }
.home-state--pause { color: #704004; font-weight: 550; }
.home-machine-state { font-weight: 700; }
.home-machine-state--ready { color: #0b5c36; }
.home-machine-state--error { color: var(--danger); }

/* ---------- Visiteur ---------- */
.home-public { display: grid; min-height: 60vh; place-items: center; }
.home-public > .card { display: grid; width: min(100%, 34rem); padding: clamp(1.5rem, 5vw, 2.75rem); justify-items: center; gap: var(--space-3); text-align: center; border-color: var(--ds-line); border-radius: 0.75rem; }
.home-public__lead { max-width: 28rem; color: var(--ds-ink-soft); }
.home-public__action { min-width: 12rem; margin-top: var(--space-2); }

/* ---------- Connexion ---------- */
.home-login { display: grid; min-height: 65vh; place-items: center; }
.home-login__card { display: grid; width: min(100%, 26rem); padding: clamp(1.25rem, 5vw, 2.25rem); gap: var(--space-3); background: var(--surface); border: 1px solid var(--ds-line); border-radius: 0.75rem; box-shadow: var(--ds-shadow); }
.home-login__card > p, .home-login__card > h1 { margin: 0; }
.home-login__lead, .home-login__help { color: var(--muted); }
.home-login__help { font-size: 0.875rem; }
.home-login__form { margin-top: var(--space-2); }
.home-login__submit { width: 100%; }
.home-login__alert { padding: var(--space-3) var(--space-4); color: #6b160e; background: #fee4e2; border: 1px solid var(--danger); border-left-width: 0.35rem; border-radius: 0.3rem; font-weight: 650; }
.home-login__alert p { margin: 0; }
.home-login__error { margin: 0; color: var(--danger); font-weight: 700; }
.home-login [aria-invalid="true"] { border-color: var(--danger); }

/* ---------- Petits écrans ---------- */
@media (max-width: 60rem) {
  .home-hero { grid-template-columns: 1fr; align-items: start; }
}
@media (max-width: 40rem) {
  .home { gap: var(--space-4); }
  .home-hero__stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .home-hero__stats:has(> :nth-child(4)) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* Cinq chiffres : trois puis deux, jamais un orphelin. */
  .home-hero__stats:has(> :nth-child(5)) { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .home-hero__stats:has(> :nth-child(5)) > * { grid-column: span 2; }
  .home-hero__stats:has(> :nth-child(5)) > :nth-child(n+4) { grid-column: span 3; }
  .home-stat { min-height: 4.25rem; }
  .home-now { grid-template-columns: auto minmax(0, 1fr); }
  .home-now > .crest { width: 3rem; height: 3rem; }
  .home-now > .button { grid-column: 1 / -1; width: 100%; }
  .home-live-card .ds-card__foot .button, .home-item > .button { width: 100%; }
  .home-tiles--compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Mise en page en deux dimensions (≥ 64 rem) ----------
   L'ordre du DOM reste l'ordre de lecture : ligne après ligne, de gauche à droite. */
@media (min-width: 64rem) {
  .home > [data-home-section="watch"] { grid-column: span 4; }
  /* Refonte « Présence » : le panneau prend toute la largeur, « À venir » comble la ligne de « À surveiller ». */
  .home > [data-home-section="upcoming"] { grid-column: span 8; }
  .home > [data-home-section="activity"] { grid-column: span 8; }
  .home > [data-home-section="grades"] { grid-column: span 4; }
}
/* « À venir » (professeur) : les séances côte à côte plutôt que l'une sous l'autre. */
[data-home-section="upcoming"] > .home-panel { grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); }
[data-home-section="upcoming"] > .home-panel > p { grid-column: 1 / -1; }
[data-home-section="upcoming"] .home-item { align-content: space-between; padding: var(--space-3); border: 1px solid var(--ds-line); border-radius: 0.5rem; }
[data-home-section="upcoming"] .home-item:first-child { padding-top: var(--space-3); border-top: 1px solid var(--ds-line); }
/* « Maintenant » (élève) : les activités en cours en cartes côte à côte. */
.home-now-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); gap: var(--space-4); }
.home-now-grid > .ds-empty { grid-column: 1 / -1; }
.home-now-grid .home-now { grid-template-columns: auto minmax(0, 1fr); align-content: start; }
.home-now-grid .home-now > .button { grid-column: 1 / -1; width: 100%; }
/* « Notes et médailles » dans la colonne étroite : tuiles côte à côte, jamais plus larges que nécessaire. */
[data-home-section="grades"] .home-tiles--compact { grid-template-columns: repeat(auto-fit, minmax(min(100%, 8rem), 1fr)); }
/* « En direct » en pleine largeur : les cartes s'alignent sur une même ligne (3 à 4 de front). */
[data-home-section="live"] .ds-card-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr)); }
/* Les titres de section ont tous la même hauteur : deux sections côte à côte restent alignées. */
.home-section > h2 { display: flex; min-height: 2.75rem; align-items: center; }
.home-notice { margin-block: 1rem; }
.home-notice__title { margin: 0 0 0.2rem; font-size: 1rem; line-height: 1.3; }

/* Logo officiel (26/10/2026) : fluide, jamais déformé, centré. */
.home-login__mark, .home-public__mark { display: block; width: min(14rem, 62vw); height: auto; aspect-ratio: 1; margin: 0 auto var(--space-3); }
/* Instance sans logo (SCHOOL_LOGO vide, docs/INSTANCE_LPPR.md) : sigle en texte, sans image inventée. */
.home-login__mark.school-wordmark, .home-public__mark.school-wordmark { display: grid; width: min(9rem, 50vw); place-items: center; color: var(--surface); background: var(--ink); border-radius: 1rem; font-size: 2rem; font-weight: 800; letter-spacing: 0.06em; }
