/* Analyses (#/analyses) : prototype Analyses.dc.html.
   Styles propres à cet écran (refonte du prototype v73) : un fichier par écran, chargé par index.html après
   shell.css. Téléphone : @media (max-width: 767px), comme la coque.
   Les règles de base de l'écran (.an-block, .an-key, .an-facts, graphiques) sont dans app.css ; ce fichier ajoute ce
   que la refonte a changé : notes à l'encre du texte, tableaux 1,7 / 1, « Mes alertes », le résumé écrit mot à mot,
   la bulle « Demander à l'analyse » et « Restaurants par semaine ». */

:root {
  /* L'IA a sa couleur, violette, partout où elle écrit (étiquette, résumé, bulle). */
  --an-ai: #3E2F7A; --an-ai-2: #5B45B0; --an-ai-soft: #ECE8FA; --an-ai-panel: #F4F1FD; --an-ai-line: #D9D2F3;
  --an-ai-line-2: #E4DFF7; --an-ai-foot: #ECE8F7; --an-ai-title: #2B2160; --an-ai-example: #F8F6FE;
  --an-ai-shadow: rgb(32 22 80 / 0.32); --an-ai-shadow-2: rgb(32 22 80 / 0.22);
  --an-alert: #A1271B;                 /* le nombre d'alertes déclenchées, les erreurs de la bulle */
  --an-last: #5A6B60;                  /* la dernière note de la page */
  --an-now: #F1F5EE;                   /* la colonne de la semaine choisie */
  --an-miss-bg: #FFE1CC; --an-miss-ink: #7A3300;
  --an-field-line: #A6B0A9;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --an-ai: #6B58C9; --an-ai-2: #B3A6F2; --an-ai-soft: color-mix(in srgb, #8C7AE6 22%, var(--app-surface));
    --an-ai-panel: color-mix(in srgb, #8C7AE6 12%, var(--app-surface)); --an-ai-line: color-mix(in srgb, #8C7AE6 40%, var(--app-surface));
    --an-ai-line-2: color-mix(in srgb, #8C7AE6 28%, var(--app-surface)); --an-ai-foot: var(--app-line);
    --an-ai-title: #D9D2FB; --an-ai-example: color-mix(in srgb, #8C7AE6 10%, var(--app-surface));
    --an-ai-shadow: rgb(0 0 0 / 0.5); --an-ai-shadow-2: rgb(0 0 0 / 0.45);
    --an-alert: #E0675C; --an-last: var(--app-muted); --an-now: color-mix(in srgb, var(--app-ink) 7%, var(--app-surface));
    --an-miss-bg: color-mix(in srgb, #E07A2E 26%, var(--app-surface)); --an-miss-ink: #F5B98A;
    --an-field-line: var(--app-line-strong);
  }
}
:root[data-theme="dark"] {
  --an-ai: #6B58C9; --an-ai-2: #B3A6F2; --an-ai-soft: color-mix(in srgb, #8C7AE6 22%, var(--app-surface));
  --an-ai-panel: color-mix(in srgb, #8C7AE6 12%, var(--app-surface)); --an-ai-line: color-mix(in srgb, #8C7AE6 40%, var(--app-surface));
  --an-ai-line-2: color-mix(in srgb, #8C7AE6 28%, var(--app-surface)); --an-ai-foot: var(--app-line);
  --an-ai-title: #D9D2FB; --an-ai-example: color-mix(in srgb, #8C7AE6 10%, var(--app-surface));
  --an-ai-shadow: rgb(0 0 0 / 0.5); --an-ai-shadow-2: rgb(0 0 0 / 0.45);
  --an-alert: #E0675C; --an-last: var(--app-muted); --an-now: color-mix(in srgb, var(--app-ink) 7%, var(--app-surface));
  --an-miss-bg: color-mix(in srgb, #E07A2E 26%, var(--app-surface)); --an-miss-ink: #F5B98A;
  --an-field-line: var(--app-line-strong);
}

@keyframes an-blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes an-pulse { 0%, 100% { opacity: 0.35; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1); } }

/* ------------------------------------------------------------------ en-tête : « Mes alertes » à droite, au bas du texte */
.an-head { align-items: flex-end; }
.an-head > .an-actions { flex: none; }
.an-head + .an-ia { margin-top: 8px; }
.an-head .an-alertes { min-height: 48px; padding: 0 18px; gap: 8px; font-size: 14px; line-height: 1.2; color: var(--app-ink); }
.an-head .an-alertes__count { display: inline-flex; align-items: center; justify-content: center; box-sizing: border-box;
  min-width: 22px; height: 22px; margin-left: 0; padding: 0 6px; border-radius: 999px; background: var(--an-alert);
  color: #FFFFFF; font-size: 12px; font-weight: 700; }

/* ------------------------------------------------------------------ notes, sous-titres, dernière note */
.an-note { margin: 8px 0 0; max-width: 72ch; font-size: 14px; color: var(--app-ink); }
.an-note--muted { color: var(--app-muted); }
.an-h3 + .an-note { margin-top: 4px; }
.an-note + .chart__legend { margin-top: 10px; }
.an-key + .an-facts + .an-note, .an-facts + .an-note { margin-top: 8px; }
.an-alertes__intro { margin-top: 14px; }
.an-last { margin: 8px 0 0; max-width: 760px; font-size: 14px; color: var(--an-last); }
.an-subtable > .small { margin: 8px 0; }
.an-subtable + .an-subtable > .small { margin-top: 16px; }

/* ------------------------------------------------------------------ tableaux : 1,7 part pour le nom, 1 pour chaque chiffre */
.an-block .table--res th, .an-block .table--res td { padding: 14px 16px; }
.an-block .table--res thead th { padding: 18px 16px 14px; }
.an-block .table--res tfoot th, .an-block .table--res tfoot td { padding-top: 14px; }
.an-block .table--res tbody td.num, .an-block .table--res tbody td.num:nth-last-child(2) { font-weight: 500; }
.an-block .table--res .row-h { height: auto; }
@media (min-width: 768px) {
  .an-table { table-layout: fixed; min-width: calc(var(--an-cols, 4) * 110px); }
  .an-table thead th:first-child { width: calc(100% * 1.7 / (var(--an-cols, 4) + 0.7)); }
  .an-table td, .an-table th { overflow-wrap: anywhere; }
}

/* ------------------------------------------------------------------ l'analyse par l'IA dans une colonne à droite
   Grand écran (27/10, demande d'Amine) : le résumé et la fenêtre des questions dans une colonne à droite qui suit le
   défilement des analyses (comme l'encart de Validations). Petit écran : le résumé reste en haut, la bulle en bas. */
.an-layout { display: flex; flex-direction: column; }
.an-layout > .an-side { order: -1; }
.an-main { min-width: 0; }
.an-fab[hidden] { display: none; }
@media (min-width: 1200px) {
  .page.an-page--side { max-width: 1540px; }
  .an-layout--side { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 28px; align-items: start; }
  /* hauteur de l'écran : le résumé défile dans sa zone (la moitié au plus), la case de question reste visible en bas */
  .an-layout--side > .an-side { order: 0; position: sticky; top: 16px; height: calc(100vh - 32px); min-height: 520px;
    display: flex; flex-direction: column; gap: 16px; }
  .an-side .an-ia { flex: 0 1 auto; min-height: 0; max-height: 50%; margin-top: 0; overflow-y: auto; border-radius: 16px; }
  .an-side .an-ia:empty { display: none; }
  .an-side .an-sum { padding: 16px 18px; }
  .an-side .an-sum__head h2 { font-size: 18px; }
  .an-side .an-sum__titre { font-size: 16px; }
  .an-side .an-sum__points { font-size: 15px; padding-left: 18px; }
  .an-chat--docked { width: 100%; max-height: none; min-height: 0; flex: 1 1 auto; box-shadow: none; }
}

/* ------------------------------------------------------------------ le résumé du mois, écrit mot à mot */
.an-ia { gap: 28px; margin-top: 20px; }
.an-sum { padding: 20px 24px; background: var(--app-surface); border: 1px solid var(--app-line); border-radius: 16px; }
.an-sum__head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.an-sum__head h2 { margin: 0; font-size: 22px; font-weight: 700; line-height: 1.3; }
.an-ai-tag { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--an-ai-soft);
  color: var(--an-ai); font-size: 13px; font-weight: 700; line-height: 1.4; white-space: nowrap; }
.an-ai-tag svg { flex: none; color: var(--an-ai-2); }
.an-ai-wait { display: flex; align-items: center; gap: 10px; margin: 10px 0 0; font-size: 15px; font-weight: 600; color: var(--an-ai); }
.an-pulse { flex: none; width: 10px; height: 10px; border-radius: 999px; background: var(--an-ai-2); animation: an-pulse 1.2s ease-in-out infinite; }
.an-sum__titre { margin: 6px 0 0; max-width: 72ch; font-size: 18px; font-weight: 600; color: var(--app-ink); }
.an-sum__points { margin: 10px 0 0; padding-left: 22px; list-style: disc; display: grid; gap: 6px; max-width: 76ch; font-size: 16px; line-height: 1.5; color: var(--app-ink); }
.an-sum__points li[hidden], .an-sum__titre[hidden] { display: none; }
.an-sum__note { margin: 10px 0 0; max-width: 72ch; font-size: 14px; color: var(--app-muted); }
.an-sum__calm { margin: 8px 0 0; max-width: 72ch; font-size: 16px; color: var(--app-ink); }
.an-cursor { display: inline-block; width: 2px; height: 1.1em; margin-left: 2px; vertical-align: -0.18em; background: var(--an-ai); animation: an-blink 0.9s infinite; }

/* ------------------------------------------------------------------ le bouton « Demander à l'analyse »
   Sous 1 200 px : un bouton de la page, en haut de la colonne de l'IA, sa fenêtre ouverte dessous. Il n'est plus posé
   en bas à droite de l'écran, par-dessus les graphiques (audit EC-11). Au-delà : la fenêtre est rangée dans la colonne. */
.an-fab { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
.an-fab > .an-chat { align-self: stretch; width: auto; }
.an-fab__btn { display: inline-flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 16px 0 14px; border: 0; border-radius: 999px;
  background: var(--an-ai); color: #FFFFFF; font: inherit; font-size: 15px; font-weight: 700; line-height: 1.2;
  box-shadow: 0 10px 28px var(--an-ai-shadow); cursor: pointer; }
.an-fab__btn:hover { background: color-mix(in srgb, var(--an-ai) 86%, #000); }
.an-fab__btn:focus-visible { outline: 3px solid var(--an-ai-2); outline-offset: 3px; }
.an-fab__btn svg { flex: none; }
.an-fab__ia { display: inline-flex; align-items: center; padding: 2px 7px; border-radius: 6px; background: #FFFFFF; color: var(--an-ai);
  font-size: 12px; font-weight: 800; letter-spacing: 0.04em; }

.an-chat { width: 384px; max-width: 100%; max-height: min(560px, calc(100vh - 120px)); display: flex; flex-direction: column; box-sizing: border-box;
  background: var(--app-surface); color: var(--app-ink); border: 1px solid var(--an-ai-line); border-radius: 16px;
  box-shadow: 0 18px 48px var(--an-ai-shadow-2); overflow: hidden; }
.an-chat[hidden] { display: none; }
.an-chat__head { display: flex; align-items: flex-start; gap: 10px; padding: 14px 12px 12px 16px; background: var(--an-ai-panel); border-bottom: 1px solid var(--an-ai-line-2); }
.an-chat__mark { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--an-ai-2); color: #FFFFFF; }
.an-chat__titles { flex: 1 1 auto; min-width: 0; }
.an-chat__titles h2 { margin: 0; font-size: 15px; font-weight: 700; line-height: 1.3; color: var(--an-ai-title); }
.an-chat__titles p { margin: 2px 0 0; font-size: 13px; color: var(--app-muted); }
.an-chat__close { flex: none; width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--an-ai);
  font: inherit; font-size: 22px; line-height: 1; cursor: pointer; }
.an-chat__close:hover { background: var(--an-ai-soft); }
.an-chat__close:focus-visible, .an-chat__example:focus-visible, .an-chat__send:focus-visible { outline: 2px solid var(--an-ai-2); outline-offset: 2px; }
.an-chat__body { flex: 1 1 auto; min-height: 140px; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 14px; }
.an-chat__hint { margin: 0; font-size: 13px; font-weight: 600; color: var(--app-muted); }
.an-chat__example { margin-top: 6px; display: inline-flex; align-items: center; min-height: 40px; box-sizing: border-box; padding: 8px 12px;
  border: 1px solid var(--an-ai-line); border-radius: 12px;
  background: var(--an-ai-example); color: var(--an-ai-title); font: inherit; font-size: 14px; font-weight: 600; line-height: 1.35;
  text-align: left; cursor: pointer; }
.an-chat__example:disabled { opacity: 0.6; cursor: not-allowed; }
.an-chat__msg { display: flex; flex-direction: column; gap: 8px; }
.an-chat__q { align-self: flex-end; max-width: 85%; margin: 0; padding: 8px 12px; border-radius: 12px 12px 4px 12px; background: var(--app-primary);
  color: var(--app-on-primary); font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
.an-chat__a { align-self: flex-start; box-sizing: border-box; max-width: 92%; min-width: 0; padding: 10px 12px; border-radius: 12px 12px 12px 4px;
  background: var(--an-ai-panel); color: var(--app-ink); font-size: 14px; line-height: 1.5; }
.an-chat__label { margin: 0 0 4px; font-size: 12px; font-weight: 700; color: var(--an-ai-2); }
.an-chat__a .an-ai-wait { margin: 0; gap: 8px; font-size: 14px; }
.an-chat__a .an-pulse { width: 9px; height: 9px; }
.an-chat__text { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }
.an-chat__a .chart { margin-top: 10px; padding: 10px 10px 8px; }
.an-chat__a .an-numbers > summary { min-height: 32px; font-size: 13px; }
@media (max-width: 1199px) { .an-chat__a .an-numbers > summary { min-height: 40px; } }      /* le doigt (audit EC-13) */
.an-chat__form { padding: 10px 12px 12px; border-top: 1px solid var(--an-ai-foot); }
.an-chat__row { display: flex; gap: 8px; }
.an-chat__input { flex: 1 1 auto; min-width: 0; box-sizing: border-box; min-height: 40px; padding: 8px 12px; border: 1px solid var(--an-field-line);
  border-radius: 10px; background: var(--app-surface); color: var(--app-ink); font: inherit; font-size: 15px; }
.an-chat__input:focus-visible { outline: 2px solid var(--an-ai-2); outline-offset: 1px; }
.an-chat__input[aria-invalid="true"] { border-color: var(--an-alert); }
.an-chat__input:disabled { opacity: 0.6; }
.an-chat__send { flex: none; min-height: 40px; padding: 0 14px; border: 0; border-radius: 10px; background: var(--an-ai); color: #FFFFFF;
  font: inherit; font-size: 14px; font-weight: 700; cursor: pointer; }
.an-chat__send:disabled { opacity: 0.6; cursor: not-allowed; }
.an-chat__err { margin: 6px 0 0; font-size: 13px; font-weight: 600; color: var(--an-alert); }
.an-chat__limit { margin-top: 8px; }
.an-chat__count { margin: 8px 0 0; font-size: 13px; color: var(--app-muted); }
.an-chat__err[hidden], .an-chat__limit[hidden], .an-chat__count[hidden] { display: none; }

/* ------------------------------------------------------------------ Restaurants par semaine */
.an-suivi__sentence { margin-top: 8px; }
.an-suivi__frame { margin-top: 16px; background: var(--app-surface); border: 1px solid var(--app-line); border-radius: 16px; overflow: hidden; }
/* position : les textes masqués des cases (lecteur d'écran) restent dans le cadre qui défile, sinon la page déborde */
.an-suivi__scroll { position: relative; overflow-x: auto; }
.an-suivi__scroll:focus-visible { outline: 2px solid var(--app-primary); outline-offset: -2px; }
.an-suivi__table { width: 100%; min-width: 820px; table-layout: fixed; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.an-suivi__table th, .an-suivi__table td { box-sizing: border-box; }
.an-suivi__table thead th:first-child { width: 200px; }
.an-suivi__table thead th { padding: 12px 8px; text-align: center; vertical-align: bottom; font-weight: 600; color: var(--app-muted);
  border-bottom: 1px solid var(--app-line); white-space: nowrap; }
.an-suivi__table thead th.an-suivi__name { padding: 12px 16px; text-align: left; }
.an-suivi__table thead th.an-suivi__now { color: var(--app-ink); }
.an-suivi__table tbody th, .an-suivi__table tbody td { height: 48px; border-top: 1px solid var(--app-line); }
.an-suivi__table tbody th { padding: 6px 16px; text-align: left; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.an-suivi__table tbody td { padding: 6px 8px; text-align: center; vertical-align: middle; }
.an-suivi__table .an-suivi__now { background: var(--an-now); }
/* Le nom du restaurant reste visible quand la grille défile (elle s'ouvre sur les semaines récentes), comme l'ancien Suivi */
.an-suivi__table thead th.an-suivi__name, .an-suivi__table tbody th { position: sticky; left: 0; z-index: 1; background: var(--app-surface); }
@media (max-width: 767px) { .an-suivi__table { min-width: 600px; } .an-suivi__table thead th:first-child { width: 152px; } }
.an-cell { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 8px; vertical-align: middle; }
.an-cell--ok { background: var(--app-ok-bg); color: var(--app-ok-ink); }
.an-cell--valide { background: var(--app-primary); color: var(--app-on-primary); }
.an-cell--attente { background: var(--app-warn-bg); color: var(--app-warn-ink); }
.an-cell--manquant { background: var(--an-miss-bg); color: var(--an-miss-ink); }
.an-cell--echec { background: var(--app-bad-bg); color: var(--app-bad-ink); }
.an-suivi__legend { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 0; padding: 12px 16px; list-style: none; border-top: 1px solid var(--app-line);
  font-size: 14px; color: var(--app-muted); }
.an-suivi__legend li { display: inline-flex; align-items: center; gap: 8px; }
.an-suivi__legend .an-cell { width: 22px; height: 22px; border-radius: 6px; }
.an-suivi__body > .an-note--muted { margin-top: 12px; }

/* ------------------------------------------------------------------ téléphone */
@media (max-width: 767px) {
  /* le bouton prend la largeur de l'écran ; sa fenêtre aussi, à la hauteur de l'écran au plus */
  .an-fab { align-items: stretch; }
  .an-fab__btn { justify-content: center; }
  .an-chat { width: 100%; max-height: calc(100vh - 220px); }
  .an-chat__input { font-size: 16px; }               /* pas de zoom du navigateur au toucher */
  .an-head > .an-actions { width: auto; }
  .an-block > h2 { font-size: 22px; }
  .an-key { font-size: 20px; }
  .an-block .table--res th, .an-block .table--res td { padding: 12px 10px; }
  .an-block .table--res thead th { padding: 14px 10px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .an-pulse, .an-cursor { animation: none; }
  .an-pulse { opacity: 1; transform: none; }
}
@media (forced-colors: active) {
  .an-fab__btn, .an-chat__send { border: 1px solid ButtonText; }
  .an-cell { border: 1px solid CanvasText; }
  .an-cursor { background: CanvasText; }
}
