/* JI Discord Bridge — widget de discussion (thème sombre, responsive) */

.jidb-widget {
  --jidb-bg: #313338;
  --jidb-bg-2: #2b2d31;
  --jidb-bg-3: #1e1f22;
  --jidb-line: #3f4147;
  --jidb-text: #dbdee1;
  --jidb-muted: #949ba4;
  --jidb-accent: #5865f2;      /* blurple Discord */
  --jidb-visitor: #3ba55d;     /* vert : messages venus du site */
  --jidb-danger: #f23f42;
  --jidb-radius: 12px;
  --jidb-height: 520px;

  display: flex;
  flex-direction: column;
  height: var(--jidb-height);
  max-height: 80vh;
  background: var(--jidb-bg);
  color: var(--jidb-text);
  border: 1px solid var(--jidb-line);
  border-radius: var(--jidb-radius);
  overflow: hidden;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
}
.jidb-widget * { box-sizing: border-box; }

/* En-tête */
.jidb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: var(--jidb-bg-2);
  border-bottom: 1px solid var(--jidb-line);
  flex: 0 0 auto;
}
.jidb-header__brand {
  font-weight: 700;
  letter-spacing: .2px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.jidb-header__brand .fa-discord { color: var(--jidb-accent); }
.jidb-header__status {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--jidb-muted);
  transition: background .3s ease;
}
.jidb-header__status[data-state="ok"] { background: var(--jidb-visitor); }
.jidb-header__status[data-state="error"] { background: var(--jidb-danger); }

/* Annonces */
.jidb-announce {
  flex: 0 0 auto;
  padding: 10px 16px;
  background: rgba(88, 101, 242, .12);
  border-bottom: 1px solid var(--jidb-line);
  font-size: 14px;
  max-height: 30%;
  overflow-y: auto;
}
.jidb-announce__item { padding: 4px 0; }
.jidb-announce__item i { color: var(--jidb-accent); margin-right: 6px; }

/* Bouton « anciens messages » */
.jidb-more { flex: 0 0 auto; text-align: center; padding: 8px; }
.jidb-more__btn {
  background: none; border: 0; color: var(--jidb-muted);
  cursor: pointer; font-size: 13px !important;
    line-height: 1.35 !important; padding: 4px 10px; border-radius: 6px;
}
.jidb-more__btn:hover { color: var(--jidb-text); background: var(--jidb-bg-2); }
.jidb-more[hidden] { display: none; }

/* Flux de messages */
.jidb-stream {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 8px 4px 8px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--jidb-bg-3) transparent;
}
.jidb-stream::-webkit-scrollbar { width: 8px; }
.jidb-stream::-webkit-scrollbar-thumb { background: var(--jidb-bg-3); border-radius: 8px; }
.jidb-stream:focus-visible { outline: 2px solid var(--jidb-accent); outline-offset: -2px; }

.jidb-loading, .jidb-empty {
  color: var(--jidb-muted); text-align: center; padding: 24px; font-size: 14px;
}

