.fagi-root,
.fagi-root * { box-sizing: border-box; }

.fagi-root {
  --fagi-primary: #51C517;
  --fagi-secondary: #007F5F;
  --fagi-accent: #FAC713;
  --fagi-ink: #153326;
  --fagi-muted: #66776c;
  --fagi-line: #dfe9e2;
  position: fixed;
  right: 22px;
  bottom: var(--fagi-bottom-desktop, 95px);
  z-index: 999999;
  color: var(--fagi-ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Icono flotante transparente */
.fagi-launcher {
  position: relative;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
  transition: transform .18s ease, filter .18s ease;
}
.fagi-launcher:hover {
  transform: translateY(-2px) scale(1.03);
  filter: drop-shadow(0 9px 16px rgba(0,127,95,.22));
}
.fagi-launcher:focus-visible {
  outline: 3px solid rgba(250,199,19,.75);
  outline-offset: 4px;
  border-radius: 14px;
}
.fagi-launcher-bot {
  width: 50px;
  height: 50px;
  display: block;
  filter: drop-shadow(0 8px 14px rgba(0,127,95,.18));
}
.fagi-icon-close {
  display: none;
  color: var(--fagi-secondary);
  font-size: 32px;
  line-height: 1;
  font-weight: 500;
}
.fagi-root.is-open .fagi-launcher-bot { display: none; }
.fagi-root.is-open .fagi-icon-close { display: block; }

.fagi-help-bubble {
  position: absolute;
  right: 64px;
  bottom: 4px;
  min-width: 215px;
  padding: 11px 13px;
  border: 1px solid rgba(0,127,95,.13);
  border-radius: 14px;
  color: #173c2a;
  background: #fff;
  box-shadow: 0 14px 34px rgba(17,63,39,.14);
  opacity: 0;
  transform: translateX(8px);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.fagi-help-bubble::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -6px;
  width: 12px;
  height: 12px;
  background: #fff;
  border-top: 1px solid rgba(0,127,95,.13);
  border-right: 1px solid rgba(0,127,95,.13);
  transform: translateY(-50%) rotate(45deg);
}
.fagi-help-bubble strong {
  display: block;
  margin-bottom: 3px;
  font-size: 13px;
  line-height: 1.2;
  font-weight: 800;
}
.fagi-help-bubble span {
  display: block;
  color: #5f7165;
  font-size: 11.7px;
  line-height: 1.35;
}
.fagi-help-bubble.is-visible { opacity: 1; transform: translateX(0); }

/* Ventana corporativa Fertisem */
.fagi-panel {
  position: absolute;
  right: 0;
  bottom: 68px;
  width: min(400px, calc(100vw - 28px));
  height: min(670px, calc(100vh - var(--fagi-bottom-desktop, 95px) - 108px));
  min-height: 360px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(0,127,95,.13);
  border-radius: 21px;
  background: #f7faf8;
  box-shadow: 0 28px 76px rgba(8,49,29,.25);
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(.975);
  transform-origin: bottom right;
  transition: opacity .2s ease, visibility .2s ease, transform .2s ease;
}
.fagi-root.is-open .fagi-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.fagi-header {
  position: relative;
  min-height: 96px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px 16px;
  color: #fff;
  background: linear-gradient(110deg, #006f52 0%, #008660 58%, #45ba23 100%);
  box-shadow: 0 8px 22px rgba(0,89,58,.17);
}
.fagi-header-topbar {
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--fagi-accent);
}
.fagi-avatar {
  position: relative;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.32);
  border-radius: 14px;
  color: var(--fagi-secondary);
  background: #fff;
  box-shadow: 0 8px 18px rgba(0,0,0,.11);
}
.fagi-brand-leaf { display: block; }
.fagi-avatar-badge {
  position: absolute;
  right: -5px;
  bottom: -5px;
  min-width: 21px;
  height: 21px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  border: 2px solid #168e58;
  border-radius: 999px;
  color: #114a32;
  background: #fff3b7;
  font-size: 8.5px;
  font-weight: 900;
}
.fagi-header-copy {
  min-width: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 3px;
}
.fagi-header-copy strong {
  overflow: hidden;
  font-size: 15.7px;
  line-height: 1.2;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fagi-header-copy span {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.2px;
  opacity: .96;
}
.fagi-header-copy i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c9f59d;
  box-shadow: 0 0 0 3px rgba(201,245,157,.15);
}
.fagi-header-copy small {
  color: rgba(255,255,255,.84);
  font-size: 10.8px;
  line-height: 1.3;
}
.fagi-header-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  margin-left: auto;
}
.fagi-header-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 25px;
  padding: 0 9px;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 999px;
  color: #fff;
  background: rgba(255,255,255,.12);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .09em;
}
.fagi-minimize {
  width: 31px;
  height: 31px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,.20);
  border-radius: 10px;
  color: #fff;
  background: rgba(255,255,255,.11);
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
}
.fagi-minimize:hover { background: rgba(255,255,255,.18); }

