/*
 * Feuille de style unique, ecrite en mobile-first et sans dependance.
 *
 * Trois contraintes ont guide ce fichier :
 *  - la saisie se fait au jardin, telephone en main : aucune cible tactile
 *    sous 44 px, et des champs a 16 px minimum sans quoi iOS zoome au focus ;
 *  - sobriete : polices systeme uniquement, aucune image decorative, aucune
 *    requete reseau supplementaire depuis le CSS ;
 *  - l'application doit rester utilisable sans JavaScript. La navigation est
 *    donc visible par defaut ; c'est le script qui la replie derriere le
 *    bouton, jamais l'inverse.
 */

:root {
    --vert-fonce: #27500a;
    --vert: #3b6d11;
    --vert-clair: #639922;
    --vert-pale: #eaf3de;
    --ambre: #ba7517;
    --ambre-pale: #faeeda;
    --rouge: #a32d2d;
    --rouge-pale: #fcebeb;

    --texte: #1c1c1a;
    --texte-doux: #5f5e5a;
    --texte-efface: #888780;
    --fond: #f7f6f2;
    --surface: #ffffff;
    --bordure: #e2e0d8;

    --rayon: 10px;
    --rayon-carte: 14px;
    --cible-tactile: 44px;
    --largeur-max: 900px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --vert-pale: #1e2b14;
        --ambre-pale: #2e2413;
        --rouge-pale: #2e1616;

        --texte: #ececea;
        --texte-doux: #a8a79f;
        --texte-efface: #83827b;
        --fond: #161714;
        --surface: #1f211d;
        --bordure: #333630;
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--fond);
    color: var(--texte);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.6;
}

h1, h2, h3 {
    margin: 0 0 0.5rem;
    font-weight: 600;
    line-height: 1.25;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }

a { color: var(--vert-clair); }

img {
    max-width: 100%;
    height: auto;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ---------------------------------------------------------------- En-tete */

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--vert-fonce);
    color: #fff;
    padding-top: env(safe-area-inset-top);
}

.app-header__bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    max-width: var(--largeur-max);
    margin: 0 auto;
    padding: 0 0.75rem;
    min-height: 56px;
}

.app-header__brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-right: auto;
    color: #fff;
    font-weight: 600;
    font-size: 1.05rem;
    text-decoration: none;
}

.app-header__logo { font-size: 1.3rem; }

/*
 * Le bouton n'existe que si le script s'est execute : sans lui, il n'aurait
 * rien a replier et n'afficherait qu'une commande morte.
 */
.app-header__burger { display: none; }

.js .app-header__burger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: var(--cible-tactile);
    height: var(--cible-tactile);
    padding: 0 10px;
    border: 0;
    border-radius: var(--rayon);
    background: transparent;
    cursor: pointer;
}

.app-header__burger:hover,
.app-header__burger:focus-visible {
    background: rgb(255 255 255 / 12%);
}

.app-header__burger-bar {
    display: block;
    height: 2px;
    border-radius: 2px;
    background: #fff;
}

/* ------------------------------------------------------------ Navigation */

/* Visible par defaut : c'est l'etat sans JavaScript. */
.app-nav { flex-basis: 100%; }

.js .app-nav { display: none; }
.js .app-nav.is-open { display: block; }

.app-nav__list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding: 0 0 0.5rem;
    list-style: none;
}

.app-nav__link {
    display: flex;
    align-items: center;
    min-height: var(--cible-tactile);
    padding: 0 0.75rem;
    border-radius: var(--rayon);
    color: #fff;
    text-decoration: none;
}

.app-nav__link:hover,
.app-nav__link:focus-visible {
    background: rgb(255 255 255 / 12%);
}

.app-nav__link.is-active {
    background: rgb(255 255 255 / 20%);
    font-weight: 600;
}

.app-nav__link--muted { color: rgb(255 255 255 / 75%); }

.app-nav__spacer { display: none; }

/* A partir de 768 px : barre horizontale permanente, plus de bouton. */
@media (min-width: 768px) {
    .js .app-header__burger { display: none; }

    .app-nav,
    .js .app-nav {
        display: block;
        flex-basis: auto;
    }

    .app-nav__list {
        flex-direction: row;
        align-items: center;
        padding: 0;
    }

    .app-nav__link {
        min-height: 38px;
        padding: 0 0.7rem;
        font-size: 0.95rem;
    }

    .app-nav__spacer {
        display: block;
        width: 1rem;
    }
}

/* ---------------------------------------------------------------- Contenu */

.app-main {
    max-width: var(--largeur-max);
    margin: 0 auto;
    padding: 1rem 0.75rem calc(5.5rem + env(safe-area-inset-bottom));
}

@media (min-width: 768px) {
    .app-main { padding-bottom: 2rem; }
}

/* ------------------------------------------------------- En-tete de page */

.page-header {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    margin-bottom: 0.35rem;
}

.page-header__back {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: var(--cible-tactile);
    height: var(--cible-tactile);
    border: 1px solid var(--bordure);
    border-radius: var(--rayon);
    background: var(--surface);
    color: var(--texte);
    font-size: 1.25rem;
    line-height: 1;
    text-decoration: none;
}

.page-header__back:hover,
.page-header__back:focus-visible {
    border-color: var(--vert);
    background: var(--vert-pale);
    color: var(--vert-clair);
}

.page-header__title {
    /* Cale la premiere ligne du titre sur le centre du bouton. */
    margin: 0;
    padding-top: 0.35rem;
    min-width: 0;
}

