/* ─── EFK AI Chatbot Widget ─────────────────────────────────────────────────── */

/* Floating button */
#efk-chat-btn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9998;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FF6B00 0%, #ff8c00 100%);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(255, 107, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  outline: none;
}

#efk-chat-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(255, 107, 0, 0.55);
}

#efk-chat-btn:active { transform: scale(0.96); }

#efk-chat-btn svg { width: 30px; height: 30px; fill: #fff; }

/* Unread badge */
#efk-chat-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: #e53e3e;
  border-radius: 50%;
  border: 2px solid #fff;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  display: none;
}

/* Chat panel */
#efk-chat-panel {
  position: fixed;
  bottom: 104px;
  right: 28px;
  z-index: 9999;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.22s ease;
}

#efk-chat-panel.efk-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
}

/* Header */
#efk-chat-header {
  background: linear-gradient(135deg, #FF6B00 0%, #e85d00 100%);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

#efk-chat-header-avatar {
  width: 38px;
  height: 38px;
  background: rgba(255,255,255,0.25);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#efk-chat-header-avatar svg { width: 22px; height: 22px; fill: #fff; }

#efk-chat-header-info { flex: 1; min-width: 0; }

#efk-chat-header-name {
  font-family: 'Poppins', 'Cairo', sans-serif;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  line-height: 1.2;
}

#efk-chat-header-status {
  font-family: 'Poppins', 'Cairo', sans-serif;
  font-size: 11px;
  color: rgba(255,255,255,0.85);
  display: flex;
  align-items: center;
  gap: 4px;
}

#efk-chat-header-status::before {
  content: '';
  width: 7px;
  height: 7px;
  background: #68d391;
  border-radius: 50%;
  display: inline-block;
}

.efk-chat-icon-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
  outline: none;
}

.efk-chat-icon-btn:hover { background: rgba(255,255,255,0.35); }

.efk-chat-icon-btn svg { width: 17px; height: 17px; fill: #fff; }

.efk-chat-icon-btn.efk-active { background: rgba(255,255,255,0.4); }

/* Messages area */
#efk-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f7f8fc;
  scroll-behavior: smooth;
}

#efk-chat-messages::-webkit-scrollbar { width: 4px; }
#efk-chat-messages::-webkit-scrollbar-track { background: transparent; }
#efk-chat-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

/* Welcome message */
.efk-welcome {
  text-align: center;
  padding: 8px 0 4px;
}

.efk-welcome-logo {
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, #FF6B00, #ff8c00);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 10px;
}

.efk-welcome-logo svg { width: 28px; height: 28px; fill: #fff; }

.efk-welcome p {
  font-family: 'Poppins', 'Cairo', sans-serif;
  font-size: 13px;
  color: #666;
  line-height: 1.5;
  margin: 0;
}

/* Message bubbles */
.efk-msg {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: efkMsgIn 0.22s ease;
}

@keyframes efkMsgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.efk-msg.efk-user { align-self: flex-end; flex-direction: row-reverse; }
.efk-msg.efk-bot  { align-self: flex-start; }

.efk-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FF6B00, #ff8c00);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.efk-msg-avatar svg { width: 16px; height: 16px; fill: #fff; }

.efk-msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-family: 'Poppins', 'Cairo', sans-serif;
  font-size: 13.5px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  min-width: 0;
}

/* Bot bubbles render markdown — disable pre-wrap so HTML flows */
.efk-msg-bubble.efk-md {
  white-space: normal;
}

/* RTL bubble — Arabic replies with embedded English keywords */
.efk-msg-bubble[dir="rtl"] {
  direction: rtl;
  text-align: right;
  unicode-bidi: embed;
}

.efk-msg-bubble.efk-md ul,
.efk-msg-bubble.efk-md ol {
  margin: 6px 0 4px 18px;
  padding: 0;
}

.efk-msg-bubble.efk-md li {
  margin-bottom: 3px;
  line-height: 1.5;
}

