/* Search to chat animations */
.search-to-chat-animation {
  animation: search-to-chat 0.5s forwards ease-in-out;
}

.chat-to-search-animation {
  animation: chat-to-search 0.5s forwards ease-in-out;
}


/* Regular search container that appears at the top */
#search-container.non-chat-mode {
  position: relative !important;
  bottom: auto !important;
  left: auto !important;
  transform: none !important;
  width: 100% !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  margin-bottom: 16px;
}

/* Ensure search container is always visible by default */
#search-container {
  display: block !important; 
  visibility: visible !important;
  opacity: 1 !important;
  position: relative;
  bottom: auto;
  left: auto;
  transform: none;
  width: 100%;
}

/* Direct chat mode styles without animation - ONLY applied in chat mode */
body.chat-mode-active #search-container,
#search-container.chat-mode:not(.search-to-chat-animation):not(.chat-to-search-animation) {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 75%; /* Match the lg:w-3/4 class */
  z-index: 100;
  border-radius: 0;
  margin-bottom: 0;
  padding: 12px 16px;
  box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.1);
  background-color: white;
  transition: none; /* Explicitly disable transitions */
}

/* Ensure proper layout for the input when in chat mode */
#search-container.chat-mode {
  transition: all 0.3s ease-in-out;
}

/* Chat mode specific styles for the results */
body.chat-mode-active #search-results {
  margin-bottom: 80px; /* Provide space for the fixed search bar */
  margin-top: 20px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

body.chat-mode-active .results-container {
  padding-bottom: 80px;
}

/* Style for message bubbles in chat mode */
body.chat-mode-active #search-results .p-4.border-b {
  background-color: #f5f7fa; /* Lighter background for the query message */
}

body.chat-mode-active #search-results .p-6 {
  background-color: white; /* White background for the response */
}

/* Add more visible spacing between messages */
body.chat-mode-active #search-results {
  margin-left: auto;
  margin-right: auto;
}

/* Ensure proper spacing for results container */
.results-container {
  padding-bottom: 16px;
}

/* Animation keyframes for transitioning between modes */
@keyframes search-to-chat {
  0% {
    position: relative;
    bottom: auto;
    left: auto;
    transform: none;
    width: 100%;
    border-radius: 8px;
  }
  100% {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 75%;
    border-radius: 0;
  }
}

@keyframes chat-to-search {
  0% {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 75%;
    border-radius: 0;
  }
  100% {
    position: relative;
    bottom: auto;
    left: auto;
    transform: none;
    width: 100%;
    border-radius: 8px;
  }
}

/* Media query for smaller screens where the layout might change */
@media (max-width: 768px) {
  body.chat-mode-active #search-container,
  #search-container.chat-mode:not(.search-to-chat-animation):not(.chat-to-search-animation) {
    width: 100% !important;
    left: 0;
    transform: none;
  }
  
  @keyframes search-to-chat {
    0% {
      position: relative;
      bottom: auto;
      width: 100%;
    }
    100% {
      position: fixed;
      bottom: 0;
      width: 100%;
    }
  }
  
  @keyframes chat-to-search {
    0% {
      position: fixed;
      bottom: 0;
      width: 100%;
    }
    100% {
      position: relative;
      bottom: auto;
      width: 100%;
    }
  }
}

#search-container.chat-mode form {
  max-width: 800px;
  margin: 0 auto;
}

/* Fix for suggestions dropdown */
#search-container .suggestions {
  position: absolute;
  width: 100%;
  top: 100%;
  left: 0;
  z-index: 110;
}

#search-container.chat-mode .suggestions {
  top: auto;
  bottom: 100%;
  margin-bottom: 8px;
}

/* Make sure the content has sufficient padding at the bottom to account for the fixed search bar */
.chat-mode-active .lg\:w-3\/4 {
  padding-bottom: 80px;
}

#search-results {
  transition: opacity 0.3s ease-in-out;
}

/* Only apply transitions when explicitly in visible state */
#search-results.results-visible {
  opacity: 1;
  visibility: visible;
  margin-bottom: 80px; /* Space for the fixed chat input */
}

