/* ============================================================
   FuelMesh AI Chat Widget
   Dark industrial theme: #0a0f1c backgrounds, #f97316 amber, white text
   ============================================================ */

#fm-chat-root {
  --fm-bg:       #0a0f1c;
  --fm-bg-2:     #111827;
  --fm-bg-3:     #1a2438;
  --fm-border:   rgba(255,255,255,0.08);
  --fm-amber:    #f97316;
  --fm-amber-dim:rgba(249,115,22,0.12);
  --fm-amber-glow:rgba(249,115,22,0.25);
  --fm-text:     #f0f4ff;
  --fm-muted:   #8899aa;
  --fm-radius:   14px;
  --fm-shadow:   0 8px 32px rgba(0,0,0,0.6), 0 0 0 1px var(--fm-border);

  position: fixed;
  z-index: 2147483647;
  bottom: 24px;
  right: 24px;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 14px;
  color: var(--fm-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── FAB launcher ── */
.fm-fab {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--fm-amber);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px var(--fm-amber-glow), 0 0 0 0 rgba(249,115,22,0.4);
  transition: transform 0.25s cubic-bezier(.34,1.56,.64,1), box-shadow 0.25s ease;
  position: relative;
  overflow: hidden;
  margin-left: auto;
}
.fm-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px var(--fm-amber-glow), 0 0 0 6px rgba(249,115,22,0.15);
}
.fm-fab:active { transform: scale(0.97); }

.fm-fab svg { transition: opacity 0.2s; }
.fm-fab .fm-icon-close  { display: none; }
.fm-fab.open .fm-icon-chat { display: none; }
.fm-fab.open .fm-icon-close  { display: block; }

/* Pulse ring on unopened widget */
.fm-fab::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--fm-amber);
  opacity: 0;
  animation: fm-pulse 2s ease-out infinite;
}
.fm-fab:not(.open)::before { opacity: 1; }
@keyframes fm-pulse {
  0%   { transform: scale(1);   opacity: 0.8; }
  100% { transform: scale(1.5); opacity: 0;   }
}

/* ── Chat window ── */
.fm-window {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 380px;
  height: 540px;
  background: var(--fm-bg);
  border: 1px solid var(--fm-border);
  border-radius: var(--fm-radius);
  box-shadow: var(--fm-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(.34,1.2,.64,1), opacity 0.22s ease;
}
.fm-window.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
}

/* ── Header ── */
.fm-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: var(--fm-bg-2);
  border-bottom: 1px solid var(--fm-border);
  flex-shrink: 0;
}

.fm-header-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--fm-amber-dim);
  border: 1px solid rgba(249,115,22,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.fm-header-title {
  flex: 1;
  min-width: 0;
}
.fm-header-title strong {
  display: block;
  font-family: 'Syne', sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: var(--fm-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fm-header-title span {
  font-size: 12px;
  color: var(--fm-muted);
}

.fm-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(34,197,94,0.5);
}

.fm-header-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--fm-muted);
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: background 0.15s, color 0.15s;
}
.fm-header-close:hover { background: var(--fm-bg-3); color: var(--fm-text); }

/* ── Message list ── */
.fm-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.fm-messages::-webkit-scrollbar { width: 4px; }
.fm-messages::-webkit-scrollbar-track { background: transparent; }
.fm-messages::-webkit-scrollbar-thumb {
  background: var(--fm-border);
  border-radius: 4px;
}

.fm-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  gap: 12px;
}
.fm-empty-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--fm-amber-dim);
  border: 1px solid rgba(249,115,22,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.fm-empty-state h3 {
  font-family: 'Syne', sans-serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--fm-text);
}
.fm-empty-state p { font-size: 13px; color: var(--fm-muted); line-height: 1.6; max-width: 260px; }

.fm-msg-row { display: flex; gap: 8px; align-items: flex-end; }
.fm-msg-row.user { flex-direction: row-reverse; }
.fm-msg-row + .fm-msg-row { margin-top: 2px; }

.fm-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: 'Syne', sans-serif;
  font-size: 11px;
  font-weight: 700;
}
.fm-msg-row.assistant .fm-msg-avatar {
  background: var(--fm-amber-dim);
  border: 1px solid rgba(249,115,22,0.2);
  color: var(--fm-amber);
}
.fm-msg-row.user .fm-msg-avatar {
  background: var(--fm-bg-3);
  border: 1px solid var(--fm-border);
  color: var(--fm-muted);
}

.fm-msg-bubble {
  max-width: 72%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}
.fm-msg-row.assistant .fm-msg-bubble {
  background: var(--fm-bg-2);
  border: 1px solid var(--fm-border);
  border-bottom-left-radius: 4px;
  color: var(--fm-text);
}
.fm-msg-row.user .fm-msg-bubble {
  background: var(--fm-amber);
  border: none;
  border-bottom-right-radius: 4px;
  color: #0a0f1c;
  font-weight: 500;
}

.fm-msg-time {
  font-size: 10px;
  color: var(--fm-muted);
  margin-top: 4px;
  padding: 0 4px;
}
.fm-msg-row.user .fm-msg-time { text-align: right; }

/* ── Typing indicator ── */
.fm-typing {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 10px 14px;
  background: var(--fm-bg-2);
  border: 1px solid var(--fm-border);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}
.fm-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fm-muted);
  animation: fm-typing-bounce 1.2s ease-in-out infinite;
}
.fm-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.fm-typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes fm-typing-bounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
  30%            { transform: translateY(-5px);  opacity: 1;   }
}

/* ── Input area ── */
.fm-input-area {
  padding: 12px 14px;
  background: var(--fm-bg-2);
  border-top: 1px solid var(--fm-border);
  flex-shrink: 0;
}
.fm-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.fm-input {
  flex: 1;
  background: var(--fm-bg-3);
  border: 1px solid var(--fm-border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--fm-text);
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 14px;
  resize: none;
  max-height: 120px;
  min-height: 44px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.2s;
  field-sizing: content;
}
.fm-input::placeholder { color: var(--fm-muted); }
.fm-input:focus { border-color: rgba(249,115,22,0.4); }

.fm-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--fm-amber);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
  color: #0a0f1c;
}
.fm-send-btn:hover { background: #fb923c; transform: scale(1.05); }
.fm-send-btn:active { transform: scale(0.95); }
.fm-send-btn:disabled { background: var(--fm-bg-3); color: var(--fm-muted); cursor: not-allowed; transform: none; }

/* Powered by label */
.fm-powered {
  text-align: center;
  font-size: 11px;
  color: var(--fm-muted);
  padding: 8px 0 6px;
  opacity: 0.6;
}

/* ── Mobile responsive ── */
@media (max-width: 480px) {
  #fm-chat-root {
    bottom: 16px;
    right: 16px;
  }
  .fm-window {
    width: calc(100vw - 32px);
    height: calc(100vh - 120px);
    bottom: 70px;
  }
  .fm-fab { width: 52px; height: 52px; }
}