:root {
    --fond: #f6f7f9;
    --texte: #1b2430;
    --principal: #1f3a5f;
    --principal-texte: #ffffff;
    --bordure: #c9d0da;
    --erreur: #9b1c1c;
    --info: #1f5f3a;
}

@media (prefers-color-scheme: dark) {
    :root {
        --fond: #141a22;
        --texte: #e8ecf1;
        --principal: #6d93c7;
        --principal-texte: #0e141b;
        --bordure: #3a4656;
        --erreur: #ff8a8a;
        --info: #8fd4a8;
    }
}

* { box-sizing: border-box; }

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

.page {
    max-width: 28rem;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

h1 { font-size: 1.6rem; margin: 0 0 .5rem; color: var(--principal); }
h2 { font-size: 1.2rem; margin: 0 0 1rem; }

form { display: flex; flex-direction: column; gap: .5rem; margin: 1rem 0; }
label { font-weight: 600; }

input {
    font: inherit;
    padding: .7rem .8rem;
    border: 1px solid var(--bordure);
    border-radius: .5rem;
    background: transparent;
    color: inherit;
}

.bouton {
    font: inherit;
    font-weight: 600;
    padding: .8rem 1rem;
    margin-top: .5rem;
    border: 0;
    border-radius: .5rem;
    background: var(--principal);
    color: var(--principal-texte);
    cursor: pointer;
}

.bouton-secondaire {
    background: transparent;
    color: var(--principal);
    border: 1px solid var(--principal);
}

a { color: var(--principal); }

.message { padding: .6rem .8rem; border-radius: .5rem; border: 1px solid currentColor; }
.message-erreur { color: var(--erreur); }
.message-info { color: var(--info); }

/* Gestion des biens et bibliothèque */
.page:has(.large) { max-width: 46rem; }

.liste { list-style: none; padding: 0; margin: .5rem 0 1rem; display: flex; flex-direction: column; gap: .5rem; }

.carte {
    border: 1px solid var(--bordure);
    border-radius: .5rem;
    padding: .7rem .9rem;
    margin: .6rem 0;
}

.carte summary { cursor: pointer; padding: .2rem 0; }
h3 { font-size: 1.05rem; margin: 1rem 0 .3rem; }

fieldset { border: 1px solid var(--bordure); border-radius: .5rem; margin: 0 0 1rem; padding: .6rem .9rem 1rem; display: flex; flex-direction: column; gap: .4rem; }
legend { font-weight: 700; padding: 0 .4rem; }

select, textarea {
    font: inherit;
    padding: .7rem .8rem;
    border: 1px solid var(--bordure);
    border-radius: .5rem;
    background: transparent;
    color: inherit;
}
option { color: initial; }

.aide { font-size: .9rem; opacity: .8; margin: .1rem 0 .4rem; }
.case { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.case input { width: 1.2rem; height: 1.2rem; }

.onglets { display: flex; flex-wrap: wrap; gap: .4rem; margin: .8rem 0; }
.onglet {
    font: inherit;
    padding: .6rem .9rem;
    border: 1px solid var(--bordure);
    border-radius: .5rem;
    background: transparent;
    color: inherit;
    cursor: pointer;
}
.onglet.actif { background: var(--principal); color: var(--principal-texte); border-color: var(--principal); font-weight: 600; }

.ligne-element { display: flex; flex-direction: column; gap: .4rem; border-bottom: 1px solid var(--bordure); padding-bottom: .5rem; }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.actions .bouton { margin-top: 0; padding: .5rem .8rem; }
.ligne-repartition { display: flex; flex-direction: column; gap: .3rem; border-bottom: 1px solid var(--bordure); padding-bottom: .6rem; }

.bouton[disabled] { opacity: .45; cursor: not-allowed; }
a.bouton { display: inline-block; text-decoration: none; }

@media (min-width: 40rem) {
    .ligne-element { flex-direction: row; justify-content: space-between; align-items: center; }
}

.alerte { padding: .7rem .9rem; border-radius: .5rem; border: 2px solid var(--erreur); color: var(--erreur); font-weight: 600; margin: .5rem 0 1rem; }
.etat-present { color: var(--info); font-weight: 600; }
.etat-manquant { color: var(--erreur); font-weight: 600; }
.etat-a-verifier { font-weight: 600; }

/* Plans : l'image porte, par-dessus, un calque SVG aux coordonnées 0..1 et des repères HTML positionnés en pourcentage */
.plan-visuel { position: relative; width: 100%; line-height: 0; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.plan-visuel.en-trace { cursor: crosshair; outline: 2px dashed var(--principal); }
.plan-image { display: block; width: 100%; height: auto; }
.plan-calque { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.plan-zone { fill: rgba(31, 58, 95, .28); stroke: var(--principal); stroke-width: 2; vector-effect: non-scaling-stroke; }
.plan-trace { fill: rgba(200, 80, 0, .25); stroke: #c85000; stroke-width: 2; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; }
.plan-numero, .plan-sommet { position: absolute; transform: translate(-50%, -50%); pointer-events: none; line-height: 1; }
.plan-numero { background: var(--principal); color: var(--principal-texte); font-weight: 700; font-size: 1rem; min-width: 1.6rem; padding: .25rem .4rem; border-radius: 1rem; text-align: center; }
.plan-sommet { width: .9rem; height: .9rem; border-radius: 50%; background: #c85000; border: 2px solid #fff; }
.plan-legende { padding-left: 1.4rem; display: flex; flex-direction: column; gap: .6rem; }
.plan-legende li { line-height: 1.4; }

/* Contrôle d'une dépense : aperçu et formulaire côte à côte sur grand écran, l'un au-dessus de l'autre sur téléphone */
.page:has(.tres-large) { max-width: 80rem; }
.facture-ecran { display: flex; flex-direction: column; gap: 1rem; }
.facture-apercu img { display: block; max-width: 100%; height: auto; border: 1px solid var(--bordure); border-radius: .5rem; }
.texte-lu { white-space: pre-wrap; overflow-x: auto; max-height: 24rem; font-size: .85rem; }
@media (min-width: 60rem) {
    .facture-ecran { display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
    .facture-apercu { position: sticky; top: 1rem; }
}

/* Débordement horizontal : le champ de fichier reste dans sa carte et le nom du fichier passe à la ligne */
input[type="file"] { display: block; width: 100%; max-width: 100%; min-width: 0; overflow-wrap: anywhere; }

/* Un libellé au-dessus de SON champ, champs de même largeur que les autres */
.champ-bloc { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.champ-bloc > input, .champ-bloc > select { width: 100%; min-width: 0; }
.filtres { display: flex; flex-direction: column; gap: .6rem; }
@media (min-width: 40rem) {
    .filtres { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
    .filtres .champ-bloc { flex: 1 1 14rem; }
}

/* Éléments d'une pièce, compacts sur téléphone : flèches de 40 px sur la même ligne que « Modifier » et « Supprimer » */
@media (max-width: 39.99rem) {
    .ligne-element > .actions-element { flex-wrap: nowrap; gap: .3rem; }
    .ligne-element > .actions-element .bouton { padding: .4rem .6rem; font-size: .9rem; min-height: 2.5rem; }
    .ligne-element > .actions-element .bouton:nth-child(-n+2) { min-width: 2.5rem; padding-inline: 0; }
    .ligne-element > .actions-element .bouton:nth-child(n+3) { flex: 1 1 auto; }
    .liste > .ligne-element { gap: .25rem; padding-bottom: .4rem; }
}
