/* ============================================
   AI Tool Interactive Demo Playground
   Live "Try It" zones on homepage AI tools section
   ============================================ */

/* --- Playground Container --- */
.ai-demo-playground {
  position: relative;
  margin-top: 16px;
  border-radius: 12px;
  background: var(--bg-primary);
  border: 1.5px solid var(--border-color);
  overflow: hidden;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.ai-demo-playground:hover,
.ai-demo-playground:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb, 37, 99, 235), 0.1);
}

/* --- Playground Header with animated tooltip --- */
.ai-demo-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: linear-gradient(135deg, rgba(var(--color-primary-rgb, 37, 99, 235), 0.06), rgba(124, 58, 237, 0.04));
  border-bottom: 1px solid var(--border-color);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-primary);
}

.ai-demo-header .demo-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-success, #10b981);
  animation: demoPulse 2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes demoPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.4); }
}

/* Pointing hand animation */
.ai-demo-header .demo-hand {
  display: inline-block;
  animation: demoPoint 2s ease-in-out infinite;
  font-size: 1rem;
}

@keyframes demoPoint {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(4px); }
}

/* --- Sample Text Area --- */
.ai-demo-text {
  padding: 16px;
  font-size: 0.92rem;
  line-height: 1.75;
  color: var(--text-primary);
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: none;
  min-height: 60px;
  position: relative;
}

[dir="rtl"] .ai-demo-text {
  direction: rtl;
  text-align: right;
}

.ai-demo-text::selection,
.ai-demo-text *::selection {
  background: rgba(var(--color-primary-rgb, 37, 99, 235), 0.25);
}

/* --- Chat Demo: Mini Input --- */
.ai-demo-chat-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-secondary, #f9fafb);
}

.ai-demo-chat-input input {
  flex: 1;
  padding: 8px 12px;
  border: 1.5px solid var(--border-color);
  border-radius: 20px;
  font-size: 0.85rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
}

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

.ai-demo-chat-input button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, background 0.2s;
  flex-shrink: 0;
}

.ai-demo-chat-input button:hover {
  transform: scale(1.08);
  background: var(--color-primary-dark, #1d4ed8);
}

[dir="rtl"] .ai-demo-chat-input button svg {
  transform: scaleX(-1);
}

/* --- Result Area --- */
.ai-demo-result {
  padding: 0 16px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease, padding 0.3s ease;
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--text-secondary);
  border-top: 0 solid transparent;
}

.ai-demo-result.active {
  max-height: 400px;
  padding: 14px 16px;
  border-top: 1px solid var(--border-color);
  overflow-y: auto;
}

[dir="rtl"] .ai-demo-result .demo-result-text {
  padding-left: 8px;
}

.ai-demo-result .demo-result-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-primary);
  margin-bottom: 6px;
}

.ai-demo-result .demo-result-text {
  white-space: pre-wrap;
  word-break: break-word;
  padding-inline: 4px;
}

/* Loading spinner inside result */
.ai-demo-result .demo-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.ai-demo-result .demo-loading .spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-color);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: demoSpin 0.7s linear infinite;
}

@keyframes demoSpin {
  to { transform: rotate(360deg); }
}

/* --- Listen Demo: Play Button --- */
.ai-demo-listen-btn,
.ai-demo-apply-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 8px 16px;
  border-radius: 20px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.ai-demo-listen-btn:hover,
.ai-demo-apply-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.ai-demo-listen-btn.playing {
  background: linear-gradient(135deg, #ef4444, #f97316);
}

/* --- Upgrade CTA inside result --- */
.ai-demo-upgrade {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(var(--color-primary-rgb, 37, 99, 235), 0.08);
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.ai-demo-upgrade a {
  color: var(--color-primary);
  font-weight: 600;
  text-decoration: none;
}

.ai-demo-upgrade a:hover {
  text-decoration: underline;
}

/* --- Dark mode --- */
[data-theme="dark"] .ai-demo-playground {
  background: var(--bg-secondary, #1e293b);
}

[data-theme="dark"] .ai-demo-header {
  background: rgba(59, 130, 246, 0.08);
}

[data-theme="dark"] .ai-demo-chat-input {
  background: var(--bg-tertiary, #334155);
}

/* --- Mobile --- */
@media (max-width: 767px) {
  .ai-demo-playground {
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
  }
  .ai-demo-text {
    font-size: 0.85rem;
    padding: 12px;
    word-break: break-word;
    overflow-wrap: break-word;
  }
  .ai-demo-header {
    font-size: 0.78rem;
    padding: 8px 12px;
  }
  .ai-demo-chat-input {
    padding: 8px 10px;
    max-width: 100%;
    box-sizing: border-box;
  }
  .ai-demo-chat-input input {
    min-width: 0;
    width: 0;
  }
  .ai-demo-result.active {
    word-break: break-word;
    overflow-wrap: break-word;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .ai-demo-header .demo-pulse,
  .ai-demo-header .demo-hand {
    animation: none;
  }
}
