/* ═══════════════════════════════════════════════════
   ANDHAPANSARI — LIGHTWEIGHT CHAT WIDGET
   Inline lead form · CRM session logging · SSE streaming
   ═══════════════════════════════════════════════════ */

:root {
  --cw-brand:        #fe9a31;
  --cw-brand-dark:   #e0851e;
  --cw-brand-glow:   rgba(254, 154, 49, 0.3);
  --cw-bg:           #fffdf8;
  --cw-surface:      #f7f3ec;
  --cw-border:        #e8dfd0;
  --cw-text:         #2c1810;
  --cw-text-muted:   #8b7355;
  --cw-shadow:       0 8px 32px rgba(44, 24, 16, 0.12);
  --cw-radius-lg:    20px;
  --cw-radius-md:    14px;
  --cw-radius-sm:    999px;
  --cw-font-display: 'Cardo', Georgia, serif;
  --cw-font-body:    'DM Sans', system-ui, sans-serif;
}

/* ── Launcher Button ── */
#chat-launcher {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9999;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--cw-brand);
  background-image: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.22) 0%, transparent 60%);
  border: none;
  cursor: pointer;
  box-shadow:
    0 4px 16px var(--cw-brand-glow),
    0 2px 6px rgba(44,24,16,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.28s ease;
  outline: none;
}

#chat-launcher:hover {
  transform: scale(1.1);
  box-shadow:
    0 8px 24px var(--cw-brand-glow),
    0 4px 10px rgba(44,24,16,0.18);
}

#chat-launcher:active {
  transform: scale(0.94);
}

#chat-launcher:focus-visible {
  outline: 3px solid var(--cw-brand);
  outline-offset: 4px;
}

#chat-launcher .launcher-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#chat-launcher .launcher-icon svg {
  width: 26px;
  height: 26px;
  fill: #fff;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
}

/* ── Chat Window ── */
#chat-window {
  position: fixed;
  bottom: 104px;
  right: 28px;
  z-index: 9998;
  width: 390px;
  max-width: calc(100vw - 40px);
  height: 580px;
  max-height: calc(100vh - 140px);
  background: var(--cw-bg);
  border-radius: var(--cw-radius-lg);
  box-shadow: var(--cw-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1.5px solid var(--cw-border);
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.34, 1.15, 0.64, 1),
              transform 0.3s cubic-bezier(0.34, 1.15, 0.64, 1);
}

#chat-window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ── Header ── */
#chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px 14px;
  background: linear-gradient(135deg, var(--cw-brand) 0%, #f07020 100%);
  flex-shrink: 0;
  position: relative;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.22);
  border: 2px solid rgba(255,255,255,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-avatar svg {
  width: 20px;
  height: 20px;
  fill: #fff;
  opacity: 0.95;
}

.chat-header-info {
  flex: 1;
  min-width: 0;
}

#chat-header-title {
  font-family: var(--cw-font-display);
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
  text-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

#chat-header-sub {
  font-family: var(--cw-font-body);
  font-size: 0.7rem;
  color: rgba(255,255,255,0.85);
  margin-top: 2px;
  letter-spacing: 0.02em;
}

#chat-close {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background 0.15s ease;
  flex-shrink: 0;
}

#chat-close:hover { background: rgba(255,255,255,0.28); }
#chat-close svg { width: 14px; height: 14px; fill: #fff; }

/* ── Messages Area ── */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: var(--cw-border); border-radius: 4px; }
#chat-messages::-webkit-scrollbar-thumb:hover { background: var(--cw-text-muted); }

/* ── Message Bubbles ── */
.msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: var(--cw-radius-md);
  font-family: var(--cw-font-body);
  font-size: 0.875rem;
  line-height: 1.55;
  position: relative;
  word-break: break-word;
  white-space: pre-wrap;
  animation: msg-in 0.25s cubic-bezier(0.34, 1.2, 0.64, 1) both;
}

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

