/* ============================================================
   Styles OWNED by the Ask AI module
   (convention: css/modules/<module-name>.css)
   ============================================================ */

/* The page is a full-height flex column: the conversation grows to
   fill the screen, the composer (suggestions + input) stays pinned
   at the bottom. Height = viewport minus .app-content paddings
   (mobile: fixed top bar + bottom tab bar). */
.ai-page {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--lc-topbar-h) - var(--safe-top) - var(--lc-bottomnav-h) - var(--safe-bottom) - 28px);
  min-height: 320px;
}

@media (min-width: 992px) {
  /* desktop: no bars, .app-content has 24px paddings */
  .ai-page {
    height: calc(100dvh - 48px);
  }
}

/* Conversation box — takes all remaining vertical space */
.ai-chat-box {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  background: #f8f9fb;
  border: 1px solid #e9ecf1;
  border-radius: 10px;
  padding: 12px;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 992px) {
  .ai-chat-box {
    padding: 16px;
  }
}

/* Composer pinned under the conversation */
.ai-composer {
  flex: 0 0 auto;
  padding-top: 10px;
}

.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

/* One message row */
.ai-msg {
  display: flex;
  margin-bottom: 12px;
}

.ai-msg.user {
  justify-content: flex-end;
}

.ai-bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.5;
  word-break: break-word;
}

.ai-msg.user .ai-bubble {
  background: #0d6efd;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-msg.assistant .ai-bubble {
  background: #fff;
  border: 1px solid #e9ecf1;
  border-bottom-left-radius: 4px;
  max-width: 90%; /* answers with tables need more room */
  position: relative;
  padding-right: 36px; /* room for the copy button */
}

/* Copy-answer button (top-right of every AI bubble) */
.ai-copy {
  position: absolute;
  top: 6px;
  right: 6px;
  border: 0;
  background: transparent;
  color: #aab3c2;
  padding: 3px 5px;
  border-radius: 6px;
  line-height: 1;
  font-size: 0.9rem;
}

.ai-copy:hover {
  color: #0d6efd;
  background: #eef4ff;
}

.ai-copy.copied {
  color: #198754;
}

/* ---------- Rich content inside an answer ---------- */

/* tables (markdown or sanitized HTML) — scroll sideways when wide */
.ai-table-wrap {
  overflow-x: auto;
  max-width: 100%;
  margin: 6px 0;
}

.ai-bubble table {
  background: #fff;
  color: #212529; /* readable even inside the blue user bubble */
  width: auto;
  min-width: 240px;
  margin: 0;
  font-size: 0.85rem;
}

.ai-bubble table th,
.ai-bubble table td {
  padding: 4px 10px;
  vertical-align: middle;
}

.ai-bubble table thead th {
  background: #f1f3f7;
}

.ai-bubble .ai-list {
  margin: 4px 0;
  padding-left: 20px;
}

/* ### markdown headings and real h1–h6 from sanitized HTML */
.ai-bubble .ai-md-h,
.ai-bubble h1, .ai-bubble h2, .ai-bubble h3,
.ai-bubble h4, .ai-bubble h5, .ai-bubble h6 {
  font-size: 1rem;
  font-weight: 600;
  margin: 8px 0 2px;
}

/* fenced code blocks (non-HTML fences) */
.ai-bubble pre.ai-code {
  background: #1e2530;
  color: #e6edf3;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 6px 0;
  font-size: 0.82rem;
  overflow-x: auto;
}

.ai-msg.assistant .ai-bubble code {
  background: #eef1f6;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.85em;
}

.ai-bubble pre.ai-code code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

/* The "queried: crm_overview..." line under an answer */
.ai-tools {
  color: #8a94a6;
  border-top: 1px dashed #e3e7ee;
  padding-top: 4px;
  margin-top: 6px;
}