.efk-msg.efk-bot .efk-msg-bubble {
  background: #fff;
  color: #2d3748;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

.efk-msg.efk-user .efk-msg-bubble {
  background: linear-gradient(135deg, #FF6B00, #ff8c00);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Typing indicator */
#efk-typing {
  display: none;
  align-self: flex-start;
  align-items: center;
  gap: 8px;
}

#efk-typing.efk-show { display: flex; }

.efk-typing-dots {
  background: #fff;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  display: flex;
  gap: 5px;
  align-items: center;
}

.efk-typing-dots span {
  width: 7px;
  height: 7px;
  background: #FF6B00;
  border-radius: 50%;
  animation: efkDot 1.2s infinite;
}

.efk-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.efk-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes efkDot {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40%           { transform: scale(1);   opacity: 1;   }
}

/* Error message */
.efk-msg-error .efk-msg-bubble {
  background: #fff5f5;
  color: #c53030;
  border: 1px solid #fed7d7;
}

/* Input area */
#efk-chat-footer {
  padding: 12px 14px;
  border-top: 1px solid #eee;
  background: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#efk-chat-input {
  flex: 1;
  border: 1.5px solid #e2e8f0;
  border-radius: 24px;
  padding: 10px 16px;
  font-family: 'Poppins', 'Cairo', sans-serif;
  font-size: 13.5px;
  outline: none;
  resize: none;
  line-height: 1.4;
  max-height: 100px;
  overflow-y: auto;
  transition: border-color 0.2s;
  background: #f7f8fc;
  color: #2d3748;
}

#efk-chat-input:focus {
  border-color: #FF6B00;
  background: #fff;
}

#efk-chat-input::placeholder { color: #a0aec0; }

/* RTL support */
[dir="rtl"] #efk-chat-input { direction: rtl; text-align: right; }

.efk-footer-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  outline: none;
}

#efk-mic-btn {
  background: #f0f0f0;
  color: #555;
}

#efk-mic-btn svg { width: 17px; height: 17px; fill: #555; }

#efk-mic-btn:hover { background: #e0e0e0; }

#efk-mic-btn.efk-recording {
  background: #e53e3e;
  animation: efkPulse 1s infinite;
}

#efk-mic-btn.efk-recording svg { fill: #fff; }

/* Mic language toggle */
#efk-mic-lang-btn {
  background: #f0f0f0;
  color: #555;
  font-family: 'Poppins', 'Cairo', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

#efk-mic-lang-btn:hover { background: #e0e0e0; }

#efk-mic-lang-btn.efk-mic-lang-ar {
  background: #fff3e8;
  color: #cc5500;
  border: 1.5px solid #FFB370;
  font-size: 14px;
}

@keyframes efkPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 62, 62, 0.4); }
  50%       { box-shadow: 0 0 0 8px rgba(229, 62, 62, 0); }
}

#efk-send-btn {
  background: linear-gradient(135deg, #FF6B00, #ff8c00);
  color: #fff;
}

#efk-send-btn svg { width: 17px; height: 17px; fill: #fff; }

#efk-send-btn:hover { background: linear-gradient(135deg, #e55e00, #e57a00); box-shadow: 0 2px 10px rgba(255,107,0,0.4); }
#efk-send-btn:active { transform: scale(0.94); }
#efk-send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* Mic not available hint */
#efk-mic-btn[title]:hover::after {
  content: attr(title);
  position: absolute;
  bottom: 52px;
  right: 14px;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
}

/* Quick reply chips */
#efk-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 14px 0;
  background: #fff;
}

.efk-chip {
  background: #fff3e8;
  border: 1.5px solid #FFB370;
  border-radius: 20px;
  padding: 5px 12px;
  font-family: 'Poppins', 'Cairo', sans-serif;
  font-size: 12px;
  color: #cc5500;
  cursor: pointer;
  transition: all 0.18s;
  outline: none;
  white-space: nowrap;
}

.efk-chip:hover {
  background: #FF6B00;
  border-color: #FF6B00;
  color: #fff;
}

/* Mobile responsive */
@media (max-width: 600px) {
  #efk-chat-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 92dvh;
    max-height: 92dvh;
    border-radius: 20px 20px 0 0;
    overflow-x: hidden;
  }

  #efk-chat-btn {
    bottom: 16px;
    right: 16px;
    width: 56px;
    height: 56px;
  }

  .efk-msg { max-width: 82%; }

  #efk-chat-messages { padding: 12px; }

  #efk-chat-footer { padding: 10px 12px; }

  #efk-chat-input { font-size: 16px; /* prevents iOS zoom */ }
}

/* RTL layout adjustments */
[dir="rtl"] #efk-chat-panel {
  right: 28px;
  left: auto;
}

[dir="rtl"] #efk-chat-btn {
  right: 28px;
  left: auto;
}

@media (max-width: 600px) {
  [dir="rtl"] #efk-chat-panel {
    right: 0;
    left: 0;
  }
}

[dir="rtl"] .efk-msg.efk-user { flex-direction: row; }
[dir="rtl"] .efk-msg.efk-bot  { flex-direction: row-reverse; }

[dir="rtl"] .efk-msg.efk-bot .efk-msg-bubble {
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 4px;
}

[dir="rtl"] .efk-msg.efk-user .efk-msg-bubble {
  border-bottom-right-radius: 16px;
  border-bottom-left-radius: 4px;
}
