/* ================================================================
   AI Chatbox Floating Component — assets/ai_chatbox_component.css
   ================================================================
   All selectors are scoped to .ai-chatbox-* to avoid collisions.
   Do not edit style.css — add overrides here instead.
   ================================================================ */

/* ----------------------------------------------------------------
   Floating Action Button (FAB)
   ---------------------------------------------------------------- */

.ai-chatbox-fab {
  position: fixed;
  bottom: 40px;
  right: 78px;
  z-index: 1050;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #3b82f6;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.45), 0 1px 4px rgba(0, 0, 0, 0.12);
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
  outline-offset: 3px;
}

.ai-chatbox-fab:hover {
  background: #2563eb;
  box-shadow: 0 6px 22px rgba(59, 130, 246, 0.55), 0 2px 6px rgba(0, 0, 0, 0.14);
  transform: translateY(-2px);
}

.ai-chatbox-fab:active {
  transform: translateY(0);
  box-shadow: 0 3px 10px rgba(59, 130, 246, 0.4);
}

.ai-chatbox-fab:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 3px;
}

/* ----------------------------------------------------------------
   Chat Panel
   ---------------------------------------------------------------- */

.ai-chatbox-panel {
  position: fixed;
  bottom: 104px;
  right: 78px;
  width: min(460px, calc(100vw - 20px));
  height: min(520px, calc(100dvh - 120px));
  z-index: 1049;
  border-radius: 14px;
  background: #ffffff;
  box-shadow:
    0 8px 40px rgba(0, 0, 0, 0.16),
    0 2px 10px rgba(0, 0, 0, 0.09);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Collapsed state */
  transform: scale(0.92) translateY(10px);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 0.24s cubic-bezier(0.34, 1.3, 0.64, 1),
    opacity 0.18s ease;
  transform-origin: bottom right;
}

.ai-chatbox-panel.ai-chatbox-open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ----------------------------------------------------------------
   Panel Header
   ---------------------------------------------------------------- */

.ai-chatbox-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  color: #fff;
  border-radius: 14px 14px 0 0;
  flex-shrink: 0;
  user-select: none;
}

.ai-chatbox-panel-title {
  font-weight: 600;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-chatbox-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* Override dbc.Button link style inside header */
.ai-chatbox-header-btn.btn-link {
  color: rgba(255, 255, 255, 0.82) !important;
  text-decoration: none !important;
  padding: 4px 8px !important;
  border-radius: 6px !important;
  transition: background 0.1s, color 0.1s !important;
  line-height: 1 !important;
}

.ai-chatbox-header-btn.btn-link:hover {
  color: #fff !important;
  background: rgba(255, 255, 255, 0.16) !important;
}

.ai-chatbox-close-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.82);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 1px 7px 3px;
  border-radius: 6px;
  transition: color 0.1s, background 0.1s;
}

.ai-chatbox-close-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
}

/* ----------------------------------------------------------------
   Body (messages area + history overlay container)
   ---------------------------------------------------------------- */

.ai-chatbox-body {
  position: relative;
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ----------------------------------------------------------------
   Messages scroll area
   ---------------------------------------------------------------- */

.ai-chatbox-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
  min-height: 0;
}

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

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

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

.ai-chatbox-messages::-webkit-scrollbar-thumb:hover {
  background: #cbd5e1;
}

/* ----------------------------------------------------------------
   Welcome message
   ---------------------------------------------------------------- */

.ai-chatbox-welcome {
  align-self: center;
  text-align: center;
  color: #64748b;
  font-size: 0.855rem;
  padding: 24px 16px;
  max-width: 280px;
  line-height: 1.55;
}

.ai-chatbox-welcome-icon {
  font-size: 2rem;
  color: #93c5fd;
  display: block;
  margin-bottom: 10px;
}

/* ----------------------------------------------------------------
   Message bubbles
   ---------------------------------------------------------------- */

.ai-chatbox-msg {
  font-size: 0.868rem;
  line-height: 1.52;
  max-width: 88%;
  word-break: break-word;
}

