/* ============================================================
   ARTISAN ESTATE CHATBOT WIDGET
   Upload to: public_html/chatbot/chatbot-widget.css
   ============================================================ */

/* ── Custom properties — edit these to rebrand ──────────────
   Primary:  dark forest green (headers, user bubbles, toggle button)
   Accent:   mid green (send button)
   BG:       very light green tint (panel background)
   ─────────────────────────────────────────────────────────── */
:root {
  --ae-primary:      #2d6b1f;
  --ae-primary-dk:   #1d4d13;
  --ae-primary-lt:   rgba(45, 107, 31, 0.12);
  --ae-accent:       #5aab1e;
  --ae-accent-dk:    #478a15;
  --ae-bg:           #f0f7ec;
  --ae-panel-bg:     #ffffff;
  --ae-msg-bg:       #e6f2df;
  --ae-text:         #1a3312;
  --ae-text-light:   #5a7a52;
  --ae-border:       #c5deba;
  --ae-panel-w:      380px;
  --ae-z:            99999;
  --ae-radius:       16px;
  --ae-transition:   0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Toggle button (always visible, bottom-right) ───────────── */
#ae-chatbot-toggle {
  position:        fixed;
  bottom:          24px;
  right:           24px;
  z-index:         var(--ae-z);
  width:           56px;
  height:          56px;
  border-radius:   50%;
  background:      var(--ae-primary);
  color:           #fff;
  border:          none;
  cursor:          pointer;
  box-shadow:      0 4px 20px rgba(0, 0, 0, 0.25);
  display:         flex;
  align-items:     center;
  justify-content: center;
  transition:      background var(--ae-transition), transform var(--ae-transition);
  font-size:       0; /* hide any stray text */
}
#ae-chatbot-toggle:hover {
  background:  var(--ae-primary-dk);
  transform:   scale(1.06);
}
#ae-chatbot-toggle svg {
  width:       26px;
  height:      26px;
  fill:        #fff;
  flex-shrink: 0;
  transition:  transform var(--ae-transition), opacity var(--ae-transition);
}
#ae-chatbot-toggle .ae-icon-open  { display: block; }
#ae-chatbot-toggle .ae-icon-close { display: none; }
#ae-chatbot-toggle.ae-open .ae-icon-open  { display: none; }
#ae-chatbot-toggle.ae-open .ae-icon-close { display: block; }

/* ── Panel (floats above toggle, grows with content up to 75vh) ─ */
#ae-chatbot-panel {
  position:         fixed;
  bottom:           92px;  /* sits above the 56px toggle + 24px margin + 12px gap */
  right:            24px;
  z-index:          calc(var(--ae-z) - 1);
  width:            var(--ae-panel-w);
  max-width:        calc(100vw - 48px);
  max-height:       75vh;
  background:       var(--ae-panel-bg);
  display:          flex;
  flex-direction:   column;
  border-radius:    12px;
  box-shadow:       0 8px 40px rgba(0, 0, 0, 0.2);
  transform:        translateX(calc(100% + 32px));
  transition:       transform var(--ae-transition);
  font-family:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size:        14px;
  color:            var(--ae-text);
  overflow:         hidden;
}
#ae-chatbot-panel.ae-open {
  transform: translateX(0);
}

/* ── Header ─────────────────────────────────────────────────── */
#ae-chatbot-header {
  background:   var(--ae-primary);
  color:        #fff;
  padding:      14px 16px;
  display:      flex;
  align-items:  center;
  gap:          12px;
  flex-shrink:  0;
  min-height:   64px;
}
#ae-chatbot-header-back {
  background:  transparent;
  border:      none;
  color:       #fff;
  cursor:      pointer;
  padding:     4px;
  display:     flex;
  align-items: center;
  opacity:     0.85;
  flex-shrink: 0;
}
#ae-chatbot-header-back:hover { opacity: 1; }
#ae-chatbot-header-back svg {
  width:  20px;
  height: 20px;
  fill:   #fff;
}
.ae-chatbot-header-info {
  display:        flex;
  flex-direction: column;
  flex:           1;
  min-width:      0;
}
.ae-chatbot-header-name {
  font-weight:   700;
  font-size:     15px;
  line-height:   1.3;
  white-space:   nowrap;
  overflow:      hidden;
  text-overflow: ellipsis;
}
.ae-chatbot-header-status {
  font-size:   12px;
  opacity:     0.8;
  margin-top:  2px;
}

