/**
 * MOTHI Chat V2 — Widget CSS v3
 * Design: clean speech-bubble style (rounded pill bubbles with tail pointer)
 * Colours: MOTHI green #006400 + gold #FFD700, white chat area
 */

/* =====================================================================
   TOKENS
===================================================================== */
#mothiv2-chat-root {
  --mothi-primary:       #006400;
  --mothi-primary-light: #1a7a1a;
  --mothi-primary-dark:  #004d00;
  --mothi-secondary:     #FFD700;
  --mothi-radius:        20px;
  --mothi-font:          'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;

  /* Panel */
  --mothi-panel-bg:      #ffffff;
  --mothi-panel-fg:      #1a1a1a;
  --mothi-panel-shadow:  0 24px 64px rgba(0,0,0,0.18), 0 4px 16px rgba(0,0,0,0.10);

  /* Bot bubble — soft light green tint */
  --mothi-bot-bg:        #e8f5e8;
  --mothi-bot-fg:        #1a3a1a;

  /* User bubble — solid deep green */
  --mothi-user-bg:       #006400;
  --mothi-user-fg:       #ffffff;

  /* Input */
  --mothi-input-bg:      #f4f4f4;
  --mothi-border:        #e8e8e8;
  --mothi-z:             99999;

  font-family: var(--mothi-font);
}

/* Dark mode */
#mothiv2-chat-root.mothi-dark {
  --mothi-panel-bg:  #1a1f1a;
  --mothi-panel-fg:  #eef2ee;
  --mothi-bot-bg:    #1e2e1e;
  --mothi-bot-fg:    #c8e6c8;
  --mothi-input-bg:  #252d25;
  --mothi-border:    #3a4a3a;
}

/* =====================================================================
   POSITIONING
===================================================================== */
#mothiv2-chat-root {
  position: fixed;
  z-index: var(--mothi-z);
  bottom: 28px;
  right: 28px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  pointer-events: none;
}

#mothiv2-chat-root.mothi-position-bottom-left {
  right: auto;
  left: 28px;
  align-items: flex-start;
}

/* =====================================================================
   FAB TOGGLE BUTTON
===================================================================== */
#mothiv2-chat-toggle {
  pointer-events: all;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--mothi-primary-light), var(--mothi-primary-dark));
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 24px rgba(0,100,0,0.45), 0 2px 8px rgba(0,0,0,0.2);
  transition: transform 0.25s cubic-bezier(.34,1.56,.64,1), box-shadow 0.2s;
  position: relative;
  flex-shrink: 0;
}

#mothiv2-chat-toggle:hover {
  transform: scale(1.1) translateY(-2px);
  box-shadow: 0 10px 32px rgba(0,100,0,0.5);
}

#mothiv2-chat-toggle:focus-visible {
  outline: 3px solid var(--mothi-secondary);
  outline-offset: 3px;
}

#mothiv2-chat-toggle:active { transform: scale(0.95); }

/* Pulse ring */
#mothiv2-chat-toggle::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0,100,0,0.3);
  animation: mothiPulse 2.5s ease-out infinite;
}
#mothiv2-chat-root.mothi-open #mothiv2-chat-toggle::after { animation: none; }

@keyframes mothiPulse {
  0%   { transform: scale(1);   opacity: 0.6; }
  70%  { transform: scale(1.5); opacity: 0;   }
  100% { transform: scale(1.5); opacity: 0;   }
}

.mothi-badge-dot {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 13px;
  height: 13px;
  background: var(--mothi-secondary);
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

/* =====================================================================
   CHAT PANEL
===================================================================== */
#mothiv2-chat-panel {
  pointer-events: all;
  width: 400px;
  max-width: calc(100vw - 56px);
  height: 620px;
  max-height: calc(100vh - 120px);
  border-radius: 28px;
  background: var(--mothi-panel-bg);
  color: var(--mothi-panel-fg);
  box-shadow: var(--mothi-panel-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-bottom: 14px;
  transform-origin: bottom right;
  animation: mothiPanelIn 0.3s cubic-bezier(.34,1.4,.64,1);
}

#mothiv2-chat-root.mothi-position-bottom-left #mothiv2-chat-panel {
  transform-origin: bottom left;
}

@keyframes mothiPanelIn {
  from { opacity: 0; transform: scale(0.88) translateY(20px); }
  to   { opacity: 1; transform: scale(1)    translateY(0);    }
}

#mothiv2-chat-panel[hidden] { display: none; }

