/* ============================================================
   WORTIS IA — PREMIUM ADAPTIVE THEME + RESPONSIVE
   Scope: #section-assistant uniquement (isolation totale)
   ============================================================ */

/* === VARIABLES : LIGHT MODE (défaut) === */
#section-assistant {
  --ai-bg-main:       #f1f5f9;
  --ai-bg-sidebar:    rgba(255, 255, 255, 0.85);
  --ai-bg-glass:      rgba(255, 255, 255, 0.7);
  --ai-border-glass:  rgba(100, 116, 139, 0.15);
  --ai-accent-blue:   #0066cc;
  --ai-accent-purple: #7c3aed;
  --ai-text-primary:  #0f172a;
  --ai-text-secondary:#64748b;
  --ai-bubble-user-bg: linear-gradient(135deg, #0066cc, #3a7bd5);
  --ai-bubble-ai-bg:  #ffffff;
  --ai-bubble-ai-border: rgba(100, 116, 139, 0.2);
  --ai-bubble-ai-text: #1e293b;
  --ai-input-bg:      rgba(255, 255, 255, 0.9);
  --ai-input-footer-bg: rgba(241, 245, 249, 0.9);
  --ai-suggest-bg:    rgba(100, 116, 139, 0.08);
  --ai-suggest-hover-bg: rgba(0, 102, 204, 0.08);
  --ai-suggest-hover-border: rgba(0, 102, 204, 0.3);
  --ai-history-hover: rgba(0, 0, 0, 0.04);
  --ai-history-active-bg: rgba(0, 102, 204, 0.08);
  --ai-history-active-border: #0066cc;
  --ai-orb-glow: rgba(0, 102, 204, 0.4);
  padding: 0 !important;
}

/* === VARIABLES : DARK MODE === */
html[data-theme='dark'] #section-assistant {
  --ai-bg-main:       #0a0c10;
  --ai-bg-sidebar:    rgba(15, 23, 42, 0.85);
  --ai-bg-glass:      rgba(30, 41, 59, 0.6);
  --ai-border-glass:  rgba(255, 255, 255, 0.08);
  --ai-accent-blue:   #00d2ff;
  --ai-accent-purple: #9d50bb;
  --ai-text-primary:  #f8fafc;
  --ai-text-secondary:#64748b;
  --ai-bubble-user-bg: linear-gradient(135deg, #00d2ff, #3a7bd5);
  --ai-bubble-ai-bg:  rgba(30, 41, 59, 0.6);
  --ai-bubble-ai-border: rgba(255, 255, 255, 0.08);
  --ai-bubble-ai-text: #f1f5f9;
  --ai-input-bg:      rgba(15, 23, 42, 0.6);
  --ai-input-footer-bg: rgba(10, 12, 16, 0.7);
  --ai-suggest-bg:    rgba(255, 255, 255, 0.05);
  --ai-suggest-hover-bg: rgba(0, 210, 255, 0.08);
  --ai-suggest-hover-border: rgba(0, 210, 255, 0.3);
  --ai-history-hover: rgba(255, 255, 255, 0.05);
  --ai-history-active-bg: rgba(0, 210, 255, 0.1);
  --ai-history-active-border: #00d2ff;
  --ai-orb-glow: rgba(0, 210, 255, 0.5);
}

/* === LAYOUT PRINCIPAL === */
.ai-shell {
  display: flex;
  position: relative;
  height: calc(100vh - 6.5rem);
  border-radius: 1.25rem;
  overflow: hidden;
  border: 1px solid var(--ai-border-glass);
  background: var(--ai-bg-main);
  color: var(--ai-text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  transition: background 0.3s ease, color 0.3s ease;
}

/* === SIDEBAR === */
.ai-sidebar {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--ai-bg-sidebar);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--ai-border-glass);
  transition: all 0.3s ease;
}

.ai-sidebar-header {
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--ai-border-glass);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.ai-sidebar-kicker {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ai-text-secondary);
  font-weight: 800;
}

