/*
 * AI LIFE - Interactive Chatbot Interface
 * Virtual Assistant Consultant untuk bahar.id
 * v4.2 - Premium UX: GPU acceleration, skeleton loader, rAF typewriter
 */

/* ============================================
   AI CHAT WRAPPER & CONTAINER
   ============================================ */

.ai-chat-wrapper {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 12px 40px;
}

.ai-chat-container {
  display: flex;
  flex-direction: column;
  height: 520px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid #333;
  background: #1a1a1a;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* ============================================
   CHAT HEADER
   ============================================ */

.ai-chat-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  background: #151515;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

/* Clear Chat / New Chat Button */
.clear-chat-btn {
  margin-left: auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid #3a3a3a;
  background: transparent;
  color: #888;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.clear-chat-btn:hover {
  border-color: #ffb400;
  color: #ffb400;
  background: rgba(255, 180, 0, 0.08);
  transform: rotate(90deg);
}

.clear-chat-btn:active {
  transform: rotate(180deg) scale(0.9);
}

.ai-chat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  border: 2px solid #ffb400;
}

.ai-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ai-chat-header-info {
  margin-left: 14px;
}

.ai-chat-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
}

.ai-chat-status {
  font-size: 12px;
  color: #aaa;
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf50;
  display: inline-block;
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ============================================
   CHAT BODY — GPU Isolated Rendering (v4.2)
   ============================================ */

.ai-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  /* GPU isolation: prevent layout thrashing from bubbles affecting page */
  contain: layout style;
  will-change: scroll-position;
}

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

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

.ai-chat-body::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 3px;
}

.ai-chat-body::-webkit-scrollbar-thumb:hover {
  background: #666;
}

/* ============================================
   CHAT MESSAGES & BUBBLES
   ============================================ */

.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: fadeInUp 0.3s ease;
  /* GPU compositing layer for smooth animation */
  transform: translateZ(0);
  will-change: transform, opacity;
}

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

/* AI Message - Left aligned */
.ai-message {
  align-self: flex-start;
}

.ai-message .chat-bubble {
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 4px 16px 16px 16px;
  color: #eee;
}

/* User Message - Right aligned */
.user-message {
  align-self: flex-end;
}

.user-message .chat-bubble {
  background: #ffb400;
  border-radius: 16px 4px 16px 16px;
  color: #111;
}

.chat-bubble {
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
}

.chat-bubble p {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.6;
}

.chat-bubble p:last-child {
  margin-bottom: 0;
}

.chat-bubble strong {
  font-weight: 700;
}

.chat-time {
  font-size: 11px;
  color: #666;
  margin-top: 4px;
  padding: 0 4px;
}

.user-message .chat-time {
  text-align: right;
}

/* ============================================
   RICH MEDIA IN CHAT BUBBLES
   ============================================ */

.chat-bubble ul {
  margin: 8px 0;
  padding-left: 18px;
}

.chat-bubble ul li {
  margin-bottom: 4px;
  font-size: 14px;
  line-height: 1.5;
}

.chat-bubble a {
  color: #ffb400;
  text-decoration: underline;
  transition: opacity 0.2s;
}

.chat-bubble a:hover {
  opacity: 0.8;
}

.user-message .chat-bubble a {
  color: #111;
  font-weight: 700;
}

/* ============================================
   TYPEWRITER CURSOR
   ============================================ */

.typewriter-cursor {
  display: inline-block;
  width: 2px;
  height: 14px;
  background: #ffb400;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink-cursor 0.7s infinite;
}

@keyframes blink-cursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ============================================
   TYPING INDICATOR (Enhanced v4.1)
   ============================================ */

.typing-indicator-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 4px 16px 16px 16px;
  width: fit-content;
  animation: fadeInUp 0.3s ease;
}

.typing-indicator-dots {
  display: flex;
  align-items: center;
  gap: 4px;
}

.typing-indicator-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffb400;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-indicator-dots span:nth-child(1) { animation-delay: 0s; }
.typing-indicator-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator-dots span:nth-child(3) { animation-delay: 0.4s; }

.typing-indicator-text {
  font-size: 12px;
  color: #888;
  font-style: italic;
  white-space: nowrap;
  animation: typingTextPulse 2s infinite ease-in-out;
}

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

@keyframes typingTextPulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

/* Legacy support for old typing-indicator class */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 4px 16px 16px 16px;
  width: fit-content;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffb400;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

