/* Admin Topo Gigio — reprend la DA du site public.
   Pensé tablette/mobile d'abord : cibles tactiles ≥ 44 px, champs à 16 px
   (en dessous, iOS zoome automatiquement au focus), zones sûres respectées. */
:root {
  --bg: #0e0d0c;
  --bg-alt: #171512;
  --card: #201d19;
  --card-hover: #29251f;
  --primary: #e11d2a;
  --primary-light: #ff4b57;
  --green: #1f9d55;
  --green-light: #34c77b;
  --accent: #f0b429;
  --text: #f6f3ee;
  --muted: #b3aca1;
  --dim: #7a7268;
  --border: #302b25;
  --font-heading: 'Playfair Display', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 14px;
  --radius-sm: 10px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

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

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overscroll-behavior: none;
}

button { font-family: inherit; cursor: pointer; border: none; }
input, textarea { font-family: inherit; font-size: 16px; }

/* ---------- Connexion ---------- */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  padding-top: calc(1.5rem + var(--sat));
  background: radial-gradient(ellipse at top, rgba(225, 29, 42, 0.13), transparent 60%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.4rem 2rem;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}
.login-mascotte { height: 96px; width: auto; margin: 0 auto 1.2rem; }
.login-card h1 { font-family: var(--font-heading); font-size: 1.6rem; margin-bottom: 0.3rem; }
.login-card .sub { color: var(--dim); font-size: 0.88rem; margin-bottom: 1.8rem; }