/* Hide results by default */
#search-results:not(.results-visible) {
  opacity: 0;
  visibility: hidden;
}

/* Add a class to the body to adjust page layout when in chat mode */
body.chat-mode-active {
  padding-bottom: 70px;
}

@keyframes moveToBottom {
  from {
    transform: translateY(0);
    left: auto;
    width: auto;
  }
  to {
    transform: translateY(calc(100vh - 100%)) translateX(-50%);
    left: 50%;
    width: calc(75% - 2rem); /* Match the exact width of the results card */
    max-width: 800px;
  }
}

@keyframes moveToTop {
  from {
    transform: translateY(calc(100vh - 100%)) translateX(-50%);
    left: 50%;
    width: calc(75% - 2rem); /* Match the exact width of the results card */
    max-width: 800px;
  }
  to {
    transform: translateY(0) translateX(0);
    left: auto;
    width: auto;
  }
}

/* Mobile animations */
@media (max-width: 768px) {
  @keyframes moveToBottom {
    from {
      transform: translateY(0);
      left: auto;
      width: auto;
    }
    to {
      transform: translateY(calc(100vh - 100%));
      left: 0;
      width: 100%;
    }
  }
  
  @keyframes moveToTop {
    from {
      transform: translateY(calc(100vh - 100%));
      left: 0;
      width: 100%;
    }
    to {
      transform: translateY(0);
      left: auto;
      width: auto;
    }
  }
}

/* Additional chat styling */
.chat-mode input {
  padding-right: 50px;
}

.chat-mode button[type="submit"] {
  border-radius: 50%;
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
}

/* Loading spinner */
.loading-icon {
  display: none;
}

.loading-icon.visible {
  display: inline-block;
}

/* New Search button visibility */
.new-search-button {
  display: none;
}

.chat-mode-active .new-search-button {
  display: inline-flex;
}

/* Responsive adjustments for chat mode */
@media (max-width: 768px) {
  #search-container.chat-mode {
    padding: 8px;
  }
  
  #search-container.chat-mode input {
    padding: 10px;
    font-size: 16px; /* Better for mobile keyboards */
  }
  
  .chat-mode button[type="submit"] {
    width: 36px;
    height: 36px;
  }
}

/* New Search container visibility */
.new-search-container {
  display: none;
}

.chat-mode-active .new-search-container {
  display: block;
}

/* Make sure the search bar has exactly the same width as the results card */
body.chat-mode-active #search-container {
  width: calc(75% - 2rem) !important; /* Account for padding in the container */
}

/* Ensure consistent width for both elements */
#search-results, 
body.chat-mode-active #search-container {
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

/* Shadow for elements at the top */
.shadow-top {
  box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Two-column layout similar to OpenAI interface */
.two-column-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.main-column {
  flex: 1;
  max-width: 70%;
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  overflow: auto;
}

.sidebar-column {
  width: 30%;
  min-width: 250px;
  max-width: 300px;
  height: 100%;
  border-left: 1px solid #e5e7eb;
  overflow-y: auto;
  padding: 1rem;
  background-color: #f9fafb;
}

/* Fixed search bar at bottom of main column */
.main-column .search-bar-fixed {
  position: sticky;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 1rem;
  background-color: white;
  box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

/* Search results container */
.main-column .results-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  padding-bottom: 80px; /* Space for fixed search bar */
}

/* Search history in sidebar */
.search-history-item {
  padding: 0.75rem;
  border-radius: 0.375rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: background-color 0.2s;
}

.search-history-item:hover {
  background-color: #f3f4f6;
}

.search-history-item.active {
  background-color: #e5e7eb;
}

/* Responsive adjustments for mobile */
@media (max-width: 768px) {
  .two-column-layout {
    flex-direction: column;
  }
  
  .main-column {
    max-width: 100%;
    height: 70vh;
  }
  
  .sidebar-column {
    width: 100%;
    max-width: 100%;
    height: 30vh;
    border-left: none;
    border-top: 1px solid #e5e7eb;
  }
}

/* Autocomplete Suggestions */
[data-search-target="suggestions"] {
  max-height: 200px;
  overflow-y: auto;
}

/* Animation to show when search results are loaded */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.fade-in {
  animation: fadeIn 0.3s ease forwards;
}

/* Ensure the results container has proper spacing */
[data-search-target="resultsContainer"] {
  padding-bottom: 20px; /* Space for the fixed search input */
}

/* Media queries for mobile devices */
@media (max-width: 768px) {
  /* Make the main layout more compact on mobile */
  .h-\[calc\(100vh-16rem\)\] {
    height: calc(100vh - 10rem);
  }
  
  /* Adjust padding and sizing */
  #search-container {
    padding: 8px;
  }
  
  #search-container input {
    padding: 10px;
    font-size: 16px; /* Better for mobile keyboards */
  }
  
  /* Make the search button more tappable */
  #search-container button[type="submit"] {
    width: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* Fullscreen and Chat Mode Styles */
