/* ==================== AI ASSISTANT FAB ==================== */

.ai-fab {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom, 0px) + 16px);
  left: 16px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  z-index: 50;
  box-shadow: 0 4px 14px rgba(102, 126, 234, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.ai-fab:active {
  transform: scale(0.92);
}

.ai-fab.hidden { display: none; }

/* ==================== AI CHAT OVERLAY ==================== */

.ai-chat-overlay {
  position: fixed;
  inset: 0;
  z-index: 99998;
  background: #fff;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.ai-chat-overlay.hidden {
  display: none;
}

/* Header */
.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #eee;
  background: #fff;
  flex-shrink: 0;
  padding-top: calc(14px + env(safe-area-inset-top));
}

.ai-chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
}

.ai-chat-title {
  font-weight: 800;
  font-size: 16px;
  color: #111;
}

.ai-chat-subtitle {
  font-size: 11px;
  color: #999;
  font-weight: 600;
}

.ai-chat-close {
  border: none;
  background: #f3f3f3;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
}

/* Messages area */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

/* Message bubbles */
.ai-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.ai-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-msg.assistant {
  align-self: flex-start;
  background: #f2f2f2;
  color: #111;
  border-bottom-left-radius: 4px;
}

/* Typing indicator */
.ai-typing {
  align-self: flex-start;
  padding: 10px 18px;
  background: #f2f2f2;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 5px;
}

.ai-typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #999;
  animation: aiTyping 1.4s infinite;
}

.ai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes aiTyping {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* Input area */
.ai-chat-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid #eee;
  background: #fff;
  flex-shrink: 0;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

.ai-chat-input {
  flex: 1;
  border: 1px solid #e5e5e5;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
  background: #fafafa;
  font-family: inherit;
  resize: none;
  max-height: 100px;
  min-height: 40px;
}

.ai-chat-input:focus {
  border-color: #667eea;
  background: #fff;
}

.ai-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

.ai-chat-send:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Image attach button (+) */
.ai-chat-image-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid #ccc;
  background: #fff;
  font-size: 20px;
  font-weight: 300;
  color: #666;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
  line-height: 1;
  padding: 0;
}

.ai-chat-image-btn:active {
  border-color: #667eea;
  color: #667eea;
}

/* Image preview above input */
.ai-image-preview {
  padding: 8px 14px 0;
  background: #fff;
  flex-shrink: 0;
}

.ai-image-preview.hidden { display: none; }

.ai-image-preview-inner {
  position: relative;
  display: inline-block;
}

.ai-image-preview-inner img {
  max-width: 120px;
  max-height: 90px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid #e5e5e5;
}

.ai-image-preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: #333;
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Image inside chat bubble */
.ai-msg-image {
  max-width: 100%;
  max-height: 200px;
  border-radius: 10px;
  object-fit: cover;
  display: block;
  margin-bottom: 6px;
}

.ai-msg.user .ai-msg-image {
  border-radius: 10px;
}

/* Contextual help button */
.ai-context-help {
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.ai-context-help:active {
  opacity: 1;
}
