/* =============================================================================
   ISRUN GPT — INTERFACE CONVERSATIONNELLE & CHATBOT STYLE CHATGPT (OFFICIEL)
   Design System : ChatGPT Light & Dark Themes + Accents ISRUN (Bleu Nuit & Or)
   ============================================================================= */

:root,
[data-gpt-theme="light"] {
  --gpt-bg: #ffffff;
  --gpt-sidebar-bg: #f9f9f9;
  --gpt-sidebar-hover: #ececec;
  --gpt-sidebar-active: #e3e3e3;
  --gpt-surface: #ffffff;
  --gpt-border: #e5e5e5;
  --gpt-border-subtle: #f0f0f0;
  --gpt-text: #0d0d0d;
  --gpt-text-secondary: #71717a;
  --gpt-text-muted: #a1a1aa;
  --gpt-user-bubble: #f4f4f4;
  --gpt-user-text: #0d0d0d;
  --gpt-bot-text: #0d0d0d;
  --gpt-input-bg: #ffffff;
  --gpt-input-border: #e5e5e5;
  --gpt-input-shadow: 0 4px 20px rgba(0, 0, 0, 0.07);
  --gpt-send-bg: #0d0d0d;
  --gpt-send-color: #ffffff;
  --gpt-send-disabled: #e5e5e5;
  --gpt-send-disabled-color: #a1a1aa;
  --gpt-card-bg: #ffffff;
  --gpt-card-border: #e5e5e5;
  --gpt-card-hover-border: #d4d4d8;
  --gpt-card-hover-bg: #fafafa;
  --gpt-action-btn-hover: #f4f4f5;
  --gpt-scrollbar: #d4d4d8;
  --gpt-modal-shadow: 0 24px 64px rgba(0, 0, 0, 0.18), 0 4px 16px rgba(0, 0, 0, 0.06);
  --gpt-gold: #c8931a;
  --gpt-navy: #002147;
}

[data-gpt-theme="dark"] {
  --gpt-bg: #212121;
  --gpt-sidebar-bg: #171717;
  --gpt-sidebar-hover: #212121;
  --gpt-sidebar-active: #2f2f2f;
  --gpt-surface: #212121;
  --gpt-border: #2f2f2f;
  --gpt-border-subtle: #262626;
  --gpt-text: #ececec;
  --gpt-text-secondary: #b4b4b4;
  --gpt-text-muted: #737373;
  --gpt-user-bubble: #2f2f2f;
  --gpt-user-text: #ececec;
  --gpt-bot-text: #ececec;
  --gpt-input-bg: #2f2f2f;
  --gpt-input-border: #3c3c3c;
  --gpt-input-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --gpt-send-bg: #ffffff;
  --gpt-send-color: #000000;
  --gpt-send-disabled: #3c3c3c;
  --gpt-send-disabled-color: #737373;
  --gpt-card-bg: #212121;
  --gpt-card-border: #2f2f2f;
  --gpt-card-hover-border: #444444;
  --gpt-card-hover-bg: #282828;
  --gpt-action-btn-hover: #2f2f2f;
  --gpt-scrollbar: #3f3f46;
  --gpt-modal-shadow: 0 24px 64px rgba(0, 0, 0, 0.6), 0 4px 16px rgba(0, 0, 0, 0.3);
  --gpt-gold: #e5a823;
  --gpt-navy: #38bdf8;
}

/* =============================================================================
   1. BOUTON FLOTTANT DÉCLENCHEUR (STYLE CHATGPT BADGE)
   ============================================================================= */
.isrun-ai-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9990;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: #0d0d0d;
  color: #ffffff;
  padding: 10px 18px 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.28), 0 0 0 1px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Plus Jakarta Sans", sans-serif;
  text-decoration: none;
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}

.isrun-ai-trigger:hover {
  transform: translateY(-2px) scale(1.02);
  background: #1a1a1a;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
  border-color: rgba(229, 168, 35, 0.45);
}

.isrun-ai-trigger__icon-wrap {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #002147 0%, #0d3875 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #e5a823;
}