.msg-bot {
  align-self: flex-start;
  background: var(--cw-surface);
  color: var(--cw-text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 6px rgba(44,24,16,0.06);
}

.msg-bot::before {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 12px;
  width: 9px;
  height: 9px;
  background: var(--cw-surface);
  clip-path: polygon(0 0, 100% 0, 0 100%);
}

.msg-user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--cw-brand) 0%, #f07020 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(254,154,49,0.28);
}

.msg-user::before {
  content: '';
  position: absolute;
  bottom: -5px;
  right: 12px;
  width: 9px;
  height: 9px;
  background: linear-gradient(135deg, var(--cw-brand) 0%, #f07020 100%);
  clip-path: polygon(0 0, 100% 0, 100% 100%);
}

.msg-welcome {
  align-self: flex-start;
  background: var(--cw-surface);
  color: var(--cw-text-muted);
  font-size: 0.84rem;
  border-bottom-left-radius: 4px;
  border-left: 3px solid var(--cw-brand);
  padding: 11px 14px;
  line-height: 1.6;
}

.msg-welcome strong { color: var(--cw-text); font-weight: 600; }

/* Typing indicator */
.msg-typing {
  align-self: flex-start;
  background: var(--cw-surface);
  color: var(--cw-text-muted);
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  box-shadow: 0 2px 6px rgba(44,24,16,0.06);
}

.typing-dots { display: flex; gap: 4px; align-items: center; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--cw-text-muted); opacity: 0.5;
  animation: dot-bounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.typing-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%            { transform: translateY(-4px); opacity: 1; }
}

.msg-error {
  align-self: flex-start;
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-bottom-left-radius: 4px;
  font-size: 0.82rem;
}

/* ── Input Area ── */
#chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1.5px solid var(--cw-border);
  background: var(--cw-bg);
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  border: 1.5px solid var(--cw-border);
  border-radius: var(--cw-radius-md);
  padding: 9px 12px;
  font-family: var(--cw-font-body);
  font-size: 0.875rem;
  line-height: 1.4;
  background: var(--cw-surface);
  color: var(--cw-text);
  outline: none;
  resize: none;
  max-height: 110px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  field-sizing: content;
}

#chat-input::placeholder { color: var(--cw-text-muted); opacity: 0.7; }
#chat-input:focus {
  border-color: var(--cw-brand);
  background: var(--cw-bg);
  box-shadow: 0 0 0 3px var(--cw-brand-glow);
}

#chat-send {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--cw-brand) 0%, #f07020 100%);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 3px 8px rgba(254,154,49,0.28);
}

#chat-send:hover:not(:disabled) { transform: scale(1.08); box-shadow: 0 5px 14px rgba(254,154,49,0.38); }
#chat-send:active:not(:disabled) { transform: scale(0.9); }
#chat-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
#chat-send svg { width: 15px; height: 15px; fill: #fff; transform: translateX(1px); }

/* Connection dot */
.conn-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #4ade80; display: inline-block;
  animation: conn-pulse 2s ease-in-out infinite;
  vertical-align: middle; margin-right: 3px;
}
.conn-dot.offline { background: #f87171; animation: none; }

@keyframes conn-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}

/* ═══════════════════════════════════════
   INLINE LEAD FORM
   Lightweight, compact, botanical note-card aesthetic
   ═══════════════════════════════════════ */

.chat-lead-form {
  display: flex;
  flex-direction: column;
  gap: 0;
  animation: lead-in 0.4s cubic-bezier(0.34, 1.2, 0.64, 1) both;
}

@keyframes lead-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Compact header — no full panel takeover */
.lead-form-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0 12px;
  animation: lead-in 0.4s cubic-bezier(0.34, 1.2, 0.64, 1) 0.05s both;
}

.lead-form-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cw-brand) 0%, #f07020 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(254,154,49,0.3);
}

.lead-form-icon svg { width: 16px; height: 16px; fill: #fff; }

.lead-form-title {
  font-family: var(--cw-font-display);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--cw-text);
  line-height: 1.2;
}

.lead-form-sub {
  font-family: var(--cw-font-body);
  font-size: 0.74rem;
  color: var(--cw-text-muted);
  margin-top: 1px;
}

