:root {
  --bg: #0f1115;
  --card: #161a21;
  --line: #262c36;
  --text: #e6e9ef;
  --muted: #98a2b3;
  --accent: #d97757;
  /* Fond de bouton et anneau de focus : 5,03:1 avec du texte blanc.
     L'accent clair (#d97757) ne donne que 3,12:1, sous le seuil AA de 4,5. */
  --accent-strong: #b8501f;
  --on-accent: #ffffff;
  --accent-soft: rgba(217, 119, 87, .14);
  --ok: #4ea87b;
  --err: #d85050;
  /* Derives des couleurs semantiques : une seule source de verite */
  --ok-soft: color-mix(in srgb, var(--ok) 16%, transparent);
  --err-soft: color-mix(in srgb, var(--err) 16%, transparent);
  /* Series des courbes : l allure prend l accent, les autres leur teinte */
  --series-hr: #c05c5c;
  --series-dist: #4e87a8;
  --series-weight: #4ea87b;
  --radius: 12px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f7f5; --card: #ffffff; --line: #e5e2dc; --text: #1f2328;
    --muted: #6b7280;
    /* Sur fond clair, l'accent sombre devient aussi la couleur de texte :
       #d97757 sur blanc tombait a 3,12:1. */
    --accent: #b8501f;
    --accent-soft: rgba(184, 80, 31, .10);
    --series-hr: #a83e3e;
    --series-dist: #2f6c8f;
    --series-weight: #2f7d55;
  }
}
* { box-sizing: border-box; }
html { color-scheme: dark light; }
body {
  margin: 0;
  padding: 0 max(1rem, env(safe-area-inset-right)) max(4rem, env(safe-area-inset-bottom))
           max(1rem, env(safe-area-inset-left));
  background: var(--bg); color: var(--text);
  caret-color: var(--accent);
  accent-color: var(--accent-strong);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
header { max-width: 940px; margin: 0 auto; padding: 2.2rem 0 1.2rem; }
h1 { margin: 0; font-size: 1.6rem; letter-spacing: -.02em; }
.sub { margin: .3rem 0 0; color: var(--muted); }
::selection { background: var(--accent-soft); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
main { max-width: 940px; margin: 0 auto; display: flex; flex-direction: column; gap: 1rem; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.1rem 1.2rem;
}
.card h2 { margin: 0 0 .9rem; font-size: 1rem; letter-spacing: .01em; }
.muted { color: var(--muted); }

.drop {
  position: relative; border: 1.5px dashed var(--line); border-radius: var(--radius);
  padding: 1.6rem 1rem; text-align: center; color: var(--muted); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop.over, .drop:focus-within {
  border-color: var(--accent); background: var(--accent-soft); color: var(--text);
}
@media (hover: hover) {
  .drop:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
}
.drop:focus-within { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
/* Un nom de fichier tres long ne doit pas elargir la zone */
#drop-label { display: inline-block; max-width: 100%; overflow-wrap: anywhere; cursor: pointer; }
.hint { display: block; margin-top: .35rem; font-size: .78rem; color: var(--muted); }
#detail-title:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 4px; }

.row { display: flex; gap: .8rem; flex-wrap: wrap; margin-top: .9rem; align-items: flex-end; }
.row.bottom { justify-content: space-between; align-items: center; }
/* Rangee de saisie : deux champs courts de meme largeur, puis la note qui
   prend le reste. Alignement par le haut, pour qu un texte d aide sous un
   champ ne decale pas les autres. */
.fields {
  display: grid;
  grid-template-columns: 9rem 9rem minmax(0, 1fr);
  align-items: start;
  gap: .8rem;
  margin-top: .9rem;
}
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field label { font-size: .82rem; color: var(--muted); }
.field .hint { margin-top: .1rem; }
label.check { display: flex; align-items: center; gap: .45rem; color: var(--text); font-size: .9rem; }
input[type=number], input[type=text], textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: .5rem .6rem; font: inherit; font-size: 16px; width: 100%;
}
input[type=number] { width: 100%; }
textarea { width: 100%; margin-top: .6rem; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .82rem; }
@media (max-width: 640px) { textarea { font-size: 16px; } }
button {
  background: var(--accent-strong); color: var(--on-accent); border: 0; border-radius: 8px;
  padding: .55rem 1.1rem; font: inherit; font-weight: 500; cursor: pointer;
}
@media (hover: hover) {
  button:hover { filter: brightness(1.07); }
}
button:active { filter: brightness(.94); }
button.row-open:active { filter: none; color: var(--accent); }
button:disabled { opacity: .55; cursor: default; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
/* Ouverture d'une sortie au clavier : un vrai bouton, sans apparence de bouton */
button.row-open {
  background: none; border: 0; padding: 0; margin: 0; font: inherit;
  color: inherit; text-align: left; cursor: pointer; border-radius: 2px;
}
button.row-open:hover { filter: none; }

table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: .78rem;
  text-transform: uppercase; letter-spacing: .04em; padding: 0 .5rem .5rem; }
td { padding: .55rem .5rem; border-top: 1px solid var(--line); }
tbody tr { cursor: pointer; }
@media (hover: hover) {
  tbody tr:hover { background: var(--accent-soft); }
}
tbody tr.active { background: var(--accent-soft); }
.num { font-variant-numeric: tabular-nums; }
.footnote { margin: .5rem 0 0; font-size: .78rem; color: var(--muted); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); vertical-align: middle; }

.status { margin-top: .8rem; padding: .6rem .8rem; border-radius: 8px; font-size: .88rem; }
.status.info { background: var(--accent-soft); }
.status.err { background: var(--err-soft); }
.status.ok { background: var(--ok-soft); }
.status .retry { margin-left: .6rem; padding: .25rem .7rem; font-size: .82rem; }
#app-status:empty { display: none; }
#app-status .status { margin: 0 0 1rem; }

.stats { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 1rem; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: .5rem .75rem; min-width: 104px; }
.stat b { display: block; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.analysis { background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: .3rem 1.1rem 1.1rem; margin-top: 1rem; }
.analysis h3 { font-size: .82rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--accent); margin: 1.1rem 0 .3rem; }
.analysis p, .analysis li { margin: .4rem 0; max-width: 68ch; }
.analysis ul { margin: .4rem 0; padding-left: 1.1rem; }

.chart { margin-bottom: 1.2rem; }
.chart h3 { font-size: .8rem; font-weight: 500; color: var(--muted); margin: 0 0 .3rem;
  text-transform: uppercase; letter-spacing: .04em; }
svg { width: 100%; height: auto; display: block; overflow: visible; }
.axis { fill: var(--muted); } /* taille posee par lineChart, selon la largeur reelle */
.gridline { stroke: var(--line); stroke-width: 1; }
.detail-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }
#detail table { display: block; overflow-x: auto; }

/* Curseur de lecture sur les courbes */
svg[data-points] { cursor: crosshair; }
.hit { pointer-events: all; }
.cursor-line { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.cursor-dot { stroke: var(--card); stroke-width: 2; }
.cursor-box { fill: var(--text); opacity: .93; }
.cursor-text { fill: var(--card); font-size: 11px; font-weight: 500;
  font-variant-numeric: tabular-nums; pointer-events: none; }

/* ------------------------------------------------------------------
   Entree tactile : le seuil de 44 px vaut pour le doigt, pas la souris.
   On cible le type de pointeur plutot que la largeur d ecran, parce
   qu un portable a ecran tactile a besoin des memes cibles.
   ------------------------------------------------------------------ */
@media (pointer: coarse) {
  button { min-height: 44px; padding: .6rem 1.15rem; }
  button.row-open { min-height: 44px; width: 100%; }
  label.check { min-height: 44px; gap: .7rem; }
  #analyze { width: 1.25rem; height: 1.25rem; }
  .drop { padding: 2rem 1rem; }
  input[type=number], input[type=text] { min-height: 44px; }
  #history td { padding-top: .7rem; padding-bottom: .7rem; }
}

/* ------------------------------------------------------------------
   Telephone : huit colonnes ne tiennent pas dans 320 px. Chaque sortie
   devient une fiche — date en tete tactile, distance et allure mises en
   avant, le reste en paires etiquetees. Meme DOM, meme contenu.
   ------------------------------------------------------------------ */
@media (max-width: 640px) {
  #history thead {
    position: absolute; width: 1px; height: 1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap;
    margin: -1px; padding: 0; border: 0;
  }
  #history thead th { padding: 0; font-size: 0; }
  #history table, #history tbody, #history tr { display: block; width: 100%; }
  #history tr { border-top: 1px solid var(--line); padding: .55rem 0 .75rem; }
  #history tr:first-child { border-top: 0; }

  #history td {
    display: inline-flex; align-items: baseline; gap: .3rem;
    border: 0; padding: 0; margin: 0 .85rem .15rem 0;
  }
  #history td::before {
    content: attr(data-label);
    font-size: .68rem; text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted);
  }
  #history td.cell-date { display: block; margin: 0 0 .35rem; }
  #history td.cell-date::before { content: none; }
  #history .row-open { display: block; font-size: 1rem; font-weight: 500; padding: .2rem 0; }
  /* Les deux chiffres qu on cherche en premier sur une sortie */
  #history td.cell-key { font-size: 1rem; }
  #history td.cell-flag:empty { display: none; }

  .fields { grid-template-columns: 1fr 1fr; }
  .field-note { grid-column: 1 / -1; }
  .stat { flex: 1 1 calc(50% - .3rem); min-width: 0; }
  .row.bottom { gap: .6rem; }
  main { gap: .75rem; }
  .card { padding: 1rem .9rem; }
}
