#ai-chat-window {
  position: fixed;
  bottom: 88px;
  right: 24px;
  width: 400px;
  height: 540px;
  border-radius: 12px;
  z-index: 9998;
  display: none;
  flex-direction: column;
  background: #fff;
  border: 1px solid #e5e7eb;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

#ai-chat-window.ai-chat-open {
  display: flex;
}

.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #222;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.ai-chat-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-chat-header-left i {
  font-size: 14px;
}

.ai-chat-header-ctx {
  font-size: 11px;
  font-weight: 400;
  opacity: 0.7;
  margin-left: 4px;
}

#ai-chat-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.2s;
}

#ai-chat-close:hover {
  opacity: 1;
}

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

#ai-chat-messages::-webkit-scrollbar {
  width: 4px;
}

#ai-chat-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 2px;
}

.ai-chat-msg {
  max-width: 90%;
}

.ai-chat-msg-user {
  align-self: flex-end;
}

.ai-chat-msg-assistant {
  align-self: flex-start;
}

.ai-chat-msg-content {
  padding: 10px 14px;
  border-radius: 10px;
  word-break: break-word;
}

.ai-chat-msg-user .ai-chat-msg-content {
  background: #222;
  color: #fff;
  border-bottom-right-radius: 3px;
  white-space: pre-wrap;
}

.ai-chat-msg-assistant .ai-chat-msg-content {
  background: #f3f4f6;
  color: #1f2937;
  border-bottom-left-radius: 3px;
}

.ai-chat-welcome {
  text-align: center;
  color: #9ca3af;
  font-size: 13px;
  padding: 20px 16px;
  line-height: 1.8;
}

.ai-chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  flex-shrink: 0;
}

#ai-chat-input {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  max-height: 100px;
  outline: none;
  background: #fff;
  color: #1f2937;
  transition: border-color 0.2s;
}

#ai-chat-input:focus {
  border-color: #555;
}

#ai-chat-input::placeholder {
  color: #9ca3af;
}

#ai-chat-send {
  padding: 8px 14px;
  background: #222;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.2s;
  flex-shrink: 0;
}

#ai-chat-send:hover {
  opacity: 0.85;
}

#ai-chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ai-chat-typing::after {
  content: '';
  display: inline-block;
  width: 3px;
  height: 14px;
  background: #555;
  margin-left: 2px;
  animation: ai-chat-blink 0.8s infinite;
  vertical-align: text-bottom;
}

@keyframes ai-chat-blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* Markdown content styles */
.ai-chat-msg-assistant .ai-chat-msg-content p {
  margin: 0 0 8px 0;
}

.ai-chat-msg-assistant .ai-chat-msg-content p:last-child {
  margin-bottom: 0;
}

.ai-chat-msg-assistant .ai-chat-msg-content code {
  background: #e5e7eb;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 13px;
  font-family: 'JetBrains Mono', Consolas, monospace;
}

.ai-chat-msg-assistant .ai-chat-msg-content pre {
  background: #1e1e2e;
  color: #e0e0e0;
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 13px;
  line-height: 1.5;
}

.ai-chat-msg-assistant .ai-chat-msg-content pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.ai-chat-msg-assistant .ai-chat-msg-content ul,
.ai-chat-msg-assistant .ai-chat-msg-content ol {
  margin: 4px 0;
  padding-left: 20px;
}

.ai-chat-msg-assistant .ai-chat-msg-content li {
  margin: 2px 0;
}

.ai-chat-msg-assistant .ai-chat-msg-content blockquote {
  border-left: 3px solid #d1d5db;
  margin: 6px 0;
  padding: 2px 10px;
  color: #6b7280;
}

.ai-chat-msg-assistant .ai-chat-msg-content strong {
  font-weight: 600;
}

.ai-chat-msg-assistant .ai-chat-msg-content a {
  color: #4f46e5;
  text-decoration: underline;
}

.ai-chat-msg-assistant .ai-chat-msg-content h1,
.ai-chat-msg-assistant .ai-chat-msg-content h2,
.ai-chat-msg-assistant .ai-chat-msg-content h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 8px 0 4px 0;
}

/* Dark theme */
[data-theme="dark"] #ai-chat-window {
  background: #1a1a2e;
  border-color: #2a2a40;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .ai-chat-header {
  background: #111;
}

[data-theme="dark"] .ai-chat-msg-user .ai-chat-msg-content {
  background: #333;
}

[data-theme="dark"] .ai-chat-msg-assistant .ai-chat-msg-content {
  background: #242440;
  color: #e0e0e0;
}

[data-theme="dark"] .ai-chat-msg-assistant .ai-chat-msg-content code {
  background: #333350;
}

[data-theme="dark"] .ai-chat-msg-assistant .ai-chat-msg-content blockquote {
  border-left-color: #4b5563;
  color: #9ca3af;
}

[data-theme="dark"] .ai-chat-msg-assistant .ai-chat-msg-content a {
  color: #818cf8;
}

[data-theme="dark"] .ai-chat-input-area {
  border-top-color: #2a2a40;
}

[data-theme="dark"] #ai-chat-input {
  background: #242440;
  border-color: #2a2a40;
  color: #e0e0e0;
}

[data-theme="dark"] #ai-chat-input::placeholder {
  color: #6b7280;
}

[data-theme="dark"] #ai-chat-send {
  background: #333;
}

[data-theme="dark"] #ai-chat-messages::-webkit-scrollbar-thumb {
  background: #4b5563;
}

[data-theme="dark"] .ai-chat-welcome {
  color: #6b7280;
}

/* Mobile */
@media (max-width: 768px) {
  #ai-chat-window {
    width: calc(100vw - 16px);
    height: 60vh;
    right: 8px;
    bottom: 72px;
    border-radius: 10px;
  }
}
