/* Phase 1.4 — customer-facing AI chat widget (ClariSprint site tokens) */
.csAiChatRoot {
  --cs-ai-navy: #030b1c;
  --cs-ai-navy2: #0d2a4b;
  --cs-ai-blue: #1265ff;
  --cs-ai-blue2: #3468ff;
  --cs-ai-line: #d8e6f4;
  --cs-ai-muted: #60708b;
  --cs-ai-ink: #10233c;
  --cs-ai-paper: #f4f8fd;
}

.agentPanel.csAiChatPanel {
  display: none;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
  width: min(400px, calc(100vw - 28px));
  max-height: min(640px, calc(100vh - 110px));
  max-height: min(640px, calc(100dvh - 110px));
}

.agentPanel.csAiChatPanel.open {
  display: flex;
}

.csAiHead {
  background: linear-gradient(145deg, var(--cs-ai-navy), var(--cs-ai-navy2));
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-radius: 21px 21px 0 0;
  flex-shrink: 0;
}

.csAiBrandRow {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.csAiMark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.csAiMark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.csAiHead h3 {
  margin: 0 0 4px;
  font-size: 18px;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.csAiHead p {
  margin: 0;
  color: #a9bdd4;
  font-size: 12px;
  line-height: 1.4;
}

.csAiStatus {
  margin-top: 6px;
  font-size: 11px;
  font-weight: 700;
  color: #7fd6ff;
}

.csAiBody {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  background: #fff;
}

.csAiTranscript {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 180px;
  max-height: 280px;
  background: linear-gradient(180deg, #f7fbff 0%, #fff 48%);
}

.csAiBubble {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--cs-ai-ink);
  white-space: pre-wrap;
  word-break: break-word;
}

.csAiBubble.bot {
  align-self: flex-start;
  background: var(--cs-ai-paper);
  border: 1px solid var(--cs-ai-line);
  border-bottom-left-radius: 6px;
}

.csAiBubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--cs-ai-blue), var(--cs-ai-blue2));
  color: #fff;
  border-bottom-right-radius: 6px;
}

.csAiBubble.system,
.csAiBubble.handoff {
  align-self: stretch;
  max-width: 100%;
  background: #eef6ff;
  border: 1px dashed #b9d4f2;
  color: #1d3f66;
  font-size: 13px;
}

.csAiBubble.operator {
  align-self: flex-start;
  background: #103057;
  color: #eef7ff;
  border-bottom-left-radius: 6px;
}

.csAiBubble .csAiTyping {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.csAiBubble .csAiTyping span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #7a93b0;
  animation: csAiPulse 1s infinite ease-in-out;
}

.csAiBubble .csAiTyping span:nth-child(2) { animation-delay: 0.15s; }
.csAiBubble .csAiTyping span:nth-child(3) { animation-delay: 0.3s; }

@keyframes csAiPulse {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

.csAiStarters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 10px;
}

.csAiStarter {
  border: 1px solid var(--cs-ai-line);
  background: #fff;
  color: #1a3558;
  border-radius: 999px;
  padding: 8px 12px;
  font: 700 12px/1.2 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  cursor: pointer;
}

.csAiStarter:hover,
.csAiStarter:focus-visible {
  border-color: var(--cs-ai-blue);
  outline: none;
  box-shadow: 0 0 0 3px rgba(18, 101, 255, 0.12);
}

.csAiComposer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 16px 12px;
  border-top: 1px solid var(--cs-ai-line);
  background: #fff;
}

.csAiComposer textarea {
  width: 100%;
  min-height: 44px;
  max-height: 110px;
  resize: none;
  border: 1px solid #d6e0ea;
  border-radius: 12px;
  padding: 11px 12px;
  font: inherit;
  color: var(--cs-ai-ink);
  outline: none;
}

.csAiComposer textarea:focus {
  border-color: var(--cs-ai-blue);
  box-shadow: 0 0 0 3px rgba(18, 101, 255, 0.1);
}

.csAiSend {
  border: 0;
  border-radius: 12px;
  padding: 0 16px;
  min-width: 72px;
  background: linear-gradient(135deg, var(--cs-ai-blue), var(--cs-ai-blue2));
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

.csAiSend:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.csAiComposer--locked {
  opacity: 0.92;
}

.csAiComposer--locked textarea {
  background: #f3f6fa;
  color: #5a6b7d;
  cursor: not-allowed;
}

.csAiComposer--team textarea {
  border-color: #bfd8ff;
  background: #f7faff;
}

.csAiHumanBtn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.csAiStarter:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.csAiActions {
  display: grid;
  gap: 8px;
  padding: 0 16px 12px;
}

.csAiHumanBtn {
  border: 1px solid #bfd8ff;
  background: #f4f8ff;
  color: #1456a0;
  border-radius: 12px;
  min-height: 42px;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
}

.csAiChannels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 0 16px 10px;
}

.csAiLegacy {
  padding: 0 16px 16px;
  border-top: 1px solid var(--cs-ai-line);
}

.csAiLegacy summary {
  cursor: pointer;
  list-style: none;
  font-size: 12px;
  font-weight: 800;
  color: var(--cs-ai-muted);
  padding: 10px 0 6px;
}

.csAiLegacy summary::-webkit-details-marker { display: none; }

.csAiLiveRegion {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* Preview-only QA strip — only mounted when ?previewQa=1 on localhost */
.csAiPreviewQa {
  position: fixed;
  z-index: 80;
  left: 50%;
  transform: translateX(-50%);
  bottom: 12px;
  width: min(520px, calc(100vw - 24px));
  background: #08152d;
  color: #eef7ff;
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(3, 11, 28, 0.35);
  padding: 10px 12px;
  display: grid;
  gap: 8px;
  font: 600 12px/1.35 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

.csAiPreviewQa[hidden] { display: none !important; }

.csAiPreviewQa .row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.csAiPreviewQa button,
.csAiPreviewQa input {
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  padding: 8px 10px;
  font: inherit;
}

.csAiPreviewQa button {
  cursor: pointer;
  font-weight: 800;
}

.csAiPreviewQa input {
  flex: 1;
  min-width: 140px;
}

@media (max-width: 650px) {
  .agentPanel.csAiChatPanel {
    right: 14px;
    left: 14px;
    bottom: 70px;
    width: auto;
    max-height: calc(100dvh - 92px);
    max-height: calc(100vh - 92px);
  }

  .csAiTranscript {
    max-height: min(180px, 28vh);
    min-height: 120px;
  }

  .csAiStarters {
    max-height: 72px;
    overflow: auto;
  }

  .csAiPreviewQa {
    bottom: auto;
    top: 10px;
    transform: translateX(-50%);
  }
}

@media (max-width: 430px) {
  .csAiChannels {
    grid-template-columns: 1fr;
  }
}
