/* ============================================
   PUBLIC CHAT WIDGET — Floating bubble + panel
   ============================================ */

.chat-widget {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* --- Floating Bubble --- */
.chat-widget__bubble {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7C6AE8 0%, #5B4BC7 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(124, 106, 232, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.25s ease;
  position: relative;
}

.chat-widget__bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 32px rgba(124, 106, 232, 0.45);
}

.chat-widget__bubble svg {
  width: 28px;
  height: 28px;
  transition: opacity 0.2s, transform 0.2s;
}

.chat-widget__bubble .icon-close {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

.chat-widget.open .chat-widget__bubble .icon-chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

.chat-widget.open .chat-widget__bubble .icon-close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

.chat-widget__unread {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #EF4444;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

.chat-widget__unread.visible {
  display: flex;
}

/* --- Chat Panel --- */
.chat-widget__panel {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 370px;
  max-height: 520px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(16px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-widget.open .chat-widget__panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* --- Panel Header --- */
.chat-widget__header {
  background: linear-gradient(135deg, #7C6AE8 0%, #5B4BC7 100%);
  color: #fff;
  padding: 1.25rem 1.25rem 1rem;
}

.chat-widget__header-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.chat-widget__header-subtitle {
  font-size: 0.8rem;
  opacity: 0.8;
}

/* --- Pre-chat Form (name/email) --- */
.chat-widget__prechat {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.chat-widget__prechat label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #1A1A2E;
  display: block;
  margin-bottom: 0.3rem;
}

.chat-widget__prechat input {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1.5px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  font-size: 0.85rem;
  font-family: inherit;
  transition: border-color 0.2s;
}

.chat-widget__prechat input:focus {
  outline: none;
  border-color: #7C6AE8;
  box-shadow: 0 0 0 3px rgba(124, 106, 232, 0.15);
}

.chat-widget__prechat-btn {
  background: #7C6AE8;
  color: #fff;
  border: none;
  padding: 0.65rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s;
}

.chat-widget__prechat-btn:hover {
  background: #5B4BC7;
}

/* --- Messages Area --- */
.chat-widget__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 200px;
  max-height: 320px;
}

.chat-widget__msg {
  max-width: 80%;
  padding: 0.6rem 0.9rem;
  border-radius: 12px;
  font-size: 0.84rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-widget__msg--visitor {
  background: #F0EEFF;
  color: #1A1A2E;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.chat-widget__msg--admin {
  background: #F3F4F6;
  color: #1A1A2E;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.chat-widget__msg--system {
  background: transparent;
  color: #9CA3AF;
  align-self: center;
  font-size: 0.75rem;
  text-align: center;
}

.chat-widget__msg-time {
  font-size: 0.65rem;
  color: #9CA3AF;
  margin-top: 0.2rem;
}

.chat-widget__typing {
  font-size: 0.75rem;
  color: #9CA3AF;
  padding: 0 1rem 0.5rem;
  display: none;
}

/* --- Input Area --- */
.chat-widget__input-area {
  padding: 0.75rem 1rem;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.chat-widget__input {
  flex: 1;
  padding: 0.55rem 0.85rem;
  border: 1.5px solid rgba(0, 0, 0, 0.1);
  border-radius: 20px;
  font-size: 0.84rem;
  font-family: inherit;
  transition: border-color 0.2s;
}

.chat-widget__input:focus {
  outline: none;
  border-color: #7C6AE8;
}

.chat-widget__send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #7C6AE8;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

.chat-widget__send:hover {
  background: #5B4BC7;
}

.chat-widget__send svg {
  width: 18px;
  height: 18px;
}

/* --- Hidden states --- */
.chat-widget__view { display: none; }
.chat-widget__view.active { display: flex; flex-direction: column; flex: 1; }

/* --- Responsive --- */
@media (max-width: 480px) {
  .chat-widget__panel {
    width: calc(100vw - 2rem);
    right: -0.5rem;
    bottom: 70px;
    max-height: 70vh;
  }
}
