/* ============================================================
   OrientaBot – orientabot.css
   Styles complets de l'interface chatbot
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:   #a51818;
  --primary-d: #7a1010;
  --yellow:    #ffd102;
  --accent:    #3959e6;
  --green:     #22c55e;
  --red:       #ef4444;
  --bg:        #700404;
  --bubble-bot:#f9f1f1;
  --text:      #1e293b;
  --muted:     #64748b;
  --border:    #e2e8f0;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  display: flex; justify-content: center; align-items: center;
  min-height: 100vh; padding: 1rem;
}

/* ── Widget ── */
#ob-widget {
  width: 100%; max-width: 440px; background: #fff;
  border-radius: 24px; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  overflow: hidden; display: flex; flex-direction: column; height: 690px;
}

/* ── Header ── */
.ob-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-d) 100%);
  color: #fff; padding: 14px 16px;
  display: flex; align-items: center; gap: 12px; position: relative;
  flex-shrink: 0;
}
.ob-header::after {
  content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--yellow), #ff8c00, var(--yellow));
}
.ob-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,0.15); border: 2px solid rgba(255,215,2,0.6);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.ob-title {
  font-size: 14px; font-weight: 700;
  font-family: 'Cairo', sans-serif; color: var(--yellow);
}
.ob-status {
  font-size: 11px; opacity: .85;
  display: flex; align-items: center; gap: 5px; margin-top: 2px;
}
.ob-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #4ade80; animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ── Historique des conversations ── */
.ob-history-bar {
  padding: 8px 12px; border-bottom: 1px solid #fde8e8;
  background: #fff8f8; display: flex; gap: 6px; align-items: center;
  overflow-x: auto; flex-shrink: 0;
}
.ob-history-bar::-webkit-scrollbar { height: 0; }
.ob-history-label {
  font-size: 11px; color: var(--muted); white-space: nowrap;
  display: flex; align-items: center; gap: 4px; flex-shrink: 0;
}
.ob-history-btn {
  padding: 4px 10px; border-radius: 20px; font-size: 11px; white-space: nowrap;
  border: 1.5px solid #e2c4c4; background: #fff; color: var(--primary);
  cursor: pointer; transition: all .15s; flex-shrink: 0;
}
.ob-history-btn:hover, .ob-history-btn.active {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.ob-history-new {
  padding: 4px 10px; border-radius: 20px; font-size: 11px;
  border: 1.5px solid #e2c4c4; background: #fff; color: var(--muted);
  cursor: pointer; transition: all .15s; flex-shrink: 0; margin-left: auto;
}
.ob-history-new:hover { background: #f1f5f9; }
/* ------------------ */
.ob-history-item {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-right: 8px;
}

.ob-history-btn {
  padding-right: 28px !important; /* Plus d'espace pour la croix */
  cursor: pointer;
}

.ob-history-delete {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(100, 116, 139, 0.15);
  color: #64748b;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  /* Toujours visible mais transparent */
  opacity: 0.6;
  pointer-events: auto;
}

/* Sur desktop, plus discret */
@media (min-width: 769px) {
  .ob-history-delete {
    opacity: 0;
  }
  
  .ob-history-item:hover .ob-history-delete {
    opacity: 0.7;
  }
  
  .ob-history-item:hover .ob-history-delete:hover {
    opacity: 1;
    color: #ef4444;
  }
}

/* Sur mobile, toujours visible et plus grand */
@media (max-width: 768px) {
  .ob-history-delete {
    opacity: 0.8;
    width: 22px;
    height: 22px;
    color: #ef4444;
    font-size: 16px;
  }
  
  .ob-history-delete:active {
    color: #ef4444;
    transform: translateY(-50%) scale(0.95);
  }
}

/* ── Messages ── */
.ob-messages {
  flex: 1; overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth;
}
.ob-messages::-webkit-scrollbar { width: 4px; }
.ob-messages::-webkit-scrollbar-thumb { background: #e2c4c4; border-radius: 2px; }

.ob-msg { display: flex; gap: 1px; align-items: flex-end; }
.ob-msg.user { flex-direction: row-reverse; }
.ob-msg-av {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); border: 2px solid var(--yellow);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0;
}
.ob-msg-content { display: flex; flex-direction: column; gap: 4px; max-width: 85%; }
.ob-msg.user .ob-msg-content { align-items: flex-end; }

.ob-bubble {
  padding: 10px 13px; font-size: 12px; line-height: 1.65; border-radius: 16px;
}
.ob-msg.bot .ob-bubble {
  background: var(--bubble-bot); color: var(--text);
  border-radius: 4px 16px 16px 16px; border-left: 3px solid var(--primary);
}
.ob-msg.user .ob-bubble {
  background: var(--primary); color: #fff;
  border-radius: 16px 16px 4px 16px;
}

/* ── Markdown dans bulle ── */
.ob-bubble h1,.ob-bubble h2,.ob-bubble h3 {
  font-family: 'Cairo', sans-serif; font-weight: 700;
  color: var(--primary); margin: 8px 0 4px; line-height: 1.3;
}
.ob-bubble h1 { font-size: 15px; }
.ob-bubble h2 { font-size: 14px; }
.ob-bubble h3 { font-size: 13.5px; }
.ob-bubble strong { font-weight: 600; color: #111; }
.ob-bubble em { font-style: italic; color: var(--muted); }
.ob-bubble ul, .ob-bubble ol { padding-left: 18px; margin: 5px 0; }
.ob-bubble li { margin: 3px 0; }
.ob-bubble p { margin: 3px 0; }
.ob-bubble hr { border: none; border-top: 1px solid #e2e8f0; margin: 8px 0; }
.ob-msg.user .ob-bubble strong { color: #fff; }

/* ── Tableaux HTML stylisés ── */
.ob-bubble table {
  width: 100%; border-collapse: collapse;
  margin: 10px 0; font-size: 12.5px;
  border-radius: 10px; overflow: hidden;
  box-shadow: 0 1px 4px rgba(165,24,24,0.1);
}
.ob-bubble thead tr { background: var(--primary); color: #fff; }
.ob-bubble thead th {
  padding: 8px 10px; text-align: left;
  font-weight: 600; font-size: 12px; border: none;
}
.ob-bubble tbody tr:nth-child(odd)  { background: #fff; }
.ob-bubble tbody tr:nth-child(even) { background: #fdf3f3; }
.ob-bubble tbody tr:hover { background: #fde8e8; transition: background .15s; }
.ob-bubble tbody td {
  padding: 7px 10px; border-bottom: 1px solid #fde8e8;
  vertical-align: top; color: var(--text);
}
.ob-bubble tbody tr:last-child td { border-bottom: none; }

/* ── Cartes établissements ── */
.ob-card {
  background: #fff; border: 1px solid #e2c4c4;
  border-radius: 12px; padding: 10px 12px;
  margin: 4px 0; display: flex; align-items: center;
  gap: 10px; cursor: default;
  transition: box-shadow .15s, border-color .15s;
}
.ob-card:hover {
  box-shadow: 0 2px 8px rgba(165,24,24,0.15);
  border-color: var(--primary);
}
.ob-card-icon {
  width: 36px; height: 36px; border-radius: 8px;
  background: #fde8e8; display: flex; align-items: center;
  justify-content: center; font-size: 16px; flex-shrink: 0;
}
.ob-card-body { flex: 1; min-width: 0; }
.ob-card-name {
  font-size: 13px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ob-card-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.ob-card-badge {
  font-size: 10px; padding: 2px 7px; border-radius: 10px;
  background: #fde8e8; color: var(--primary);
  font-weight: 600; flex-shrink: 0;
}

/* ── Actions sous message ── */
.ob-actions { display: flex; align-items: center; gap: 4px; padding: 2px 0; }
.ob-actions-sep { width: 1px; height: 16px; background: #e2e8f0; margin: 0 2px; }
.ob-icon-btn {
  width: 26px; height: 26px; border-radius: 7px;
  border: 1px solid #e2e8f0; background: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; transition: all .15s; position: relative;
}
.ob-icon-btn:hover { background: #f1f5f9; border-color: #cbd5e1; transform: scale(1.1); }
.ob-icon-btn.helpful:hover,  .ob-icon-btn.helpful.active  { background: #dcfce7; border-color: var(--green); }
.ob-icon-btn.unhelpful:hover,.ob-icon-btn.unhelpful.active { background: #fee2e2; border-color: var(--red); }
.ob-icon-btn.facebook:hover { background: #e8f0fe; border-color: #1877f2; }
.ob-icon-btn.whatsapp:hover { background: #dcfce7; border-color: #25d366; }
.ob-icon-btn.copy.copied    { background: #dcfce7; border-color: var(--green); }
.ob-icon-btn::after {
  content: attr(data-tip); position: absolute;
  bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: #1e293b; color: #fff; font-size: 10px; white-space: nowrap;
  padding: 3px 7px; border-radius: 5px; opacity: 0; pointer-events: none;
  transition: opacity .15s;
}
.ob-icon-btn:hover::after { opacity: 1; }

/* ── Typing indicator ── */
.ob-typing .ob-bubble { padding: 12px 14px; }
.ob-dots { display: flex; gap: 4px; align-items: center; }
.ob-dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: #94a3b8; animation: obBounce 1.2s infinite;
}
.ob-dots span:nth-child(2) { animation-delay: .2s; }
.ob-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes obBounce { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-6px)} }

/* ── Suggestions ── */
.ob-sugg { padding: 0 12px 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.ob-sugg button {
  font-size: 12px; padding: 5px 12px; border-radius: 20px;
  border: 1.5px solid #e2c4c4; background: #fdf6f6; color: var(--primary);
  cursor: pointer; transition: all .15s;
}
.ob-sugg button:hover { background: var(--primary); color: #fff; }

/* ── Barre de saisie ── */
.ob-bar {
  padding: 10px 12px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; align-items: center; flex-shrink: 0;
}
.ob-bar textarea {
  flex: 1; padding: 10px 15px; border-radius: 20px;
  border: 1.5px solid #e2c4c4; background: #fdf6f6;
  font-size: 13.5px; outline: none; color: var(--text);
  transition: border-color .15s, height .1s; font-family: inherit;
  resize: none; overflow: hidden;
  min-height: 40px; max-height: 120px;
  line-height: 1.5; display: block;
}
.ob-bar textarea:focus { border-color: var(--primary); background: #fff; }
.ob-send-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--primary); border: none; cursor: pointer;
  color: var(--yellow); font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: transform .1s, background .15s; flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(165,24,24,0.4);
}
.ob-send-btn:hover { background: var(--primary-d); }
.ob-send-btn:active { transform: scale(.93); }
.ob-send-btn.stopping {
  background: #64748b;
  box-shadow: 0 4px 12px rgba(100,116,139,0.4);
}

/* ── Message d'erreur + bouton Réessayer ── */
.ob-bubble-error {
  background: #fee2e2; color: #991b1b;
  border-left: 3px solid var(--red);
}
.ob-retry-btn {
  align-self: flex-start;
  padding: 5px 14px; border-radius: 20px; font-size: 12px; font-weight: 600;
  border: 1.5px solid var(--red); color: var(--red); background: #fff;
  cursor: pointer; transition: all .15s;
}
.ob-retry-btn:hover { background: var(--red); color: #fff; }

/* ── Footer ── */
.ob-footer {
  text-align: center; font-size: 11px;
  color: #94a3b8; padding: 4px 0 8px; flex-shrink: 0;
}
