/* ==========================================
   Greene – GreenPlanVision AI Assistant
   Chat Widget Styles
   ========================================== */

/* Chat Bubble (FAB) */
.greene-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9998;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, #16A34A, #22C55E);
  color: #fff;
  box-shadow: 0 4px 20px rgba(22, 163, 74, 0.4), 0 0 0 0 rgba(22, 163, 74, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  animation: greene-pulse 3s ease-in-out infinite;
}

.greene-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(22, 163, 74, 0.5);
}

.greene-fab.active {
  animation: none;
  transform: scale(1);
}

.greene-fab svg {
  width: 26px;
  height: 26px;
  transition: transform 0.3s ease;
}

.greene-fab.active .greene-fab-chat { display: none; }
.greene-fab:not(.active) .greene-fab-close { display: none; }

@keyframes greene-pulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(22, 163, 74, 0.4), 0 0 0 0 rgba(22, 163, 74, 0.3); }
  50% { box-shadow: 0 4px 20px rgba(22, 163, 74, 0.4), 0 0 0 12px rgba(22, 163, 74, 0); }
}

/* Notification Badge */
.greene-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 14px;
  height: 14px;
  background: #EF4444;
  border-radius: 50%;
  border: 2px solid #fff;
  display: none;
}

.greene-badge.visible { display: block; }
.dark .greene-badge { border-color: var(--bg-main); }

