:root {
  --fond: #f4f6f8;
  --fond-carte: #ffffff;
  --texte: #1a2230;
  --texte-att: #5b6472;
  --bordure: #e1e5ea;
  --accent: #0f172a;
  --accent-clair: #2563eb;
  --ligne-alt: #f8fafc;
  --ok: #16a34a;
  --alerte: #dc2626;
  --info: #1d4ed8;
  --cadre: #64748b;
  color-scheme: light;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond: #0b1220;
    --fond-carte: #131c2e;
    --texte: #e6e9ef;
    --texte-att: #9aa4b2;
    --bordure: #263043;
    --accent: #38bdf8;
    --accent-clair: #38bdf8;
    --ligne-alt: #0f1929;
    --cadre: #8a97ab;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --fond: #0b1220;
  --fond-carte: #131c2e;
  --texte: #e6e9ef;
  --texte-att: #9aa4b2;
  --bordure: #263043;
  --accent: #38bdf8;
  --accent-clair: #38bdf8;
  --ligne-alt: #0f1929;
  --cadre: #8a97ab;
  color-scheme: dark;
}

* { box-sizing: border-box; }

#ecran-connexion {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--accent);
}

#ecran-connexion[hidden] {
  display: none;
}

.carte-connexion {
  width: 100%;
  max-width: 340px;
  background: var(--fond-carte);
  color: var(--texte);
  border-radius: 12px;
  padding: 28px 24px;
  text-align: center;
}

.logo-connexion {
  height: 32px;
  margin-bottom: 16px;
}

.carte-connexion h2 {
  margin: 0 0 8px 0;
}

.carte-connexion p {
  font-size: 13px;
  color: var(--texte-att);
  margin: 0 0 18px 0;
}

.carte-connexion input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--bordure);
  background: var(--fond);
  color: var(--texte);
  font-size: 14px;
  margin-bottom: 12px;
}

.carte-connexion button {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent-clair);
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.erreur-connexion {
  color: var(--alerte);
  font-size: 12.5px;
  margin: 10px 0 0 0 !important;
}

body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
}

header {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 10;
  background: var(--accent);
  color: white;
  padding: 12px 16px;
}

.entete-titre {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  height: 22px;
  width: auto;
  background: #ffffff;
  border-radius: 4px;
  padding: 3px 6px;
}

header h1 {
  margin: 0;
  font-size: 17px;
}

header .maj {
  font-size: 11.5px;
  opacity: 0.8;
}

nav.onglets {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 12px;
  background: var(--fond-carte);
  border-bottom: 1px solid var(--bordure);
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + 52px);
  z-index: 9;
  -webkit-overflow-scrolling: touch;
}

nav.onglets button {
  flex: none;
  border: 1px solid var(--bordure);
  background: var(--fond);
  color: var(--texte);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  white-space: nowrap;
  cursor: pointer;
}

nav.onglets button.actif {
  background: var(--accent-clair);
  border-color: var(--accent-clair);
  color: white;
  font-weight: 600;
}

main {
  padding: 12px;
  padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
}

.barre-outils {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.barre-outils input[type="search"] {
  flex: 1;
  min-width: 160px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--bordure);
  background: var(--fond-carte);
  color: var(--texte);
  font-size: 13px;
}

.info-source {
  font-size: 11.5px;
  color: var(--texte-att);
}

.info-source-haut {
  margin: 0 0 10px 0;
  font-weight: 600;
  color: var(--texte);
}

.carte {
  background: var(--fond-carte);
  border: 1px solid var(--bordure);
  border-radius: 10px;
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 480px;
}

th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--bordure);
  white-space: nowrap;
}

th {
  background: var(--ligne-alt);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--texte-att);
  position: sticky;
  top: 0;
}

tbody tr:nth-child(even) {
  background: var(--ligne-alt);
}

.etat {
  padding: 24px;
  text-align: center;
  color: var(--texte-att);
}

.etat.erreur {
  color: var(--alerte);
}

/* Mise en évidence vérifiée dans l'original Excel (StatcamTemp) :
   - colonne "A Charger" toujours en bleu gras (constante sur toutes les lignes)
   - lignes dont la date n'est pas celle du jour : grisées et barrées
     (sauf la colonne "A Charger", qui reste bleue même sur ces lignes) */
td.col-plaque {
  font-weight: 700;
  letter-spacing: 0.02em;
}

td.col-a-charger {
  color: var(--info);
  font-weight: 700;
}

tr.ligne-passee td {
  color: var(--texte-att);
  text-decoration: line-through;
}

tr.ligne-passee td.col-a-charger {
  color: var(--info);
  text-decoration: none;
}

td.col-num-cmd {
  font-weight: 700;
}

/* Terval Anthracites empile parfois plusieurs éléments dans une même cellule
   (produits + pourcentages alignés en face) : on respecte les retours à la ligne
   pour reproduire la hauteur de ligne de l'original. Ciblé sur cette seule feuille
   pour ne pas changer le rendu (nowrap + ellipsis) des autres feuilles brutes. */
table.table-multiligne td {
  white-space: pre-line;
  vertical-align: middle;
}

tr.ligne-total td {
  font-weight: 700;
  background: var(--ligne-alt);
  border-top: 2px solid var(--texte);
}

.pastille {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  background: var(--ok);
}