/* ----------------------------------------------------------------- Cartes */

.card {
    background: var(--surface);
    border: 1px solid var(--bordure);
    border-radius: var(--rayon-carte);
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.card__title {
    margin: 0 0 0.25rem;
    font-size: 1rem;
    font-weight: 600;
}

.card__meta {
    margin: 0;
    color: var(--texte-doux);
    font-size: 0.875rem;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--bordure);
    border-radius: var(--rayon-carte);
    padding: 0.85rem 1rem;
}

.stat__label {
    margin: 0;
    color: var(--texte-doux);
    font-size: 0.8125rem;
}

.stat__value {
    margin: 0.15rem 0 0;
    font-size: 1.6rem;
    font-weight: 600;
    line-height: 1.2;
}

/* ---------------------------------------------------------------- Galerie */

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 6px;
    margin-top: 0.75rem;
}

.gallery__item {
    position: relative;
    margin: 0;
    aspect-ratio: 1;
    border-radius: var(--rayon);
    overflow: hidden;
    background: var(--fond);
}

.gallery__item img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery__delete {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgb(0 0 0 / 55%);
    color: #fff;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
}

.gallery__delete:hover {
    background: var(--rouge);
}

/* ----------------------------------------------------------------- Badges */

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.badge--ok      { background: var(--vert-pale);  color: var(--vert-clair); }
.badge--attente { background: var(--ambre-pale); color: var(--ambre); }
.badge--alerte  { background: var(--rouge-pale); color: var(--rouge); }

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: var(--cible-tactile);
    padding: 0 1rem;
    border: 1px solid var(--bordure);
    border-radius: var(--rayon);
    background: var(--surface);
    color: var(--texte);
    font: inherit;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
}

.btn:hover { border-color: var(--texte-efface); }

.btn--primary {
    background: var(--vert);
    border-color: var(--vert);
    color: #fff;
}

.btn--primary:hover {
    background: var(--vert-fonce);
    border-color: var(--vert-fonce);
}

.btn--block { width: 100%; }

.btn-row {
    display: flex;
    gap: 0.5rem;
}

.btn-row > .btn { flex: 1; }

/* -------------------------------------------------- Bouton d'action flottant */

.fab {
    position: fixed;
    right: 1rem;
    bottom: calc(1rem + env(safe-area-inset-bottom));
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--vert);
    color: #fff;
    font-size: 1.4rem;
    text-decoration: none;
    box-shadow: 0 3px 10px rgb(0 0 0 / 22%);
}

.fab:hover { background: var(--vert-fonce); }

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

.form-field { margin-bottom: 1rem; }

.form-field label {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
    font-weight: 500;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="file"],
select,
textarea {
    width: 100%;
    min-height: var(--cible-tactile);
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--bordure);
    border-radius: var(--rayon);
    background: var(--surface);
    color: var(--texte);
    /* 16 px minimum : en dessous, iOS zoome tout seul a la prise de focus. */
    font-size: 16px;
    font-family: inherit;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
.btn:focus-visible,
a:focus-visible {
    outline: 2px solid var(--vert-clair);
    outline-offset: 2px;
}

textarea {
    min-height: 90px;
    resize: vertical;
}

.form-help {
    margin: 0.25rem 0 0;
    color: var(--texte-doux);
    font-size: 0.8125rem;
}

/*
 * Choix multiples ou exclusifs presentes en liste.
 *
 * Les cases et boutons radio gardent leur taille native, mais toute la ligne
 * est cliquable : viser un rond de 13 px avec un doigt terreux ne marche pas.
 */
.form-field input[type="radio"],
.form-field input[type="checkbox"] {
    width: auto;
    min-height: auto;
    margin: 0.2rem 0.6rem 0 0;
    flex-shrink: 0;
}

.form-field label > input[type="radio"],
.form-field label > input[type="checkbox"] {
    margin-top: 0;
}

.form-field > div > label,
.form-field fieldset label {
    display: flex;
    align-items: flex-start;
    min-height: var(--cible-tactile);
    padding: 0.5rem 0.6rem;
    margin-bottom: 2px;
    border: 1px solid var(--bordure);
    border-radius: var(--rayon);
    background: var(--surface);
    font-weight: 400;
    cursor: pointer;
}

.form-field > div > label:hover,
.form-field fieldset label:hover {
    border-color: var(--vert-clair);
}

.form-field label:has(input:checked) {
    border-color: var(--vert);
    background: var(--vert-pale);
}

.choice__title {
    display: block;
    font-weight: 500;
}

.choice__hint {
    display: block;
    margin-top: 0.1rem;
    color: var(--texte-doux);
    font-size: 0.8125rem;
    line-height: 1.45;
}

.form-error {
    margin: 0.25rem 0 0;
    color: var(--rouge);
    font-size: 0.8125rem;
}

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

.flash {
    margin: 0 0 1rem;
    padding: 0.7rem 0.9rem;
    border-radius: var(--rayon);
    font-size: 0.925rem;
}

.flash--success { background: var(--vert-pale);  color: var(--vert-clair); }
.flash--warning { background: var(--ambre-pale); color: var(--ambre); }
.flash--error   { background: var(--rouge-pale); color: var(--rouge); }

.empty-state {
    padding: 2rem 1rem;
    color: var(--texte-doux);
    text-align: center;
}

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

.login {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100dvh;
    max-width: 380px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

.login__title {
    margin-bottom: 1.25rem;
    text-align: center;
}