/* User bubble — right-aligned, blue */
.ai-chatbox-msg-user {
  align-self: flex-end;
  background: #3b82f6;
  color: #fff;
  border-radius: 14px 14px 4px 14px;
  padding: 8px 12px;
}

.ai-chatbox-msg-user b {
  display: block;
  font-size: 0.72rem;
  opacity: 0.72;
  margin-bottom: 2px;
}

.ai-chatbox-msg-user .dash-markdown p:last-child {
  margin-bottom: 0;
}

.ai-chatbox-msg-user .dash-markdown {
  color: #fff;
  font-size: 0.868rem;
}

/* Bot bubble — left-aligned, light grey */
.ai-chatbox-msg-bot {
  align-self: flex-start;
  background: #f1f5f9;
  color: #1e293b;
  border-radius: 14px 14px 14px 4px;
  padding: 8px 12px;
}

.ai-chatbox-msg-bot b {
  display: block;
  font-size: 0.72rem;
  color: #64748b;
  margin-bottom: 2px;
}

.ai-submit-button{
    align-self: flex-end;
    min-height: 38px;
}

.ai-chatbox-msg-bot .dash-markdown {
  font-size: 0.868rem;
  color: #1e293b;
}

.ai-chatbox-msg-bot .dash-markdown p:last-child {
  margin-bottom: 0;
}

.ai-chatbox-msg-bot .dash-markdown table {
  font-size: 0.8rem;
  width: 100%;
  border-collapse: collapse;
  margin: 6px 0;
}

.ai-chatbox-msg-bot .dash-markdown th,
.ai-chatbox-msg-bot .dash-markdown td {
  border: 1px solid #e2e8f0;
  padding: 4px 8px;
  text-align: left;
}

.ai-chatbox-msg-bot .dash-markdown th {
  background: #e8edf4;
  font-weight: 600;
}

.ai-chatbox-msg-bot .dash-markdown blockquote {
  border-left: 3px solid #93c5fd;
  padding-left: 10px;
  margin: 6px 0;
  color: #475569;
  font-style: italic;
}

/* Thinking / loading indicator */
.ai-chatbox-thinking {
  align-self: flex-start;
  color: #94a3b8;
  font-size: 0.82rem;
  padding: 8px 12px;
  background: #f8fafc;
  border-radius: 14px 14px 14px 4px;
  border: 1px solid #e2e8f0;
}

/* ----------------------------------------------------------------
   Tool call notification card
   ---------------------------------------------------------------- */

.ai-chatbox-tool-card {
  align-self: flex-start;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 0.78rem;
  color: #166534;
  display: flex;
  align-items: baseline;
  gap: 5px;
  max-width: 96%;
  flex-wrap: wrap;
}

.ai-chatbox-tool-icon {
  color: #16a34a;
  flex-shrink: 0;
}

.ai-chatbox-tool-result {
  color: #6b7280;
  font-style: italic;
}

/* ----------------------------------------------------------------
   Input bar
   ---------------------------------------------------------------- */

.ai-chatbox-input-bar {
  padding: 9px 11px;
  border-top: 1px solid #e2e8f0;
  background: #fafafa;
  flex-shrink: 0;
}

.ai-chatbox-input-bar .input-group {
  gap: 0;
}

.ai-chatbox-input-bar .input-group textarea.form-control {
  border-radius: 10px 0 0 10px !important;
  font-size: 0.868rem !important;
  border-color: #d1d5db !important;
  background: #fff;
  transition: border-color 0.15s;
}

.ai-chatbox-input-bar .input-group textarea.form-control:focus {
  border-color: #3b82f6 !important;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15) !important;
}

.ai-chatbox-input-bar .input-group .btn {
  border-radius: 0 10px 10px 0 !important;
  padding: 0 14px !important;
}

/* ----------------------------------------------------------------
   History overlay (slides in over the messages area)
   ---------------------------------------------------------------- */

