:root {
  --ss-primary: #6366f1;
  --ss-secondary: #8b5cf6;
  --ss-background: #ffffff;
  --ss-surface: #f8fafc;
  --ss-text: #1e293b;
  --ss-text-secondary: #64748b;
  --ss-border: #e2e8f0;
  --ss-shadow: rgba(0, 0, 0, 0.1);
  --ss-shadow-lg: rgba(0, 0, 0, 0.15);
  --ss-radius: 0.75rem;
  --ss-radius-lg: 1rem;
  --ss-radius-sm: 0.5rem;
  --ss-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --ss-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --ss-bot-bg: #f3f4f6;
  --ss-bot-bg-dark: #374151;
}

[data-theme="dark"] {
  --ss-background: #0f172a;
  --ss-surface: #1e293b;
  --ss-text: #f1f5f9;
  --ss-text-secondary: #94a3b8;
  --ss-border: #334155;
  --ss-shadow: rgba(0, 0, 0, 0.3);
  --ss-shadow-lg: rgba(0, 0, 0, 0.5);
  --ss-bot-bg: #1f2937;
  --ss-bot-bg-dark: #111827;
  --ss-code-bg: rgba(255, 255, 255, 0.1);
}

.star-support-widget {
  font-family: var(--ss-font-family);
  font-size: 14px;
  line-height: 1.5;
}

.star-support-button {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ss-primary), var(--ss-secondary));
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
  transition: var(--ss-transition);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
}

.star-support-button:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
}

.star-support-button:active {
  transform: scale(0.95);
}

.star-support-button::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ss-primary), var(--ss-secondary));
  opacity: 0;
  transition: var(--ss-transition);
  z-index: -1;
}

.star-support-button:hover::before {
  opacity: 0.3;
  transform: scale(1.1);
}

.star-support-chat {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 400px;
  height: 680px;
  max-height: 90vh;
  background: var(--ss-background);
  border: 1px solid var(--ss-border);
  border-radius: 1rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  z-index: 10000;
  overflow: hidden;
  animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.star-support-header {
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, var(--ss-primary), var(--ss-secondary));
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 1rem 1rem 0 0;
  position: relative;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1), 0 0 1px rgba(0, 0, 0, 0.1);
}

.star-support-title {
  font-weight: 600;
  color: white;
  margin: 0;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.7;
    transform: scale(1.2);
  }
}

.star-support-close {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.8);
  padding: 0.5rem;
  border-radius: 0.375rem;
  transition: var(--ss-transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.star-support-close:hover {
  color: white;
  background: rgba(255, 255, 255, 0.1);
  transform: rotate(90deg);
}

.star-support-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1.25rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  background: var(--ss-background);
}

.star-support-messages::-webkit-scrollbar {
  width: 6px;
}

.star-support-messages::-webkit-scrollbar-track {
  background: transparent;
}

.star-support-messages::-webkit-scrollbar-thumb {
  background: var(--ss-border);
  border-radius: 3px;
}

.star-support-messages::-webkit-scrollbar-thumb:hover {
  background: var(--ss-text-secondary);
}

.star-support-welcome-bubble {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: fadeInUp 0.4s ease-out;
}


.star-support-welcome-avatar {
  width: 36px;
  height: 36px;
  color: var(--ss-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 0;
  background: var(--ss-surface);
  border-radius: 50%;
  padding: 0.375rem;
  border: 1px solid var(--ss-border);
}

.star-support-welcome-content {
  flex: 1;
}

.star-support-welcome-text {
  background: linear-gradient(135deg, var(--ss-primary), var(--ss-secondary));
  color: white;
  padding: 0.875rem 1.125rem;
  border-radius: 1.125rem;
  font-size: 0.875rem;
  line-height: 1.5;
  border: none;
  position: relative;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
  font-weight: 500;
}

.star-support-welcome-text::before {
  content: '';
  position: absolute;
  left: -4px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-right: 5px solid var(--ss-primary);
}

.star-support-suggested-questions {
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  animation: fadeInUp 0.5s ease-out 0.2s both;
}

.star-support-suggested-question {
  background: white;
  border: 1.5px solid var(--ss-primary);
  border-radius: 2rem;
  padding: 0.5rem 1rem;
  font-size: 0.813rem;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--ss-primary);
  font-family: var(--ss-font-family);
  line-height: 1.4;
  text-align: left;
  font-weight: 500;
}

[data-theme="dark"] .star-support-suggested-question {
  background: var(--ss-surface);
  color: var(--ss-primary);
}