.ai-sidebar-title {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--ai-text-primary);
  margin-top: 0.15rem;
}

.ai-new-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 0.6rem;
  background: rgba(0, 102, 204, 0.1);
  border: 1px solid rgba(0, 102, 204, 0.2);
  color: var(--ai-accent-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

html[data-theme='dark'] .ai-new-btn {
  background: rgba(0, 210, 255, 0.1);
  border-color: rgba(0, 210, 255, 0.2);
}

.ai-new-btn:hover {
  transform: scale(1.1);
  background: var(--ai-accent-blue);
  color: white;
}

.ai-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ai-history-item {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: 0.75rem;
  background: transparent;
  border: 1px solid transparent;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ai-history-item:hover {
  background: var(--ai-history-hover);
  border-color: var(--ai-border-glass);
}

.ai-history-item.active {
  background: var(--ai-history-active-bg);
  border-color: var(--ai-history-active-border);
}

.ai-history-actions-btn:hover {
  background: rgba(0, 102, 204, 0.1) !important;
  color: var(--ai-accent-blue) !important;
  opacity: 1 !important;
  transform: scale(1.1);
}

html[data-theme='dark'] .ai-history-actions-btn:hover {
  background: rgba(0, 210, 255, 0.1) !important;
  color: var(--ai-accent-blue) !important;
}

/* === ZONE CHAT === */
.ai-chat-container {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: radial-gradient(circle at bottom right, rgba(0, 102, 204, 0.06), transparent 50%);
}

html[data-theme='dark'] .ai-chat-container {
  background: radial-gradient(circle at bottom right, rgba(0, 210, 255, 0.06), transparent 50%);
}

.ai-chat-header {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--ai-border-glass);
  display: flex;
  align-items: center;
  gap: 0.85rem;
  background: var(--ai-bg-sidebar);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
  min-height: 4rem;
}

.ai-chat-header-info {
  flex: 1;
  min-width: 0;
}

#ai-conv-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.ai-chat-avatar {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ai-accent-blue), var(--ai-accent-purple));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.9rem;
  flex-shrink: 0;
  box-shadow: 0 0 16px var(--ai-orb-glow);
}

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* === BULLES === */
.ai-message {
  max-width: 82%;
  padding: 0.6rem 0.85rem;
  border-radius: 1rem;
  font-size: 0.84rem;
  line-height: 1.55;
  position: relative;
  animation: ai-fade-up 0.35s ease-out forwards;
}

.ai-message.user {
  align-self: flex-end;
  background: var(--ai-bubble-user-bg);
  color: white;
  border-bottom-right-radius: 0.25rem;
}

.ai-message.ai {
  align-self: flex-start;
  background: var(--ai-bubble-ai-bg);
  border: 1px solid var(--ai-bubble-ai-border);
  color: var(--ai-bubble-ai-text);
  border-bottom-left-radius: 0.25rem;
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

html[data-theme='dark'] .ai-message.ai {
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}

/* === GOTO BUTTONS (Premium Actions) === */
.ai-goto-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.9rem;
  margin: 0.4rem 0.4rem 0.4rem 0;
  background: rgba(0, 102, 204, 0.08);
  border: 1px solid rgba(0, 102, 204, 0.2);
  color: var(--ai-accent-blue);
  font-size: 0.78rem;
  font-weight: 700;
  border-radius: 2rem;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.02);
  vertical-align: middle;
}

.ai-goto-btn:hover {
  background: var(--ai-accent-blue);
  color: white;
  border-color: transparent;
  transform: translateY(-1.5px) scale(1.02);
  box-shadow: 0 6px 15px var(--ai-orb-glow);
}

.ai-goto-btn i {
  font-size: 0.85rem;
}

html[data-theme='dark'] .ai-goto-btn {
  background: rgba(0, 210, 255, 0.1);
  border-color: rgba(0, 210, 255, 0.2);
  color: var(--ai-accent-blue);
}

