/* ── AiChat Widget ── */
:root {
  --aichat-color: #1F6CC0;
  --aichat-grad:  linear-gradient(135deg, #1FB6D9, #1F6CC0, #1C4E9A);
}

#aichat-widget * { box-sizing: border-box; }

/* ── Bubble button ── */
#aichat-bubble {
  position: fixed;
  bottom: 28px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--aichat-grad);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 9000;
  box-shadow: 0 6px 20px rgba(31, 108, 192, .4);
  transition: transform .2s, box-shadow .2s;
  border: none;
  outline: none;
}
#aichat-bubble.aichat-right { right: 28px; }
#aichat-bubble.aichat-left  { left: 28px; }
#aichat-bubble:hover { transform: scale(1.07); box-shadow: 0 8px 28px rgba(31, 108, 192, .5); }
#aichat-bubble svg { width: 26px; height: 26px; fill: #fff; }
.aichat-badge {
  position: absolute;
  top: -3px; right: -3px;
  width: 14px; height: 14px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid #fff;
  display: none;
}
#aichat-bubble.has-unread .aichat-badge { display: block; }

/* ── Panel ── */
#aichat-panel {
  position: fixed;
  bottom: 96px;
  width: 370px;
  height: 540px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, .15);
  display: flex;
  flex-direction: column;
  z-index: 8999;
  overflow: hidden;
  transform: scale(.92) translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: transform .22s cubic-bezier(.34,1.3,.64,1), opacity .18s;
}
#aichat-panel.aichat-right { right: 28px; }
#aichat-panel.aichat-left  { left: 28px; }
#aichat-panel.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ── Header ── */
#aichat-header {
  background: var(--aichat-grad);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.aichat-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,.22);
  overflow: hidden;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.35);
  display: flex; align-items: center; justify-content: center;
}
.aichat-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.aichat-header-info { flex: 1; }
.aichat-name {
  font-family: 'Montserrat', sans-serif;
  font-weight: 700; font-size: .9rem; color: #fff;
}
.aichat-status {
  font-size: .72rem; color: rgba(255,255,255,.75);
  display: flex; align-items: center; gap: 5px;
}
.aichat-dot {
  width: 7px; height: 7px;
  border-radius: 50%; background: #4ade80; flex-shrink: 0;
}
#aichat-close {
  background: none; border: none;
  color: rgba(255,255,255,.75);
  font-size: 1.2rem; cursor: pointer; padding: 4px;
  line-height: 1; transition: color .15s;
}
#aichat-close:hover { color: #fff; }

/* ── Messages ── */
#aichat-messages {
  flex: 1; overflow-y: auto;
  padding: 18px 16px;
  display: flex; flex-direction: column; gap: 10px;
  background: #f8fafc;
  scroll-behavior: smooth;
}
#aichat-messages::-webkit-scrollbar { width: 4px; }
#aichat-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

.aichat-msg {
  display: flex;
  max-width: 84%;
  animation: aichat-fade-in .2s ease;
}
.aichat-msg.bot  { align-self: flex-start; }
.aichat-msg.user { align-self: flex-end; flex-direction: row-reverse; }

.aichat-bubble {
  padding: 9px 14px;
  border-radius: 16px;
  font-size: .84rem; line-height: 1.55;
  word-break: break-word;
}
.aichat-msg.bot .aichat-bubble {
  background: #fff; color: #1a202c;
  border-radius: 4px 16px 16px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.aichat-msg.user .aichat-bubble {
  background: var(--aichat-color); color: #fff;
  border-radius: 16px 4px 16px 16px;
}

/* ── Markdown in bot bubbles ── */
.aichat-msg.bot .aichat-bubble ul { margin: 4px 0 2px 0; padding-left: 1.3em; }
.aichat-msg.bot .aichat-bubble li { margin-bottom: 3px; }
.aichat-msg.bot .aichat-bubble hr { border: none; border-top: 1px solid #e2e8f0; margin: 6px 0; }
.aichat-msg.bot .aichat-bubble strong { font-weight: 600; }
.aichat-msg.bot .aichat-bubble a { color: var(--aichat-color); text-decoration: underline; word-break: break-all; }

/* ── Typing indicator ── */
.aichat-typing { align-self: flex-start; }
.aichat-typing .aichat-bubble {
  background: #fff;
  border-radius: 4px 16px 16px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  display: flex; align-items: center; gap: 4px;
  padding: 11px 14px;
}
.aichat-dot {
  width: 6px; height: 6px;
  border-radius: 50%; background: #94a3b8;
  animation: aichat-blink 1.2s infinite;
}
.aichat-dot:nth-child(2) { animation-delay: .2s; }
.aichat-dot:nth-child(3) { animation-delay: .4s; }

@keyframes aichat-blink {
  0%, 80%, 100% { opacity: .25; }
  40%           { opacity: 1; }
}
@keyframes aichat-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* ── Tableaux markdown dans les bulles bot ── */
.aichat-msg.bot .aichat-bubble .aichat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .78rem;
  margin: 4px 0;
}
.aichat-msg.bot .aichat-bubble .aichat-table th,
.aichat-msg.bot .aichat-bubble .aichat-table td {
  border: 1px solid #e2e8f0;
  padding: 5px 8px;
  text-align: left;
  vertical-align: top;
}
.aichat-msg.bot .aichat-bubble .aichat-table th {
  background: #f1f5f9;
  font-weight: 600;
  color: #1e3a5f;
}
.aichat-msg.bot .aichat-bubble .aichat-table tr:nth-child(even) td {
  background: #f8fafc;
}

/* ── Input area ── */
#aichat-footer {
  padding: 12px 14px;
  border-top: 1px solid #e5e7eb;
  display: flex; align-items: flex-end; gap: 8px;
  background: #fff; flex-shrink: 0;
}
#aichat-input {
  flex: 1;
  border: 1.5px solid #e2e8f0; border-radius: 12px;
  padding: 9px 13px;
  font-family: 'Poppins', sans-serif; font-size: .83rem;
  resize: none; outline: none; max-height: 110px;
  line-height: 1.45; transition: border-color .15s;
  color: #1a202c; background: #f8fafc;
}
#aichat-input:focus { border-color: var(--aichat-color); background: #fff; }
#aichat-send {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--aichat-grad); border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: opacity .15s, transform .15s;
}
#aichat-send:hover { opacity: .88; transform: scale(1.05); }
#aichat-send svg { width: 16px; height: 16px; fill: #fff; }
#aichat-send:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* ── Responsive mobile ── */
@media (max-width: 480px) {
  #aichat-panel {
    width: 100vw; height: 100dvh;
    bottom: 0; right: 0 !important; left: 0 !important;
    border-radius: 0;
  }
  #aichat-bubble.aichat-right { bottom: 18px; right: 18px; }
  #aichat-bubble.aichat-left  { bottom: 18px; left: 18px; }
}
