:root {
    --bg: #f7f5f0;
    --surface: #ffffff;
    --text: #1f1b16;
    --muted: #6b6359;
    --border: #e4ded4;
    --primary: #b8660b;
    --primary-text: #ffffff;
    --danger: #b42318;
    --success: #1f7a3a;
    --warning: #9a5b00;
    --radius: 10px;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #171512;
        --surface: #221f1b;
        --text: #f1ece4;
        --muted: #a69c8f;
        --border: #3a352e;
        --primary: #e08a2c;
        --primary-text: #171512;
        --danger: #f97066;
        --success: #47cd89;
        --warning: #fdb022;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--primary); }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: .75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topbar-nav { display: flex; gap: 1rem; align-items: center; }

.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.auth-card { max-width: 420px; margin: 2rem auto; }

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: 1rem; }
.field input, .field select, .field textarea {
    padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg); color: var(--text); font: inherit;
}
.field-help { margin: 0; font-size: .85rem; color: var(--muted); }
.field-error { margin: 0; font-size: .85rem; color: var(--danger); }
.has-error input { border-color: var(--danger); }
.checkbox { display: flex; gap: .5rem; align-items: center; margin-bottom: 1rem; }

.btn { display: inline-block; padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--border); font: inherit; cursor: pointer; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid currentColor; }
.flash-error { color: var(--danger); }
.flash-success { color: var(--success); }

/* --- Navigation & mise en page --- */
.topbar { gap: 1rem; flex-wrap: wrap; }
.mainnav { display: flex; gap: .25rem; flex: 1; }
.mainnav a { padding: .35rem .7rem; border-radius: 8px; text-decoration: none; color: var(--muted); }
.mainnav a:hover { color: var(--text); }
.mainnav a[aria-current="page"] { background: var(--bg); color: var(--text); font-weight: 600; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.page-head h1, .page-head h2 { margin: 0; }
.section { margin-bottom: 1rem; }
.narrow { max-width: 640px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.empty { text-align: center; padding: 2rem; }
.small { font-size: .875rem; }
.prewrap { white-space: pre-wrap; }
.plain-list { list-style: none; padding: 0; margin: 0 0 .5rem; display: grid; gap: .35rem; }
.stat { font-size: 2rem; font-weight: 700; margin: 0; }
.actions { display: flex; gap: .5rem; }
.inline-form { display: flex; gap: 1rem; align-items: end; flex-wrap: wrap; }
.inline-form label { display: flex; flex-direction: column; gap: .3rem; }
.inline-form input, .inline-form select { padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.danger-zone { margin-top: 2rem; }
.btn-danger { color: var(--danger); background: transparent; border-color: var(--danger); }
.btn-icon { padding: .4rem .6rem; background: transparent; color: var(--muted); }
.btn:hover { filter: brightness(1.05); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* --- Tableaux --- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
th, td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* --- Statistiques --- */
.stats { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: .5rem; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; display: flex; flex-direction: column; }
.stat-label { font-size: .8rem; color: var(--muted); }
.stat-value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.swatch { display: inline-block; width: .9em; height: .9em; border-radius: 3px; vertical-align: -1px; border: 1px solid rgba(0,0,0,.15); }

/* --- Badges de statut --- */
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); vertical-align: middle; }
.badge-brewing, .badge-fermenting { color: var(--primary); border-color: var(--primary); }
.badge-conditioning { color: #2f6fb3; border-color: #2f6fb3; }
.badge-packaged { color: var(--success); border-color: var(--success); }
.badge-cancelled { color: var(--muted); text-decoration: line-through; }

.timeline { display: flex; list-style: none; padding: 0; margin: 0 0 1rem; gap: .25rem; flex-wrap: wrap; counter-reset: step; }
.timeline li { flex: 1; min-width: 100px; padding: .4rem .6rem; border-top: 3px solid var(--border); color: var(--muted); font-size: .85rem; }
.timeline li.current { border-color: var(--primary); color: var(--text); font-weight: 600; }

/* --- Formulaires --- */
.form-grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.line-head, .line-row { display: grid; grid-template-columns: minmax(180px, 3fr) 1fr 1.4fr 1fr auto; gap: .5rem; align-items: start; }
.line-head { font-size: .8rem; color: var(--muted); padding-bottom: .3rem; }
.line-row { margin-bottom: .5rem; }
.line-cell select, .line-cell input { width: 100%; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.line-cell.has-error select, .line-cell.has-error input { border-color: var(--danger); }
@media (max-width: 700px) {
    .line-head { display: none; }
    .line-row { grid-template-columns: 1fr 1fr; padding-bottom: .5rem; border-bottom: 1px solid var(--border); }
    .line-row .line-cell:first-child { grid-column: 1 / -1; }
}

/* --- Stocks --- */
.flash-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.alert-card { border-color: var(--warning); }
.alert-card h2 { color: var(--warning); }

/* --- iSpindel --- */
.config-list { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 1rem 0; }
.config-list dt { font-weight: 600; }
.config-list dd { margin: 0; overflow-wrap: anywhere; }
code { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: .05rem .3rem; font-size: .9em; }
.chart-box { position: relative; height: 320px; }
.status-box { border: 2px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; background: var(--surface); }
.status-box .status-title { font-size: 1.15rem; font-weight: 700; margin: 0 0 .5rem; display: flex; align-items: center; gap: .6rem; }
.status-ok { border-color: var(--success); }
.status-ok .status-title { color: var(--success); }
.status-wait { border-color: var(--warning); border-style: dashed; }
.pulse { width: .8rem; height: .8rem; border-radius: 50%; background: var(--warning); animation: pulse 1.2s ease-in-out infinite; flex: none; }
@keyframes pulse { 50% { opacity: .25; transform: scale(.7); } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }
.steps { padding-left: 1.4rem; }
.steps > li { margin-bottom: .6rem; }
.guide h2 { scroll-margin-top: 1rem; }
.guide h3 { margin-top: 1.2rem; }
.tip { border-left: 4px solid var(--primary); padding: .5rem .9rem; background: var(--bg); border-radius: 0 8px 8px 0; }
.toc { columns: 2; }