/* =====================================================================
   HEADER  — gradient top, large rounded corners, no hard edges
===================================================================== */
.mothi-header {
  background: linear-gradient(160deg, var(--mothi-primary-light) 0%, var(--mothi-primary-dark) 100%);
  color: #fff;
  padding: 20px 20px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  border-radius: 28px 28px 0 0;
}

/* Decorative circles */
.mothi-header::before {
  content: '';
  position: absolute;
  top: -30px; right: -20px;
  width: 110px; height: 110px;
  background: rgba(255,215,0,0.15);
  border-radius: 50%;
  pointer-events: none;
}
.mothi-header::after {
  content: '';
  position: absolute;
  bottom: -50px; right: 50px;
  width: 90px; height: 90px;
  background: rgba(255,255,255,0.07);
  border-radius: 50%;
  pointer-events: none;
}

.mothi-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.mothi-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  border: 2px solid rgba(255,215,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}

.mothi-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.1px;
}

.mothi-subtitle {
  font-size: 11px;
  opacity: 0.82;
  margin-top: 2px;
}

/* Online indicator dot */
.mothi-subtitle::before {
  content: '';
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #4ade80;
  margin-right: 5px;
  vertical-align: middle;
  box-shadow: 0 0 6px #4ade80;
}

.mothi-header-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.mothi-icon-btn {
  background: rgba(255,255,255,0.14);
  border: none;
  color: rgba(255,255,255,0.9);
  cursor: pointer;
  padding: 8px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.mothi-icon-btn:hover,
.mothi-icon-btn:focus-visible {
  background: rgba(255,255,255,0.28);
  outline: 2px solid rgba(255,215,0,0.5);
  outline-offset: 1px;
}

/* =====================================================================
   MESSAGES AREA
===================================================================== */
.mothi-messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
  background: #ffffff;
}

.mothi-messages::-webkit-scrollbar { width: 4px; }
.mothi-messages::-webkit-scrollbar-track { background: transparent; }
.mothi-messages::-webkit-scrollbar-thumb {
  background: rgba(0,100,0,0.18);
  border-radius: 2px;
}

/* =====================================================================
   SPEECH BUBBLES  — rounded pill with a small tail pointer
===================================================================== */
.mothi-msg {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: mothiMsgIn 0.24s cubic-bezier(.34,1.4,.64,1);
}

@keyframes mothiMsgIn {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0)     scale(1);   }
}

/* Bot: left-aligned, tail bottom-left */
.mothi-msg-bot  {
  align-self: flex-start;
  margin-right: 40px;
}

/* User: right-aligned, tail bottom-right */
.mothi-msg-user {
  align-self: flex-end;
  margin-left: 40px;
}

/* Bubble base */
.mothi-bubble {
  padding: 14px 20px;
  font-size: 14.5px;
  line-height: 1.65;
  word-break: break-word;
  position: relative;
  border: none;
}

/* BOT bubble */
.mothi-msg-bot .mothi-bubble {
  background: var(--mothi-bot-bg);
  color: var(--mothi-bot-fg);
  border-radius: 20px 20px 20px 4px;
  box-shadow: 0 4px 16px rgba(0,100,0,0.10);
}

/* BOT tail */
.mothi-msg-bot .mothi-bubble::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 18px;
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 4px solid transparent;
  border-top: 11px solid var(--mothi-bot-bg);
}

/* USER bubble */
.mothi-msg-user .mothi-bubble {
  background: var(--mothi-user-bg);
  color: var(--mothi-user-fg);
  border-radius: 20px 20px 4px 20px;
  box-shadow: 0 4px 20px rgba(0,100,0,0.30);
}

/* USER tail */
.mothi-msg-user .mothi-bubble::after {
  content: '';
  position: absolute;
  bottom: -10px;
  right: 18px;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 10px solid transparent;
  border-top: 11px solid var(--mothi-user-bg);
}

/* Welcome / first message */
.mothi-welcome-card .mothi-bubble {
  background: #d4edda;
  border-left: 4px solid var(--mothi-secondary);
  border-radius: 20px 20px 20px 4px;
}
.mothi-welcome-card .mothi-bubble::after {
  border-top-color: #d4edda;
}

/* Timestamp */
.mothi-msg-time {
  font-size: 10px;
  color: #aaa;
  margin-top: 8px;
  padding: 0 4px;
}
.mothi-msg-user .mothi-msg-time { text-align: right; color: rgba(0,100,0,0.5); }

