/* Ask CRM chat dock — lower-left embedded widget. Self-contained; visual cues
   borrowed from shadcn/Vercel-chatbot (rounded cards, soft borders, bubbles). */

.chat-dock {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 25; /* above content; below col-menu(35)/gate(40)/rls-pop(50)/uh-tip(60) */
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* collapsed: only the FAB; expanded: only the panel */
.chat-dock.collapsed .chat-panel { display: none; }
.chat-dock:not(.collapsed) .chat-fab { display: none; }

.chat-fab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #004bea; /* QXO blue */
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
}
.chat-fab:hover { background: #0039b3; }
.chat-fab .ai-spark { width: 26px; height: 26px; }

.chat-panel {
  display: flex;
  flex-direction: column;
  width: 760px;
  max-width: calc(100vw - 32px);
  height: 780px;
  max-height: calc(100vh - 32px);
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
  overflow: hidden;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid #0039b3;
  background: #004bea;
}
.chat-title {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  color: #fff;
}
.chat-head-btns { display: flex; gap: 4px; }
.chat-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
}
.chat-x svg { width: 17px; height: 17px; }
.chat-x:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }

/* AI sparkle logo (title + collapsed FAB) */
.ai-spark { width: 18px; height: 18px; flex: none; }

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #fff;
}
.chat-empty { color: #9ca3af; text-align: center; margin: auto 0; padding: 0 24px; }

/* message bubbles */
.cm { max-width: 88%; padding: 8px 11px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.cm-user { align-self: flex-end; background: #004bea; color: #fff; border-bottom-right-radius: 4px; }
.cm-bot { align-self: flex-start; background: #f1f3f5; color: #111827; border-bottom-left-radius: 4px; }
.cm-bot.streaming::after {
  content: "▍";
  margin-left: 1px;
  animation: cm-blink 1s steps(2, start) infinite;
}
@keyframes cm-blink { to { visibility: hidden; } }
.cm-err { align-self: flex-start; background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.cm-action { align-self: flex-start; background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; font-size: 12px; font-weight: 600; }

/* tool card */
.cm-tool {
  align-self: stretch;
  max-width: 100%;
  background: #f8f9fb;
  border: 1px solid #e9ecf1;
  border-radius: 10px;
  padding: 8px 10px;
  color: #374151;
}
.cm-toolname { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; color: #4338ca; font-size: 12px; }
.cm-toolargs { color: #6b7280; font-size: 11px; margin-left: 6px; }
.cm-widget { margin-top: 8px; }

/* widgets: table */
.cm-wt { font-weight: 600; color: #374151; margin: 2px 0 6px; font-size: 12px; }
.cm-tablewrap { max-height: 240px; overflow: auto; border: 1px solid #eef0f3; border-radius: 8px; }
.cm-table { border-collapse: collapse; width: 100%; font-size: 12px; }
.cm-table th, .cm-table td { padding: 5px 8px; border-bottom: 1px solid #f1f3f5; text-align: left; white-space: nowrap; }
.cm-table th { position: sticky; top: 0; background: #fafbfc; font-weight: 600; color: #6b7280; }
.cm-table td.r, .cm-table th.r { text-align: right; }
.cm-trunc { color: #9ca3af; font-size: 11px; margin-top: 4px; }

/* widgets: kpi strip */
.cm-kpis { display: flex; flex-wrap: wrap; gap: 6px; }
.cm-kpi { background: #f8f9fb; border: 1px solid #eef0f3; border-radius: 8px; padding: 6px 9px; min-width: 64px; }
.cm-kv { font-weight: 700; color: #111827; font-size: 13px; }
.cm-kl { color: #6b7280; font-size: 11px; margin-top: 1px; }
.cm-wtext { color: #374151; }

/* widgets: bar chart */
.cm-bars { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.cm-bar { display: grid; grid-template-columns: 108px 1fr 54px; align-items: center; gap: 6px; font-size: 12px; }
.cm-bar-l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #374151; }
.cm-bar-t { background: #eef0f3; border-radius: 4px; height: 14px; overflow: hidden; }
.cm-bar-f { height: 100%; background: #004bea; border-radius: 4px; min-width: 2px; }
.cm-bar-f.neg { background: #ef4444; }
.cm-bar-v { text-align: right; color: #111827; font-variant-numeric: tabular-nums; }

/* widgets: vega-lite chart */
.cm-vega { width: 100%; margin-top: 6px; overflow-x: auto; }
.cm-vega svg { max-width: 100%; }

.chat-form {
  display: flex;
  gap: 6px;
  padding: 10px;
  border-top: 1px solid #eef0f3;
  background: #fafbfc;
}
.chat-form textarea {
  flex: 1;
  resize: none;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 7px 9px;
  font: inherit;
  outline: none;
}
.chat-form textarea:focus { border-color: #004bea; }
.chat-send {
  border: none;
  background: #004bea;
  color: #fff;
  font-weight: 600;
  padding: 0 14px;
  border-radius: 8px;
  cursor: pointer;
}
.chat-send:hover { background: #0039b3; }
.chat-send:disabled { background: #9db6f7; cursor: default; }
