/* ============================================================
   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;
  align-content: flex-start;
  gap: 6px;
  margin-bottom: 8px;
  max-height: 120px;     /* KT-CODE-1 — ~3 hàng câu hỏi hiện gọn; nhiều hơn thì cuộn */
  overflow-y: auto;
}

/* Nút "Tất cả câu hỏi" NẰM NGOÀI vùng cuộn -> LUÔN hiện dù nhiều câu ghim
   (fix 3.46.1: trước đây nằm trong .ai-suggestions bị cắt nửa ở hàng cuối). */
.ai-suggest-all {
  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;
}

/* Internal record deep-links inside an answer. The AI marks a record name
   as [Name](crm:<module>/<id>); clicking opens the record the same way its
   module list does (contact 360, deal/task/ticket detail, dyn-object modal). */
.ai-rec-link {
  color: #0d6efd;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}

.ai-rec-link:hover {
  text-decoration: underline;
}

.ai-rec-link .ai-rec-ic {
  font-size: 0.78em;
  margin-left: 3px;
  opacity: 0.6;
  vertical-align: baseline;
}

/* ===== §C design-ai-facet-card.md — card kết quả tìm kiếm tương tác ===== */
.aix-card{background:var(--bs-body-bg,#fff);border:1px solid var(--bs-border-color,#dee2e6);border-radius:.5rem;margin:.5rem 0;font-size:.85rem;overflow:hidden}
.aix-card.aix-busy{opacity:.6;pointer-events:none}
.aix-head{padding:.4rem .75rem;font-weight:600;border-bottom:1px solid var(--bs-border-color,#dee2e6);background:var(--bs-tertiary-bg,#f8f9fa)}
.aix-chips{display:flex;gap:.35rem;padding:.5rem .75rem .25rem;overflow-x:auto;white-space:nowrap;scrollbar-width:thin}
.aix-chip{display:inline-flex;align-items:center;gap:.3rem;font-size:.78rem;padding:.15rem .6rem;border:1px solid var(--bs-border-color,#dee2e6);border-radius:999px;cursor:pointer;user-select:none;flex:0 0 auto}
.aix-chip:hover{background:var(--bs-tertiary-bg,#f1f3f5)}
.aix-chip.active{background:var(--bs-primary,#0d6efd);border-color:var(--bs-primary,#0d6efd);color:#fff}
.aix-chip.static,.aix-facet-val.static{cursor:default}
.aix-chip.static:hover{background:transparent}
.aix-count{opacity:.75}
.aix-facets{padding:.15rem .75rem .3rem;font-size:.78rem;color:var(--bs-secondary-color,#6c757d)}
.aix-facet-row{display:flex;gap:.35rem;align-items:baseline;overflow-x:auto;white-space:nowrap;padding:.1rem 0;scrollbar-width:thin}
.aix-facet-name{flex:0 0 auto;font-weight:600}
.aix-facet-val{flex:0 0 auto;cursor:pointer;padding:.05rem .45rem;border-radius:999px;border:1px solid transparent}
.aix-facet-val:hover{background:var(--bs-tertiary-bg,#f1f3f5)}
.aix-facet-val.static:hover{background:transparent}
.aix-facet-val.active{border-color:var(--bs-primary,#0d6efd);color:var(--bs-primary,#0d6efd);font-weight:600}
.aix-list{padding:.25rem .75rem}
.aix-item{padding:.3rem 0;border-top:1px dashed var(--bs-border-color,#e9ecef)}
.aix-item:first-child{border-top:0}
.aix-sub{color:var(--bs-secondary-color,#6c757d);font-size:.75rem}
.aix-snip{color:var(--bs-secondary-color,#6c757d);font-size:.78rem;overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
.aix-snip em{font-style:normal;font-weight:600;color:var(--bs-emphasis-color,#111)}
.aix-foot{padding:.35rem .75rem .55rem}

/* ===== fix test 3.12.0 — blockquote/hr markdown + link "hỏi tiếp" ===== */
.ai-md-bq{border-left:3px solid var(--bs-border-color,#dee2e6);padding:.15rem .6rem;margin:.25rem 0;color:var(--bs-secondary-color,#6c757d)}
.ai-md-hr{margin:.5rem 0;opacity:.15}
.ai-ask-link{text-decoration:none;border-bottom:1px dashed currentColor}
.ai-ask-link:hover{border-bottom-style:solid}
