/**
 * ============================================================================
 * PPA GUIDE CHAT WIDGET STYLES
 * ============================================================================
 *
 * Modern, clean chat interface with dark mode support
 * ============================================================================
 */

/* Chat Widget Container */
.ppa-chat-widget {
  position: fixed !important;
  bottom: 110px !important;
  right: 30px !important;
  width: 400px;
  height: 600px;
  max-height: calc(100vh - 130px);
  background: var(--background);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  z-index: 19998 !important;
  overflow: hidden;
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
}

/* Chat Header */
.ppa-chat-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.ppa-chat-header-content {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.ppa-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  color: white;
  flex-shrink: 0;
}

.ppa-chat-title h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
  color: white;
}

.ppa-chat-status {
  font-size: 0.8125rem;
  margin: 0;
  opacity: 0.9;
  color: white;
}

/* Header Actions Container */
.ppa-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Fullscreen Button */
.ppa-chat-fullscreen {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-size: 14px;
}

.ppa-chat-fullscreen:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

/* Close Button */
.ppa-chat-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.ppa-chat-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.ppa-welcome-message i {
  margin-right: 6px;
  color: var(--text-dark);
}

.ppa-guardrail {
  font-size: 0.8rem;
  opacity: 0.8;
}

/* Messages Container */
.ppa-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--background-dark);
  color: var(--text-dark);
}

/* Custom scrollbar */
.ppa-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.ppa-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.ppa-chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

.ppa-chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--text-light);
}

/* Welcome Message */
.ppa-chat-welcome {
  display: flex;
  gap: 0.75rem;
  background: var(--background);
  padding: 1rem;
  border-radius: 12px;
  border-left: 4px solid #667eea;
}

.ppa-welcome-message p {
  margin: 0 0 0.5rem 0;
  color: var(--text-dark);
  font-size: 0.9375rem;
  line-height: 1.5;
  
}

.ppa-welcome-message p:last-child {
  margin-bottom: 0;
}

.ppa-welcome-message small {
  font-size: 0.8125rem;
  color: var(--text-light);
}

/* Chat Messages */
.ppa-chat-message {
  display: flex;
  gap: 0.75rem;
  animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ppa-chat-message-user {
  justify-content: flex-end;
}

.ppa-chat-message-assistant {
  justify-content: flex-start;
}

.ppa-message-content {
  max-width: 75%;
  padding: 0.875rem 1rem;
  border-radius: 12px;
  font-size: 0.9375rem;
  line-height: 1.5;
}

.ppa-chat-message-user .ppa-message-content {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.ppa-chat-message-assistant .ppa-message-content {
  background: var(--background);
  color: var(--text-dark);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-color);
}

.ppa-message-content p {
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Error Message */
.ppa-message-error {
  background: #fef2f2 !important;
  color: #dc2626 !important;
  border: 1px solid #fecaca !important;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

[data-theme="dark"] .ppa-message-error {
  background: rgba(220, 38, 38, 0.1) !important;
  color: #fca5a5 !important;
  border-color: rgba(220, 38, 38, 0.3) !important;
}

.ppa-message-error i {
  margin-top: 2px;
  flex-shrink: 0;
}

/* Typing Indicator */
.ppa-typing-indicator .ppa-message-content {
  padding: 0.75rem 1rem;
}

.ppa-typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.ppa-typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-light);
  animation: typingBounce 1.4s ease-in-out infinite;
}

.ppa-typing-dots span:nth-child(1) {
  animation-delay: 0s;
}

.ppa-typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.ppa-typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-8px);
  }
}

/* Input Wrapper */
.ppa-chat-input-wrapper {
  padding: 1rem;
  background: var(--background);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.ppa-chat-input-container {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.ppa-chat-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border-color);
  border-radius: 24px;
  font-size: 0.9375rem;
  background: var(--background-alt);
  color: var(--text-dark);
  transition: all 0.2s ease;
  font-family: var(--font-family);
}

.ppa-chat-input:focus {
  outline: none;
  border-color: #667eea;
  background: var(--background);
}

.ppa-chat-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ppa-chat-input::placeholder {
  color: var(--text-light);
}

.ppa-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.ppa-chat-send:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.ppa-chat-send:active {
  transform: scale(1);
}

