/* ==========================================================================
   Chat page styles — extracted from chat.templ
   ========================================================================== */

/* Search highlight */
mark {
  background-color: rgba(255, 193, 7, 0.3);
  padding: 0 2px;
  border-radius: 2px;
}

.search-highlight {
  animation: highlightFade 3s ease-out;
  background-color: rgba(255, 193, 7, 0.15);
  border-radius: 0.5rem;
}

@keyframes highlightFade {
  0%   { background-color: rgba(255, 193, 7, 0.3); }
  100% { background-color: transparent; }
}

.search-result-item:hover {
  background-color: var(--bs-gray-100);
}

.search-result-group {
  border-bottom: 1px solid var(--bs-border-color);
}

.search-snippet {
  color: var(--bs-body-color);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: block; }

@keyframes pulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* Chat sidebar */
.chat-sidebar {
  background: var(--bs-body-bg);
  height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
}

.session-search {
  padding: 1rem;
  border-bottom: 1px solid var(--bs-border-color);
}

.session-search input {
  background: var(--bs-gray-100);
  border: none;
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
}

.session-search input:focus {
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-primary);
  box-shadow: 0 0 0 0.2rem rgba(var(--bs-primary-rgb), 0.25);
}

/*
 * Outer #session-list-container is never replaced, so it owns the scroll
 * behaviour. Inner #session-list (.session-list-container) gets stripped
 * by HTMX swaps that target the outer container (search results, "clear
 * search" fallback in handleSearchInput), so we cannot rely on it for
 * scroll context. Keep both rules in sync as a safety net.
 */
#session-list-container,
.session-list-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
}

#session-list-container::-webkit-scrollbar,
.session-list-container::-webkit-scrollbar {
  width: 6px;
}

#session-list-container::-webkit-scrollbar-track,
.session-list-container::-webkit-scrollbar-track {
  background: transparent;
}

#session-list-container::-webkit-scrollbar-thumb,
.session-list-container::-webkit-scrollbar-thumb {
  background: var(--bs-gray-400);
  border-radius: 3px;
}

#session-list-container::-webkit-scrollbar-thumb:hover,
.session-list-container::-webkit-scrollbar-thumb:hover {
  background: var(--bs-gray-500);
}

.session-group-header {
  padding: 0.75rem 1rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--bs-secondary);
  background: var(--bs-body-bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.session-item {
  margin: 0 0.5rem 0.25rem;
  padding: 0.75rem;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.session-item:hover {
  background: var(--bs-gray-100);
  border-color: var(--bs-border-color);
}

.session-item.active {
  background: var(--bs-primary-bg-subtle);
  border-color: var(--bs-primary);
}

.session-item .session-name {
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item .session-time {
  font-size: 0.75rem;
  color: var(--bs-secondary);
}

.session-item .session-actions {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.session-item:hover .session-actions {
  opacity: 1;
}

.session-item .query-count {
  font-size: 0.7rem;
  padding: 0.125rem 0.375rem;
}

.new-chat-btn {
  border-radius: 0.5rem;
  font-weight: 500;
  padding: 0.625rem;
}

/* Chat message bubble — applied by JS in appendMessage() */
.chat-message-bubble {
  max-width: 75%;
  white-space: pre-wrap;       /* preserve newlines */
  font-family: var(--bs-font-monospace, monospace); /* keep table alignment */
  -webkit-user-select: text;   /* ensure message text stays selectable */
  user-select: text;
  cursor: text;
}

/* Rendered-markdown assistant bubbles: real HTML, so drop the monospace/pre-wrap
   ASCII-alignment hack and let tables, lists and paragraphs lay out normally. */
.chat-message-bubble.markdown-body {
  white-space: normal;
  font-family: inherit;
}
.chat-message-bubble.markdown-body > :first-child { margin-top: 0; }
.chat-message-bubble.markdown-body > :last-child { margin-bottom: 0; }
.chat-message-bubble.markdown-body table {
  border-collapse: collapse;
  margin: 0.5rem 0;
  width: auto;
  font-size: 0.9rem;
}
.chat-message-bubble.markdown-body th,
.chat-message-bubble.markdown-body td {
  border: 1px solid var(--bs-border-color, #dee2e6);
  padding: 0.35rem 0.6rem;
  text-align: left;
}
.chat-message-bubble.markdown-body th {
  background: var(--bs-tertiary-bg, #f1f3f5);
  font-weight: 600;
}
.chat-message-bubble.markdown-body tbody tr:nth-child(even) {
  background: var(--bs-tertiary-bg, #f8f9fa);
}
.chat-message-bubble.markdown-body pre {
  background: var(--bs-tertiary-bg, #f1f3f5);
  padding: 0.6rem;
  border-radius: 0.375rem;
  overflow-x: auto;
}
.chat-message-bubble.markdown-body code {
  font-family: var(--bs-font-monospace, monospace);
  font-size: 0.875em;
}

/* Feature 022: Access denied message styling */
.access-denied-message {
  background: linear-gradient(135deg, #fff5f5 0%, #fee2e2 100%) !important;
  border: 1px solid #fca5a5 !important;
  color: #991b1b !important;
}

.access-denied-message::before {
  content: "🔒 ";
}

[data-bs-theme="dark"] .access-denied-message {
  background: linear-gradient(135deg, #450a0a 0%, #7f1d1d 100%) !important;
  border-color: #b91c1c !important;
  color: #fecaca !important;
}
