/* =====================================================================
   Bati'Tools — charte.css
   Charte graphique commune : variables de design (couleurs, espacements,
   typographie, rayons, ombres) + mécanisme clair/sombre.

   Ce fichier ne contient QUE des tokens (variables). Il ne redéfinit pas
   encore les styles des boutons, cartes, formulaires, etc. — ça viendra
   page par page, à mesure qu'on migre chaque page dessus.

   Palette : reprise à l'identique de style-v0.css / base-v0.css
   (ambre #edb518 + rouge sombre #79031d), avec deux corrections de
   contraste repérées (texte d'erreur illisible sur fond rouge sombre,
   placeholder illisible dans les champs de saisie).
   ===================================================================== */

:root {
  /* ---------- Espacements ---------- */
  --space-1: 0.5rem;   /* 8px */
  --space-2: 0.75rem;  /* 12px */
  --space-3: 1rem;     /* 16px */
  --space-4: 1.25rem;  /* 20px */
  --space-5: 1.5rem;   /* 24px */
  --space-6: 2rem;     /* 32px */

  /* ---------- Rayons ---------- */
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;

  /* ---------- Ombres ---------- */
  --shadow-focus: 0 0 0 3px color-mix(in oklab, var(--accent) 25%, transparent);
  --shadow-card:  0 4px 15px rgba(0, 0, 0, 0.25);

  /* ---------- Typographie fluide ---------- */
  --fs-0: clamp(0.95rem, 0.8rem + 0.4vw, 1rem);     /* texte courant */
  --fs-1: clamp(1.05rem, 0.9rem + 0.6vw, 1.1rem);   /* texte un peu plus gros */
  --fs-2: clamp(1.25rem, 1.05rem + 0.8vw, 1.5rem);  /* sous-titres */
  --fs-3: clamp(1.45rem, 1.2rem + 1.2vw, 1.9rem);   /* titres */

  /* ---------- Couleurs — thème clair (par défaut) ---------- */
  --bg:            #edb518;  /* arrière-plan global (ambre) */
  --surface:       #79031d;  /* panneaux / cartes / boîtes de résultat (rouge sombre) */
  --text:          #f5f7f7;  /* texte principal (sur --bg ou --surface) */
  --field-text:    #0b0e13;  /* texte À L'INTÉRIEUR des champs de saisie (fond clair) */
  --field-bg:      #f5f7f7;  /* fond des champs de saisie */
  --muted:         #000407;  /* texte secondaire sur fond clair (--bg) */
  --border:        #f5f7f7;  /* séparateurs */
  --accent:        #79031d;  /* couleur d'action principale (boutons, liens) */
  --ok:            #cccccc;  /* texte de succès */
  --err:           #ffb4a8;  /* texte d'erreur — corrigé : l'ancien #b3261e était
                                quasi illisible sur le fond --surface (rouge sur rouge) */
  --input-placeholder: #6b7280; /* corrigé : l'ancien #cccccc était illisible
                                    sur le fond clair des champs (--field-bg) */

  /* Libellés "entrée" / "sortie" des cartes d'outils (page d'accueil) */
  --data-in:  #9aa6b2;  /* corrigé : l'ancien #798080 manquait de contraste sur --surface */
  --data-out: #d5e4a4;

  /* Variante de --muted lisible sur un fond --surface (ex: texte secondaire
     à l'intérieur d'une .card). --muted seul est prévu pour un fond --bg clair
     et devient illisible sur --surface (rouge sombre) : voir règle .card .hint
     plus bas. Calculé à partir de --text/--surface, donc reste correct
     automatiquement quel que soit le thème (clair/sombre/manuel). */
  --muted-on-surface: color-mix(in oklab, var(--text) 65%, var(--surface));

  /* ---------- Mesures des champs / contrôles ---------- */
  --control-pad-y: 0.8rem;
  --control-pad-x: 0.9rem;
  --control-font: 1rem; /* ≥16px pour éviter le zoom auto sur iOS */

  --input-control-min-h:   2.5rem;   /* ≈ 40px (densité compacte) */
  --input-control-ideal-h: 2.75rem;  /* ≈ 44px (recommandé) */
  --input-control-max-h:   3rem;     /* ≈ 48px (confort) */
  --input-control-px: 0.875rem;
  --input-control-py: 0.5rem;
  --input-control-radius: 0.5rem;
}

