/* Managira Chatbot Styles */

/* Chatbot Toggle Button - uses organization theme */
/* ISOLATION: Chatbot styles are scoped to prevent page CSS from affecting them */
.chatbot-toggle {
  position: fixed !important;
  bottom: 20px !important;
  right: 20px !important;
  width: 52px !important;
  height: 52px !important;
  background: linear-gradient(135deg, var(--org-primary-color) 0%, var(--org-primary-hover) 100%) !important;
  border-radius: 50% !important;
  border: none !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  box-shadow: 0 4px 20px rgba(1, 83, 91, 0.4) !important;
  transition: all 0.3s ease !important;
  z-index: 1000 !important;
  padding: 0 !important;
  margin: 0 !important;
  min-width: unset !important;
  max-width: unset !important;
  color: white !important;
  font-size: inherit !important;
  line-height: normal !important;
  text-align: center !important;
  text-decoration: none !important;
}

.chatbot-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 30px rgba(1, 83, 91, 0.6);
}

/* Hide chatbot on public dashboard - all screens */
body[data-page="publicDashboard"] .chatbot-toggle,
body[data-page="publicDashboard"] .chatbot-container {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Hide chatbot when URL contains publicDashboard */
[data-page*="publicDashboard"] .chatbot-toggle,
[data-page*="publicDashboard"] .chatbot-container {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.chatbot-toggle svg {
  width: 30px;
  height: 30px;
  fill: white;
}

/* Mobile Toggle Button Adjustments */
@media (max-width: 768px) {
  .chatbot-toggle {
    width: 48px;
    height: 48px;
    bottom: 16px;
    right: 16px;
  }
  
  .chatbot-toggle svg {
    width: 26px;
    height: 26px;
  }
}

@media (max-width: 480px) {
  .chatbot-toggle {
    width: 44px;
    height: 44px;
    bottom: 12px;
    right: 12px;
  }
  
  .chatbot-toggle svg {
    width: 24px;
    height: 24px;
  }
}

/* Chatbot Container — fully isolated from page styles */
.chatbot-container {
  position: fixed !important;
  bottom: 90px !important;
  right: 20px !important;
  width: 380px !important;
  height: 500px !important;
  background: white !important;
  border-radius: 16px !important;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15) !important;
  display: none;
  flex-direction: column;
  overflow: hidden !important;
  z-index: 999 !important;
  font-family: var(--font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif) !important;
  border: none !important;
  transition: all 0.3s ease !important;
  padding: 0 !important;
  margin: 0 !important;
  color: #333 !important;
  text-align: left !important;
}

.chatbot-container.active {
  display: flex;
}

.chatbot-container.minimized {
  height: 60px;
  overflow: hidden;
  border-radius: 12px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
  width: 250px;
  right: 100px; /* Push it left to avoid chat button */
}

.chatbot-container.minimized .chatbot-content,
.chatbot-container.minimized .chatbot-input-area {
  display: none;
}

/* Desktop minimized header padding (default for large screens) */
.chatbot-container.minimized .chatbot-header {
  padding: 14px 10px;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  .chatbot-container {
    width: calc(100vw - 20px);
    height: calc(100vh - 120px);
    bottom: 10px;
    right: 10px;
    left: 10px;
    border-radius: 12px;
    max-height: 70vh;
    border: none; /* Remove white border */
  }
  
  /* When chat is open, cover the toggle button */
  .chatbot-container.active {
    right: 10px;
    left: 10px;
    width: calc(100vw - 20px);
  }
  
  .chatbot-container.minimized {
    width: 250px;
    height: 50px;
    right: 80px; /* Push left to avoid chat button on mobile */
    left: auto;
    border-radius: 25px;
  }
}

@media (max-width: 480px) {
  .chatbot-container {
    width: calc(100vw - 16px);
    height: calc(100vh - 100px);
    bottom: 8px;
    right: 8px;
    left: 8px;
    border-radius: 10px;
    max-height: 65vh;
    border: none; /* Remove white border */
  }
  
  /* When chat is open, cover the toggle button completely */
  .chatbot-container.active {
    right: 8px;
    left: 8px;
    width: calc(100vw - 16px);
  }
  
  .chatbot-container.minimized {
    width: 200px;
    height: 45px;
    right: 70px; /* Push left to avoid chat button on small mobile */
    left: auto;
    border-radius: 22px;
  }
}

/* Toggle button transitions */
.chatbot-toggle {
  transition: opacity 0.3s ease;
}



/* Keyboard Adjustment for Mobile */
@media (max-width: 768px) {
  .chatbot-container.keyboard-active {
    height: 50vh;
    max-height: 50vh;
  }
}

/* Chatbot Header - uses organization theme */
.chatbot-header {
  background: linear-gradient(135deg, var(--org-primary-color), var(--org-primary-hover));
  color: white;
  padding: 10px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  /* border-radius: 16px 16px 0 0; */
}

.chatbot-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

/* Mobile Header Adjustments */
@media (max-width: 768px) {
  .chatbot-header {
    padding: 14px 16px;
    border-radius: 12px 12px 0 0;
  }
  
  .chatbot-header h3 {
    font-size: 16px;
  }
  
  .chatbot-container.minimized .chatbot-header {
    padding: 10px 10px;
    border-radius: 25px;
  }
  
  .chatbot-container.minimized .chatbot-header h3 {
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  .chatbot-header {
    padding: 12px 14px;
    border-radius: 10px 10px 0 0;
  }
  
  .chatbot-header h3 {
    font-size: 15px;
  }
  
  .chatbot-container.minimized .chatbot-header {
    padding: 10px 10px;
    border-radius: 22px;
  }
  
  .chatbot-container.minimized .chatbot-header h3 {
    font-size: 13px;
  }
}

.chatbot-controls {
  display: flex;
  gap: 8px;
}

.chatbot-minimize,
.chatbot-close {
  background: none;
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s ease;
}

.chatbot-minimize:hover,
.chatbot-close:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Mobile Controls Adjustments */
@media (max-width: 768px) {
  .chatbot-controls {
    gap: 6px;
  }
  
  .chatbot-minimize,
  .chatbot-close {
    font-size: 16px;
    width: 26px;
    height: 26px;
    padding: 2px;
  }
}

@media (max-width: 480px) {
  .chatbot-controls {
    gap: 4px;
  }
  
  .chatbot-minimize,
  .chatbot-close {
    font-size: 14px;
    width: 24px;
    height: 24px;
    padding: 1px;
  }
}

.chatbot-minimize {
  font-size: 16px;
  font-weight: bold;
}

/* Chatbot Content */
.chatbot-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 400px;
}

/* Chat Messages Area */
.chatbot-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background: #f8f9fa;
}

