:root { --jai-primary: #0A4DA2; }

#jewechwi-chat-box,
#ai-chat-box {
  position: fixed;
  bottom: 20px;
  width: 340px;
  max-width: calc(100vw - 24px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 34px rgba(0,0,0,.22);
  font-family: Arial, sans-serif;
  z-index: 2147483000;
  overflow: hidden;
  transition: transform .2s ease, opacity .2s ease, width .2s ease;
  box-sizing: border-box;
}

#jewechwi-chat-box.pos-right,
#ai-chat-box.pos-right {
  right: 20px;
  left: auto;
}

#jewechwi-chat-box.pos-left,
#ai-chat-box.pos-left {
  left: 20px;
  right: auto;
}

#jewechwi-chat-box.minimized,
#ai-chat-box.minimized {
  width: auto;
  max-width: none;
  background: transparent;
  box-shadow: none;
  overflow: visible;
  border-radius: 999px;
}

#jewechwi-chat-header,
#ai-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--jai-primary);
  color: #fff;
  padding: 12px 16px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 16px 16px 0 0;
  min-height: 70px;
  box-sizing: border-box;
  user-select: none;
  touch-action: manipulation;
}

#jewechwi-chat-box.minimized #jewechwi-chat-header,
#ai-chat-box.minimized #ai-chat-header {
  padding: 8px;
  border-radius: 999px;
  min-height: auto;
  justify-content: center;
  box-shadow: 0 10px 24px rgba(0,0,0,.22);
}

#jewechwi-chat-header img,
#ai-chat-header img,
#jewechwi-chat-avatar,
#ai-chat-avatar {
  width: 46px !important;
  height: 46px !important;
  min-width: 46px !important;
  min-height: 46px !important;
  border-radius: 60% !important;
  object-fit: cover !important;
  flex-shrink: 0 !important;
  border: 2px solid #fff;
  background: #fff;
  display: block;
}

#jewechwi-chat-title,
#ai-chat-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#jewechwi-chat-wa,
#ai-chat-wa {
  margin-left: auto;
  font-size: 12px;
  color: #fff;
  text-decoration: none;
  padding: 6px 10px;
  border: 1px solid rgba(255,255,255,.6);
  border-radius: 999px;
  transition: all .2s ease;
  flex-shrink: 0;
}

#jewechwi-chat-box.minimized #jewechwi-chat-title,
#jewechwi-chat-box.minimized #jewechwi-chat-wa,
#ai-chat-box.minimized #ai-chat-title,
#ai-chat-box.minimized #ai-chat-wa {
  display: none;
}

#jewechwi-chat-messages,
#ai-chat-messages {
  padding: 15px;
  max-height: 320px;
  overflow-y: auto;
  background: #fafafa;
  scroll-behavior: smooth;
  box-sizing: border-box;
}

#jewechwi-chat-messages a,
#ai-chat-messages a {
  color: var(--jai-primary);
  font-weight: 600;
  text-decoration: none;
  overflow-wrap: anywhere;
}

#jewechwi-chat-input,
#ai-chat-input {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid #eee;
  background: #fff;
  box-sizing: border-box;
}

#jewechwi-chat-input input,
#ai-chat-input input {
  flex: 1;
  min-height: 46px;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid #d8dee8;
  background: #fff;
  outline: none;
  font-size: 14px;
  min-width: 0;
  box-sizing: border-box;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}

#jewechwi-chat-input input::placeholder,
#ai-chat-input input::placeholder {
  color: #6b7280;
}

#jewechwi-chat-input button,
#ai-chat-input button {
  background: var(--jai-primary);
  color: #fff;
  border: none;
  border-radius: 999px;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
  padding: 0;
  margin: 0;
  line-height: 1;
  font-size: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
  touch-action: manipulation;
  position: relative;
  flex-shrink: 0;
}

#jewechwi-chat-input button::before,
#ai-chat-input button::before {
  content: none !important;
  display: none !important;
}

#jewechwi-chat-input button:hover,
#ai-chat-input button:hover {
  filter: brightness(1.06);
}

#jewechwi-chat-input button:active,
#ai-chat-input button:active {
  transform: scale(0.96);
}

#jewechwi-chat-input input:focus,
#ai-chat-input input:focus {
  border-color: rgba(10,77,162,.36);
  box-shadow: 0 0 0 3px rgba(10,77,162,.12);
}

#jewechwi-chat-input button:focus,
#ai-chat-input button:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(10,77,162,.18);
}

#jewechwi-chat-input button .jewechwi-send-svg,
#ai-chat-input button .jewechwi-send-svg {
  width: 18px;
  height: 18px;
  display: block;
  fill: #fff;
  transform: translateX(1px) translateY(0);
  transform-origin: center;
  pointer-events: none;
  flex-shrink: 0;
}

#jewechwi-chat-box.minimized #jewechwi-chat-messages,
#jewechwi-chat-box.minimized #jewechwi-chat-input,
#ai-chat-box.minimized #ai-chat-messages,
#ai-chat-box.minimized #ai-chat-input {
  display: none;
}

.clarisse-message,
.jewechwi-agent-message {
  padding: 10px 12px;
  margin: 8px 0;
  background: #f6f8fa;
  border-radius: 10px;
  line-height: 1.45;
  color: #1f2937;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.user-message,
.jewechwi-user-message {
  padding: 8px 10px;
  margin: 8px 0;
  background: #eef4ff;
  border-radius: 10px;
  line-height: 1.45;
  color: #111827;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.clarisse-loader,
.jewechwi-loader {
  font-size: .92em;
  color: #666;
  margin: 8px 0;
  padding: 4px 2px;
}

@media (max-width: 768px) {
  #jewechwi-chat-box,
  #ai-chat-box {
    width: min(360px, calc(100vw - 16px));
    max-width: calc(100vw - 16px);
    right: 8px !important;
    left: auto !important;
    bottom: max(8px, env(safe-area-inset-bottom));
  }

  #jewechwi-chat-box.pos-left,
  #ai-chat-box.pos-left {
    left: 8px !important;
    right: auto !important;
  }

  #jewechwi-chat-box.minimized,
  #ai-chat-box.minimized {
    width: auto;
    max-width: none;
  }

  #jewechwi-chat-messages,
  #ai-chat-messages {
    max-height: 45vh;
  }

  #jewechwi-chat-input button,
  #ai-chat-input button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  #jewechwi-chat-input button .jewechwi-send-svg,
  #ai-chat-input button .jewechwi-send-svg {
    width: 18px;
    height: 18px;
    transform: translateX(1px) translateY(0);
  }
}
