/* =========================================================================
   PALETTES DE COULEURS

   Source de vérité = le thème actif, défini dans l'administration (table
   `color_themes`) et injecté dans <head> APRÈS cette feuille — une règle
   `:root` plus tardive l'emporte à spécificité égale.

   Ces palettes servent de **repli** : si la base est indisponible ou si
   aucun thème n'est défini, la page reste lisible (sombre par défaut).
   Corollaire : modifier un thème dans l'admin ne modifie PAS ce bloc, qui
   n'est qu'un garde-fou.
   ========================================================================= */

:root {
  /* --- Sombre (valeur par défaut de l'application) --- */
  --bg: #12141a;
  --bg-soft: #1a1d26;
  --card: #20242f;
  --border: #2c3140;
  --text: #e8eaf0;
  --text-dim: #9aa1b2;
  --accent: #7c9cff;
  --accent-strong: #5b81f5;
  --danger: #e5636f;
  /* Texte posé sur un aplat (bouton, bulle de message, case de calendrier). */
  --on-accent: #ffffff;
  --on-mood: #12141a;
  /* Échelle d'humeur 1 → 5 : rouge → orange → neutre → vert. */
  --mood-1: #e5636f;
  --mood-2: #e5916f;
  --mood-3: #9aa1b2;
  --mood-4: #6fae8f;
  --mood-5: #4f9d6f;
  /* Variation positive (tendance à la hausse) — distincte de l'humeur :
     changer l'échelle d'humeur ne doit pas changer le vert des KPI. */
  --positive: #6fae8f;
  /* Non coloristiques : hors périmètre de personnalisation. */
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

html[data-mode="light"] {
  /* --- Clair : mêmes rôles, valeurs recalculées pour le contraste.

     Les textes sont nettement plus foncés et l'accent est assombri : sur un
     fond clair, un accent clair (comme #7c9cff) tomberait sous le seuil de
     contraste AA pour le texte. --- */
  --bg: #f2f4fa;
  --bg-soft: #ffffff;
  --card: #ffffff;
  --border: #d8ddeb;
  --text: #151a26;
  --text-dim: #5b6479;
  --accent: #3d63e8;
  --accent-strong: #2c4ed6;
  --danger: #c8394b;
  --on-accent: #ffffff;
  --on-mood: #10131c;
  --mood-1: #e87481;
  --mood-2: #eda06f;
  --mood-3: #93a0b4;
  --mood-4: #6ec49a;
  --mood-5: #4fae7c;
  /* Vert nettement plus foncé : le vert clair du sombre tomberait sous le
     contraste AA sur un fond blanc (2,2:1 au lieu des 4,5:1 requis). */
  --positive: #147a4f;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.5rem;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.5rem;
}
.topbar .brand { font-weight: 700; color: var(--text); font-size: 1.1rem; }
.topbar nav { display: flex; gap: 1.1rem; align-items: center; flex-wrap: wrap; }

.container { max-width: 860px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }

.footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 1.5rem;
}

h1 { font-size: 1.6rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.3rem;
  margin-bottom: 1.2rem;
}

.cards { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }

.reminder-banner {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-color: var(--accent);
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}
.card.stat { flex: 1; min-width: 150px; text-align: center; margin-bottom: 0; }
.stat-value { font-size: 2rem; font-weight: 700; }
.stat-label { color: var(--text-dim); font-size: 0.9rem; }

/* --- Tableau de bord : cartes de KPI ---------------------------- */
.kpi-cards .stat { min-width: 140px; }
.stat-trend { font-size: 0.75rem; margin-top: 0.25rem; }
.stat-trend.up { color: var(--positive); }
.stat-trend.down { color: var(--danger); }
.stat-trend.flat { color: var(--text-dim); }

/* --- Heatmap 12 semaines ----------------------------------------
   Colonnes = semaines, lignes = jours (lundi en haut). Le CSS
   `grid-auto-flow: column` épouse exactement l'ordre dans lequel le
   serveur émet les cellules (semaine après semaine) : aucune
   transposition n'est nécessaire côté client. */
:root { --hm-size: 15px; --hm-gap: 4px; }
.heatmap {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.3rem;
}
.hm-labels {
  display: grid;
  grid-template-rows: repeat(7, var(--hm-size));
  row-gap: var(--hm-gap);
  font-size: 0.7rem;
  color: var(--text-dim);
}
/* Les lignes masquées gardent leur hauteur : la grille reste alignée. */
.hm-labels .muted { visibility: hidden; }

