:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --sunken: #efece5;
  --ink: #1d1b18;
  --muted: #6b655c;
  --line: #e2ddd2;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --accent-soft: #fdebdf;
  --ok: #2b8a3e;
  --ok-soft: #e3f4e6;
  --warn: #b45309;
  --warn-soft: #fdf0d5;
  --bad: #b42318;
  --bad-soft: #fde7e4;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(40 30 10 / 6%), 0 4px 14px rgb(40 30 10 / 5%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --surface: #211f1c;
    --sunken: #1b1a17;
    --ink: #f1ede6;
    --muted: #a59e92;
    --line: #36322c;
    --accent: #ff8c42;
    --accent-ink: #1d1206;
    --accent-soft: #3a2413;
    --ok: #69db7c;
    --ok-soft: #1c3322;
    --warn: #ffc15c;
    --warn-soft: #3b2e12;
    --bad: #ff8a80;
    --bad-soft: #3d1c19;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.7rem; line-height: 1.2; letter-spacing: -0.02em; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); }
ul, ol { margin: 0; padding-left: 1.2rem; }
li + li { margin-top: 0.35rem; }
strong { font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.grow { flex: 1; min-width: 0; }
.block { display: block; margin-top: 0.5rem; color: var(--muted); }
.neg { color: var(--bad); }
.loading { padding: 3rem; text-align: center; color: var(--muted); }
.unit { font-weight: 400; font-size: 0.8rem; color: var(--muted); }
.small-title { margin: 1.1rem 0 0.4rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

/* ---------- Structure ---------- */
#app { min-height: 100dvh; }
.nav {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand img { border-radius: 8px; }
.nav-links { display: flex; gap: 0.25rem; overflow-x: auto; scrollbar-width: none; }
.nav-links::-webkit-scrollbar { display: none; }
.nav-links a {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 0.8rem; border-radius: 999px;
  color: var(--muted); text-decoration: none; white-space: nowrap; font-size: 0.95rem;
}
.nav-links a:hover { color: var(--ink); background: var(--sunken); }
.nav-links a[aria-current="page"] { color: var(--accent-ink); background: var(--accent); font-weight: 600; }
.dot { min-width: 1.25rem; padding: 0 0.3rem; border-radius: 999px; background: var(--warn); color: #fff; font-size: 0.75rem; font-weight: 700; text-align: center; }
#view { max-width: 1120px; margin: 0 auto; padding: 1.5rem 1rem 4rem; display: grid; gap: 1.25rem; }

@media (max-width: 720px) {
  .brand span { display: none; }
  .nav { padding-inline: 0.6rem; }
}
@media (min-width: 1000px) {
  #app { display: grid; grid-template-columns: 232px 1fr; }
  .nav { position: sticky; top: 0; height: 100dvh; flex-direction: column; align-items: stretch; padding: 1.25rem 0.9rem; border-bottom: 0; border-right: 1px solid var(--line); }
  .brand { padding: 0 0.5rem 1rem; font-size: 1.05rem; }
  .nav-links { flex-direction: column; overflow: visible; }
  .nav-links a { border-radius: 10px; justify-content: space-between; }
  #view { margin: 0; padding: 2rem 2.5rem 4rem; width: 100%; }
}

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; }
.row { display: flex; gap: 0.5rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }

/* ---------- Blocs ---------- */
.panel, .card, .empty {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem;
}
.panel > * + *, .card > * + * { margin-top: 0.75rem; }
.panel > h2 + p { margin-top: 0.25rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.list { display: grid; gap: 0.75rem; }
.empty { text-align: center; padding: 2.5rem 1.25rem; display: grid; gap: 0.75rem; justify-items: center; }
.empty p { max-width: 46ch; color: var(--muted); }

details.panel > summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::after { content: "+"; font-size: 1.4rem; line-height: 1; color: var(--muted); }
details.panel[open] > summary::after { content: "–"; }

.stats { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stats.two { grid-template-columns: repeat(2, 1fr); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0.8rem 0.95rem; display: grid; gap: 0.1rem; }
.panel .stat { background: var(--sunken); border-color: transparent; }
.stat span { font-size: 0.82rem; color: var(--muted); }
.stat strong { font-size: 1.4rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: 0.78rem; }
.stat.warn { background: var(--warn-soft); border-color: transparent; }
.stat.warn strong { color: var(--warn); }

.notice { padding: 0.8rem 1rem; border-radius: 12px; background: var(--sunken); font-size: 0.93rem; }
.notice.warn { background: var(--warn-soft); }
.notice.warn strong { color: var(--warn); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 44px; padding: 0 1rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--sunken); }
.btn.danger { color: var(--bad); border-color: transparent; background: transparent; }
.btn.small { min-height: 36px; padding: 0 0.6rem; font-size: 0.85rem; }
.spool .actions { gap: 0.3rem; }
.btn:disabled, .icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.icon-btn { width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 1rem; cursor: pointer; }
.icon-btn:hover:not(:disabled) { background: var(--sunken); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.chip { min-height: 36px; padding: 0 0.85rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font: inherit; font-size: 0.9rem; cursor: pointer; }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.filters { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }

/* ---------- Formulaires ---------- */
.form-grid { display: grid; gap: 0.9rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.form-grid.three { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.field { display: grid; gap: 0.3rem; align-content: start; }
.field.wide { grid-column: 1 / -1; }
.field.inline { max-width: 340px; }
.field label { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.3rem 0.35rem; font-size: 0.875rem; font-weight: 600; }
.field label > input, .field label > select, .field label > textarea { flex: 1 0 100%; }
.field small, .panel small { color: var(--muted); font-size: 0.8rem; }
input[type="text"], input[type="password"], input[type="date"], select, textarea {
  width: 100%; min-height: 44px; padding: 0.55rem 0.7rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); font: inherit; font-weight: 400;
}
input[type="color"] { width: 100%; height: 44px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.check { display: flex; gap: 0.6rem; align-items: flex-start; font-weight: 400; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: 0.15rem; accent-color: var(--accent); flex: none; }
.fil-row { display: grid; grid-template-columns: 1fr 90px 40px; gap: 0.5rem; margin-bottom: 0.5rem; }

/* ---------- Bobines ---------- */
.spool-head { display: flex; align-items: center; gap: 0.75rem; }
.swatch { width: 40px; height: 40px; flex: none; border-radius: 50%; border: 1px solid rgb(0 0 0 / 15%); box-shadow: inset 0 0 0 9px rgb(255 255 255 / 22%); }
.swatch.tiny { display: inline-block; width: 12px; height: 12px; box-shadow: none; vertical-align: middle; }
.meter { height: 8px; border-radius: 999px; background: var(--sunken); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: inherit; background: var(--ok); }
.spool[data-state="basse"] .meter span { background: var(--warn); }
.spool[data-state="basse"] { border-color: var(--warn); }
.spool[data-state="finie"] { opacity: 0.6; }
.spool-numbers { display: flex; align-items: baseline; gap: 0.3rem; font-variant-numeric: tabular-nums; }
.spool-numbers strong { font-size: 1.25rem; }
.actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.actions.col { flex-direction: column; }
.badge { padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.78rem; font-weight: 650; white-space: nowrap; background: var(--sunken); color: var(--muted); }
.badge[data-state="neuve"] { background: var(--ok-soft); color: var(--ok); }
.badge[data-state="basse"] { background: var(--warn-soft); color: var(--warn); }

/* ---------- Listes et tableaux ---------- */
.plain { list-style: none; padding: 0; }
.plain.rows li { display: flex; align-items: center; gap: 0.75rem; padding: 0.65rem 0; border-top: 1px solid var(--line); margin: 0; }
.plain.rows li:first-child { border-top: 0; padding-top: 0; }
.alert[data-kind="warn"] .grow::before { content: "●  "; color: var(--warn); }
.alert[data-kind="info"] .grow::before { content: "●  "; color: var(--muted); }
.lines { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.lines td { padding: 0.35rem 0; border-top: 1px solid var(--line); }
.lines tr:first-child td { border-top: 0; }
.lines td:last-child { text-align: right; white-space: nowrap; }
.lines .total td { font-weight: 700; border-top: 2px solid var(--ink); }
.lines .current td:first-child::after { content: " · choisie"; color: var(--muted); font-size: 0.8rem; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; min-width: 520px; }
.table th { text-align: left; font-size: 0.8rem; color: var(--muted); font-weight: 600; padding: 0.4rem 0.6rem 0.4rem 0; border-bottom: 1px solid var(--line); }
.table td { padding: 0.55rem 0.6rem 0.55rem 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr.current td:first-child { font-weight: 700; }
.checklist { list-style: none; padding: 0; }
.checklist li { padding: 0.6rem 0; border-top: 1px solid var(--line); margin: 0; }
.checklist li:first-child { border-top: 0; }
.checklist input:checked + span strong { text-decoration: line-through; color: var(--muted); }
.glossary { margin: 0; display: grid; gap: 0.6rem; }
.glossary dt { font-weight: 650; }
.glossary dd { margin: 0; color: var(--muted); }

/* ---------- Calculateur ---------- */
.calc { display: grid; gap: 1.25rem; align-items: start; }
.calc-form { display: grid; gap: 1.25rem; }
@media (min-width: 1180px) {
  .calc { grid-template-columns: minmax(0, 1.25fr) minmax(300px, 1fr); }
  .calc-result { position: sticky; top: 1.25rem; max-height: calc(100dvh - 2.5rem); overflow-y: auto; }
}
.score { display: flex; align-items: center; gap: 1rem; padding: 0.9rem 1rem; border-radius: 12px; background: var(--sunken); }
.score-num { font-size: 2.4rem; font-weight: 750; line-height: 1; font-variant-numeric: tabular-nums; }
.score-num small { font-size: 0.9rem; font-weight: 500; color: var(--muted); }
.score[data-tone="great"], .score-pill[data-tone="great"] { background: var(--ok-soft); color: var(--ok); }
.score[data-tone="good"], .score-pill[data-tone="good"] { background: var(--ok-soft); color: var(--ok); }
.score[data-tone="meh"], .score-pill[data-tone="meh"] { background: var(--warn-soft); color: var(--warn); }
.score[data-tone="bad"], .score-pill[data-tone="bad"] { background: var(--bad-soft); color: var(--bad); }
.score .muted, .score strong { color: var(--ink); }
.score .muted { opacity: 0.75; }
.score-pill { flex: none; min-width: 48px; padding: 0.5rem 0.6rem; border-radius: 12px; font-size: 1.2rem; font-weight: 750; text-align: center; font-variant-numeric: tabular-nums; }

.product { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; }
.product > * + * { margin-top: 0; }
.rank { width: 2rem; font-size: 1.3rem; font-weight: 750; color: var(--muted); text-align: center; }
.product-numbers { display: flex; gap: 1.25rem; }
.product-numbers div { display: grid; }
.product-numbers strong { font-variant-numeric: tabular-nums; }

/* ---------- Connexion, fenêtre, message ---------- */
.login { grid-column: 1 / -1; min-height: 100dvh; display: grid; place-items: center; padding: 1rem; }
.login form { width: min(380px, 100%); display: grid; gap: 1rem; justify-items: stretch; text-align: center; }
.login img { justify-self: center; border-radius: 14px; }
.login .field { text-align: left; }

dialog { width: min(680px, calc(100vw - 1.5rem)); max-height: calc(100dvh - 1.5rem); padding: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgb(20 15 10 / 50%); }
dialog form { display: grid; gap: 1rem; padding: 1.25rem; }
dialog header, dialog footer { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
dialog footer { position: sticky; bottom: -1.25rem; margin: 0 -1.25rem -1.25rem; padding: 0.9rem 1.25rem; background: var(--surface); border-top: 1px solid var(--line); }

#toast { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); z-index: 50; max-width: calc(100vw - 2rem); padding: 0.7rem 1.1rem; border-radius: 12px; background: var(--ink); color: var(--bg); font-weight: 600; box-shadow: 0 6px 24px rgb(0 0 0 / 25%); }
#toast[data-kind="error"] { background: var(--bad); color: #fff; }
#toast[hidden] { display: none; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .chip, .nav-links a { transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease; }
}