/* === ORB ANIMÉ === */
.ai-orb-wrapper {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.6rem 0;
}

.ai-orb {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: linear-gradient(45deg, var(--ai-accent-blue), var(--ai-accent-purple));
  box-shadow: 0 0 16px var(--ai-orb-glow);
  flex-shrink: 0;
}

.ai-orb.thinking {
  animation: ai-orb-pulse 1.8s infinite ease-in-out;
}

.ai-orb-label {
  font-size: 0.78rem;
  color: var(--ai-text-secondary);
  font-weight: 500;
  font-style: italic;
}

/* === SUGGESTIONS === */
.ai-suggestions {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  scrollbar-width: none;
}

.ai-suggestions::-webkit-scrollbar { display: none; }

.ai-suggest-btn {
  white-space: nowrap;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  background: var(--ai-suggest-bg);
  border: 1px solid var(--ai-border-glass);
  color: var(--ai-text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.ai-suggest-btn:hover {
  background: var(--ai-suggest-hover-bg);
  border-color: var(--ai-suggest-hover-border);
  color: var(--ai-accent-blue);
}

/* === INPUT === */
.ai-input-wrapper {
  padding: 0.75rem 1.25rem 1rem;
  background: var(--ai-input-footer-bg);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--ai-border-glass);
  flex-shrink: 0;
}

.ai-input-box {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--ai-input-bg);
  border: 1.5px solid var(--ai-border-glass);
  border-radius: 1.25rem;
  padding: 0.4rem 0.6rem 0.4rem 0.75rem;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.ai-input-box:focus-within {
  border-color: var(--ai-accent-blue);
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

html[data-theme='dark'] .ai-input-box:focus-within {
  box-shadow: 0 0 0 3px rgba(0, 210, 255, 0.12);
}

.ai-input-field {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--ai-text-primary);
  font-size: 0.88rem;
  padding: 0.5rem 0;
  outline: none;
  resize: none;
  max-height: 120px;
  font-family: inherit;
  line-height: 1.5;
}

.ai-input-field::placeholder {
  color: var(--ai-text-secondary);
  opacity: 0.7;
}

.ai-input-btn {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--ai-text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  border: none;
}

.ai-input-btn:hover {
  color: var(--ai-accent-blue);
  background: var(--ai-suggest-hover-bg);
}

.ai-input-btn.send {
  background: var(--ai-accent-blue);
  color: white;
  box-shadow: 0 4px 12px var(--ai-orb-glow);
}

.ai-input-btn.send:hover {
  transform: scale(1.08);
  opacity: 0.9;
}

.ai-input-btn.send:disabled {
  opacity: 0.4;
  transform: none;
  cursor: not-allowed;
}

.ai-footer-note {
  text-align: center;
  font-size: 0.65rem;
  color: var(--ai-text-secondary);
  margin-top: 0.6rem;
  opacity: 0.6;
}

/* === SCROLLBARS === */
.ai-history-list::-webkit-scrollbar,
.ai-chat-messages::-webkit-scrollbar { width: 5px; }
.ai-history-list::-webkit-scrollbar-track,
.ai-chat-messages::-webkit-scrollbar-track { background: transparent; }
.ai-history-list::-webkit-scrollbar-thumb,
.ai-chat-messages::-webkit-scrollbar-thumb {
  background: var(--ai-border-glass);
  border-radius: 10px;
}

/* === ANIMATIONS === */
@keyframes ai-fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes ai-orb-pulse {
  0%, 100% { transform: scale(1);   box-shadow: 0 0 16px var(--ai-orb-glow); }
  50%       { transform: scale(1.35); box-shadow: 0 0 30px var(--ai-orb-glow), 0 0 60px var(--ai-orb-glow); filter: hue-rotate(30deg); }
}

/* === RESPONSIVE === */

/* Tablette (≤ 1024px) : sidebar plus étroite */
@media (max-width: 1024px) {
  .ai-shell { height: calc(100vh - 9rem); }
  .ai-sidebar { width: 220px; }
  .ai-chat-messages { padding: 1.25rem; }
  .ai-input-wrapper { padding: 0.85rem 1.25rem 1rem; }
}

/* Mobile (≤ 768px) : sidebar tiroir, chat plein écran */
@media (max-width: 768px) {
  .ai-shell {
    flex-direction: row;
    height: calc(100vh - 7rem);
    border-radius: 0.75rem;
    border: 1px solid var(--ai-border-glass);
    margin: 0;
  }

  .ai-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 85%;
    z-index: 50;
    transform: translateX(-105%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 40px rgba(0,0,0,0.2);
    background: var(--ai-bg-sidebar);
    visibility: hidden;
  }

  .ai-sidebar.is-open {
    transform: translateX(0);
    visibility: visible;
  }

  .ai-chat-container {
    width: 100%;
    height: 100%;
  }

  .ai-chat-header {
    padding: 0.5rem 0.75rem;
    min-height: 3.5rem;
    gap: 0.65rem;
  }
  
  .ai-chat-avatar {
    width: 2rem;
    height: 2rem;
  }
  
  .ai-chat-header h4 {
    font-size: 0.8rem !important;
  }

  .ai-chat-messages {
    padding: 1rem 0.75rem;
    gap: 0.85rem;
  }

  .ai-message {
    max-width: 92%;
    font-size: 0.82rem;
  }

  .ai-input-wrapper {
    padding: 0.6rem 0.75rem 0.75rem;
  }

  .ai-input-box {
    padding: 0.25rem 0.4rem 0.25rem 0.6rem;
    gap: 0.5rem;
  }

  /* Overlay pour fermer le tiroir */
  .ai-sidebar-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(4px);
    z-index: 45;
    display: none;
  }

  .ai-sidebar-overlay.is-visible {
    display: block;
  }
}