/* ============================================
   SUGGESTED PROMPTS (Dynamic)
   ============================================ */

.ai-chat-suggestions {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid #2a2a2a;
  flex-shrink: 0;
  transition: all 0.3s ease;
}

.suggestion-btn {
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  color: #ccc;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-family: 'Lato', sans-serif;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.suggestion-btn:hover {
  background: #3a3a3a;
  border-color: #ffb400;
  color: #fff;
  transform: translateY(-1px);
}

.suggestion-btn:active {
  transform: translateY(0);
}

/* ============================================
   CHAT INPUT AREA
   ============================================ */

.ai-chat-input-area {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: #151515;
  border-top: 1px solid #333;
  gap: 10px;
  flex-shrink: 0;
}

.ai-chat-input {
  flex: 1;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 24px;
  padding: 12px 18px;
  font-size: 14px;
  font-family: 'Lato', sans-serif;
  color: #eee;
  outline: none;
  transition: border-color 0.2s ease;
  height: auto;
  margin: 0;
  box-sizing: border-box;
}

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

.ai-chat-input::placeholder {
  color: #666;
}

.ai-chat-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: #ffb400;
  color: #111;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.ai-chat-send-btn:hover {
  transform: scale(1.05);
  opacity: 0.9;
}

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

.ai-chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ============================================
   LEAD GENERATION FORM (In-Chat)
   ============================================ */

.chat-lead-form {
  background: #1e1e1e;
  border: 1px solid #ffb400;
  border-radius: 12px;
  padding: 16px;
  margin-top: 8px;
}

