.chat-widget * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.chat-widget {
  direction: rtl;
}

/* Toggle button */
.chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgb(147 51 234 / 0.8) 0%, rgb(147 51 234) 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgb(147 51 234 / 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999999;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-toggle:hover {
  transform: scale(1.1) rotate(5deg);
  box-shadow: 0 6px 28px rgb(147 51 234 / 0.55);
}

/* Chat box container */
.chat-box {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 380px;
  height: 560px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18);
  display: none;
  flex-direction: column;
  z-index: 999998;
  overflow: hidden;
  animation: chatSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.chat-box.open {
  display: flex;
}

/* Header */
.chat-header {
  background: linear-gradient(135deg, rgb(147 51 234 / 0.8) 0%, rgb(147 51 234) 100%);
  color: #fff;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.header-info {
  display: flex;
  flex-direction: column;
}

.header-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.3px;
}

.header-phone {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 2px;
}

.chat-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.chat-close:hover {
  background: rgba(255, 255, 255, 0.35);
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f0f2f5;
  display: none;
}

.chat-messages:empty {
  display: block;
}

.chat-messages:not(:empty) {
  display: block;
}

.chat-msg {
  margin-bottom: 12px;
  max-width: 85%;
  clear: both;
}

.chat-msg.visitor {
  float: left;
}

.chat-msg.admin {
  float: right;
}

.chat-msg .bubble {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.chat-msg .msg-content {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  position: relative;
}

.chat-msg.visitor .msg-content {
  background: linear-gradient(135deg, rgb(147 51 234 / 0.8) 0%, rgb(147 51 234) 100%);
  color: #fff;
  border-bottom-left-radius: 4px;
}

.chat-msg.admin .msg-content {
  background: #fff;
  color: #1a1a1a;
  border-bottom-right-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.admin-avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgb(147 51 234 / 0.8) 0%, rgb(147 51 234) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  margin-top: 2px;
}

.chat-msg .time {
  font-size: 10px;
  color: #999;
  margin-top: 3px;
  padding: 0 4px;
  clear: both;
}

.chat-msg.visitor .time {
  text-align: left;
  padding-left: 14px;
}

.chat-msg.admin .time {
  padding-right: 42px;
}

.msg-image {
  max-width: 220px;
  max-height: 200px;
  border-radius: 12px;
  display: block;
  cursor: pointer;
  transition: transform 0.2s;
}

.msg-image:hover {
  transform: scale(1.02);
}

/* Phone form */
.chat-phone-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 28px;
  background: #f8f9fc;
  text-align: center;
}

.phone-form-icon {
  font-size: 56px;
  margin-bottom: 16px;
  opacity: 0.7;
}

.phone-form-label {
  font-size: 15px;
  color: #555;
  margin-bottom: 20px;
  line-height: 1.5;
}

.phone-form-input-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.phone-form-input-wrap .phone-input:first-child {
  margin-bottom: 2px;
}

.phone-input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  font-size: 16px;
  color: #222;
  outline: none;
  transition: border-color 0.2s;
  text-align: center;
  direction: ltr;
}

.phone-input:focus {
  border-color: rgb(147 51 234 / 1);
}

.phone-start-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, rgb(147 51 234 / 0.8) 0%, rgb(147 51 234) 100%);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
}

.phone-start-btn:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

.phone-start-btn:active {
  transform: translateY(0);
}

/* Image preview bar */
.chat-image-preview {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: #f5f5f5;
  border-top: 1px solid #e8e8e8;
}

.chat-image-preview.show {
  display: flex;
}

.preview-img {
  width: 38px;
  height: 38px;
  object-fit: cover;
  border-radius: 8px;
}

.img-name {
  font-size: 12px;
  color: #666;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-send-btn {
  padding: 6px 16px;
  background: linear-gradient(135deg, rgb(147 51 234 / 0.8) 0%, rgb(147 51 234) 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.preview-send-btn:hover {
  opacity: 0.88;
}

.preview-remove-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: #c00;
  padding: 2px 6px;
  line-height: 1;
}

/* Input area */
.chat-input-area {
  display: none;
  align-items: center;
  padding: 10px 12px;
  border-top: 1px solid #e8e8e8;
  background: #fff;
  gap: 8px;
  flex-shrink: 0;
}

.chat-text-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 10px 4px;
  font-size: 14px;
  color: #222;
  background: transparent;
}

.chat-text-input::placeholder {
  color: #aaa;
}

.img-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #888;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.img-btn:hover {
  color: rgb(147 51 234);
  background: rgba(102, 126, 234, 0.08);
}

.send-btn {
  background: linear-gradient(135deg, rgb(147 51 234 / 0.8) 0%, rgb(147 51 234) 100%);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.15s;
}

.send-btn:hover {
  opacity: 0.9;
  transform: scale(1.05);
}

.send-btn:active {
  transform: scale(0.95);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Scrollbar styling */
.chat-messages::-webkit-scrollbar {
  width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #c1c7cd;
  border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #a8b0b8;
}

/* Mobile responsive */
@media (max-width: 480px) {
  .chat-box {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
  }

  .chat-toggle {
    bottom: 16px;
    right: 16px;
    width: 50px;
    height: 50px;
  }

  .chat-msg {
    max-width: 90%;
  }

  .phone-form-label {
    font-size: 14px;
  }

  .chat-input-area {
    padding: 8px 10px;
  }
}