.isrun-ai-trigger__status-dot {
  position: absolute;
  top: -1px;
  right: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10b981;
  border: 2px solid #0d0d0d;
  animation: isrun-ai-pulse 2s infinite;
}

@keyframes isrun-ai-pulse {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.isrun-ai-trigger__content {
  display: flex;
  flex-direction: column;
}

.isrun-ai-trigger__title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #ffffff;
}

.isrun-ai-trigger__sub {
  font-size: 0.72rem;
  color: #a1a1aa;
}

.isrun-ai-trigger__model-tag {
  background: rgba(229, 168, 35, 0.2);
  color: #f3b833;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}

/* =============================================================================
   2. BACKDROP & MODAL PRINCIPALE STYLE CHATGPT
   ============================================================================= */
.isrun-gpt-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 9998;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.isrun-gpt-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

.isrun-gpt-modal {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 960px;
  max-width: calc(100vw - 32px);
  height: 720px;
  max-height: calc(100vh - 48px);
  background: var(--gpt-bg);
  border-radius: 20px;
  box-shadow: var(--gpt-modal-shadow);
  border: 1px solid var(--gpt-border);
  z-index: 9999;
  display: flex;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Plus Jakarta Sans", sans-serif;
  color: var(--gpt-text);
  transform: translateY(20px) scale(0.97);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.26s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.26s ease, visibility 0.26s ease;
}

.isrun-gpt-modal.is-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  visibility: visible;
}

/* Plein écran (Fullscreen) */
.isrun-gpt-modal.is-fullscreen {
  bottom: 0 !important;
  right: 0 !important;
  width: 100vw !important;
  max-width: 100vw !important;
  height: 100vh !important;
  max-height: 100vh !important;
  border-radius: 0 !important;
  border: none !important;
}

/* =============================================================================
   3. SIDEBAR GAUCHE (HISTORIQUE DES DISCUSSIONS STYLE CHATGPT)
   ============================================================================= */
.isrun-gpt-sidebar {
  width: 260px;
  background: var(--gpt-sidebar-bg);
  border-right: 1px solid var(--gpt-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.25s ease, transform 0.25s ease, opacity 0.25s ease;
  user-select: none;
}

.isrun-gpt-sidebar.is-collapsed {
  width: 0 !important;
  padding: 0 !important;
  opacity: 0;
  overflow: hidden;
  border-right: none;
}

.isrun-gpt-sidebar__top {
  padding: 14px 12px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.isrun-gpt-btn-new-chat {
  flex: 1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--gpt-surface);
  border: 1px solid var(--gpt-border);
  border-radius: 10px;
  color: var(--gpt-text);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.isrun-gpt-btn-new-chat:hover {
  background: var(--gpt-sidebar-hover);
  border-color: var(--gpt-text-muted);
}

.isrun-gpt-btn-icon {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: var(--gpt-text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.isrun-gpt-btn-icon:hover {
  background: var(--gpt-sidebar-hover);
  color: var(--gpt-text);
}

.isrun-gpt-sidebar__list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.isrun-gpt-sidebar__section-title {
  padding: 8px 10px 4px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gpt-text-muted);
}

.isrun-gpt-sidebar__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--gpt-text);
  font-size: 0.83rem;
  cursor: pointer;
  transition: background 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.isrun-gpt-sidebar__item:hover {
  background: var(--gpt-sidebar-hover);
}

.isrun-gpt-sidebar__item.is-active {
  background: var(--gpt-sidebar-active);
  font-weight: 600;
}

.isrun-gpt-sidebar__item-icon {
  flex-shrink: 0;
  color: var(--gpt-text-muted);
}

.isrun-gpt-sidebar__bottom {
  padding: 12px;
  border-top: 1px solid var(--gpt-border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.78rem;
}

.isrun-gpt-sidebar__badge-seal {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #ffffff;
  padding: 1px;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.isrun-gpt-sidebar__badge-seal img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.isrun-gpt-sidebar__badge-info {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.isrun-gpt-sidebar__badge-info strong {
  font-size: 0.8rem;
  color: var(--gpt-text);
}

.isrun-gpt-sidebar__badge-info span {
  font-size: 0.7rem;
  color: var(--gpt-text-muted);
}

/* =============================================================================
   4. ZONE PRINCIPALE DE CONVERSATION (MAIN CHAT AREA)
   ============================================================================= */
.isrun-gpt-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--gpt-bg);
  min-width: 0;
  position: relative;
}

/* En-tête supérieur (Modèle ISRUN GPT-4o & Actions) */
.isrun-gpt-topbar {
  height: 54px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--gpt-border-subtle);
  flex-shrink: 0;
  background: var(--gpt-bg);
  z-index: 10;
}

.isrun-gpt-topbar__left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.isrun-gpt-model-selector {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--gpt-text);
  cursor: pointer;
  background: transparent;
  border: none;
  transition: background 0.15s ease;
}

.isrun-gpt-model-selector:hover {
  background: var(--gpt-sidebar-hover);
}

.isrun-gpt-model-tag {
  background: rgba(229, 168, 35, 0.18);
  color: var(--gpt-gold);
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 2px;
}

.isrun-gpt-topbar__right {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Corps de discussion (Messages & Scroll) */
.isrun-gpt-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 120px;
  scroll-behavior: smooth;
}

.isrun-gpt-messages::-webkit-scrollbar {
  width: 6px;
}
.isrun-gpt-messages::-webkit-scrollbar-thumb {
  background: var(--gpt-scrollbar);
  border-radius: 4px;
}

.isrun-gpt-container {
  max-width: 768px;
  margin: 0 auto;
  width: 100%;
}

/* =============================================================================
   5. ÉTAT INITIAL VUIDE (HERO CHATGPT GREETING & CARTES DE SUGGESTIONS)
   ============================================================================= */
.isrun-gpt-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  text-align: center;
  padding: 40px 12px 20px;
}