/* Message */
.jidb-msg {
  display: flex;
  gap: 12px;
  padding: 6px 16px;
  animation: jidb-in .18s ease;
}
.jidb-msg:hover { background: rgba(0, 0, 0, .12); }
.jidb-widget .jidb-msg__avatar {
  width: 38px !important;
  height: 38px !important;
  min-width: 38px;
  max-width: 38px;
  flex: 0 0 38px;
  border-radius: 50% !important;
  object-fit: cover !important;
  aspect-ratio: 1 / 1;
  background: var(--jidb-bg-3);
  padding: 0 !important;
  border: 0 !important;
}
.jidb-msg__body { min-width: 0; flex: 1 1 auto; }
.jidb-msg__head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.jidb-msg__name { font-weight: 600; color: #f2f3f5; }
.jidb-msg__time { font-size: 11px; color: var(--jidb-muted); }
.jidb-msg__badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  padding: 1px 6px; border-radius: 4px; color: #fff;
}
.jidb-msg__text {
  white-space: pre-wrap; overflow-wrap: anywhere; color: var(--jidb-text); margin-top: 2px;
}
.jidb-msg__text a { color: #00a8fc; text-decoration: none; }
.jidb-msg__text a:hover { text-decoration: underline; }
.jidb-msg__edited { font-size: 10px; color: var(--jidb-muted); margin-left: 4px; }

/* Variante « visiteur du site » : le signe distinctif du pont site <-> Discord */
.jidb-msg--visitor { box-shadow: inset 3px 0 0 var(--jidb-visitor); }
.jidb-msg--visitor .jidb-msg__badge { background: var(--jidb-visitor); }
.jidb-msg--bot .jidb-msg__badge { background: var(--jidb-accent); }

/* Variante « vous » : messages envoyes depuis CE navigateur (teinte accent) */
.jidb-msg--mine {
  box-shadow: inset 3px 0 0 var(--jidb-accent);
  background: rgba(88, 101, 242, .08);
  background: color-mix(in srgb, var(--jidb-accent) 10%, transparent);
}
.jidb-msg--mine .jidb-msg__badge { background: var(--jidb-accent); }

/* Pièces jointes */
.jidb-att { margin-top: 6px; }
.jidb-att__img {
  max-width: min(400px, 100%); max-height: 300px; border-radius: 8px;
  display: block; cursor: zoom-in; background: var(--jidb-bg-3);
}
.jidb-att__file {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--jidb-bg-2); border: 1px solid var(--jidb-line);
  border-radius: 8px; padding: 8px 12px; color: var(--jidb-text);
  text-decoration: none; margin-top: 4px;
}
.jidb-att__file i { color: var(--jidb-accent); }

/* Réactions */
.jidb-reacts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.jidb-react {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--jidb-bg-2); border: 1px solid var(--jidb-line);
  border-radius: 8px; padding: 2px 7px; font-size: 13px !important;
    line-height: 1.35 !important;
}
.jidb-react img { width: 16px; height: 16px; vertical-align: middle; }
.jidb-react__count { color: var(--jidb-muted); font-size: 12px; }

/* Zone de saisie */
.jidb-composer {
  flex: 0 0 auto; padding: 10px 12px 12px;
  background: var(--jidb-bg-2); border-top: 1px solid var(--jidb-line);
}
.jidb-composer__pseudo {
  width: 100%; margin-bottom: 8px; padding: 7px 10px;
  background: var(--jidb-bg-3); border: 1px solid var(--jidb-line);
  border-radius: 8px; color: var(--jidb-text); font-size: 13px !important;
    line-height: 1.35 !important;
}
.jidb-composer__row { display: flex; gap: 8px; align-items: flex-end; }
.jidb-composer__input {
  flex: 1 1 auto; resize: none; max-height: 120px;
  padding: 10px 12px; background: var(--jidb-bg-3);
  border: 1px solid var(--jidb-line); border-radius: 10px;
  color: var(--jidb-text); font: inherit;
}
.jidb-composer__input:focus,
.jidb-composer__pseudo:focus { outline: none; border-color: var(--jidb-accent); }
.jidb-composer__send {
  flex: 0 0 auto; width: 44px; height: 44px; border: 0; border-radius: 10px;
  background: var(--jidb-accent); color: #fff; cursor: pointer;
  font-size: 16px; transition: filter .15s ease;
}
.jidb-composer__send:hover { filter: brightness(1.1); }
.jidb-composer__send:disabled { opacity: .5; cursor: not-allowed; }
.jidb-composer__hint { font-size: 11px; color: var(--jidb-muted); margin-top: 6px; }
.jidb-composer__hint[data-kind="error"] { color: var(--jidb-danger); }

/* Notice admin */
.jidb-notice {
  padding: 12px 16px; border: 1px dashed var(--jidb-danger);
  border-radius: 8px; color: #b71c1c; background: #fff4f4; font-size: 14px;
}

