/* =========================================================
   SmartLease AI Assistant Widget
   Fully scoped under .sl-ast-* to avoid Bootstrap conflicts.
   ========================================================= */

/* ---- Variables ---- */
:root {
  --sl-ast-green:       #006837;
  --sl-ast-green-light: #00A67E;
  --sl-ast-gold:        #C9A84C;
  --sl-ast-dark:        #0A2540;
  --sl-ast-bubble-user: #006837;
  --sl-ast-bubble-ai:   #F0F2F5;
  --sl-ast-text-user:   #ffffff;
  --sl-ast-text-ai:     #1a1a2e;
  --sl-ast-radius:      18px;
  --sl-ast-panel-w:     380px;
  --sl-ast-panel-h:     540px;
  --sl-ast-z:           9999;
}

/* ---- FAB toggle button ---- */
.sl-ast-fab {
  position: fixed;
  bottom: 88px;        /* sits above the theme-switcher FAB */
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--sl-ast-green), var(--sl-ast-green-light));
  box-shadow: 0 4px 16px rgba(0, 104, 55, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--sl-ast-z);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  outline: none;
}

.sl-ast-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 22px rgba(0, 104, 55, 0.55);
}

.sl-ast-fab:active {
  transform: scale(0.95);
}

.sl-ast-fab svg {
  width: 26px;
  height: 26px;
  fill: #fff;
  transition: opacity 0.15s;
}

.sl-ast-fab .sl-ast-icon-open  { display: block; }
.sl-ast-fab .sl-ast-icon-close { display: none; }
.sl-ast-fab.is-open .sl-ast-icon-open  { display: none; }
.sl-ast-fab.is-open .sl-ast-icon-close { display: block; }

/* ---- Chat panel ---- */
.sl-ast-panel {
  position: fixed;
  bottom: 156px;      /* above the FAB */
  right: 24px;
  width: var(--sl-ast-panel-w);
  height: var(--sl-ast-panel-h);
  background: #ffffff;
  border-radius: 20px;
  box-shadow:
    0 8px 40px rgba(0, 0, 0, 0.18),
    0 2px 8px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: var(--sl-ast-z);
  transform-origin: bottom right;
  animation: sl-ast-open 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.sl-ast-panel.sl-ast-closing {
  animation: sl-ast-close 0.18s ease-in forwards;
}

@keyframes sl-ast-open {
  from { opacity: 0; transform: scale(0.85) translateY(16px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes sl-ast-close {
  from { opacity: 1; transform: scale(1) translateY(0); }
  to   { opacity: 0; transform: scale(0.85) translateY(16px); }
}

/* ---- Panel header ---- */
.sl-ast-header {
  background: linear-gradient(135deg, var(--sl-ast-dark) 0%, #163a60 100%);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sl-ast-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sl-ast-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--sl-ast-green), var(--sl-ast-green-light));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.9rem;
  color: #fff;
  flex-shrink: 0;
  font-family: 'Playfair Display', serif;
}

.sl-ast-header-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.sl-ast-header-subtitle {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.55);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 1px;
}

.sl-ast-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
  flex-shrink: 0;
}

.sl-ast-status-dot.thinking {
  background: var(--sl-ast-gold);
  animation: sl-ast-pulse 1s ease-in-out infinite;
}

@keyframes sl-ast-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

.sl-ast-close-btn {
  background: rgba(255,255,255,0.12);
  border: none;
  color: rgba(255,255,255,0.75);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.sl-ast-close-btn:hover {
  background: rgba(255,255,255,0.22);
  color: #fff;
}

/* ---- Messages scroll area ---- */
.sl-ast-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.sl-ast-messages::-webkit-scrollbar {
  width: 4px;
}
.sl-ast-messages::-webkit-scrollbar-track {
  background: transparent;
}
.sl-ast-messages::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.12);
  border-radius: 4px;
}

/* ---- Message row ---- */
.sl-ast-msg {
  display: flex;
  gap: 8px;
  max-width: 100%;
  animation: sl-ast-msg-in 0.2s ease-out forwards;
}

@keyframes sl-ast-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.sl-ast-msg--user {
  flex-direction: row-reverse;
}

.sl-ast-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--sl-ast-green), var(--sl-ast-green-light));
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  font-family: 'Playfair Display', serif;
}

.sl-ast-msg--user .sl-ast-msg-avatar {
  background: #e2e8f0;
  color: #475569;
  font-family: 'Inter', sans-serif;
}

.sl-ast-bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: var(--sl-ast-radius);
  font-size: 0.875rem;
  line-height: 1.6;
  word-break: break-word;
}