.chat-lead-form h6 {
  color: #ffb400;
  font-size: 13px;
  font-weight: 700;
  margin: 0 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chat-lead-form .lead-field {
  margin-bottom: 10px;
}

.chat-lead-form .lead-field input,
.chat-lead-form .lead-field textarea {
  width: 100%;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  font-family: 'Lato', sans-serif;
  color: #eee;
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.2s;
}

.chat-lead-form .lead-field input:focus,
.chat-lead-form .lead-field textarea:focus {
  border-color: #ffb400;
}

.chat-lead-form .lead-field textarea {
  resize: vertical;
  min-height: 60px;
  max-height: 120px;
}

.chat-lead-form .lead-field input::placeholder,
.chat-lead-form .lead-field textarea::placeholder {
  color: #666;
}

.chat-lead-form .lead-submit-btn {
  width: 100%;
  background: #ffb400;
  color: #111;
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-size: 13px;
  font-weight: 700;
  font-family: 'Lato', sans-serif;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chat-lead-form .lead-submit-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.chat-lead-form .lead-submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ============================================
   RATE LIMIT ERROR & LINKEDIN BUTTON
   ============================================ */

.chat-rate-limit {
  text-align: center;
  padding: 8px 0;
}

.chat-rate-limit .linkedin-btn {
  display: inline-block;
  background: #0077b5;
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  margin-top: 8px;
  transition: all 0.2s;
}

.chat-rate-limit .linkedin-btn:hover {
  background: #005f8f;
  transform: translateY(-1px);
}

.chat-rate-limit .linkedin-btn i {
  margin-right: 6px;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media only screen and (max-width: 992px) {
  .ai-chat-wrapper {
    padding: 0 8px 30px;
  }

  .ai-chat-container {
    height: 480px;
    border-radius: 12px;
  }

  .chat-message {
    max-width: 88%;
  }

  .ai-chat-suggestions {
    padding: 10px 14px;
    gap: 6px;
  }

  .suggestion-btn {
    font-size: 11px;
    padding: 6px 12px;
  }
}

@media only screen and (max-width: 600px) {
  .ai-chat-container {
    height: calc(100vh - 200px);
    min-height: 400px;
    max-height: 560px;
    border-radius: 10px;
  }

  .ai-chat-header {
    padding: 12px 14px;
  }

  .ai-chat-avatar {
    width: 36px;
    height: 36px;
  }

  .ai-chat-title {
    font-size: 14px;
  }

  .ai-chat-body {
    padding: 14px;
    gap: 12px;
  }

  .chat-bubble {
    padding: 10px 14px;
    font-size: 13px;
  }

  .chat-bubble p {
    font-size: 13px;
  }

  .chat-message {
    max-width: 92%;
  }

  .ai-chat-suggestions {
    padding: 8px 12px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .suggestion-btn {
    flex-shrink: 0;
    font-size: 11px;
    padding: 6px 10px;
  }

  .ai-chat-input-area {
    padding: 10px 12px;
    gap: 8px;
  }

  .ai-chat-input {
    padding: 10px 14px;
    font-size: 13px;
  }

  .ai-chat-send-btn {
    width: 38px;
    height: 38px;
    font-size: 14px;
  }

  .chat-lead-form {
    padding: 12px;
  }

  .chat-lead-form .lead-field input,
  .chat-lead-form .lead-field textarea {
    padding: 8px 10px;
    font-size: 12px;
  }
}

/* ============================================
   DARK MODE OVERRIDES (body.dark)
   ============================================ */

body.dark .ai-chat-container {
  background: #1a1a1a;
  border-color: #333;
}

body.dark .ai-chat-header {
  background: #151515;
}

body.dark .ai-chat-body {
  background: #1a1a1a;
}

body.dark .ai-message .chat-bubble {
  background: #2a2a2a;
  border-color: #3a3a3a;
}

body.dark .ai-chat-input {
  background: #2a2a2a;
  border-color: #3a3a3a;
  color: #eee;
}

body.dark .ai-chat-input:focus {
  border-color: #ffb400;
}

/* ============================================
   SECTION POSITIONING
   ============================================ */

#bl-ai-life-section {
  /* Inherits positioning from .bl-main > section:nth-child(3) */
}

/* ============================================
   PROFILE PICTURE RESPONSIVE (v4.2)
   ============================================ */

.profile-picture .my-picture {
  width: 100%;
  height: auto;
  max-height: 400px;
  object-fit: cover;
  object-position: top center;
  border-radius: 8px;
  background-color: #2a2a2a;
}

/* ============================================
   CLEAR CHAT CONFIRMATION (v4.2)
   ============================================ */

.clear-chat-confirm {
  align-self: center;
  background: #1e1e1e;
  border: 1px solid #444;
  border-radius: 12px;
  padding: 16px 20px;
  text-align: center;
  animation: fadeInUp 0.25s ease;
  max-width: 240px;
}

.clear-chat-confirm p {
  margin: 0 0 12px;
  font-size: 13px;
  color: #ccc;
  font-weight: 600;
}

.clear-chat-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.clear-confirm-yes,
.clear-confirm-no {
  padding: 7px 16px;
  border-radius: 18px;
  font-size: 12px;
  font-family: 'Lato', sans-serif;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.clear-confirm-yes {
  background: #ffb400;
  color: #111;
}

.clear-confirm-yes:hover {
  background: #e6a200;
  transform: translateY(-1px);
}

.clear-confirm-no {
  background: transparent;
  border: 1px solid #555;
  color: #999;
}

.clear-confirm-no:hover {
  border-color: #888;
  color: #fff;
}

/* ============================================
   SHIMMERING SKELETON LOADER (v4.2 Premium)
   ============================================ */

.skeleton-loader {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 18px;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 4px 16px 16px 16px;
  width: 70%;
  max-width: 280px;
  animation: fadeInUp 0.3s ease;
  transform: translateZ(0);
}

.skeleton-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(
    90deg,
    #333 0%,
    #444 20%,
    #555 40%,
    #444 60%,
    #333 80%,
    #333 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton-line:nth-child(1) { width: 92%; }
.skeleton-line:nth-child(2) { width: 78%; animation-delay: 0.15s; }
.skeleton-line:nth-child(3) { width: 60%; animation-delay: 0.3s; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Skeleton fade-out transition */
.skeleton-loader.skeleton-exit {
  opacity: 0;
  transform: translateY(-4px) translateZ(0);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* ============================================
   PERSONA SWITCH INDICATOR (v4.0)
   ============================================ */

.chat-persona-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  animation: fadeInUp 0.4s ease;
}

.persona-indicator-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, transparent, #444, transparent);
}

.persona-indicator-text {
  font-size: 11px;
  color: #888;
  white-space: nowrap;
  padding: 4px 12px;
  background: #222;
  border-radius: 12px;
  border: 1px solid #333;
  letter-spacing: 0.3px;
}

.persona-indicator-text strong {
  color: #ffb400;
  font-weight: 700;
}

/* Subtle avatar pulse on persona switch */
.ai-chat-avatar.persona-switching {
  animation: avatarPulse 0.6s ease;
}

@keyframes avatarPulse {
  0% { transform: scale(1); border-color: #ffb400; }
  50% { transform: scale(1.1); border-color: #fff; }
  100% { transform: scale(1); border-color: #ffb400; }
}