@keyframes jidb-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .jidb-msg { animation: none; } }

/* Mobile */
@media (max-width: 520px) {
  .jidb-widget { font-size: 14px; max-height: 85vh; }
  .jidb-msg { padding: 6px 12px; gap: 10px; }
  .jidb-widget .jidb-msg__avatar {
    width: 32px !important; height: 32px !important;
    min-width: 32px; max-width: 32px; flex-basis: 32px;
  }
}

/* ===== Bulle flottante (façon WidgetBot) ===== */
.jidb-launcher {
  position: fixed !important;
  bottom: 20px;
  z-index: 99999;
  width: -moz-fit-content !important;
  width: fit-content !important;   /* empeche un thème de l'etirer en pleine largeur */
  max-width: 100vw;
}
.jidb-launcher--right { right: 20px !important; left: auto !important; }
.jidb-launcher--left  { left: 20px !important; right: auto !important; }

.jidb-launcher__row {
  display: flex;                 /* pas inline-flex : evite l'espace de ligne de base */
  align-items: center;
  gap: 10px;
  line-height: 0;
  font-size: 0;
  vertical-align: bottom;
}
/* Ceinture + bretelles : le bouton reste du bon cote meme si la largeur est forcee */
.jidb-launcher--right .jidb-launcher__row { justify-content: flex-end; }
.jidb-launcher--left  .jidb-launcher__row { justify-content: flex-start; flex-direction: row-reverse; }

