/**
 * ============================================================================
 * SOLID'SERVE - AI Console Styles
 * ============================================================================
 *
 * @file        ai-console.css
 * @description Floating action button + slide-in drawer for AI assistant
 * @version     001
 *
 * Copyright (c) 2026 Tutator Development Corp. All rights reserved.
 * ============================================================================
 */

/* =========================================
   FAB — Floating Action Button
   ========================================= */

.ai-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--color-primary, #C62828);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  z-index: 1000;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

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

.ai-fab:active {
  transform: scale(0.95);
}

.ai-fab svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.ai-fab.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.5);
}

/* Pulse animation on first load */
@keyframes ai-fab-pulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); }
  50% { box-shadow: 0 4px 16px rgba(198, 40, 40, 0.5), 0 0 0 8px rgba(198, 40, 40, 0.1); }
}

.ai-fab.pulse {
  animation: ai-fab-pulse 2s ease-in-out 3;
}


/* =========================================
   DRAWER — Right-side Panel
   ========================================= */

.ai-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.ai-drawer-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.ai-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 400px;
  max-width: 100vw;
  background: #fff;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
}

.ai-drawer.open {
  transform: translateX(0);
}

/* ---- Drawer Header ---- */

.ai-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-gray-200, #e5e7eb);
  background: var(--color-gray-50, #f9fafb);
  flex-shrink: 0;
}

.ai-drawer-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  color: var(--color-gray-800, #1f2937);
}