.ppa-chat-send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Dark Mode */
[data-theme="dark"] .ppa-chat-widget {
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .ppa-chat-header {
  background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
}

[data-theme="dark"] .ppa-chat-message-user .ppa-message-content {
  background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
}

[data-theme="dark"] .ppa-chat-send {
  background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
}

[data-theme="dark"] .ppa-chat-send:hover:not(:disabled) {
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .ppa-chat-widget {
    width: calc(100vw - 60px);
    right: 30px;
    bottom: 100px;
    height: calc(100vh - 120px);
    max-height: calc(100vh - 120px);
  }

  .ppa-message-content {
    max-width: 85%;
  }
}

/* Small screens - Full screen with keyboard awareness */
@media (max-width: 430px) {
  .ppa-chat-widget {
    width: 100vw !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    height: 100dvh !important; /* Use dynamic viewport height for mobile browsers */
    max-height: 100dvh !important;
    border-radius: 0 !important;
    border: none !important;
  }

  .ppa-chat-header {
    padding: 1rem;
  }

  .ppa-chat-messages {
    padding: 1rem;
    /* Extra bottom padding to ensure content isn't hidden by keyboard */
    padding-bottom: env(safe-area-inset-bottom, 1rem);
  }

  .ppa-chat-input-wrapper {
    padding: 0.75rem 1rem;
    /* Ensure input stays above keyboard */
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }

  .ppa-message-content {
    max-width: 80%;
    font-size: 0.875rem;
  }

  .ppa-chat-input {
    font-size: 16px; /* Prevents zoom on iOS */
  }

  .ppa-chat-close {
    width: 36px;
    height: 36px;
  }
}

/* Extra support for devices with keyboard */
@media (max-width: 430px) {
  /* When keyboard is visible, use visual viewport */
  .ppa-chat-widget.keyboard-visible {
    height: 100vh !important;
    max-height: 100vh !important;
  }
}

/* Landscape mode on small screens */
@media (max-width: 430px) and (orientation: landscape) {
  .ppa-chat-widget {
    height: 100vh !important;
    max-height: 100vh !important;
  }

  .ppa-chat-header {
    padding: 0.75rem 1rem;
  }

  .ppa-chat-header h3 {
    font-size: 1rem;
  }

  .ppa-chat-status {
    font-size: 0.75rem;
  }
}

/* ============================================================================
   TYPEWRITER EFFECT
   ============================================================================ */

/* Blinking cursor for typewriter effect */
.ppa-typing-cursor::after {
  content: '|';
  animation: blink 1s step-end infinite;
  margin-left: 2px;
  color: var(--text-dark);
  opacity: 0.7;
}

@keyframes blink {
  0%, 100% {
    opacity: 0.7;
  }
  50% {
    opacity: 0;
  }
}

/*=======================================
STOP BUTTON STYLES
========================================*/

/* Stop Generating Button */
.ppa-chat-stop {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #dc2626;
  border: none;
  color: white;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.ppa-chat-stop:hover {
  background: #b91c1c;
}

/* Follow-up Suggestions */
.ppa-followups {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.ppa-followup-btn {
  font-size: 0.75rem;
  padding: 0.4rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--background-alt);
  color: var(--text-dark);
  cursor: pointer;
  transition: all 0.15s ease;
}

.ppa-followup-btn:hover {
  background: #667eea;
  color: white;
  border-color: #667eea;
}

/* ============================================================================
   IMPROVED FULLSCREEN MODE (DESKTOP & TABLET)
   ============================================================================ */

.ppa-chat-widget.ppa-chat-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-height: 100vh !important;
  transform: none !important;
  border-radius: 0 !important;

  /* Remove floating feel */
  box-shadow: none !important;
  border: none !important;

  background: var(--background);
  z-index: 20000 !important;
}

/* Header becomes app-like */
.ppa-chat-widget.ppa-chat-fullscreen .ppa-chat-header {
  padding: 1.25rem 2rem;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}

/* Add subtle “Study Mode” cue */
.ppa-chat-widget.ppa-chat-fullscreen .ppa-chat-status::after {
  content: " • Study mode";
  opacity: 0.85;
  font-weight: 500;
}

/* Center messages for readability */
.ppa-chat-widget.ppa-chat-fullscreen .ppa-chat-messages {
  padding: 2rem 1rem;
  align-items: center;
}

/* Limit content width (huge UX win) */
.ppa-chat-widget.ppa-chat-fullscreen .ppa-chat-message {
  width: 100%;
  max-width: 820px;
}

/* Improve reading comfort */
.ppa-chat-widget.ppa-chat-fullscreen .ppa-message-content {
  font-size: 1rem;
  line-height: 1.65;
}

/* Input bar becomes docked & calm */
.ppa-chat-widget.ppa-chat-fullscreen .ppa-chat-input-wrapper {
  padding: 1.25rem 2rem;
  border-top: 1px solid var(--border-color);
  background: var(--background);
}

/* Bigger input in fullscreen */
.ppa-chat-widget.ppa-chat-fullscreen .ppa-chat-input {
  font-size: 1rem;
  padding: 0.85rem 1.25rem;
}

