/* Portail Lajus — design system "outil interne accueillant".
   Public : utilisateurs novices (fonctions supports d'une entreprise de paysage).
   Principes : identité verte (métier paysage), hiérarchie visuelle forte
   (l'essentiel en grand, le détail replié), langage visuel doux (fonds teintés,
   coins arrondis, ombres légères) plutôt que du blanc uniforme. */

:root {
  /* Palette — vert "paysage" en couleur de marque */
  --vert-900: #14351f;
  --vert-800: #1c4428;
  --vert-700: #226332;
  --vert-600: #2e7d32;
  --vert-500: #3d9142;
  --vert-100: #e3f2e5;
  --vert-50:  #f0f7f1;

  --sidebar-bg: var(--vert-900);
  --sidebar-text: #cde5d3;
  --sidebar-active: rgba(255, 255, 255, .12);

  --bg: #f4f6f3;              /* fond légèrement teinté, pas de blanc brut */
  --surface: #ffffff;
  --border: #e3e8e1;
  --text: #1f2a22;
  --text-muted: #67736a;

  --accent: var(--vert-600);
  --accent-hover: var(--vert-700);
  --danger: #b3261e;
  --danger-bg: #fdeceb;
  --ok: #256c2a;
  --ok-bg: #e6f4e7;
  --warn-bg: #fdf3e0;
  --warn: #9a6700;

  --radius: 12px;
  --ombre: 0 1px 2px rgba(31, 42, 34, .06), 0 4px 12px rgba(31, 42, 34, .05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15.5px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}

/* ── Layout ─────────────────────────────────────────────────────────── */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 244px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.content {
  flex: 1;
  padding: 2.2rem 2.8rem 3rem;
  max-width: 1180px;
}

/* ── Sidebar ────────────────────────────────────────────────────────── */

.brand {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: 1.2rem 1.1rem;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
}

.brand-mark {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--vert-500);
  color: #fff;
  font-weight: 700;
  font-size: 1.15rem;
  display: flex; align-items: center; justify-content: center;
}

.brand strong { color: #fff; display: block; font-size: 1rem; line-height: 1.2; }
.brand small  { color: var(--sidebar-text); font-size: .74rem; }

.sidebar nav { flex: 1; padding: 1rem .7rem; }

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .62rem .8rem;
  margin-bottom: 3px;
  border-radius: 8px;
  border-left: 3px solid transparent;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: .92rem;
}
.sidebar nav a:hover  { background: var(--sidebar-active); color: #fff; }
.sidebar nav a.active {
  background: var(--sidebar-active);
  border-left-color: var(--vert-500);
  color: #fff;
  font-weight: 600;
}
.sidebar nav a svg { flex-shrink: 0; opacity: .9; }

.nav-section {
  padding: 1.1rem .8rem .35rem;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #86a58f;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1rem 1.1rem;
  border-top: 1px solid rgba(255, 255, 255, .1);
  font-size: .88rem;
}

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--vert-600);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; font-weight: 600;
  flex-shrink: 0;
}

