.iai-widget {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 99999;
  font-family: Arial, sans-serif;
}

.iai-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px 10px 10px;
  background: #d5222a;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(213, 34, 42, 0.28);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.iai-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(213, 34, 42, 0.38);
}

.iai-toggle.iai-blink {
  animation: iai-blink 1.1s ease-in-out infinite;
}

@keyframes iai-blink {
  0%, 100% { box-shadow: 0 8px 24px rgba(213, 34, 42, 0.28); }
  50% { box-shadow: 0 0 0 6px rgba(213, 34, 42, 0.32); }
}

.iai-unread {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #facc15;
  color: #111;
  font-size: 11px;
  font-weight: 800;
  border-radius: 999px;
  min-width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  animation: iai-pop 0.25s ease;
}

@keyframes iai-pop {
  0% { transform: scale(0.4); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.iai-toggle-logo {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: contain;
  background: #fff;
  border: 1px solid rgba(255, 255, 255, 0.55);
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  backface-visibility: hidden;
  transform-style: preserve-3d;
  will-change: transform;
  animation: iai-logo-coin-flip 9s ease-in-out infinite;
}

.iai-toggle-text {
  line-height: 1.1;
  text-align: left;
}

@keyframes iai-logo-coin-flip {
  0% { transform: rotateY(0deg); }
  8% { transform: rotateY(180deg); }
  16% { transform: rotateY(360deg); }
  24% { transform: rotateY(540deg); }
  32% { transform: rotateY(720deg); }
  100% { transform: rotateY(720deg); }
}

.iai-panel {
  position: relative;
  width: 360px;
  max-width: calc(100vw - 36px);
  height: min(78vh, 760px);
  min-height: 540px;
  margin-top: 10px;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  border: 1px solid #e5e7eb;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: iai-panel-in 0.2s ease;
}

@keyframes iai-panel-in {
  0% { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}

.iai-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  z-index: 5;
  background:
    linear-gradient(135deg, transparent 0 6px, rgba(0,0,0,0.25) 6px 7px, transparent 7px 100%),
    linear-gradient(135deg, transparent 0 9px, rgba(0,0,0,0.25) 9px 10px, transparent 10px 100%);
}

@media (max-width: 767px) {
  .iai-panel {
    max-width: calc(100vw - 20px);
    height: 82vh;
    min-height: 0;
  }
  .iai-resize-handle { display: none; }
}

.iai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: #0f172a;
  color: #fff;
}

.iai-title {
  margin: 0;
  font-size: 15px;
}

.iai-close {
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}

.iai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: #f8fafc;
  scroll-behavior: smooth;
}

.iai-message {
  max-width: 85%;
  padding: 10px 12px;
  margin: 0 0 8px;
  border-radius: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
}

.iai-anim-in {
  animation: iai-msg-in 0.25s ease;
}

@keyframes iai-msg-in {
  0% { opacity: 0; transform: translateY(6px); }
  100% { opacity: 1; transform: translateY(0); }
}

.iai-user {
  margin-left: auto;
  background: #d5222a;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.iai-assistant {
  margin-right: auto;
  background: #fff;
  color: #111827;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}

.iai-msg-content {
  white-space: pre-wrap;
}

.iai-assistant a {
  color: #c61d25;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}

.iai-assistant a:hover {
  color: #9f141b;
}

.iai-assistant.typing {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 12px 14px;
}

.iai-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #d5222a;
  display: inline-block;
  opacity: 0.5;
  animation: iai-dot-bounce 1s ease-in-out infinite;
}

.iai-dot:nth-child(2) { animation-delay: 0.15s; }
.iai-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes iai-dot-bounce {
  0%, 100% { transform: translateY(0); opacity: 0.4; }
  50% { transform: translateY(-4px); opacity: 1; }
}

.iai-show-more {
  display: inline-block;
  margin-top: 6px;
  background: transparent;
  color: #c61d25;
  border: 1px solid #d5222a;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.iai-show-more:hover {
  background: #fff5f5;
}

.iai-reactions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.iai-react-btn {
  border: 1px solid #e5e7eb;
  background: #fff;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}

.iai-react-btn:hover { transform: scale(1.1); }
.iai-react-btn.picked { background: #d5222a; color: #fff; border-color: #d5222a; }

.iai-whatsapp-cta {
  display: inline-block;
  margin-top: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: #25d366;
  color: #fff !important;
  text-decoration: none !important;
  font-weight: 600;
  font-size: 13px;
  box-shadow: 0 4px 10px rgba(37, 211, 102, 0.25);
}

.iai-whatsapp-cta:hover {
  background: #1ebd5a;
}

.iai-handover-box {
  margin: 8px 0;
  padding: 10px;
  border: 1px solid #f0d0d2;
  border-radius: 10px;
  background: #fff7f7;
}

.iai-handover-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
  color: #1f2937;
}

.iai-handover-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.iai-handover-name,
.iai-handover-phone {
  flex: 1;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 13px;
}

.iai-handover-send {
  border: 0;
  background: #d5222a;
  color: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
}

.iai-handover-send:hover {
  background: #b1191f;
}

.iai-quick-box {
  margin: 0 0 10px;
  padding: 10px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #fff;
}

.iai-quick-label {
  display: block;
  font-size: 13px;
  color: #374151;
  margin-bottom: 6px;
}

.iai-quick-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.iai-quick-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: #d5222a;
  color: #fff;
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13px;
  line-height: 1.3;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.iai-quick-item:hover {
  background: #b1191f;
  transform: translateX(2px);
}

.iai-feedback-box {
  margin: 10px 0;
  padding: 10px;
  border: 1px solid #f0d0d2;
  border-radius: 10px;
  background: #fff7f7;
}

.iai-feedback-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

.iai-feedback-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.iai-feedback-btn {
  border: 1px solid #d5222a;
  background: #fff;
  color: #d5222a;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

.iai-feedback-btn.active {
  background: #d5222a;
  color: #fff;
}

.iai-feedback-comment {
  width: 100%;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 8px;
  resize: vertical;
  margin-bottom: 8px;
}

.iai-feedback-send {
  border: none;
  background: #d5222a;
  color: #fff;
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}

.iai-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
}

.iai-input {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
}

.iai-input:focus {
  outline: 2px solid #fee2e2;
  border-color: #d5222a;
}

.iai-send {
  border: 0;
  background: #111827;
  color: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 14px;
}

.iai-send:hover {
  background: #1f2937;
}

@media (prefers-reduced-motion: reduce) {
  .iai-anim-in,
  .iai-toggle-logo,
  .iai-toggle.iai-blink,
  .iai-unread {
    animation: none !important;
  }
  .iai-messages { scroll-behavior: auto; }
}
