/**
 * CAF AI Agent — TrustyPlugins-branded chat widget
 */

.caf-ai-root {
  --caf-ai-orange: #ff6a00;
  --caf-ai-orange-hover: #e85f00;
  --caf-ai-orange-soft: #fff3e8;
  --caf-ai-orange-ring: rgba(255, 106, 0, 0.22);
  --caf-ai-ink: #1a1a1a;
  --caf-ai-muted: #6b7280;
  --caf-ai-line: #ebebeb;
  --caf-ai-panel: #ffffff;
  --caf-ai-stage: #f6f6f7;
  --caf-ai-shadow: 0 16px 40px rgba(26, 26, 26, 0.16);
  --caf-ai-radius: 14px;
  --caf-ai-font: 'Poppins', Helvetica, Arial, Lucida, sans-serif;

  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 99999;
  font-family: var(--caf-ai-font);
  color: var(--caf-ai-ink);
  -webkit-font-smoothing: antialiased;
}

.caf-ai-launcher {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  padding: 12px 18px 12px 12px;
  background: var(--caf-ai-orange);
  color: #fff;
  box-shadow: 0 10px 28px rgba(255, 106, 0, 0.38);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.caf-ai-launcher:hover {
  transform: translateY(-2px);
  background: var(--caf-ai-orange-hover);
  box-shadow: 0 14px 32px rgba(255, 106, 0, 0.45);
}

.caf-ai-launcher:focus-visible {
  outline: 3px solid var(--caf-ai-orange-ring);
  outline-offset: 2px;
}

.caf-ai-launcher-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #fff;
  flex-shrink: 0;
  overflow: hidden;
}

.caf-ai-launcher-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.caf-ai-launcher-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.caf-ai-panel {
  position: absolute;
  right: 0;
  bottom: 68px;
  width: min(390px, calc(100vw - 28px));
  height: min(580px, calc(100vh - 110px));
  display: flex;
  flex-direction: column;
  background: var(--caf-ai-panel);
  border: 1px solid var(--caf-ai-line);
  border-radius: var(--caf-ai-radius);
  box-shadow: var(--caf-ai-shadow);
  overflow: hidden;
  animation: caf-ai-rise 0.22s ease;
}

@keyframes caf-ai-rise {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.caf-ai-panel[hidden] {
  display: none !important;
}

/* Divi/theme CSS often overrides the native [hidden] attribute. */
.caf-ai-root [hidden] {
  display: none !important;
}

.caf-ai-root [hidden] {
  display: none !important;
}

.caf-ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 13px;
  background: #000;
  border-bottom: 1px solid var(--caf-ai-line);
}

.caf-ai-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.caf-ai-avatar {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: #fff;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 6px 14px rgba(255, 106, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.55);
}

.caf-ai-avatar svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.caf-ai-brand-text {
  min-width: 0;
}

.caf-ai-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.25;
  color: #fff;
  letter-spacing: -0.01em;
  padding-bottom: 0;
}

.caf-ai-status {
  margin: 3px 0 0;
  font-size: 12px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.3;
}

.caf-ai-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18);
}

.caf-ai-close {
  border: 0;
  background: #f3f4f6;
  color: #4b5563;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

.caf-ai-close:hover {
  background: #ebebeb;
  color: var(--caf-ai-ink);
}

.caf-ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  background: var(--caf-ai-stage);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.caf-ai-product-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  background: #fff7f0;
  border-bottom: 1px solid #ffe0c2;
}

.caf-ai-product-bar[hidden] {
  display: none !important;
}

.caf-ai-product-bar-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--caf-ai-ink);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.caf-ai-change-product {
  border: 0;
  background: transparent;
  color: var(--caf-ai-orange);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 0;
  flex-shrink: 0;
  font-family: inherit;
}

.caf-ai-change-product:hover {
  text-decoration: underline;
}

.caf-ai-picker {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 2px 0 6px;
}

.caf-ai-picker-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--caf-ai-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.caf-ai-picker-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.caf-ai-product-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--caf-ai-line);
  background: #fff;
  border-radius: 12px;
  padding: 11px 12px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.caf-ai-product-card:hover {
  border-color: var(--caf-ai-orange);
  box-shadow: 0 6px 16px rgba(255, 106, 0, 0.12);
  transform: translateY(-1px);
}

.caf-ai-product-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