.ai-drawer-title svg {
  width: 20px;
  height: 20px;
  color: var(--color-primary, #C62828);
}

.ai-drawer-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ai-drawer-actions button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  color: var(--color-gray-500, #6b7280);
  transition: background 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-drawer-actions button:hover {
  background: var(--color-gray-100, #f3f4f6);
  color: var(--color-gray-700, #374151);
}

.ai-drawer-actions button svg {
  width: 18px;
  height: 18px;
}


/* ---- Messages Area ---- */

.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.ai-messages::-webkit-scrollbar-thumb {
  background: var(--color-gray-300, #d1d5db);
  border-radius: 4px;
}

/* Welcome state */
.ai-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 32px 24px;
  gap: 12px;
  color: var(--color-gray-500, #6b7280);
}

.ai-welcome-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--color-primary-bg, #FFEBEE);
  color: var(--color-primary, #C62828);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-welcome-icon svg {
  width: 24px;
  height: 24px;
}

.ai-welcome h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-gray-800, #1f2937);
  margin: 0;
}

.ai-welcome p {
  font-size: 13px;
  line-height: 1.5;
  margin: 0;
  max-width: 280px;
}

.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 8px;
}

.ai-suggestion-chip {
  padding: 6px 12px;
  border-radius: 16px;
  border: 1px solid var(--color-gray-200, #e5e7eb);
  background: #fff;
  font-size: 12px;
  color: var(--color-gray-600, #4b5563);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  white-space: nowrap;
}

.ai-suggestion-chip:hover {
  border-color: var(--color-primary, #C62828);
  background: var(--color-primary-bg, #FFEBEE);
  color: var(--color-primary, #C62828);
}


/* ---- Message Bubbles ---- */

.ai-msg {
  display: flex;
  gap: 8px;
  max-width: 100%;
}

.ai-msg.user {
  flex-direction: row-reverse;
}

.ai-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}

.ai-msg.assistant .ai-msg-avatar {
  background: var(--color-primary-bg, #FFEBEE);
  color: var(--color-primary, #C62828);
}

.ai-msg.user .ai-msg-avatar {
  background: var(--color-gray-200, #e5e7eb);
  color: var(--color-gray-600, #4b5563);
}

.ai-msg-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  max-width: calc(100% - 44px);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.ai-msg.assistant .ai-msg-bubble {
  background: var(--color-gray-50, #f9fafb);
  color: var(--color-gray-800, #1f2937);
  border-bottom-left-radius: 4px;
}

.ai-msg.user .ai-msg-bubble {
  background: var(--color-primary, #C62828);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Markdown inside assistant bubble */
.ai-msg.assistant .ai-msg-bubble p {
  margin: 0 0 8px;
}
.ai-msg.assistant .ai-msg-bubble p:last-child {
  margin-bottom: 0;
}
.ai-msg.assistant .ai-msg-bubble strong {
  font-weight: 600;
}
.ai-msg.assistant .ai-msg-bubble code {
  background: var(--color-gray-200, #e5e7eb);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}
.ai-msg.assistant .ai-msg-bubble ul,
.ai-msg.assistant .ai-msg-bubble ol {
  margin: 4px 0 8px;
  padding-left: 20px;
}
.ai-msg.assistant .ai-msg-bubble li {
  margin-bottom: 2px;
}
.ai-msg.assistant .ai-msg-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 12px;
}
.ai-msg.assistant .ai-msg-bubble th,
.ai-msg.assistant .ai-msg-bubble td {
  border: 1px solid var(--color-gray-200, #e5e7eb);
  padding: 4px 8px;
  text-align: left;
}
.ai-msg.assistant .ai-msg-bubble th {
  background: var(--color-gray-100, #f3f4f6);
  font-weight: 600;
}

/* Thinking indicator */
.ai-thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
}

.ai-thinking-dots {
  display: flex;
  gap: 4px;
}

.ai-thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-gray-400, #9ca3af);
  animation: ai-dot-bounce 1.4s ease-in-out infinite;
}

.ai-thinking-dots span:nth-child(2) { animation-delay: 0.16s; }
.ai-thinking-dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes ai-dot-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.ai-thinking-text {
  font-size: 12px;
  color: var(--color-gray-400, #9ca3af);
  font-style: italic;
}

/* Error state */
.ai-msg-error .ai-msg-bubble {
  background: var(--color-error-bg, #FFEBEE) !important;
  color: var(--color-error, #C62828) !important;
  border: 1px solid rgba(198, 40, 40, 0.2);
}


/* ---- Charts ---- */

.ai-chart-wrap {
  padding: 4px 0;
}

.ai-chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-gray-700, #374151);
  margin-bottom: 8px;
  text-align: center;
}

.ai-chart-svg {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
}

.ai-chart-svg text {
  font-family: 'DM Sans', -apple-system, sans-serif;
}

svg.ai-chart-bar-svg,
svg.ai-chart-hbar-svg {
  width: 100%;
}

.ai-chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 10px;
  justify-content: center;
}

.ai-chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--color-gray-600, #4b5563);
  white-space: nowrap;
}

.ai-chart-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ai-chart-val {
  color: var(--color-gray-400, #9ca3af);
  font-size: 10px;
}


/* ---- Input Area ---- */

.ai-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--color-gray-200, #e5e7eb);
  background: #fff;
  flex-shrink: 0;
}

.ai-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--color-gray-50, #f9fafb);
  border: 1px solid var(--color-gray-200, #e5e7eb);
  border-radius: 12px;
  padding: 8px 12px;
  transition: border-color 0.2s;
}

.ai-input-row:focus-within {
  border-color: var(--color-primary, #C62828);
  box-shadow: 0 0 0 2px rgba(198, 40, 40, 0.1);
}

.ai-input-row textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  padding: 2px 0;
  color: var(--color-gray-800, #1f2937);
  max-height: 120px;
  outline: none;
}

.ai-input-row textarea::placeholder {
  color: var(--color-gray-400, #9ca3af);
}

.ai-send-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--color-primary, #C62828);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.ai-send-btn:hover {
  background: var(--color-primary-dark, #B71C1C);
}

.ai-send-btn:active {
  transform: scale(0.92);
}

.ai-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ai-send-btn svg {
  width: 16px;
  height: 16px;
}

.ai-input-hint {
  font-size: 11px;
  color: var(--color-gray-400, #9ca3af);
  text-align: center;
  margin-top: 6px;
}

.ai-input-hint kbd {
  background: var(--color-gray-100, #f3f4f6);
  border: 1px solid var(--color-gray-200, #e5e7eb);
  border-radius: 3px;
  padding: 1px 4px;
  font-size: 10px;
  font-family: inherit;
}


/* =========================================
   RESPONSIVE
   ========================================= */

@media (max-width: 768px) {
  .ai-drawer {
    width: 100%;
  }

  .ai-fab {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
  }

  .ai-fab svg {
    width: 22px;
    height: 22px;
  }
}

@media (max-width: 480px) {
  .ai-msg-bubble {
    max-width: calc(100% - 36px);
    font-size: 13px;
  }

  .ai-input-hint {
    display: none;
  }
}
