/* NDE Terrain — back-office. Feuille autonome : aucune ressource externe (intranet NDE). */
:root {
  --encre: #15242E;
  --texte: #1F2A30;
  --doux: #5E6B72;
  --bleu: #00679A; /* bleu NDE profond (logo), 6,2:1 sur blanc */
  --bleu-fonce: #00476B;
  --bleu-pale: #E3F3FB;
  --orange: #B8651C;
  --orange-pale: #FBF1E6;
  --vert: #2E7D4F;
  --vert-pale: #E7F4EC;
  --rouge: #B3261E;
  --rouge-pale: #FCEBEA;
  --trait: #D6DEE3;
  --fond: #F3F6F8;
  --carte: #FFFFFF;
  --rayon: 8px;
  --ombre: 0 1px 2px rgba(21, 36, 46, .06), 0 1px 8px rgba(21, 36, 46, .04);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--fond); color: var(--texte);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--bleu); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; color: var(--encre); }
h2 { font-size: 17px; margin: 0 0 12px; color: var(--encre); }
h3 { font-size: 15px; margin: 0 0 8px; color: var(--encre); }
p { margin: 0 0 10px; }
.discret { color: var(--doux); font-size: 13px; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 13px; }

/* ---------- ossature ---------- */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.menu { background: var(--encre); color: #C9D6DD; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.marque { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; font-weight: 700; font-size: 17px; }
.marque .logo-nde { height: 42px; width: auto; flex: none; background: #fff; border-radius: 8px; padding: 4px 7px; box-sizing: content-box; }
.marque small { display: block; font-weight: 400; font-size: 11px; color: #8FA3AE; letter-spacing: .04em; }
.menu nav a { display: flex; align-items: center; gap: 10px; color: #C9D6DD; padding: 9px 10px; border-radius: 6px; font-size: 14px; }
.menu nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.menu nav a.actif { background: var(--bleu); color: #fff; }
.menu nav .titre { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7F939E; padding: 16px 10px 6px; }
.menu nav .compteur { margin-left: auto; background: var(--orange); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; font-weight: 600; }
.principal { min-width: 0; }
.barre { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 28px; background: var(--carte); border-bottom: 1px solid var(--trait); }
.barre .qui { font-size: 13px; color: var(--doux); }
.barre .qui strong { color: var(--texte); }
.contenu { padding: 24px 28px 48px; max-width: 1280px; }
.entete { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.barre .bouton-menu { display: none; }

/* ---------- blocs ---------- */
.carte { background: var(--carte); border: 1px solid var(--trait); border-radius: var(--rayon); box-shadow: var(--ombre); padding: 18px 20px; margin-bottom: 18px; }
.grille { display: grid; gap: 18px; }
.grille.deux { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grille.trois { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grille.quatre { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grille.cote { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
.chiffre { display: block; padding: 16px 18px; border-radius: var(--rayon); background: var(--carte); border: 1px solid var(--trait); box-shadow: var(--ombre); color: inherit; }
a.chiffre:hover { text-decoration: none; border-color: var(--bleu); }
.chiffre .valeur { font-size: 28px; font-weight: 700; color: var(--encre); line-height: 1.1; }
.chiffre .libelle { font-size: 13px; color: var(--doux); }
.chiffre.alerte .valeur { color: var(--orange); }

/* ---------- tableaux ---------- */
.defile { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--doux); font-weight: 600; padding: 10px 12px; border-bottom: 2px solid var(--trait); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--trait); vertical-align: top; }
tbody tr:hover { background: #F8FAFB; }
td.nombre, th.nombre { text-align: right; }
.vide { padding: 28px; text-align: center; color: var(--doux); }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 12px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #EEF1F3; color: var(--doux); }
.badge.bleu { background: var(--bleu-pale); color: var(--bleu-fonce); }
.badge.vert { background: var(--vert-pale); color: var(--vert); }
.badge.orange { background: var(--orange-pale); color: var(--orange); }
.badge.rouge { background: var(--rouge-pale); color: var(--rouge); }
.badge.encre { background: var(--encre); color: #fff; }

/* ---------- formulaires ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--encre); }
input[type=text], input[type=password], input[type=email], input[type=date], input[type=number], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #C3CED5; border-radius: 6px; font: inherit; background: #fff; color: var(--texte);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(0,103,154,.35); border-color: var(--bleu); }
textarea { min-height: 80px; resize: vertical; }
.champ { margin-bottom: 14px; }
.aide { font-size: 12px; color: var(--doux); margin-top: 3px; }
.erreur-champ { font-size: 12px; color: var(--rouge); margin-top: 3px; }
.ligne-filtres { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.ligne-filtres .champ { margin: 0; min-width: 150px; flex: 1; }
.case { display: flex; align-items: center; gap: 6px; font-weight: 400; font-size: 14px; margin: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 6px; border: 1px solid transparent; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; background: var(--bleu); color: #fff; white-space: nowrap; }
.btn:hover { background: var(--bleu-fonce); text-decoration: none; }
.btn.second { background: #fff; color: var(--encre); border-color: #C3CED5; }
.btn.second:hover { background: #F3F6F8; }
.btn.danger { background: var(--rouge); }
.btn.danger:hover { background: #8F1E18; }
.btn.succes { background: var(--vert); }
.btn.petit { padding: 5px 10px; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- messages ---------- */
.message { padding: 12px 16px; border-radius: var(--rayon); margin-bottom: 18px; font-size: 14px; border-left: 4px solid; }
.message.succes { background: var(--vert-pale); border-color: var(--vert); }
.message.erreur { background: var(--rouge-pale); border-color: var(--rouge); }
.message.avertissement { background: var(--orange-pale); border-color: var(--orange); }

/* ---------- fiche mission ---------- */
.proprietes { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; margin: 0; }
.proprietes dt { color: var(--doux); }
.proprietes dd { margin: 0; }
.chronologie { list-style: none; margin: 0; padding: 0; }
.chronologie li { position: relative; padding: 0 0 14px 22px; font-size: 14px; }
.chronologie li::before { content: ""; position: absolute; left: 5px; top: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--bleu); }
.chronologie li::after { content: ""; position: absolute; left: 9px; top: 18px; bottom: 0; width: 1px; background: var(--trait); }
.chronologie li:last-child::after { display: none; }
.vignettes { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.vignette { width: 150px; }
.vignette a { display: block; width: 150px; height: 112px; border-radius: 6px; overflow: hidden; background: #E3E9ED; border: 1px solid var(--trait); }
.vignette img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vignette .meta { font-size: 11px; color: var(--doux); margin-top: 4px; word-break: break-all; }
.signalements { margin: 10px 0 0; padding: 0; list-style: none; }
.signalements li { background: var(--orange-pale); border-left: 3px solid var(--orange); padding: 6px 10px; margin-bottom: 6px; font-size: 13px; border-radius: 0 6px 6px 0; }
details.panneau { border: 1px solid var(--trait); border-radius: 6px; padding: 10px 12px; margin-top: 10px; }
details.panneau summary { cursor: pointer; font-weight: 600; font-size: 14px; }
details.panneau[open] summary { margin-bottom: 10px; }

/* ---------- connexion ---------- */
.page-connexion { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--encre) 0%, #1D4A60 100%); }
.boite-connexion { width: 100%; max-width: 380px; background: #fff; border-radius: 12px; padding: 30px 28px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.boite-connexion .marque { color: var(--encre); padding: 0 0 20px; }
.menu .marque { flex-direction: column; align-items: flex-start; gap: 10px; }
.menu .marque .logo-nde { height: 48px; padding: 6px 10px; }
.boite-connexion .marque .logo-nde { height: 64px; padding: 0; background: none; }
.boite-connexion .btn { width: 100%; margin-top: 6px; padding: 11px; }

/* ---------- pagination ---------- */
.pagination { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; font-size: 13px; }
.pagination a, .pagination span { padding: 5px 10px; border-radius: 6px; border: 1px solid var(--trait); background: #fff; }
.pagination .courant { background: var(--bleu); color: #fff; border-color: var(--bleu); }
.pagination .inactif { color: #A8B4BB; }

/* ---------- petits écrans ---------- */
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .menu { position: fixed; inset: 0 auto 0 0; width: 260px; transform: translateX(-100%); transition: transform .2s; z-index: 20; }
  .app.menu-ouvert .menu { transform: none; }
  .barre .bouton-menu { display: inline-flex; }
  .barre, .contenu { padding-left: 16px; padding-right: 16px; }
  .grille.deux, .grille.trois, .grille.cote { grid-template-columns: 1fr; }
  .grille.quatre { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media print {
  .menu, .barre, .actions, .ligne-filtres { display: none !important; }
  .app { display: block; }
  .carte { box-shadow: none; }
}
td .mono, td.mono { white-space: nowrap; }

/* ---------- PIL : pilotage et tableau de bord de direction ---------- */
.pil-entete { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.pil-entete h2 { margin-bottom: 4px; }
.pil-table td.nombre { white-space: nowrap; }
.pil-table td.discret { font-size: 12px; }
.pil-definitions .proprietes { font-size: 13px; }
.pil-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--encre); }
.pil-carte { height: 560px; border-radius: 6px; border: 1px solid var(--trait); margin-top: 8px; }
.pil-pastille { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.pil-pastille.pil-constats { background: var(--rouge); }
.pil-pastille.pil-coupures { background: var(--bleu); }
.pil-pastille.pil-ecarts { background: var(--orange); }
@media (max-width: 960px) { .pil-carte { height: 420px; } }

/* ---------- graphiques (rendu serveur, sans script) ---------- */
/* Palette validée (contrôle daltonisme et contraste) : série 1 = orange NDE (fraudes), série 2 = bleu NDE. */
:root { --serie-1: #E05206; --serie-2: #00679A; --grille: #E6ECF0; }
.titre-section { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--doux); margin: 22px 0 10px; }
.gr-vide { margin: 8px 0; }
.gr-s1 { background: var(--serie-1); }
.gr-s2 { background: var(--serie-2); }
.gr-legende { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--texte); margin: 4px 0 10px; }
.gr-legende span { display: inline-flex; align-items: center; gap: 6px; }
.gr-cle { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: none; }

/* Barres horizontales */
.gr-barres { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.gr-barres li { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; align-items: center; gap: 10px; font-size: 13.5px; }
.gr-barres-libelle { color: var(--texte); overflow-wrap: anywhere; }
.gr-barres-piste { height: 18px; display: flex; align-items: center; }
.gr-barres-barre { display: block; height: 18px; background: var(--serie-2); border-radius: 0 4px 4px 0; min-width: 0; transition: filter .15s; }
.gr-barres li:hover .gr-barres-barre { filter: brightness(1.15); }
.gr-barres-valeur { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--encre); min-width: 2ch; text-align: right; }

/* Colonnes par jour */
.gr-colonnes { display: grid; grid-template-columns: auto 1fr; grid-template-rows: 200px auto; column-gap: 8px; }
.gr-axe-y { position: relative; width: 32px; font-size: 11px; color: var(--doux); font-variant-numeric: tabular-nums; }
.gr-axe-y span { position: absolute; right: 0; transform: translateY(50%); }
.gr-zone { position: relative; border-bottom: 1px solid #B9C5CC; }
.gr-grille { position: absolute; left: 0; right: 0; height: 1px; background: var(--grille); }
.gr-barres-jours { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 2px; }
.gr-jour { position: relative; flex: 1 1 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; outline: none; cursor: default; }
.gr-jour:hover, .gr-jour:focus-visible { background: rgba(0, 103, 154, .06); }
.gr-jour:focus-visible { box-shadow: inset 0 0 0 2px var(--bleu); }
.gr-pile { width: 100%; max-width: 24px; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.gr-seg { display: block; flex-basis: 0; min-height: 2px; }
.gr-pile .gr-seg:first-child { border-radius: 4px 4px 0 0; }
.gr-bulle { display: none; position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); z-index: 5; background: var(--encre); color: #fff; border-radius: 6px; padding: 8px 10px; font-size: 12.5px; white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.18); pointer-events: none; }
.gr-bulle span { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.gr-bulle .gr-cle { outline: 1px solid rgba(255,255,255,.6); }
.gr-jour:hover .gr-bulle, .gr-jour:focus .gr-bulle { display: block; }
.gr-jour { --decalage: 0; }
.gr-jour:nth-child(-n+4) .gr-bulle { left: 0; transform: none; }
.gr-jour:nth-last-child(-n+4) .gr-bulle { left: auto; right: 0; transform: none; }
.gr-axe-x { grid-column: 2; display: flex; gap: 2px; font-size: 11px; color: var(--doux); padding-top: 4px; }
.gr-axe-x span { flex: 1 1 0; text-align: center; white-space: nowrap; overflow: visible; }
.gr-message { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--doux); margin: 0; }
.gr-tableau { margin-top: 12px; font-size: 13px; }
.gr-tableau summary { cursor: pointer; color: var(--bleu); }
.gr-tableau .defile { max-height: 260px; overflow-y: auto; margin-top: 8px; }

/* Courbe de tendance */
.gr-courbe { width: 100%; height: auto; display: block; overflow: visible; }
.gr-courbe-base { stroke: var(--grille); stroke-width: 1; vector-effect: non-scaling-stroke; }
.gr-courbe-trait { fill: none; stroke: var(--serie-2); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.gr-courbe-point { fill: var(--serie-2); stroke: #fff; stroke-width: 2; vector-effect: non-scaling-stroke; }
.gr-courbe-cible { fill: transparent; }
.gr-courbe-cible:hover { fill: rgba(0, 103, 154, .08); }
.gr-courbe-dates { display: flex; justify-content: space-between; font-size: 11px; color: var(--doux); }
.tendances { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(230px, 100%), 1fr)); gap: 14px; }
.tendance { min-width: 0; }
.tendance { border: 1px solid var(--trait); border-radius: var(--rayon); padding: 12px 14px; }
.tendance .valeur { font-size: 22px; font-weight: 700; color: var(--encre); }
.tendance .libelle { font-size: 12.5px; color: var(--doux); min-height: 2.4em; }

/* Jauge (part d'un total) */
.jauge { height: 6px; background: var(--bleu-pale); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.jauge span { display: block; height: 100%; background: var(--bleu); border-radius: 3px; }

/* ---------- en-tête : menu « compte » ---------- */
.compte { position: relative; margin-left: auto; }
.compte > summary { list-style: none; display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 4px 6px 4px 4px; border-radius: 999px; border: 1px solid transparent; }
.compte > summary::-webkit-details-marker { display: none; }
.compte > summary:hover, .compte[open] > summary { background: var(--fond); border-color: var(--trait); }
.compte > summary:focus-visible { outline: 2px solid var(--bleu); outline-offset: 2px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--bleu); color: #fff; font-weight: 700; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; flex: none; letter-spacing: .02em; }
.compte-qui { display: flex; flex-direction: column; line-height: 1.25; font-size: 13px; color: var(--doux); }
.compte-qui strong { color: var(--texte); font-size: 13.5px; }
.compte-chevron { color: var(--doux); font-size: 11px; }
.compte-panneau { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: 260px; background: var(--carte); border: 1px solid var(--trait); border-radius: 10px; box-shadow: 0 10px 30px rgba(21,36,46,.16); padding: 8px; }
.compte-entete { padding: 8px 10px 10px; border-bottom: 1px solid var(--trait); margin-bottom: 6px; font-size: 13px; color: var(--doux); display: grid; gap: 2px; }
.compte-entete strong { color: var(--texte); font-size: 14px; }
.compte-panneau a, .compte-panneau button { display: flex; width: 100%; align-items: center; gap: 8px; padding: 10px; border-radius: 6px; font: inherit; font-size: 14px; color: var(--texte); background: none; border: 0; cursor: pointer; text-align: left; }
.compte-panneau a:hover, .compte-panneau button:hover { background: var(--fond); text-decoration: none; }
.compte-panneau form { margin: 0; }
.compte-panneau .sortie { color: var(--rouge); }

/* ---------- voile du menu (petits écrans) ---------- */
.voile { display: none; }

/* ---------- colonnes d'un flux d'export ---------- */
.colonnes-flux { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.colonnes-flux code { font-family: Consolas, "Courier New", monospace; font-size: 12px; background: var(--fond); border: 1px solid var(--trait); border-radius: 4px; padding: 1px 6px; color: var(--texte); overflow-wrap: anywhere; }

@media (max-width: 960px) {
  .app.menu-ouvert .menu { box-shadow: 0 10px 40px rgba(0,0,0,.3); }
  .app.menu-ouvert .voile { display: block; position: fixed; inset: 0; z-index: 15; background: rgba(13, 25, 33, .45); }
  .barre { gap: 8px; padding-top: 8px; padding-bottom: 8px; }
}

/* ---------- smartphone ---------- */
@media (max-width: 720px) {
  .compte-qui, .compte-chevron { display: none; }
  .compte > summary { padding: 2px; }
  .barre .bouton-menu { padding: 8px 12px; }
  .contenu { padding-top: 16px; }
  .entete { align-items: flex-start; }
  h1 { font-size: 20px; }
  .carte { padding: 14px; }
  .grille.quatre { grid-template-columns: 1fr 1fr; gap: 10px; }
  .gr-colonnes { grid-template-rows: 170px auto; }
  .gr-barres li { grid-template-columns: 1fr auto; }
  .gr-barres { gap: 8px; }
  .gr-barres-piste { grid-column: 1 / -1; grid-row: 2; height: 12px; }
  .gr-barres-barre { height: 12px; }
  .gr-axe-x span:not(:first-child):not(:last-child) { visibility: hidden; }

  /* Tableaux en cartes : chaque ligne devient une fiche « intitulé : valeur » (intitulés posés par nde.js). */
  .carte[style*="padding:0"] { padding: 0 !important; }
  table.en-cartes thead { display: none; }
  table.en-cartes, table.en-cartes tbody, table.en-cartes tr, table.en-cartes td { display: block; width: 100%; }
  table.en-cartes tr { padding: 12px 14px; border-bottom: 1px solid var(--trait); }
  table.en-cartes tr:last-child { border-bottom: 0; }
  table.en-cartes td { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; padding: 4px 0; border: 0; text-align: right; min-height: 0; }
  table.en-cartes td::before { content: attr(data-label); flex: none; max-width: 42%; text-align: left; font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--doux); }
  table.en-cartes td:not([data-label])::before, table.en-cartes td[data-label=""]::before { display: none; }
  table.en-cartes td:not([data-label]), table.en-cartes td[data-label=""] { justify-content: flex-start; text-align: left; }
  table.en-cartes td:first-child { font-weight: 600; }
  table.en-cartes .valeur-cellule { min-width: 0; overflow-wrap: anywhere; }
  table.en-cartes .valeur-cellule .actions, table.en-cartes .valeur-cellule form { display: inline-flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
  table.en-cartes td .mono, table.en-cartes td.mono { white-space: normal; overflow-wrap: anywhere; }
  table.en-cartes td.vide { text-align: center; justify-content: center; }
  table.en-cartes td .actions, table.en-cartes td form.actions { justify-content: flex-end; flex-wrap: wrap; }
}

p .mono { overflow-wrap: anywhere; }
.pil-table td:first-child, .pil-table th:first-child { white-space: nowrap; }
