/* ============================================================
   Merik Co. — Chat Widget Styles
   ============================================================ */

:root {
  --chat-primary:   #8b5cf6;
  --chat-primary-d: #7c3aed;
  --chat-bg:        #ffffff;
  --chat-surface:   #f5f7fa;
  --chat-border:    #e2e8f0;
  --chat-text:      #1a202c;
  --chat-muted:     #718096;
  --chat-radius:    16px;
  --chat-shadow:    0 8px 40px rgba(0,0,0,.18);
  --chat-z:         99999;
}

/* ── Bubble trigger ── */
#mrfChatBubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  height: 52px;
  padding: 0 20px 0 16px;
  border-radius: 50px;
  background: var(--chat-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  z-index: var(--chat-z);
  box-shadow: 0 4px 24px rgba(139,92,246,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-family: 'DM Sans', system-ui, sans-serif;
  transition: transform .2s, background .2s, border-radius .25s, padding .25s, width .25s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  overflow: hidden;
}
#mrfChatBubble.open { width: 52px; padding: 0; border-radius: 50%; }
#mrfChatBubble:hover  { background: var(--chat-primary-d); transform: scale(1.05); }
#mrfChatBubble:active { transform: scale(.94); }

/* unread badge */
#mrfChatBadge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: #fff;
  border-radius: 50%;
  font-size: .68rem;
  font-weight: 700;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  display: none;
}

/* ── Chat window ── */
#mrfChatWindow {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 360px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 120px);
  background: var(--chat-bg);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  z-index: var(--chat-z);
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: mrfChatIn .22s ease;
  border: 1px solid var(--chat-border);
}
#mrfChatWindow.open { display: flex; }

@keyframes mrfChatIn {
  from { opacity: 0; transform: translateY(20px) scale(.96); }
  to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

/* ── Header ── */
.mrf-chat-header {
  background: var(--chat-primary);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.mrf-chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.mrf-chat-header-info { flex: 1; min-width: 0; }
.mrf-chat-header-title {
  font-weight: 700;
  font-size: .92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mrf-chat-header-status {
  font-size: .72rem;
  opacity: .85;
  display: flex;
  align-items: center;
  gap: 5px;
}
.mrf-chat-header-status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
}
.mrf-chat-header-status.offline::before { background: #fbbf24; }
.mrf-chat-header-close {
  background: rgba(255,255,255,.2);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  transition: background .15s;
  flex-shrink: 0;
}
.mrf-chat-header-close:hover { background: rgba(255,255,255,.35); }

/* ── Pre-chat form ── */
#mrfPreChat {
  padding: 20px 18px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.mrf-chat-field label {
  display: block;
  font-size: .78rem;
  font-weight: 600;
  color: var(--chat-muted);
  margin-bottom: 4px;
}
.mrf-chat-field input,
.mrf-chat-field select {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--chat-border);
  border-radius: 8px;
  font-size: .88rem;
  outline: none;
  color: var(--chat-text);
  background: var(--chat-bg);
  transition: border-color .2s;
  box-sizing: border-box;
}
.mrf-chat-field input:focus,
.mrf-chat-field select:focus { border-color: var(--chat-primary); }
.mrf-chat-start-btn {
  margin-top: 4px;
  padding: 11px;
  background: var(--chat-primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-weight: 700;
  font-size: .9rem;
  cursor: pointer;
  transition: background .2s;
  width: 100%;
}
.mrf-chat-start-btn:hover { background: var(--chat-primary-d); }

/* ── Messages area ── */
#mrfMessages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}
#mrfMessages::-webkit-scrollbar { width: 4px; }
#mrfMessages::-webkit-scrollbar-track { background: transparent; }
#mrfMessages::-webkit-scrollbar-thumb { background: var(--chat-border); border-radius: 4px; }

/* individual message */
.mrf-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: mrfMsgIn .18s ease;
}
@keyframes mrfMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0);   }
}
.mrf-msg.visitor   { align-self: flex-end; align-items: flex-end; }
.mrf-msg.agent,
.mrf-msg.bot       { align-self: flex-start; align-items: flex-start; }
.mrf-msg.system    { align-self: center; align-items: center; max-width: 95%; }