.message {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
}

.message-bot {
  align-items: flex-start;
}

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

.message-bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
}

.message-bot .message-bubble {
  background: white;
  color: #333;
  border: 1px solid #e1e5e9;
  border-bottom-left-radius: 6px;
}

.message-user .message-bubble {
  background: var(--org-primary-color);
  color: white;
  border-bottom-right-radius: 6px;
}

/* FAQ Results */
.faq-results {
  margin-top: 8px;
}

.faq-item {
  background: white;
  border: 1px solid #e1e5e9;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.faq-item:hover {
  background: #f8f9fa;
  border-color: var(--org-primary-color);
}

.faq-question {
  font-weight: 600;
  color: var(--org-primary-color);
  font-size: 13px;
  margin-bottom: 4px;
}

.faq-category {
  font-size: 11px;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Mobile Content Adjustments */
@media (max-width: 768px) {
  .chatbot-messages {
    padding: 16px;
  }
  
  .message {
    margin-bottom: 12px;
  }
  
  .message-bubble {
    max-width: 90%;
    padding: 10px 14px;
    font-size: 14px;
    border-radius: 16px;
  }
  
  .faq-item {
    padding: 10px;
    margin-bottom: 6px;
    border-radius: 6px;
  }
  
  .faq-question {
    font-size: 12px;
  }
  
  .faq-category {
    font-size: 10px;
  }
}

@media (max-width: 480px) {
  .chatbot-messages {
    padding: 12px;
  }
  
  .message {
    margin-bottom: 10px;
  }
  
  .message-bubble {
    max-width: 95%;
    padding: 8px 12px;
    font-size: 13px;
    border-radius: 14px;
  }
  
  .faq-item {
    padding: 8px;
    margin-bottom: 4px;
    border-radius: 5px;
  }
  
  .faq-question {
    font-size: 11px;
  }
  
  .faq-category {
    font-size: 9px;
  }
}

/* Suggestions */
.suggestions {
  margin-top: 8px;
}

.suggestion-item {
  background: white;
  border: 1px solid #e1e5e9;
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--org-primary-color);
  transition: all 0.2s ease;
}

.suggestion-item:hover {
  background: var(--org-primary-color);
  color: white;
}

