/* AI Chat Widget */
.ai-chat-button {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0078d4, #0063b1);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  z-index: 999;
}

.ai-chat-button img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

.ai-chat-button:hover {
  transform: scale(1.1);
  background: linear-gradient(135deg, #1a86da, #0078d4);
}

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

.ai-chat-tooltip {
  position: fixed;
  bottom: 46px;
  right: 100px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  white-space: nowrap;
  z-index: 999;
}

.ai-chat-button:hover + .ai-chat-tooltip {
  opacity: 1;
}

.ai-chat-container {
  position: fixed;
  bottom: 100px;
  right: 30px;
  width: 400px;
  height: 520px;
  background: var(--nav-bg);
  backdrop-filter: var(--nav-blur);
  -webkit-backdrop-filter: var(--nav-blur);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.95);
  transform-origin: bottom right;
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.25s,
              transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 998;
}

.ai-chat-container.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Header */
.ai-chat-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.ai-chat-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}

.ai-chat-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
  animation: statusPulse 2s infinite;
}

.ai-chat-status-dot.thinking {
  background: var(--warning);
  animation: statusPulse 1s infinite;
}

.ai-chat-status-dot.offline {
  background: var(--text-muted);
  animation: none;
}

@keyframes statusPulse {
  0%, 100% { box-shadow: 0 0 0 0 currentColor; }
  50% { box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.1); }
}

.ai-chat-header-actions {
  display: flex;
  gap: 2px;
}

.ai-chat-action-btn {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  font-size: 14px;
}

.ai-chat-action-btn:hover {
  background: var(--bg-alt);
  color: var(--text);
}

/* Messages */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.ai-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--text-light);
}

/* Message bubbles */
.ai-message {
  padding: 12px 16px;
  max-width: 88%;
  position: relative;
}

.ai-message.user {
  background: var(--primary);
  color: white;
  align-self: flex-end;
  margin-left: auto;
  border-radius: 16px 16px 4px 16px;
  animation: messageSlideRight 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.ai-message.ai {
  background: var(--bg-alt);
  color: var(--text);
  align-self: flex-start;
  border-radius: 4px 16px 16px 16px;
  animation: messageSlideLeft 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.ai-message.error {
  background: var(--error-light);
  color: var(--error);
  border: 1px solid var(--error);
  border-radius: 4px 16px 16px 16px;
  animation: messageSlideLeft 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes messageSlideRight {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes messageSlideLeft {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}

/* AI avatar */
.ai-msg-avatar {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-bottom: 4px;
}

.ai-msg-avatar img {
  width: 16px;
  height: 16px;
  object-fit: contain;
}

/* Message content */
.ai-message ul {
  margin: 8px 0;
  padding-left: 20px;
}

.ai-message li {
  margin: 4px 0;
}

.ai-message a {
  color: inherit;
  text-decoration: underline;
}

.ai-message pre {
  background: var(--code-bg);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 13px;
}

.ai-message code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 13px;
}

.ai-message pre code {
  background: none;
  padding: 0;
  border-radius: 0;
}

/* Copy button */
.ai-msg-copy {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: all 0.15s;
  display: block;
  margin-top: 4px;
  margin-left: auto;
}

.ai-message:hover .ai-msg-copy {
  opacity: 1;
}

.ai-msg-copy:hover {
  background: var(--hover-bg);
  color: var(--text);
}

.ai-msg-copy.copied {
  color: var(--success);
  opacity: 1;
}

/* Timestamps */
.ai-msg-time {
  display: block;
  font-size: 10px;
  color: var(--text-light);
  margin-top: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.ai-message:hover .ai-msg-time {
  opacity: 1;
}

.ai-message.user .ai-msg-time {
  text-align: right;
  color: rgba(255, 255, 255, 0.6);
}

/* Retry button */
.ai-retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid currentColor;
  color: inherit;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  margin-top: 8px;
  transition: all 0.15s;
  opacity: 0.8;
}

.ai-retry-btn:hover {
  opacity: 1;
  background: rgba(220, 38, 38, 0.1);
}

/* Typing indicator */
.ai-typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px 0;
  align-items: center;
}

.ai-typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s ease-in-out infinite;
}

.ai-typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.ai-typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Welcome state */
.ai-chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 20px 16px;
  flex: 1;
}

.ai-welcome-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.ai-welcome-icon img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.ai-welcome-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.ai-welcome-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.5;
}

.ai-suggested-prompts {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.ai-prompt-chip {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s;
}

.ai-prompt-chip i {
  color: var(--primary);
  font-size: 12px;
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.ai-prompt-chip:hover {
  border-color: var(--primary);
  background: var(--hover-bg);
  transform: translateX(2px);
}

/* Captcha */
.ai-chat-captcha {
  padding: 40px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  animation: fadeSlideIn 0.3s ease;
}

.ai-chat-captcha.verified {
  animation: fadeSlideOut 0.3s ease forwards;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeSlideOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-10px); }
}

