/* AI Assistant Chat Sidebar — loaded on all admin pages via base_site.html */

.ai-chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9998;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #417690 0%, #315b70 100%);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}

.ai-chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0,0,0,0.3);
}

.ai-chat-fab svg {
  width: 24px;
  height: 24px;
  fill: #fff;
}

.ai-chat-fab-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 14px;
  height: 14px;
  background: #10b981;
  border-radius: 50%;
  border: 2px solid #fff;
}

/* Panel */
.ai-chat-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: 475px;
  max-height: calc(100vh - 48px);
  height: 700px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-chat-panel.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* Header */
.ai-chat-header {
  padding: 14px 16px;
  background: linear-gradient(135deg, #417690 0%, #315b70 100%);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.ai-chat-header-icon {
  width: 32px;
  height: 32px;
  background: rgba(255,255,255,0.18);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-chat-header-icon svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

.ai-chat-header-text {
  flex: 1;
}

.ai-chat-header-title {
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
}

.ai-chat-header-subtitle {
  color: rgba(255,255,255,0.75);
  font-size: 11px;
  margin: 1px 0 0;
}

.ai-chat-new {
  background: none;
  border: 1px solid rgba(255,255,255,0.3);
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  padding: 5px 8px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-family: inherit;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.ai-chat-new:hover {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.5);
  color: #fff;
}

.ai-chat-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.ai-chat-close:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

.ai-chat-close svg {
  width: 18px;
  height: 18px;
}

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

.ai-chat-messages::-webkit-scrollbar {
  width: 5px;
}

.ai-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

/* Message bubbles */
.ai-chat-msg {
  max-width: 88%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
}

.ai-chat-msg-user {
  align-self: flex-end;
  background: #417690;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-chat-msg-assistant {
  align-self: flex-start;
  background: #fff;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}

.ai-chat-msg-assistant p {
  margin: 0 0 8px;
}

.ai-chat-msg-assistant p:last-child {
  margin-bottom: 0;
}

.ai-chat-msg-assistant code {
  background: #f1f5f9;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}

.ai-chat-msg-assistant strong {
  font-weight: 600;
}

.ai-chat-msg-assistant ul, .ai-chat-msg-assistant ol {
  margin: 4px 0;
  padding-left: 18px;
}

.ai-chat-msg-assistant li {
  margin-bottom: 2px;
}

/* Typing indicator */
.ai-chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}

.ai-chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9ca3af;
  animation: ai-chat-bounce 1.4s infinite ease-in-out;
}

.ai-chat-typing-dot:nth-child(2) {
  animation-delay: 0.16s;
}

.ai-chat-typing-dot:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes ai-chat-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-5px); }
}

/* Welcome state */
.ai-chat-welcome {
  text-align: center;
  padding: 30px 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ai-chat-welcome-icon {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #417690 0%, #315b70 100%);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}

.ai-chat-welcome-icon svg {
  width: 26px;
  height: 26px;
  fill: #fff;
}

.ai-chat-welcome h3 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 700;
  color: #1f2937;
}

.ai-chat-welcome p {
  margin: 0 0 20px;
  font-size: 12.5px;
  color: #6b7280;
  line-height: 1.5;
}

.ai-chat-suggestions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.ai-chat-suggestion {
  padding: 9px 14px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 12.5px;
  color: #374151;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}

.ai-chat-suggestion:hover {
  border-color: #417690;
  background: #f0f7fb;
}

/* Input area */
.ai-chat-input-area {
  padding: 12px 14px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}

.ai-chat-input {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  font-family: inherit;
  resize: none;
  outline: none;
  line-height: 1.45;
  max-height: 100px;
  overflow-y: auto;
  transition: border-color 0.15s;
}

.ai-chat-input:focus {
  border-color: #417690;
}

.ai-chat-input::placeholder {
  color: #9ca3af;
}

.ai-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: #417690;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}

.ai-chat-send:hover {
  background: #315b70;
}

.ai-chat-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ai-chat-send svg {
  width: 16px;
  height: 16px;
  fill: #fff;
}

/* Error state */
.ai-chat-error {
  align-self: center;
  padding: 8px 14px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  font-size: 12px;
  color: #991b1b;
  text-align: center;
}

/* Attach button */
.ai-chat-attach {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color 0.15s, background 0.15s;
  color: #6b7280;
}

.ai-chat-attach:hover {
  border-color: #417690;
  background: #f0f7fb;
  color: #417690;
}

.ai-chat-attach svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* File preview strip (between messages and input) */
.ai-chat-file-previews {
  padding: 6px 14px 0;
  background: #fff;
  display: none;
  flex-wrap: wrap;
  gap: 6px;
}

.ai-chat-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px 4px 7px;
  background: #f0f7fb;
  border: 1px solid #bfdbf0;
  border-radius: 20px;
  font-size: 12px;
  color: #2c5f78;
  max-width: 320px;
}

.ai-chat-file-chip-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.ai-chat-file-chip-icon svg {
  fill: #417690;
}

.ai-chat-file-chip-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.ai-chat-file-chip-size {
  color: #6b7280;
  font-size: 11px;
  flex-shrink: 0;
}

.ai-chat-file-chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  padding: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b7280;
  flex-shrink: 0;
  border-radius: 50%;
  transition: background 0.12s, color 0.12s;
}

.ai-chat-file-chip-remove:hover {
  background: #dbeafe;
  color: #1d4ed8;
}

.ai-chat-file-chip-remove svg {
  width: 12px;
  height: 12px;
}

/* File chip in user message bubble */
.ai-chat-msg-file-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  opacity: 0.85;
  margin-bottom: 5px;
  padding: 3px 8px;
  background: rgba(255,255,255,0.15);
  border-radius: 12px;
  width: fit-content;
}

.ai-chat-msg-file-chip svg {
  fill: currentColor;
  flex-shrink: 0;
}

/* Drag-over state on the panel */
.ai-chat-panel.ai-chat-drag-over {
  box-shadow: 0 0 0 3px #417690, 0 12px 48px rgba(0,0,0,0.18);
}

.ai-chat-panel.ai-chat-drag-over::after {
  content: "Drop file here";
  position: absolute;
  inset: 0;
  background: rgba(65, 118, 144, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: #417690;
  border-radius: 14px;
  pointer-events: none;
}

/* h3/h4 inside assistant messages */
.ai-chat-msg-assistant h3 {
  font-size: 13px;
  font-weight: 700;
  margin: 10px 0 4px;
  color: #1f2937;
}

.ai-chat-msg-assistant h4 {
  font-size: 12.5px;
  font-weight: 600;
  margin: 8px 0 3px;
  color: #374151;
}

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