.star-support-suggested-question:hover {
  background: var(--ss-primary);
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.star-support-suggested-question:active {
  transform: translateY(0);
}

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

.star-support-message-wrapper {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.75rem;
}

.star-support-message-wrapper.user {
  align-items: flex-end;
}

.star-support-message-wrapper.assistant {
  align-items: flex-start;
}

.star-support-message-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.star-support-message-avatar {
  width: 32px;
  height: 32px;
  color: var(--ss-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--ss-surface);
  border-radius: 50%;
  border: 1px solid var(--ss-border);
}

.star-support-message-avatar svg {
  width: 18px;
  height: 18px;
}

.star-support-message-content {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-width: 80%;
}

.star-support-message {
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  word-wrap: break-word;
  font-size: 0.875rem;
  line-height: 1.5;
  font-family: var(--ss-font-family);
  animation: messageSlide 0.2s ease-out;
  overflow-wrap: anywhere;
  position: relative;
}

/* Markdown styles */
.star-support-message strong {
  font-weight: 600;
  color: var(--ss-text);
}

.star-support-message em {
  font-style: italic;
}

.star-support-message code {
  background-color: var(--ss-code-bg, rgba(0, 0, 0, 0.06));
  padding: 0.125rem 0.25rem;
  border-radius: 0.25rem;
  font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
  font-size: 0.875em;
}

.star-support-message a {
  color: var(--ss-primary);
  text-decoration: underline;
}

.star-support-message a:hover {
  text-decoration: none;
}

.star-support-message.user {
  background: var(--ss-primary);
  color: white;
  border: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.star-support-message.assistant {
  background: var(--ss-bot-bg);
  color: var(--ss-text);
  border: 1px solid var(--ss-border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.star-support-message.assistant.typing-indicator {
  padding: 0.75rem 1.25rem !important;
}

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

.star-support-message-label {
  font-size: 0.75rem;
  color: var(--ss-text-secondary);
  padding-left: 0.375rem;
  opacity: 0.7;
}

.star-support-input-container {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--ss-border);
  display: flex;
  gap: 0.75rem;
  align-items: center;
  background: var(--ss-surface);
}

.star-support-input {
  flex: 1;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--ss-border);
  border-radius: 0.5rem;
  background: var(--ss-background);
  color: var(--ss-text);
  font-family: inherit;
  font-size: 0.875rem;
  outline: none;
  transition: var(--ss-transition);
}

.star-support-input:focus {
  border-color: var(--ss-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.star-support-input::placeholder {
  color: var(--ss-text-secondary);
  opacity: 0.7;
}

.star-support-send {
  padding: 0.5rem;
  width: 36px;
  height: 36px;
  background: var(--ss-primary);
  color: white;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: var(--ss-transition);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.star-support-send:hover:not(:disabled) {
  background: var(--ss-secondary);
}

.star-support-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}



/* Typing indicator */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0 !important;
  min-width: 50px;
  justify-content: center;
}

.typing-indicator span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--ss-primary);
  animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
  animation-delay: -0.32s;
}

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

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

@keyframes typing {
  0%, 60%, 100% {
    transform: scale(0.8);
    opacity: 0.3;
  }
  30% {
    transform: scale(1.2);
    opacity: 1;
  }
}

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

.star-support-hidden {
  display: none !important;
}



/* Position variants */
.star-support-chat[data-position="bottom-left"] {
  left: 1rem;
  right: auto;
}

.star-support-chat[data-position="top-right"] {
  top: 1rem;
  bottom: auto;
}

.star-support-chat[data-position="top-left"] {
  top: 1rem;
  left: 1rem;
  right: auto;
  bottom: auto;
}

/* Responsive design */
@media (max-width: 480px) {
  .star-support-chat {
    position: fixed;
    width: 100%;
    height: 100%;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    height: calc(var(--vh, 1vh) * 100); /* Fallback for JS calculated viewport */
    max-height: none;
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    border-radius: 0;
    border: none;
    display: flex;
    flex-direction: column;
  }
  
  .star-support-button {
    position: fixed;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    right: calc(1rem + env(safe-area-inset-right, 0px));
    z-index: 9999;
  }
  
  .star-support-header {
    flex-shrink: 0;
    padding-top: calc(1rem + env(safe-area-inset-top, 0px));
  }
  
  .star-support-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    padding-bottom: 1rem;
  }
  
  .star-support-input-container {
    flex-shrink: 0;
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    background: var(--ss-background);
    border-top: 1px solid var(--ss-border);
    position: relative;
    z-index: 100;
  }
  
  /* Ensure input and buttons are large enough for touch */
  .star-support-input {
    min-height: 44px; /* iOS recommended touch target size */
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 0.75rem 1rem;
  }
  
  .star-support-send {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
  }
  
  .star-support-close {
    min-width: 44px;
    min-height: 44px;
  }
  
  /* Adjust message container padding */
  .star-support-messages {
    padding: 1rem;
  }
  
  /* Ensure suggested questions are touch-friendly */
  .star-support-suggested-question {
    min-height: 44px;
    padding: 0.75rem 1.25rem;
    font-size: 15px;
  }
  
  /* Adjust message bubbles for mobile */
  .star-support-message {
    max-width: 85%;
    font-size: 15px;
  }
  
  /* Handle landscape orientation */
  @media (orientation: landscape) and (max-height: 500px) {
    .star-support-header {
      padding: 0.75rem 1rem;
    }
    
    .star-support-messages {
      padding: 0.75rem;
    }
    
    .star-support-input-container {
      padding: 0.75rem;
    }
  }
}

