/* ==========================================
   MaPaMe Chat Panel — Elderly-Friendly AI Assistant
   Floating overlay, voice input, warm palette
   ========================================== */

/* Widget container — fixed bottom-right, always on top */
#mp-chat-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9500;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Floating trigger button — 72px for elderly touch targets */
#mp-chat-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--bg-sidebar) 100%);
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(93, 64, 55, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  color: #FFFFFF;
}
#mp-chat-btn:hover {
  transform: scale(1.06);
  box-shadow: 0 8px 32px rgba(93, 64, 55, 0.5);
}
#mp-chat-btn svg {
  width: 32px;
  height: 32px;
  fill: currentColor;
}
#mp-chat-btn .mp-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  background: var(--secondary);
  border-radius: 50%;
  border: 2px solid #FFFFFF;
}

/* Chat panel — slide-up from button */
#mp-chat-panel {
  display: none;
  position: absolute;
  bottom: 84px;
  right: 0;
  width: 420px;
  height: 580px;
  background: var(--bg-page);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
  overflow: hidden;
  flex-direction: column;
}
#mp-chat-panel.open {
  display: flex;
  animation: mp-slide-up 0.25s ease;
}
@keyframes mp-slide-up {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Header — warm brown gradient */
#mp-chat-header {
  background: linear-gradient(135deg, var(--bg-sidebar) 0%, #4E342E 100%);
  color: var(--text-on-sidebar);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}
.mp-chat-avatar {
  width: 44px;
  height: 44px;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.mp-chat-info h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: #FFFFFF;
}
.mp-chat-info p {
  margin: 3px 0 0;
  font-size: 0.78rem;
  color: var(--text-on-sidebar-muted);
}
#mp-chat-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-on-sidebar);
  cursor: pointer;
  font-size: 28px;
  opacity: 0.7;
  transition: opacity 0.15s;
  padding: 4px 8px;
  line-height: 1;
}
#mp-chat-close:hover { opacity: 1; }

/* Messages area */
#mp-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--bg-page);
}
#mp-chat-messages::-webkit-scrollbar { width: 6px; }
#mp-chat-messages::-webkit-scrollbar-track { background: transparent; }
#mp-chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }

/* Message bubbles */
.mp-msg {
  max-width: 88%;
  padding: 14px 18px;
  border-radius: 18px;
  font-size: 1rem;
  line-height: 1.6;
  word-wrap: break-word;
}
.mp-msg.bot {
  background: var(--bg-card);
  color: var(--text-primary);
  align-self: flex-start;
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.mp-msg.user {
  background: var(--bg-sidebar);
  color: var(--text-on-sidebar);
  align-self: flex-end;
  border-bottom-right-radius: 6px;
}
.mp-msg.system {
  background: var(--cat-family-bg);
  color: var(--text-secondary);
  align-self: center;
  text-align: center;
  font-size: 0.88rem;
  padding: 10px 16px;
  border-radius: 12px;
}
.mp-msg strong { font-weight: 700; }

/* Typing indicator */
.mp-msg.typing {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  align-self: flex-start;
  border-bottom-left-radius: 6px;
  padding: 14px 22px;
}
.mp-typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.mp-typing-dots span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: mp-dot-bounce 1.4s ease-in-out infinite;
}
.mp-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.mp-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes mp-dot-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Confirmation card */
.mp-confirm-card {
  background: var(--bg-card);
  border: 2px solid var(--secondary);
  border-radius: var(--radius);
  padding: 16px;
  align-self: flex-start;
  max-width: 92%;
}
.mp-confirm-card p {
  margin: 0 0 14px;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text-primary);
}
.mp-confirm-actions {
  display: flex;
  gap: 10px;
}
.mp-confirm-actions button {
  flex: 1;
  min-height: 52px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, transform 0.1s;
}
.mp-confirm-actions button:active { transform: scale(0.97); }
.mp-confirm-yes {
  background: var(--secondary);
  color: #FFFFFF;
}
.mp-confirm-yes:hover { background: #4A7A28; }
.mp-confirm-no {
  background: var(--bg-page);
  color: var(--text-secondary);
  border: 1px solid var(--border) !important;
}
.mp-confirm-no:hover { background: var(--bg-card-hover); }

/* Input area */
#mp-chat-input-area {
  padding: 14px 16px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Microphone button */
#mp-chat-mic {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--secondary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
  color: #FFFFFF;
}
#mp-chat-mic:hover { background: #4A7A28; }
#mp-chat-mic svg { width: 24px; height: 24px; fill: currentColor; }
#mp-chat-mic.listening {
  background: #C62828;
  animation: mp-pulse 1.5s ease-in-out infinite;
}
@keyframes mp-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(198, 40, 40, 0.5); }
  70%  { box-shadow: 0 0 0 14px rgba(198, 40, 40, 0); }
  100% { box-shadow: 0 0 0 0 rgba(198, 40, 40, 0); }
}
#mp-chat-mic.hidden { display: none; }

/* Text input */
#mp-chat-input {
  flex: 1;
  min-height: 48px;
  padding: 12px 18px;
  border: 2px solid var(--border);
  border-radius: 28px;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  background: var(--bg-input);
  color: var(--text-primary);
  transition: border-color 0.15s, box-shadow 0.15s;
}
#mp-chat-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
  background: var(--bg-input-focus);
}
#mp-chat-input::placeholder { color: var(--text-muted); }

/* Send button */
#mp-chat-send {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
  color: #FFFFFF;
}
#mp-chat-send:hover { background: var(--accent-hover); }
#mp-chat-send:active { transform: scale(0.94); }
#mp-chat-send:disabled { background: var(--border); cursor: not-allowed; }
#mp-chat-send svg { width: 22px; height: 22px; fill: currentColor; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  #mp-chat-widget { bottom: 12px; right: 12px; }
  #mp-chat-btn { width: 64px; height: 64px; }
  #mp-chat-btn svg { width: 28px; height: 28px; }
  #mp-chat-panel {
    width: calc(100vw - 24px);
    height: calc(100vh - 120px);
    bottom: 76px;
    right: 0;
    max-height: 580px;
  }
}
@media (max-width: 480px) {
  #mp-chat-widget { bottom: 0; right: 0; left: 0; }
  #mp-chat-panel.open {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    bottom: 0;
    z-index: 9600;
  }
  #mp-chat-btn {
    position: fixed;
    bottom: 16px;
    right: 16px;
  }
}
