@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600&family=Inter:wght@400;500;600&display=swap");

:root {
  --fond: #f4f1ea;
  --surface: #fffdf9;
  --texte: #1f2a24;
  --doux: #6f766f;
  --ligne: #e6e0d4;
  --accent: #2e5e4e;
  --accent-fonce: #1f4337;
  --accent-clair: #e4eee8;
  --ambre: #c27a2c;
  --ambre-clair: #f8ecdc;
  --danger: #b54040;
  --ombre: 0 1px 2px rgba(31, 42, 36, .05), 0 4px 14px rgba(31, 42, 36, .06);
  --ombre-forte: 0 6px 24px rgba(31, 42, 36, .12);
  --rayon: 14px;
}

* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }
body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background: var(--fond);
  color: var(--texte);
}
h1, h2, h3 { font-family: "Fraunces", Georgia, serif; font-weight: 600; letter-spacing: -.01em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- En-tête ---------- */
header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 2rem;
  padding: .9rem 2rem;
  background: rgba(255, 253, 249, .88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--ligne);
}
header h1 { margin: 0; font-size: 1.35rem; display: flex; align-items: center; gap: .55rem; }
header h1::before {
  content: "⌂"; display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 1.2rem; font-family: "Inter", sans-serif;
}
nav { display: flex; gap: .25rem; background: var(--fond); padding: .25rem; border-radius: 999px; }
nav button {
  border: none; background: transparent; color: var(--doux);
  padding: .45rem 1.1rem; border-radius: 999px; font-weight: 500;
}
nav button:hover { color: var(--texte); background: transparent; }
nav button.actif { background: var(--surface); color: var(--accent-fonce); box-shadow: var(--ombre); }
.actions { margin-left: auto; display: flex; gap: .5rem; }

