/* ==========================================================================
   CWK Wiki Chat Widget
   All selectors prefixed .cwk-chat- to avoid Just the Docs collisions.
   Uses JTD CSS custom properties for automatic dark/light mode support.
   ========================================================================== */

/* ---------- Toggle button ---------- */

.cwk-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: var(--link-color, #2563eb);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cwk-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.cwk-chat-toggle svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}

.cwk-chat-toggle[aria-expanded="true"] {
  display: none;
}

/* ---------- Chat panel ---------- */

.cwk-chat-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: 420px;
  height: 540px;
  max-height: calc(100vh - 48px);
  display: none;
  flex-direction: column;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  background: var(--body-background-color, #fff);
  border: 1px solid var(--border-color, #e0e0e0);
  font-family: inherit;
}

.cwk-chat-panel.cwk-chat-open {
  display: flex;
}

/* ---------- Header ---------- */

.cwk-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--link-color, #2563eb);
  color: #fff;
  flex-shrink: 0;
}

.cwk-chat-header-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
}

.cwk-chat-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  font-size: 20px;
  opacity: 0.8;
  transition: opacity 0.15s;
}

.cwk-chat-close:hover {
  opacity: 1;
}

/* ---------- Messages area ---------- */

.cwk-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cwk-chat-message {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.5;
  word-wrap: break-word;
  color: var(--body-text-color, #1a1a1a);
}

.cwk-chat-message-user {
  align-self: flex-end;
  background: var(--link-color, #2563eb);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.cwk-chat-message-assistant {
  align-self: flex-start;
  background: var(--sidebar-color, #f5f6fa);
  border-bottom-left-radius: 4px;
}

.cwk-chat-message-assistant a {
  color: var(--link-color, #2563eb);
  text-decoration: underline;
}

/* Markdown rendered in assistant messages */
.cwk-chat-message-assistant p {
  margin: 0 0 8px;
}

.cwk-chat-message-assistant p:last-child {
  margin-bottom: 0;
}

.cwk-chat-message-assistant ul,
.cwk-chat-message-assistant ol {
  margin: 4px 0 8px 20px;
  padding: 0;
}

.cwk-chat-message-assistant li {
  margin-bottom: 2px;
}

.cwk-chat-message-assistant code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12.5px;
}

/* Typing indicator */
.cwk-chat-typing {
  align-self: flex-start;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--body-text-color, #888);
  opacity: 0.7;
}

/* Welcome message */
.cwk-chat-welcome {
  text-align: center;
  color: var(--body-text-color, #666);
  opacity: 0.7;
  font-size: 13px;
  padding: 20px 16px 8px;
  line-height: 1.5;
}

/* ---------- Input area ---------- */

.cwk-chat-input-area {
  display: flex;
  padding: 12px;
  border-top: 1px solid var(--border-color, #e0e0e0);
  gap: 8px;
  flex-shrink: 0;
  background: var(--body-background-color, #fff);
}

.cwk-chat-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border-color, #d0d0d0);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: inherit;
  resize: none;
  outline: none;
  background: var(--body-background-color, #fff);
  color: var(--body-text-color, #1a1a1a);
  min-height: 40px;
  max-height: 80px;
}

.cwk-chat-input:focus {
  border-color: var(--link-color, #2563eb);
}

.cwk-chat-input::placeholder {
  color: var(--body-text-color, #999);
  opacity: 0.6;
}

.cwk-chat-send {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: var(--link-color, #2563eb);
  color: #fff;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: opacity 0.15s;
  align-self: flex-end;
}

.cwk-chat-send:hover {
  opacity: 0.9;
}

.cwk-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Error ---------- */

.cwk-chat-error {
  align-self: center;
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  text-align: center;
}

/* ---------- Mobile ---------- */

@media (max-width: 768px) {
  .cwk-chat-panel {
    width: calc(100vw - 16px);
    height: calc(100vh - 16px);
    bottom: 8px;
    right: 8px;
    border-radius: 8px;
  }

  .cwk-chat-toggle {
    bottom: 16px;
    right: 16px;
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .cwk-chat-toggle,
  .cwk-chat-panel,
  .cwk-chat-send {
    transition: none;
  }
}
