:root {
    --bg: #f5f4ef;
    --surface: #ffffff;
    --text: #1f2a24;
    --muted: #66706a;
    --line: #dcdcd2;
    --primary: #2f6b3f;
    --primary-dark: #234f2f;
    --red: #b3261e;
    --red-bg: #fdecea;
    --orange: #a65c00;
    --orange-bg: #fff3e0;
    --green: #2f6b3f;
    --green-bg: #e7f3ea;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }

.topbar {
    background: var(--primary-dark);
    color: #fff;
    padding: .5rem 1rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem 1.5rem;
}
.topbar .brand { color: #fff; font-weight: 700; text-decoration: none; }
.topbar nav { display: flex; flex-wrap: wrap; gap: .25rem; }
.topbar nav a {
    color: #dfeee3;
    text-decoration: none;
    padding: .3rem .6rem;
    border-radius: 6px;
}
.topbar nav a:hover, .topbar nav a.active { background: rgba(255,255,255,.15); color: #fff; }
.topbar nav a.logout { opacity: .75; }

/* Sous-menu Configuration : s'ouvre au survol ou au clic (focus). */
.dropdown { position: relative; }
.dropdown > button {
    background: none;
    border: 0;
    color: #dfeee3;
    font-weight: normal;
    padding: .3rem .6rem;
    border-radius: 6px;
}
.dropdown > button:hover, .dropdown > button.active, .dropdown:focus-within > button { background: rgba(255,255,255,.15); color: #fff; }
.dropdown .menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 10;
    min-width: 200px;
    background: var(--primary-dark);
    border-radius: 0 0 8px 8px;
    padding: .25rem;
    box-shadow: 0 4px 12px rgba(0,0,0,.2);
}
.dropdown:hover .menu, .dropdown:focus-within .menu { display: block; }
.topbar nav .dropdown .menu a { display: block; }

.container { max-width: 1100px; margin: 0 auto; padding: 1.25rem 16px 3rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

.grid { display: grid; gap: .75rem 1rem; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid .wide { grid-column: 1 / -1; }

label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
input, select, textarea {
    width: 100%;
    font: inherit;
    padding: .45rem .55rem;
    border: 1px solid #c4c6bb;
    border-radius: 6px;
    background: #fff;
    color: var(--text);
}
input[type=checkbox] { width: auto; }
textarea { min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.btn, button {
    display: inline-block;
    font: inherit;
    font-weight: 600;
    padding: .5rem 1rem;
    border-radius: 6px;
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover, button:hover { background: var(--primary-dark); }
.btn-light { background: #fff; color: var(--primary); }
.btn-light:hover { background: var(--green-bg); }
.btn-danger { background: #fff; color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: var(--red-bg); }
.btn-sm { padding: .2rem .55rem; font-size: .85rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: 1rem; }
form.inline { display: inline; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: .45rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td input[type=number] { max-width: 110px; }
tr.muted td { color: var(--muted); }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash-ok { background: var(--green-bg); color: var(--green); }
.flash-error { background: var(--red-bg); color: var(--red); }
.flash-warn { background: var(--orange-bg); color: var(--orange); }

.banner {
    background: var(--red-bg);
    color: var(--red);
    border: 2px solid var(--red);
    border-radius: 8px;
    padding: .75rem 1rem;
    margin: .75rem 0;
}
.banner-days { font-size: 1.6rem; font-weight: 800; margin-right: .25rem; }
.banner-expired { background: var(--red); color: #fff; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-orange { background: var(--orange-bg); color: var(--orange); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-grey { background: #eceee8; color: var(--muted); }
.badge-blue { background: #e6eef8; color: #1f4e86; }

/* Bouton qui déplie un formulaire : <details><summary class="btn">Modifier</summary>…</details> */
summary.btn { display: inline-block; list-style: none; }
summary.btn::-webkit-details-marker { display: none; }
details[open] > summary.btn { margin-bottom: .75rem; }

/* Onglets de page (ex. Analyses : demande / import / historique) */
.tabs { display: flex; flex-wrap: wrap; gap: .25rem; border-bottom: 2px solid var(--line); margin-bottom: 1rem; }
.tabs a {
    padding: .5rem 1rem;
    text-decoration: none;
    color: var(--muted);
    font-weight: 600;
    border-radius: 8px 8px 0 0;
    margin-bottom: -2px;
    border-bottom: 2px solid transparent;
}
.tabs a:hover { color: var(--primary); background: var(--green-bg); }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--surface); }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.stats { display: flex; flex-wrap: wrap; gap: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .75rem 1rem; min-width: 140px; }
.stat b { display: block; font-size: 1.4rem; }

.login-box { max-width: 380px; margin: 10vh auto 0; }
.checklist label { display: flex; gap: .5rem; align-items: center; color: var(--text); font-size: 1rem; padding: .25rem 0; }

@media (max-width: 600px) {
    .topbar nav a { padding: .25rem .45rem; font-size: .9rem; }
    th, td { padding: .35rem .4rem; }
}

/* Fiche lot : liste des documents présents / absents */
.docs-statut { list-style: none; margin: 0; padding: 0; }
.docs-statut li { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .4rem 0; border-bottom: 1px solid #eceee8; }
.docs-statut li:last-child { border-bottom: 0; }
.docs-statut li > a { min-width: 17rem; }
/* Consignes d'abattage (PAC) */
.consignes .poignee { cursor: grab; font-size: 1.2rem; color: var(--muted); user-select: none; }
.consignes tr.dragging { opacity: .45; }
.consignes [data-move] { padding: 0 .35rem; margin: .15rem .1rem 0 0; }
.ouvriers-chaine { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; }
/* Abattage : lots d'une ICA, regroupés par troupeau */
.ica-lots th.sous-titre { background: var(--green-bg); color: var(--green); text-align: left; }
.ica-lots input:disabled { opacity: .4; }

/* AFSCA : traçabilité par jour */
.jour summary { cursor: pointer; padding: .25rem 0; }
.jour[open] summary { margin-bottom: .5rem; }
.jour .docs .btn { margin: .1rem .1rem .1rem 0; }

/* Photo depuis le GSM */
.btn-photo { margin-top: .4rem; }
.photo-info { display: flex; align-items: center; gap: .5rem; margin-top: .35rem; }
.photo-info img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid #ccc; }

/* Statistiques : filtres, chiffres clés, graphiques */
.filtres-stats { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: flex-end; }
.filtres-stats > div { min-width: 150px; }
.filtres-stats label { margin-bottom: .15rem; }
.filtres-stats .filtres-actions { min-width: 0; }
.tuiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .75rem; margin: 1rem 0; }
.tuile { background: #fff; border: 1px solid rgba(11,11,11,.10); border-radius: 10px; padding: .8rem 1rem; display: flex; flex-direction: column; gap: .15rem; }
.tuile-label { color: #52514e; font-size: .9rem; }
.tuile-valeur { font-size: 2rem; font-weight: 600; line-height: 1.15; color: #0b0b0b; }
.tuile-valeur small { font-size: .9rem; font-weight: 400; color: #52514e; }
.tuile-delta { font-size: .9rem; font-weight: 600; }
.tuile-delta.bon { color: #006300; } .tuile-delta.mauvais { color: #b3261e; } .tuile-delta.neutre { color: #898781; font-weight: 400; }
.tuile-avant { font-size: .8rem; color: #898781; }
.graph { margin-top: .25rem; }
.graph-svg { width: 100%; height: auto; display: block; }
.graph-svg text { font: 11px system-ui, -apple-system, "Segoe UI", sans-serif; fill: #898781; }
.graph-svg .grille { stroke: #e1e0d9; stroke-width: 1; }
.graph-svg .axe { stroke: #c3c2b7; stroke-width: 1; }
.graph-svg .ligne { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.graph-svg .point { stroke: #fff; stroke-width: 2; }
.graph-svg .marque:hover, .graph-svg .point:hover { opacity: .75; }
.graph-legende { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-size: .85rem; color: #52514e; margin-bottom: .3rem; }
.graph-legende i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .35rem; vertical-align: -1px; }
.graph-chiffres summary { cursor: pointer; font-size: .85rem; color: #52514e; margin-top: .3rem; }
.barres-h { display: flex; flex-direction: column; gap: .4rem; }
.bh-ligne { display: grid; grid-template-columns: minmax(110px, 28%) 1fr auto; align-items: center; gap: .6rem; font-size: .9rem; }
.bh-nom { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bh-piste { display: flex; gap: 2px; height: 16px; }
.bh-piste i { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.bh-piste i + i { border-radius: 0 4px 4px 0; }
.bh-val { font-variant-numeric: tabular-nums; color: #52514e; }
@media (max-width: 600px) { .filtres-stats > div { min-width: 45%; } .tuile-valeur { font-size: 1.6rem; } }
/* QR code mortalité : saisie au GSM et fiche imprimable */
.qr-saisie { max-width: 520px; margin: 0 auto; }
.qr-saisie h1 { margin-bottom: 0; }
.qr-troupeau { font-size: 1.15rem; font-weight: 600; margin-top: .2rem; }
.qr-saisie select { font-size: 1.05rem; padding: .55rem; margin-bottom: .5rem; }
.qr-ligne { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .75rem 0; border-bottom: 1px solid #eceee8; }
.qr-ligne > div { display: flex; flex-direction: column; gap: .1rem; }
.qr-enclos { font-size: 1.3rem; }
.qr-ligne input { width: 6.5rem; font-size: 1.5rem; padding: .45rem; text-align: center; }
.qr-bouton { width: 100%; font-size: 1.2rem; padding: .85rem; margin-top: 1rem; }
.qr-fiche { max-width: 420px; margin: 0 auto 1rem; text-align: center; background: #fff; border: 2px solid #1f3c2a; border-radius: 12px; padding: 1.25rem; }
.qr-fiche-titre { font-size: 2rem; font-weight: 700; margin: 0; }
.qr-fiche-troupeau { font-size: 1.2rem; margin: .25rem 0 .75rem; }
.qr-fiche #qr svg { width: 100%; max-width: 320px; height: auto; }
.qr-fiche-consigne { font-size: 1.05rem; margin: .5rem 0 0; }
@media print {
    .topbar, .no-print, .flash { display: none !important; }
    body { background: #fff; }
    .qr-fiche { border-width: 3px; margin-top: 2cm; max-width: 13cm; }
}
/* QR codes : plusieurs fiches, impression d'une fiche ou de toutes (une par page) */
.qr-fiches { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center; }
.qr-fiches .qr-fiche { margin: 0; flex: 1 1 300px; }
.qr-fiche .qr svg { width: 100%; max-width: 320px; height: auto; }
.zone-danger { border-color: #e9b4b0; }
.zone-danger summary { cursor: pointer; color: #b3261e; }
@media print {
    h1, .qr-fiches { margin: 0; }
    .qr-fiches { display: block; }
    .qr-fiches .qr-fiche { page-break-after: always; break-after: page; }
    body.imprimer-une .qr-fiche:not(.a-imprimer) { display: none; }
}