/* AnimaGest — feuille de style unique (mobile d'abord, thème sombre automatique). */

:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #f0eee7;
  --text: #1d2621;
  --muted: #66706a;
  --border: #e3e0d7;
  --primary: #2e7d5b;
  --primary-hover: #276b4e;
  --primary-ink: #ffffff;
  --primary-soft: #e3f1e9;
  --danger: #b93a32;
  --danger-soft: #fbe9e6;
  --warn: #a8600f;
  --warn-soft: #fcefdc;
  --info-soft: #e7eef9;
  --info: #2f5b9a;
  --shadow: 0 1px 2px rgba(30, 40, 35, .05), 0 3px 10px rgba(30, 40, 35, .05);
  --radius: 14px;
  --sidebar: 248px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131714;
    --surface: #1b201d;
    --surface-2: #232a26;
    --text: #e6ebe7;
    --muted: #9aa49e;
    --border: #2f3732;
    --primary: #5dbb8c;
    --primary-hover: #74c99d;
    --primary-ink: #0c1912;
    --primary-soft: #1d3327;
    --danger: #ef7f74;
    --danger-soft: #3a2220;
    --warn: #e6a65a;
    --warn-soft: #3a2d1b;
    --info-soft: #1f2a3b;
    --info: #8db3ea;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.55rem; letter-spacing: -.01em; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75em; }
img { max-width: 100%; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.tiny { font-size: .78rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.strong { font-weight: 600; }
.hidden, [hidden] { display: none !important; }
.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2;
        stroke-linecap: round; stroke-linejoin: round; vertical-align: -4px; }

/* ---------- Structure ---------- */

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-logo { font-size: 1.35rem; line-height: 1; }
.topbar-actions { display: flex; gap: 4px; align-items: center; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent;
  color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); text-decoration: none; }

.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 40; width: var(--sidebar);
  padding: 18px 12px; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  transform: translateX(-100%); transition: transform .2s ease;
}
.sidebar.ouvert { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .25); }
.sidebar .brand { padding: 4px 10px 16px; }
.side-section { margin: 14px 10px 4px; font-size: .72rem; font-weight: 700; letter-spacing: .06em;
                text-transform: uppercase; color: var(--muted); }
.side-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px;
  color: var(--text); font-weight: 500;
}
.side-link:hover { background: var(--surface-2); text-decoration: none; }
.side-link.actif { background: var(--primary-soft); color: var(--primary); }
.side-link.bouton { width: 100%; border: 0; background: none; font: inherit; cursor: pointer; text-align: left; }
.voile { position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .35); display: none; }
.voile.ouvert { display: block; }

.content { max-width: 1040px; margin: 0 auto; padding: 18px 16px 110px; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  padding: 6px 4px; padding-bottom: max(6px, env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
}
.bottomnav a, .bottomnav button {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0;
  font-size: .7rem; color: var(--muted); background: none; border: 0; font-family: inherit; cursor: pointer;
}
.bottomnav a:hover { text-decoration: none; }
.bottomnav .actif { color: var(--primary); font-weight: 600; }
.bottomnav .plus span.rond {
  display: flex; align-items: center; justify-content: center; width: 48px; height: 48px; margin-top: -22px;
  border-radius: 50%; background: var(--primary); color: var(--primary-ink); box-shadow: var(--shadow);
}
.bottomnav .plus .icon { width: 26px; height: 26px; }

@media (min-width: 960px) {
  .sidebar { transform: none; }
  .voile, .bottomnav, #menu-btn { display: none !important; }
  .content { padding-bottom: 48px; }
  body.connecte .topbar { margin-left: var(--sidebar); }
  body.connecte .topbar .brand { visibility: hidden; }
  body.connecte .content { margin-left: calc(var(--sidebar) + max(0px, (100vw - var(--sidebar) - 1040px) / 2)); }
  body.connecte .flashes { margin-left: calc(var(--sidebar) + max(0px, (100vw - var(--sidebar) - 1040px) / 2)); }
}
body:not(.connecte) .topbar { justify-content: center; }

/* ---------- Messages ---------- */

.flashes { max-width: 1040px; margin: 12px auto 0; padding: 0 16px; }
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 8px; background: var(--primary-soft);
         border: 1px solid transparent; }
.flash-error { background: var(--danger-soft); color: var(--danger); }
.flash-info { background: var(--info-soft); color: var(--info); }

