:root {
  --noir: #02090f;
  --lime: #cbfe01;
  --orange: #ff5100;
  --gris: #f4f2ee;
  --bord: #e3e3df;
  --texte: #1a1a1a;
  --doux: #6b6b6b;
}

* { box-sizing: border-box; }

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

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------------------------------------------------------- connexion */
.connexion {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.connexion form {
  background: #fff;
  border: 1px solid var(--bord);
  border-radius: 14px;
  padding: 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(2, 9, 15, 0.07);
}
.monogramme {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px; height: 46px;
  border-radius: 10px;
  background: var(--lime);
  font-weight: 800;
  margin-bottom: 18px;
}

/* ------------------------------------------------------------- charpente */
.appli { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }

.lateral {
  background: var(--noir);
  color: #fff;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.lateral h1 { font-size: 15px; margin: 0 0 22px; display: flex; align-items: center; gap: 10px; }
.lateral button {
  background: none; border: 0; color: #cfcfcf;
  text-align: left; padding: 9px 12px; border-radius: 8px;
  cursor: pointer; width: 100%;
}
.lateral button:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.lateral button.actif { background: var(--lime); color: var(--noir); font-weight: 700; }
.lateral .pousse { margin-top: auto; }
.lateral .groupe { font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: #7d7d7d; margin: 16px 12px 6px; }

.principal { display: flex; flex-direction: column; min-width: 0; }

.barre {
  position: sticky; top: 0; z-index: 5;
  background: #fff; border-bottom: 1px solid var(--bord);
  padding: 12px 24px; display: flex; align-items: center; gap: 12px;
}
.barre .titre { font-weight: 700; margin-right: auto; }

/* Les formulaires se lisent mieux en colonne etroite. La bibliotheque
   d'images, elle, profite de toute la largeur : elle s'en exempte. */
.contenu { padding: 24px; max-width: 980px; }
.contenu.large { max-width: none; }

/* --------------------------------------------------------------- boutons */
.btn {
  border: 1px solid var(--noir); background: var(--noir); color: #fff;
  padding: 8px 16px; border-radius: 8px; cursor: pointer; font-weight: 600;
}
.btn:hover { opacity: .88; }
.btn[disabled] { opacity: .4; cursor: not-allowed; }
.btn.clair { background: #fff; color: var(--noir); }
.btn.lime { background: var(--lime); border-color: var(--lime); color: var(--noir); }
.btn.petit { padding: 4px 10px; font-size: 13px; border-radius: 6px; }
.btn.danger { background: #fff; color: #b00020; border-color: #e6c3c9; }

/* ---------------------------------------------------------------- blocs */
.carte {
  background: #fff; border: 1px solid var(--bord);
  border-radius: 12px; padding: 20px; margin-bottom: 16px;
}
.carte > h3 { margin: 0 0 4px; font-size: 16px; }
.carte > .aide { color: var(--doux); font-size: 13px; margin: 0 0 16px; }

.champ { margin-bottom: 14px; }
.champ label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
/* Tous les champs de saisie sauf les cases a cocher : viser les types un par
   un laissait sans style ceux ajoutes plus tard (password, email...). */
.champ input:not([type="checkbox"]):not([type="radio"]),
.champ textarea, .champ select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--bord);
  border-radius: 8px; background: #fff;
}
.champ textarea { min-height: 86px; resize: vertical; }
.champ input:focus, .champ textarea:focus, .champ select:focus {
  outline: 2px solid var(--lime); outline-offset: -1px; border-color: var(--lime);
}
.champ .note { font-size: 12px; color: var(--doux); margin-top: 4px; }

.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 700px) { .duo { grid-template-columns: 1fr; } .appli { grid-template-columns: 1fr; } }

.ligne { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.ligne input, .ligne textarea { flex: 1; }

.badge {
  display: inline-block; background: var(--gris); border-radius: 999px;
  padding: 2px 10px; font-size: 12px; color: var(--doux);
}
.badge.ok { background: #e7f7d4; color: #3d6b00; }

/* --------------------------------------------------------------- projets */
.projet-entete {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--bord);
  border-radius: 10px; background: #fff; margin-bottom: 8px;
}
.projet-entete .num {
  width: 26px; height: 26px; border-radius: 6px; background: var(--gris);
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.projet-entete .nom { font-weight: 600; margin-right: auto; }

/* ---------------------------------------------------------------- alerte */
.alerte {
  padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px;
}
.alerte.err { background: #fdecef; color: #8c0018; border: 1px solid #f3c6ce; }
.alerte.ok { background: #eef8dd; color: #3d6b00; border: 1px solid #d3e9ab; }
.alerte.info { background: #eef2f7; color: #24425f; border: 1px solid #ccd9e6; }

.vide { color: var(--doux); font-style: italic; }

/* ------------------------------------------------------- bascule de mode */
.bascule { display: inline-flex; background: var(--gris); border-radius: 9px; padding: 3px; }
.bascule button {
  border: 0; background: none; padding: 6px 14px; border-radius: 7px;
  cursor: pointer; font-weight: 600; font-size: 13px; color: var(--doux);
}
.bascule button.actif { background: #fff; color: var(--noir); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.barre select {
  padding: 7px 10px; border: 1px solid var(--bord); border-radius: 8px; background: #fff;
}

/* ------------------------------------------------------------- apercu */
#zone-apercu { flex: 1; min-height: 0; }
#apercu { width: 100%; height: calc(100vh - 58px); border: 0; display: block; background: #fff; }

/* ------------------------------------------------------------- modale */
.modale {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(2, 9, 15, .55);
  display: grid; place-items: center; padding: 24px;
}
.modale > div {
  background: #fff; border-radius: 14px; padding: 22px;
  max-width: 760px; width: 100%; max-height: 82vh; overflow: auto;
}
.grille-images {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px; margin: 16px 0;
}
.grille-images button {
  border: 2px solid var(--bord); background: #fff; border-radius: 10px;
  padding: 6px; cursor: pointer; text-align: center;
}
.grille-images button:hover { border-color: var(--lime); }
.grille-images button.actif { border-color: var(--orange); }
.grille-images img { width: 100%; height: 86px; object-fit: cover; border-radius: 6px; display: block; }
.grille-images span { font-size: 11px; color: var(--doux); display: block; margin-top: 5px; word-break: break-all; }

/* ---------- gestionnaire d'images ---------- */
.onglets-images { margin-bottom: 16px; display: inline-flex; flex-wrap: wrap; }

.grille-medias {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px; margin: 16px 0;
}
.media {
  border: 1px solid var(--bord); border-radius: 10px; background: #fff;
  padding: 10px; display: flex; flex-direction: column; gap: 4px;
}
/* Un liseré vert signale d'un coup d'œil ce qui sert réellement dans le site. */
.media.employee { border-left: 3px solid var(--lime); }
/* La vignette est un bouton : elle ouvre la vue agrandie. */
.media-vue {
  border: 0; padding: 0; background: none; cursor: zoom-in; display: block;
  width: 100%; border-radius: 6px;
}
.media-vue:hover img { outline: 2px solid var(--lime); outline-offset: -2px; }
.media img {
  width: 100%; height: 110px; object-fit: contain; background: #f4f6f8;
  border-radius: 6px; display: block;
}
.media-nom { font-size: 12px; font-weight: 600; word-break: break-all; }
.media-info { font-size: 11px; color: var(--doux); }
.media-usage {
  font-size: 11px; color: var(--doux); font-style: italic;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.media.employee .media-usage { color: #3d7a00; font-style: normal; }
.media-actions {
  display: flex; flex-wrap: wrap; gap: 5px; margin-top: auto; padding-top: 6px;
}
/* Quatre boutons ne tiennent pas sur une ligne dans une vignette etroite :
   ils passaient hors de la carte. Ils s'enroulent, et « Supprimer » — le seul
   irreversible — prend sa propre ligne, ce qui le rend aussi moins facile a
   cliquer par erreur. */
.media-actions .btn {
  flex: 1 1 auto; min-width: 0; padding: 4px 8px; font-size: 12px;
  text-align: center; text-decoration: none; white-space: nowrap;
}
/* Le bouton de téléchargement ne porte qu'une flèche : il ne doit pas
   s'étirer comme les autres. */
.media-actions a.btn { flex: 0 0 auto; }
.media-actions .btn.danger { flex: 1 1 100%; }

/* ---------- vue agrandie ---------- */
.visionneuse-corps { text-align: left; }
.visionneuse-corps > img {
  width: 100%; max-height: 60vh; object-fit: contain;
  background: #f4f6f8; border-radius: 10px; display: block;
}
.visionneuse-usages {
  margin: 10px 0 0; padding-left: 18px; font-size: 13px; color: #3d7a00;
}

.emplacements { display: grid; gap: 14px; }
.emplacement {
  display: grid; grid-template-columns: 150px 1fr; gap: 14px;
  align-items: start; padding: 12px; border: 1px solid var(--bord);
  border-radius: 10px;
}
.emplacement-vue {
  width: 100%; height: 110px; object-fit: contain; background: #f4f6f8;
  border-radius: 6px; display: block;
}
.emplacement-corps .champ { margin: 8px 0 10px; }
@media (max-width: 720px) {
  .emplacement { grid-template-columns: 1fr; }
}

/* ---------- sous-menu des projets ---------- */
/* Replié par défaut : neuf projets de plus dans la colonne noieraient les
   autres rubriques. Il s'ouvre quand on est dans la vue Projets. */
.sous-menu { display: none; margin: 2px 0 6px; }
.sous-menu.ouvert { display: block; }
.sous-menu button {
  font-size: 13px; padding: 6px 12px 6px 26px; color: #9d9d9d;
  position: relative; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis;
}
.sous-menu button::before {
  content: ""; position: absolute; left: 14px; top: 50%;
  width: 4px; height: 4px; border-radius: 50%; background: #5a5a5a;
  transform: translateY(-50%);
}
.sous-menu button.actif {
  background: rgba(203, 254, 1, .15); color: var(--lime); font-weight: 600;
}
.sous-menu button.actif::before { background: var(--lime); }

/* ---------- mise en page : blocs masqués ---------- */
.projet-entete.masque { opacity: .55; border-style: dashed; }
.projet-entete.masque .nom { text-decoration: line-through; }

/* ---------- vignette-bouton d-un logo ---------- */
.vignette-logo {
  flex: 0 0 42px; width: 42px; height: 42px; padding: 3px;
  border: 1px solid var(--bord); border-radius: 8px; background: #fff;
  cursor: pointer;
}
.vignette-logo:hover { border-color: var(--lime); }
.vignette-logo img { width: 100%; height: 100%; object-fit: contain; display: block; }

/* ---------- bibliothèque : colonne des dossiers + grille ---------- */
.bibliotheque { display: grid; grid-template-columns: 190px 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .bibliotheque { grid-template-columns: 1fr; } }

.dossiers {
  background: #fff; border: 1px solid var(--bord); border-radius: 12px;
  padding: 8px; display: flex; flex-direction: column; gap: 2px;
  position: sticky; top: 70px;
}
.dossiers button {
  display: flex; align-items: center; gap: 8px; width: 100%;
  border: 0; background: none; cursor: pointer; text-align: left;
  padding: 7px 10px; border-radius: 8px; font-size: 14px;
}
.dossiers button:hover { background: var(--gris); }
.dossiers button.actif { background: var(--noir); color: #fff; font-weight: 600; }
.dossiers .nom { margin-right: auto; overflow: hidden; text-overflow: ellipsis; }
.dossiers .compte { font-size: 11px; color: var(--doux); }
.dossiers button.actif .compte { color: #b9b9b9; }
.dossiers .nouveau {
  margin-top: 6px; border-top: 1px solid var(--bord); border-radius: 0 0 8px 8px;
  color: var(--doux); font-weight: 600;
}

/* Le menu de rangement d-une vignette. */
.media select {
  width: 100%; margin-top: 4px; padding: 4px 6px; font-size: 12px;
  border: 1px solid var(--bord); border-radius: 6px; background: #fff;
}
/* Une image du thème est citée par le gabarit, pas par le contenu : on la
   distingue pour éviter de la ranger ailleurs sans y penser. */
.media.theme { border-left: 3px solid var(--orange); }
.media.theme .media-usage { color: var(--orange); font-style: normal; }
