/* ═══════════════════════════════════════════════════════════════════════════════
   ELOP Intelligence Chat Widget
   Slide-out panel on the right side of every page
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ── Floating Chat Button ──────────────────────────────────────────────────── */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(99,102,241,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  transition: transform 0.2s, box-shadow 0.2s;
  font-size: 24px;
}
.chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(99,102,241,0.5);
}
.chat-fab.hidden { display: none; }

/* ── Chat Panel ────────────────────────────────────────────────────────────── */
.chat-panel {
  position: fixed;
  top: 0;
  right: -420px;
  width: 400px;
  height: 100vh;
  background: #fff;
  box-shadow: -4px 0 24px rgba(0,0,0,0.12);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.chat-panel.open { right: 0; }

/* ── Header ────────────────────────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  flex-shrink: 0;
}
.chat-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
}
.chat-header-title svg { width: 20px; height: 20px; }
.chat-header-actions { display: flex; gap: 4px; }
.chat-header-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 6px;
  color: #fff;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background 0.15s;
}
.chat-header-btn:hover { background: rgba(255,255,255,0.25); }

/* ── Messages Area ─────────────────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8fafc;
}

/* ── Message Bubbles ───────────────────────────────────────────────────────── */
.chat-msg {
  max-width: 92%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.5;
  word-wrap: break-word;
}
.chat-msg.user {
  align-self: flex-end;
  background: #6366f1;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant {
  align-self: flex-start;
  background: #fff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}
.chat-msg.assistant strong { color: #4f46e5; }
.chat-msg.error {
  align-self: flex-start;
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  border-bottom-left-radius: 4px;
}

/* ── Inline Data Tables ────────────────────────────────────────────────────── */
.chat-table-wrap {
  margin-top: 8px;
  overflow-x: auto;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
}
.chat-table {
  width: 100%;
  font-size: 12px;
  border-collapse: collapse;
  white-space: nowrap;
}
.chat-table th {
  background: #f1f5f9;
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  color: #475569;
  border-bottom: 1px solid #e2e8f0;
  position: sticky;
  top: 0;
}
.chat-table td {
  padding: 5px 10px;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
}
.chat-table tr:hover td { background: #f8fafc; }
.chat-table tr:last-child td { border-bottom: none; }

/* ── Navigation Links ──────────────────────────────────────────────────────── */
.chat-nav-links {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chat-nav-btn {
  display: inline-block;
  padding: 4px 12px;
  background: #eef2ff;
  color: #4f46e5;
  border: 1px solid #c7d2fe;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
}
.chat-nav-btn:hover {
  background: #4f46e5;
  color: #fff;
  border-color: #4f46e5;
}

/* ── SQL Toggle ────────────────────────────────────────────────────────────── */
.chat-sql-toggle {
  margin-top: 6px;
  font-size: 11px;
  color: #94a3b8;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.chat-sql-toggle:hover { color: #64748b; }
.chat-sql-block {
  display: none;
  margin-top: 4px;
  padding: 8px;
  background: #1e293b;
  color: #a5f3fc;
  border-radius: 6px;
  font-family: 'Fira Code', 'Cascadia Mono', monospace;
  font-size: 11px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.chat-sql-block.show { display: block; }

/* ── Meta Info (model, tokens, time) ───────────────────────────────────────── */
.chat-meta {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  font-size: 10.5px;
  color: #94a3b8;
}
.chat-meta span {
  background: #f1f5f9;
  padding: 1px 6px;
  border-radius: 4px;
}

/* ── Typing Indicator ──────────────────────────────────────────────────────── */
.chat-typing {
  align-self: flex-start;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  display: none;
}
.chat-typing.show { display: flex; gap: 4px; }
.chat-typing .dot {
  width: 7px;
  height: 7px;
  background: #94a3b8;
  border-radius: 50%;
  animation: chatBounce 1.4s infinite ease-in-out;
}
.chat-typing .dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes chatBounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* ── Suggestion Chips ──────────────────────────────────────────────────────── */
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 16px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}
.chat-chip {
  padding: 5px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 16px;
  font-size: 12px;
  color: #475569;
  background: #fff;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.chat-chip:hover {
  background: #6366f1;
  color: #fff;
  border-color: #6366f1;
}

/* ── Input Area ────────────────────────────────────────────────────────────── */
.chat-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
  resize: none;
  min-height: 20px;
  max-height: 80px;
  line-height: 1.4;
}
.chat-input:focus { border-color: #6366f1; box-shadow: 0 0 0 2px rgba(99,102,241,0.1); }
.chat-input::placeholder { color: #94a3b8; }
.chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: #6366f1;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.chat-send-btn:hover { background: #4f46e5; }
.chat-send-btn:disabled { background: #c7d2fe; cursor: not-allowed; }

/* ── Settings Panel ────────────────────────────────────────────────────────── */
.chat-settings {
  display: none;
  padding: 16px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}
.chat-settings.show { display: block; }
.chat-settings-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.chat-settings-row label {
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  min-width: 65px;
}
.chat-settings-row select,
.chat-settings-row input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 12px;
  outline: none;
}
.chat-settings-row select:focus,
.chat-settings-row input:focus { border-color: #6366f1; }
.chat-settings-save {
  padding: 6px 16px;
  background: #6366f1;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.chat-settings-save:hover { background: #4f46e5; }
.chat-settings-status {
  font-size: 11px;
  margin-left: 8px;
  color: #059669;
}

/* ── Welcome Message ───────────────────────────────────────────────────────── */
.chat-welcome {
  text-align: center;
  padding: 24px 16px;
  color: #64748b;
}
.chat-welcome h3 {
  color: #1e293b;
  margin: 0 0 8px;
  font-size: 16px;
}
.chat-welcome p {
  font-size: 13px;
  line-height: 1.5;
  margin: 0;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .chat-panel {
    width: 100vw;
    right: -100vw;
  }
  .chat-panel.open { right: 0; }
}
