/* 8Body — thème sombre, accents laiton. Pensé mobile d'abord :
   l'usage réel, c'est le téléphone en cuisine ou dans les rayons. */

:root {
  --bg: #0e1116;
  --bg-raise: #161b23;
  --bg-sunk: #0a0d12;
  --line: #262d38;
  --line-soft: #1c222b;
  --txt: #e6e9ef;
  --txt-dim: #9aa4b2;
  --txt-faint: #616b7a;
  --gold: #d9a441;
  --gold-dim: #8a6a2c;
  --green: #4caf7d;
  --red: #e0645c;
  --blue: #5b93d3;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--txt);
  font: 15px/1.5 var(--sans);
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; }

/* ------------------------------------------------------------------ shell */

header.app {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.bar {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--gold);
  font-size: 15px;
}

nav.tabs { display: flex; gap: 2px; margin-left: auto; }

nav.tabs button {
  background: none;
  border: 1px solid transparent;
  color: var(--txt-dim);
  padding: 6px 13px;
  border-radius: 7px;
  font-size: 13.5px;
}
nav.tabs button:hover { color: var(--txt); background: var(--bg-raise); }
nav.tabs button[aria-selected="true"] {
  color: var(--gold);
  background: var(--bg-raise);
  border-color: var(--line);
}

#sync {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--txt-faint);
  white-space: nowrap;
}
#sync.saving { color: var(--gold); }
#sync.error { color: var(--red); }

main { max-width: 1180px; margin: 0 auto; padding: 18px 16px 80px; }
section[hidden] { display: none; }

/* ------------------------------------------------------------- day header */

.daybar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.daybar select, .daybar input[type="date"] {
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  color: var(--txt);
  padding: 7px 9px;
  border-radius: 7px;
}

.note {
  flex-basis: 100%;
  font-size: 12.5px;
  color: var(--txt-dim);
  border-left: 2px solid var(--gold-dim);
  padding-left: 10px;
  margin: 2px 0 0;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--txt-dim);
  user-select: none;
  cursor: pointer;
}
.toggle input { accent-color: var(--gold); width: 15px; height: 15px; }

button.primary {
  background: linear-gradient(180deg, #e6bb5e 0%, var(--gold) 45%, #b8862f 100%);
  color: #17120a;
  border: none;
  font-weight: 650;
  padding: 9px 18px;
  border-radius: 7px;
  letter-spacing: 0.02em;
}
button.primary:hover { filter: brightness(1.1); }
button.primary:active { transform: translateY(1px); }
button.primary:disabled { opacity: 0.5; cursor: default; transform: none; }

button.ghost {
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  color: var(--txt-dim);
  padding: 7px 13px;
  border-radius: 7px;
  font-size: 13px;
}
button.ghost:hover { color: var(--txt); border-color: var(--gold-dim); }

/* ----------------------------------------------------------- meal cards */

.meals { display: grid; gap: 12px; }

.meal {
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.meal > header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
}
/* Sans flex-shrink: 0, « Repas 1 » se coupe en deux sur un écran de 375 px. */
.meal h3, .meal .time, .meal .target { flex-shrink: 0; white-space: nowrap; }
.meal h3 { font-size: 15px; }
.meal .time {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--gold);
  background: color-mix(in srgb, var(--gold) 12%, transparent);
  padding: 2px 7px;
  border-radius: 4px;
}
.meal .target { font-family: var(--mono); font-size: 12px; color: var(--txt-faint); }
.meal > header .spacer { margin-left: auto; }

/* ---------------------------------------------------------------- reels */

.reels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 1px;
  background: var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
}

.reel {
  background: var(--bg-raise);
  padding: 11px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.reel-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--txt-faint);
}

.reel-window {
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 8px;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
/* Rainure façon machine à sous : la fenêtre semble creusée dans le meuble. */
.reel-window::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.45) 0%, transparent 26%, transparent 74%, rgba(0, 0, 0, 0.45) 100%);
}

.reel-food {
  font-size: 13.5px;
  font-weight: 550;
  line-height: 1.25;
  word-break: break-word;
}
.reel-portion {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--gold);
  margin-top: 3px;
}
.reel-window.spinning .reel-food { filter: blur(0.6px); opacity: 0.8; }
.reel-window.spinning .reel-portion { visibility: hidden; }

.reel.held .reel-window { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold-dim) inset; }
.reel.empty .reel-food { color: var(--txt-faint); font-style: italic; font-weight: 400; }