.mrf-msg-bubble {
  padding: 9px 13px;
  border-radius: 14px;
  font-size: .88rem;
  line-height: 1.5;
  word-break: break-word;
}
.mrf-msg.visitor .mrf-msg-bubble {
  background: var(--chat-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.mrf-msg.agent .mrf-msg-bubble,
.mrf-msg.bot   .mrf-msg-bubble {
  background: var(--chat-surface);
  color: var(--chat-text);
  border: 1px solid var(--chat-border);
  border-bottom-left-radius: 4px;
}
.mrf-msg.system .mrf-msg-bubble {
  background: transparent;
  color: var(--chat-muted);
  font-size: .75rem;
  font-style: italic;
  border: none;
  padding: 2px 6px;
  text-align: center;
}

/* agent joined / transfer / closed highlight */
.mrf-msg.system.event .mrf-msg-bubble {
  background: rgba(139,92,246,.08);
  border: 1px solid rgba(139,92,246,.2);
  border-radius: 8px;
  font-style: normal;
  font-weight: 600;
  color: var(--chat-primary-d);
  padding: 6px 12px;
  font-size: .78rem;
}

.mrf-msg-meta {
  font-size: .68rem;
  color: var(--chat-muted);
  margin-top: 2px;
  padding: 0 2px;
}

/* typing indicator */
#mrfTyping {
  display: none;
  align-self: flex-start;
  padding: 8px 14px;
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
#mrfTyping span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chat-muted);
  margin: 0 2px;
  animation: mrfDot 1.2s infinite;
}
#mrfTyping span:nth-child(2) { animation-delay: .2s; }
#mrfTyping span:nth-child(3) { animation-delay: .4s; }
@keyframes mrfDot {
  0%, 80%, 100% { transform: scale(.7); opacity: .5; }
  40%            { transform: scale(1);  opacity: 1;   }
}

/* ── Input area ── */
.mrf-chat-input-row {
  border-top: 1px solid var(--chat-border);
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
  background: var(--chat-bg);
}
#mrfInput {
  flex: 1;
  border: 1.5px solid var(--chat-border);
  border-radius: 20px;
  padding: 9px 14px;
  font-size: .88rem;
  outline: none;
  resize: none;
  max-height: 100px;
  min-height: 38px;
  line-height: 1.4;
  color: var(--chat-text);
  background: var(--chat-surface);
  transition: border-color .2s;
  overflow-y: auto;
  font-family: inherit;
}
#mrfInput:focus { border-color: var(--chat-primary); }
#mrfSendBtn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--chat-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  flex-shrink: 0;
  transition: background .2s, transform .15s;
  touch-action: manipulation;
}
#mrfSendBtn:hover  { background: var(--chat-primary-d); }
#mrfSendBtn:active { transform: scale(.9); }

/* ── Rating screen ── */
#mrfRating {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 20px;
  gap: 14px;
  text-align: center;
  flex: 1;
}
#mrfRating p { font-size: .92rem; color: var(--chat-text); font-weight: 600; margin: 0; }
.mrf-stars { display: flex; gap: 8px; }
.mrf-star {
  font-size: 1.6rem;
  cursor: pointer;
  color: #d1d5db;
  transition: color .15s, transform .15s;
}
.mrf-star:hover, .mrf-star.active { color: #f59e0b; transform: scale(1.15); }
.mrf-rating-thanks { font-size: .82rem; color: var(--chat-muted); }

/* ── Closed state ── */
#mrfClosed {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 20px;
  gap: 10px;
  text-align: center;
  flex: 1;
}
#mrfClosed p { font-size: .88rem; color: var(--chat-muted); margin: 0; }
.mrf-chat-new-btn {
  margin-top: 6px;
  padding: 9px 22px;
  background: var(--chat-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  font-size: .85rem;
  cursor: pointer;
  transition: background .2s;
}
.mrf-chat-new-btn:hover { background: var(--chat-primary-d); }

/* ── Mobile ── */
@media (max-width: 480px) {
  #mrfChatWindow {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    border-radius: var(--chat-radius) var(--chat-radius) 0 0;
  }
  #mrfChatBubble { bottom: 80px; right: 16px; }
}