/* Source links */
.star-support-sources {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--ss-border);
}

.star-support-sources-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--ss-text-secondary);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.star-support-sources-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.star-support-source-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--ss-surface);
  border: 1px solid var(--ss-border);
  border-radius: 6px;
  text-decoration: none;
  color: var(--ss-text);
  font-size: 13px;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.star-support-source-link:hover {
  background: var(--ss-primary);
  color: white;
  border-color: var(--ss-primary);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.star-support-source-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.star-support-source-title {
  flex: 1;
  font-weight: 500;
}

.star-support-source-arrow {
  opacity: 0.5;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.star-support-source-link:hover .star-support-source-arrow {
  opacity: 1;
  transform: translateX(2px);
}

/* Email form styles */
.star-support-email-form {
  margin: 0 0 1rem 0;
  padding: 1.25rem;
  background: var(--ss-surface);
  border: 1px solid var(--ss-border);
  border-radius: var(--ss-radius);
  animation: slideUp 0.3s ease-out;
}

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

.star-support-email-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-weight: 600;
  color: var(--ss-text);
}

.star-support-email-form label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  color: var(--ss-text);
  font-weight: 500;
}

.star-support-email-input,
.star-support-email-textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--ss-border);
  border-radius: var(--ss-radius-sm);
  background: var(--ss-background);
  color: var(--ss-text);
  font-family: inherit;
  font-size: 0.875rem;
  outline: none;
  transition: var(--ss-transition);
  margin-bottom: 1rem;
}

.star-support-email-input:focus,
.star-support-email-textarea:focus {
  border-color: var(--ss-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.star-support-email-input::placeholder,
.star-support-email-textarea::placeholder {
  color: var(--ss-text-secondary);
  opacity: 0.7;
}

.star-support-email-textarea {
  min-height: 80px;
  resize: vertical;
  max-height: 150px;
}

.star-support-email-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.star-support-email-cancel,
.star-support-email-submit {
  padding: 0.5rem 1.25rem;
  border-radius: var(--ss-radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--ss-transition);
  border: none;
  font-family: inherit;
}

.star-support-email-cancel {
  background: transparent;
  color: var(--ss-text-secondary);
  border: 1px solid var(--ss-border);
}

.star-support-email-cancel:hover {
  background: var(--ss-surface);
  border-color: var(--ss-text-secondary);
}

.star-support-email-submit {
  background: var(--ss-primary);
  color: white;
}

.star-support-email-submit:hover:not(:disabled) {
  background: var(--ss-secondary);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.star-support-email-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.star-support-email-success {
  padding: 1rem;
  background: var(--ss-surface);
  color: var(--ss-primary);
  border-radius: var(--ss-radius);
  text-align: center;
  font-weight: 500;
  animation: slideUp 0.3s ease-out;
  border: 1px solid var(--ss-primary);
}

/* Mobile adjustments for email form */
@media (max-width: 480px) {
  .star-support-email-form {
    margin: 0 0 1rem 0;
    padding: 1rem;
  }
  
  .star-support-email-input,
  .star-support-email-textarea {
    font-size: 16px; /* Prevent zoom on iOS */
  }
  
  .star-support-email-buttons {
    flex-direction: column-reverse;
  }
  
  .star-support-email-cancel,
  .star-support-email-submit {
    width: 100%;
    padding: 0.75rem;
  }
}