/* ===================================================
   Machine Expert Chatbot - Floating UI
   =================================================== */

:root {
  --mec-primary: #0057B8;
  --mec-primary-dark: #003d8a;
  --mec-accent: #FF6B00;
  --mec-bg: #0d1117;
  --mec-surface: #161b22;
  --mec-surface2: #21262d;
  --mec-border: rgba(255,255,255,0.08);
  --mec-text: #e6edf3;
  --mec-text-muted: #8b949e;
  --mec-radius: 16px;
  --mec-shadow: 0 24px 64px rgba(0,0,0,0.5);
  --mec-transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── FAB BUTTON ── */
#mec-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 62px;
  height: 62px;
  background: linear-gradient(135deg, var(--mec-primary), #0099ff);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 999998;
  box-shadow: 0 8px 32px rgba(0,87,184,0.45), 0 0 0 0 rgba(0,87,184,0.4);
  transition: var(--mec-transition);
  animation: mec-pulse 3s ease-in-out infinite;
}

#mec-fab:hover {
  transform: scale(1.12) rotate(-5deg);
  box-shadow: 0 12px 40px rgba(0,87,184,0.65);
}

#mec-fab svg { transition: transform 0.3s ease; }
#mec-fab.active svg { transform: rotate(45deg); }

@keyframes mec-pulse {
  0%, 100% { box-shadow: 0 8px 32px rgba(0,87,184,0.45), 0 0 0 0 rgba(0,153,255,0.4); }
  50%       { box-shadow: 0 8px 32px rgba(0,87,184,0.45), 0 0 0 14px rgba(0,153,255,0); }
}

/* Badge notification */
#mec-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  background: var(--mec-accent);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: mec-bounce 1s ease-in-out 2s 3;
}

@keyframes mec-bounce {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.3); }
}

/* ── CHAT WINDOW ── */
#mec-window {
  position: fixed;
  bottom: 104px;
  right: 28px;
  width: 390px;
  height: 580px;
  background: var(--mec-bg);
  border-radius: var(--mec-radius);
  border: 1px solid var(--mec-border);
  box-shadow: var(--mec-shadow);
  display: flex;
  flex-direction: column;
  z-index: 999997;
  overflow: hidden;
  transform: scale(0.85) translateY(30px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#mec-window.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ── HEADER ── */
#mec-header {
  background: linear-gradient(135deg, var(--mec-primary-dark) 0%, var(--mec-primary) 100%);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

#mec-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.mec-avatar {
  width: 42px;
  height: 42px;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 20px;
  border: 2px solid rgba(255,255,255,0.2);
}

#mec-header-info { flex: 1; }
#mec-header-info h3 {
  color: white;
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 2px;
  letter-spacing: -0.3px;
}
#mec-header-info p {
  color: rgba(255,255,255,0.75);
  font-size: 11.5px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.mec-status-dot {
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: 50%;
  animation: mec-blink 2s ease-in-out infinite;
}

@keyframes mec-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

#mec-close {
  background: rgba(255,255,255,0.1);
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.8);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}
#mec-close:hover { background: rgba(255,255,255,0.25); color: white; }

/* ── QUICK CATEGORIES ── */
#mec-categories {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  background: var(--mec-surface);
  border-bottom: 1px solid var(--mec-border);
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}
#mec-categories::-webkit-scrollbar { display: none; }

.mec-cat-btn {
  background: var(--mec-surface2);
  border: 1px solid var(--mec-border);
  color: var(--mec-text-muted);
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: inherit;
}
.mec-cat-btn:hover {
  background: var(--mec-primary);
  border-color: var(--mec-primary);
  color: white;
  transform: translateY(-1px);
}

/* ── MESSAGES AREA ── */
#mec-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--mec-surface2) transparent;
}
#mec-messages::-webkit-scrollbar { width: 4px; }
#mec-messages::-webkit-scrollbar-track { background: transparent; }
#mec-messages::-webkit-scrollbar-thumb { background: var(--mec-surface2); border-radius: 4px; }