body.chat-mode .search-container {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1rem;
  background-color: white;
  box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.1);
  z-index: 20;
}

body.chat-mode .results-container {
  height: auto !important;
  overflow: visible !important;
}

body.chat-mode .search-results {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

body.chat-mode .new-search-container {
  display: block !important;
}

/* Media Queries for Responsive Layout */
@media (max-width: 1023px) {
  .search-to-chat-animation {
    animation: search-to-chat-mobile 0.5s forwards ease-in-out;
  }
  
  .chat-to-search-animation {
    animation: chat-to-search-mobile 0.5s forwards ease-in-out;
  }
  
  @keyframes search-to-chat-mobile {
    0% {
      transform: translateY(0);
    }
    100% {
      transform: translateY(0);
      position: fixed;
      bottom: 0;
      left: 0;
      right: 0;
    }
  }
  
  @keyframes chat-to-search-mobile {
    0% {
      transform: translateY(0);
      position: fixed;
      bottom: 0;
      left: 0;
      right: 0;
    }
    100% {
      transform: translateY(0);
    }
  }
}

/* Shadow Effect for the Search Container when Sticky */
.shadow-top {
  box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.1);
}

/* Autocomplete Suggestions Styling */
.suggestion-item {
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: background-color 0.15s;
}

.suggestion-item:hover, .suggestion-item.selected {
  background-color: rgba(0, 0, 0, 0.05);
}

/* Text Truncation */
.line-clamp-1 {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Chat layout specific styles */
.chat-input-container {
  width: 100%;
  max-width: 4xl;
  margin-left: auto;
  margin-right: auto;
  padding: 1rem;
  background-color: white;
  box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.1);
  border-top: 1px solid #f0f0f0;
}

@media (min-width: 1024px) {
  .chat-input-container {
    width: 100%;
    max-width: 56rem; /* 4xl in tailwind */
    margin-left: auto;
    margin-right: auto;
  }
}

/* Chat message styles */
.chat-message-user {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1rem;
}

.chat-message-ai {
  display: flex;
  justify-content: flex-start;
  width: 100%;
  margin-bottom: 1.5rem;
}

.chat-message-user .message-bubble {
  background-color: #6366f1; /* Brand color */
  color: white;
  padding: 1rem;
  border-radius: 0.5rem;
  max-width: 75%;
}

.chat-message-ai .message-bubble {
  background-color: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  border-radius: 0.5rem;
  padding: 1rem;
  width: 100%;
}

/* Ensure fixed input is centered */
.fixed-input-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 56rem; /* 4xl in tailwind */
  margin-left: auto;
  margin-right: auto;
  padding: 1rem;
  background-color: white;
  box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

/* Chat container with extra bottom padding for fixed input */
.chat-container {
  padding-bottom: 5rem;
}

/* Back button styles */
.back-button {
  display: flex;
  align-items: center;
  margin-right: 1rem;
  padding: 0.75rem;
  background-color: rgba(99, 102, 241, 0.1);
  color: #6366f1;
  border-radius: 0.375rem;
  transition: background-color 0.2s;
}

.back-button:hover {
  background-color: rgba(99, 102, 241, 0.2);
}

.back-button i {
  margin-right: 0.5rem;
} 