/* Scope Tailwind base styles to prevent affecting host page */
#linkflow-chat-tw-scope {
  @tailwind base;
}

@tailwind components;
@tailwind utilities;

/* Custom styles for LinkFlow Chat */
.linkflow-chat-widget {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Chat widget specific styles */
.chat-widget {
  /* Container for chat components - positioning handled by individual components */
}

/* Ensure proper z-index layering */
.chat-widget button {
  z-index: 50;
}

.chat-widget .chat-window {
  z-index: 40;
}

/* Custom scrollbar styles */
.scrollbar-thin {
  scrollbar-width: thin;
}

.scrollbar-thin::-webkit-scrollbar {
  width: 6px;
}

.scrollbar-thin::-webkit-scrollbar-track {
  @apply lfc-bg-gray-100 lfc-rounded-full;
}

.scrollbar-thin::-webkit-scrollbar-thumb {
  @apply lfc-bg-gray-300 lfc-rounded-full;
}

.scrollbar-thin::-webkit-scrollbar-thumb:hover {
  @apply lfc-bg-gray-400;
}

.message-bubble {
  @apply lfc-rounded-lg lfc-px-3 lfc-py-2 lfc-max-w-xs lfc-break-words;
}

.message-user {
  @apply lfc-bg-primary-500 lfc-text-white lfc-ml-auto;
}

.message-ai {
  @apply lfc-bg-gray-100 lfc-text-gray-800;
}

.message-system {
  @apply lfc-bg-yellow-50 lfc-text-yellow-800 lfc-border lfc-border-yellow-200;
}

/* Block-specific styles */
.linkflow-chat-block {
  position: relative;
  z-index: 9999;
}

/* Position classes for blocks */
.ai-cs-position-bottom-right {
  position: fixed;
  bottom: 20px;
  right: 20px;
}

.ai-cs-position-bottom-left {
  position: fixed;
  bottom: 20px;
  left: 20px;
}

.ai-cs-position-top-right {
  position: fixed;
  top: 20px;
  right: 20px;
}

.ai-cs-position-top-left {
  position: fixed;
  top: 20px;
  left: 20px;
}

.ai-cs-position-center {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* Size classes for blocks */
.ai-cs-size-small .ai-cs-chat-button {
  width: 50px;
  height: 50px;
  font-size: 18px;
}

.ai-cs-size-medium .ai-cs-chat-button {
  width: 60px;
  height: 60px;
  font-size: 22px;
}

.ai-cs-size-large .ai-cs-chat-button {
  width: 70px;
  height: 70px;
  font-size: 26px;
}

/* Chat button base styles for blocks */
.ai-cs-chat-button {
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;
  background-color: var(--ai-cs-primary-color, #007cba);
  color: var(--ai-cs-secondary-color, #ffffff);
}

.ai-cs-chat-button:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.ai-cs-chat-button:active {
  transform: scale(0.95);
}

/* Responsive visibility for blocks */
@media (max-width: 768px) {
  .ai-cs-hide-mobile {
    display: none !important;
  }
}

@media (min-width: 769px) {
  .ai-cs-hide-desktop {
    display: none !important;
  }
}

/* No animation class for blocks */
.ai-cs-no-animation .ai-cs-chat-button,
.ai-cs-no-animation .ai-cs-chat-window {
  transition: none !important;
  animation: none !important;
  transform: none !important;
}

.ai-cs-no-animation .ai-cs-chat-button:hover {
  transform: none !important;
}

/* Design tokens: CSS variables to support runtime theming */
:root {
  /* Brand */
  --ai-primary-50: 239 246 255;
  --ai-primary-100: 219 234 254;
  --ai-primary-200: 191 219 254;
  --ai-primary-300: 147 197 253;
  --ai-primary-400: 96 165 250;
  --ai-primary-500: 59 130 246;
  --ai-primary-600: 37 99 235;
  --ai-primary-700: 29 78 216;
  --ai-primary-800: 30 64 175;
  --ai-primary-900: 30 58 138;

  /* Text */
  --ai-text-primary: 17 24 39; /* #111827 */
  --ai-text-secondary: 107 114 128; /* #6B7280 */
  --ai-text-tertiary: 156 163 175; /* #9CA3AF */
  --ai-text-disabled: 156 163 175; /* #9CA3AF */

  /* Background */
  --ai-bg-base: 255 255 255;
  --ai-bg-layer: 249 250 251; /* #F9FAFB */
  --ai-bg-overlay: 255 255 255;
  --ai-bg-accent: 239 246 255; /* brand tint */
  --ai-bg-muted: 243 244 246; /* #F3F4F6 */

  /* Border & Focus */
  --ai-border-subtle: 229 231 235; /* #E5E7EB */
  --ai-border-strong: 209 213 219; /* #D1D5DB */
  --ai-focus: 147 197 253; /* #93C5FD */

  /* States */
  --ai-success-bg: 236 253 245; /* #ECFDF5 */
  --ai-success-text: 6 95 70; /* #065F46 */
  --ai-success-border: 167 243 208; /* #A7F3D0 */
  --ai-warning-bg: 255 251 235; /* #FFFBEB */
  --ai-warning-text: 133 77 14; /* #854D0E */
  --ai-warning-border: 253 230 138; /* #FDE68A */
  --ai-danger-bg: 254 242 242; /* #FEF2F2 */
  --ai-danger-text: 153 27 27; /* #991B1B */
  --ai-danger-border: 252 165 165; /* #FCA5A5 */
  --ai-info-bg: 239 246 255; /* #EFF6FF */
  --ai-info-text: 30 64 175; /* #1E40AF */
  --ai-info-border: 191 219 254; /* #BFDBFE */

  /* Button legacy fallback variables used by blocks */
  --ai-cs-primary-color: rgb(var(--ai-primary-500));
  --ai-cs-secondary-color: 255 255 255;
}

/* Chat message content: robust wrapping for long URLs and CJK text */
.ai-cs-message-content {
  /* Prefer breaking anywhere to avoid overflow from long URLs */
  overflow-wrap: anywhere;
  /* Fallback for older engines */
  word-break: break-word;
  word-wrap: break-word;
  /* Ensure flex children can shrink */
  min-width: 0;
}

/* Utility mappings using semantic tokens */
.text-primary-token { color: rgb(var(--ai-text-primary)); }
.text-secondary-token { color: rgb(var(--ai-text-secondary)); }
.bg-base-token { background-color: rgb(var(--ai-bg-base)); }
.bg-layer-token { background-color: rgb(var(--ai-bg-layer)); }
.border-subtle-token { border-color: rgb(var(--ai-border-subtle)); }
.ring-focus-token { --tw-ring-color: rgb(var(--ai-focus)); }