/* ---------- Couleurs — thème sombre (automatique, selon l'OS) ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0d1117;
    --surface:       #161b22;
    --text:          #e6eaf2;
    --field-text:    #0e1116;
    --field-bg:      #e6eaf2;
    --muted:         #9aa6b2;
    --border:        #2b3344;
    --accent:        #60a5fa;
    --ok:            #cccccc;
    --err:           #f87171;
    --input-placeholder: #6b7280;
  }
}

/* ---------- Bascule manuelle (indépendante des préférences OS) ----------
   Un bouton pourra plus tard poser data-theme="light" ou data-theme="dark"
   sur <html> (et retenir le choix, ex. via localStorage) pour forcer un
   thème quel que soit le réglage du système. Tant qu'aucun choix manuel
   n'est fait, c'est prefers-color-scheme ci-dessus qui décide. */
html[data-theme="light"] {
  color-scheme: light;
  --bg:            #edb518;
  --surface:       #79031d;
  --text:          #f5f7f7;
  --field-text:    #0b0e13;
  --field-bg:      #f5f7f7;
  --muted:         #000407;
  --border:        #f5f7f7;
  --accent:        #79031d;
  --ok:            #cccccc;
  --err:           #ffb4a8;
  --input-placeholder: #6b7280;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg:            #0d1117;
  --surface:       #161b22;
  --text:          #e6eaf2;
  --field-text:    #0e1116;
  --field-bg:      #e6eaf2;
  --muted:         #9aa6b2;
  --border:        #2b3344;
  --accent:        #60a5fa;
  --ok:            #cccccc;
  --err:           #f87171;
  --input-placeholder: #6b7280;
}

/* =====================================================================
   Composants partagés
   Ajoutés au fur et à mesure des migrations de pages (première page :
   connexion.php). Un même type d'objet DOM = une même classe partout.
   ===================================================================== */

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Layout ---------- */
.container {
  max-width: 560px;
  margin: 0 auto;
  padding-inline: var(--space-3);
}
.container-wide {
  max-width: 1100px;
  margin: 0 auto;
  padding-inline: var(--space-3);
}
.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

/* ---------- En-tête / pied de page de site ---------- */
.site-header, .site-footer {
  background: var(--surface);
  color: var(--text);
  padding: var(--space-3) 0;
}
.site-title {
  font-size: var(--fs-2);
  margin: 0;
  color: var(--text);
}
.site-nav {
  display: flex;
  gap: var(--space-3);
  align-items: center;
}
.site-footer {
  margin-top: var(--space-6);
}
.site-footer small { color: var(--muted-on-surface); }
/* Pied de page simple (une seule ligne centrée) : connexion/déconnexion/inscription */
.site-footer > .container { text-align: center; }

/* ---------- Liens texte ---------- */
.link {
  color: var(--text);
  text-decoration: underline;
}
.link:hover, .link:focus-visible { opacity: .8; }

/* ---------- Titres de section ---------- */
.h {
  font-size: var(--fs-2);
  margin: 0 0 var(--space-3);
  color: var(--text);
}

/* ---------- Carte / panneau ---------- */
.card {
  background: var(--surface);
  color: var(--text);
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: var(--control-pad-y) var(--control-pad-x);
  font-size: var(--control-font);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  transition: filter .15s ease, transform .05s ease;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }
.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: color-mix(in oklab, var(--text) 10%, transparent); }
.btn.danger { border-color: var(--err); color: var(--err); background: transparent; }

/* ---------- Formulaires ---------- */
.form {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-3);
}
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.field label { font-weight: 600; font-size: var(--fs-0); }

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
select {
  font: inherit;
  background: var(--field-bg);
  color: var(--field-text);
  border: 1px solid var(--border);
  border-radius: var(--input-control-radius);
  padding: var(--input-control-py) var(--input-control-px);
  min-height: var(--input-control-ideal-h);
  width: 100%;
}
input::placeholder { color: var(--input-placeholder); }

:where(input, button, .btn):focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
}

.hint { color: var(--muted); font-size: var(--fs-0); }
.form-message { color: var(--err); font-size: var(--fs-0); min-height: 1.2em; }

/* ---------- Messages (succès / erreurs) ---------- */
.success, .errors {
  padding: var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--fs-0);
  margin-bottom: var(--space-3);
}
.success {
  background: color-mix(in oklab, var(--ok) 25%, var(--surface));
  border: 1px solid var(--ok);
  color: var(--text);
}
.errors {
  background: color-mix(in oklab, var(--err) 20%, var(--surface));
  border: 1px solid var(--err);
  color: var(--text);
}
.errors ul { margin: 0; padding-left: var(--space-4); }