.ai-chatbox-history-overlay {
  position: absolute;
  inset: 0;
  background: #fff;
  display: flex;
  flex-direction: column;
  transform: translateX(102%);
  transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  z-index: 5;
}

.ai-chatbox-history-overlay.ai-chatbox-history-visible {
  transform: translateX(0);
}

.ai-chatbox-history-header {
  display: flex;
  align-items: center;
  padding: 9px 12px;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
  font-size: 0.9rem;
  background: #f8fafc;
}

/* Back button inside history header */
.ai-chatbox-back-btn.btn-link {
  font-size: 0.8rem !important;
  padding: 2px 6px !important;
  color: #3b82f6 !important;
  text-decoration: none !important;
  border-radius: 5px !important;
}

.ai-chatbox-back-btn.btn-link:hover {
  background: #eff6ff !important;
}

/* ----------------------------------------------------------------
   Conversation list (inside history overlay)
   ---------------------------------------------------------------- */

.ai-chatbox-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px 10px;
}

.ai-chatbox-history-list::-webkit-scrollbar {
  width: 4px;
}

.ai-chatbox-history-list::-webkit-scrollbar-thumb {
  background: #e2e8f0;
  border-radius: 4px;
}

.ai-chatbox-date-group {
  font-size: 0.7rem;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 8px 6px 3px;
  margin: 0;
}

.ai-chatbox-conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
  margin-bottom: 1px;
  border-left: 3px solid transparent;
}

.ai-chatbox-conv-item:hover {
  background: #f1f5f9;
}

.ai-chatbox-conv-item.ai-chatbox-conv-active {
  background: #eff6ff;
  border-left-color: #3b82f6;
}

.ai-chatbox-conv-title {
  flex: none;
  font-size: 0.83rem;
  font-weight: 500;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  max-width: 100%;
}

.ai-chatbox-conv-item:hover .ai-chatbox-conv-title {
  color: #1d4ed8;
}

.ai-chatbox-conv-preview {
  font-size: 0.74rem;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.ai-chatbox-conv-actions {
  display: flex;
  gap: 1px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.12s;
}

.ai-chatbox-conv-item:hover .ai-chatbox-conv-actions {
  opacity: 1;
}

/* Action buttons (edit / delete) */
.ai-chatbox-conv-action-btn.btn-link {
  background: none !important;
  color: #94a3b8 !important;
  padding: 3px 6px !important;
  font-size: 0.74rem !important;
  border-radius: 5px !important;
  text-decoration: none !important;
  line-height: 1 !important;
  border: none !important;
}

.ai-chatbox-conv-action-btn.btn-link:hover {
  color: #475569 !important;
  background: #e2e8f0 !important;
}

.ai-chatbox-conv-action-btn.btn-link.text-danger:hover {
  color: #dc2626 !important;
  background: #fee2e2 !important;
}

/* Empty history state */
.ai-chatbox-empty-history {
  text-align: center;
  color: #94a3b8;
  font-size: 0.83rem;
  padding: 28px 16px;
}

/* ----------------------------------------------------------------
   Responsive breakpoints
   ---------------------------------------------------------------- */

/* Medium screens: tighten horizontal margin so panel never clips */
@media (max-width: 600px) {
  .ai-chatbox-panel {
    right: max(8px, calc((100vw - min(460px, calc(100vw - 20px))) / 2));
    bottom: max(74px, min(104px, 8vh));
  }

  .ai-chatbox-fab {
    right: max(12px, min(78px, 5vw));
    bottom: max(20px, min(40px, 3vh));
  }
}

/* Small screens: snap to near-full-width with tight edges */
@media (max-width: 480px) {
  .ai-chatbox-panel {
    right: 8px;
    bottom: 76px;
  }

  .ai-chatbox-fab {
    right: 16px;
    bottom: 18px;
  }
}

/* Very small screens: shrink FAB slightly */
@media (max-width: 360px) {
  .ai-chatbox-fab {
    width: 46px;
    height: 46px;
    font-size: 1.05rem;
  }
}