/* Contact Info */
.contact-info {
  margin-top: 8px;
  padding: 8px 12px;
  background: #e7f3ff;
  border-radius: 6px;
  font-size: 12px;
  color: #0969da;
}

/* Input Area */
.chatbot-input-area {
  padding: 16px 20px !important;
  background: white !important;
  border-top: 1px solid #e1e5e9 !important;
  display: flex !important;
  gap: 8px !important;
  align-items: center !important;
  min-height: auto !important;
}

.chatbot-input {
  flex: 1 !important;
  border: 1px solid #e1e5e9 !important;
  border-radius: 20px !important;
  padding: 10px 16px !important;
  font-size: 15px !important;
  outline: none !important;
  transition: border-color 0.2s ease !important;
  min-height: 40px !important;
  height: 40px !important;
  box-sizing: border-box !important;
  margin: 0 !important;
  width: auto !important;
  background: white !important;
  color: #333 !important;
}

.chatbot-input:focus {
  border-color: var(--org-primary-color);
}

.chatbot-send {
  background: var(--org-primary-color, #01535b) !important;
  border: none !important;
  border-radius: 50% !important;
  width: 40px !important;
  height: 40px !important;
  min-width: 40px !important;
  min-height: 40px !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: background 0.2s ease !important;
  padding: 0 !important;
  margin: 0 !important;
  color: white !important;
}

.chatbot-send:hover {
  background: var(--org-primary-hover, #013c44);
}

.chatbot-send:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.chatbot-send svg {
  width: 16px;
  height: 16px;
  fill: white;
}

/* Mobile Input Adjustments */
@media (max-width: 768px) {
  .chatbot-input-area {
    padding: 12px 16px;
    gap: 8px;
  }
  
  .chatbot-input {
    padding: 8px 14px;
    font-size: 16px; /* Prevents zoom on iOS */
    border-radius: 18px;
  }
  
  .chatbot-send {
    width: 36px;
    height: 36px;
  }
  
  .chatbot-send svg {
    width: 14px;
    height: 14px;
  }
}

@media (max-width: 480px) {
  .chatbot-input-area {
    padding: 10px 14px;
    gap: 6px;
  }
  
  .chatbot-input {
    padding: 6px 12px;
    font-size: 16px;
    border-radius: 16px;
  }
  
  .chatbot-send {
    width: 34px;
    height: 34px;
  }
  
  .chatbot-send svg {
    width: 13px;
    height: 13px;
  }
}

/* Welcome Message */
.welcome-message {
  text-align: center;
  padding: 20px 16px;
  background: linear-gradient(135deg, #f8fffe 0%, #eef9f8 100%);
  border-radius: 12px;
  margin: 16px;
  border: 1px solid #e1f2f0;
}

.welcome-message h4 {
  color: var(--org-primary-color, #01535b);
  margin: 0 0 12px 0;
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.welcome-message p {
  color: #4a6765;
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

/* Popular Questions */
.popular-questions {
  margin-top: 16px;
}

.popular-questions h5 {
  font-size: 14px;
  font-weight: 600;
  color: var(--org-primary-color, #01535b);
  margin-bottom: 8px;
}

.popular-question {
  background: white;
  border: 1px solid #e1e5e9;
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 13px;
  color: #333;
  transition: all 0.2s ease;
}

.popular-question:hover {
  background: #f8f9fa;
  border-color: var(--org-primary-color, #01535b);
  color: var(--org-primary-color, #01535b);
}

/* Loading Animation */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--org-primary-color, #01535b);
  animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
  0%, 80%, 100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Scrollbar Styling */
.chatbot-messages::-webkit-scrollbar {
  width: 4px;
}

.chatbot-messages::-webkit-scrollbar-track {
  background: #f1f3f4;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background: #c1c7cd;
  border-radius: 2px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Responsive Design */
@media (max-width: 480px) {
  .chatbot-container {
    width: calc(100vw - 40px);
    right: 20px;
    left: 20px;
    height: 450px;
  }
  
  .chatbot-toggle {
    bottom: 15px;
    right: 15px;
  }
}

@media (max-width: 360px) {
  .chatbot-container {
    bottom: 80px;
    height: 400px;
  }
}

/* Animation for container show/hide */
.chatbot-container {
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.chatbot-container.active {
  transform: translateY(0);
  opacity: 1;
}

/* Mobile Welcome Message Adjustments */
@media (max-width: 768px) {
  .welcome-message {
    padding: 16px 14px;
    margin: 12px;
  }
  
  .welcome-message h4 {
    font-size: 16px;
    margin-bottom: 10px;
  }
  
  .welcome-message p {
    font-size: 13px;
  }
  
  .popular-questions h5 {
    font-size: 13px;
    margin-bottom: 6px;
  }
  
  .popular-question {
    padding: 8px 10px;
    margin-bottom: 4px;
    font-size: 12px;
    border-radius: 5px;
  }
}

@media (max-width: 480px) {
  .welcome-message {
    padding: 12px 10px;
    margin: 8px;
  }
  
  .welcome-message h4 {
    font-size: 14px;
    margin-bottom: 8px;
    gap: 6px;
  }
  
  .welcome-message p {
    font-size: 12px;
    line-height: 1.4;
  }
  
  .popular-questions {
    margin-top: 12px;
  }
  
  .popular-questions h5 {
    font-size: 12px;
    margin-bottom: 4px;
  }
  
  .popular-question {
    padding: 6px 8px;
    margin-bottom: 3px;
    font-size: 11px;
    border-radius: 4px;
  }
}

/* ==========================================================
   Mobile Polish Overrides (final layer)
   ========================================================== */
@media (max-width: 768px) {
  .chatbot-container {
    width: min(96vw, 420px) !important;
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) translateY(20px) !important;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    max-height: min(76vh, 620px) !important;
    height: min(76vh, 620px) !important;
    border-radius: 16px !important;
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.24) !important;
    border: 1px solid rgba(15, 23, 42, 0.08) !important;
    overflow: hidden !important;
  }

  .chatbot-container.active {
    transform: translateX(-50%) translateY(0) !important;
  }

  .chatbot-header {
    min-height: 56px !important;
    padding: 12px 14px !important;
  }

  .chatbot-header h3 {
    font-size: 17px !important;
    line-height: 1.2 !important;
    letter-spacing: 0.1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chatbot-controls {
    gap: 4px !important;
    margin-left: 8px;
  }

  .chatbot-minimize,
  .chatbot-close {
    width: 28px !important;
    height: 28px !important;
    border-radius: 8px !important;
  }

  .chatbot-content {
    height: auto !important;
    min-height: 0;
  }

  .chatbot-messages {
    padding: 12px !important;
    background: #f6f8fb !important;
  }

  .welcome-message {
    margin: 0 0 12px 0 !important;
    padding: 14px 12px !important;
    border-radius: 12px !important;
  }

  .welcome-message h4 {
    font-size: 16px !important;
    margin-bottom: 8px !important;
  }

  .welcome-message p {
    font-size: 13px !important;
    line-height: 1.45 !important;
  }

  .popular-questions {
    margin-top: 8px !important;
  }

  .popular-questions h5 {
    font-size: 13px !important;
    margin-bottom: 8px !important;
    padding: 0 2px;
  }

  .popular-question {
    border-radius: 10px !important;
    padding: 10px 11px !important;
    margin-bottom: 7px !important;
    font-size: 12.5px !important;
    line-height: 1.35;
  }

  .message {
    margin-bottom: 10px !important;
  }

  .message-bubble {
    border-radius: 14px !important;
    padding: 10px 12px !important;
    font-size: 13px !important;
    line-height: 1.4 !important;
  }

  .chatbot-input-area {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: rgba(255, 255, 255, 0.98) !important;
    backdrop-filter: blur(8px);
    border-top: 1px solid #e6eaf0 !important;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)) 12px !important;
    gap: 8px !important;
  }

  .chatbot-input {
    height: 38px !important;
    min-height: 38px !important;
    font-size: 16px !important;
    border-radius: 999px !important;
    padding: 8px 13px !important;
    border: 1px solid #d8dee8 !important;
    background: #fff !important;
  }

  .chatbot-send {
    width: 38px !important;
    height: 38px !important;
    min-width: 38px !important;
    min-height: 38px !important;
  }

  .chatbot-send svg {
    width: 14px !important;
    height: 14px !important;
  }
}

@media (max-width: 420px) {
  .chatbot-container {
    width: calc(100vw - 12px) !important;
    border-radius: 14px !important;
    max-height: 74vh !important;
    height: 74vh !important;
  }

  .chatbot-header {
    min-height: 52px !important;
    padding: 10px 12px !important;
  }

  .chatbot-header h3 {
    font-size: 15px !important;
  }

  .chatbot-messages {
    padding: 10px !important;
  }

  .welcome-message {
    padding: 12px 10px !important;
  }
}