/**
 * Styles for the Melchior chat sidebar.
 */

/* Base styles */
.melchior-chat-sidebar {
  background-color: rgba(243, 243, 243, 0.5);
  display: flex;
  flex-direction: column;
  width: 320px;
  transition: all 0.3s ease;
  overflow: hidden;
  font-family: var(--font-serif);
  color: #000;
  position: fixed;
  top: 150px;
  left: 0;
  bottom: 0;
  z-index: 100;
}

/* For browsers that support dynamic viewport units */
@supports (height: 100dvh) {
  .melchior-chat-sidebar {
    /* Height is auto-calculated from top and bottom positions */
    max-height: calc(100dvh - 20px); /* Small buffer for safety */
  }
}

/* Loading state */
.melchior-chat-sidebar.loading {
  pointer-events: none;
}

/* Collapsed state - narrow sidebar rather than hidden */
.melchior-chat-sidebar.collapsed {
  width: 50px; /* Just enough to show icons */
  overflow: hidden;
}

@media (max-width: 767px) {
  .melchior-chat-sidebar.collapsed {
    width: 0;
  }
}

/* Hide text in collapsed state */
.melchior-chat-sidebar.collapsed .link-text,
.melchior-chat-sidebar.collapsed .chat-sidebar-top,
.melchior-chat-sidebar.collapsed .chat-sidebar-title,
.melchior-chat-sidebar.collapsed .history-title,
.melchior-chat-sidebar.collapsed .conversation-title,
.melchior-chat-sidebar.collapsed .chat-sidebar-unauthenticated,
.melchior-chat-sidebar.collapsed .chat-sidebar-content,
.melchior-chat-sidebar.collapsed .chat-sidebar-empty p {
  display: none;
}

.melchior-chat-sidebar.collapsed .chat-sidebar-header .chat-icon {
  display: none;
}

/* Center icons in collapsed state */
.melchior-chat-sidebar.collapsed .chat-icon-container,
.melchior-chat-sidebar.collapsed .chat-option-link,
.melchior-chat-sidebar.collapsed .conversation-icon {
  justify-content: center;
  margin: 0 auto;
}

.melchior-chat-sidebar.collapsed .chat-options {
  align-items: center;
}

/* Toggle button style */
.chat-sidebar-toggle {
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  font-size: 16px;
}

.chat-sidebar-toggle:hover {
  color: #E91E63;
}

.melchior-chat-sidebar.collapsed .chat-sidebar-toggle {
  transform: rotate(180deg);
}

/* Header styles */
.chat-sidebar-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  padding: 15px;
}

.chat-sidebar-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  background-image: url("../assets/robo_icon_pink.svg");
  background-position: 17px center;
  background-repeat: no-repeat;
  background-size: 26.11px 24.09px;
  padding-left: 61px;
}

.chat-sidebar-toggle {
  background: url('../assets/collapse.svg') no-repeat center center;
  border: none;
  cursor: pointer;
  display: flex;
  height: 30px;
  justify-content: center;
  padding: 0;
  width: 30px;
}

.toggle-icon {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z'/%3E%3C/svg%3E");
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  display: block;
  height: 20px;
  width: 20px;
}

.chat-sidebar-toggle:focus {
  outline: 2px solid #0366d6;
  outline-offset: 2px;
  border-radius: 4px;
}

/* Chat icon section at top */
.chat-sidebar-top {
  padding: 15px 10px;
  display: flex;
  flex-direction: column;
}

.chat-icon-container {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 15px;
}

.chat-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Chat options */
.chat-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-option-link {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  color: #333;
  text-decoration: none;
  border-radius: 5px;
  font-weight: 500;
  transition: background-color 0.2s;
}

.chat-option-link:hover {
  background-color: #f0f0f0;
  text-decoration: none;
}

.new-chat-link {
  font-size: 1.6rem;
  display: flex;
  gap: 1rem;
  align-items: baseline;
}

.new-chat-link:hover {
  background-color: rgba(233, 30, 99, 0.1);
}

.search-chat-link {
  color: #333;
}

/* History section */
.chat-history-section {
  padding: 15px 15px 5px;
  margin-top: 10px;
}

.history-title {
  font-size: 1.6rem;
  font-weight: 500;
  color: rgba(0, 0, 0, 0.3);
  margin: 0;
}

.history-title::after {
  display: none;
}

/* Content styles */
.chat-sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 0 15px;
}

/* Empty state */
.chat-sidebar-empty {
  color: #586069;
  font-size: 14px;
  text-align: center;
  padding: 20px 0;
}

/* Conversation list */
.chat-conversation-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.chat-conversation-item {
  display: flex;
  align-items: center;
  padding: 4px 10px;
  position: relative;
  transition: background-color 0.2s ease;
  margin: 4px 0;
}

.chat-conversation-item.active {
  background-color: rgba(0,0,0, 0.05);  
  position: relative;
  transition: all 0.2s ease;
}

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

/* Make sure hover doesn't override active state */
.chat-conversation-item.active:hover {
  background-color: rgba(0,0,0, 0.05);
}

/* Add subtle animation for active conversation */
@keyframes activeHighlight {
  0% { box-shadow: 0 1px 3px rgba(233, 30, 99, 0.1); }
  50% { box-shadow: 0 1px 8px rgba(233, 30, 99, 0.25); }
  100% { box-shadow: 0 1px 3px rgba(233, 30, 99, 0.1); }
}

.chat-conversation-item.active {
  animation: activeHighlight 3s ease infinite;
}