.champ { text-align: left; margin-bottom: 1rem; }
.champ label {
  display: block; font-size: 0.75rem; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 0.4rem;
}
.champ input {
  width: 100%; padding: 0.85rem 0.9rem;
  background: var(--bg-alt); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  transition: border-color 0.2s;
}
.champ input:focus { outline: none; border-color: var(--primary); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  padding: 0.8rem 1.4rem; border-radius: 50px;
  font-size: 0.92rem; font-weight: 600; white-space: nowrap;
  transition: transform 0.15s, background 0.2s, opacity 0.2s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-primary:hover:not(:disabled) { background: var(--primary-light); }
.btn-vert { background: var(--green); color: #fff; }
.btn-vert:hover:not(:disabled) { background: var(--green-light); }
.btn-ligne { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ligne:hover:not(:disabled) { background: var(--card-hover); border-color: var(--dim); }
.btn-sm { padding: 0.6rem 1rem; font-size: 0.85rem; min-height: 40px; }
.btn-xs { padding: 0.45rem 0.7rem; font-size: 0.76rem; border-radius: 8px; min-height: 34px; }

.erreur {
  background: rgba(225, 29, 42, 0.12); border: 1px solid rgba(225, 29, 42, 0.4);
  color: #ff9aa2; padding: 0.7rem 0.9rem; border-radius: var(--radius-sm);
  font-size: 0.85rem; margin-bottom: 1rem; text-align: left;
}

/* ---------- Application ---------- */
.app { display: none; flex-direction: column; height: 100vh; height: 100dvh; }
.app.actif { display: flex; }

.topbar {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.7rem 1.2rem; padding-top: calc(0.7rem + var(--sat));
  background: var(--bg-alt); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar-mascotte { height: 38px; width: auto; flex-shrink: 0; }
.topbar-txt { min-width: 0; }
.topbar-titre { font-family: var(--font-heading); font-size: 1.1rem; line-height: 1.2; }
.topbar-sous { font-size: 0.72rem; color: var(--dim); }
.topbar-actions { margin-left: auto; display: flex; gap: 0.5rem; align-items: center; }

/* Bandeau de brouillon */
.bandeau {
  display: none; align-items: center; gap: 0.9rem;
  padding: 0.75rem 1.2rem;
  background: linear-gradient(90deg, rgba(240, 180, 41, 0.14), rgba(240, 180, 41, 0.04));
  border-bottom: 1px solid rgba(240, 180, 41, 0.3);
  flex-shrink: 0; flex-wrap: wrap;
}
.bandeau.actif { display: flex; }
/* Photos déposées sans placement : ton neutre, pas d'alerte. */
.bandeau.bandeau-photos {
  background: linear-gradient(90deg, rgba(31, 157, 85, 0.14), rgba(31, 157, 85, 0.04));
  border-bottom-color: rgba(31, 157, 85, 0.3);
}
.bandeau.bandeau-photos .bandeau-texte { color: var(--green-light); }
.bandeau-info { min-width: 0; }
.bandeau-texte { font-size: 0.86rem; color: var(--accent); font-weight: 600; }
.bandeau-fichiers {
  font-size: 0.78rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bandeau-actions { margin-left: auto; display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Fil de discussion */
.fil { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 1.5rem 1.2rem; }
.fil-inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 1.1rem; }

.accueil { text-align: center; padding: 2rem 0.5rem; }
.accueil h2 { font-family: var(--font-heading); font-size: 1.5rem; margin-bottom: 0.6rem; }
.accueil p { color: var(--muted); font-size: 0.94rem; max-width: 480px; margin: 0 auto 1.8rem; }
.exemples { display: flex; flex-wrap: wrap; gap: 0.6rem; justify-content: center; }
.exemple {
  background: var(--card); border: 1px solid var(--border); color: var(--muted);
  padding: 0.7rem 1rem; border-radius: 50px; font-size: 0.84rem;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.exemple:hover { background: var(--card-hover); color: var(--text); border-color: var(--dim); }

.msg { display: flex; gap: 0.8rem; align-items: flex-start; }
.msg-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-size: 0.9rem; font-weight: 700; flex-shrink: 0;
}
.msg-moi .msg-avatar { background: var(--primary); color: #fff; }
.msg-bot .msg-avatar { background: var(--card); border: 1px solid var(--border); }
.msg-bot .msg-avatar img { width: 24px; height: 24px; }
.msg-corps {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.85rem 1.1rem; font-size: 0.95rem;
  white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0;
}
.msg-moi { flex-direction: row-reverse; }
.msg-moi .msg-corps { background: rgba(225, 29, 42, 0.12); border-color: rgba(225, 29, 42, 0.3); }
.msg-erreur .msg-corps { background: rgba(225, 29, 42, 0.1); border-color: rgba(225, 29, 42, 0.4); color: #ff9aa2; }

.msg-images { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.5rem; }
.msg-images:last-child { margin-bottom: 0; }
.msg-images img {
  max-width: 190px; max-height: 190px; width: auto; height: auto;
  border-radius: var(--radius-sm); border: 1px solid var(--border); display: block;
}

/* Attente */
.pense { display: flex; gap: 0.35rem; padding: 0.4rem 0; }
.pense span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: rebond 1.3s infinite ease-in-out; }
.pense span:nth-child(2) { animation-delay: 0.18s; }
.pense span:nth-child(3) { animation-delay: 0.36s; }
@keyframes rebond {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}
.pense-note { font-size: 0.8rem; color: var(--dim); margin-top: 0.3rem; }

/* ---------- Saisie ---------- */
.saisie-zone {
  border-top: 1px solid var(--border); background: var(--bg-alt);
  padding: 0.9rem 1.2rem calc(1rem + var(--sab));
  flex-shrink: 0;
}
.saisie-inner { max-width: 760px; margin: 0 auto; }

.jointes { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.6rem; }
.jointes:empty { display: none; }
.jointe {
  display: flex; align-items: center; gap: 0.5rem;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 50px; padding: 0.3rem 0.35rem 0.3rem 0.3rem;
  font-size: 0.8rem; color: var(--muted); max-width: 220px;
}
.jointe img { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.jointe span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.jointe button {
  background: transparent; color: var(--dim); font-size: 1.15rem; line-height: 1;
  padding: 0 0.35rem; flex-shrink: 0;
}
.jointe button:hover { color: var(--primary-light); }
.jointe-attente { padding: 0.5rem 0.9rem; color: var(--accent); }

.saisie-boite {
  display: flex; gap: 0.4rem; align-items: flex-end;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.45rem;
  transition: border-color 0.2s;
}
.saisie-boite:focus-within { border-color: var(--primary); }
.saisie-boite textarea {
  flex: 1; background: transparent; border: none; color: var(--text);
  resize: none; max-height: 140px; line-height: 1.5; padding: 0.55rem 0.3rem;
}
.saisie-boite textarea:focus { outline: none; }
.btn-joindre {
  width: 44px; height: 44px; border-radius: 50%;
  background: transparent; color: var(--muted);
  display: grid; place-items: center; flex-shrink: 0;
  transition: background 0.2s, color 0.2s;
}
.btn-joindre:hover { background: var(--card-hover); color: var(--text); }
.envoyer {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: grid; place-items: center; flex-shrink: 0;
  font-size: 1.15rem; transition: background 0.2s;
}
.envoyer:hover:not(:disabled) { background: var(--primary-light); }
.envoyer:disabled { opacity: 0.4; cursor: not-allowed; }
.saisie-aide { font-size: 0.75rem; color: var(--dim); margin-top: 0.55rem; text-align: center; }

/* ---------- Glisser-déposer ---------- */
.depot {
  display: none; position: fixed; inset: 0; z-index: 70;
  background: rgba(14, 13, 12, 0.9); place-items: center;
}
.depot.actif { display: grid; }
.depot-carte {
  border: 2px dashed var(--accent); border-radius: var(--radius);
  padding: 3rem 4rem; text-align: center; font-size: 1.15rem;
  color: var(--accent); font-weight: 600; line-height: 2;
}

/* ---------- Médiathèque ---------- */
.panneau { display: none; position: fixed; inset: 0; z-index: 55; }
.panneau.actif { display: block; }
.panneau-fond { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.65); }
.panneau-carte {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(440px, 100%);
  background: var(--bg-alt); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding-top: var(--sat); padding-bottom: var(--sab);
}
.panneau-tete {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.2rem 0.8rem; border-bottom: 1px solid var(--border);
}
.panneau-tete h3 { font-family: var(--font-heading); font-size: 1.25rem; }
.panneau-actions { padding: 0.9rem 1.2rem; border-bottom: 1px solid var(--border); }
.panneau-corps { flex: 1; overflow-y: auto; padding: 1.1rem 1.2rem; }
.panneau-vide { color: var(--dim); font-size: 0.88rem; text-align: center; padding: 2rem 0.5rem; }

.media {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 1rem;
}
.media img { width: 100%; height: 150px; object-fit: cover; display: block; background: var(--bg); }
.media-nom { font-weight: 600; font-size: 0.9rem; padding: 0.7rem 0.8rem 0.1rem; }
.media-dim { font-size: 0.75rem; color: var(--dim); padding: 0 0.8rem 0.6rem; }
.media-actions { display: flex; gap: 0.4rem; padding: 0 0.8rem 0.8rem; flex-wrap: wrap; }

/* ---------- Modale ---------- */
.modale {
  display: none; position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.72); place-items: center; padding: 1.5rem; z-index: 80;
}
.modale.actif { display: grid; }
.modale-carte {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.8rem; max-width: 460px; width: 100%;
}
.modale-carte h3 { font-family: var(--font-heading); font-size: 1.25rem; margin-bottom: 0.7rem; }
.modale-carte p { color: var(--muted); font-size: 0.92rem; margin-bottom: 1.4rem; }
.modale-input {
  width: 100%; padding: 0.75rem 0.9rem; margin: -0.6rem 0 1.4rem;
  background: var(--bg-alt); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
}
.modale-input:focus { outline: none; border-color: var(--primary); }
.modale-actions { display: flex; gap: 0.7rem; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(1.6rem + var(--sab)); left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--card); border: 1px solid var(--border);
  border-left: 3px solid var(--green); border-radius: var(--radius-sm);
  padding: 0.85rem 1.3rem; font-size: 0.9rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  /* Masqué hors état actif : translateY seul ne suffit pas à sortir de l'écran
     un élément de faible hauteur. */
  visibility: hidden; opacity: 0;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s, visibility 0.25s;
  z-index: 90; max-width: 90vw;
}
.toast.actif { transform: translateX(-50%) translateY(0); visibility: visible; opacity: 1; }

/* ---------- Tablette ---------- */
@media (max-width: 780px) {
  .topbar-actions .lbl { display: none; }
  .topbar-actions .btn-sm { padding: 0.6rem 0.85rem; }
}

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .topbar { padding: 0.6rem 0.9rem; padding-top: calc(0.6rem + var(--sat)); gap: 0.6rem; }
  .topbar-mascotte { height: 32px; }
  .topbar-titre { font-size: 1rem; }
  .topbar-sous { display: none; }
  .topbar-actions { gap: 0.35rem; }

  .fil { padding: 1.1rem 0.9rem; }
  .saisie-zone { padding: 0.8rem 0.9rem calc(0.9rem + var(--sab)); }
  .bandeau { padding: 0.7rem 0.9rem; }
  .bandeau-info { width: 100%; }
  .bandeau-actions { width: 100%; margin-left: 0; }
  .bandeau-actions .btn { flex: 1; }

  .msg { gap: 0.55rem; }
  .msg-corps { padding: 0.75rem 0.9rem; font-size: 0.92rem; }
  .msg-images img { max-width: 140px; max-height: 140px; }
  .accueil { padding: 1.2rem 0.2rem; }
  .exemple { font-size: 0.8rem; padding: 0.6rem 0.85rem; }

  /* La médiathèque devient une feuille qui monte du bas : plus naturel au pouce. */
  .panneau-carte {
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%; height: 88dvh;
    border-left: none; border-top: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
  }
  .media img { height: 190px; }
  .depot-carte { padding: 2rem; font-size: 1rem; }
  .modale-carte { padding: 1.4rem; }
  .modale-actions .btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
