/* ==============================
   AI Chatbot – CSS V1
   Adapted to mgpt-* structure
   ============================== */

#mgpt-chatbot {
  width: 100%;
  margin: 40px auto;
  max-width: 900px;
}

.mgpt-chatbot-inner {

  --border-radius: 14px;
  --border-width: 2px;
  --border-color: var(--mgpt-border-color, #ff6a00);
  --spacing: 12px;

  --bg-user: var(--mgpt-user-bg, #6c5ce7);
  --bg-bot: var(--mgpt-bot-bg, #f4f6ff);

  font-family: inherit;
  color: inherit;

  border: var(--border-width) solid var(--border-color);
  border-radius: var(--border-radius);

  background: var(--mgpt-chatbot-bg-color, #ffffff);

  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);

  width: 100%;
  box-sizing: border-box;

  display: flex;
  flex-direction: column;
}

/* Message area */
#mgpt-chat-messages {
  padding: var(--spacing);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Messages injected by JS */
.mgpt-message {
  display: flex;
}

/* User message */
.mgpt-message.user {
  justify-content: flex-end;
}

/* Bot message */
.mgpt-message.bot {
  justify-content: flex-start;
}

.mgpt-message.bot,
.mgpt-message.user {
  line-height: 1.6;
}

/* Bubble */
.mgpt-bubble {
  padding: 12px 16px;
  border-radius: var(--border-radius);
  max-width: 100%;
  font-size: 0.95em;
  line-height: 1.6;
}

.mgpt-message.user .mgpt-bubble {
  background: var(--bg-user);
}

.mgpt-message.bot .mgpt-bubble {
  background: var(--bg-bot);
}

/* Form */
#mgpt-chat-form {
  display: flex;
  gap: 8px;
  padding: var(--spacing);
  border-top: 1px solid #ffffff;
}

#mgpt-chat-input {
  flex: 1;
  font-family: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--mgpt-input-bg-color, #ffffff);
  border: 1px solid #c0c0c0; /* gris argenté */
}

#mgpt-chat-input:focus {
  outline: none;
  border-color: #a8a8a8;
  box-shadow: 0 0 0 2px rgba(192,192,192,0.2);
}

#mgpt-chat-form button {
  font-family: inherit;
  padding: 0;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: none;
  background: var(--mgpt-button-bg, #38bdf8);
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

#mgpt-chat-form button::before {
  content: "";
  width: 18px;
  height: 18px;
  background: white;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M2 21l21-9L2 3v7l15 2-15 2z'/%3E%3C/svg%3E") no-repeat center;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M2 21l21-9L2 3v7l15 2-15 2z'/%3E%3C/svg%3E") no-repeat center;
  mask-size: contain;
  -webkit-mask-size: contain;
}

#mgpt-chat-form button:hover {
  background: var(--mgpt-button-hover-color, #0ea5e9);
  transform: scale(1.05);
}

/* ==============================
   Floating Bubble Mode
============================== */

#mgpt-floating-wrapper {
  position: fixed;
  bottom: 20px;
  z-index: 999999;
  pointer-events: auto;
}

#mgpt-floating-bubble {
  pointer-events: auto;
}

.mgpt-position-right {
  right: 20px;
}

.mgpt-position-left {
  left: 20px;
}

/* Bulle ronde */
#mgpt-floating-bubble {
  width: 110px;
  height: 110px;
  background: var(--mgpt-bubble-color, #ff6a00);
  color: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 10px 25px rgba(0,0,0,0.25);
  font-size: 28px;
}

#mgpt-floating-bubble svg {
  width: 44px;
  height: 44px;
  display: block;
}

/* Fenêtre cachée par défaut */
#mgpt-floating-chat {
  width: min(550px, calc(100vw - 40px));
  max-width: calc(100vw - 40px);
  margin-bottom: 10px;
  box-sizing: border-box;
}