/* === DROPDOWN MENU (Premium) === */
.ai-dropdown {
  position: relative;
}

.ai-dropdown-menu {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 110;
  min-width: 160px;
  background: var(--ai-bg-glass);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  border: 1px solid var(--ai-border-glass);
  border-radius: 0.85rem;
  box-shadow: 0 12px 30px rgba(0,0,0,0.15);
  padding: 0.4rem;
  display: none;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-10px) scale(0.95);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-dropdown-menu.show {
  display: block;
  pointer-events: auto;
  opacity: 1;
  transform: translateY(4px) scale(1);
}

.ai-dropdown-item {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border-radius: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ai-text-primary);
  text-align: left;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ai-dropdown-item:hover {
  background: var(--ai-history-hover);
  color: var(--ai-accent-blue);
}

.ai-dropdown-item.danger:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.08);
}

.ai-dropdown-item i {
  font-size: 1rem;
  opacity: 0.7;
}

/* Specific to history items */
.ai-history-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ai-history-content {
  flex: 1;
  min-width: 0;
}

/* Specific to message bubbles */
.ai-message-options {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.ai-message:hover .ai-message-options {
  opacity: 1;
}

.ai-msg-actions-btn {
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 0.5rem;
  background: rgba(0,0,0,0.05);
  border: none;
  color: var(--ai-text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.ai-msg-actions-btn:hover {
  background: rgba(0,0,0,0.1);
  color: var(--ai-accent-blue);
}

html[data-theme='dark'] .ai-msg-actions-btn {
  background: rgba(255,255,255,0.05);
}

/* Très petit mobile (≤ 480px) */
@media (max-width: 480px) {
  .ai-shell { height: calc(100vh - 8rem); }
  .ai-sidebar { width: 80%; max-width: 280px; }
  .ai-message { max-width: 95%; font-size: 0.82rem; padding: 0.7rem 0.9rem; }
  .ai-suggestions { gap: 0.35rem; }
  .ai-suggest-btn { font-size: 0.7rem; padding: 0.35rem 0.7rem; }
}
