/**
 * App2Chat Sidebar Widget Styles
 * Documentation-focused chat interface with slide-in animations
 * Mobile-responsive design with full-screen mode on mobile devices
 */

/* Container */
.app2chat-sidebar-container {
  position: fixed;
  top: 0;
  bottom: 0;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  pointer-events: none; /* Allow clicks through the container */
}

.app2chat-sidebar-container[data-position="right"] {
  right: 0;
}

.app2chat-sidebar-container[data-position="left"] {
  left: 0;
}

/* Trigger Button */
.app2chat-sidebar-trigger {
  position: fixed;
  padding: 12px 16px;
  background: linear-gradient(135deg, #0066FF 0%, #0052CC 100%);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 102, 255, 0.4);
  transition: all 0.3s ease;
  pointer-events: auto;
  z-index: 10000;
}

/* Position trigger button on right side */
.app2chat-sidebar-container[data-position="right"] .app2chat-sidebar-trigger {
  right: 0;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.app2chat-sidebar-container[data-position="left"] .app2chat-sidebar-trigger {
  left: 0;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

/* Trigger button vertical positions */
.app2chat-sidebar-trigger-top {
  top: 80px;
}

.app2chat-sidebar-trigger-middle {
  top: 50%;
  transform: translateY(-50%);
}

.app2chat-sidebar-trigger-bottom {
  bottom: 80px;
}

.app2chat-sidebar-trigger:hover {
  box-shadow: 0 6px 16px rgba(0, 102, 255, 0.5);
  transform: translateX(0) scale(1.05);
}

.app2chat-sidebar-container[data-position="right"] .app2chat-sidebar-trigger:hover {
  transform: translateX(-2px) scale(1.05);
}

.app2chat-sidebar-container[data-position="left"] .app2chat-sidebar-trigger:hover {
  transform: translateX(2px) scale(1.05);
}

.app2chat-sidebar-trigger.app2chat-sidebar-hidden {
  display: none;
}

.app2chat-sidebar-trigger-error {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
  cursor: help;
}

/* Sidebar Panel */
.app2chat-sidebar-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 400px;
  max-width: 100vw;
  background: #ffffff;
  box-shadow: 0 0 32px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: auto;
  z-index: 9999;
}

/* Positioning based on data-position */
.app2chat-sidebar-container[data-position="right"] .app2chat-sidebar-panel {
  right: 0;
  transform: translateX(100%);
}

.app2chat-sidebar-container[data-position="left"] .app2chat-sidebar-panel {
  left: 0;
  transform: translateX(-100%);
}

/* Open state - need higher specificity than position rules */
.app2chat-sidebar-container[data-position="right"] .app2chat-sidebar-panel.app2chat-sidebar-open {
  transform: translateX(0);
}

.app2chat-sidebar-container[data-position="left"] .app2chat-sidebar-panel.app2chat-sidebar-open {
  transform: translateX(0);
}

/* Hidden state */
.app2chat-sidebar-panel.app2chat-sidebar-hidden {
  display: none;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .app2chat-sidebar-panel {
    background: #1e293b;
    box-shadow: 0 0 32px rgba(0, 0, 0, 0.6);
  }
}

/* Header */
.app2chat-sidebar-header {
  background: linear-gradient(135deg, #0066FF 0%, #0052CC 100%);
  color: white;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.app2chat-sidebar-header-title {
  flex: 1;
}

.app2chat-sidebar-header-name {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.app2chat-sidebar-header-status {
  font-size: 13px;
  opacity: 0.9;
  display: flex;
  align-items: center;
}

.app2chat-sidebar-header-status::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  margin-right: 6px;
}

.app2chat-sidebar-close-btn {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

.app2chat-sidebar-close-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Messages Container */
.app2chat-sidebar-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #f8f9fa;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (prefers-color-scheme: dark) {
  .app2chat-sidebar-messages {
    background: #0f172a;
  }
}

/* Custom Scrollbar */
.app2chat-sidebar-messages::-webkit-scrollbar {
  width: 6px;
}

.app2chat-sidebar-messages::-webkit-scrollbar-track {
  background: transparent;
}

.app2chat-sidebar-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

.app2chat-sidebar-messages::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

@media (prefers-color-scheme: dark) {
  .app2chat-sidebar-messages::-webkit-scrollbar-thumb {
    background: #475569;
  }

  .app2chat-sidebar-messages::-webkit-scrollbar-thumb:hover {
    background: #64748b;
  }
}

/* Message */
.app2chat-sidebar-message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: slideInMessage 0.3s ease;
}

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

.app2chat-sidebar-message-bot {
  align-self: flex-start;
}

.app2chat-sidebar-message-user {
  align-self: flex-end;
}

.app2chat-sidebar-message-content {
  padding: 12px 16px;
  border-radius: 12px;
  word-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.5;
  font-size: 14px;
}

.app2chat-sidebar-message-bot .app2chat-sidebar-message-content {
  background: #ffffff;
  color: #1e293b;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
  .app2chat-sidebar-message-bot .app2chat-sidebar-message-content {
    background: #334155;
    color: #e2e8f0;
  }
}

.app2chat-sidebar-message-user .app2chat-sidebar-message-content {
  background: #0066FF;
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

@media (prefers-color-scheme: dark) {
  .app2chat-sidebar-message-user .app2chat-sidebar-message-content {
    background: #3b82f6;
    color: #ffffff;
  }
}

/* Links in messages */
.app2chat-sidebar-message-content a {
  color: inherit;
  text-decoration: underline;
  word-break: break-all;
}

.app2chat-sidebar-message-content a:hover {
  opacity: 0.8;
}

.app2chat-sidebar-message-time {
  font-size: 11px;
  color: #64748b;
  margin-top: 4px;
  padding: 0 4px;
}

@media (prefers-color-scheme: dark) {
  .app2chat-sidebar-message-time {
    color: #94a3b8;
  }
}

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

/* Typing Indicator */
.app2chat-sidebar-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: #ffffff;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  width: fit-content;
}

@media (prefers-color-scheme: dark) {
  .app2chat-sidebar-typing-indicator {
    background: #334155;
  }
}

.app2chat-sidebar-typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #cbd5e1;
  animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
    background: #cbd5e1;
  }
  30% {
    transform: translateY(-8px);
    background: #94a3b8;
  }
}

@media (prefers-color-scheme: dark) {
  .app2chat-sidebar-typing-indicator span {
    background: #64748b;
  }

  @keyframes typing {
    0%, 60%, 100% {
      transform: translateY(0);
      background: #64748b;
    }
    30% {
      transform: translateY(-8px);
      background: #94a3b8;
    }
  }
}

/* Input Container */
.app2chat-sidebar-input-container {
  padding: 16px 20px;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

@media (prefers-color-scheme: dark) {
  .app2chat-sidebar-input-container {
    background: #1e293b;
    border-top: 1px solid #334155;
  }
}

.app2chat-sidebar-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
  background: #ffffff;
  color: #1e293b;
}

@media (prefers-color-scheme: dark) {
  .app2chat-sidebar-input {
    background: #0f172a;
    border: 1px solid #334155;
    color: #e2e8f0;
  }
}

.app2chat-sidebar-input:focus {
  border-color: #0066FF;
}

@media (prefers-color-scheme: dark) {
  .app2chat-sidebar-input:focus {
    border-color: #3b82f6;
  }
}

.app2chat-sidebar-send-btn {
  width: 44px;
  height: 44px;
  background: #0066FF;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.app2chat-sidebar-send-btn:hover {
  background: #0052CC;
}

.app2chat-sidebar-send-btn:active {
  transform: scale(0.95);
}

/* Mobile Responsive - Full Screen */
@media (max-width: 767px) {
  .app2chat-sidebar-panel {
    width: 100vw;
    max-width: 100vw;
  }

  .app2chat-sidebar-message {
    max-width: 90%;
  }

  .app2chat-sidebar-header {
    padding: 16px 20px;
  }

  .app2chat-sidebar-messages {
    padding: 16px;
  }

  .app2chat-sidebar-input-container {
    padding: 12px 16px;
  }

  /* Hide trigger button on mobile when panel is open */
  .app2chat-sidebar-panel:not(.app2chat-sidebar-hidden) ~ .app2chat-sidebar-trigger {
    display: none;
  }
}

/* Tablet */
@media (min-width: 768px) and (max-width: 1023px) {
  .app2chat-sidebar-panel {
    width: 360px;
  }
}

/* Utility Classes */
.app2chat-sidebar-hidden {
  display: none !important;
}