.fagi-messages {
  flex: 1;
  overflow-y: auto;
  padding: 17px 15px 11px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.fagi-messages::-webkit-scrollbar { width: 6px; }
.fagi-messages::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #c7d6cb;
}

.fagi-message { display: flex; margin-bottom: 12px; }
.fagi-message-user { justify-content: flex-end; }
.fagi-message-assistant { flex-direction: column; align-items: flex-start; }
.fagi-message-bubble {
  max-width: 88%;
  padding: 11px 13px;
  border: 1px solid var(--fagi-line);
  border-left: 3px solid rgba(81,197,23,.72);
  border-radius: 15px 15px 15px 6px;
  color: #27372d;
  background: #fff;
  box-shadow: 0 7px 18px rgba(20,55,34,.06);
  font-size: 13.4px;
  line-height: 1.52;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.fagi-message-user .fagi-message-bubble {
  color: #fff;
  border: 0;
  border-radius: 15px 15px 6px 15px;
  background: var(--fagi-secondary);
  box-shadow: 0 7px 18px rgba(0,127,95,.16);
}

.fagi-typing { display: flex; align-items: center; gap: 4px; padding: 14px 16px; }
.fagi-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8da293;
  animation: fagi-bounce 1.2s infinite ease-in-out;
}
.fagi-typing span:nth-child(2) { animation-delay: .15s; }
.fagi-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes fagi-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