.isrun-gpt-hero__sparkle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #002147 0%, #0d3875 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #e5a823;
  margin-bottom: 20px;
  box-shadow: 0 4px 16px rgba(0, 33, 71, 0.25);
}

.isrun-gpt-hero__title {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--gpt-text);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.isrun-gpt-hero__subtitle {
  font-size: 0.92rem;
  color: var(--gpt-text-secondary);
  max-width: 520px;
  line-height: 1.5;
  margin-bottom: 36px;
}

.isrun-gpt-suggestions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 680px;
  text-align: left;
}

.isrun-gpt-suggestion-card {
  padding: 14px 16px;
  background: var(--gpt-card-bg);
  border: 1px solid var(--gpt-card-border);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.isrun-gpt-suggestion-card:hover {
  background: var(--gpt-card-hover-bg);
  border-color: var(--gpt-card-hover-border);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.05);
}

.isrun-gpt-suggestion-card__heading {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--gpt-text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.isrun-gpt-suggestion-card__desc {
  font-size: 0.76rem;
  color: var(--gpt-text-secondary);
  line-height: 1.4;
}

/* =============================================================================
   6. BULLES & MESSAGES (STYLE CHATGPT AVATAR + TYPOGRAPHIE)
   ============================================================================= */
.isrun-gpt-msg-row {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  width: 100%;
}

/* Message Utilisateur */
.isrun-gpt-msg-row--user {
  justify-content: flex-end;
}

.isrun-gpt-bubble-user {
  max-width: 80%;
  background: var(--gpt-user-bubble);
  color: var(--gpt-user-text);
  padding: 12px 18px;
  border-radius: 20px;
  font-size: 0.95rem;
  line-height: 1.5;
  word-break: break-word;
}

/* Message Assistant IA (ChatGPT Layout) */
.isrun-gpt-msg-row--bot {
  justify-content: flex-start;
  align-items: flex-start;
}

.isrun-gpt-avatar-bot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #002147;
  color: #e5a823;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.isrun-gpt-bot-content {
  flex: 1;
  min-width: 0;
  color: var(--gpt-bot-text);
  font-size: 0.96rem;
  line-height: 1.65;
}

.isrun-gpt-bot-content ul,
.isrun-gpt-bot-content ol {
  margin: 10px 0 14px 20px;
  padding: 0;
}

