:root {
  color-scheme: light;
  --surface-0: #f5f3ef;
  --surface-1: #fdfcfa;
  --surface-2: #f0ede7;
  --border: #e4e0d8;
  --grid: #ece9e3;
  --text-primary: #17140f;
  --text-secondary: #55514a;
  --text-muted: #7c776e;
  --series-1: #2a78d6; /* densité */
  --series-2: #eb6834; /* température */
  --band: rgba(27, 175, 122, .14);
  --accent: #a3530c;
  --on-accent: #ffffff;
  --beer: #e8a33a;
  --foam: #fff7e6;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --warning-text: #8a5a00;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(30, 20, 5, .05), 0 4px 16px rgba(30, 20, 5, .05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #12110f;
    --surface-1: #1b1a17;
    --surface-2: #24221e;
    --border: #312e29;
    --grid: #2a2824;
    --text-primary: #fbf8f2;
    --text-secondary: #c8c3b8;
    --text-muted: #918b80;
    --series-1: #3987e5;
    --series-2: #d95926;
    --band: rgba(25, 158, 112, .18);
    --accent: #f0a640;
    --on-accent: #1b1206;
    --foam: #f5ead2;
    --good-text: #4cc94c;
    --warning-text: #fab219;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #12110f;
  --surface-1: #1b1a17;
  --surface-2: #24221e;
  --border: #312e29;
  --grid: #2a2824;
  --text-primary: #fbf8f2;
  --text-secondary: #c8c3b8;
  --text-muted: #918b80;
  --series-1: #3987e5;
  --series-2: #d95926;
  --band: rgba(25, 158, 112, .18);
  --accent: #f0a640;
  --on-accent: #1b1206;
  --foam: #f5ead2;
  --good-text: #4cc94c;
  --warning-text: #fab219;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main, .top, .foot { max-width: 1180px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
h1, h2, h3 { letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0; }
h3 { font-size: .8rem; margin: 0 0 10px; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--text-muted); }
.small { font-size: .82rem; }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- En-tête ---------- */
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-top: 24px; padding-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 40px; height: 40px; flex: none; }
.brand h1 { margin: 0; font-size: 1.5rem; line-height: 1.2; }
.brand p { margin: 0; font-size: .82rem; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: .9rem; font-weight: 550; cursor: pointer;
  border-radius: 10px; padding: 8px 14px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent);
}
.btn svg { width: 16px; height: 16px; }
.btn.ghost { background: transparent; color: var(--text-primary); border-color: var(--border); }
.btn.ghost:hover { border-color: var(--text-muted); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn:disabled svg { animation: spin 1s linear infinite; }
.btn:focus-visible, .card:focus-visible, tr[tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.small-btn { padding: 5px 12px; font-size: .82rem; }
@keyframes spin { to { transform: rotate(360deg); } }

section { margin-top: 28px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.section-head p { margin: 2px 0 0; }

.error {
  margin-top: 16px; padding: 12px 16px; border-radius: 12px;
  background: var(--surface-1); border: 1px solid var(--critical); border-left-width: 4px;
}
.error::before { content: "⚠ "; color: var(--critical); font-weight: 700; }

.panel, .tile, .card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.panel { padding: 16px; }

/* ---------- Chiffres clés ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile { padding: 14px 16px; }
.tile .label { color: var(--text-secondary); font-size: .8rem; }
.tile .value { font-size: 1.75rem; font-weight: 680; line-height: 1.25; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.tile .value small { font-size: .95rem; font-weight: 550; color: var(--text-secondary); margin-left: 2px; }
.tile .sub { color: var(--text-muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Cartes lots en cours ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 14px; }
.card {
  display: block; width: 100%; padding: 18px; cursor: pointer; text-align: left;
  color: inherit; font: inherit; transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--text-muted); }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.card-head { display: flex; gap: 14px; align-items: flex-start; }
.glass { width: 34px; height: 46px; flex: none; }
.card-title { flex: 1; min-width: 0; }
.card-title .name { font-weight: 680; font-size: 1.08rem; line-height: 1.3; }
.card-title .meta { color: var(--text-muted); font-size: .82rem; margin-top: 2px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  font-size: .75rem; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-secondary); white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--series-1); }
.pill.cond::before { background: var(--text-muted); }

.gauge { margin: 18px 0 6px; }
.gauge-track { position: relative; height: 10px; border-radius: 5px; background: var(--surface-2); }
.gauge-fill { position: absolute; inset: 0 auto 0 0; border-radius: 5px; background: linear-gradient(90deg, var(--foam), var(--beer)); }
.gauge-marker {
  position: absolute; top: 50%; width: 16px; height: 16px; margin-left: -8px; transform: translateY(-50%);
  border-radius: 50%; background: var(--beer); border: 3px solid var(--surface-1); box-shadow: 0 0 0 1px var(--border);
}
.gauge-labels { display: flex; justify-content: space-between; font-size: .75rem; color: var(--text-muted); margin-top: 6px; font-variant-numeric: tabular-nums; }
.gauge-labels strong { color: var(--text-primary); font-weight: 650; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 16px 0; }
.stat .k { font-size: .72rem; color: var(--text-muted); }
.stat .v { font-size: 1.1rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.3; }
.stat .s { font-size: .72rem; color: var(--text-secondary); }

.spark-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }
.spark { flex: 1; height: 38px; min-width: 0; }
.spark polyline { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark circle { fill: var(--series-1); stroke: var(--surface-2); stroke-width: 2; }
.trend { font-size: .8rem; text-align: right; white-space: nowrap; }
.trend .lbl { display: block; font-size: .7rem; color: var(--text-muted); }
.ok { color: var(--good-text); }
.warn { color: var(--warning-text); }

.card-foot { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; margin-top: 12px; font-size: .78rem; color: var(--text-secondary); }
.card-foot span { display: inline-flex; align-items: center; gap: 5px; }
.card-foot svg { width: 14px; height: 14px; flex: none; }

.skeleton { height: 300px; border-radius: 14px; background: linear-gradient(90deg, var(--surface-1), var(--surface-2), var(--surface-1)); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.empty { text-align: center; padding: 28px; }

/* ---------- Détail ---------- */
.detail { scroll-margin-top: 16px; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 14px; align-items: start; }
.chart { margin: 0 0 14px; }
.chart figcaption { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 8px; }
.chart-title { font-weight: 650; font-size: .92rem; }
.legend { display: inline-flex; align-items: center; gap: 6px; font-size: .75rem; color: var(--text-secondary); }
.key { display: inline-block; width: 16px; height: 2px; margin-left: 6px; }
.key:first-child { margin-left: 0; }
.key.s1 { background: var(--series-1); }
.key.s2 { background: var(--series-2); }
.key.dash { background: repeating-linear-gradient(90deg, var(--text-muted) 0 4px, transparent 4px 7px); }
.key.band { height: 10px; background: var(--band); border-radius: 2px; }
.canvas-wrap { position: relative; height: 230px; }
.table-wrap { padding: 0; overflow: auto; }
#table-wrap { max-height: 360px; margin-top: 10px; }

.sheet { display: grid; gap: 14px; }
.sheet dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: .85rem; }
.sheet dt { color: var(--text-muted); }
.sheet dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.ing { list-style: none; margin: 0; padding: 0; font-size: .85rem; }
.ing li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--grid); }
.ing li:last-child { border-bottom: 0; }
.ing .q { font-variant-numeric: tabular-nums; color: var(--text-secondary); white-space: nowrap; text-align: right; }
.ing .d { display: block; font-size: .74rem; color: var(--text-muted); }
.ing-group + .ing-group { margin-top: 12px; }
.ing-group h4 { margin: 0 0 2px; font-size: .78rem; color: var(--text-secondary); font-weight: 600; }
.timeline { list-style: none; margin: 0; padding: 0; font-size: .85rem; }
.timeline li { position: relative; padding: 0 0 12px 18px; }
.timeline li::before { content: ""; position: absolute; left: 3px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.timeline li::after { content: ""; position: absolute; left: 6.5px; top: 17px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline li.future::before { background: var(--accent); }
.timeline .when { display: block; font-size: .75rem; color: var(--text-muted); }

/* ---------- Historique ---------- */
.history-grid { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 14px; align-items: start; }
.history-side { display: grid; gap: 14px; }
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.bars li { font-size: .85rem; }
.bars .row { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.bars .row span:last-child { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.bars .bar { height: 8px; border-radius: 0 4px 4px 0; background: var(--series-1); min-width: 3px; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th.left, td.left { text-align: left; }
th { position: sticky; top: 0; background: var(--surface-1); color: var(--text-muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:last-child td { border-bottom: 0; }
.history tbody tr { cursor: pointer; }
.history tbody tr:hover { background: var(--surface-2); }
.recipe-cell { display: flex; align-items: center; gap: 10px; white-space: normal; min-width: 180px; }
.recipe-cell .st { display: block; font-size: .75rem; color: var(--text-muted); }
.swatch { width: 12px; height: 18px; border-radius: 2px 2px 4px 4px; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.est { color: var(--text-muted); }
.status-tag { font-size: .75rem; color: var(--text-secondary); }

.foot { padding-top: 32px; padding-bottom: 32px; text-align: center; }

@media (max-width: 900px) {
  .detail-grid, .history-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .tile .value { font-size: 1.45rem; }
  .brand h1 { font-size: 1.25rem; }
  .btn .lbl-long { display: none; }
}