.caf-ai-product-card-top strong {
  font-size: 13.5px;
  font-weight: 800;
  color: var(--caf-ai-ink);
  line-height: 1.3;
}

.caf-ai-product-badge {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--caf-ai-orange-hover);
  background: var(--caf-ai-orange-soft);
  border-radius: 999px;
  padding: 3px 8px;
}

.caf-ai-product-blurb {
  font-size: 12px;
  color: var(--caf-ai-muted);
  line-height: 1.4;
}

.caf-ai-composer.is-locked .caf-ai-input-shell {
  opacity: 0.72;
  background: #f3f4f6;
}

.caf-ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 2px 4px;
}

.caf-ai-suggestions[hidden] {
  display: none !important;
}

.caf-ai-chip {
  border: 1px solid #ffd7b8;
  background: #fff;
  color: var(--caf-ai-ink);
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.caf-ai-chip:hover {
  background: var(--caf-ai-orange-soft);
  border-color: var(--caf-ai-orange);
  color: var(--caf-ai-orange-hover);
}

.caf-ai-msg {
  max-width: 92%;
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 12.5px;
  line-height: 1.55;
  word-break: break-word;
}

.caf-ai-msg-body {
  display: block;
}

.caf-ai-msg-body > *:first-child {
  margin-top: 0;
}

.caf-ai-msg-body > *:last-child {
  margin-bottom: 0;
}

.caf-ai-msg-body p {
  margin: 0 0 0.65em;
  padding: 0;
}

.caf-ai-msg-body .caf-ai-h,
.caf-ai-msg-body h3,
.caf-ai-msg-body h4,
.caf-ai-msg-body h5 {
  margin: 0.85em 0 0.35em;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.3;
  color: var(--caf-ai-ink);
}

.caf-ai-msg-body h3 {
  font-size: 14.5px;
}

.caf-ai-msg-body h4 {
  font-size: 13.5px;
}

.caf-ai-msg-body h5 {
  font-size: 13px;
  font-weight: 700;
  color: #374151;
}

.caf-ai-msg-body .caf-ai-list {
  margin: 0.35em 0 0.75em;
  padding-left: 1.15em;
}

.caf-ai-msg-body ul.caf-ai-list {
  list-style: disc;
}

.caf-ai-msg-body .caf-ai-list li {
  margin: 0.28em 0;
  padding-left: 0.15em;
}

.caf-ai-msg-body .caf-ai-list li::marker {
  color: #111;
}

.caf-ai-msg-body strong {
  font-weight: 700;
  color: var(--caf-ai-ink);
}

.caf-ai-msg-body em {
  font-style: italic;
}

.caf-ai-msg-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: #f3f4f6;
  border-radius: 5px;
  padding: 0.1em 0.35em;
}

.caf-ai-msg-body .caf-ai-hr {
  border: 0;
  border-top: 1px solid var(--caf-ai-line);
  margin: 0.75em 0;
}

.caf-ai-compare {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0.35em 0 0.75em;
}

.caf-ai-compare-row {
  background: #faf7f4;
  border: 1px solid #f0e6df;
  border-radius: 10px;
  padding: 8px 10px;
}

.caf-ai-compare-feature {
  font-weight: 700;
  font-size: 12.5px;
  line-height: 1.35;
  margin-bottom: 3px;
  color: var(--caf-ai-ink);
}

.caf-ai-compare-vals {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12.5px;
  line-height: 1.4;
  color: #374151;
}

.caf-ai-compare-vals strong {
  font-weight: 700;
  color: var(--caf-ai-ink);
}

.caf-ai-msg--bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--caf-ai-line);
  border-bottom-left-radius: 5px;
  box-shadow: 0 1px 2px rgba(26, 26, 26, 0.04);
  white-space: normal;
}

.caf-ai-msg--user {
  align-self: flex-end;
  background: var(--caf-ai-orange);
  color: #fff;
  border: 0;
  border-bottom-right-radius: 5px;
  box-shadow: 0 6px 14px rgba(255, 106, 0, 0.22);
  white-space: pre-wrap;
}

.caf-ai-msg--error {
  align-self: stretch;
  background: #fff5f5;
  border: 1px solid #fecaca;
  color: #991b1b;
  white-space: pre-wrap;
}