/* ---------- Blocs ---------- */

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap;
             margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.page-head p { margin: 2px 0 0; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card > h2:first-child, .card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-head { margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.card.alerte { border-color: var(--danger); background: linear-gradient(var(--danger-soft), var(--danger-soft)) padding-box; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.cols-2 { display: grid; gap: 16px; }
@media (min-width: 760px) { .cols-2 { grid-template-columns: 1fr 1fr; align-items: start; } }
.stack > * + * { margin-top: 16px; }
.empty { text-align: center; color: var(--muted); padding: 18px 8px; }
.empty .emoji { font-size: 2rem; display: block; margin-bottom: 4px; }
.sep { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }

/* Listes à lignes */
.rows { list-style: none; margin: 0; padding: 0; }
.rows > li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.rows > li:first-child { border-top: 0; padding-top: 2px; }
.rows .main { flex: 1; min-width: 0; }
.rows .titre { font-weight: 600; }
.rows .sous { color: var(--muted); font-size: .875rem; }
.rows .aside { text-align: right; flex: none; }
.rows a.ligne { display: contents; color: inherit; }
@media (max-width: 560px) {
  /* Lignes avec boutons : les boutons passent sous le texte plutôt que de l'écraser. */
  .rows > li:has(> .aside.actions) { flex-wrap: wrap; }
  .rows > li:has(> .aside.actions) > .main { flex-basis: calc(100% - 50px); }
  .rows > li > .aside.actions { margin-left: 50px; }
}
.pastille { flex: none; width: 38px; height: 38px; border-radius: 12px; display: flex; align-items: center;
            justify-content: center; font-size: 1.2rem; background: var(--surface-2); }
.pastille.retard { background: var(--danger-soft); }
.pastille.bientot { background: var(--warn-soft); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px;
         font-size: .76rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.retard { background: var(--danger-soft); color: var(--danger); }
.badge.bientot { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--primary-soft); color: var(--primary); }
.badge.info { background: var(--info-soft); color: var(--info); }

/* Chiffres clés */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.kpi .val { font-size: 1.45rem; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.kpi .lbl { color: var(--muted); font-size: .82rem; }

/* ---------- Boutons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: .92rem;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: .84rem; border-radius: 8px; }
.btn-ok { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.btn-ok:hover { background: var(--primary); color: var(--primary-ink); }
.btn:disabled { opacity: .55; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions.fin { justify-content: flex-end; }
form.inline { display: inline; }

/* ---------- Formulaires ---------- */

label { font-weight: 600; font-size: .9rem; display: block; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .aide { font-size: .8rem; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number],
input[type=search], input[type=email], input:not([type]), select, textarea {
  width: 100%; min-height: 42px; padding: 8px 11px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
input[type=file] { font: inherit; font-size: .9rem; max-width: 100%; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1 1 160px; }
.row > .field.etroit { flex: 0 1 120px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; margin: 0; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 0 0 16px; }
legend { font-weight: 700; padding: 0 6px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: space-between; align-items: center;
                margin-top: 8px; }

/* Choix des animaux */
.choix-animaux { display: grid; gap: 10px; }
.groupe-animaux .entete { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px;
                          font-weight: 600; font-size: .9rem; }
.puces { display: flex; flex-wrap: wrap; gap: 8px; }
.puce { position: relative; }
.puce input { position: absolute; opacity: 0; pointer-events: none; }
.puce span {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 99px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 500; font-size: .92rem;
  user-select: none;
}
.puce input:checked + span { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.puce input:focus-visible + span { outline: 2px solid var(--primary); }
.puce .avatar { width: 22px; height: 22px; font-size: .8rem; }

/* Raccourcis */
.raccourcis { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: thin; }
.raccourcis button { flex: none; }

/* ---------- Animaux ---------- */

.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; background: var(--primary-soft); font-size: 1.35rem;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.grand { width: 88px; height: 88px; font-size: 2.6rem; }
.animaux-grille { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.carte-animal {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 10px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text);
}
.carte-animal:hover { text-decoration: none; border-color: var(--primary); }
.carte-animal .avatar { width: 64px; height: 64px; font-size: 2rem; }
.carte-animal .nom { font-weight: 700; }
.carte-animal .badge { margin-top: 2px; }
.mini-animaux { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.mini-animaux a { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: none; width: 64px;
                  font-size: .78rem; color: var(--text); text-align: center; }
.mini-animaux a:hover { text-decoration: none; }
.mini-animaux .avatar { width: 52px; height: 52px; font-size: 1.6rem; position: relative; overflow: visible; }
.mini-animaux .avatar img { border-radius: 50%; }
.point-alerte { position: absolute; top: 0; right: 0; width: 12px; height: 12px; border-radius: 50%;
                background: var(--danger); border: 2px solid var(--surface); }
.fiche-head { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.fiche-head .infos { flex: 1; min-width: 200px; }
.fiche-head h1 { margin: 0; }
dl.infos-liste { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
dl.infos-liste dt { color: var(--muted); font-size: .88rem; }
dl.infos-liste dd { margin: 0; }

/* ---------- Prises ---------- */

.prise { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.prise:first-child { border-top: 0; padding-top: 2px; }
.prise .heure { font-weight: 700; font-variant-numeric: tabular-nums; width: 52px; flex: none; }
.prise .main { flex: 1; min-width: 160px; }
.prise .etat { font-size: .84rem; }
.prise.donnee .heure, .prise.sautee .heure { color: var(--muted); }
.prise.donnee .main .titre { text-decoration: line-through; text-decoration-color: var(--muted); color: var(--muted); }
.prise.en_retard .heure { color: var(--danger); }
.prise .boutons { display: flex; gap: 6px; flex: none; }
.histo-prises { display: grid; gap: 4px; }
.histo-prises .jour { display: flex; gap: 10px; align-items: center; font-size: .88rem; }
.histo-prises .jour .date { width: 92px; color: var(--muted); flex: none; }
.marque { display: inline-flex; align-items: center; justify-content: center; min-width: 54px; padding: 1px 6px;
          border-radius: 6px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.marque.donnee { background: var(--primary-soft); color: var(--primary); }
.marque.sautee { background: var(--warn-soft); color: var(--warn); }
.marque.oubliee { background: var(--danger-soft); color: var(--danger); }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 6px 0 2px; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }

/* Lignes de traitement (formulaire d'ordonnance) */
.ligne-traitement { position: relative; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
                    margin-bottom: 12px; background: var(--surface-2); }
.ligne-traitement .retirer { position: absolute; top: 8px; right: 8px; }
.chips-heures { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chip { padding: 3px 10px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface);
        font: inherit; font-size: .8rem; cursor: pointer; color: var(--text); }
.chip.on { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }

/* ---------- Agenda ---------- */

.jour-agenda { margin-bottom: 18px; }
.jour-agenda h3 { font-size: .9rem; color: var(--muted); margin-bottom: 6px; }
.jour-agenda h3::first-letter { text-transform: uppercase; }
.jour-agenda h3 .aujourdhui { color: var(--primary); }
.evt { display: flex; gap: 12px; align-items: center; padding: 10px 12px; margin-bottom: 6px; border-radius: 12px;
       background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.evt:hover { text-decoration: none; border-color: var(--primary); }
.evt .quand { font-weight: 700; font-size: .85rem; width: 48px; flex: none; color: var(--muted); }

/* ---------- Tableaux ---------- */

.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); }

/* Filtres */
.filtres { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filtres select, .filtres input { width: auto; min-width: 120px; flex: 1 1 140px; min-height: 38px; }
.onglets { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.onglets a { padding: 6px 12px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border);
             color: var(--text); font-size: .88rem; font-weight: 500; }
.onglets a.actif { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.onglets a:hover { text-decoration: none; }

/* ---------- Graphiques ---------- */

.barres { display: grid; gap: 8px; }
.barre { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: .9rem; }
.barre .nom { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barre .piste { height: 14px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.barre .piste > span { display: block; height: 100%; background: var(--primary); border-radius: 0 4px 4px 0; min-width: 2px; }
.barre .val { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 74px; text-align: right; }
.histo-mois { display: flex; align-items: flex-end; gap: 2px; height: 180px; padding-top: 20px;
              border-bottom: 1px solid var(--border); }
.histo-mois .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
                   height: 100%; min-width: 0; position: relative; outline: none; }
.histo-mois .col .b { width: 100%; max-width: 24px; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 1px; }
.histo-mois .col .b.vide { background: var(--border); }
.histo-mois .col:hover .b, .histo-mois .col:focus-visible .b { background: var(--primary-hover); }
.histo-mois .col .v { font-size: .72rem; color: var(--muted); position: absolute; top: -18px; white-space: nowrap; }
.histo-axe { display: flex; gap: 2px; margin-top: 4px; }
.histo-axe span { flex: 1; min-width: 0; text-align: center; font-size: .68rem; color: var(--muted); white-space: nowrap; overflow: visible; }
.barre:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
.infobulle { position: fixed; z-index: 60; pointer-events: none; padding: 6px 10px; border-radius: 8px;
             background: var(--text); color: var(--bg); font-size: .82rem; font-weight: 600; box-shadow: var(--shadow);
             white-space: nowrap; transform: translate(-50%, calc(-100% - 10px)); }

/* ---------- Ajout rapide ---------- */

dialog.feuille {
  border: 0; padding: 16px; border-radius: 18px 18px 0 0; width: 100%; max-width: 520px; margin: auto auto 0;
  background: var(--surface); color: var(--text); box-shadow: 0 -10px 40px rgba(0, 0, 0, .25);
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
@media (min-width: 600px) { dialog.feuille { border-radius: 18px; margin: auto; } }
dialog.feuille::backdrop { background: rgba(0, 0, 0, .4); }
.feuille-titre { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.ajouts { display: grid; gap: 8px; }
.ajouts a { display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: 12px;
            background: var(--surface-2); color: var(--text); }
.ajouts a:hover { text-decoration: none; background: var(--primary-soft); }
.ajouts .e { font-size: 1.5rem; width: 36px; text-align: center; }
.ajouts .t { font-weight: 600; }
.ajouts .d { font-size: .82rem; color: var(--muted); }

/* ---------- Connexion ---------- */

.auth { max-width: 400px; margin: 7vh auto 0; }
.auth .logo { font-size: 3rem; text-align: center; }
.auth h1 { text-align: center; }

/* ---------- Divers ---------- */

.photo-ordonnance { max-height: 520px; border-radius: 10px; border: 1px solid var(--border); }
.copie { display: flex; gap: 8px; }
.copie input { font-size: .82rem; font-family: ui-monospace, Consolas, monospace; }
.note-pied { font-size: .8rem; color: var(--muted); text-align: center; margin-top: 24px; }
@media print { .topbar, .sidebar, .bottomnav, .actions, .form-actions { display: none !important; } .content { margin: 0; } }