.sl-ast-msg--user .sl-ast-bubble {
  background: var(--sl-ast-bubble-user);
  color: var(--sl-ast-text-user);
  border-bottom-right-radius: 4px;
}

.sl-ast-msg--assistant .sl-ast-bubble {
  background: var(--sl-ast-bubble-ai);
  color: var(--sl-ast-text-ai);
  border-bottom-left-radius: 4px;
}

/* Markdown-like formatting inside bubbles */
.sl-ast-bubble strong { font-weight: 700; }
.sl-ast-bubble em     { font-style: italic; }
.sl-ast-bubble code {
  background: rgba(0,0,0,0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.82em;
  font-family: monospace;
}
.sl-ast-msg--user .sl-ast-bubble code {
  background: rgba(255,255,255,0.2);
}
.sl-ast-bubble p      { margin: 0 0 6px; }
.sl-ast-bubble p:last-child { margin-bottom: 0; }
.sl-ast-bubble ul, .sl-ast-bubble ol {
  margin: 4px 0;
  padding-left: 18px;
}
.sl-ast-bubble li { margin: 2px 0; }

/* Source citation pill */
.sl-ast-sources {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.sl-ast-source-pill {
  font-size: 0.68rem;
  background: rgba(0,104,55,0.1);
  color: var(--sl-ast-green);
  border-radius: 20px;
  padding: 2px 8px;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Typing indicator ---- */
.sl-ast-typing {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sl-ast-typing-dots {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--sl-ast-bubble-ai);
  border-radius: var(--sl-ast-radius);
  border-bottom-left-radius: 4px;
}

.sl-ast-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: sl-ast-bounce 1.2s ease-in-out infinite;
}
.sl-ast-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.sl-ast-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes sl-ast-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%            { transform: translateY(-6px); }
}

/* ---- Input area ---- */
.sl-ast-input-area {
  border-top: 1px solid #f0f0f0;
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
  background: #fff;
}

.sl-ast-input {
  flex: 1;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 9px 13px;
  font-size: 0.875rem;
  font-family: 'Inter', sans-serif;
  color: #1a1a2e;
  background: #f8fafc;
  resize: none;
  outline: none;
  max-height: 100px;
  min-height: 40px;
  line-height: 1.5;
  transition: border-color 0.15s;
  overflow-y: auto;
}

.sl-ast-input:focus {
  border-color: var(--sl-ast-green);
  background: #fff;
}

.sl-ast-input::placeholder {
  color: #94a3b8;
}

.sl-ast-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--sl-ast-green), var(--sl-ast-green-light));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.1s;
  outline: none;
}

.sl-ast-send-btn:hover:not(:disabled) {
  opacity: 0.88;
}

.sl-ast-send-btn:active:not(:disabled) {
  transform: scale(0.92);
}

.sl-ast-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.sl-ast-send-btn svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

/* ---- Footer credit ---- */
.sl-ast-footer {
  text-align: center;
  font-size: 0.65rem;
  color: #cbd5e1;
  padding: 5px 0 7px;
  background: #fff;
  flex-shrink: 0;
  border-top: 1px solid #f8fafc;
  letter-spacing: 0.02em;
}

/* ---- Welcome / empty state ---- */
.sl-ast-welcome {
  text-align: center;
  padding: 24px 16px;
  color: #64748b;
}

.sl-ast-welcome-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--sl-ast-green), var(--sl-ast-green-light));
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
  font-size: 1.4rem;
  font-weight: 800;
  color: #fff;
  font-family: 'Playfair Display', serif;
}

.sl-ast-welcome h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 6px;
}

.sl-ast-welcome p {
  font-size: 0.8rem;
  line-height: 1.55;
  margin-bottom: 16px;
}

.sl-ast-suggestions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.sl-ast-suggestion {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.78rem;
  color: #334155;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, border-color 0.15s;
  font-family: 'Inter', sans-serif;
}

.sl-ast-suggestion:hover {
  background: #f0fdf4;
  border-color: var(--sl-ast-green);
  color: var(--sl-ast-green);
}

/* ---- Error bubble ---- */
.sl-ast-error-bubble {
  background: #fef2f2;
  color: #b91c1c;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.8rem;
  text-align: center;
  border: 1px solid #fecaca;
}

/* ---- Mobile responsive ---- */
@media (max-width: 480px) {
  .sl-ast-panel {
    width: calc(100vw - 16px);
    right: 8px;
    bottom: 80px;
    height: 70vh;
    max-height: 520px;
    border-radius: 16px;
  }

  .sl-ast-fab {
    bottom: 16px;
    right: 16px;
  }
}