.muted { color: var(--muted); }

/* --muted est conçu pour un fond --bg clair ; à l'intérieur d'un bloc sur
   fond --surface (carte, en-tête, pied de page), on utilise la variante
   adaptée pour rester lisible. Un .muted/.hint dans une cellule de tableau
   (fond --field-bg clair) garde volontairement la couleur de base. */
.card .hint, .card .muted,
.site-header .hint, .site-header .muted,
.site-footer .hint, .site-footer .muted {
  color: var(--muted-on-surface);
}

/* =====================================================================
   Page d'accueil (index.php)
   ===================================================================== */

/* ---------- Logo + badge utilisateur dans l'en-tête ---------- */
.site-header h2 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: 0;
}
.user-tag {
  font-size: var(--fs-0);
  opacity: .9;
  color: var(--text);
}

/* ---------- Menu burger (mobile) ---------- */
.burger {
  display: none;
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: var(--space-1);
  margin-left: auto;
  border-radius: var(--radius-sm);
}
.burger:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}
.burger-line {
  display: block;
  width: 26px;
  height: 2px;
  background: var(--text);
  margin: 5px 0;
  transition: transform .25s ease, opacity .25s ease;
}
.burger[aria-expanded="true"] .burger-line:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.burger[aria-expanded="true"] .burger-line:nth-child(2) { opacity: 0; }
.burger[aria-expanded="true"] .burger-line:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.site-header nav a {
  color: var(--text);
  text-decoration: none;
  margin-left: var(--space-3);
  font-weight: 600;
  transition: opacity .2s;
}
.site-header nav a:hover { opacity: .75; }

@media (max-width: 768px) {
  .burger { display: inline-block; }
  #primaryNav {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    background: var(--surface);
    display: grid;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    transform-origin: top center;
    transform: scaleY(0);
    opacity: 0;
    pointer-events: none;
    transition: transform .25s ease, opacity .25s ease;
    z-index: 1000;
    border-bottom-left-radius: var(--radius-md);
    border-bottom-right-radius: var(--radius-md);
  }
  #primaryNav a { margin-left: 0; padding: var(--space-2); border-radius: var(--radius-sm); }
  #primaryNav.is-open { transform: scaleY(1); opacity: 1; pointer-events: auto; }
}
@media (min-width: 769px) {
  #primaryNav { display: flex; }
}

/* ---------- Héro ---------- */
.hero {
  text-align: center;
  padding-bottom: var(--space-5);
}
.hero h1 { font-size: var(--fs-3); }
.hero p { max-width: 600px; margin: var(--space-2) auto var(--space-3); }

/* ---------- Services / cartes ---------- */
.services { padding: var(--space-5) var(--space-3); }
.services h2 { text-align: center; margin-bottom: var(--space-5); color: var(--text); }
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: var(--space-4);
}
.card h3 { margin: 0 0 var(--space-2); color: var(--text); }

