/* Royal Farms Chat Widget (CSP-safe) */

.rf-chat-widget {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 2147483000;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

.rf-chat-toggle {
  border: 0;
  background: var(--royal-farms-primary-green);
  color: #fff;
  height: 64px;
  padding: 0 8px 0 28px;
  border-radius: 999px;
  box-shadow: 0 12px 36px rgba(19, 86, 12, 0.3);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  transition: all 400ms cubic-bezier(0.175, 0.885, 0.32, 1.275);
  position: relative;
  animation: rf-chat-entrance 600ms cubic-bezier(0.2, 0.9, 0.2, 1.1) backwards;
  z-index: 2;
}

@keyframes rf-chat-entrance {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.8);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.rf-chat-toggle:hover {
  transform: translateY(-4px) scale(1.03);
  box-shadow: 0 16px 48px rgba(19, 86, 12, 0.4);
}

.rf-chat-toggle:active {
  transform: translateY(0) scale(0.96);
}

.rf-chat-toggle:focus {
  outline: 3px solid rgba(19, 86, 12, 0.3);
  outline-offset: 3px;
}

.rf-chat-toggle__text {
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.4px;
  user-select: none;
}

.rf-chat-toggle__icon-wrap {
  width: 30px;
  height: 30px;
  background: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 250ms ease;
  color: var(--royal-farms-primary-green);
}

.rf-chat-toggle:hover .rf-chat-toggle__icon-wrap {
  background: #f0f0f0;
  transform: scale(1.05);
}

.rf-chat-status {
  position: absolute;
  left: 4px;
  bottom: 4px;
  width: 16px;
  height: 16px;
  background: #29c51b;
  border: 4px solid #fff;
  border-radius: 50%;
  z-index: 3;
}

.rf-chat-status::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  background: inherit;
  animation: rf-chat-ping 2.5s infinite;
}

@keyframes rf-chat-ping {
  0% {
    transform: scale(1);
    opacity: 0.8;
  }

  75%,
  100% {
    transform: scale(3.5);
    opacity: 0;
  }
}

/* Attention-grabbing micro-animation when closed */
.rf-chat-widget:not(.rf-chat-panel--open) .rf-chat-toggle {
  animation: rf-chat-float 4s ease-in-out infinite, rf-chat-entrance 600ms cubic-bezier(0.2, 0.9, 0.2, 1.1) backwards;
}

@keyframes rf-chat-float {
  0% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-4px);
  }

  100% {
    transform: translateY(0);
  }
}

.rf-chat-panel {
  position: absolute;
  right: 0;
  bottom: 64px;
  width: 340px;
  max-width: calc(100vw - 36px);
  height: 420px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(0, 0, 0, 0.08);
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  pointer-events: none;
  visibility: hidden;
  transition: opacity 160ms ease, transform 180ms cubic-bezier(.2, .9, .2, 1), visibility 0ms linear 180ms;
}

.rf-chat-panel--open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  visibility: visible;
  transition: opacity 160ms ease, transform 180ms cubic-bezier(.2, .9, .2, 1), visibility 0ms;
}

.rf-chat-header {
  background: linear-gradient(135deg, #13560c 0%, #1a7111 100%);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rf-chat-title {
  font-weight: 700;
  font-size: 14px;
}

.rf-chat-close {
  border: 0;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
}

.rf-chat-close:hover {
  background: rgba(255, 255, 255, 0.20);
  transform: translateY(-1px);
}

.rf-chat-close:active {
  transform: translateY(0) scale(0.97);
}

.rf-chat-messages {
  flex: 1;
  padding: 12px;
  overflow: auto;
  background: #f6f8fa;
}

.rf-chat-bubble {
  margin: 8px 0;
  display: flex;
  animation: rf-chat-pop 180ms cubic-bezier(.2, .9, .2, 1);
}

@keyframes rf-chat-pop {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.rf-chat-bubble__text {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.45;
  max-width: 85%;
  white-space: pre-wrap;
  word-break: break-word;
}

.rf-chat-bubble--user {
  justify-content: flex-end;
}

.rf-chat-bubble--user .rf-chat-bubble__text {
  background: #13560c;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.rf-chat-bubble--bot .rf-chat-bubble__text {
  background: #fff;
  color: #222;
  border: 1px solid rgba(0, 0, 0, 0.05);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.03);
  border-bottom-left-radius: 4px;
}

.rf-chat-bubble--system .rf-chat-bubble__text {
  background: rgba(19, 86, 12, 0.08);
  color: #1f2d1f;
  border: 1px solid rgba(19, 86, 12, 0.10);
}

.rf-chat-bubble__text a {
  color: #13560c;
  text-decoration: underline;
  font-weight: 600;
}

.rf-chat-bubble--user .rf-chat-bubble__text a {
  color: #fff;
}

.rf-chat-bubble__text a:hover {
  text-decoration: none;
  opacity: 0.8;
}

.rf-chat-actions {
  padding: 10px 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  background: #fff;
}

.rf-chat-action {
  width: 100%;
  border: 1px solid rgba(0, 0, 0, 0.10);
  background: #fff;
  color: #222;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 8px;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.rf-chat-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.08);
  border-color: rgba(0, 0, 0, 0.18);
}

.rf-chat-action:active {
  transform: translateY(0) scale(0.99);
}

.rf-chat-action--whatsapp {
  border-color: rgba(37, 211, 102, 0.4);
}

.rf-chat-suggestions__title {
  font-size: 12px;
  font-weight: 700;
  color: #445;
  margin: 8px 0;
}

.rf-chat-suggestion {
  width: 100%;
  text-align: left;
  border: 0;
  background: #f1f3f5;
  color: #222;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 12.5px;
  margin-bottom: 8px;
  transition: transform 160ms ease, background 160ms ease;
}

.rf-chat-suggestion:hover {
  background: #e9ecef;
  transform: translateY(-1px);
}

.rf-chat-suggestion:active {
  transform: translateY(0) scale(0.99);
}

.rf-chat-footer {
  padding: 10px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  display: flex;
  gap: 8px;
  background: #fff;
}

.rf-chat-input {
  flex: 1;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 10px;
  padding: 10px 10px;
  font-size: 13px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.rf-chat-input:focus {
  outline: none;
  border-color: rgba(19, 86, 12, 0.45);
  box-shadow: 0 0 0 3px rgba(19, 86, 12, 0.14);
}

.rf-chat-send {
  border: 0;
  background: #13560c;
  color: #fff;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease, filter 160ms ease, opacity 160ms ease;
}

.rf-chat-send:hover {
  filter: brightness(1.03);
  transform: translateY(-1px);
}

.rf-chat-send:active {
  transform: translateY(0) scale(0.98);
}

.rf-chat-send:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
}

.rf-chat-bubble--typing .rf-chat-bubble__text {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.rf-chat-typing {
  display: inline-flex;
  gap: 4px;
  line-height: 1;
}

.rf-chat-typing__dot {
  display: inline-block;
  transform: translateY(0);
  opacity: 0.55;
  animation: rf-chat-dot 900ms infinite ease-in-out;
}

.rf-chat-typing__dot:nth-child(2) {
  animation-delay: 120ms;
}

.rf-chat-typing__dot:nth-child(3) {
  animation-delay: 240ms;
}

@keyframes rf-chat-dot {

  0%,
  100% {
    transform: translateY(0);
    opacity: 0.55;
  }

  50% {
    transform: translateY(-3px);
    opacity: 0.9;
  }
}

.rf-chat-modal {
  position: fixed;
  inset: 0;
  z-index: 2147483002;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 160ms ease, visibility 0ms linear 180ms;
}

.rf-chat-modal--open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 160ms ease, visibility 0ms;
}

.rf-chat-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(2px);
}