@media (max-width: 768px) {

  #mgpt-floating-wrapper {
    right: 12px !important;
    left: auto !important;
    bottom: 12px !important;
    width: auto !important;
    height: auto !important;
    inset: auto 12px 12px auto !important;
  }

  #mgpt-floating-wrapper.mgpt-position-left {
    left: 12px !important;
    right: auto !important;
    inset: auto auto 12px 12px !important;
  }

  #mgpt-floating-bubble {
    width: 72px;
    height: 72px;
    font-size: 24px;
  }

  #mgpt-floating-bubble svg {
  width: 36px;
  height: 36px;
}

  #mgpt-floating-chat {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    padding: 10px !important;
    box-sizing: border-box !important;
    background: var(--mgpt-chatbot-bg-color, #ffffff) !important;
  }

  #mgpt-chatbot {
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    margin: 0 !important;
  }

  .mgpt-chatbot-inner {
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    border-radius: 14px !important;
    overflow: hidden !important;
  }

  #mgpt-close-chat {
    flex: 0 0 42px !important;
    margin: 8px auto 10px auto !important;
  }

  #mgpt-chat-form {
    flex: 0 0 auto !important;
    padding: 10px !important;
    padding-bottom: calc(env(safe-area-inset-bottom) + 10px) !important;
  }

  #mgpt-chat-messages {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
  }
}

.mgpt-hidden {
  display: none;
}

/* =========================
   True Progressive Height System
========================= */

.mgpt-chatbot-inner {
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

#mgpt-chat-messages {
  flex: 1;
  overflow-y: auto;
}

/* =========================
   Close Button
========================= */

#mgpt-close-chat {
  width: 42px;
  height: 42px;
  margin: 12px auto 16px auto;
  border-radius: 50%;
  border: none;
  background: var(--mgpt-bubble-color, #ff6a00);
  color: #ffffff;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

#mgpt-close-chat:hover {
  transform: scale(1.08);
  opacity: 0.9;
}

.mgpt-timer {
  font-size: 12px;
  opacity: 0.7;
  font-style: italic;
}

/* =========================
   Fix BBPress / mobile
========================= */

#mgpt-chat-form {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  width: 100% !important;
  flex-wrap: nowrap !important;
}

#mgpt-chat-input {
  flex: 1 1 auto !important;
  width: 100% !important;
  min-width: 0 !important;
  display: block !important;
  margin: 0 !important;
  box-sizing: border-box !important;
  height: 44px !important;
}

#mgpt-chat-form button {
  flex: 0 0 44px !important;
  width: 44px !important;
  min-width: 44px !important;
  max-width: 44px !important;
  height: 44px !important;
  margin: 0 !important;
}

/* Fix visibilité icône send */
#mgpt-chat-form button::before {
  content: "";
  display: block !important;
  width: 18px !important;
  height: 18px !important;
  min-width: 18px !important;
  min-height: 18px !important;
  background-color: #ffffff !important;
  opacity: 1 !important;

  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M2 21l21-9L2 3v7l15 2-15 2z'/%3E%3C/svg%3E") no-repeat center / contain !important;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M2 21l21-9L2 3v7l15 2-15 2z'/%3E%3C/svg%3E") no-repeat center / contain !important;
}

#mgpt-chat-form button {
  position: relative;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 0 !important;
  line-height: 0 !important;
}

/* =========================
   Better readability - generic
========================= */

.mgpt-message.bot .mgpt-bubble {
  padding: 16px 18px;
  line-height: 1.72;
  font-size: 0.97em;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
}

.mgpt-message.user .mgpt-bubble {
  line-height: 1.5;
}

.mgpt-timer {
  display: block;
  margin-bottom: 12px;
  font-size: 12px;
  opacity: 0.65;
  font-style: normal;
}

