/* 4ALL API support chat widget styles
 * Loaded from /widget/chat-widget.css on every 4allapi.com property.
 * Designed not to conflict with host page styles — all classes are namespaced
 * under #chat-widget-root and prefixed with `cw-`.
 */
#chat-widget-root,
#chat-widget-root *,
#chat-widget-root *::before,
#chat-widget-root *::after {
  box-sizing: border-box;
}

#chat-widget-root {
  --cw-bg:        rgba(15, 18, 28, 0.97);
  --cw-text:      #f4f7ff;
  --cw-muted:     rgba(226, 232, 255, 0.5);
  --cw-border:    rgba(255, 255, 255, 0.08);
  --cw-accent-a:  #9071ff;
  --cw-accent-b:  #76d4ff;
  --cw-bubble-bg: linear-gradient(135deg, var(--cw-accent-a), var(--cw-accent-b));
  font-family: "Segoe UI Variable Display", "Segoe UI", "PingFang SC",
    "Microsoft YaHei", -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--cw-text);
}

.cw-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2147483646;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--cw-bubble-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.35);
  border: none;
  padding: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.cw-bubble:hover  { transform: scale(1.06); box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45); }
.cw-bubble:active { transform: scale(0.97); }
.cw-bubble svg    { width: 28px; height: 28px; fill: #fff; }

.cw-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2147483647;
  width: 380px;
  height: min(620px, calc(100vh - 48px));
  background: var(--cw-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  transform: translateY(120%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.3, 0.7, 0.4, 1), opacity 0.2s ease;
}
.cw-panel.cw-open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 480px) {
  .cw-panel {
    bottom: 0; right: 0; left: 0;
    width: 100%;
    height: 100vh;
    border-radius: 0;
  }
}

.cw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--cw-border);
  flex-shrink: 0;
}
.cw-header-title {
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.cw-header-close {
  background: none;
  border: none;
  color: var(--cw-text);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 6px;
  opacity: 0.7;
  border-radius: 8px;
  transition: opacity 0.15s, background 0.15s;
}
.cw-header-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.05);
}

.cw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.cw-messages::-webkit-scrollbar { width: 6px; }
.cw-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

.cw-msg {
  max-width: 88%;
  word-wrap: break-word;
  font-size: 0.92rem;
  line-height: 1.55;
  padding: 10px 14px;
}
.cw-msg-bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px 14px 14px 4px;
}
.cw-msg-user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--cw-accent-a), #7090ff);
  color: #fff;
  border-radius: 14px 14px 4px 14px;
  white-space: pre-wrap;
}
.cw-msg p          { margin: 0 0 8px; }
.cw-msg p:last-child { margin-bottom: 0; }
.cw-msg a          { color: var(--cw-accent-b); text-decoration: underline; word-break: break-all; }
.cw-msg a:hover    { text-decoration: none; }
.cw-msg code {
  background: rgba(0, 0, 0, 0.32);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.86em;
}
.cw-msg pre {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 6px 0;
  font-size: 0.86em;
}
.cw-msg pre code  { background: none; padding: 0; }
.cw-msg strong    { font-weight: 700; }
.cw-msg em        { font-style: italic; }
.cw-msg ul,
.cw-msg ol        { margin: 6px 0 6px 20px; padding: 0; }
.cw-msg li        { margin: 2px 0; }

.cw-thinking      { display: inline-flex; align-items: center; gap: 6px; }
.cw-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cw-accent-b);
  opacity: 0.5;
  animation: cw-dot 1.2s infinite;
}
.cw-dot:nth-child(2) { animation-delay: 0.15s; }
.cw-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes cw-dot {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40%           { opacity: 1;   transform: translateY(-2px); }
}

.cw-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px 4px;
  border-top: 1px solid var(--cw-border);
  flex-shrink: 0;
}
.cw-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--cw-text);
  font-size: 0.92rem;
  resize: none;
  max-height: 120px;
  min-height: 40px;
  outline: none;
  font-family: inherit;
  line-height: 1.4;
}
.cw-input::placeholder { color: var(--cw-muted); }
.cw-input:focus        { border-color: rgba(144, 113, 255, 0.5); }
.cw-send {
  align-self: flex-end;
  background: var(--cw-bubble-bg);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 0 18px;
  height: 40px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.1s;
}
.cw-send:hover:not(:disabled)   { opacity: 0.92; }
.cw-send:active:not(:disabled)  { transform: scale(0.97); }
.cw-send:disabled               { opacity: 0.45; cursor: not-allowed; }

.cw-footer {
  padding: 8px 16px 14px;
  font-size: 0.78rem;
  color: var(--cw-muted);
  text-align: center;
  flex-shrink: 0;
}
.cw-footer a { color: rgba(118, 212, 255, 0.85); }