/* Sources */
.mothi-sources {
  margin-top: 10px;
  padding: 8px 14px;
  background: rgba(0,100,0,0.06);
  border-left: 3px solid var(--mothi-primary);
  border-radius: 0 8px 8px 0;
  font-size: 11px;
  color: var(--mothi-primary);
}
.mothi-sources-label {
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 3px;
  opacity: 0.65;
}
.mothi-sources a {
  color: var(--mothi-primary);
  text-decoration: none;
  display: block;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mothi-sources a:hover { text-decoration: underline; }
.mothi-sources a::before { content: '↗ '; }

/* =====================================================================
   TYPING INDICATOR
===================================================================== */
.mothi-typing-wrap {
  display: flex;
  flex-direction: column;
  align-self: flex-start;
  max-width: 80%;
  margin-right: 40px;
  animation: mothiMsgIn 0.24s cubic-bezier(.34,1.4,.64,1);
}

.mothi-typing {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 16px 22px;
  background: var(--mothi-bot-bg);
  border-radius: 20px 20px 20px 4px;
  box-shadow: 0 4px 16px rgba(0,100,0,0.10);
  width: fit-content;
  position: relative;
}

.mothi-typing::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 18px;
  width: 0; height: 0;
  border-left: 10px solid transparent;
  border-right: 4px solid transparent;
  border-top: 11px solid var(--mothi-bot-bg);
}

.mothi-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--mothi-primary);
  opacity: 0.45;
  animation: mothiBounce 1.3s ease-in-out infinite;
}
.mothi-dot:nth-child(2) { animation-delay: 0.18s; }
.mothi-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes mothiBounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.45; }
  30%            { transform: translateY(-7px); opacity: 1;    }
}

/* =====================================================================
   INPUT AREA
===================================================================== */
.mothi-input-area {
  background: #ffffff;
  padding: 14px 20px 16px;
  flex-shrink: 0;
  border-top: 1px solid #f0f0f0;
}

#mothiv2-chat-form {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--mothi-input-bg);
  border-radius: 50px;
  padding: 10px 10px 10px 22px;
  border: 1.5px solid transparent;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#mothiv2-chat-form:focus-within {
  border-color: rgba(0,100,0,0.3);
  box-shadow: 0 0 0 3px rgba(0,100,0,0.08);
  background: #fff;
}

#mothiv2-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 14px;
  color: var(--mothi-panel-fg);
  resize: none;
  min-height: 24px;
  max-height: 100px;
  overflow-y: auto;
  line-height: 1.5;
  font-family: var(--mothi-font);
}
#mothiv2-input::placeholder { color: #bbb; }
#mothiv2-input::-webkit-scrollbar { width: 3px; }
#mothiv2-input::-webkit-scrollbar-thumb { background: rgba(0,100,0,0.2); border-radius: 2px; }

#mothiv2-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--mothi-primary-light), var(--mothi-primary-dark));
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 3px 10px rgba(0,100,0,0.35);
}
#mothiv2-send-btn:hover:not(:disabled) {
  transform: scale(1.08);
  box-shadow: 0 5px 16px rgba(0,100,0,0.5);
}
#mothiv2-send-btn:focus-visible {
  outline: 3px solid var(--mothi-secondary);
  outline-offset: 2px;
}
#mothiv2-send-btn:active:not(:disabled) { transform: scale(0.93); }
#mothiv2-send-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

.mothi-powered-by {
  font-size: 10px;
  text-align: center;
  color: #ccc;
  margin: 10px 0 0;
  letter-spacing: 0.2px;
}

/* Screen-reader only */
.screen-reader-text {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(1px,1px,1px,1px) !important;
  white-space: nowrap !important;
}

/* =====================================================================
   RESPONSIVE — MOBILE
===================================================================== */
@media (max-width: 480px) {
  #mothiv2-chat-root {
    bottom: 0; right: 0; left: 0;
    align-items: stretch;
    pointer-events: none;
  }
  #mothiv2-chat-panel {
    width: 100%;
    max-width: 100%;
    height: 92dvh;
    max-height: 92dvh;
    border-radius: 24px 24px 0 0;
    margin-bottom: 0;
    pointer-events: all;
  }
  .mothi-header { border-radius: 24px 24px 0 0; }
  #mothiv2-chat-toggle {
    position: fixed;
    bottom: 20px; right: 20px;
    pointer-events: all;
  }
  #mothiv2-chat-root.mothi-position-bottom-left #mothiv2-chat-toggle {
    right: auto; left: 20px;
  }
}

/* =====================================================================
   HIGH CONTRAST / PRINT
===================================================================== */
@media (forced-colors: active) {
  #mothiv2-chat-toggle, #mothiv2-send-btn { forced-color-adjust: none; }
}
@media print { #mothiv2-chat-root { display: none !important; } }
