#ai-chat-widget {
  --ai-chat-accent: #0f766e;
  --ai-chat-accent-contrast: #ffffff;
  --ai-chat-surface: #ffffff;
  --ai-chat-surface-alt: #f1f5f4;
  --ai-chat-text: #111827;
  --ai-chat-text-muted: #6b7280;
  --ai-chat-border: #e5e7eb;
  --ai-chat-error-bg: #fef2f2;
  --ai-chat-error-text: #991b1b;
  --ai-chat-radius: 16px;

  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1000;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ai-chat-text);
}

#ai-chat-widget * {
  box-sizing: border-box;
}

.ai-chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--ai-chat-accent);
  color: var(--ai-chat-accent-contrast);
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}
.ai-chat-toggle:hover {
  transform: scale(1.05);
}
.ai-chat-toggle:focus-visible {
  outline: 2px solid var(--ai-chat-accent);
  outline-offset: 3px;
}

.ai-chat-panel {
  position: absolute;
  right: 0;
  bottom: 68px;
  width: 340px;
  max-width: calc(100vw - 40px);
  height: 440px;
  max-height: calc(100vh - 120px);
  background: var(--ai-chat-surface);
  border-radius: var(--ai-chat-radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transition: opacity 0.15s ease, transform 0.15s ease, width 0.15s ease, height 0.15s ease;
}
.ai-chat-panel[hidden] {
  display: flex;
  opacity: 0;
  transform: scale(0.96) translateY(8px);
  pointer-events: none;
}
.ai-chat-panel--expanded {
  width: 480px;
  height: 640px;
  max-height: calc(100vh - 80px);
}
@media (prefers-reduced-motion: reduce) {
  .ai-chat-panel,
  .ai-chat-toggle {
    transition: none;
  }
}

.ai-chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--ai-chat-accent);
  color: var(--ai-chat-accent-contrast);
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}
.ai-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.ai-chat-close,
.ai-chat-expand {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ai-chat-close {
  font-size: 20px;
  line-height: 1;
}
.ai-chat-close:focus-visible,
.ai-chat-expand:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--ai-chat-surface);
}

.ai-chat-msg {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
}
.ai-chat-msg a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-word;
}
.ai-chat-msg--user {
  align-self: flex-end;
  background: var(--ai-chat-accent);
  color: var(--ai-chat-accent-contrast);
  border-bottom-right-radius: 4px;
}
.ai-chat-msg--assistant {
  align-self: flex-start;
  background: var(--ai-chat-surface-alt);
  color: var(--ai-chat-text);
  border-bottom-left-radius: 4px;
}
.ai-chat-msg--assistant a {
  color: var(--ai-chat-accent);
}
.ai-chat-msg--error {
  align-self: flex-start;
  background: var(--ai-chat-error-bg);
  color: var(--ai-chat-error-text);
}
.ai-chat-msg--typing {
  color: var(--ai-chat-text-muted);
  font-style: italic;
}

.ai-chat-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--ai-chat-border);
  flex-shrink: 0;
}
.ai-chat-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--ai-chat-border);
  border-radius: 20px;
  padding: 9px 14px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
.ai-chat-input:focus-visible {
  border-color: var(--ai-chat-accent);
}
.ai-chat-form button {
  padding: 0 18px;
  border: none;
  border-radius: 20px;
  background: var(--ai-chat-accent);
  color: var(--ai-chat-accent-contrast);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}
.ai-chat-form button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

@media (max-width: 480px) {
  #ai-chat-widget {
    right: 12px;
    bottom: 12px;
  }
  .ai-chat-panel {
    width: calc(100vw - 24px);
  }
  .ai-chat-panel--expanded {
    width: calc(100vw - 24px);
    height: calc(100vh - 24px);
    max-height: calc(100vh - 24px);
  }
}
