/* =========================================================
   PLANTCAM CHAT — GLOBAL UI STYLES
   Covers:
   • Floating FAB
   • Floating Panel
   • Dedicated Page (31000)
   • Modal Chat (31010 UI only)
   ========================================================= */


/* =========================================================
   FLOATING CHAT BUTTON (FAB)
   ========================================================= */

#pc-chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  z-index: 9999;
  box-shadow: 0 6px 16px rgba(0,0,0,.25);
}

.pc-fab-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
}


/* =========================================================
   FLOATING CHAT PANEL
   ========================================================= */

#pc-chat-panel {
  position: fixed;
  right: 18px;
  bottom: 86px;
  width: 360px;
  max-width: calc(100vw - 36px);
  height: 520px;
  max-height: calc(100vh - 140px);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,.22);
  background: #fff;
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 99999;
  border: 1px solid #e5e7eb;
}

#pc-chat-header {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #111827;
  color: #fff;
}

#pc-chat-messages {
  padding: 12px;
  overflow: auto;
  flex: 1;
  background: #f9fafb;
}


/* =========================================================
   DEDICATED CHAT PAGE (31000)
   ========================================================= */

#plantcam-chat-page {
  width: 95%;
  max-width: 900px;
  margin: 16px auto;
  height: calc(100vh - 200px);
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0,0,0,.15);
  overflow: hidden;
}

.pc-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px;
  background: linear-gradient(135deg,#020617,#0f172a);
  color: #fff;
}

.pc-avatar-large {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid #38bdf8;
}


/* =========================================================
   MESSAGE THREAD — SHARED
   ========================================================= */

.pc-messages,
.pcm-messages,
#pcm-messages {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 16px;
  background: #f8fafc;
}


/* =========================================================
   MESSAGE ROW LAYOUT
   ========================================================= */

.pcm-msg {
  display: flex;
  width: 100%;
  margin: 10px 0;
  gap: 8px;
  align-items: flex-start;   /* FIX: align from top */
}

.pcm-msg.assistant {
  justify-content: flex-start;
}

.pcm-msg.user {
  justify-content: flex-end;
}

/* =========================================================
   AVATAR
   ========================================================= */

.pcm-avatar {
  width: 32px;          /* slightly bigger */
  height: 32px;
  min-width: 32px;     /* prevents flex shrink */
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  flex-shrink: 0;      /* prevents distortion */
}


/* =========================================================
   MESSAGE BUBBLES
   ========================================================= */

.pcm-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  max-width: 65%;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.pcm-msg.assistant .pcm-bubble {
  background: #fff;
  border: 1px solid #e5e7eb;
}

.pcm-msg.user .pcm-bubble {
  background: #d1f5d3;
  border: 1px solid #b7e4ba;
}


/* =========================================================
   INPUT BAR
   ========================================================= */

.pc-input,
.pcm-input {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  position: sticky;
  bottom: 0;
  z-index: 3;
}

/* Ensure input never floats mid-screen */
.pcm-input {
  flex: 0 0 auto;
}

/* Messages must stretch above input */
#pcm-messages,
#pc-messages,
#pcm_messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

/* Modal chat root must be column flex */
#plantcam-chat-page,
#pc-modal-chat,
#plantcam-chat-modal {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}


#pcm-input {
  flex: 1;
  padding: 10px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  outline: none;
}

#pcm-send {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid #2563eb;
  background: #2563eb;
  color: #fff;
  cursor: pointer;
}

/* ==========================
   ADMIN BANNER
========================== */

.pc-admin-banner {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  font-size: 12px;
  background: #f5f7f5;
  border-top: 1px solid #e2e6e2;
  color: #3d4b3d;
}

.pc-admin-banner.inactive {
  background: #ffe8e8;
  color: #b3261e;
}



/* =========================================================
   FOOTER
   ========================================================= */

.pc-footer {
  text-align: center;
  font-size: .75rem;
  color: #666;
  padding: 8px;
  background: #f8fafc;
}


/* =========================================================
   TYPING INDICATOR
   ========================================================= */

.pcm-msg.typing .pcm-bubble {
  display: flex;
  gap: 6px;
  align-items: center;
  background: #f1f3f5;
}

.pcm-dot {
  width: 8px;
  height: 8px;
  background: #9aa0a6;
  border-radius: 50%;
  animation: pcm-bounce 1.4s infinite ease-in-out;
}

.pcm-dot:nth-child(2) { animation-delay: .2s; }
.pcm-dot:nth-child(3) { animation-delay: .4s; }

@keyframes pcm-bounce {
  0%,80%,100% { transform: scale(0); opacity:.3; }
  40% { transform: scale(1); opacity:1; }
}


/* =========================================================
   MOBILE — DEDICATED PAGE
   ========================================================= */

@media (max-width:768px) {
  #plantcam-chat-page {
    width:100%;
    max-width:100%;
    margin:0;
    height:calc(100vh - 120px);
    border-radius:0;
  }
}

/* ===== Plant Typing Animation ===== */

.pcm-plant-typing {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 18px;
}

.pcm-plant-typing span {
  display: inline-block;
  animation: pcmPlantBounce 1.4s infinite ease-in-out;
}

/* Stagger animation */
.pcm-plant-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.pcm-plant-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

/* Bounce animation */
@keyframes pcmPlantBounce {

  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.6;
  }

  40% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* =========================================================
   Wider assistant replies for paragraph text
  
   ========================================================= */

/* Desktop / tablet */
.pcm-msg.assistant .pcm-bubble {
  max-width: 88%;
}

/* Keep user a bit narrower */
.pcm-msg.user .pcm-bubble {
  max-width: 72%;
}

/* Mobile: use almost full width for assistant paragraphs */
@media (max-width: 768px) {
  .pcm-msg.assistant .pcm-bubble {
    max-width: 94%;
  }
  .pcm-msg.user .pcm-bubble {
    max-width: 80%;
  }
}

/* TEMP: Disable floating bot */
#pc-chat-fab,
#pc-chat-panel {
  display: none !important;
}

/* =========================================================
   MESSAGE COUNTER (above chat input)
   ========================================================= */

.pc-message-counter {
  flex: 0 0 auto;
  padding: 6px 12px;
  font-size: 12px;
  text-align: center;
  color: #6b7280;
  background: #f9fafb;
  border-top: 1px solid #e5e7eb;
}

/* Default */
.pc-message-counter {
  flex: 0 0 auto;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  text-align: center;

  background: #eef6ff;
  color: #1e40af;

  border-top: 1px solid #dbeafe;
}
/* Plenty messages (Plant healthy) */
.pc-message-counter.healthy {
  background: #ecfdf5;
  color: #166534;
}

/* Normal usage */
.pc-message-counter.normal {
  background: #eef6ff;
  color: #1e40af;
}

/* Warning */
.pc-message-counter.warning {
  background: #fff7ed;
  color: #b45309;
}

/* Danger */
.pc-message-counter.danger {
  background: #fee2e2;
  color: #b91c1c;
}

/* =========================================================
   UPGRADE LINK (when chat limit reached)
   ========================================================= */

.pc-upgrade-link {
  display: inline-block;
  margin-left: 8px;
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
  background: #16a34a;   /* Plant green */
  color: #fff;
  text-decoration: none;
  font-weight: 500;
}

.pc-upgrade-link:hover {
  background: #15803d;
}