/*
  InesGPT — console de gestion de la base de connaissances.

  THESIS : ce que le bot sait est une matiere qu'on relit et qu'on corrige, pas
  un tableau de bord a contempler. La page refuse la grille de cartes
  statistiques : elle s'ouvre sur le texte lui-meme.

  OWN-WORLD : le registre du document de travail — papier machine, filets fins,
  encre noire, une seule couleur d'action empruntee au stylo rouge du
  correcteur. Aucune ombre portee : la hierarchie vient du filet et de l'espace.

  STORY : le delegue voit ce que le bot sait, repere ce qui est faux ou perime,
  corrige sur place, et sait ce qu'on lui a demande sans reponse.

  FIRST VIEWPORT : un bandeau de comptage en une ligne, puis immediatement la
  liste des sources avec leur contenu lisible. La recherche est en haut a
  droite, l'ajout est une action franche.

  FORM : liste-document plutot que tableau de bord. Structure retenue en 1er
  sur ma liste : la tache est de relire et corriger du texte.
*/

/* ---------- Fondations ---------- */

:root {
  /* Papier legerement chaud : la lecture longue sur blanc pur fatigue. */
  --papier: #faf9f6;
  --papier-creux: #f2f0ea;
  --encre: #1a1918;
  --encre-pale: #6b6862;
  --filet: #d8d4c9;
  --filet-net: #b8b2a3;

  /* Rouge de correction : la seule couleur, reservee a l'action et a l'alerte. */
  --correction: #b3261e;
  --correction-pale: #f7e9e8;

  --vert: #2f6b3f;
  --vert-pale: #e8f0e9;

  --pas: 0.5rem;
  --rayon: 3px;

  /* Georgia et Iowan sont installees partout et ont une vraie couleur de
     texte ; les piles systeme sans-serif donnent le meme rendu que tout le
     monde. */
  --texte: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --interface: ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  --chiffres: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --papier: #16151a;
    --papier-creux: #1e1d23;
    --encre: #ecebe6;
    --encre-pale: #9c988e;
    --filet: #34323a;
    --filet-net: #4a4752;
    --correction: #ff8a80;
    --correction-pale: #2d1f1e;
    --vert: #8fd4a0;
    --vert-pale: #1c2a20;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--papier);
  color: var(--encre);
  font-family: var(--texte);
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

/* Cible tactile confortable partout, sans exception mobile. */
button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--correction);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------- Ossature ---------- */

/* Page de connexion : une seule action, centree, rien d'autre. */
.page--connexion {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 2rem 1.25rem;
}

.connexion {
  width: 100%;
  max-width: 26rem;
  text-align: center;
}

.connexion .titre {
  font-size: 2rem;
  margin-bottom: 0.75rem;
}

.connexion-intro {
  margin: 0 0 1.75rem;
  color: var(--encre-pale);
  text-wrap: pretty;
}

.connexion-bouton {
  display: block;
  padding: 0.75rem 1rem;
  text-decoration: none;
  text-align: center;
}

.connexion-erreur {
  margin: 0 0 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--correction-pale);
  color: var(--correction);
  border-radius: var(--rayon);
  font-family: var(--interface);
  font-size: 0.875rem;
  text-align: left;
}

.connexion-note {
  margin: 1.25rem 0 0;
  font-family: var(--interface);
  font-size: 0.8125rem;
  color: var(--encre-pale);
}

/* Identite de la personne connectee, discrete dans l'en-tete. */
.utilisateur {
  font-family: var(--interface);
  font-size: 0.8125rem;
  color: var(--encre-pale);
}

.utilisateur a {
  color: var(--encre-pale);
  text-underline-offset: 3px;
}

.utilisateur a:hover {
  color: var(--correction);
}

.page {
  max-width: 60rem;
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 2.5rem) clamp(1rem, 4vw, 2rem) 6rem;
}

.entete {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--filet-net);
}

