/* Public Ergon AI — bottom-right launcher. Guides only; no CRM data. */

.ergon-ai-root {
  --ai-cream: #f4efe6;
  --ai-paper: #fffdf8;
  --ai-ink: #14161f;
  --ai-muted: #5c5866;
  --ai-navy: #0c1220;
  --ai-violet: #7c3aed;
  --ai-lilac: #ece4ff;
  --ai-line: rgba(20, 22, 31, 0.1);
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 72;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: Manrope, system-ui, sans-serif;
  letter-spacing: -0.01em;
}

.ergon-ai-panel {
  display: none;
  width: min(400px, calc(100vw - 32px));
  height: min(560px, calc(100dvh - 108px));
  flex-direction: column;
  overflow: hidden;
  border-radius: 24px;
  background: var(--ai-paper);
  border: 1px solid var(--ai-line);
  box-shadow: 0 28px 70px rgba(12, 18, 32, 0.28);
  color: var(--ai-ink);
}

.ergon-ai-root.is-open .ergon-ai-panel {
  display: flex;
}

.ergon-ai-root.is-expanded .ergon-ai-launch {
  display: none;
}

.ergon-ai-panel.is-expanded {
  position: fixed;
  inset: 12px;
  width: auto;
  height: auto;
  max-width: none;
  border-radius: 20px;
}

.ergon-ai-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 12px 10px 14px;
  border-bottom: 1px solid var(--ai-line);
  background: linear-gradient(180deg, #f7f2ff 0%, var(--ai-paper) 100%);
}

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

.ergon-ai-face {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
}

.ergon-ai-face::before {
  content: "";
  position: absolute;
  inset: 0;
  background: conic-gradient(from 0deg, #7c3aed, #1d5faf, #f08a24, #7c3aed);
  animation: ergon-ai-spin 8s linear infinite;
}

.ergon-ai-face img {
  position: relative;
  z-index: 1;
  width: 26px;
  height: 26px;
  margin: 5px;
  object-fit: contain;
}

.ergon-ai-brand b {
  font-family: "Bricolage Grotesque", Manrope, sans-serif;
  font-size: 16px;
  letter-spacing: -0.04em;
  display: block;
  line-height: 1.1;
}

.ergon-ai-brand span {
  display: block;
  font-size: 11px;
  color: var(--ai-muted);
  font-weight: 700;
}

.ergon-ai-tools {
  display: flex;
  align-items: center;
  gap: 2px;
}

.ergon-ai-iconbtn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ai-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.ergon-ai-iconbtn:hover {
  background: var(--ai-lilac);
  color: var(--ai-ink);
}

.ergon-ai-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px 0;
}