.sidebar-footer .user-name { flex: 1; color: #eaf4ec; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer a { color: var(--sidebar-text); display: flex; }
.sidebar-footer a:hover { color: #fff; }

/* ── Titres & contenu ───────────────────────────────────────────────── */

h1 { font-size: 1.55rem; margin: 0 0 .35rem; letter-spacing: -.01em; }
h2 { font-size: 1.12rem; margin: 2rem 0 .7rem; }
h3 { font-size: 1rem; }
h4 { font-size: .92rem; margin: .4rem 0 .5rem; }
.page-sub { color: var(--text-muted); font-size: .93rem; margin: 0 0 1.6rem; max-width: 62ch; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.3rem 1.5rem;
  margin-bottom: 1.1rem;
  box-shadow: var(--ombre);
}

.card h3 { margin: 0 0 .4rem; }
.card > p { margin: 0 0 1rem; color: var(--text-muted); font-size: .9rem; max-width: 68ch; }

/* ── Bandeau d'état (hero) — fraîcheur des données sur l'accueil ────── */
/* Répond en un coup d'œil à LA question de l'utilisateur : "c'est bon ou pas ?" */

.hero-etat {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  border-radius: var(--radius);
  padding: 1.2rem 1.5rem;
  margin-bottom: 1.3rem;
  border: 1px solid var(--border);
  box-shadow: var(--ombre);
}
.hero-etat.ok   { background: var(--ok-bg);    border-color: #cce7cd; }
.hero-etat.err  { background: var(--danger-bg); border-color: #f5cdca; }
.hero-etat.muet { background: var(--surface); }

.hero-icone {
  width: 46px; height: 46px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--border);
}
.hero-etat.ok  .hero-icone { color: var(--ok); }
.hero-etat.err .hero-icone { color: var(--danger); }

.hero-etat strong { display: block; font-size: 1.05rem; margin-bottom: .1rem; }
.hero-etat p { margin: 0; color: var(--text-muted); font-size: .9rem; }

/* ── Formulaires / boutons ──────────────────────────────────────────── */

input[type="text"], input[type="password"], input[type="number"], textarea, select {
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: var(--surface);
  margin-bottom: .8rem;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid #bfe3c4;
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .58rem 1.15rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--vert-50); border-color: var(--vert-500); }

.exemples { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: 1rem; }
.exemples button {
  font: inherit;
  font-size: .8rem;
  padding: .35rem .75rem;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--vert-50);
  color: var(--vert-700);
  cursor: pointer;
}
.exemples button:hover { border-color: var(--vert-500); background: var(--vert-100); }

.checkbox-line { display: flex; align-items: center; gap: .45rem; font-size: .87rem; color: var(--text-muted); margin-bottom: .9rem; }
.checkbox-line input { width: auto; margin: 0; }

/* ── Résultats / tableaux ───────────────────────────────────────────── */

.resultats { margin-top: 1.2rem; }
.resultats .card { overflow-x: auto; }

table.dataframe, .resultats table, .card table {
  border-collapse: collapse;
  width: 100%;
  font-size: .85rem;
  background: var(--surface);
}
.resultats th, .card th {
  text-align: left;
  padding: .55rem .75rem;
  background: var(--vert-50);
  border-bottom: 1px solid var(--border);
  color: var(--vert-800);
  font-weight: 600;
  white-space: nowrap;
}
.resultats td, .card td { padding: .5rem .75rem; border-bottom: 1px solid var(--border); }
.resultats tbody tr:nth-child(even) td, .card tbody tr:nth-child(even) td { background: #fafcfa; }
.resultats tr:hover td, .card tbody tr:hover td { background: var(--vert-50); }

/* Graphique auto de la page Analyse libre (Chart.js a besoin d'un parent dimensionné) */
.graphique-boite { position: relative; width: 100%; }
.graphique-note  { margin: .6rem 0 0; }

/* Résultats d'Analyse libre : compteur + SQL repliable, puis tableau | graphique */
.resultats-entete { display: flex; align-items: baseline; gap: 1.2rem; flex-wrap: wrap; margin-bottom: .6rem; }
.resultats-entete .muted { margin: 0; }
.sql-details summary {
  color: var(--text-muted);
  font-size: .85rem;
  cursor: pointer;
}
.sql-details summary:hover { color: var(--vert-700); }
.sql-details[open] { flex-basis: 100%; }
.sql-details pre.sql { margin: .5rem 0 0; }

.resultats-duo {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.1rem;
  align-items: start;
}
.resultats-duo.pleine-largeur { grid-template-columns: minmax(0, 1fr); }
@media (max-width: 1100px) { .resultats-duo { grid-template-columns: minmax(0, 1fr); } }

#tableau-filtre { max-width: 300px; padding: .45rem .7rem; margin-bottom: .7rem; }

/* Tri par clic + colonnes numériques alignées à droite (fragment_resultats.html) */
th.triable { cursor: pointer; user-select: none; }
th.triable .fleche { color: #9aa79d; font-size: .72rem; margin-left: .3rem; }
th.triable:hover .fleche, th.triable[data-tri="asc"] .fleche, th.triable[data-tri="desc"] .fleche { color: var(--vert-600); }
.resultats th.nombre { text-align: right; }
.resultats td.nombre { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

pre.sql {
  background: #16241a;
  color: #d9e8dc;
  padding: .9rem 1.05rem;
  border-radius: 8px;
  font-size: .8rem;
  overflow-x: auto;
}

.note-erreur {
  background: var(--danger-bg);
  border: 1px solid #f0c4c0;
  color: var(--danger);
  border-radius: 8px;
  padding: .75rem .95rem;
  font-size: .88rem;
}

/* Badges avec pastille — lisibles même sans percevoir la couleur */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .18rem .6rem;
  border-radius: 99px;
  font-size: .76rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-ok  { background: var(--ok-bg); color: var(--ok); border: 1px solid #c4e3c6; }
.badge-err { background: var(--danger-bg); color: var(--danger); border: 1px solid #f0c4c0; }

.muted { color: var(--text-muted); font-size: .87rem; }

details > summary { cursor: pointer; }
details.card > summary { font-size: .95rem; }
details.card[open] > summary { margin-bottom: .8rem; }

iframe.dashboard {
  width: 100%;
  height: 800px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

/* Indicateur HTMX */
.htmx-indicator { display: none; color: var(--text-muted); font-size: .87rem; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-flex; align-items: center; gap: .45rem; }
.htmx-indicator::before {
  content: "";
  width: 14px; height: 14px;
  border: 2px solid var(--vert-100);
  border-top-color: var(--vert-600);
  border-radius: 50%;
  animation: tourne .8s linear infinite;
}
@keyframes tourne { to { transform: rotate(360deg); } }

/* ── Jobs / rapports / règles ───────────────────────────────────────── */

.etat-job { margin-top: .9rem; }
.etat-job:empty { margin: 0; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .8rem;
  margin: .9rem 0;
}
.stat {
  background: var(--vert-50);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .65rem .85rem;
  display: flex;
  flex-direction: column;
}
.stat-valeur  { font-size: 1.3rem; font-weight: 700; color: var(--vert-800); }
.stat-libelle { font-size: .76rem; color: var(--text-muted); }

.deux-colonnes { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
@media (max-width: 760px) { .deux-colonnes { grid-template-columns: 1fr; } }

.periode-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: .8rem;
  margin-bottom: .8rem;
}
@media (max-width: 760px) { .periode-grid { grid-template-columns: 1fr 1fr; } }

.champ-label { display: block; font-size: .87rem; margin-bottom: .35rem; }
label { font-size: .87rem; color: var(--text); }

select[multiple] { min-height: 8rem; }

.table-regles input[type="text"] { margin-bottom: 0; }
.table-regles .input-ordre { width: 4.5rem; margin-bottom: 0; }
.table-regles td { vertical-align: middle; }
.centre { text-align: center; }

.feedback { display: flex; align-items: center; gap: .5rem; margin-top: .8rem; }
.btn-feedback {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: .28rem .6rem;
  font-size: .95rem;
  line-height: 1;
  cursor: pointer;
}
.btn-feedback:hover { border-color: var(--accent); background: var(--vert-50); }

/* ── Chat (onglet Discuter) ─────────────────────────────────────────── */

.chat-entete { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.chat-entete .page-sub { margin-bottom: 1rem; }

.chat-conteneur {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 13.5rem);
  min-height: 420px;
  padding: 0;
  overflow: hidden;
}

.fil {
  flex: 1;
  overflow-y: auto;
  padding: 1.3rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .8rem;
}

.chat-vide { text-align: center; margin: auto; }

.bulle {
  max-width: 72%;
  padding: .7rem 1rem;
  border-radius: 14px;
  font-size: .93rem;
  line-height: 1.55;
  overflow-wrap: break-word;
}
.bulle.moi {
  align-self: flex-end;
  background: var(--vert-100);
  border: 1px solid #cfe8d3;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.bulle.ia {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Curseur clignotant pendant que la réponse arrive en flux */
.bulle.ia.en-cours .md::after {
  content: "▍";
  color: var(--vert-600);
  animation: clignote 1s steps(2) infinite;
}
.bulle.ia.en-cours .md:empty::after { content: "▍ L'assistant écrit…"; font-size: .85em; color: var(--text-muted); }
@keyframes clignote { 50% { opacity: 0; } }

/* Markdown dans les réponses */
.bulle .md > :first-child { margin-top: 0; }
.bulle .md > :last-child  { margin-bottom: 0; }
.bulle .md pre {
  background: #16241a;
  color: #d9e8dc;
  padding: .7rem .9rem;
  border-radius: 8px;
  overflow-x: auto;
  font-size: .8rem;
}
.bulle .md code { background: #e8ede8; padding: .08rem .3rem; border-radius: 4px; font-size: .85em; }
.bulle .md pre code { background: none; padding: 0; }
.bulle .md table { margin: .5rem 0; }
.bulle .md th, .bulle .md td { border: 1px solid var(--border); padding: .35rem .6rem; }

.composer {
  border-top: 1px solid var(--border);
  padding: .9rem 1.2rem;
  background: var(--surface);
}
.composer textarea { margin-bottom: .5rem; resize: vertical; }
.composer-actions { display: flex; align-items: center; justify-content: flex-end; gap: .9rem; }
.composer.htmx-request .btn { opacity: .55; pointer-events: none; }

/* ── Page de connexion ──────────────────────────────────────────────── */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--vert-50) 0%, var(--bg) 55%);
}
.login-card {
  width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2.1rem 2.3rem 1.9rem;
  box-shadow: 0 8px 32px rgba(31, 42, 34, .1);
}
.login-card .brand { border: none; padding: 0 0 1.3rem; }
.login-card .brand strong { color: var(--text); }
.login-card .brand small  { color: var(--text-muted); }
.login-card .btn { width: 100%; justify-content: center; }

/* ── Responsive ─────────────────────────────────────────────────────── */

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .sidebar nav { display: flex; flex-wrap: wrap; padding: .4rem; }
  .nav-section { display: none; }
  .content { padding: 1.2rem; }
}