.titre {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

/* Le portrait a un fond blanc a bord franc : sans cerne, il flotte sur le
   papier. Le filet fin l'ancre, dans la meme grammaire que le reste. */
.marque {
  display: inline-block;
  vertical-align: -0.45em;
  margin-right: 0.5rem;
  border-radius: 50%;
  border: 1px solid var(--filet-net);
  object-fit: cover;
  background: var(--papier-creux);
}

.marque--grande {
  display: block;
  margin: 0 auto 1.25rem;
  vertical-align: baseline;
}

.titre span {
  color: var(--encre-pale);
  font-weight: 400;
}

/* Comptage en une ligne de prose plutot qu'en tuiles de chiffres. */
.compteurs {
  font-family: var(--interface);
  font-size: 0.875rem;
  color: var(--encre-pale);
}

.compteurs b {
  font-family: var(--chiffres);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--encre);
}

.compteurs .alerte {
  color: var(--correction);
}

/* ---------- Onglets ---------- */

.onglets {
  display: flex;
  gap: 1.5rem;
  margin: 1.5rem 0 0;
  border-bottom: 1px solid var(--filet);
  font-family: var(--interface);
}

.onglet {
  appearance: none;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 0.6rem 0;
  font-size: 0.9375rem;
  color: var(--encre-pale);
  cursor: pointer;
  transition: color 160ms ease-out, border-color 160ms ease-out;
}

.onglet:hover {
  color: var(--encre);
}

.onglet[aria-selected='true'] {
  color: var(--encre);
  border-bottom-color: var(--correction);
  font-weight: 600;
}

.onglet .pastille {
  display: inline-block;
  min-width: 1.25rem;
  margin-left: 0.35rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: var(--correction);
  color: #fff;
  font-family: var(--chiffres);
  font-size: 0.75rem;
  text-align: center;
}

/* ---------- Barre d'outils ---------- */

.outils {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin: 1.25rem 0;
}

.champ-recherche {
  flex: 1 1 14rem;
  min-width: 0;
  padding: 0.55rem 0.75rem;
  background: var(--papier);
  border: 1px solid var(--filet-net);
  border-radius: var(--rayon);
  font-family: var(--interface);
  font-size: 0.9375rem;
}

.champ-recherche::placeholder {
  color: var(--encre-pale);
}

.bouton {
  appearance: none;
  padding: 0.55rem 0.9rem;
  background: var(--papier);
  color: var(--encre);
  border: 1px solid var(--filet-net);
  border-radius: var(--rayon);
  font-family: var(--interface);
  font-size: 0.9375rem;
  cursor: pointer;
  transition: background-color 150ms ease-out, border-color 150ms ease-out;
}

.bouton:hover:not(:disabled) {
  background: var(--papier-creux);
  border-color: var(--encre-pale);
}

.bouton:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.bouton--primaire {
  background: var(--encre);
  color: var(--papier);
  border-color: var(--encre);
  font-weight: 600;
}

.bouton--primaire:hover:not(:disabled) {
  background: var(--correction);
  border-color: var(--correction);
  color: #fff;
}

.bouton--danger {
  color: var(--correction);
  border-color: var(--correction);
}

.bouton--danger:hover:not(:disabled) {
  background: var(--correction);
  color: #fff;
}

.bouton--discret {
  border-color: transparent;
  background: none;
  color: var(--encre-pale);
  padding: 0.35rem 0.5rem;
}

.bouton--discret:hover:not(:disabled) {
  color: var(--encre);
  background: var(--papier-creux);
}

/* ---------- Liste des sources ---------- */

.liste {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--filet);
}

.source {
  border-bottom: 1px solid var(--filet);
  padding: 1rem 0;
}

.source[data-archivee='1'] {
  opacity: 0.55;
}

.source-tete {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  justify-content: space-between;
}

.source-titre {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  color: inherit;
  font-family: inherit;
}

.source-titre:hover {
  color: var(--correction);
}