.caf-ai-msg a {
  color: var(--caf-ai-orange);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.caf-ai-msg--user a {
  color: #fff;
}

.caf-ai-typing {
  display: none !important;
  align-self: flex-start;
  align-items: center;
  gap: 5px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--caf-ai-line);
  border-radius: 14px;
  border-bottom-left-radius: 5px;
}

.caf-ai-typing.is-visible {
  display: inline-flex !important;
}

.caf-ai-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #c4c4c4;
  animation: caf-ai-bounce 1s infinite ease-in-out;
}

.caf-ai-typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.caf-ai-typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes caf-ai-bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-3px);
    opacity: 1;
    background: var(--caf-ai-orange);
  }
}

.caf-ai-composer {
  border-top: 1px solid var(--caf-ai-line);
  background: linear-gradient(180deg, #fafafa 0%, #ffffff 40%);
  padding: 14px 14px 12px;
}

.caf-ai-form {
  margin: 0;
}

.caf-ai-input-shell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 6px 6px 6px 14px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(26, 26, 26, 0.04);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.caf-ai-input-shell:focus-within {
  border-color: var(--caf-ai-orange);
  box-shadow: 0 0 0 3px var(--caf-ai-orange-ring);
}

.caf-ai-input-shell .caf-ai-input,
.caf-ai-form input.caf-ai-input {
  flex: 1;
  width: 100%;
  min-width: 0;
  height: 40px;
  margin: 0 !important;
  padding: 0 4px 0 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  outline: none !important;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 40px;
  color: var(--caf-ai-ink);
  -webkit-appearance: none;
  appearance: none;
}

.caf-ai-input-shell .caf-ai-input::placeholder,
.caf-ai-form input.caf-ai-input::placeholder {
  color: #9ca3af;
  font-weight: 400;
}

.caf-ai-send {
  border: 0 !important;
  border-radius: 10px !important;
  background: var(--caf-ai-orange) !important;
  color: #fff !important;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0 !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(255, 106, 0, 0.28);
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.caf-ai-send:hover {
  background: var(--caf-ai-orange-hover) !important;
  box-shadow: 0 6px 16px rgba(255, 106, 0, 0.36);
  transform: translateY(-1px);
}

.caf-ai-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.caf-ai-send svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.caf-ai-handoff-card {
  border: 1px solid #ffd7b8;
  background: linear-gradient(180deg, #fff8f2 0%, #fff 100%);
}

.caf-ai-handoff-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--caf-ai-ink, #1a1a1a);
  margin: 0 0 6px;
}

.caf-ai-handoff-note {
  font-size: 12px;
  line-height: 1.4;
  color: var(--caf-ai-muted);
  margin: 0 0 10px;
}

.caf-ai-handoff {
  display: flex;
  gap: 8px;
}

.caf-ai-handoff-link,
.caf-ai-copy-chat {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid #ffd7b8;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.caf-ai-handoff-link {
  background: #fff;
  color: var(--caf-ai-orange-hover);
}

.caf-ai-handoff-link:hover {
  background: var(--caf-ai-orange-soft);
}

.caf-ai-copy-chat {
  background: var(--caf-ai-orange);
  border-color: var(--caf-ai-orange);
  color: #fff;
}

.caf-ai-copy-chat:hover {
  background: var(--caf-ai-orange-hover);
}

.caf-ai-copy-hint {
  text-align: center;
  color: var(--caf-ai-muted);
  font-size: 11px;
}

.caf-ai-copy-hint[hidden] {
  display: none !important;
}

.caf-ai-votes {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--caf-ai-line);
}

.caf-ai-votes-label {
  font-size: 11px;
  color: var(--caf-ai-muted);
  margin-right: 2px;
}

.caf-ai-vote {
  border: 1px solid var(--caf-ai-line);
  background: #fff;
  border-radius: 8px;
  width: 30px;
  height: 28px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
}

.caf-ai-vote:hover,
.caf-ai-vote.is-active {
  border-color: var(--caf-ai-orange);
  background: var(--caf-ai-orange-soft);
}

.caf-ai-vote:disabled {
  cursor: default;
  opacity: 0.85;
}

@media (max-width: 480px) {
  .caf-ai-root {
    right: 12px;
    bottom: 12px;
  }

  .caf-ai-panel {
    bottom: 62px;
    height: min(70vh, calc(100vh - 90px));
  }

  .caf-ai-launcher-label {
    display: none;
  }

  .caf-ai-launcher {
    padding: 12px;
    border-radius: 50%;
  }
}
