/* ============================================
   AI Chat BI - Styles
   Mohamed Aggoubi / Weglob
   ============================================ */

/* === Layout principal === */
.aichat-wrap {
  display: flex;
  height: calc(100vh - 140px);
  min-height: 500px;
  gap: 0;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  overflow: hidden;
  background: #f8f9fa;
  margin: 10px 0;
  box-shadow: 0 2px 20px rgba(0,0,0,0.08);
}

/* === Sidebar === */
.aichat-sidebar {
  width: 260px;
  min-width: 220px;
  background: #1e2433;
  color: #c9d1d9;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px 12px;
  border-bottom: 1px solid #30363d;
}

.btn-new-chat {
  display: block;
  background: linear-gradient(135deg, #4f8ef7, #6c63ff);
  color: #fff !important;
  border-radius: 8px;
  padding: 10px 14px;
  text-align: center;
  font-weight: 600;
  font-size: 13px;
  text-decoration: none !important;
  transition: opacity 0.2s;
}
.btn-new-chat:hover { opacity: 0.85; }

.sidebar-sessions {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.sidebar-sessions::-webkit-scrollbar { width: 4px; }
.sidebar-sessions::-webkit-scrollbar-thumb { background: #30363d; border-radius: 4px; }

.session-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border-radius: 6px;
  margin: 2px 8px;
  text-decoration: none !important;
  color: #c9d1d9 !important;
  transition: background 0.15s;
}
.session-item:hover  { background: #2d3748; }
.session-item.active { background: #2d3748; border-left: 3px solid #4f8ef7; }

.session-icon { font-size: 16px; margin-top: 1px; }
.session-ref  { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.session-meta { font-size: 10px; color: #6b7280; margin-top: 2px; }

.no-sessions { padding: 20px; text-align: center; color: #6b7280; font-size: 12px; }

/* === Zone Chat principale === */
.aichat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  overflow: hidden;
}

/* === Messages === */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: #e0e0e0; border-radius: 4px; }

.message-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: fadeInUp 0.25s ease;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message-row.user  { flex-direction: row-reverse; }

.message-avatar {
  font-size: 24px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: #f0f4ff;
  border-radius: 50%;
}
.message-row.user .message-avatar { background: #e8f5e9; }

.message-bubble {
  max-width: 75%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-content {
  background: #f0f4ff;
  border-radius: 12px 12px 12px 0;
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.6;
  color: #1a1a2e;
  word-break: break-word;
}
.message-row.user .message-content {
  background: linear-gradient(135deg, #4f8ef7, #6c63ff);
  color: #ffffff;
  border-radius: 12px 12px 0 12px;
}

/* Markdown dans les messages */
.message-content h1, .message-content h2, .message-content h3 { font-size: 1em; font-weight: 700; margin: 6px 0 4px; }
.message-content ul, .message-content ol { margin: 4px 0; padding-left: 18px; }
.message-content li { margin-bottom: 2px; }
.message-content p  { margin: 4px 0; }
.message-content code { background: rgba(0,0,0,0.08); border-radius: 4px; padding: 1px 5px; font-family: monospace; font-size: 12px; }
.message-content strong { font-weight: 700; }
.message-row.user .message-content code { background: rgba(255,255,255,0.2); }

/* === Graphiques === */
.chart-container {
  background: #ffffff;
  border: 1px solid #e8ecf0;
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 1px 8px rgba(0,0,0,0.06);
  max-width: 100%;
}

.query-badge {
  display: inline-block;
  background: #eef2ff;
  color: #4f8ef7;
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid #c7d7fd;
}

.message-time {
  font-size: 10px;
  color: #9ca3af;
  text-align: right;
}
.message-row.user .message-time { text-align: right; }

/* === Typing indicator === */
.typing-dots {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 14px 18px;
  background: #f0f4ff;
  border-radius: 12px 12px 12px 0;
}
.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4f8ef7;
  animation: typing 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%            { transform: translateY(-6px); opacity: 1; }
}

/* === Écran de bienvenue === */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  flex: 1;
}

.welcome-icon { font-size: 64px; margin-bottom: 16px; }

.welcome-screen h2 {
  font-size: 22px;
  color: #1a1a2e;
  margin-bottom: 8px;
}

.welcome-screen p {
  color: #6b7280;
  font-size: 14px;
  max-width: 480px;
  margin-bottom: 28px;
  line-height: 1.6;
}

.suggestions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  max-width: 760px;
  width: 100%;
}

.suggestion-card {
  background: #f8f9ff;
  border: 1px solid #dde5ff;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px;
  color: #374151;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
  line-height: 1.4;
}
.suggestion-card:hover {
  background: #eef2ff;
  border-color: #4f8ef7;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(79,142,247,0.15);
}

/* === Zone de saisie === */
.chat-input-area {
  padding: 14px 20px;
  border-top: 1px solid #e8ecf0;
  background: #ffffff;
}

.chat-input-wrap {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: #f0f4ff;
  border: 2px solid #e0e8ff;
  border-radius: 12px;
  padding: 8px 14px;
  transition: border-color 0.2s;
}
.chat-input-wrap:focus-within { border-color: #4f8ef7; }

.chat-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: 14px;
  color: #1a1a2e;
  line-height: 1.5;
  max-height: 150px;
  outline: none;
  font-family: inherit;
}
.chat-input::placeholder { color: #9ca3af; }

.send-btn {
  background: linear-gradient(135deg, #4f8ef7, #6c63ff);
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 38px;
  height: 38px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s;
}
.send-btn:hover    { opacity: 0.85; }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.input-hint {
  margin-top: 6px;
  font-size: 11px;
  color: #9ca3af;
  text-align: center;
}
.input-hint kbd {
  background: #e8ecf0;
  border-radius: 3px;
  padding: 1px 5px;
  font-family: monospace;
  font-size: 10px;
}

/* === Responsive === */
@media (max-width: 768px) {
  .aichat-sidebar { width: 200px; min-width: 0; }
  .aichat-wrap    { height: calc(100vh - 100px); }
  .suggestions-grid { grid-template-columns: 1fr; }
  .message-bubble  { max-width: 90%; }
}

@media (max-width: 540px) {
  .aichat-sidebar { display: none; }
}