/* Inline form */
.lead-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid var(--cw-border);
  border-bottom: 1px solid var(--cw-border);
  animation: lead-in 0.4s cubic-bezier(0.34, 1.2, 0.64, 1) 0.1s both;
}

.lead-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.lead-field-wrap {
  position: relative;
}

.lead-input {
  width: 100%;
  box-sizing: border-box;
  height: 44px;
  padding: 14px 12px 6px;
  border: 1.5px solid var(--cw-border);
  border-radius: 10px;
  background: rgba(247,243,236,0.6);
  font-family: var(--cw-font-body);
  font-size: 0.85rem;
  color: var(--cw-text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.lead-input.full { grid-column: 1 / -1; }
.lead-input::placeholder { color: transparent; }

.lead-input:focus {
  border-color: var(--cw-brand);
  background: var(--cw-bg);
  box-shadow: 0 0 0 3px var(--cw-brand-glow);
}

.lead-label {
  position: absolute;
  top: 13px;
  left: 12px;
  font-family: var(--cw-font-body);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--cw-text-muted);
  pointer-events: none;
  transition: top 0.18s ease, font-size 0.18s ease, color 0.18s ease;
}

.lead-input:focus ~ .lead-label,
.lead-input:not(:placeholder-shown) ~ .lead-label {
  top: 6px;
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--cw-brand-dark);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.lead-error {
  min-height: 16px;
  color: #b42318;
  font-family: var(--cw-font-body);
  font-size: 0.72rem;
  padding: 0 2px;
  animation: lead-in 0.2s ease both;
}

/* Submit row */
.lead-submit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 10px;
  animation: lead-in 0.4s cubic-bezier(0.34, 1.2, 0.64, 1) 0.15s both;
}

#chat-lead-submit {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 20px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--cw-brand) 0%, #f07020 100%);
  color: #fff;
  font-family: var(--cw-font-body);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.2s ease, opacity 0.2s ease;
  box-shadow: 0 3px 10px rgba(254,154,49,0.32);
  white-space: nowrap;
}

#chat-lead-submit:hover {
  transform: translateY(-1px) scale(1.02);
  box-shadow: 0 6px 16px rgba(254,154,49,0.4);
}

#chat-lead-submit:active { transform: scale(0.97); box-shadow: 0 2px 6px rgba(254,154,49,0.28); }

#chat-lead-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

#chat-lead-submit svg { width: 14px; height: 14px; fill: #fff; }

.lead-privacy {
  font-family: var(--cw-font-body);
  font-size: 0.65rem;
  color: var(--cw-text-muted);
  opacity: 0.7;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  max-width: 130px;
  line-height: 1.4;
}

.lead-privacy svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 1.5; flex-shrink: 0; }

/* Form collapse animation */
.chat-lead-form.collapsing {
  animation: lead-collapse 0.4s ease forwards;
}

@keyframes lead-collapse {
  0%   { opacity: 1; transform: translateY(0); max-height: 400px; }
  40%  { opacity: 0; transform: translateY(-8px); }
  100% { opacity: 0; transform: translateY(-12px); max-height: 0; padding: 0; margin: 0; display: none; }
}

/* Welcome message — appears after form collapse */
#chat-welcome-msg {
  animation: msg-in 0.35s ease both;
}

/* Session badge */
.chat-session-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(254,154,49,0.1);
  border: 1px solid rgba(254,154,49,0.2);
  font-family: var(--cw-font-body);
  font-size: 0.62rem;
  color: var(--cw-text-muted);
  margin-top: 6px;
  animation: lead-in 0.3s ease 0.2s both;
  opacity: 0;
}

.chat-session-badge.visible { opacity: 1; }

/* Mobile */
@media (max-width: 480px) {
  #chat-launcher { bottom: 20px; right: 20px; width: 54px; height: 54px; }
  #chat-window {
    bottom: 88px;
    right: 10px;
    left: 10px;
    width: auto;
    max-height: 75vh;
    border-radius: 18px 18px 14px 14px;
  }
  .msg { max-width: 85%; }
  .lead-row { grid-template-columns: 1fr 1fr; }
  .lead-input { height: 42px; }
}
