/* ============================================================
   casasmooth Chat Widget — chat.css
   Uses CSS vars from site.css (:root block)
   ============================================================ */

/* Floating action button */
#cs-chat-btn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9999;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal), var(--teal-strong));
  box-shadow: 0 8px 32px var(--teal-glow), 0 2px 8px rgba(0,0,0,0.4);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
#cs-chat-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 40px var(--teal-glow), 0 2px 8px rgba(0,0,0,0.5);
}
#cs-chat-btn svg {
  width: 26px;
  height: 26px;
  fill: #000;
  transition: opacity 0.15s;
}
#cs-chat-btn.is-open .cs-icon-open { display: none; }
#cs-chat-btn:not(.is-open) .cs-icon-close { display: none; }

/* Unread badge */
#cs-chat-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--amber);
  border: 2px solid var(--bg);
  display: none;
}
#cs-chat-badge.visible { display: block; }

/* Panel */
#cs-chat-panel {
  position: fixed;
  bottom: 96px;
  right: 28px;
  z-index: 9998;
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: var(--bg1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(16px) scale(0.97);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s cubic-bezier(0.34,1.56,0.64,1), opacity 0.18s ease;
}
#cs-chat-panel.is-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* Header */
#cs-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.cs-chat-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--teal-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.cs-chat-avatar svg { width: 18px; height: 18px; fill: var(--teal); }
.cs-chat-title {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.2;
}
.cs-chat-subtitle {
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
}
.cs-chat-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--muted);
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
}
.cs-chat-close:hover { color: var(--ink); background: var(--surface2); }
.cs-chat-close svg { width: 16px; height: 16px; fill: currentColor; }

/* Messages area */
#cs-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface3) transparent;
}
#cs-chat-messages::-webkit-scrollbar { width: 4px; }
#cs-chat-messages::-webkit-scrollbar-track { background: transparent; }
#cs-chat-messages::-webkit-scrollbar-thumb {
  background: var(--surface3);
  border-radius: 2px;
}

/* Message bubbles */
.cs-msg {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: cs-msg-in 0.18s ease;
}
@keyframes cs-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.cs-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.cs-msg.assistant { align-self: flex-start; }

.cs-msg-bubble {
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}
.cs-msg.assistant .cs-msg-bubble {
  background: var(--surface2);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}
.cs-msg.user .cs-msg-bubble {
  background: var(--teal);
  color: #000;
  font-weight: 500;
  border-bottom-right-radius: 4px;
}

/* Simple markdown rendering */
.cs-msg-bubble strong { font-weight: 700; }
.cs-msg-bubble em { font-style: italic; }
.cs-msg-bubble ul {
  margin: 6px 0 2px 0;
  padding-left: 18px;
  list-style: disc;
}
.cs-msg-bubble li { margin-bottom: 2px; }
.cs-msg-bubble p { margin: 0 0 6px; }
.cs-msg-bubble p:last-child { margin-bottom: 0; }

/* Typing indicator */
.cs-typing {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  align-items: center;
  background: var(--surface2);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  max-width: 60px;
}
.cs-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: cs-bounce 1.2s infinite;
}
.cs-typing span:nth-child(2) { animation-delay: 0.18s; }
.cs-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes cs-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40%           { transform: translateY(-5px); opacity: 1; }
}

/* Suggestions chips */
#cs-chat-suggestions {
  padding: 4px 12px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}
.cs-chip {
  background: var(--teal-dim);
  color: var(--teal-strong);
  border: 1px solid rgba(0,196,154,0.18);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s, border-color 0.15s;
}
.cs-chip:hover {
  background: rgba(0,196,154,0.2);
  border-color: rgba(0,196,154,0.35);
}

/* Input area */
#cs-chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#cs-chat-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  padding: 9px 16px;
  font-size: 13.5px;
  color: var(--ink);
  outline: none;
  resize: none;
  line-height: 1.4;
  max-height: 80px;
  overflow-y: auto;
  transition: border-color 0.15s;
  font-family: inherit;
}
#cs-chat-input::placeholder { color: var(--muted); }
#cs-chat-input:focus { border-color: var(--teal); }

#cs-chat-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--teal);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: flex-end;
  transition: background 0.15s, transform 0.1s;
}
#cs-chat-send:hover { background: var(--teal-strong); }
#cs-chat-send:active { transform: scale(0.93); }
#cs-chat-send:disabled { background: var(--surface3); cursor: not-allowed; }
#cs-chat-send svg { width: 18px; height: 18px; fill: #000; }

/* Error state */
.cs-msg-error {
  font-size: 12px;
  color: var(--amber);
  text-align: center;
  padding: 4px 8px;
}

/* Light theme adjustments */
[data-theme="light"] .cs-msg.user .cs-msg-bubble { color: #fff; }
[data-theme="light"] #cs-chat-send svg { fill: #fff; }
[data-theme="light"] #cs-chat-btn svg { fill: #fff; }
