/* Feuille de style unique. Mobile d'abord : tout est dimensionne pour un iPhone tenu
   a une main, et l'ecran large n'est qu'un cas particulier traite a la fin.

   Les couleurs passent toutes par des variables. Le theme sombre n'est pas une
   surcouche : c'est le meme jeu de variables avec d'autres valeurs, ce qui evite
   les oublis de contraste. */

:root {
  --fond: #f6f6f8;
  --carte: #ffffff;
  --texte: #1a1a1f;
  --discret: #6a6a76;
  --bord: #e2e2ea;
  --accent: #0f766e;
  --accent-texte: #ffffff;
  --danger: #b3261e;
  --rayon: 14px;
  --ombre: 0 1px 3px rgba(0, 0, 0, .08);
  /* Marges de securite du materiel : encoche en haut, barre de geste en bas. */
  --haut: env(safe-area-inset-top, 0px);
  --bas: env(safe-area-inset-bottom, 0px);
}

[data-theme="sombre"] {
  --fond: #131316;
  --carte: #1e1e23;
  --texte: #f2f2f6;
  --discret: #9b9baa;
  --bord: #303038;
  --accent-texte: #ffffff;
  --danger: #f2b8b5;
  --ombre: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* Empeche Safari de grossir le texte en paysage. */
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(64px + var(--bas));
}

/* --- Entete ------------------------------------------------------------- */

.entete {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + var(--haut)) 16px 10px;
  background: color-mix(in srgb, var(--fond) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--bord);
}

.entete h1 {
  flex: 1;
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  /* Un titre qui passe a la ligne fait sauter la mise en page a chaque changement
     d'ecran. On le tronque plutot que de laisser l'entete respirer. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Vue ---------------------------------------------------------------- */

.vue { padding: 16px; display: grid; gap: 12px; }

.carte {
  background: var(--carte);
  border: 1px solid var(--bord);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 14px 16px;
}

.carte h2 { margin: 0 0 8px; font-size: 16px; font-weight: 650; }
.discret { color: var(--discret); font-size: 14px; }
.vide { text-align: center; color: var(--discret); padding: 32px 16px; }

.ligne { display: flex; align-items: center; gap: 12px; }
.ligne .titre { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* --- Controles ---------------------------------------------------------- */

/* 44px : c'est la taille minimale d'une cible tactile confortable sur iPhone.
   En dessous, on rate le bouton une fois sur cinq en marchant. */
button, .bouton {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--bord);
  border-radius: 10px;
  background: var(--carte);
  color: var(--texte);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  /* Supprime le surlignage bleu au tap, qui fait "page web" et pas "application". */
  -webkit-tap-highlight-color: transparent;
}

button.principal { background: var(--accent); color: var(--accent-texte); border-color: transparent; }
button.discret { background: none; border-color: transparent; color: var(--discret); }
button.danger { color: var(--danger); }
button:active { opacity: .7; }

button.icone {
  min-width: 44px;
  padding: 0;
  border-color: transparent;
  background: none;
  font-size: 20px;
}
button.icone.tourne { animation: tourner .8s linear infinite; }
@keyframes tourner { to { transform: rotate(360deg); } }

input, textarea, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--bord);
  border-radius: 10px;
  background: var(--fond);
  color: var(--texte);
  font-family: inherit;
  /* 16px exactement, et jamais moins : en dessous, Safari zoome automatiquement a la
     mise au point et l'utilisateur se retrouve avec une page decalee.
     A ecrire en proprietes separees : `font: 16px/1.4 inherit` est invalide (le
     raccourci n'accepte pas `inherit` comme famille) et le navigateur retombe alors
     sur sa taille par defaut, autour de 13px. */
  font-size: 16px;
  line-height: 1.4;
}
textarea { min-height: 96px; resize: vertical; }

label { display: grid; gap: 6px; font-size: 14px; color: var(--discret); }

.champs { display: grid; gap: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

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

.onglets {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  padding-bottom: var(--bas);
  background: color-mix(in srgb, var(--carte) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--bord);
}

.onglets a {
  flex: 1;
  padding: 12px 4px;
  text-align: center;
  text-decoration: none;
  color: var(--discret);
  font-size: 13px;
  font-weight: 550;
  -webkit-tap-highlight-color: transparent;
}
.onglets a.actif { color: var(--accent); }

/* --- Bandeaux ----------------------------------------------------------- */

.maj {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(8px + var(--haut)) 16px 8px;
  background: var(--accent);
  color: var(--accent-texte);
  font-size: 14px;
}
.maj span { flex: 1; }
.maj button { min-height: 36px; background: rgba(255, 255, 255, .18); border-color: transparent; color: inherit; }
/* Quand le bandeau est la, c'est lui qui absorbe l'encoche, plus l'entete. */
.maj:not([hidden]) ~ .entete { padding-top: 10px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--bas));
  transform: translate(-50%, 12px);
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: #1a1a1f;
  color: #fff;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* --- Ecran large -------------------------------------------------------- */