.isrun-gpt-bot-content li {
  margin-bottom: 6px;
}

.isrun-gpt-bot-content strong {
  color: var(--gpt-text);
  font-weight: 700;
}

.isrun-gpt-bot-content a {
  color: var(--gpt-navy);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Cartes d'action intégrées */
.isrun-gpt-actions-deck {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.isrun-gpt-action-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: #002147;
  color: #ffffff !important;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none !important;
  transition: all 0.18s ease;
  box-shadow: 0 2px 8px rgba(0, 33, 71, 0.2);
}

.isrun-gpt-action-pill:hover {
  background: #0a3d7c;
  transform: translateY(-1px);
}

.isrun-gpt-action-pill--gold {
  background: #e5a823;
  color: #001229 !important;
  box-shadow: 0 2px 8px rgba(229, 168, 35, 0.3);
}

.isrun-gpt-action-pill--gold:hover {
  background: #f3b833;
}

/* Barre d'actions du message (Copier, Thumbs, Régénérer) */
.isrun-gpt-msg-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  opacity: 0.85;
}

.isrun-gpt-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: var(--gpt-text-muted);
  font-size: 0.74rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.isrun-gpt-tool-btn:hover {
  background: var(--gpt-action-btn-hover);
  color: var(--gpt-text);
}

/* Curseur clignotant lors de la génération continue */
.isrun-gpt-cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  background: var(--gpt-text);
  margin-left: 3px;
  vertical-align: middle;
  animation: isrun-gpt-blink 0.8s infinite;
}

@keyframes isrun-gpt-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* =============================================================================
   7. CAPSULE DE SAISIE INFÉRIEURE STYLE CHATGPT (FLOATING INPUT CAPSULE)
   ============================================================================= */
.isrun-gpt-input-wrapper {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px 20px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, var(--gpt-bg) 35%, var(--gpt-bg) 100%);
  pointer-events: none;
}

.isrun-gpt-input-box {
  pointer-events: auto;
  max-width: 768px;
  margin: 0 auto;
  background: var(--gpt-input-bg);
  border: 1px solid var(--gpt-input-border);
  border-radius: 26px;
  box-shadow: var(--gpt-input-shadow);
  padding: 8px 12px 8px 14px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.isrun-gpt-input-box:focus-within {
  border-color: var(--gpt-text-secondary);
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.12);
}

.isrun-gpt-btn-attach {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--gpt-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  margin-bottom: 2px;
  transition: all 0.15s ease;
}

.isrun-gpt-btn-attach:hover {
  background: var(--gpt-sidebar-hover);
  color: var(--gpt-text);
}

.isrun-gpt-textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--gpt-text);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.45;
  resize: none;
  max-height: 160px;
  min-height: 24px;
  padding: 6px 0;
}

.isrun-gpt-textarea::placeholder {
  color: var(--gpt-text-muted);
}

.isrun-gpt-btn-send {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--gpt-send-disabled);
  color: var(--gpt-send-disabled-color);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: not-allowed;
  flex-shrink: 0;
  margin-bottom: 2px;
  transition: all 0.18s ease;
}

.isrun-gpt-btn-send.is-active {
  background: var(--gpt-send-bg);
  color: var(--gpt-send-color);
  cursor: pointer;
}

.isrun-gpt-disclaimer {
  max-width: 768px;
  margin: 6px auto 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--gpt-text-muted);
  pointer-events: auto;
}

/* =============================================================================
   8. RESPONSIVE & ADAPTATION MOBILE
   ============================================================================= */
@media (max-width: 768px) {
  .isrun-gpt-modal {
    bottom: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    border: none !important;
  }

  .isrun-gpt-sidebar {
    position: absolute;
    top: 54px;
    bottom: 0;
    left: 0;
    z-index: 50;
    width: 270px;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
    transform: translateX(-100%);
  }

  .isrun-gpt-sidebar.is-mobile-open {
    transform: translateX(0);
  }

  .isrun-gpt-suggestions-grid {
    grid-template-columns: 1fr;
  }

  .isrun-ai-trigger {
    bottom: 18px;
    right: 18px;
    padding: 8px 14px;
  }
}