.source-meta {
  margin: 0.2rem 0 0;
  font-family: var(--interface);
  font-size: 0.8125rem;
  color: var(--encre-pale);
}

.source-meta .type {
  font-weight: 600;
  color: var(--encre);
}

.source-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

/* Apercu du contenu : c'est la matiere, elle doit etre lisible d'emblee. */
.source-apercu {
  margin: 0.5rem 0 0;
  color: var(--encre-pale);
  font-size: 0.9375rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.source-detail {
  margin-top: 0.75rem;
}

/* ---------- Apercu du fichier d'origine ---------- */

.apercu {
  margin: 0.75rem 0;
  border: 1px solid var(--filet-net);
  border-radius: var(--rayon);
  overflow: hidden;
}

.apercu-barre {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.5rem 0.4rem 0.75rem;
  background: var(--papier-creux);
  border-bottom: 1px solid var(--filet);
  font-family: var(--interface);
  font-size: 0.8125rem;
}

.apercu-nom {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.apercu-barre a {
  text-decoration: none;
  display: inline-block;
}

/* Hauteur assez grande pour lire une page, sans manger tout l'ecran. */
.apercu-cadre {
  display: block;
  width: 100%;
  height: min(70vh, 34rem);
  border: 0;
  background: var(--papier-creux);
}

.apercu-image {
  display: block;
  width: 100%;
  max-height: min(70vh, 34rem);
  object-fit: contain;
  background: var(--papier-creux);
}

.apercu-texte {
  margin: 0;
  padding: 0.9rem;
  max-height: min(60vh, 28rem);
  overflow: auto;
  background: var(--papier-creux);
  font-family: var(--chiffres);
  font-size: 0.8125rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.apercu-repli {
  margin: 0;
  padding: 1.25rem;
  font-family: var(--interface);
  font-size: 0.875rem;
  color: var(--encre-pale);
  text-align: center;
}

.jeton-fichier {
  color: var(--correction);
  font-weight: 600;
}

.jeton-hors {
  color: var(--encre-pale);
  font-weight: 600;
}

/* Explication du retrait : discrete, mais lisible sans cliquer. */
.avis-hors {
  margin: 0.5rem 0 0;
  padding: 0.5rem 0.75rem;
  background: var(--papier-creux);
  border-radius: var(--rayon);
  font-family: var(--interface);
  font-size: 0.8125rem;
  color: var(--encre-pale);
}

.source-detail textarea {
  width: 100%;
  min-height: 9rem;
  padding: 0.75rem;
  background: var(--papier-creux);
  border: 1px solid var(--filet-net);
  border-radius: var(--rayon);
  font-family: var(--texte);
  font-size: 0.9375rem;
  line-height: 1.6;
  resize: vertical;
}

.source-detail input[type='text'] {
  width: 100%;
  margin-bottom: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--papier-creux);
  border: 1px solid var(--filet-net);
  border-radius: var(--rayon);
  font-weight: 600;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.6rem;
  align-items: center;
}

.detail-note {
  font-family: var(--interface);
  font-size: 0.8125rem;
  color: var(--encre-pale);
}

/* ---------- Formulaire de note ---------- */

.formulaire-note {
  margin: 0 0 1.25rem;
  padding: 1rem;
  background: var(--papier-creux);
  border: 1px solid var(--filet-net);
  border-radius: var(--rayon);
}

.formulaire-note input[type='text'],
.formulaire-note textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  margin-bottom: 0.5rem;
  background: var(--papier);
  border: 1px solid var(--filet-net);
  border-radius: var(--rayon);
  font-family: var(--texte);
}

.formulaire-note input[type='text'] {
  font-weight: 600;
}

.formulaire-note textarea {
  min-height: 6rem;
  line-height: 1.6;
  resize: vertical;
}

.formulaire-note ::placeholder {
  color: var(--encre-pale);
}

/* ---------- Depot de fichiers ---------- */

.depot {
  margin: 1.25rem 0;
  padding: 1.5rem;
  border: 1px dashed var(--filet-net);
  border-radius: var(--rayon);
  text-align: center;
  font-family: var(--interface);
  color: var(--encre-pale);
  transition: border-color 150ms ease-out, background-color 150ms ease-out;
}

.depot[data-survol='1'] {
  border-color: var(--correction);
  background: var(--correction-pale);
  color: var(--encre);
}

.depot input[type='file'] {
  display: none;
}

.depot label {
  color: var(--correction);
  cursor: pointer;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- Questions ---------- */

.question {
  border-bottom: 1px solid var(--filet);
  padding: 0.9rem 0;
}

.question-texte {
  margin: 0;
  font-size: 1rem;
}

.question-meta {
  margin: 0.25rem 0 0;
  font-family: var(--interface);
  font-size: 0.8125rem;
  color: var(--encre-pale);
}

.etat {
  display: inline-block;
  padding: 0.05rem 0.4rem;
  border-radius: var(--rayon);
  font-size: 0.75rem;
  font-weight: 600;
}

.etat--ouvert {
  background: var(--correction-pale);
  color: var(--correction);
}

.etat--resolu {
  background: var(--vert-pale);
  color: var(--vert);
}

/* ---------- Test de recherche ---------- */

.extrait {
  border-left: 1px solid var(--filet-net);
  padding: 0.5rem 0 0.5rem 0.9rem;
  margin: 0.75rem 0;
}

.extrait-score {
  font-family: var(--chiffres);
  font-size: 0.8125rem;
  color: var(--encre-pale);
}

.verdict {
  padding: 0.75rem 1rem;
  border-radius: var(--rayon);
  font-family: var(--interface);
  font-size: 0.9375rem;
}

.verdict--oui {
  background: var(--vert-pale);
  color: var(--vert);
}

.verdict--non {
  background: var(--correction-pale);
  color: var(--correction);
}

/* ---------- Etats ---------- */

.vide {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--encre-pale);
  font-family: var(--interface);
}

.vide p {
  margin: 0 0 0.5rem;
}

.squelette {
  height: 1rem;
  margin: 0.6rem 0;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--papier-creux) 25%, var(--filet) 50%, var(--papier-creux) 75%);
  background-size: 200% 100%;
  animation: glisse 1.4s ease-in-out infinite;
}

