/* 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 {
  --paper: #FAF7F1;      /* fond de page (papier chaud) */
  --ink: #14213D;        /* tout le texte courant (bleu nuit) */
  --ink-muted: #5A6478;  /* texte secondaire, sources, méthodo */
  --water: #0E7DA7;      /* RÉSERVÉ : chiffre eau, son ±, le remplissage */
  --carbon: #4A5160;     /* RÉSERVÉ : chiffre carbone et son ± */
  --rule: #DDD6C9;       /* filets 1px, bordures de tableau */
  --flag: #A34730;       /* RÉSERVÉ : anomalies, unmatched, erreurs */
}

/* ---------------------------------------------------------------- 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: rgba(14, 125, 167, 0.15); }

: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;
}

/* ------------------------------------------------------------- colonne */

.sheet {
  max-width: 680px;
  margin: 0 auto;
  padding: 48px 24px 56px;
}

.rule {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 0;
}

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

.masthead { margin-bottom: 20px; }

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

.brand {
  color: var(--ink-muted);
  text-decoration: none;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.brand:hover { color: var(--ink); }

.scan-meta {
  color: var(--ink-muted);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

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

/* --------------------------------------------------------------- états */

.panel { display: none; padding: 56px 0; }

body[data-state="idle"]       .panel[data-panel="idle"],
body[data-state="analyzing"]  .panel[data-panel="analyzing"],
body[data-state="correcting"] .panel[data-panel="correcting"],
body[data-state="result"]     .panel[data-panel="result"],
body[data-state="error"]      .panel[data-panel="error"] { display: block; }

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

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

.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;
}

.dropzone-hint {
  font-size: 12.5px;
  color: var(--ink-muted);
}

/* --------------------------------------------------- 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 { color: var(--rule); }

.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: 11px;
  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;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 4px;
}

.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; }

.ingredients {
  width: 100%;
  border-collapse: collapse;
}

.ingredients th {
  text-align: left;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: 14px 8px 8px 0;
  border-bottom: 1px solid var(--rule);
}
.ingredients th.col-pct { text-align: right; }

.ingredients td {
  padding: 10px 8px 10px 0;
  border-bottom: 1px solid var(--rule);
  vertical-align: baseline;
}

.ingredients .cell-label { width: 40%; }
.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). */
tr.is-unmatched select { color: var(--flag); }
tr.is-unmatched td { border-bottom-style: dashed; border-bottom-color: var(--flag); }

.col-pct { width: 84px; }
.ingredients input.pct {
  width: 64px;
  border: none;
  border-bottom: 1px solid var(--rule);
  text-align: right;
  padding: 2px 4px;
  font-variant-numeric: tabular-nums;
}
.ingredients input.pct::placeholder { color: var(--ink-muted); font-size: 12px; letter-spacing: 0.04em; }
.ingredients input.pct:focus { border-bottom-color: var(--ink); }

.col-x { width: 28px; }
.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 */

.equivalents {
  margin-top: 36px;
  text-align: center;
  color: var(--ink);
  font-size: 15px;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

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

.panel[data-panel="result"] .actions { justify-content: center; }

/* --------------------------------------------------------------- erreur */

.error-msg {
  text-align: center;
  color: var(--flag);
  font-size: 15px;
  max-width: 420px;
  margin: 0 auto;
}

.panel[data-panel="error"] .actions { justify-content: center; }

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

.colophon { margin-top: 24px; }

.colophon .rule { margin-bottom: 22px; }

.methodo, .sources {
  font-size: 12.5px;
  color: var(--ink-muted);
  max-width: 560px;
}
.sources { margin-top: 10px; }

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

@media (max-width: 560px) {
  .sheet { padding: 32px 18px 44px; }
  .panel { padding: 40px 0; }
  .totals { grid-template-columns: 1fr; }
  .total--carbon {
    border-left: none;
    border-top: 1px solid var(--rule);
  }
  .masthead-row { margin-bottom: 22px; }
  .actions { flex-wrap: wrap; gap: 18px; }
  .ingredients .cell-label { width: auto; }
}

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

@media print {
  body { background: #fff; }
  .sheet { max-width: none; padding: 0; }
  .dropzone, .actions, .ghost-btn, .row-delete, .fill, .analyzing-label { display: none !important; }
  .panel { padding: 24px 0; }
  /* le bulletin imprimé montre la liste ET le résultat */
  body[data-state="result"] .panel[data-panel="result"],
  body[data-state="result"] .panel[data-panel="correcting"] { display: block; }
  .total-num { font-size: 64px; }
}