/* ── Messages area ───────────────────────────────────────────── */
#ae-chatbot-messages {
  flex:             1;
  overflow-y:       auto;
  min-height:       0; /* required for flexbox to allow scrolling within max-height */
  padding:          16px 14px;
  display:          flex;
  flex-direction:   column;
  gap:              4px;
  background:       #eaf4e3;
  scroll-behavior:  smooth;
}
#ae-chatbot-messages::-webkit-scrollbar { width: 4px; }
#ae-chatbot-messages::-webkit-scrollbar-track { background: transparent; }
#ae-chatbot-messages::-webkit-scrollbar-thumb { background: var(--ae-border); border-radius: 4px; }

/* ── Date stamp ──────────────────────────────────────────────── */
.ae-chatbot-datestamp {
  text-align:   center;
  font-size:    11px;
  color:        var(--ae-text-light);
  margin:       8px 0;
  flex-shrink:  0;
}

/* ── Message rows ────────────────────────────────────────────── */
.ae-chatbot-row {
  display:    flex;
  align-items: flex-end;
  gap:         8px;
  max-width:   100%;
}
.ae-chatbot-row.ae-user {
  flex-direction:  row-reverse;
  justify-content: flex-start;
}
.ae-chatbot-row.ae-bot {
  flex-direction:  row;
  justify-content: flex-start;
}

/* ── Avatar ─────────────────────────────────────────────────── */
.ae-chatbot-avatar {
  width:         32px;
  height:        32px;
  border-radius: 50%;
  background:    var(--ae-primary);
  flex-shrink:   0;
  display:       flex;
  align-items:   center;
  justify-content: center;
  overflow:      hidden;
  align-self:    flex-end;
  margin-bottom: 18px; /* space for the "Bot" label */
}
.ae-chatbot-avatar svg {
  width:  18px;
  height: 18px;
  fill:   #fff;
}

/* ── Bot message group (avatar + bubble + label) ────────────── */
.ae-chatbot-bot-group {
  display:        flex;
  flex-direction: column;
  align-items:    flex-start;
  max-width:      78%;
  gap:            2px;
}
.ae-chatbot-sender-label {
  font-size:   11px;
  color:       var(--ae-text-light);
  padding:     0 2px;
  margin-top:  2px;
}

/* ── Message bubbles ─────────────────────────────────────────── */
.ae-chatbot-bubble {
  padding:       10px 14px;
  border-radius: var(--ae-radius);
  line-height:   1.55;
  word-break:    break-word;
  max-width:     100%;
  white-space:   pre-wrap;
}
.ae-chatbot-row.ae-user .ae-chatbot-bubble {
  background:              var(--ae-primary);
  color:                   #fff;
  border-bottom-right-radius: 4px;
  max-width:               72%;
}
.ae-chatbot-row.ae-bot .ae-chatbot-bubble {
  background:              #ffffff;
  color:                   var(--ae-text);
  border-bottom-left-radius: 4px;
  box-shadow:              0 1px 4px rgba(0,0,0,0.08);
}

/* ── Typing indicator ────────────────────────────────────────── */
.ae-chatbot-typing .ae-chatbot-bubble {
  padding: 12px 16px;
  display: flex;
  gap:     5px;
  align-items: center;
}
.ae-chatbot-typing .ae-chatbot-bubble span {
  width:         7px;
  height:        7px;
  border-radius: 50%;
  background:    var(--ae-primary);
  opacity:       0.4;
  animation:     ae-bounce 1.2s infinite ease-in-out;
  flex-shrink:   0;
}
.ae-chatbot-typing .ae-chatbot-bubble span:nth-child(2) { animation-delay: 0.2s; }
.ae-chatbot-typing .ae-chatbot-bubble span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ae-bounce {
  0%, 80%, 100% { transform: translateY(0);    opacity: 0.4; }
  40%            { transform: translateY(-5px); opacity: 1;   }
}

