/* Water & Carbon Footprint Scanner — bulletin d'analyse de laboratoire.
   Discipline chromatique (SPEC §7.2) : deux accents, chacun marié à sa
   métrique, jamais utilisés ailleurs. Un seul thème : le papier. */

/* ---------------------------------------------------------------- fonts */

@font-face {
  font-family: "Space Grotesk";
  src: url("fonts/space-grotesk-regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("fonts/space-grotesk-medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

/* --------------------------------------------------------------- tokens */

:root {
  /* Le socle pointe vers la palette commune (theme.css) : l'app a
     rejoint le crème/brun du site. Eau et carbone gardent leurs
     couleurs propres — elles disent quelque chose — avec une version
     par mode, juste en dessous. */
  --paper: var(--g-fond);      /* fond de page */
  --ink: var(--g-encre);       /* tout le texte courant */
  --ink-muted: var(--g-encre-douce); /* texte secondaire, sources, méthodo */
  --water: #0E7DA7;      /* RÉSERVÉ : chiffre eau, son ±, le remplissage */
  --carbon: #4A5160;     /* RÉSERVÉ : chiffre carbone et son ± */
  --rule: var(--g-filet);      /* filets 1px, bordures de tableau */
  --card: var(--g-surface);    /* fond des lignes et dossiers en boîte */
  --flag: var(--g-alerte);     /* RÉSERVÉ : anomalies, unmatched, erreurs */
}

html[data-theme="dark"] {
  --water: #5BB8DC;
  --carbon: #9AA5B4;
}

/* ---------------------------------------------------------------- socle */

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

::selection { background: color-mix(in srgb, var(--water) 15%, transparent); }

:focus { outline: none; }
:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

input, select {
  font: inherit;
  color: var(--ink);
  background: transparent;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ------------------------------------------------------------- feuille */

/* Le bulletin occupe tout l'écran : pas de colonne centrée. */

.sheet {
  margin: 0 auto;
  padding: 24px 24px 56px;
}

/* ------------------------------------------------------------- en-tête */

.masthead { margin-bottom: 20px; }

.masthead-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 35px;
}

/* La marque du site — même dessin que sur la page d'accueil de
   geheim.land : police du portail, 30 px, encre pleine, posée en haut
   à gauche de l'écran. Elle ramène à l'accueil. */
.brand {
  color: var(--ink);
  text-decoration: none;
  font-family: "OCR A Std Regular", "OCR A", ui-monospace, monospace;
  font-size: 30px;
  font-weight: 400;
  letter-spacing: 1px;
  /* Interligne du portail, pas celui du corps de texte (1,6) : sinon la
     demi-approche pousse la marque 6 px plus bas que sur l'accueil. */
  line-height: normal;
}
.brand:hover { color: var(--ink-muted); }

.title {
  font-size: 20px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

/* ------------------------------------------------------------- sections */

/* Une seule page : les trois sections du bulletin sont toujours
   visibles et se remplissent sur place (pas de changement d'écran). */

.section { padding: 40px 0 48px; }

[hidden] { display: none !important; }

/* ------------------------------------------------------------- accueil */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 190px;
  border: 1px solid var(--rule);
  cursor: pointer;
  transition: border-color 160ms ease, min-height 240ms ease;
}
.dropzone:hover, .dropzone.is-dragover { border-color: var(--ink); }

.dropzone-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.dropzone-cross {
  font-size: 28px;
  font-weight: 400;
  line-height: 1;
  color: var(--ink-muted);
}

.dropzone-label {
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

/* Une fois des données présentes, la zone photo se fait discrète. */
body.has-data .dropzone {
  min-height: 72px;
  flex-direction: row;
  gap: 14px;
}
body.has-data .dropzone-cross { font-size: 20px; }
body.has-data .dropzone-text { align-items: flex-start; gap: 2px; }

/* Tant qu'une photo est en place, l'appel à en importer une disparaît :
   on retire la photo pour en proposer une autre. */
body.has-photo .dropzone { display: none; }

.scan-error {
  margin-top: 14px;
  font-size: 13px;
  color: var(--flag);
}

/* La photo analysée reste visible pour vérifier la liste. */
.photo-wrap {
  position: relative;
  display: inline-block;
  margin-top: 16px;
  max-width: 100%;
}

.photo-preview {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border: 1px solid var(--rule);
}

.photo-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  line-height: 1;
  font-size: 16px;
  background: var(--paper);
  border: 1px solid var(--rule);
  color: var(--ink);
}
.photo-remove:hover { color: var(--flag); border-color: var(--flag); }

/* --------------------------------------------------- les deux totaux */

.totals {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.total {
  position: relative;
  text-align: center;
  padding: 34px 12px 30px;
  overflow: hidden;
}
.total--carbon { border-left: 1px solid var(--rule); }

.total-num {
  position: relative;
  font-size: clamp(56px, 11vw, 96px);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.total--water .total-num  { color: var(--water); }
.total--carbon .total-num { color: var(--carbon); }

.total-pm {
  position: relative;
  font-size: 15px;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  min-height: 1.2em;
}
.total--water .total-pm  { color: var(--water); opacity: 0.75; }
.total--carbon .total-pm { color: var(--carbon); opacity: 0.75; }

.total-unit {
  position: relative;
  margin-top: 10px;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

/* L'unique animation : un remplissage bleu qui monte (SPEC §7.5). */

.fill {
  position: absolute;
  inset: 0;
  background: var(--water);
  opacity: 0;
  transform: scaleY(0);
  transform-origin: bottom;
  pointer-events: none;
}

.totals--pending .fill {
  animation: rise 1.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes rise {
  0%   { transform: scaleY(0); opacity: 0.08; }
  72%  { transform: scaleY(1); opacity: 0.08; }
  100% { transform: scaleY(1); opacity: 0; }
}

.totals--pending .total-num,
.totals--empty .total-num { color: var(--rule); }

/* Ligne d'attente de la composition, avant tout scan. */
.placeholder-row td {
  color: var(--ink-muted);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-align: center;
  padding: 22px 12px;
}

.analyzing-label {
  margin-top: 34px;
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-muted);
  animation: breathe 1.8s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
  .totals--pending .fill { animation: pulse 1.8s ease-in-out infinite; transform: scaleY(1); }
  .analyzing-label { animation: none; }
  @keyframes pulse {
    0%, 100% { opacity: 0.03; }
    50%      { opacity: 0.1; }
  }
}

/* ---------------------------------------------------------- correction */

.section-title {
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 26px;
}

.net-weight-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

.net-weight-row label {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

#net-weight {
  width: 90px;
  border: none;
  border-bottom: 1px solid var(--rule);
  padding: 2px 4px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
#net-weight:focus { border-bottom-color: var(--ink); }

.unit-inline { color: var(--ink-muted); font-size: 13px; }

/* Chaque ligne du tableau est une boîte : fond carte, filet continu,
   un souffle d'écart entre deux lignes — aucun trait de séparation.
   Largeurs fixes : le tableau ne déborde jamais de sa colonne, quelle
   que soit la longueur d'un libellé. */

/* Le tableau tient toujours dans sa colonne : jamais de défilement, les
   largeurs sont posées sur la ligne d'en-tête (c'est elle que suit
   `table-layout: fixed`). */

.ingredients {
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0 8px;
}

.ingredients th {
  text-align: left;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: 6px 12px 0;
}
/* Les en-têtes chiffrés se calent sur leur colonne, à droite comme
   elle. Le « % » gagne les 4 px du rembourrage propre à son champ. */
.ingredients th.col-pct { text-align: right; padding-right: 16px; }
.ingredients th.col-num { text-align: right; }

.ingredients .col-label { width: 24%; }
.ingredients .col-key { width: 22%; }

.ingredients td {
  padding: 10px 12px;
  background: var(--card);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  vertical-align: baseline;
  overflow-wrap: anywhere;
}
.ingredients td:first-child { border-left: 1px solid var(--rule); }
.ingredients td:last-child { border-right: 1px solid var(--rule); }

.ingredients .cell-label .low-confidence { color: var(--ink-muted); font-size: 12px; display: block; }

.label-input {
  width: 100%;
  border: none;
  border-bottom: 1px solid transparent;
  padding: 2px 0;
}
.label-input:hover, .label-input:focus { border-bottom-color: var(--ink); }
.label-input::placeholder { color: var(--ink-muted); }

.ingredients select {
  width: 100%;
  border: none;
  border-bottom: 1px solid transparent;
  padding: 2px 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: none;
}
.ingredients select:hover, .ingredients select:focus { border-bottom-color: var(--ink); }

/* Le signal unmatched est typographique, pas un badge (SPEC §7.4) :
   la boîte de la ligne passe en tireté couleur anomalie. */
tr.is-unmatched select { color: var(--flag); }
tr.is-unmatched td {
  border-top-style: dashed;
  border-bottom-style: dashed;
  border-color: var(--flag);
}
tr.is-unmatched td:first-child { border-left-style: dashed; }
tr.is-unmatched td:last-child { border-right-style: dashed; }

.col-pct { width: 76px; }
.ingredients input.pct {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--rule);
  text-align: right;
  padding: 2px 4px;
  font-variant-numeric: tabular-nums;
}

/* Ce que chaque ingrédient coûte vraiment, dans la couleur de sa
   métrique : le bleu de l'eau, l'ardoise du carbone. Les cases restent
   vides tant que la liste n'a pas été (re)calculée. */
.col-num { width: 14%; text-align: right; }
.ingredients td.cell-water,
.ingredients td.cell-co2 {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ingredients td.cell-water { color: var(--water); }
.ingredients td.cell-co2 { color: var(--carbon); }
.ingredients input.pct::placeholder { color: var(--ink-muted); font-size: 12px; letter-spacing: 0.04em; }
.ingredients input.pct:focus { border-bottom-color: var(--ink); }

/* Le « × » respire : sa colonne est plus large que le signe, il ne
   colle plus au bord de la ligne. */
.col-x { width: 46px; }
.ingredients td.col-x { text-align: center; padding: 10px 6px; }
.row-delete {
  color: var(--ink-muted);
  font-size: 15px;
  line-height: 1;
  padding: 2px 6px;
}
.row-delete:hover { color: var(--flag); }

.ghost-btn {
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
}
.ghost-btn:hover { color: var(--ink); }

.warnings {
  list-style: none;
  margin-top: 20px;
}
.warnings li {
  font-size: 12.5px;
  color: var(--flag);
  padding-left: 14px;
  position: relative;
}
.warnings li::before { content: "—"; position: absolute; left: 0; }
.warnings:empty { display: none; }

/* --------------------------------------------------------------- actions */

.actions {
  margin-top: 40px;
  display: flex;
  align-items: baseline;
  gap: 28px;
}

.primary-btn {
  border: 1px solid var(--ink);
  padding: 12px 34px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  transition: background 160ms ease, color 160ms ease;
}
.primary-btn:hover { background: var(--ink); color: var(--paper); }
.primary-btn[disabled] { opacity: 0.4; pointer-events: none; }

.link-btn {
  font-size: 12.5px;
  color: var(--ink-muted);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1px;
}
.link-btn:hover { color: var(--ink); border-bottom-color: var(--ink); }

/* -------------------------------------------------------------- résultat */

.result-warning {
  margin-top: 18px;
  text-align: center;
  font-size: 12.5px;
  color: var(--flag);
}

/* ------------------------------------------------------------------ faq */

/* Deux dossiers dépliables, fermés par défaut : la méthode résumée et le
   tableau complet des facteurs. Chaque dossier est une boîte — fond
   carte, filet — plutôt qu'une pile de traits de séparation. */

.faq details {
  background: var(--card);
  border: 1px solid var(--rule);
}
.faq details + details { margin-top: 12px; }

.faq summary {
  list-style: none;
  cursor: pointer;
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary:hover { color: var(--ink); }
.faq summary::after { content: "+"; font-size: 15px; line-height: 1; }
.faq details[open] summary::after { content: "−"; }

.faq-body {
  padding: 2px 18px 24px;
  font-size: 13.5px;
}
.faq-body p + p { margin-top: 10px; }

/* Le tableau des facteurs — mêmes lignes en boîte que la composition ;
   dans le dossier crème, elles reprennent le fond papier. */

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

.factors {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 6px;
  font-variant-numeric: tabular-nums;
}

.factors th {
  text-align: left;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: 4px 12px 0;
}

.factors td {
  padding: 8px 12px;
  background: var(--paper);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  font-size: 13px;
}
.factors td:first-child { border-left: 1px solid var(--rule); }
.factors td:last-child { border-right: 1px solid var(--rule); }

.factors .num { text-align: right; white-space: nowrap; }

/* L'intitulé de catégorie reste un simple libellé, hors boîte. */
.factors .factors-cat td {
  background: transparent;
  border: none;
  padding: 16px 12px 0;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

/* -------------------------------------------------------------- colophon */

.colophon { margin-top: 32px; }

.sources-intro, .sources-list {
  font-size: 12.5px;
  color: var(--ink-muted);
}

.sources-list { list-style: none; margin-top: 2px; }
.sources-list li { padding-left: 14px; position: relative; }
.sources-list li::before { content: "—"; position: absolute; left: 0; }

/* -------------------------------------------------------------- mobile */

@media (max-width: 560px) {
  .sheet { padding: 24px 18px 44px; }
  .brand { font-size: 24px; }

  /* En colonne étroite, la phrase passe sur deux lignes : la mise en
     ligne héritée de `has-data` la collerait à gauche. On garde le
     signe au-dessus du texte, le tout centré. (Sur ordinateur, rien
     ne change.) */
  .dropzone { padding: 16px; }
  body.has-data .dropzone { flex-direction: column; gap: 8px; }
  body.has-data .dropzone-text { align-items: center; }
  .dropzone-label { text-align: center; }
  .section { padding: 30px 0 36px; }
  .totals { grid-template-columns: 1fr; }
  .total--carbon {
    border-left: none;
    border-top: 1px solid var(--rule);
  }
  .masthead-row { margin-bottom: 29px; }
  .actions { flex-wrap: wrap; gap: 18px; }

  /* Six colonnes dans une main : tout se resserre, mais rien ne défile
     et rien ne dépasse. */
  .ingredients { font-size: 11px; }
  .ingredients th { font-size: 9.5px; letter-spacing: 0.06em; padding: 6px 6px 0; }
  .ingredients th.col-pct { padding-right: 10px; }
  .ingredients td { padding: 8px 6px; }
  .ingredients .col-label { width: 22%; }
  .ingredients .col-key { width: 20%; }
  .col-pct { width: 52px; }
  .col-num { width: 16%; }
  .col-x { width: 30px; }
  .ingredients td.col-x { padding: 8px 2px; }
}

/* ------------------------------------------------- ordinateur : paysage */

/* Sur grand écran, le bulletin s'étale en deux colonnes sans séparation
   explicite : photo puis composition à gauche, résultats à droite.
   Mobile inchangé. */

@media (min-width: 1000px) {
  .sheet {
    padding: 24px 24px 40px;
    display: grid;
    grid-template-columns: 7fr minmax(360px, 5fr);
    grid-template-areas:
      "head head"
      "sample results"
      "list results"
      "faq faq"
      "foot foot";
    column-gap: 72px;
    align-content: start;
  }
  /* Dès qu'il y a des ingrédients, la colonne de gauche prend de la
     place sur celle des résultats : le tableau a six colonnes à loger. */
  body.has-data .sheet { grid-template-columns: 8fr minmax(320px, 4fr); }

  .masthead { grid-area: head; margin-bottom: 0; }
  .masthead-row { margin-bottom: 25px; }
  #section-sample { grid-area: sample; }
  #section-list { grid-area: list; }
  #section-results { grid-area: results; }
  #section-faq { grid-area: faq; }
  .colophon { grid-area: foot; margin-top: 8px; }

  .section { padding: 22px 0 26px; }

  .dropzone { min-height: 130px; }
  .photo-preview { max-height: 240px; }

  /* Les deux totaux s'empilent dans la colonne gauche, en plus petit. */
  #section-results .totals { grid-template-columns: 1fr; }
  #section-results .total--carbon {
    border-left: none;
    border-top: 1px solid var(--rule);
  }
  #section-results .total { padding: 20px 12px 16px; }
  #section-results .total-num { font-size: clamp(44px, 4.5vw, 68px); }
  .result-warning { text-align: left; }
  .analyzing-label { margin-top: 20px; }
}

/* ------------------------------------------------------------ impression */

@media print {
  body { background: #fff; }
  .sheet { max-width: none; padding: 0; }
  .dropzone, .actions, .ghost-btn, .row-delete, .fill,
  .analyzing-label, .scan-error { display: none !important; }
  .section { padding: 24px 0; }
  .total-num { font-size: 64px; }
}