.mgpt-sources {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.mgpt-sources-title {
  margin-bottom: 8px;
  font-size: 0.92em;
  font-weight: 600;
  opacity: 0.8;
}

.mgpt-sources ul {
  margin: 0;
  padding-left: 18px;
}

.mgpt-sources li {
  margin-bottom: 6px;
  line-height: 1.45;
}

.mgpt-sources a {
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

/* =========================
   Gradient Finish
========================= */

#mgpt-chatbot.mgpt-gradients-enabled .mgpt-chatbot-inner {
  background: linear-gradient(
    135deg,
    var(--mgpt-chatbot-bg-color, #ffffff),
    color-mix(in srgb, var(--mgpt-chatbot-bg-color, #ffffff) 85%, #000000)
  );
}

#mgpt-chatbot.mgpt-gradients-enabled .mgpt-message.user .mgpt-bubble {
  background: linear-gradient(
    135deg,
    var(--mgpt-user-bg, #6c5ce7),
    color-mix(in srgb, var(--mgpt-user-bg, #6c5ce7) 75%, #ffffff)
  );
}

#mgpt-chatbot.mgpt-gradients-enabled .mgpt-message.bot .mgpt-bubble {
  background: linear-gradient(
    135deg,
    var(--mgpt-bot-bg, #f4f6ff),
    color-mix(in srgb, var(--mgpt-bot-bg, #f4f6ff) 85%, #000000)
  );
}

#mgpt-chatbot.mgpt-gradients-enabled #mgpt-chat-input {
  background: linear-gradient(
    135deg,
    var(--mgpt-input-bg-color, #ffffff),
    color-mix(in srgb, var(--mgpt-input-bg-color, #ffffff) 92%, #000000)
  );
}

#mgpt-chatbot.mgpt-gradients-enabled #mgpt-chat-form button {
  background: linear-gradient(
    135deg,
    var(--mgpt-button-bg, #38bdf8),
    color-mix(in srgb, var(--mgpt-button-bg, #38bdf8) 70%, #000000)
  );
}

#mgpt-chatbot.mgpt-gradients-enabled #mgpt-close-chat,
body.mgpt-gradients-enabled #mgpt-floating-bubble {
  background: linear-gradient(
    135deg,
    var(--mgpt-bubble-color, #ff6a00),
    color-mix(in srgb, var(--mgpt-bubble-color, #ff6a00) 70%, #000000)
  );
}

/* Gradient border */
#mgpt-chatbot.mgpt-gradients-enabled .mgpt-chatbot-inner {
  border-color: transparent;
  background:
    linear-gradient(
      135deg,
      var(--mgpt-chatbot-bg-color, #ffffff),
      color-mix(in srgb, var(--mgpt-chatbot-bg-color, #ffffff) 85%, #000000)
    ) padding-box,
    linear-gradient(
      135deg,
      var(--mgpt-border-color, #ff6a00),
      color-mix(in srgb, var(--mgpt-border-color, #ff6a00) 70%, #000000)
    ) border-box;
}

/* Soft gradient */
#mgpt-chatbot.mgpt-gradients-enabled.mgpt-gradient-soft .mgpt-chatbot-inner {
  background:
    linear-gradient(
      135deg,
      var(--mgpt-chatbot-bg-color, #ffffff),
      color-mix(in srgb, var(--mgpt-chatbot-bg-color, #ffffff) 92%, #ffffff)
    ) padding-box,
    linear-gradient(
      135deg,
      var(--mgpt-border-color, #ff6a00),
      color-mix(in srgb, var(--mgpt-border-color, #ff6a00) 80%, #ffffff)
    ) border-box;
}

/* Vivid gradient */
#mgpt-chatbot.mgpt-gradients-enabled.mgpt-gradient-vivid .mgpt-message.user .mgpt-bubble,
#mgpt-chatbot.mgpt-gradients-enabled.mgpt-gradient-vivid #mgpt-chat-form button,
#mgpt-chatbot.mgpt-gradients-enabled.mgpt-gradient-vivid #mgpt-close-chat,
body.mgpt-gradients-enabled.mgpt-gradient-vivid #mgpt-floating-bubble {
  filter: saturate(1.15);
}

/* Premium gradient */
#mgpt-chatbot.mgpt-gradients-enabled.mgpt-gradient-premium .mgpt-chatbot-inner {
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.14);
}

#mgpt-chatbot.mgpt-chatbot-collapsed #mgpt-chat-messages {
  max-height: 58px;
  overflow: hidden;
}

#mgpt-chatbot.mgpt-chatbot-collapsed #mgpt-chat-messages .mgpt-message:not(:first-child) {
  display: none;
}

#mgpt-chatbot.mgpt-chatbot-collapsed #mgpt-thinking {
  display: none !important;
}