.conversation-icon {
  color: #888;
  margin-right: 10px;
  min-width: 20px;
  display: flex;
  align-items: center;
}

.chat-conversation-item.active .conversation-icon {
  color: #E91E63;
  transform: scale(1.1); /* Slightly larger icon */
  transition: transform 0.2s ease;
}

.chat-conversation-link {
  color: #333;
  display: flex;
  flex: 1;
  text-decoration: none;
  overflow: hidden;
  border-radius: 4px;
}

/* Focus state for better accessibility */
.chat-conversation-link:focus {
  outline: 2px solid rgba(233, 30, 99, 0.5);
}

.chat-conversation-item.active .chat-conversation-link:focus {
  outline-color: #E91E63;
}

.conversation-title {
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Conversation Actions */
.conversation-actions {
  display: flex;
  gap: 5px;
  margin-left: 5px;
  opacity: 0.5;
  transition: opacity 0.2s ease;
}

.chat-conversation-item:hover .conversation-actions {
  opacity: 1;
}

.conversation-edit-btn,
.conversation-clear-btn {
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  padding: 3px;
  transition: color 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
}

.conversation-edit-btn:hover {
  color: #E91E63;
  background-color: rgba(233, 30, 99, 0.1);
}

.conversation-clear-btn:hover {
  color: #dc3545;
  background-color: rgba(220, 53, 69, 0.1);
}

/* Loading state for clear button */
.conversation-clear-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.conversation-clear-btn .loading-spinner {
  font-size: 12px;
}

.conversation-edit-form {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 5px 0;
}

.conversation-title-input {
  flex: 1;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 14px;
  margin-right: 5px;
}

.conversation-title-input:focus {
  border-color: #E91E63;
  outline: none;
  box-shadow: 0 0 0 2px rgba(233, 30, 99, 0.2);
}

.conversation-save-btn,
.conversation-cancel-btn {
  background: none;
  border: none;
  cursor: pointer;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  padding: 0;
}

.conversation-save-btn {
  color: #28a745;
  margin-right: 3px;
}

.conversation-cancel-btn {
  color: #dc3545;
}

.conversation-save-btn:hover {
  background-color: rgba(40, 167, 69, 0.1);
}

.conversation-cancel-btn:hover {
  background-color: rgba(220, 53, 69, 0.1);
}

/* Hide edit elements in collapsed state */
.melchior-chat-sidebar.collapsed .conversation-actions,
.melchior-chat-sidebar.collapsed .conversation-edit-form {
  display: none;
}


/* Actions */
.chat-sidebar-actions {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

.chat-new-conversation-btn {
  background-color: #0366d6;
  border: none;
  border-radius: 4px;
  color: #ffffff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  transition: background-color 0.2s ease;
}

.chat-new-conversation-btn:hover {
  background-color: #0353b4;
}

.chat-new-conversation-btn:focus {
  outline: 2px solid #ffffff;
  outline-offset: -2px;
  box-shadow: 0 0 0 2px #0366d6;
}

.chat-new-conversation-btn:focus-visible {
  outline: 3px solid #0366d6;
  outline-offset: 2px;
}

/* Unauthenticated state */
.chat-sidebar-unauthenticated {
  color: #586069;
  font-size: 16px;
}

.chat-login-btn {
  background-color: #0366d6;
  border-radius: 4px;
  color: #ffffff;
  display: inline-block;
  font-size: 14px;
  font-weight: 500;
  margin-top: 15px;
  padding: 8px 16px;
  text-decoration: none;
  transition: background-color 0.2s ease;
}

.chat-login-btn:hover {
  background-color: #0353b4;
}

.chat-login-btn:focus {
  outline: 2px solid #ffffff;
  outline-offset: -2px;
  box-shadow: 0 0 0 2px #0366d6;
}

.chat-login-btn:focus-visible {
  outline: 3px solid #0366d6;
  outline-offset: 2px;
}

/* Loading indicator */
.chat-sidebar-loader {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.chat-sidebar-loader.active {
  opacity: 1;
  pointer-events: all;
}

.loader-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e1e4e8;
  border-top: 4px solid #0366d6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Pagination styles for conversation list */
.chat-conversation-pagination {
  display: flex;
  justify-content: space-between;
  margin-top: 15px;
  padding: 10px 0;
  border-top: 1px solid #e1e4e8;
}

.pagination-button {
  background-color: #f5f7fa;
  border: 1px solid #e1e4e8;
  border-radius: 4px;
  color: #24292e;
  cursor: pointer;
  font-size: 14px;
  padding: 5px 10px;
  transition: background-color 0.2s ease;
}

.pagination-button:hover:not(:disabled) {
  background-color: #e1e4e8;
}

.pagination-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination-info {
  font-size: 12px;
  color: #6a737d;
}


/* Tablet styles */
@media (max-width: 991px) {
  .melchior-chat-sidebar {
    width: 280px;
    background-color: rgba(243, 243, 243, 1);
    top: 70px !important; /* Override JS positioning for tablet/mobile */
  }

  .melchior-chat-sidebar h3 {
    text-align: left;
  }

}

/* Mobile styles */
@media (max-width: 767px) {  
  /* Handle orientation changes */
  @media (orientation: landscape) {
    .melchior-chat-sidebar {
      max-height: 100%;
      overflow-y: auto;
    }
  }
}

/* Print styles - hide sidebar when printing */
@media print {
  .melchior-chat-sidebar,
  .chat-sidebar-toggle-tablet,
  .sidebar-overlay {
    display: none !important;
  }
}