.rf-chat-modal__dialog {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.98);
  width: min(420px, calc(100vw - 36px));
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.30);
  border: 1px solid rgba(0, 0, 0, 0.08);
  overflow: hidden;
  transition: transform 180ms cubic-bezier(.2, .9, .2, 1);
}

.rf-chat-modal--open .rf-chat-modal__dialog {
  transform: translate(-50%, -50%) scale(1);
}

.rf-chat-modal__header {
  padding: 12px 12px;
  background: linear-gradient(135deg, #13560c 0%, #0f7a3c 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rf-chat-modal__title {
  font-weight: 800;
  font-size: 14px;
}

.rf-chat-modal__close {
  border: 0;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
}

.rf-chat-modal__close:hover {
  background: rgba(255, 255, 255, 0.20);
  transform: translateY(-1px);
}

.rf-chat-modal__close:active {
  transform: translateY(0) scale(0.97);
}

.rf-chat-modal__body {
  padding: 12px;
  background: #fff;
}

.rf-chat-modal__footer {
  padding: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  background: #fff;
}

.rf-chat-modal__form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rf-chat-modal__hint {
  font-size: 12.5px;
  color: #344;
}

.rf-chat-modal__input,
.rf-chat-modal__textarea {
  width: 100%;
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: 10px;
  padding: 10px 10px;
  font-size: 13px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.rf-chat-modal__textarea {
  resize: vertical;
  min-height: 70px;
}

.rf-chat-modal__input:focus,
.rf-chat-modal__textarea:focus {
  outline: none;
  border-color: rgba(19, 86, 12, 0.45);
  box-shadow: 0 0 0 3px rgba(19, 86, 12, 0.14);
}

.rf-chat-modal__error {
  font-size: 12.5px;
  color: #9b1c1c;
  min-height: 16px;
}

.rf-chat-btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 160ms ease, filter 160ms ease, background 160ms ease, opacity 160ms ease;
}

.rf-chat-btn--primary {
  background: #13560c;
  color: #fff;
}

.rf-chat-btn--primary:hover {
  filter: brightness(1.03);
  transform: translateY(-1px);
}

.rf-chat-btn--primary:active {
  transform: translateY(0) scale(0.98);
}

.rf-chat-btn--ghost {
  background: #eef2f4;
  color: #223;
}

.rf-chat-btn--ghost:hover {
  background: #e6ebee;
  transform: translateY(-1px);
}

.rf-chat-btn--ghost:active {
  transform: translateY(0) scale(0.98);
}

@media (prefers-reduced-motion: reduce) {

  .rf-chat-toggle,
  .rf-chat-panel,
  .rf-chat-bubble,
  .rf-chat-action,
  .rf-chat-suggestion,
  .rf-chat-input,
  .rf-chat-send,
  .rf-chat-modal,
  .rf-chat-modal__dialog,
  .rf-chat-modal__close,
  .rf-chat-btn {
    transition: none !important;
    animation: none !important;
  }

  .rf-chat-typing__dot {
    animation: none !important;
  }
}

@media (max-width: 480px) {
  .rf-chat-panel {
    width: min(360px, calc(100vw - 36px));
    height: min(520px, calc(100vh - 120px));
  }
}