.jidb-launcher__bubble {
  position: relative;
  box-sizing: border-box !important;
  width: var(--jidb-fab-size, 60px) !important;
  height: var(--jidb-fab-size, 60px) !important;
  min-width: var(--jidb-fab-size, 60px) !important;
  min-height: var(--jidb-fab-size, 60px) !important;
  max-width: var(--jidb-fab-size, 60px) !important;
  max-height: var(--jidb-fab-size, 60px) !important;
  padding: 0 !important;
  margin: 0 !important;
  border: 0 !important;
  line-height: 1 !important;      /* le theme etirait le bouton en hauteur */
  font-size: 0 !important;        /* neutralise la hauteur de ligne du contenu */
  border-radius: 50%;
  background: var(--jidb-fab-bg, #5865f2);
  color: var(--jidb-fab-fg, #fff);
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}
.jidb-launcher__bubble:hover { transform: scale(1.06); filter: brightness(1.08); }
.jidb-launcher__bubble:active { transform: scale(.97); }

.jidb-launcher__icon {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: calc(var(--jidb-fab-size, 60px) * .45) !important;
  line-height: 1 !important;
  transition: opacity .15s ease, transform .2s ease;
}
.jidb-launcher__img {
  width: calc(var(--jidb-fab-size, 60px) * .62);
  height: calc(var(--jidb-fab-size, 60px) * .62);
  border-radius: 50%;
  object-fit: cover;
}
.jidb-launcher__icon--close { opacity: 0; transform: translate(-50%, -50%) rotate(-90deg); }
.jidb-launcher.is-open .jidb-launcher__icon { opacity: 0; transform: translate(-50%, -50%) rotate(90deg); }
.jidb-launcher.is-open .jidb-launcher__icon--close { opacity: 1; transform: translate(-50%, -50%) rotate(0); }

.jidb-launcher__label {
  background: #1e1f22; color: #fff;
  font-size: 14px !important; font-weight: 600; line-height: 1.3 !important;
  padding: 8px 12px; border-radius: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .3);
  white-space: nowrap;
  transition: opacity .15s ease, transform .15s ease;
}
.jidb-launcher.is-open .jidb-launcher__label { opacity: 0; transform: scale(.9); pointer-events: none; }

.jidb-launcher__badge {
  position: absolute;
  top: -3px; right: -3px;
  min-width: 20px; height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--jidb-danger, #f23f42);
  color: #fff; font-size: 12px !important; font-weight: 700; line-height: 20px !important;
  text-align: center;
  border: 2px solid #1e1f22;
  box-sizing: border-box;
  overflow: visible;
}

/* Panneau ouvert au-dessus de la bulle */
.jidb-launcher__panel {
  position: absolute;
  bottom: 74px;
  width: 384px;
  max-width: calc(100vw - 40px);
}
.jidb-launcher--right .jidb-launcher__panel { right: 0; transform-origin: bottom right; }
.jidb-launcher--left .jidb-launcher__panel { left: 0; transform-origin: bottom left; }
.jidb-launcher__panel[hidden] { display: none; }

.jidb-launcher.is-open .jidb-launcher__panel { animation: jidb-pop .18s ease; }
@keyframes jidb-pop {
  from { opacity: 0; transform: scale(.92) translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* Le widget flottant remplit le panneau et porte l'ombre */
.jidb-widget--float {
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .45);
}
.jidb-header__right { display: inline-flex; align-items: center; gap: 10px; }
.jidb-header__close {
  background: none; border: 0; color: var(--jidb-muted); cursor: pointer;
  font-size: 16px; padding: 2px 4px; line-height: 1;
}
.jidb-header__close:hover { color: var(--jidb-text); }

@media (max-width: 480px) {
  .jidb-launcher { bottom: 14px; }
  .jidb-launcher--right { right: 14px !important; left: auto !important; }
  .jidb-launcher--left  { left: 14px !important; right: auto !important; }
  .jidb-launcher__panel {
    position: fixed;
    left: 10px; right: 10px; bottom: 84px;
    width: auto; max-width: none;
  }
  .jidb-widget--float { max-height: 72vh; }
  .jidb-launcher__label { display: none; }
  /* iOS : eviter le zoom automatique au focus (police >= 16px) */
  .jidb-composer__input, .jidb-composer__pseudo { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .jidb-launcher.is-open .jidb-launcher__panel { animation: none; }
}

/* ===== Info-bulle de la crate =====
   Par defaut : totalement neutralisee (masquee, hors du flux) pour ne jamais
   elargir la ligne ni s'afficher au tactile. Reactivee au survol seulement
   sur les appareils pointeurs. */
.jidb-launcher__tip {
  display: none !important;
  position: absolute !important;
  pointer-events: none;
}

/* ===== Info-bulle de la crate (survol, ordinateurs uniquement) ===== */
@media (hover: hover) and (pointer: fine) {
  .jidb-launcher__tip {
    display: block !important;
    position: absolute;
    bottom: calc(100% + 12px);
    max-width: 240px;
    width: max-content;
    background: #1e1f22;
    color: #fff;
    font-size: 13px !important;
    line-height: 1.35 !important;
    line-height: 1.35;
    padding: 8px 11px;
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .4);
    opacity: 0;
    transform: translateY(6px);
    transition: opacity .15s ease, transform .15s ease;
    pointer-events: none;
    z-index: 2;
  }
  .jidb-launcher--right .jidb-launcher__tip { right: 0; }
  .jidb-launcher--left .jidb-launcher__tip { left: 0; }

  /* Petite flèche pointant vers la bulle */
  .jidb-launcher__tip::after {
    content: "";
    position: absolute;
    top: 100%;
    border: 6px solid transparent;
    border-top-color: #1e1f22;
  }
  .jidb-launcher--right .jidb-launcher__tip::after { right: 20px; }
  .jidb-launcher--left .jidb-launcher__tip::after { left: 20px; }

  .jidb-launcher__bubble:hover ~ .jidb-launcher__tip,
  .jidb-launcher__bubble:focus-visible ~ .jidb-launcher__tip {
    opacity: 1;
    transform: translateY(0);
  }
  .jidb-launcher.is-open .jidb-launcher__tip {
    opacity: 0 !important;
    pointer-events: none;
  }
}
