/* ── Chat Widget FAB ── */
.chat-fab {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-green), var(--accent-purple));
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 900;
  box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  border: none;
  outline: none;
}
.chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(16, 185, 129, 0.5);
}
.chat-fab.active {
  transform: scale(0.9);
}
.chat-fab svg {
  transition: transform 0.3s ease, opacity 0.3s ease;
}
.chat-fab.active .fab-icon-chat { opacity: 0; transform: scale(0.5); position: absolute; }
.chat-fab.active .fab-icon-close { opacity: 1; transform: scale(1); }
.chat-fab .fab-icon-close { opacity: 0; transform: scale(0.5); position: absolute; }
.chat-fab .fab-icon-chat { opacity: 1; transform: scale(1); }

/* ── Chat Widget Panel ── */
.chat-widget {
  position: fixed;
  bottom: 160px;
  right: 24px;
  width: 380px;
  height: 500px;
  max-height: calc(100vh - 200px);
  background: rgba(10, 18, 12, 0.97);
  backdrop-filter: blur(24px);
  border: 1px solid rgba(16, 185, 129, 0.15);
  border-radius: 20px;
  z-index: 899;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(16, 185, 129, 0.08);
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.chat-widget.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Header */
.cw-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(16, 185, 129, 0.1);
  flex-shrink: 0;
}
.cw-ai-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent-green), var(--accent-purple));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.cw-ai-name {
  font-size: 0.88rem;
  font-weight: 700;
}
.cw-ai-status {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.68rem;
  color: var(--accent-green);
  font-weight: 500;
}
.cw-ai-status .dot {
  width: 5px;
  height: 5px;
  background: var(--accent-green);
  border-radius: 50%;
  animation: pulse 2s infinite;
}
.cw-expand {
  margin-left: auto;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background 0.2s;
  cursor: pointer;
  background: none;
  border: none;
}
.cw-expand:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
}

/* Messages */
.cw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(16, 185, 129, 0.15) transparent;
}
.cw-messages::-webkit-scrollbar { width: 4px; }
.cw-messages::-webkit-scrollbar-thumb { background: rgba(16, 185, 129, 0.15); border-radius: 4px; }

.cw-bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.82rem;
  line-height: 1.55;
  animation: fadeInUp 0.3s ease;
}
.cw-bubble.ai {
  align-self: flex-start;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(16, 185, 129, 0.08);
  border-bottom-left-radius: 4px;
}
.cw-bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent-green), var(--accent-purple));
  border-bottom-right-radius: 4px;
}
.cw-bubble .time {
  font-size: 0.6rem;
  color: rgba(255,255,255,0.4);
  margin-top: 4px;
  text-align: right;
}

/* Quick Actions */
.cw-quick {
  display: flex;
  gap: 6px;
  padding: 6px 14px;
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}
.cw-quick::-webkit-scrollbar { display: none; }
.cw-quick-btn {
  padding: 4px 10px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.15);
  border-radius: 16px;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: all 0.2s;
  cursor: pointer;
}
.cw-quick-btn:hover {
  background: rgba(16, 185, 129, 0.16);
  color: var(--text-primary);
}

/* Input */
.cw-input-area {
  padding: 10px 14px;
  border-top: 1px solid rgba(16, 185, 129, 0.08);
  flex-shrink: 0;
}
.cw-input-row {
  display: flex;
  gap: 8px;
}
.cw-input {
  flex: 1;
  padding: 10px 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(16, 185, 129, 0.15);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 0.82rem;
  font-family: 'Inter', sans-serif;
  outline: none;
  transition: border-color 0.2s;
}
.cw-input:focus {
  border-color: var(--accent-green);
}
.cw-input::placeholder {
  color: var(--text-muted);
}
.cw-send {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--accent-green), var(--accent-purple));
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  border: none;
  transition: transform 0.2s, box-shadow 0.2s;
}
.cw-send:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

/* Action / Summary Cards inside widget */
.cw-bubble .chat-action-card {
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: 10px;
  padding: 10px;
  margin-top: 8px;
  font-size: 0.78rem;
}
.cw-bubble .chat-action-card.expense {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.25);
}
.cw-bubble .chat-action-title {
  font-weight: 700;
  font-size: 0.78rem;
  margin-bottom: 6px;
}
.cw-bubble .chat-action-detail {
  font-size: 0.74rem;
  color: var(--text-secondary);
  margin-bottom: 2px;
}
.cw-bubble .chat-action-buttons {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.cw-bubble .chat-action-btn {
  flex: 1;
  padding: 6px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.74rem;
  text-align: center;
  cursor: pointer;
  border: none;
  transition: opacity 0.2s;
}
.cw-bubble .chat-action-btn:hover { opacity: 0.85; }
.cw-bubble .chat-action-btn.confirm { background: var(--accent-green); color: #fff; }
.cw-bubble .chat-action-btn.cancel { background: var(--accent-red); color: #fff; }

.cw-bubble .chat-summary-card {
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: 10px;
  padding: 10px;
  margin-top: 8px;
}
.cw-bubble .chat-summary-title {
  font-weight: 700;
  font-size: 0.78rem;
  margin-bottom: 6px;
  color: var(--accent-emerald);
}
.cw-bubble .chat-summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  padding: 2px 0;
  color: var(--text-secondary);
}
.cw-bubble .chat-summary-row .val {
  font-weight: 600;
  color: var(--text-primary);
}

/* Typing */
.cw-typing {
  display: flex;
  gap: 4px;
  padding: 6px 10px;
}
.cw-typing span {
  width: 5px;
  height: 5px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite;
}
.cw-typing span:nth-child(2) { animation-delay: 0.2s; }
.cw-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* Responsive */
@media (max-width: 480px) {
  .chat-widget {
    width: calc(100vw - 24px);
    right: 12px;
    bottom: 140px;
    height: 420px;
    max-height: calc(100vh - 180px);
    border-radius: 16px;
  }
  .chat-fab {
    right: 16px;
    bottom: 80px;
    width: 50px;
    height: 50px;
  }
}
