/* ===== Chatbox Widget ===== */

/* Toggle button */
.chatbox-toggle-btn {
  position: fixed;
  bottom: 82px;
  right: 20px;
  z-index: 10001;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background: var(--white, #fff);
  color: var(--black-2, #121212);
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  mix-blend-mode: exclusion;
}

.chatbox-toggle-btn:hover {
  color: var(--gray-2, #999);
  transform: translateY(-2px);
}

.chatbox-toggle-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Badge */
.chatbox-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--black-2, #121212);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Window */
.chatbox-window {
  position: fixed;
  bottom: 146px;
  right: 20px;
  z-index: 10000;
  width: 370px;
  max-width: calc(100vw - 32px);
  border-radius: 16px;
  border: 1px solid var(--white-4, #f0f0f0);
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  background: var(--white, #fff);
  font-family: "Kanit", sans-serif;
  animation: chatboxSlideUp 0.3s ease;
}

@keyframes chatboxSlideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Header */
.chatbox-header {
  background: var(--black-2, #121212);
  color: var(--white, #fff);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chatbox-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chatbox-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--black-2, #121212);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.chatbox-close-btn {
  background: none;
  border: none;
  color: var(--white, #fff);
  font-size: 20px;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.chatbox-close-btn:hover {
  opacity: 1;
  color: var(--primary);
}

/* Welcome */
.chatbox-welcome {
  padding: 24px 20px;
  text-align: center;
  background: var(--white, #fff);
  color: var(--black-2, #121212);
  border-bottom: 1px solid var(--white-4, #f0f0f0);
}

.chatbox-welcome .form-control {
  border-radius: 8px;
  border: none;
  font-size: 0.875rem;
}

.chatbox-welcome .btn {
  border-radius: 8px;
  font-weight: 500;
}

/* Messages area */
.chatbox-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  min-height: 260px;
  max-height: 360px;
  background: var(--white-4, #f5f7fa);
}

/* Bubbles */
.chatbox-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  margin-bottom: 8px;
  word-wrap: break-word;
  font-size: 0.875rem;
  line-height: 1.4;
  position: relative;
}

.chatbox-bubble.visitor {
  background: var(--white, #fff);
  color: var(--black-2, #121212);
  border: 1px solid var(--white-4, #f0f0f0);
  border-bottom-left-radius: 4px;
  margin-right: auto;
}

.chatbox-bubble.admin {
  background: var(--primary);
  color: var(--black-2, #121212);
  border-bottom-right-radius: 4px;
  margin-left: auto;
}

.chatbox-bubble-time {
  font-size: 0.68rem;
  opacity: 0.6;
  margin-top: 4px;
  text-align: right;
}

/* Typing indicator */
.chatbox-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  font-size: 0.75rem;
  color: var(--gray-2, #999);
}

.chatbox-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gray-5, #bbb);
  animation: chatboxDot 1.4s infinite;
}

.chatbox-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.chatbox-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes chatboxDot {
  0%,
  60%,
  100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  30% {
    opacity: 1;
    transform: scale(1.1);
  }
}

/* Input area */
.chatbox-input-area {
  padding: 12px;
  border-top: 1px solid var(--white-4, #f0f0f0);
  background: var(--white, #fff);
}

.chatbox-input-area .form-control {
  border-radius: 20px;
  border: 1px solid var(--white-4, #f0f0f0);
  padding: 8px 16px;
  font-size: 0.875rem;
}

.chatbox-input-area .form-control:focus {
  box-shadow: none;
  border-color: var(--primary);
}

.chatbox-send-btn {
  border-radius: 50%;
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--black-2, #121212);
  color: var(--primary);
  border: none;
  margin-left: 6px;
  transition: transform 0.2s;
}

.chatbox-send-btn:hover {
  transform: scale(1.08);
  background: var(--primary);
  color: var(--black-2, #121212);
}

@media only screen and (min-width: 992px) and (max-width: 1199px) {
  .chatbox-toggle-btn {
    right: 20px;
    bottom: 142px;
  }

  .chatbox-window {
    right: 20px;
    bottom: 206px;
  }
}

@media only screen and (min-width: 768px) and (max-width: 991px) {
  .chatbox-toggle-btn {
    right: 10px;
    bottom: 122px;
  }

  .chatbox-window {
    right: 10px;
    bottom: 186px;
    width: 360px;
  }
}

/* Mobile */
@media only screen and (max-width: 767px) {
  .chatbox-window {
    width: calc(100vw - 16px);
    right: 8px;
    bottom: 170px;
    border-radius: 12px;
  }

  .chatbox-toggle-btn {
    right: 5px;
    bottom: 117px;
    width: 50px;
    height: 50px;
    font-size: 20px;
  }
}