.hm-grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, var(--hm-size));
  grid-auto-columns: var(--hm-size);
  gap: var(--hm-gap);
}
.hm-cell {
  display: block;
  width: var(--hm-size);
  height: var(--hm-size);
  border-radius: 3px;
  background: var(--bg-soft);
}
.hm-future { background: transparent; }
.hm-nomood { background: var(--accent); opacity: 0.4; }
.hm-mood-1 { background: var(--mood-1); }
.hm-mood-2 { background: var(--mood-2); }
.hm-mood-3 { background: var(--mood-3); }
.hm-mood-4 { background: var(--mood-4); }
.hm-mood-5 { background: var(--mood-5); }
a.hm-cell:hover, a.mg-cell:hover {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.hm-legend {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-wrap: wrap;
  margin-top: 0.8rem;
  font-size: 0.75rem;
  color: var(--text-dim);
}
.hm-legend .hm-cell { width: 13px; height: 13px; }

/* --- Calendrier mensuel ----------------------------------------- */
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.mg-head {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-dim);
  padding-bottom: 0.3rem;
}
.mg-cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  text-decoration: none;
  color: var(--text);
}
/* La couleur de fond vient des classes hm-* (écrit / humeur). `.mg-cell` ne
   la fixe PAS : même spécificité que `.hm-mood-N` mais définie plus tard,
   un `background` ici les aurait écrasées — toutes les cellules seraient
   alors peintes en --bg-soft, avec un texte --on-mood (sombre) illisible. */
.mg-cell.hm-empty { background: var(--bg-soft); }
.mg-outside { background: transparent; }
.mg-day { position: relative; z-index: 1; }
/* Point d'humeur discret sous le jour : la couleur de fond porte
   l'information, le point la rappelle pour les daltoniens. */
.mg-dot {
  position: absolute;
  bottom: 4px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
}
/* Texte sombre sur les jours remplis : les teintes d'humeur sont
   moyennement claires, un texte blanc n'atteindrait pas le contraste AA. */
.mg-cell.hm-mood-1, .mg-cell.hm-mood-2, .mg-cell.hm-mood-3,
.mg-cell.hm-mood-4, .mg-cell.hm-mood-5, .mg-cell.hm-nomood {
  color: var(--on-mood);
  font-weight: 600;
}

/* --- Graphiques (Chart.js) --------------------------------------
   Hauteur fixe : Chart.js est configuré en `maintainAspectRatio:false`,
   c'est donc le conteneur qui décide des dimensions du canvas. */
.chart-grid, .split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 1rem;
  margin-bottom: 1.4rem;
}
.chart-card h2 { font-size: 1rem; }
.chart-box { position: relative; height: 220px; }
.chart-box-pie { height: 230px; }

.actions { display: flex; gap: 1rem; margin-bottom: 1.4rem; flex-wrap: wrap; }

.button {
  display: inline-block;
  background: var(--accent-strong);
  color: var(--on-accent);
  border: none;
  border-radius: var(--radius);
  padding: 0.55rem 1.1rem;
  font-size: 0.95rem;
  cursor: pointer;
  font-family: inherit;
}
.button:hover { filter: brightness(1.1); text-decoration: none; }
.button.secondary { background: var(--bg-soft); border: 1px solid var(--border); color: var(--text); }
.button.danger { background: var(--danger); }

.page-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.8rem; }
.page-actions { display: flex; gap: 0.7rem; flex-wrap: wrap; }

.entry-list { list-style: none; padding: 0; margin: 0; }
.entry-list li { padding: 0.45rem 0; border-bottom: 1px solid var(--border); }
.entry-list li:last-child { border-bottom: none; }
.entry-list.detailed li {
  border: none;
  /* `.entry-list li` ci-dessus a une spécificité (0,1,1) supérieure à
     `.card` (0,1,0) : sans ce rappel, il écrase le padding de la carte et
     le texte vient toucher le bord arrondi. Ici (0,2,1) l'emporte. */
  padding: 1rem 1.2rem;
}
.entry-list.detailed a { display: block; color: var(--text); }
.entry-list.detailed a:hover { text-decoration: none; border-color: var(--accent); }
.entry-list h3 { margin: 0.2rem 0; }
.entry-list p { margin: 0; color: var(--text-dim); font-size: 0.92rem; }