.hold {
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  color: var(--txt-faint);
  border-radius: 5px;
  padding: 4px 0;
  font-size: 10px;
  font-family: var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.hold:hover { color: var(--txt-dim); border-color: var(--gold-dim); }
.reel.held .hold { background: var(--gold); border-color: var(--gold); color: #17120a; font-weight: 700; }

/* ---------------------------------------------------------------- stats */

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  padding: 0;
}
.stat {
  flex: 1 1 84px;
  padding: 9px 12px;
  border-right: 1px solid var(--line-soft);
  min-width: 0;
}
.stat:last-child { border-right: none; }
.stat .k {
  display: block;
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--txt-faint);
  margin-bottom: 2px;
}
.stat .v { font-family: var(--mono); font-size: 14.5px; font-weight: 600; }
.stat .v small { font-size: 10.5px; color: var(--txt-faint); font-weight: 400; }
.v.good { color: var(--green); }
.v.warn { color: var(--gold); }
.v.bad { color: var(--red); }

.gap {
  border-top: 1px solid var(--line-soft);
  padding: 10px 14px;
  font-size: 12.5px;
  background: var(--bg-sunk);
}
.gap-title { color: var(--txt-dim); margin-bottom: 6px; }
.boosters { display: flex; flex-wrap: wrap; gap: 6px; }
.booster {
  background: var(--bg-raise);
  border: 1px solid var(--line);
  color: var(--txt);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
}
.booster:hover { border-color: var(--gold); }
.booster b { color: var(--gold); font-family: var(--mono); font-weight: 600; }

/* ------------------------------------------------------------ day total */

.daytotal {
  margin-top: 12px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.daytotal > header {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 10px;
}
.daytotal h3 { font-size: 14px; }

/* ---------------------------------------------------------------- suivi */

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }

.card {
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.card > h3 { font-size: 14px; margin-bottom: 4px; }
.card > p.sub { font-size: 12.5px; color: var(--txt-dim); margin: 0 0 12px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 12px; }
.kpi {
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 13px;
}
.kpi .k { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--txt-faint); }
.kpi .v { font-family: var(--mono); font-size: 21px; font-weight: 650; margin: 3px 0 1px; }
.kpi .h { font-size: 11.5px; color: var(--txt-dim); }

.banner {
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 13.5px;
  border: 1px solid;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.banner.alert { background: color-mix(in srgb, var(--gold) 9%, var(--bg-raise)); border-color: var(--gold-dim); }
.banner.ok { background: color-mix(in srgb, var(--green) 8%, var(--bg-raise)); border-color: #2f6a4f; }
.banner b { color: var(--gold); }
.banner.ok b { color: var(--green); }

.entry { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--txt-faint); }
.field input, .field select {
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  color: var(--txt);
  padding: 7px 9px;
  border-radius: 7px;
  font-family: var(--mono);
  width: 100%;
}
.field.narrow input { max-width: 110px; }
.field input:focus, .field select:focus { outline: none; border-color: var(--gold-dim); }

svg.chart { width: 100%; height: auto; display: block; }
svg.chart text { font-family: var(--mono); font-size: 9px; fill: var(--txt-faint); }

table.log { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12.5px; }
table.log th {
  text-align: left;
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--txt-faint);
  font-weight: 500;
  padding: 5px 8px;
  border-bottom: 1px solid var(--line);
}
table.log td { padding: 5px 8px; border-bottom: 1px solid var(--line-soft); }
table.log tr:last-child td { border-bottom: none; }
table.log td.num { text-align: right; }
table.log button {
  background: none; border: none; color: var(--txt-faint);
  padding: 0 4px; font-size: 14px; line-height: 1;
}
table.log button:hover { color: var(--red); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  color: var(--txt-dim);
  border-radius: 20px;
  padding: 4px 11px;
  font-size: 12px;
}
.chip[aria-pressed="true"] {
  background: color-mix(in srgb, var(--red) 16%, var(--bg-sunk));
  border-color: var(--red);
  color: var(--txt);
}

.hint { font-size: 12px; color: var(--txt-faint); margin: 8px 0 0; }
.empty-state { color: var(--txt-faint); font-size: 13px; padding: 20px 0; text-align: center; }

@media (max-width: 560px) {
  .bar { flex-wrap: wrap; gap: 8px; }
  nav.tabs { margin-left: 0; order: 3; flex-basis: 100%; }
  .reels { grid-template-columns: repeat(2, 1fr); }
  main { padding: 12px 10px 60px; }
}

/* ------------------------------------------------------------- courses */

.field input[type="range"] {
  accent-color: var(--gold);
  padding: 0;
  min-width: 130px;
  background: none;
  border: none;
}
.field label span { color: var(--gold); font-weight: 500; text-transform: none; letter-spacing: 0; }