.captcha-message {
  text-align: center;
  margin-bottom: 30px;
}

.captcha-message i {
  font-size: 48px;
  color: var(--primary);
  margin-bottom: 16px;
  display: block;
}

.captcha-message h3 {
  font-size: 20px;
  margin-bottom: 8px;
  color: var(--text);
}

.captcha-message p {
  color: var(--text-muted);
  font-size: 14px;
}

.captcha-error {
  margin-top: 16px;
  padding: 12px 20px;
  background: var(--error-light);
  color: var(--error);
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
}

.cf-turnstile {
  margin: 0 auto;
}

/* Input area */
.ai-chat-input-wrap {
  border-top: 1px solid var(--border);
}

.ai-chat-input {
  padding: 12px 16px 0;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.ai-chat-input textarea {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
  resize: none;
  overflow-y: auto;
  max-height: 120px;
  min-height: 40px;
  transition: border-color 0.2s;
  scrollbar-width: thin;
}

.ai-chat-input textarea:focus {
  border-color: var(--primary);
}

.ai-chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  opacity: 0.4;
  pointer-events: none;
}

.ai-chat-send-btn.active {
  opacity: 1;
  pointer-events: auto;
}

.ai-chat-send-btn.active:hover {
  background: var(--primary-hover);
  transform: scale(1.1);
}

.ai-chat-send-btn:active {
  transform: scale(0.9);
}

.ai-chat-send-btn.sending {
  animation: sendPulse 0.4s ease;
}

@keyframes sendPulse {
  0% { transform: scale(1); }
  30% { transform: scale(0.85); }
  60% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* Keyboard hint */
.ai-input-hint {
  padding: 4px 16px 8px;
  font-size: 11px;
  color: var(--text-light);
  display: none;
}

.ai-chat-input:focus-within ~ .ai-input-hint {
  display: block;
}

.ai-input-hint kbd {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 10px;
}

.ai-hint-sep {
  margin: 0 4px;
}


/* Utilities */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.mb-2 { margin-bottom: 20px; }
.mb-4 { margin-bottom: 40px; }

/* Loading */
.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  padding: 40px;
  color: var(--text-muted);
  min-height: 100px; /* Reserve space to prevent CLS */
}

.loading.loading-top {
  margin-bottom: 2rem;
}

.loading.loading-bottom {
  margin-top: 2rem;
}

/* Page separator (hidden but helps with tracking) */
.page-separator {
  height: 0;
  visibility: hidden;
  margin: 0;
  padding: 0;
}

/* Scroll to top */
.scroll-top {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 48px;
  height: 48px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
  z-index: 100;
}

.scroll-top.show {
  opacity: 1;
  visibility: visible;
}

.scroll-top:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
}

/* Mobile Menu */
.mobile-menu {
  position: fixed;
  top: 0;
  right: -300px;
  width: 300px;
  height: 100vh;
  background: var(--card-bg);
  border-left: 1px solid var(--border);
  transition: right 0.3s;
  z-index: 200;
  overflow-y: auto;
}

.mobile-menu.active {
  right: 0;
}

.mobile-menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.mobile-menu-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text);
  cursor: pointer;
}

.mobile-menu-links {
  padding: 20px;
}

.mobile-menu-links > a {
  display: block;
  padding: 15px 0;
  color: var(--text);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
}

.mobile-menu-section {
  margin: 20px 0;
}

.mobile-menu-section h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.mobile-menu-section a {
  display: block;
  padding: 10px 0 10px 15px;
  color: var(--text);
  font-size: 14px;
  border-bottom: none;
}

.mobile-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
  z-index: 190;
}

.mobile-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Responsive */
@media (max-width: 768px) {
  /* Hide desktop dropdowns on mobile */
  .nav-dropdown {
    display: none;
  }
  .nav-links {
    display: none;
  }
  
  .nav-mobile {
    display: block;
  }
  
  .hero {
    padding: 40px 0;
  }
  
  .articles-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  .footer-content {
    grid-template-columns: 1fr;
    gap: 30px;
  }
  
  .scroll-top {
    bottom: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
  
  /* AI Chat mobile styles */
  .ai-chat-container {
    width: 100vw;
    height: calc(100dvh - 60px);
    right: 0;
    bottom: 0;
    border-radius: 16px 16px 0 0;
    transform-origin: bottom center;
  }

  .ai-chat-button {
    right: 16px;
    bottom: 16px;
    width: 52px;
    height: 52px;
    font-size: 20px;
  }

  .ai-chat-tooltip {
    display: none;
  }

  .ai-prompt-chip {
    font-size: 14px;
    padding: 12px 14px;
  }

  .ai-input-hint {
    display: none !important;
  }

  /* Adjust scroll-top button position when AI chat is present */
  .scroll-top {
    bottom: 80px;
  }
}

