/* ═══════════════════════════════════════════════════════════════════
 * ai-chat.css — Slide-in Asistente IA panel for the dashboard pages
 *
 * Triggered by /js/ai-chat.js (`.tb-ai` clicks across all dashboards).
 * The panel pins to the right edge, fixed-height, with the message
 * thread scrolling internally.
 * ═══════════════════════════════════════════════════════════════════ */

.ai-chat-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 9000;
}
.ai-chat-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.ai-chat-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 420px;
  max-width: 100vw;
  background: #ffffff;
  display: flex; flex-direction: column;
  box-shadow: -16px 0 40px rgba(15,23,42,0.18);
  transform: translateX(100%);
  transition: transform 0.22s cubic-bezier(.22,.61,.36,1);
  z-index: 9001;
  font-family: var(--sans, system-ui, -apple-system, sans-serif);
  color: #131318;
}
.ai-chat-panel.open { transform: translateX(0); }

/* HEAD */
.ai-chat-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(15,23,42,0.08);
  flex-shrink: 0;
}
.ai-chat-avatar {
  width: 40px; height: 40px; border-radius: 8px;
  background: linear-gradient(135deg, #cc6b3d, #e8855a);
  display: grid; place-items: center;
  flex-shrink: 0;
  box-shadow: 0 3px 10px rgba(204,107,61,0.35);
}
.ai-chat-avatar svg { width: 20px; height: 20px; fill: #fff; }
.ai-chat-id { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.ai-chat-title {
  font-size: 14px; font-weight: 700; color: #131318;
  line-height: 1.1;
}
.ai-chat-status {
  display: flex; align-items: center; gap: 4px;
  font-size: 11.5px; color: #6c6a72;
  margin-top: 3px;
}
.ai-chat-status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #22C55E;
  box-shadow: 0 0 0 2.5px rgba(34,197,94,0.22);
  flex-shrink: 0;
}
.ai-chat-powered {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(217,119,87,0.10);
  border: 1px solid rgba(217,119,87,0.28);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px; font-weight: 600;
  color: #c96338;
  white-space: nowrap;
  flex-shrink: 0;
}
.ai-chat-powered svg { width: 12px; height: 12px; fill: currentColor; }
.ai-chat-close {
  width: 34px; height: 34px;
  background: rgba(15,23,42,0.06);
  border: none; border-radius: 8px;
  cursor: pointer;
  display: grid; place-items: center;
  color: #131318;
  flex-shrink: 0;
}
.ai-chat-close svg { width: 14px; height: 14px; fill: currentColor; }
.ai-chat-close:hover { background: rgba(15,23,42,0.12); }

/* MESSAGES */
.ai-chat-msgs {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px 12px;
  background: #fafaf6;
  display: flex; flex-direction: column; gap: 10px;
}
.ai-chat-msg {
  max-width: 84%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px; line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.ai-chat-msg.bot {
  align-self: flex-start;
  background: #ffffff;
  color: #131318;
  border: 1px solid rgba(15,23,42,0.08);
  border-bottom-left-radius: 4px;
}
.ai-chat-msg.user {
  align-self: flex-end;
  background: #131318;
  color: #ffffff;
  border-bottom-right-radius: 4px;
}
.ai-chat-msg.error {
  align-self: stretch;
  background: rgba(226,72,58,0.08);
  color: #b53322;
  border: 1px solid rgba(226,72,58,0.22);
  font-size: 12.5px;
  text-align: center;
}

.ai-chat-typing {
  align-self: flex-start;
  background: #fff;
  border: 1px solid rgba(15,23,42,0.08);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: inline-flex; gap: 4px;
}
.ai-chat-typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #6c6a72;
  opacity: 0.4;
  animation: ai-chat-blink 1.2s infinite;
}
.ai-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-chat-blink {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* SUGGESTIONS (shown before first user message) — matches the legacy
   broker.html chat: faint terracotta-tinted chips */
.ai-chat-suggestions {
  display: flex; flex-wrap: wrap; gap: 7px;
  padding: 10px 18px 12px;
  border-top: 1px solid rgba(15,23,42,0.06);
  background: #fff;
  flex-shrink: 0;
}
.ai-chat-chip {
  padding: 6px 13px;
  border-radius: 999px;
  background: rgba(204,107,61,0.07);
  border: 1px solid rgba(204,107,61,0.22);
  color: #c96338;
  font-family: inherit; font-size: 12.5px; font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  line-height: 1.4;
}
.ai-chat-chip:hover {
  background: rgba(204,107,61,0.14);
  border-color: #cc6b3d;
  transform: translateY(-1px);
}
.ai-chat-suggestions[hidden] { display: none; }

/* COMPOSER */
.ai-chat-composer {
  border-top: 1px solid rgba(15,23,42,0.06);
  padding: 12px 14px 6px;
  display: grid; grid-template-columns: 1fr auto;
  gap: 8px; align-items: flex-end;
  background: #fff;
  flex-shrink: 0;
}
.ai-chat-attrib {
  text-align: center;
  font-size: 10.5px;
  color: #8a8a92;
  padding: 0 14px 10px;
  background: #fff;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  flex-shrink: 0;
  opacity: 0.85;
}
.ai-chat-attrib svg { width: 10px; height: 10px; fill: currentColor; opacity: 0.6; }
.ai-chat-composer textarea {
  width: 100%;
  min-height: 40px; max-height: 140px;
  resize: none;
  background: #fafaf6;
  border: 1px solid rgba(15,23,42,0.10);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit; font-size: 13.5px;
  color: #131318;
  outline: none;
  line-height: 1.45;
}
.ai-chat-composer textarea:focus { border-color: rgba(15,23,42,0.32); background: #fff; }
.ai-chat-send {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: #131318;
  color: #fff;
  border: none;
  display: grid; place-items: center;
  cursor: pointer;
  transition: opacity 0.12s;
}
.ai-chat-send svg { width: 16px; height: 16px; fill: #fff; }
.ai-chat-send:hover { opacity: 0.85; }
.ai-chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

@media (max-width: 520px) {
  .ai-chat-panel { width: 100vw; }
}