/* ---------- Boutons ---------- */
button, .bouton {
  font: inherit; font-size: .9rem; font-weight: 500;
  padding: .5rem .95rem; border-radius: 10px;
  border: 1px solid var(--ligne); background: var(--surface); color: var(--texte);
  cursor: pointer; transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
button:hover, .bouton:hover { border-color: #cfc7b7; background: #fff; }
button:active { transform: translateY(1px); }
#btn-ajouter, #btn-enregistrer { background: var(--accent); border-color: var(--accent); color: #fff; }
#btn-ajouter:hover, #btn-enregistrer:hover { background: var(--accent-fonce); border-color: var(--accent-fonce); }
button.discret { background: transparent; border: 1px dashed #cfc7b7; color: var(--doux); }
button.discret:hover { color: var(--texte); border-color: var(--doux); }
button.danger { background: transparent; color: var(--danger); border-color: transparent; }
button.danger:hover { background: #fbecec; border-color: transparent; }

/* ---------- États (sauvegarde, OneDrive) ---------- */
.actions { align-items: center; }
#etat-sauvegarde, #etat-onedrive { font-size: .82rem; color: var(--doux); margin-right: .4rem; display: inline-flex; align-items: center; gap: .4rem; }
#etat-sauvegarde.ok { color: var(--accent); }
#etat-sauvegarde.erreur { color: var(--danger); font-weight: 500; }
#etat-onedrive a { color: inherit; font-weight: 500; }
.pastille { width: 8px; height: 8px; border-radius: 50%; background: #c9c2b4; display: inline-block; }
.pastille.verte { background: #3d9a6a; }
.pastille.rouge { background: var(--danger); }
.erreur-chargement { max-width: 560px; margin: 3rem auto; }
.erreur-chargement code { background: #efebe3; padding: .05rem .35rem; border-radius: 5px; }

/* ---------- Contenu ---------- */
main { padding: 1.6rem 2rem 3rem; max-width: 1304px; margin: 0 auto; }
main h2 { font-size: 1.25rem; margin: 2rem 0 .8rem; }

.filtres {
  display: flex; flex-wrap: wrap; gap: .6rem; align-items: center;
  margin-bottom: 1.4rem;
}
.filtres input, .filtres select, dialog input, dialog select, dialog textarea {
  font: inherit; font-size: .92rem; color: var(--texte);
  padding: .6rem .8rem; border: 1px solid var(--ligne); border-radius: 10px;
  background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
.filtres input:focus, .filtres select:focus, dialog input:focus, dialog select:focus, dialog textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-clair);
}
#recherche {
  flex: 1; min-width: 260px; padding-left: 2.3rem;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236f766f' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='m14 14-3.2-3.2'/%3E%3C/svg%3E") no-repeat .8rem center;
}
#compteur { color: var(--doux); font-size: .88rem; margin-left: .3rem; }

.grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 1rem; }
.carte {
  background: var(--surface); border: 1px solid var(--ligne);
  border-radius: var(--rayon); padding: 1.1rem 1.2rem; box-shadow: var(--ombre);
}

/* Cartes objets */
.objet {
  cursor: pointer; display: flex; flex-direction: column; gap: .15rem;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.objet:hover { transform: translateY(-2px); box-shadow: var(--ombre-forte); border-color: #d8d0c0; }
.objet .tete { display: flex; gap: .8rem; align-items: flex-start; margin-bottom: .35rem; }
.icone {
  flex: none; width: 40px; height: 40px; border-radius: 11px;
  display: grid; place-items: center; font-size: 1.2rem;
  background: var(--teinte, var(--accent-clair));
}
.objet h3 { margin: 0; font-family: "Inter", sans-serif; font-size: 1rem; font-weight: 600; line-height: 1.3; }
.objet .sous { color: var(--doux); font-size: .86rem; }
.objet .cat { font-size: .78rem; color: var(--doux); text-transform: uppercase; letter-spacing: .04em; margin-top: .1rem; }
.etiquettes { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: auto; padding-top: .8rem; }
.etiquette {
  font-size: .74rem; font-weight: 500; padding: .2rem .55rem; border-radius: 999px;
  background: var(--accent-clair); color: var(--accent-fonce);
}
.etiquette.alerte { background: var(--ambre-clair); color: #8a5214; }
.etiquette.gris { background: #efebe3; color: var(--doux); }

/* Pièces */
.piece h3 { margin: 0 0 .7rem; font-size: 1.1rem; display: flex; justify-content: space-between; align-items: baseline; }
.piece h3 small {
  font-family: "Inter", sans-serif; font-size: .75rem; font-weight: 600;
  background: var(--accent-clair); color: var(--accent-fonce);
  padding: .15rem .55rem; border-radius: 999px;
}
.piece ul { margin: 0; padding: 0; list-style: none; font-size: .9rem; }
.piece li { padding: .35rem 0; border-top: 1px solid var(--ligne); cursor: pointer; }
.piece li:first-child { border-top: none; }
.piece li:hover { color: var(--accent); }
.piece li.vide { color: var(--doux); cursor: default; }

/* Maison */
#fiche-maison { padding: 1.6rem 1.8rem; background: linear-gradient(135deg, #fffdf9 0%, #eef3ee 100%); }
#fiche-maison h2 { margin: 0; font-size: 1.7rem; }
.docs { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--ligne); border-radius: var(--rayon); box-shadow: var(--ombre); overflow: hidden; }
.docs li { display: flex; align-items: center; gap: .8rem; padding: .7rem 1rem; border-top: 1px solid var(--ligne); }
.docs li:first-child { border-top: none; }
.docs li:hover { background: #faf7f1; }
.docs .type {
  flex: none; min-width: 92px; text-align: center;
  font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  padding: .2rem .5rem; border-radius: 6px; background: #efebe3; color: var(--doux);
}

/* ---------- Dialogues ---------- */
dialog {
  border: none; border-radius: 18px; padding: 1.6rem 1.8rem;
  max-width: 780px; width: 94vw; max-height: 90vh;
  background: var(--surface); color: var(--texte); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog[open] { animation: entree .18s ease-out; }
@keyframes entree { from { opacity: 0; transform: translateY(8px) scale(.98); } }
dialog::backdrop { background: rgba(25, 35, 30, .45); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 1rem; font-size: 1.45rem; }
dialog h3 { font-size: 1rem; margin: 1.4rem 0 .6rem; }
dialog h3 small { font-family: "Inter", sans-serif; font-weight: 400; color: var(--doux); }

.fiche .entete { display: flex; gap: 1rem; align-items: center; margin-bottom: .4rem; }
.fiche .entete .icone { width: 52px; height: 52px; font-size: 1.6rem; border-radius: 14px; }
.fiche .entete h2 { margin: 0; }
.fiche .entete .sous { color: var(--doux); }
.fiche dl {
  display: grid; grid-template-columns: 150px 1fr; gap: 0; margin: 1rem 0 0;
  border: 1px solid var(--ligne); border-radius: 12px; overflow: hidden;
}
.fiche dt, .fiche dd { padding: .55rem .9rem; border-top: 1px solid var(--ligne); }
.fiche dt:first-of-type, .fiche dd:first-of-type { border-top: none; }
.fiche dt { color: var(--doux); font-size: .86rem; background: #faf7f1; }
.fiche dd { margin: 0; }
#fiche-maison dl { background: rgba(255,255,255,.7); }

.champs { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem 1rem; }
dialog label { display: flex; flex-direction: column; gap: .3rem; font-size: .8rem; font-weight: 500; color: var(--doux); }
label.large { margin-top: .8rem; }
.ligne-doc { display: grid; grid-template-columns: 120px 1fr 2fr auto; gap: .5rem; margin-bottom: .5rem; }
.ligne-doc button { padding: .4rem .7rem; }
.pied { display: flex; gap: .5rem; margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--ligne); }
.espace { flex: 1; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  header { flex-wrap: wrap; gap: .8rem; padding: .8rem 1rem; }
  .actions { margin-left: 0; }
  main { padding: 1.2rem 1rem 2rem; }
  .actions { flex-wrap: wrap; }
}
@media (max-width: 600px) {
  .champs, .ligne-doc { grid-template-columns: 1fr; }
  .fiche dl { grid-template-columns: 1fr; }
  .fiche dd { border-top: none; padding-top: 0; }
}

/* ---------- Pages simples (connexion, erreurs) ---------- */
.page-simple { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.boite { width: 100%; max-width: 420px; padding: 2rem; }
.boite code { background: #efebe3; padding: .05rem .35rem; border-radius: 5px; word-break: break-all; }
.form-connexion { display: flex; flex-direction: column; gap: 1rem; }
.form-connexion .logo {
  width: 52px; height: 52px; border-radius: 14px; margin: 0 auto;
  display: grid; place-items: center; background: var(--accent); color: #fff; font-size: 1.6rem;
}
.form-connexion h2 { text-align: center; margin: 0 0 .4rem; }
.form-connexion label { display: flex; flex-direction: column; gap: .35rem; font-size: .82rem; font-weight: 500; color: var(--doux); }
.form-connexion input {
  font: inherit; padding: .7rem .85rem; border: 1px solid var(--ligne); border-radius: 10px; background: #fff; outline: none;
}
.form-connexion input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-clair); }
.form-connexion button { background: var(--accent); border-color: var(--accent); color: #fff; padding: .75rem; margin-top: .3rem; }
.form-connexion button:hover { background: var(--accent-fonce); }
.message-erreur { margin: 0; padding: .6rem .8rem; border-radius: 10px; background: #fbecec; color: var(--danger); font-size: .88rem; }