.fagi-products {
  width: 100%;
  display: grid;
  gap: 9px;
  margin-top: 9px;
}
.fagi-product-card {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 10px;
  padding: 9px;
  border: 1px solid #dfe9e2;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 7px 17px rgba(20,56,32,.05);
}
.fagi-product-image {
  width: 70px;
  height: 70px;
  display: block;
  overflow: hidden;
  border: 1px solid #edf2ee;
  border-radius: 10px;
  background: #f4f7f4;
}
.fagi-product-image img { width: 100%; height: 100%; display: block; object-fit: contain; }
.fagi-product-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.fagi-product-title {
  display: -webkit-box;
  overflow: hidden;
  color: #173c28;
  font-size: 12.5px;
  font-weight: 800;
  line-height: 1.34;
  text-decoration: none;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.fagi-product-meta {
  margin: 4px 0 7px;
  color: #667469;
  font-size: 11.2px;
  line-height: 1.35;
}
.fagi-product-button {
  margin-top: auto;
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 8px;
  color: #fff !important;
  background: var(--fagi-secondary);
  box-shadow: 0 5px 12px rgba(0,127,95,.16);
  font-size: 11.2px;
  font-weight: 800;
  line-height: 1.2;
  text-decoration: none !important;
}
.fagi-product-button:hover { background: #006b50; }

.fagi-quick-wrap { padding: 2px 14px 10px; }
.fagi-quick-title {
  margin-bottom: 7px;
  color: #4e6557;
  font-size: 10.4px;
  font-weight: 900;
  letter-spacing: .07em;
  text-transform: uppercase;
}
.fagi-quick {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.fagi-quick::-webkit-scrollbar { display: none; }
.fagi-chip {
  flex: 0 0 auto;
  max-width: 240px;
  padding: 8px 11px;
  border: 1px solid rgba(0,127,95,.22);
  border-radius: 999px;
  color: #24523c;
  background: #fff;
  font-size: 11.4px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fagi-chip:hover {
  color: #fff;
  border-color: var(--fagi-secondary);
  background: var(--fagi-secondary);
}

.fagi-whatsapp {
  min-height: 41px;
  margin: 0 14px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 13px;
  border: 1px solid #a9dfbc;
  border-radius: 12px;
  color: #116e35 !important;
  background: #eefaf2;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none !important;
}
.fagi-whatsapp:hover { background: #e3f7e9; }
.fagi-whatsapp-icon { font-size: 13px; line-height: 1; }

.fagi-composer {
  min-height: 54px;
  margin: 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 7px 7px 12px;
  border: 1px solid #d9e5dc;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 7px 18px rgba(15,54,30,.05);
}
.fagi-composer textarea {
  flex: 1;
  min-height: 35px;
  max-height: 108px;
  padding: 8px 0 6px;
  border: 0 !important;
  outline: 0 !important;
  box-shadow: none !important;
  color: #213529;
  background: transparent;
  resize: none;
  font: inherit;
  font-size: 12.9px;
  line-height: 1.4;
}
.fagi-composer button {
  width: 48px;
  height: 40px;
  flex: 0 0 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: var(--fagi-secondary);
  box-shadow: 0 7px 15px rgba(0,127,95,.19);
  cursor: pointer;
}
.fagi-composer button:hover { background: #006b50; }
.fagi-composer button:disabled { opacity: .55; cursor: wait; }
.fagi-send-icon { font-size: 18px; font-weight: 900; line-height: 1; }
.fagi-footer-note {
  padding: 8px 12px 11px;
  color: #7e8c82;
  font-size: 9.3px;
  line-height: 1.3;
  text-align: center;
}

@media (max-width: 520px) {
  .fagi-root {
    right: 12px;
    bottom: var(--fagi-bottom-mobile, 90px);
  }
  .fagi-launcher { width: 43px; height: 43px; }
  .fagi-launcher-bot { width: 40px; height: 40px; }
  .fagi-help-bubble {
    right: 52px;
    min-width: 190px;
    padding: 10px 12px;
  }
  .fagi-root.is-open .fagi-launcher,
  .fagi-root.is-open .fagi-help-bubble { display: none; }
  .fagi-panel {
    position: fixed;
    inset: 9px;
    width: auto;
    height: auto;
    min-height: 0;
    border-radius: 18px;
  }
  .fagi-header {
    min-height: 91px;
    padding: 16px 13px 14px;
  }
  .fagi-avatar {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
    border-radius: 12px;
  }
  .fagi-brand-leaf { width: 27px; height: 27px; }
  .fagi-header-copy strong { font-size: 14.8px; }
  .fagi-header-copy small { font-size: 10.2px; }
  .fagi-header-chip { display: none; }
  .fagi-minimize { width: 32px; height: 32px; }
  .fagi-messages { padding: 14px 12px 10px; }
  .fagi-message-bubble { max-width: 92%; }
  .fagi-quick-wrap { padding: 2px 12px 8px; }
  .fagi-whatsapp { margin: 0 12px 9px; }
  .fagi-composer { margin: 0 10px; }
  .fagi-composer button { width: 45px; flex-basis: 45px; }
}

@media (prefers-reduced-motion: reduce) {
  .fagi-panel,
  .fagi-launcher,
  .fagi-help-bubble { transition: none; }
  .fagi-typing span { animation: none; }
}