@keyframes glisse {
  to {
    background-position: -200% 0;
  }
}

.message {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  max-width: calc(100vw - 2rem);
  padding: 0.7rem 1.1rem;
  background: var(--encre);
  color: var(--papier);
  border-radius: var(--rayon);
  font-family: var(--interface);
  font-size: 0.9375rem;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.18);
  animation: monte 200ms cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: 10;
}

.message[data-type='erreur'] {
  background: var(--correction);
  color: #fff;
}

@keyframes monte {
  from {
    opacity: 0;
    transform: translate(-50%, 0.5rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Mobile ---------- */

@media (max-width: 40rem) {
  .titre {
    font-size: 1.25rem;
  }

  /* Le PDF natif est illisible sur un petit ecran : on privilegie
     l'ouverture en plein ecran par le lecteur du telephone. */
  .apercu-cadre {
    height: 50vh;
  }

  .apercu-barre {
    justify-content: flex-start;
  }

  .source-tete {
    flex-direction: column;
    gap: 0.5rem;
  }

  .source-actions {
    width: 100%;
  }

  .onglets {
    gap: 1rem;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .onglets::-webkit-scrollbar {
    display: none;
  }

  .onglet {
    white-space: nowrap;
  }

  /* 16px minimum : en dessous, iOS zoome au focus. */
  .champ-recherche,
  .source-detail textarea,
  .source-detail input[type='text'],
  .formulaire-note input[type='text'],
  .formulaire-note textarea {
    font-size: 16px;
  }
}
