/* ─── Chat Widget ──────────────────────────────────────────────────────────── */

.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent-a-grad);
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: transform 0.2s, box-shadow 0.2s;
}
.chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(121, 71, 248, 0.3);
}
.chat-fab svg {
  width: 24px;
  height: 24px;
  fill: white;
}

.chat-panel {
  position: fixed;
  bottom: 88px;
  right: 24px;
  width: 400px;
  height: 520px;
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(45, 42, 38, 0.15);
  z-index: 9998;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--font);
  transition: width 0.3s ease, height 0.3s ease;
}
.chat-panel.open {
  display: flex;
  animation: chatSlideUp 0.25s ease-out;
}

@keyframes chatSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-header {
  padding: 14px 16px;
  background: var(--accent-a-grad);
  color: white;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.chat-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.chat-expand {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  opacity: 0.7;
  padding: 2px 4px;
  border-radius: 4px;
  transition: opacity 0.2s, background 0.2s;
}
.chat-expand:hover { opacity: 1; background: rgba(255,255,255,0.15); }
.chat-close {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 18px;
  opacity: 0.8;
  padding: 0 4px;
}
.chat-close:hover { opacity: 1; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--accent-a-soft);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
}
.chat-msg.bot {
  align-self: flex-start;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.chat-msg.bot strong { color: var(--accent-a); }
.chat-msg.error {
  align-self: flex-start;
  background: var(--red-soft);
  color: var(--red);
  font-size: 12px;
}

.chat-msg-sql {
  margin-top: 6px;
  padding: 6px 8px;
  background: rgba(45, 42, 38, 0.04);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  cursor: pointer;
  overflow: hidden;
  max-height: 20px;
  transition: max-height 0.3s;
}
.chat-msg-sql.expanded {
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
}
.chat-msg-sql::before {
  content: "SQL \25B6";
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.chat-msg-sql.expanded::before {
  content: "SQL \25BC";
}

.chat-dashboard-btn {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 16px;
  background: linear-gradient(135deg, #e85d26, #f39c12);
  color: #fff;
  text-decoration: none;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  transition: opacity 0.2s, transform 0.15s;
  box-shadow: 0 2px 8px rgba(232, 93, 38, 0.25);
}
.chat-dashboard-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(232, 93, 38, 0.35);
}

.chat-typing {
  align-self: flex-start;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.chat-typing .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: dotPulse 1.2s infinite;
}
.chat-typing .dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

.chat-input-bar {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  background: white;
}
.chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: var(--font);
  background: var(--bg-input);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
}
.chat-input:focus {
  border-color: var(--accent-a);
}
.chat-input::placeholder {
  color: var(--text-muted);
}
.chat-send {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent-a-grad);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s;
}
.chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.chat-send svg {
  width: 16px;
  height: 16px;
  fill: white;
}

/* ─── Expanded mode ───────────────────────────────────────────────────────── */
.chat-panel.expanded {
  width: 700px;
  height: 680px;
  transition: width 0.3s ease, height 0.3s ease;
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .chat-panel {
    width: calc(100vw - 16px);
    height: calc(100vh - 120px);
    right: 8px;
    bottom: 80px;
    border-radius: var(--radius-sm);
  }
}