.entry-date { color: var(--text-dim); font-size: 0.85rem; text-transform: capitalize; }
.mood-badge {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.55rem;
  font-size: 0.82rem;
  margin-left: 0.5rem;
}

.entry-detail .entry-content { white-space: pre-wrap; margin: 1rem 0; }
.entry-footer { display: flex; gap: 0.8rem; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 1rem; }

.form label { display: block; margin: 0.9rem 0 0.3rem; font-weight: 600; font-size: 0.92rem; }
.form input[type="text"], .form input[type="date"], .form textarea {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.7rem;
  font-family: inherit;
  font-size: 0.98rem;
}
.form textarea { resize: vertical; }
.form-actions { display: flex; gap: 0.8rem; margin-top: 1.2rem; }
.hint { color: var(--text-dim); font-weight: 400; font-size: 0.85rem; }

.mood-picker { display: flex; gap: 0.5rem; }
.mood-option {
  cursor: pointer;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.3rem 0.6rem;
  font-size: 1.3rem;
}
.mood-option input { display: none; }
.mood-option:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); }

.skill-picker { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.skill-chip {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.85rem;
  font-size: 0.88rem;
  color: var(--text);
}
.skill-chip:hover { text-decoration: none; border-color: var(--accent); }
.skill-chip.active { background: color-mix(in srgb, var(--accent) 18%, transparent); border-color: var(--accent); }

.chat-messages { min-height: 260px; max-height: 60vh; overflow-y: auto; display: flex; flex-direction: column; gap: 0.7rem; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg-bubble {
  max-width: 80%;
  padding: 0.6rem 0.9rem;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .msg-bubble { background: var(--accent-strong); color: var(--on-accent); border-bottom-right-radius: 4px; }
.msg.assistant .msg-bubble { background: var(--bg-soft); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

.chat-input { display: flex; gap: 0.7rem; align-items: flex-end; }
.chat-input textarea {
  flex: 1;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.7rem;
  font-family: inherit;
  resize: none;
}

.empty { color: var(--text-dim); text-align: center; padding: 1rem 0; }
.inline { display: inline; }

.search-bar { display: flex; gap: 0.7rem; align-items: center; }
.search-bar input {
  flex: 1;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.8rem;
  font-family: inherit;
  font-size: 0.95rem;
}

.tag-cloud { display: flex; gap: 0.45rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tag-chip {
  display: inline-block;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.7rem;
  font-size: 0.82rem;
  color: var(--text-dim);
}
.tag-chip:hover { border-color: var(--accent); color: var(--text); text-decoration: none; }
.tag-chip.active { background: color-mix(in srgb, var(--accent) 18%, transparent); border-color: var(--accent); color: var(--text); }
.tag-count { opacity: 0.7; font-size: 0.75rem; }
.entry-tags { margin-top: 0.5rem; display: flex; gap: 0.35rem; flex-wrap: wrap; }
.entry-tags a { text-decoration: none; }
.linklike {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 1rem;
  font-family: inherit;
  padding: 0;
}
.linklike:hover { text-decoration: underline; }

.msg.thinking .msg-bubble::after { content: "…"; animation: dots 1.2s infinite; }
@keyframes dots { 0% { content: ""; } 33% { content: "."; } 66% { content: ".."; } }

/* --- Analyse IA : éclairage du jour + humeur perçue ---------------------- */
.mood-hint {
  margin: 0.4rem 0 0;
  font-style: italic;
  color: var(--accent);
}
.reflection {
  border-color: var(--accent);
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 10%, transparent), transparent 55%);
  margin: 1.2rem 0;
}
.reflection h2 { margin-top: 0; }
.reflection-body h2 { font-size: 1rem; margin: 0.9rem 0 0.4rem; }
.reflection-body h2:first-child { margin-top: 0; }
.reflection-body p { margin: 0.4rem 0; }
.reflection-body ul { margin: 0.3rem 0; padding-left: 1.3rem; }
.reflection-body li { margin: 0.25rem 0; }
.mood-opinion { margin: 1.2rem 0; }
.mood-opinion h2 { margin-top: 0; font-size: 1rem; }
.mood-opinion p { margin: 0.3rem 0 0.8rem; color: var(--text-dim); }

/* --- Administration ------------------------------------------------------ */
.admin-section { margin-bottom: 1.6rem; }
.admin-section h2 { border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; }
.admin-nav { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.admin-nav a {
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: var(--text);
}
.admin-nav a.active { background: color-mix(in srgb, var(--accent) 18%, transparent); border-color: var(--accent); }
.admin-nav a:hover { text-decoration: none; border-color: var(--accent); }
.setting-row { margin-bottom: 0.9rem; }
.setting-row .hint { display: block; margin-top: 0.2rem; }
.setting-restart {
  display: inline-block;
  margin-left: 0.4rem;
  font-size: 0.75rem;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 999px;
  padding: 0 0.45rem;
}
.admin-form input[type="text"], .admin-form input[type="number"], .admin-form select,
.admin-form textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
}
.admin-form textarea { min-height: 20rem; font-family: ui-monospace, monospace; }
.flash {
  border: 1px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
}
.flash.error { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.skill-editor-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.skill-editor-row:last-child { border-bottom: none; }

/* --- Sélecteur de thème (barre supérieure) -----------------------------
   Le menu est rendu côté serveur : ouvrir le bouton ne déclenche aucune
   requête, la bascule se fait par simple changement d'attribut sur <html>. */
/* --- Sélecteur de langue -------------------------------------------------
   Deux pastilles FR / EN, l'active en surbrillance. Sans JS et en POST :
   la forme reste utilisable même si les scripts ne se chargent pas. */
.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  margin-right: 0.2rem;
}
.lang-switch .lang-option {
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  opacity: 0.55;
}
.lang-switch .lang-option:hover { opacity: 0.9; text-decoration: none; }
.lang-switch .lang-option.active {
  background: var(--bg-soft);
  opacity: 1;
}
.lang-sep { opacity: 0.35; font-size: 0.8rem; }

.theme-picker { position: relative; }
.theme-toggle { display: inline-flex; align-items: center; gap: 0.3rem; }
.theme-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.45rem);
  min-width: 175px;
  margin: 0;
  padding: 0.35rem;
  list-style: none;
  z-index: 60;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
}
.theme-menu li { margin: 0; }
.theme-menu button {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.theme-menu button:hover { background: var(--bg-soft); }
/* color-mix et non une copie de l'accent : l'état actif suit le thème. */
.theme-menu button.active {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}
.theme-swatch {
  width: 14px;
  height: 14px;
  flex: none;
  border-radius: 4px;
  border: 1px solid var(--border);
}
/* Aperçu indicatif du MODE (et non des couleurs exactes du thème, qu'on ne
   connaît pas ici : seules les variables du thème actif sont injectées). */
.theme-swatch[data-mode="dark"] { background: #12141a; }
.theme-swatch[data-mode="light"] { background: #f2f4fa; }

/* --- Administration des thèmes ------------------------------------------ */
.theme-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.theme-row:last-child { border-bottom: none; }
.theme-row-main { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.theme-active-badge {
  color: var(--on-accent);
  background: var(--accent-strong);
  border-radius: 999px;
  padding: 0.05rem 0.55rem;
  font-size: 0.75rem;
}
/* Aperçu : les points sont peints avec les variables du thème ACTIF, donc
   cette rangée montre le rendu courant — pas celui du thème listé. D'où
   l'étiquette explicite en dessous. */
.theme-preview { display: inline-flex; gap: 3px; margin-left: 0.35rem; }
.theme-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid var(--border);
}
.theme-sample { flex-basis: 100%; margin: 0; }

.color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 0.9rem;
  margin-top: 0.6rem;
}
.color-field { display: flex; flex-direction: column; gap: 0.3rem; }
.color-field label { font-size: 0.85rem; font-weight: 600; }
.color-field input[type="color"] {
  width: 100%;
  height: 38px;
  padding: 2px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.color-field code { font-size: 0.72rem; color: var(--text-dim); }

/* --- Indicateur « l'IA réfléchit » --------------------------------------
   Discret et non bloquant : l'entrée est déjà enregistrée et lisible,
   cette carte signale seulement qu'un complément arrive. */
.analysis-wait { display: flex; align-items: center; gap: 0.7rem; }
.analysis-wait p { margin: 0; }
.analysis-spinner {
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-top-color: var(--accent);
  animation: analysis-spin 0.9s linear infinite;
}
@keyframes analysis-spin { to { transform: rotate(360deg); } }
.analysis-slow .analysis-spinner { animation-duration: 2.5s; }

/* Respect de la préférence système : sans animation, on garde l'info. */
@media (prefers-reduced-motion: reduce) {
  .analysis-spinner { animation: none; }
}