/* Bot message */
.mec-msg-bot {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: mec-slide-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes mec-slide-in {
  from { opacity: 0; transform: translateY(15px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.mec-msg-bot .mec-bubble {
  background: var(--mec-surface);
  border: 1px solid var(--mec-border);
  color: var(--mec-text);
  padding: 12px 14px;
  border-radius: 4px 14px 14px 14px;
  max-width: 85%;
  font-size: 13.5px;
  line-height: 1.65;
  white-space: pre-line;
}

/* User message */
.mec-msg-user {
  display: flex;
  justify-content: flex-end;
  animation: mec-slide-in-right 0.25s ease;
}

@keyframes mec-slide-in-right {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

.mec-msg-user .mec-bubble {
  background: linear-gradient(135deg, var(--mec-primary), #0099ff);
  color: white;
  padding: 10px 14px;
  border-radius: 14px 4px 14px 14px;
  max-width: 80%;
  font-size: 13.5px;
  line-height: 1.55;
}

/* Typing indicator */
.mec-typing {
  display: flex;
  gap: 10px;
  align-items: center;
}
.mec-typing-dots {
  display: flex;
  gap: 4px;
  background: var(--mec-surface);
  border: 1px solid var(--mec-border);
  padding: 12px 16px;
  border-radius: 4px 14px 14px 14px;
}
.mec-typing-dots span {
  width: 7px;
  height: 7px;
  background: var(--mec-text-muted);
  border-radius: 50%;
  animation: mec-dot 1.4s ease-in-out infinite;
}
.mec-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.mec-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes mec-dot {
  0%, 80%, 100% { transform: scale(1); opacity: 0.4; }
  40%            { transform: scale(1.3); opacity: 1; }
}

/* Sources */
.mec-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--mec-border);
}
.mec-source-tag {
  background: rgba(0,87,184,0.2);
  border: 1px solid rgba(0,87,184,0.3);
  color: #58a6ff;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 20px;
}

/* Emoji formatting in messages */
.mec-bubble strong {
  color: white;
  font-weight: 700;
}
.mec-bubble em {
  color: #58a6ff;
  font-style: normal;
  font-weight: 600;
}

/* ── INPUT AREA ── */
#mec-input-area {
  padding: 12px 14px;
  background: var(--mec-surface);
  border-top: 1px solid var(--mec-border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}

#mec-input {
  flex: 1;
  background: var(--mec-surface2);
  border: 1px solid var(--mec-border);
  color: var(--mec-text);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  resize: none;
  outline: none;
  font-family: inherit;
  line-height: 1.5;
  max-height: 100px;
  transition: border-color 0.2s;
  min-height: 40px;
}
#mec-input:focus { border-color: var(--mec-primary); }
#mec-input::placeholder { color: var(--mec-text-muted); }

#mec-send {
  width: 40px;
  height: 40px;
  background: var(--mec-primary);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--mec-transition);
  color: white;
}
#mec-send:hover { background: #0099ff; transform: scale(1.08); }
#mec-send:disabled { background: var(--mec-surface2); cursor: not-allowed; transform: none; }

/* ── FOOTER ── */
#mec-footer {
  padding: 6px 14px 8px;
  background: var(--mec-surface);
  text-align: center;
  font-size: 10.5px;
  color: var(--mec-text-muted);
  border-top: 1px solid var(--mec-border);
  flex-shrink: 0;
}

/* ── WELCOME CARD ── */
.mec-welcome-card {
  background: linear-gradient(135deg, rgba(0,87,184,0.15), rgba(0,153,255,0.08));
  border: 1px solid rgba(0,87,184,0.25);
  border-radius: 14px;
  padding: 16px;
  text-align: center;
}
.mec-welcome-card h4 {
  color: white;
  font-size: 15px;
  font-weight: 700;
  margin: 8px 0 6px;
}
.mec-welcome-card p {
  color: var(--mec-text-muted);
  font-size: 12.5px;
  line-height: 1.6;
  margin: 0;
}
.mec-welcome-icon {
  font-size: 34px;
  display: block;
}

/* ── RESPONSIVE ── */
@media (max-width: 480px) {
  #mec-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 85vh;
    border-radius: 20px 20px 0 0;
  }
  #mec-fab {
    bottom: 20px;
    right: 20px;
  }
}

/* Position variants */
.mec-pos-bottom-left  #mec-fab { right: auto; left: 28px; }
.mec-pos-bottom-left  #mec-window { right: auto; left: 28px; }