@media (min-width: 760px) {
  .entete, .vue, .onglets { max-width: 720px; margin-inline: auto; }
  .onglets { position: static; border-top: none; border-radius: 0; }
  body { padding-bottom: 24px; }
}

/* --- Saisie de l'intensite ------------------------------------------------
   Trois grandes cibles plutot qu'une liste deroulante : noter une douleur se fait
   souvent d'une main, parfois en pleine crise. Une touche au lieu de trois, et le
   code couleur est directement sous les yeux. */

.niveaux { display: grid; gap: 10px; }

.niveau {
  display: grid;
  gap: 2px;
  min-height: 76px;
  padding: 12px 16px 12px 60px;
  position: relative;
  text-align: left;
  border-color: transparent;
  background: color-mix(in srgb, var(--teinte) 12%, var(--carte));
}
[data-theme="sombre"] .niveau { background: color-mix(in srgb, var(--teinte) 26%, var(--carte)); }

.niveau .lettre {
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--teinte);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
}
.niveau .nom { font-size: 16px; font-weight: 650; }
.niveau .detail { font-size: 13px; color: var(--discret); }

/* --- Pastille d'intensite -------------------------------------------------
   La lettre accompagne toujours la couleur : le PDF peut etre imprime en noir et
   blanc, et une pastille seule ne dirait plus rien. */

.pastille {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 26px; height: 22px;
  border-radius: 6px;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}
.pastille.grande { width: 34px; height: 30px; font-size: 16px; }

/* --- Listes d'episodes ---------------------------------------------------- */

.episode { padding: 8px 0; cursor: pointer; border-top: 1px solid var(--bord); }
.carte h2 + .episode { border-top: none; }
.episode .heure { flex: none; font-variant-numeric: tabular-nums; font-weight: 600; }
.episode .chevron { flex: none; color: var(--discret); font-size: 20px; }

.carte.edition { border-color: var(--accent); }
.centre { text-align: center; }

/* --- Segments (periode, intensite) ---------------------------------------- */

.segments { display: flex; gap: 6px; }
.segments button { flex: 1; min-height: 40px; padding: 0 8px; }
.segments button.actif { background: var(--accent); color: var(--accent-texte); border-color: transparent; }
.segments.intensites button { font-weight: 700; }

/* --- Tableau --------------------------------------------------------------
   Un tableau de six colonnes ne rentre pas dans un ecran de telephone. Il defile
   donc horizontalement dans son propre conteneur, sans jamais faire deborder la
   page elle-meme, ce qui casserait toute la mise en page. */

.carte.sans-marge { padding: 0; overflow: hidden; }
.tableau-defilant { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 8px 10px; text-align: left; white-space: nowrap; vertical-align: middle; }
th { font-size: 12px; font-weight: 650; color: var(--discret); background: var(--fond); }
tbody tr { border-top: 1px solid var(--bord); cursor: pointer; }
tbody tr:active { background: var(--fond); }
td:first-child, td:nth-child(2) { font-variant-numeric: tabular-nums; }
/* La remarque est la seule colonne qui a le droit de s'etaler. */
td:last-child { white-space: normal; min-width: 180px; }

.legende { display: grid; gap: 6px; padding: 0 4px; }
.entree-legende .titre { font-size: 14px; color: var(--discret); }

/* --- Import d'une note ---------------------------------------------------- */

.proposition .source {
  margin: 8px 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--fond);
  font-size: 13px;
  color: var(--discret);
  white-space: pre-wrap;
}
.proposition .case { width: 22px; height: 22px; min-height: 0; flex: none; }

/* Repere visuel des valeurs devinees : elles doivent attirer l'oeil sans crier,
   puisqu'elles sont probablement justes, seulement pas certaines. */
.devine { color: #a85800; font-weight: 650; }
.segments.intensites button.devine { border-color: #a85800; }

.etiquette {
  flex: none;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bord);
  color: var(--discret);
  font-size: 12px;
  font-weight: 600;
}

/* --- Lien presente comme un bouton ---------------------------------------- */

a.bouton {
  display: inline-grid;
  place-items: center;
  text-decoration: none;
}

/* L'icone des pistes est un lien, pas un bouton : il lui faut les memes dimensions
   de cible tactile que ses voisins. */
.entete a.icone {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  text-decoration: none;
  font-size: 19px;
}

/* Respecte le reglage systeme d'animations reduites : sur une app qu'on ouvre
   vingt fois par jour, les animations decoratives finissent par lasser. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