.course-groupe { padding: 0; margin-bottom: 10px; }

.cg-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.cg-head h3 { font-size: 14px; }
/* Le numéro donne l'ordre du parcours : on suit les rayons dans cet ordre. */
.cg-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--gold);
  color: #17120a;
  font: 600 11px/20px var(--mono);
  text-align: center;
  flex: 0 0 auto;
}
.cg-meta { margin-left: auto; font-family: var(--mono); font-size: 11.5px; color: var(--txt-faint); }

ul.cl { list-style: none; margin: 0; padding: 0; }

.cl-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13.5px;
}
.cl-item:last-child { border-bottom: none; }
.cl-item input[type="checkbox"] { accent-color: var(--gold); width: 16px; height: 16px; flex: 0 0 auto; }
.cl-item.fait { opacity: 0.45; }
.cl-item.fait .cl-nom { text-decoration: line-through; }

.cl-nom { flex: 1 1 auto; min-width: 0; }
.cl-alias { color: var(--txt-faint); font-size: 11.5px; }
.cl-paquets { font-family: var(--mono); font-size: 12px; color: var(--gold); white-space: nowrap; }
.cl-prix {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  min-width: 58px;
  text-align: right;
  flex: 0 0 auto;
}
.cl-flag {
  font-size: 10.5px;
  color: var(--red);
  border: 1px solid color-mix(in srgb, var(--red) 45%, transparent);
  border-radius: 20px;
  padding: 1px 8px;
  white-space: nowrap;
  cursor: help;
}

@media (max-width: 560px) {
  .cl-item { flex-wrap: wrap; row-gap: 3px; }
  .cl-nom { flex-basis: calc(100% - 90px); }
  .cl-paquets { order: 3; flex-basis: 100%; padding-left: 26px; }
  .cl-flag { order: 4; margin-left: 26px; }
}

/* --------------------------------------------------- quinzaine et enseignes */

.jours {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.jour {
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 4px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  color: var(--txt-dim);
  line-height: 1.2;
}
.jour:hover { border-color: var(--gold-dim); color: var(--txt); }
.jour.actif { background: var(--gold); border-color: var(--gold); color: #17120a; }
/* Une journée figée n'est plus retirée par le tirage : le contour le dit. */
.jour.fige { box-shadow: 0 0 0 1px var(--gold-dim) inset; }
.jour.fige::after { content: "📌"; position: absolute; }
.jour { position: relative; }
.jour.fige::after { top: 2px; right: 3px; font-size: 8px; }

.j-nom { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.75; }
.j-num { font-family: var(--mono); font-size: 12px; font-weight: 600; }
.j-kcal { font-family: var(--mono); font-size: 10px; opacity: 0.7; }

.jour-titre {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 4px 0 2px;
}
.jour-titre h3 { font-size: 15px; text-transform: capitalize; }
.jour-titre button:first-of-type { margin-left: auto; }

.ens {
  display: grid;
  grid-template-columns: 22px minmax(90px, 1fr) minmax(60px, 2fr) 74px 84px 92px;
  align-items: center;
  gap: 10px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  font-size: 13.5px;
}
.ens:last-child { border-bottom: none; }
.ens:hover { background: var(--bg-sunk); }
.ens.actuelle { background: color-mix(in srgb, var(--gold) 8%, transparent); }

.ens-rang {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--bg-sunk); border: 1px solid var(--line);
  font: 600 11px/18px var(--mono); text-align: center; color: var(--txt-faint);
}
.ens.actuelle .ens-rang { background: var(--gold); border-color: var(--gold); color: #17120a; }
.ens-nom small { color: var(--gold); font-size: 11px; }
.ens-barre { background: var(--bg-sunk); border-radius: 4px; height: 8px; overflow: hidden; }
.ens-barre i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold-dim), var(--gold)); }
.ens-prix { font-family: var(--mono); font-weight: 600; text-align: right; }
.ens-ecart, .ens-src { font-size: 11.5px; color: var(--txt-faint); text-align: right; }

.cl-src { font-size: 11px; cursor: help; }

#c-prix-etat { font-family: var(--mono); font-size: 11.5px; color: var(--txt-faint); }

@media (max-width: 700px) {
  .ens { grid-template-columns: 20px 1fr 70px; row-gap: 2px; }
  .ens-barre { grid-column: 2 / -1; }
  .ens-ecart { grid-column: 2; text-align: left; }
  .ens-src { grid-column: 3; }
}

/* Une valeur de repli n'a pas le meme statut qu'une mesure : elle s'affiche en retrait. */
table.log td.faible { color: var(--txt-faint); font-style: italic; }
