/* ── AI Copilot floating panel ──────────────────────────────────────────────── */

#ai-copilot-toggle {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 1050;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6f42c1, #0d6efd);
  color: #fff;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(111, 66, 193, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
#ai-copilot-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(111, 66, 193, 0.55);
}

/* Panel */
#ai-copilot-panel {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 380px;
  max-width: 100vw;
  height: 520px;
  max-height: 90vh;
  z-index: 1049;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.15);
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}
#ai-copilot-panel.open {
  transform: translateY(0);
}

/* Header */
#ai-copilot-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, #6f42c1, #0d6efd);
  color: #fff;
  flex-shrink: 0;
}
#ai-copilot-header .ai-title {
  font-weight: 600;
  font-size: 0.95rem;
  flex: 1;
}
#ai-copilot-header .ai-subtitle {
  font-size: 0.7rem;
  opacity: 0.8;
}
#ai-copilot-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  line-height: 1;
  opacity: 0.85;
}
#ai-copilot-close:hover { opacity: 1; background: rgba(255,255,255,0.15); }

/* Messages area */
#ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: #f8f9fa;
}

.ai-msg {
  max-width: 88%;
  padding: 0.55rem 0.8rem;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-break: break-word;
}
.ai-msg.user {
  align-self: flex-end;
  background: #0d6efd;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-msg.assistant {
  align-self: flex-start;
  background: #fff;
  color: #212529;
  border: 1px solid #e9ecef;
  border-bottom-left-radius: 4px;
}
.ai-msg.error {
  align-self: flex-start;
  background: #fff3cd;
  color: #664d03;
  border: 1px solid #ffc107;
  font-size: 0.82rem;
}
.ai-msg table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.4rem;
  font-size: 0.8rem;
}
.ai-msg th, .ai-msg td {
  border: 1px solid #dee2e6;
  padding: 0.25rem 0.4rem;
  text-align: left;
}
.ai-msg th { background: #e9ecef; font-weight: 600; }

/* Typing indicator */
.ai-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.55rem 0.9rem;
  background: #fff;
  border: 1px solid #e9ecef;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}
.ai-typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #6f42c1;
  animation: ai-bounce 1.2s infinite;
}
.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-5px); }
}

/* Suggestions */
.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 0.85rem 0.5rem;
  background: #f8f9fa;
}
.ai-suggestion-btn {
  font-size: 0.75rem;
  padding: 0.25rem 0.55rem;
  border: 1px solid #c4b5fd;
  border-radius: 20px;
  background: #fff;
  color: #6f42c1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.ai-suggestion-btn:hover { background: #6f42c1; color: #fff; border-color: #6f42c1; }

/* Input bar */
#ai-chat-form {
  display: flex;
  gap: 0.4rem;
  padding: 0.65rem 0.85rem;
  border-top: 1px solid #e9ecef;
  background: #fff;
  flex-shrink: 0;
}
#ai-chat-input {
  flex: 1;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s;
}
#ai-chat-input:focus { border-color: #6f42c1; }
#ai-chat-send {
  background: linear-gradient(135deg, #6f42c1, #0d6efd);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
  font-size: 0.875rem;
  cursor: pointer;
  transition: opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
#ai-chat-send:disabled { opacity: 0.55; cursor: not-allowed; }
#ai-chat-send:not(:disabled):hover { opacity: 0.9; }

/* Dark mode */
body.dark-mode #ai-copilot-panel { background: #1a1a2e; }
body.dark-mode #ai-chat-messages { background: #16213e; }
body.dark-mode .ai-msg.assistant { background: #0f3460; color: #e0e0e0; border-color: #1a4a80; }
body.dark-mode .ai-msg.error { background: #3a2a00; color: #ffd166; border-color: #856404; }
body.dark-mode #ai-chat-form { background: #1a1a2e; border-top-color: #0f3460; }
body.dark-mode #ai-chat-input { background: #0f3460; color: #e0e0e0; border-color: #1a4a80; }
body.dark-mode .ai-suggestions { background: #16213e; }
body.dark-mode .ai-suggestion-btn { background: #0f3460; color: #c4b5fd; border-color: #4c3a8f; }
body.dark-mode .ai-suggestion-btn:hover { background: #6f42c1; color: #fff; }
body.dark-mode .ai-msg table th { background: #0a2540; }
body.dark-mode .ai-msg th, body.dark-mode .ai-msg td { border-color: #1a4a80; }

/* Mobile: full-width panel */
@media (max-width: 480px) {
  #ai-copilot-panel { width: 100vw; border-radius: 16px 16px 0 0; }
}