/* Chat Window */
.greene-window {
  position: fixed;
  bottom: 5.5rem;
  right: 1.5rem;
  z-index: 9997;
  width: 380px;
  max-width: calc(100vw - 2rem);
  height: 520px;
  max-height: calc(100vh - 8rem);
  border-radius: 20px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg-main, #FFFAF5);
  border: 1px solid var(--glass-border, rgba(251,146,60,0.2));
  box-shadow: 0 12px 48px rgba(0,0,0,0.15), 0 0 0 1px rgba(0,0,0,0.04);
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.greene-window.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.dark .greene-window {
  background: var(--bg-main, #0F172A);
  box-shadow: 0 12px 48px rgba(0,0,0,0.4), 0 0 0 1px rgba(96,165,250,0.1);
}

/* Chat Header */
.greene-header {
  background: linear-gradient(135deg, #16A34A, #22C55E);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.greene-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.greene-avatar svg {
  width: 22px;
  height: 22px;
  color: #fff;
}

.greene-header-info {
  flex: 1;
}

.greene-header-name {
  font-family: 'Ubuntu Sans', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.greene-header-status {
  font-family: 'Ubuntu Sans', sans-serif;
  font-size: 0.7rem;
  color: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  gap: 4px;
}

.greene-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #BBF7D0;
  animation: greene-status-pulse 2s ease-in-out infinite;
}

@keyframes greene-status-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.greene-header-close {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.greene-header-close:hover {
  background: rgba(255,255,255,0.25);
}

/* Chat Messages */
.greene-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

.greene-messages::-webkit-scrollbar {
  width: 4px;
}

.greene-messages::-webkit-scrollbar-track {
  background: transparent;
}

.greene-messages::-webkit-scrollbar-thumb {
  background: var(--glass-border, rgba(251,146,60,0.2));
  border-radius: 4px;
}

/* Message Bubble */
.greene-msg {
  max-width: 85%;
  display: flex;
  gap: 0.5rem;
  animation: greene-msg-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes greene-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.greene-msg-bot {
  align-self: flex-start;
}

.greene-msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.greene-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #16A34A, #22C55E);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.greene-msg-avatar svg {
  width: 14px;
  height: 14px;
  color: #fff;
}

.greene-msg-user .greene-msg-avatar {
  background: var(--primary, #EA580C);
}

.greene-msg-bubble {
  padding: 0.65rem 0.9rem;
  border-radius: 14px;
  font-family: 'Ubuntu Sans', sans-serif;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-body, #7C2D12);
}

.greene-msg-bot .greene-msg-bubble {
  background: var(--bg-alt, #FFF3E8);
  border-bottom-left-radius: 4px;
}

.dark .greene-msg-bot .greene-msg-bubble {
  background: var(--bg-alt, #1E293B);
  color: #E2E8F0;
}

.dark .greene-msg-bubble {
  color: #E2E8F0;
}

.dark .greene-msg-bubble a {
  color: #60A5FA;
}

.dark .greene-msg-bubble strong {
  color: #F1F5F9;
}

.greene-msg-user .greene-msg-bubble {
  background: linear-gradient(135deg, #16A34A, #22C55E);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.greene-msg-bubble p { margin: 0 0 0.4rem; }
.greene-msg-bubble p:last-child { margin-bottom: 0; }
.greene-msg-bubble strong { font-weight: 700; }
.greene-msg-bubble a { color: var(--primary, #EA580C); text-decoration: underline; }
.greene-msg-user .greene-msg-bubble a { color: #BBF7D0; }

/* Quick Replies */
.greene-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.greene-quick-btn {
  font-family: 'Ubuntu Sans', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid rgba(22, 163, 74, 0.3);
  background: rgba(22, 163, 74, 0.08);
  color: #16A34A;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.greene-quick-btn:hover {
  background: #16A34A;
  color: #fff;
  border-color: #16A34A;
}

.dark .greene-quick-btn {
  border-color: rgba(34, 197, 94, 0.3);
  background: rgba(34, 197, 94, 0.1);
  color: #4ADE80;
}

.dark .greene-quick-btn:hover {
  background: #22C55E;
  color: #0F172A;
}

/* Typing Indicator */
.greene-typing {
  display: flex;
  gap: 4px;
  padding: 0.65rem 0.9rem;
  align-items: center;
}

.greene-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted, #C2410C);
  opacity: 0.4;
  animation: greene-typing 1.2s ease-in-out infinite;
}

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

@keyframes greene-typing {
  0%, 60%, 100% { opacity: 0.4; transform: scale(1); }
  30% { opacity: 1; transform: scale(1.2); }
}

/* Input Area */
.greene-input-area {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--glass-border, rgba(251,146,60,0.15));
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-shrink: 0;
  background: var(--bg-main, #FFFAF5);
}

.dark .greene-input-area {
  background: var(--bg-main, #0F172A);
}

.greene-input {
  flex: 1;
  border: 1px solid var(--glass-border, rgba(251,146,60,0.2));
  border-radius: 12px;
  padding: 0.55rem 0.85rem;
  font-family: 'Ubuntu Sans', sans-serif;
  font-size: 0.85rem;
  color: var(--text-dark, #431407);
  background: var(--bg-alt, #FFF3E8);
  resize: none;
  outline: none;
  min-height: 38px;
  max-height: 100px;
  line-height: 1.4;
  transition: border-color 0.2s ease;
}

.greene-input:focus {
  border-color: #16A34A;
}

.dark .greene-input {
  background: var(--bg-alt, #1E293B);
  color: var(--text-dark, #F1F5F9);
}

.greene-input::placeholder {
  color: var(--text-muted, #C2410C);
  opacity: 0.6;
}

.greene-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #16A34A, #22C55E);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.greene-send:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.4);
}

.greene-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.greene-send svg {
  width: 18px;
  height: 18px;
}

/* Powered by */
.greene-powered {
  text-align: center;
  padding: 0.3rem;
  font-family: 'Ubuntu Sans', sans-serif;
  font-size: 0.6rem;
  color: var(--text-muted, #C2410C);
  opacity: 0.5;
}

/* Mobile */
@media (max-width: 480px) {
  .greene-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }

  .greene-fab {
    bottom: 1rem;
    right: 1rem;
    width: 50px;
    height: 50px;
  }
}

/* Cookie banner visible: push FAB up */
.cookie-banner-show ~ .greene-fab {
  bottom: 8rem;
}

@media (max-width: 600px) {
  .cookie-banner-show ~ .greene-fab {
    bottom: 12rem;
  }
}
