/* 
 * Z-Index Hierarchy:
 * - Modal backdrop: 1055
 * - Mobile chat drawer: 1080
 * - Mobile chat drawer content: 1081
 * - Mobile chat prompt: 1085
 * - Bootstrap modal: 1090
 */
/* Navbar Chat Toggle Styles */
.navbar-chat-toggle {
  display: flex;
  align-items: center;
}

.navbar-chat-toggler {
  background: none;
  border: none;
  color: #566a7f;
  transition: color 0.2s ease;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 0.375rem;
}
.navbar-chat-toggler:hover {
  color: #2B828F;
  background-color: rgba(43, 130, 143, 0.1);
}
.navbar-chat-toggler:active {
  transform: scale(0.95);
}

/* Hide other navbar elements when chat is active */
.navbar-chat-active {
  /* Visual indicator for active chat state */
  background: linear-gradient(135deg, rgba(43, 130, 143, 0.02) 0%, rgba(43, 130, 143, 0.05) 100%);
  border-bottom: 2px solid rgba(43, 130, 143, 0.1);
}
.navbar-chat-active .layout-menu-toggle {
  display: none !important;
  opacity: 0;
  transform: translateX(-10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.navbar-chat-active .navbar-dropdown,
.navbar-chat-active .dropdown-user {
  display: none !important;
  opacity: 0;
  transform: translateX(-10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.navbar-chat-active .navbar-nav-right > ul.navbar-nav:last-child {
  display: none !important;
  opacity: 0;
  transform: translateX(-10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.navbar-chat-active .chat-toggler {
  display: none !important;
  opacity: 0;
  transform: translateX(-10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.navbar-chat-active .navbar-search-wrapper {
  display: none !important;
  opacity: 0;
  transform: translateX(-10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.navbar-chat-active .navbar-chat-wrapper {
  flex: 1;
  justify-content: center;
  transition: all 0.3s ease;
  background: rgba(43, 130, 143, 0.05);
  border-radius: 0.5rem;
  padding: 0.5rem;
  margin: 0 1rem;
  animation: chatWrapperActive 0.3s ease;
  width: 100%;
  max-width: none;
}
.navbar-chat-active .navbar-nav-right {
  width: 100%;
  justify-content: center;
}
.navbar-chat-active .navbar-chat-input-group {
  max-width: none;
  width: 100%;
  transition: all 0.3s ease;
}

/* Navbar Chat Input Styles */
.navbar-chat-input-group {
  position: relative;
  min-width: 200px;
  max-width: 400px;
  animation: slideInInput 0.3s ease;
}

@keyframes slideInInput {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
.navbar-chat-input {
  border-radius: 20px;
  border: 1px solid #d9dee3;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  background: #f5f5f9;
  transition: all 0.2s ease;
  width: 100%;
}
.navbar-chat-input:focus {
  background: white;
  border-color: #2B828F;
  box-shadow: 0 0 0 0.2rem rgba(43, 130, 143, 0.25);
  outline: none;
}
.navbar-chat-input:focus + .navbar-chat-submit {
  background: #1a5259;
  transform: scale(1.05);
}
.navbar-chat-input::placeholder {
  color: #a1acb8;
  font-size: 0.875rem;
}

.navbar-chat-submit {
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: #2B828F;
  color: white;
  transition: all 0.2s ease;
  flex-shrink: 0;
}
.navbar-chat-submit:hover {
  background: #1a5259;
  transform: scale(1.05);
}
.navbar-chat-submit:active {
  background: #0f3a40;
  transform: scale(0.95);
}
.navbar-chat-submit:disabled {
  background: #6c757d;
  cursor: not-allowed;
  transform: none;
}

.navbar-chat-close {
  border-radius: 50%;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: #e9ecef;
  color: #6c757d;
  transition: all 0.2s ease;
  flex-shrink: 0;
}
.navbar-chat-close:hover {
  background: #dee2e6;
  color: #495057;
  transform: scale(1.05);
}
.navbar-chat-close:active {
  transform: scale(0.95);
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
  .navbar-chat-input-group {
    min-width: 150px;
    max-width: 250px;
  }
  .navbar-chat-input {
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
  }
  .navbar-chat-submit {
    width: 1.75rem;
    height: 1.75rem;
  }
  .navbar-chat-close {
    width: 1.5rem;
    height: 1.5rem;
  }
}
@media (max-width: 576px) {
  .navbar-chat-input-group {
    min-width: 120px;
    max-width: 180px;
  }
  .navbar-chat-input {
    font-size: 0.75rem;
    padding: 0.35rem 0.7rem;
  }
  .navbar-chat-submit {
    width: 1.5rem;
    height: 1.5rem;
  }
  .navbar-chat-close {
    width: 1.25rem;
    height: 1.25rem;
  }
}
/* Hide navbar chat input on very small screens and show alternative */
@media (max-width: 480px) {
  .navbar-chat-input-group {
    display: none !important;
  }
  .navbar-chat-mobile-toggle {
    display: flex !important;
  }
}
/* Mobile Chat Drawer Styles */
.mobile-chat-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1050;
  pointer-events: none;
  transition: all 0.3s ease;
}
.mobile-chat-drawer.active {
  pointer-events: all;
}
.mobile-chat-drawer__content {
  background: white;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
  transform: translateY(100%);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  display: flex;
  flex-direction: column;
  max-height: 80vh;
  min-height: 200px;
}
.mobile-chat-drawer__content.active {
  transform: translateY(0);
  opacity: 1;
}
.mobile-chat-drawer__header {
  padding: 1rem;
  border-bottom: 1px solid #e9ecef;
  background: white;
  border-radius: 16px 16px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.mobile-chat-drawer__header h6 {
  margin: 0;
  font-weight: 600;
  color: #495057;
}
.mobile-chat-drawer__header .btn-close {
  padding: 0.25rem;
  background: transparent;
  border: none;
  color: #6c757d;
  font-size: 1.25rem;
  cursor: pointer;
  transition: color 0.2s ease;
}
.mobile-chat-drawer__header .btn-close:hover {
  color: #495057;
}
.mobile-chat-drawer__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: calc(80vh - 120px);
  /* Custom scrollbar styling */
}
.mobile-chat-drawer__messages::-webkit-scrollbar {
  width: 4px;
}
.mobile-chat-drawer__messages::-webkit-scrollbar-track {
  background: transparent;
}
.mobile-chat-drawer__messages::-webkit-scrollbar-thumb {
  background: #dee2e6;
  border-radius: 2px;
}
.mobile-chat-drawer__messages::-webkit-scrollbar-thumb:hover {
  background: #adb5bd;
}
.mobile-chat-drawer__input-area {
  padding: 1rem;
  border-top: 1px solid #e9ecef;
  background: white;
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}
.mobile-chat-drawer__input-area .form-control {
  border: 1px solid #dee2e6;
  border-radius: 20px;
  padding: 0.5rem 1rem;
  resize: none;
  min-height: 40px;
  max-height: 100px;
  font-size: 0.875rem;
}
.mobile-chat-drawer__input-area .form-control:focus {
  border-color: #5a6acf;
  box-shadow: 0 0 0 0.2rem rgba(90, 106, 207, 0.25);
}
.mobile-chat-drawer__input-area .btn-send {
  background: #5a6acf;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  cursor: pointer;
  transition: background-color 0.2s ease;
  flex-shrink: 0;
}
.mobile-chat-drawer__input-area .btn-send:hover {
  background: #4a5bbf;
}
.mobile-chat-drawer__input-area .btn-send:disabled {
  background: #6c757d;
  cursor: not-allowed;
}
.mobile-chat-drawer__input-area .btn-send i {
  font-size: 0.875rem;
}
.mobile-chat-drawer__drag-handle {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 4px;
  background: #dee2e6;
  border-radius: 2px;
  cursor: grab;
  transition: background-color 0.2s ease;
}
.mobile-chat-drawer__drag-handle:hover {
  background: #adb5bd;
}
.mobile-chat-drawer__drag-handle:active {
  cursor: grabbing;
}

.mobile-chat-toggle {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  width: 56px;
  height: 56px;
  background: #5a6acf;
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 1.25rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(90, 106, 207, 0.3);
  transition: all 0.2s ease;
  z-index: 1040;
  display: none;
}
.mobile-chat-toggle:hover {
  background: #4a5bbf;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(90, 106, 207, 0.4);
}
.mobile-chat-toggle:active {
  transform: translateY(0);
}
@media (max-width: 768px) {
  .mobile-chat-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

.mobile-chat-message {
  margin-bottom: 0.75rem;
  max-width: 80%;
  word-wrap: break-word;
}
.mobile-chat-message.user {
  align-self: flex-end;
  margin-left: auto;
}
.mobile-chat-message.user .message-bubble {
  background: #5a6acf;
  color: white;
  border-radius: 18px 18px 4px 18px;
}
.mobile-chat-message.ai {
  align-self: flex-start;
  margin-right: auto;
}
.mobile-chat-message.ai .message-bubble {
  background: #f8f9fa;
  color: #495057;
  border-radius: 18px 18px 18px 4px;
  border: 1px solid #e9ecef;
}
.mobile-chat-message .message-bubble {
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  line-height: 1.4;
}
.mobile-chat-message .message-time {
  font-size: 0.75rem;
  color: #6c757d;
  margin-top: 0.25rem;
  text-align: right;
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.75rem 1rem;
  background: #f8f9fa;
  border-radius: 18px;
  border: 1px solid #e9ecef;
  max-width: 80px;
  margin-bottom: 0.75rem;
  align-self: flex-start;
}
.typing-indicator .dot {
  width: 6px;
  height: 6px;
  background: #6c757d;
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out;
}
.typing-indicator .dot:nth-child(1) {
  animation-delay: -0.32s;
}
.typing-indicator .dot:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes typing {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}
/* Prevent text selection during drag */
.mobile-chat-drawer__header * {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
  .mobile-chat-drawer__input,
  .mobile-chat-prompt__input {
    font-size: 16px; /* Prevents zoom on iOS */
  }
  .mobile-chat-drawer__content {
    -webkit-transform: translateY(-100%);
    transform: translateY(-100%);
  }
  .mobile-chat-drawer.active .mobile-chat-drawer__content {
    -webkit-transform: translateY(0);
    transform: translateY(0);
  }
}
/* Header input prompt for first message */
.mobile-chat-prompt {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: white;
  border-bottom: 1px solid #e9ecef;
  padding: 1rem;
  z-index: 1085; /* Higher than modal-backdrop (1055) and drawer (1080) but lower than modal (1090) */
  transform: translateY(-100%);
  transition: transform 0.3s ease;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  pointer-events: none; /* Don't block interactions when hidden */
  /* Ensure it doesn't interfere with navbar */
  margin-top: 0;
}
.mobile-chat-prompt.active {
  transform: translateY(0);
  pointer-events: auto; /* Allow interactions when visible */
}

.mobile-chat-prompt__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.mobile-chat-prompt__title {
  font-size: 1rem;
  font-weight: 600;
  color: #495057;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mobile-chat-prompt__close {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: #6c757d;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 50%;
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.mobile-chat-prompt__close:hover {
  background-color: #e9ecef;
}

.mobile-chat-prompt__input-group {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.mobile-chat-prompt__input {
  flex: 1;
  border: 1px solid #dee2e6;
  border-radius: 20px;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s ease;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}
.mobile-chat-prompt__input:focus {
  border-color: #2B828F;
}

.mobile-chat-prompt__send-btn {
  background: #2B828F;
  color: white;
  border: none;
  border-radius: 50%;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.mobile-chat-prompt__send-btn:hover {
  background: #1a5259;
}
.mobile-chat-prompt__send-btn:active {
  background: #0f3a40;
  transform: scale(0.95);
}

/* Hide desktop chat modal on mobile */
@media (max-width: 768px) {
  #chatModal {
    display: none !important;
  }
  .navbar-chat-wrapper {
    display: block !important;
  }
}
/* Show desktop chat modal on larger screens */
@media (min-width: 769px) {
  .mobile-chat-drawer,
  .mobile-chat-prompt {
    display: none !important;
  }
}
/* Smooth transitions for navbar elements */
#layout-navbar .layout-menu-toggle,
#layout-navbar .navbar-nav:not(.navbar-chat-wrapper),
#layout-navbar .navbar-search-wrapper {
  transition: opacity 0.3s ease, transform 0.3s ease;
}

@keyframes chatWrapperActive {
  from {
    opacity: 0.8;
    transform: scale(0.98);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