.ergon-ai-tab {
  border: 1px solid var(--ai-line);
  background: #fff;
  color: var(--ai-muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.ergon-ai-tab.is-on {
  background: var(--ai-navy);
  border-color: var(--ai-navy);
  color: #fff;
}

.ergon-ai-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ergon-ai-pane {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ergon-ai-pane[hidden] {
  display: none !important;
}

.ergon-ai-log,
.ergon-ai-guides {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.ergon-ai-log {
  padding: 12px 14px 8px;
}

.ergon-ai-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 12px;
}

.ergon-ai-empty p {
  font-size: 13px;
  color: var(--ai-muted);
  max-width: 28ch;
  line-height: 1.45;
}

.ergon-ai-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.ergon-ai-chip {
  border: 1px solid var(--ai-line);
  background: #fff;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  color: var(--ai-ink);
}

.ergon-ai-chip:hover {
  border-color: rgba(124, 58, 237, 0.4);
  background: var(--ai-lilac);
}

.ergon-ai-msg {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

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

.ergon-ai-bubble {
  max-width: 86%;
  border-radius: 16px;
  padding: 10px 12px;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.ergon-ai-msg.is-user .ergon-ai-bubble {
  background: var(--ai-violet);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.ergon-ai-msg.is-ai .ergon-ai-bubble {
  background: #f3efe8;
  border: 1px solid var(--ai-line);
  border-top-left-radius: 6px;
}

.ergon-ai-bubble p { margin: 0 0 8px; }
.ergon-ai-bubble p:last-child { margin-bottom: 0; }
.ergon-ai-bubble ol,
.ergon-ai-bubble ul { margin: 0 0 8px; padding-left: 1.2em; }
.ergon-ai-bubble li { margin: 0 0 4px; }
.ergon-ai-bubble strong { font-weight: 800; }

.ergon-ai-source {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 0 0 6px 44px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--ai-lilac);
  color: #5b21b6;
  font-size: 10px;
  font-weight: 800;
}

.ergon-ai-typing {
  display: flex;
  gap: 4px;
  padding: 6px 2px;
}

.ergon-ai-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8a8494;
  animation: ergon-ai-pulse 1s ease-in-out infinite;
}

.ergon-ai-typing i:nth-child(2) { animation-delay: .15s; }
.ergon-ai-typing i:nth-child(3) { animation-delay: .3s; }

.ergon-ai-error {
  margin: 0 12px 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #fde8e8;
  color: #b42318;
  font-size: 12px;
  font-weight: 700;
}

.ergon-ai-composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--ai-line);
  background: #fff;
}

.ergon-ai-composer textarea {
  flex: 1;
  resize: none;
  min-height: 42px;
  max-height: 110px;
  border: 1px solid var(--ai-line);
  border-radius: 14px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  background: var(--ai-cream);
  color: var(--ai-ink);
}

.ergon-ai-composer textarea:focus {
  outline: 2px solid rgba(124, 58, 237, 0.35);
  border-color: transparent;
}

.ergon-ai-send {
  align-self: flex-end;
  height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--ai-violet);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
}

.ergon-ai-send:disabled {
  opacity: 0.5;
  cursor: default;
}

.ergon-ai-guides-search {
  padding: 10px 12px 0;
}

.ergon-ai-guides-search input {
  width: 100%;
  border: 1px solid var(--ai-line);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-size: 13px;
  background: #fff;
}

.ergon-ai-audiences {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px 0;
}

.ergon-ai-guides {
  padding: 8px 12px 12px;
}

.ergon-ai-guide {
  width: 100%;
  text-align: left;
  border: 1px solid var(--ai-line);
  background: #fff;
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
}

.ergon-ai-guide.is-open {
  border-color: rgba(124, 58, 237, 0.35);
  background: #fbf8ff;
}

.ergon-ai-guide h4 {
  font-family: "Bricolage Grotesque", Manrope, sans-serif;
  font-size: 14px;
  letter-spacing: -0.03em;
  margin: 0 0 4px;
}

.ergon-ai-guide .meta {
  font-size: 11px;
  color: var(--ai-muted);
  font-weight: 700;
}

.ergon-ai-guide-body {
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.45;
  color: #2b2833;
}

.ergon-ai-ask-guide {
  margin-top: 10px;
  border: 0;
  border-radius: 999px;
  background: var(--ai-navy);
  color: #fff;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.ergon-ai-launch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 16px 0 6px;
  border: 0;
  border-radius: 999px;
  background: var(--ai-navy);
  color: #fff;
  box-shadow: 0 16px 40px rgba(12, 18, 32, 0.28);
  cursor: pointer;
}

.ergon-ai-launch:hover {
  transform: translateY(-2px);
  background: #151c2e;
}

.ergon-ai-launch .ergon-ai-face {
  width: 44px;
  height: 44px;
}

.ergon-ai-launch .ergon-ai-face img {
  width: 32px;
  height: 32px;
  margin: 6px;
}

.ergon-ai-launch-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.05;
  padding-right: 4px;
}

.ergon-ai-launch-copy small {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #c4b5fd;
}

.ergon-ai-launch-copy b {
  font-family: "Bricolage Grotesque", Manrope, sans-serif;
  font-size: 16px;
  letter-spacing: -0.04em;
  font-weight: 800;
}

.ergon-ai-root.is-open .ergon-ai-launch-copy small {
  color: #ddd6fe;
}

@keyframes ergon-ai-spin {
  to { transform: rotate(1turn); }
}

@keyframes ergon-ai-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

@media (max-width: 640px) {
  .ergon-ai-panel {
    width: min(100vw - 20px, 400px);
    height: min(72dvh, 560px);
  }
  .ergon-ai-launch-copy small { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .ergon-ai-face::before,
  .ergon-ai-typing i,
  .ergon-ai-launch { animation: none !important; transform: none !important; }
}