/* ── Human handoff form ──────────────────────────────────────── */
#ae-chatbot-handoff {
  background:    #fff;
  border:        1px solid var(--ae-border);
  border-radius: var(--ae-radius);
  padding:       16px;
  margin-top:    8px;
  display:       flex;
  flex-direction: column;
  gap:           10px;
  box-shadow:    0 1px 4px rgba(0,0,0,0.08);
}
.ae-handoff-title {
  font-weight: 600;
  font-size:   14px;
  color:       var(--ae-text);
}
.ae-handoff-subtitle {
  font-size:  13px;
  color:      var(--ae-text-light);
  margin-top: -6px;
}
.ae-handoff-input {
  border:        1px solid var(--ae-border);
  border-radius: 8px;
  padding:       9px 12px;
  font-size:     14px;
  font-family:   inherit;
  color:         var(--ae-text);
  background:    var(--ae-bg);
  width:         100%;
  box-sizing:    border-box;
  outline:       none;
  transition:    border-color 0.2s;
}
.ae-handoff-input:focus {
  border-color: var(--ae-primary);
  box-shadow:   0 0 0 2px var(--ae-primary-lt);
}
textarea.ae-handoff-input {
  resize:     vertical;
  min-height: 72px;
}
.ae-handoff-submit {
  background:    var(--ae-primary);
  color:         #fff;
  border:        none;
  border-radius: 8px;
  padding:       10px 16px;
  font-size:     14px;
  font-weight:   600;
  cursor:        pointer;
  transition:    background 0.2s;
  width:         100%;
}
.ae-handoff-submit:hover    { background: var(--ae-primary-dk); }
.ae-handoff-submit:disabled { opacity: 0.6; cursor: not-allowed; }
.ae-handoff-error {
  font-size:  12px;
  color:      #c0392b;
  margin-top: -4px;
}
.ae-handoff-success {
  font-size:   14px;
  color:       #27643a;
  font-weight: 500;
  text-align:  center;
  padding:     8px 0;
}

/* ── Input bar ───────────────────────────────────────────────── */
#ae-chatbot-input-bar {
  display:      flex;
  align-items:  center;
  gap:          8px;
  padding:      10px 12px;
  border-top:   1px solid var(--ae-border);
  background:   #fff;
  flex-shrink:  0;
}
.ae-chatbot-icon-btn {
  background:  transparent;
  border:      none;
  cursor:      pointer;
  color:       var(--ae-text-light);
  padding:     6px;
  border-radius: 50%;
  display:     flex;
  align-items: center;
  flex-shrink: 0;
  transition:  color 0.2s, background 0.2s;
}
.ae-chatbot-icon-btn:hover {
  color:       var(--ae-primary);
  background:  var(--ae-primary-lt);
}
.ae-chatbot-icon-btn svg {
  width:  18px;
  height: 18px;
  fill:   currentColor;
}
#ae-chatbot-input {
  flex:        1;
  border:      none;
  outline:     none;
  font-size:   14px;
  font-family: inherit;
  color:       var(--ae-text);
  background:  transparent;
  padding:     6px 0;
  min-width:   0;
}
#ae-chatbot-input::placeholder { color: var(--ae-text-light); }
#ae-chatbot-send {
  background:    var(--ae-primary);
  border:        none;
  border-radius: 50%;
  width:         36px;
  height:        36px;
  display:       flex;
  align-items:   center;
  justify-content: center;
  cursor:        pointer;
  flex-shrink:   0;
  transition:    background 0.2s, transform 0.15s;
}
#ae-chatbot-send:hover    { background: var(--ae-primary-dk); transform: scale(1.05); }
#ae-chatbot-send:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
#ae-chatbot-send svg {
  width:  16px;
  height: 16px;
  fill:   #fff;
}

/* ── Mobile: sheet slides up from bottom ─────────────────────── */
@media (max-width: 440px) {
  #ae-chatbot-panel {
    bottom:        0;
    right:         0;
    width:         100vw;
    max-width:     100vw;
    max-height:    85dvh;
    border-radius: 12px 12px 0 0;
    transform:     translateY(calc(100% + 16px));
  }
  #ae-chatbot-panel.ae-open {
    transform: translateY(0);
  }
  #ae-chatbot-toggle {
    bottom: 16px;
    right:  16px;
  }
}