/* Libellés d'entrée / sortie sur les cartes d'outils */
.inData  { color: var(--data-in, #9aa6b2); }
.outData { color: var(--data-out, #d5e4a4); }

/* ---------- Pied de page riche (colonnes) ---------- */
.footer-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  text-align: left;
}
.footer-container h4 { margin: 0 0 var(--space-2); color: var(--text); }
.footer-container ul { list-style: none; margin: 0; padding: 0; }
.footer-container ul li { margin-bottom: var(--space-1); }
.footer-container ul li a { color: var(--text); text-decoration: none; font-size: var(--fs-0); }
.footer-container ul li a:hover { text-decoration: underline; }
.footer-bottom {
  text-align: center;
  margin-top: var(--space-5);
  font-size: var(--fs-0);
  color: var(--muted-on-surface);
  border-top: 1px solid var(--border);
  padding-top: var(--space-3);
}

/* =====================================================================
   Page d'administration (admin.php)
   Chrome (en-tête, chips, badges, pagination) aux couleurs de la charte ;
   le tableau lui-même reste sur un fond clair (--field-bg) pour la
   lisibilité d'une liste dense de données.
   ===================================================================== */
.bar { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.links a { color: var(--text); text-decoration: none; }
.links a:hover { text-decoration: underline; }

.flash {
  background: color-mix(in oklab, var(--err) 20%, var(--surface));
  border: 1px solid var(--err);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
  color: var(--text);
}

/* ---------- Chips (filtres) ---------- */
.chip a {
  display: inline-block;
  padding: var(--space-1) var(--space-2);
  border-radius: 999px;
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  background: transparent;
}
.chip a:hover { background: color-mix(in oklab, var(--text) 10%, transparent); }
.chip a.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- Tableau ---------- */
.table-wrap { overflow: auto; border-radius: var(--radius-lg); }
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--field-bg);
  color: var(--field-text);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
th, td {
  padding: var(--space-2);
  border-bottom: 1px solid color-mix(in oklab, var(--field-text) 12%, transparent);
  text-align: left;
  font-size: var(--fs-0);
  vertical-align: middle;
}
th {
  background: color-mix(in oklab, var(--field-text) 6%, var(--field-bg));
  position: sticky;
  top: 0;
  z-index: 2;
}
th.sticky-col, td.sticky-col { position: sticky; left: 0; background: var(--field-bg); z-index: 3; }
th.sticky-col { background: color-mix(in oklab, var(--field-text) 6%, var(--field-bg)); z-index: 4; }
td, th { min-width: 120px; }
td.sticky-col, th.sticky-col { min-width: 60px; }
.nowrap { white-space: nowrap; }

/* ---------- Badges de statut (couleurs sémantiques, indépendantes de la charte) ---------- */
.badge { display: inline-block; padding: 4px 8px; border-radius: 999px; font-size: 12px; }
.badge.ok   { background: #e6ffed; color: #027a48; border: 1px solid #abefc6; }
.badge.wait { background: #fff1f2; color: #b42318; border: 1px solid #fecdd3; }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: var(--space-1); margin-top: var(--space-3); flex-wrap: wrap; }
.pagination a {
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  border: 1px solid color-mix(in oklab, var(--field-text) 20%, transparent);
  text-decoration: none;
  color: var(--field-text);
  background: var(--field-bg);
}
.pagination a.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* =====================================================================
   Pages outils CVC / PB (calculateurs mono-page)
   Structure reprise de base-v0.css : en-tête simple (.title-row +
   .home-link), grilles de champs (.grid-3 / .row), panneau d'état/résultat
   (#calc / #result) et libellés de statut (.err / .ok) en span nu.
   ===================================================================== */
main {
  max-width: 920px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-3) calc(2.5rem + env(safe-area-inset-bottom));
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-block: 0 var(--space-3);
}
.title-row h1 { margin: 0; color: var(--text); }
.home-link {
  white-space: nowrap;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
}
.home-link:hover, .home-link:focus-visible { text-decoration: underline; }

.grid-3 {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(3, 1fr);
}
.row {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: 1fr 1fr;
}
.grid-3 label,
.row label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: var(--fs-0);
}

#calc, #result {
  margin-top: var(--space-2);
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: var(--fs-0);
  word-break: break-word;
  color: var(--text);
}
.err { color: var(--err); }
.ok  { color: var(--ok); }

@media (max-width: 900px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .grid-3, .row { grid-template-columns: 1fr; }
}

/* ---------- Points de rupture (table -> cartes en mobile) ---------- */
@media (max-width: 840px) {
  th, td { padding: var(--space-1); font-size: 13px; }
}
@media (max-width: 640px) {
  .table-wrap { overflow: visible; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { position: absolute; left: -9999px; top: -9999px; height: 0; width: 0; overflow: hidden; }
  table { border-radius: 0; background: transparent; }
  tbody tr {
    background: var(--field-bg);
    border: 1px solid color-mix(in oklab, var(--field-text) 15%, transparent);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-2);
  }
  td, th { border: none; border-bottom: 1px solid color-mix(in oklab, var(--field-text) 10%, transparent); }
  tbody tr td:last-child { border-bottom: none; }
  td {
    display: grid;
    grid-template-columns: 42% 58%;
    align-items: baseline;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-2);
  }
  td::before { content: attr(data-label); font-weight: 600; color: color-mix(in oklab, var(--field-text) 70%, transparent); }
  td.actions-cell { display: block; padding: var(--space-2); }
  td.actions-cell .actions { display: flex; gap: var(--space-1); flex-wrap: wrap; }
  th.sticky-col, td.sticky-col { position: static; }
  td.hide-xs { display: none; }
}
@media (max-width: 380px) {
  td { grid-template-columns: 48% 52%; }
}
