/* Base styles */
:root {
  --primary-color: #3490dc;
  --secondary-color: #f6993f;
  --background-color: #f8fafc;
  --text-color: #2d3748;
  --border-color: #e2e8f0;
  --success-color: #38c172;
  --error-color: #e3342f;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.6;
  color: var(--text-color);
  background-color: var(--background-color);
  padding: 20px;
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  padding: 20px;
  display: flex;
  flex-direction: column;
  min-height: 90vh;
}

/* Two-column layout */
.two-column-layout {
  display: flex;
  gap: 20px;
  height: 70vh;
}

.chat-column {
  flex: 3;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Added */
}

.source-column {
  flex: 2;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

#source-viewer {
  background-color: #f9fafc;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 15px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#source-content {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  background-color: white;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  margin-top: 10px;
}

.placeholder-text {
  color: #a0aec0;
  font-style: italic;
  text-align: center;
  margin-top: 20px;
}

/* Source document styles */
.source-document {
  padding: 10px;
}

.source-document h4 {
  margin-bottom: 15px;
  color: var(--primary-color);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

.document-title-link {
  color: var(--primary-color);
  text-decoration: none;
  border-bottom: 1px dotted var(--primary-color);
  transition: color 0.2s, border-bottom 0.2s;
}

.document-title-link:hover {
  color: #2779bd;
  border-bottom: 1px solid #2779bd;
}

.source-document-content {
  line-height: 1.6;
  font-size: 0.95rem;
}

.error-message {
  color: var(--error-color);
  padding: 10px;
  background-color: #fff5f5;
  border-radius: 4px;
  border: 1px solid #fed7d7;
}

/* Chunk link styles */
.chunk-link {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: bold;
  padding: 2px 5px;
  border-radius: 3px;
  background-color: #ebf4ff;
  transition: background-color 0.2s;
}

.chunk-link:hover {
  background-color: #c3dafe;
  text-decoration: underline;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--border-color);
}

h1 {
  font-size: 2rem;
  margin-bottom: 10px;
  color: var(--primary-color);
}

/* Main content */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 20px;
  align-items: center;
}

/* Admin login */
.admin-login {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: white;
  padding: 15px;
  border-radius: 5px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  display: flex;
  gap: 5px;
}

.admin-login input {
  padding: 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 14px;
}

.admin-login button {
  padding: 8px 12px;
  font-size: 14px;
}

/* Admin status indicator */
.admin-status {
  position: fixed;
  bottom: 10px;
  right: 10px;
  background-color: var(--success-color);
  color: white;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  opacity: 0.8;
  z-index: 1000;
}

/* Hide delete buttons by default */
.delete-document-btn, .delete-chunk-btn {
  display: none;
}

/* Show delete buttons in admin mode */
body.admin-mode .delete-document-btn,
body.admin-mode .delete-chunk-btn {
  display: block;
}

.tab-button {
  background-color: transparent;
  color: var(--text-color);
  border: none;
  padding: 10px 20px;
  cursor: pointer;
  font-size: 16px;
  border-bottom: 2px solid transparent;
}

.tab-button.active {
  color: var(--primary-color);
  border-bottom: 2px solid var(--primary-color);
}

.tab-panel {
  display: none;
  flex: 1;
}

.tab-panel.active {
  display: flex;
  flex-direction: column;
}

/* Chat tab */
#chat-tab {
  display: flex;
  flex-direction: column;
  height: 100%;
}

#chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-bottom: 15px;
  overflow: hidden; /* Added */
}

#chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  background-color: #f9fafc;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  min-height: 0;       /* Added */
  /* Removed height: 100%; */
  /* Removed max-height: none; */
  display: flex;
  flex-direction: column;
}

.chat-input-container {
  display: flex;
  margin-top: 15px;
}

input[type="text"] {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px 0 0 4px;
  font-size: 16px;
}

button {
  background-color: var(--primary-color);
  color: white;
  border: none;
  padding: 12px 20px;
  cursor: pointer;
  font-size: 16px;
  transition: background-color 0.3s;
}

button:hover {
  background-color: #2779bd;
}

#send-button {
  border-radius: 0 4px 4px 0;
}

/* Chat messages */
.user-message, .ai-message, .system-message {
  padding: 10px 15px;
  margin-bottom: 10px;
  border-radius: 10px;
  max-width: 80%;
  word-wrap: break-word;
}

.user-message {
  background-color: var(--primary-color);
  color: white;
  align-self: flex-end;
}

.ai-message {
  background-color: #f1f5f8;
  color: var(--text-color);
  align-self: flex-start;
}

.system-message {
  background-color: #f8f9fa;
  color: #6c757d;
  border: 1px solid #e9ecef;
  margin: 10px auto;
  text-align: center;
  max-width: 90%;
}

/* Loading */
.hidden {
  display: none !important;
}

/* Admin mode styles */
.admin-login {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 300px;
}

.admin-login input {
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 16px;
  width: 100%;
}

.admin-login button {
  padding: 10px 15px;
  font-size: 16px;
  width: 100%;
}

#loading {
  text-align: center;
  margin: 20px 0;
}

.spinner {
  border: 4px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  border-top: 4px solid var(--primary-color);
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 0 auto 10px;
}

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

/* Sources */
#sources-container {
  margin: 15px 0;
  padding: 15px;
  background-color: #f9fafc;
  border: 1px solid var(--border-color);
  border-radius: 4px;
}

h2, h3 {
  font-size: 1.2rem;
  margin-bottom: 10px;
  color: var(--primary-color);
}

.document-section {
  margin-bottom: 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  overflow: hidden;
}

.document-header {
  padding: 1rem;
  background-color: #f8fafc;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: background-color 0.2s;
  position: relative;
}

.document-header:hover {
  background-color: #f1f5f8;
}

.toggle-icon {
  font-size: 0.8em;
  transition: transform 0.2s;
}

.chunks-container {
  padding: 0 1rem;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.5s ease-out;
  visibility: hidden;
  opacity: 0;
  transition: max-height 0.5s ease-out, opacity 0.3s ease-out, visibility 0s 0.3s;
}

.chunks-container.open {
  max-height: 10000px; /* Increased from 1000px to show more chunks */
  visibility: visible;
  opacity: 1;
  transition: max-height 0.5s ease-out, opacity 0.3s ease-out, visibility 0s;
}

.chunk-item {
  padding: 1rem 0;
  border-top: 1px solid #e2e8f0;
}

.chunk-item:first-child {
  border-top: none;
}

.chunk-preview {
  color: #4a5568;
  font-size: 0.875rem;
  line-height: 1.5;
}

/* Documents and Chunks */
#documents-tab, #chunks-tab {
  display: none;
  flex-direction: column;
}

#documents-tab.active, #chunks-tab.active {
  display: flex;
}

.document-section {
  margin-bottom: 1.5rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
}

.document-header {
  padding: 1rem;
  background-color: #f8fafc;
  font-weight: bold;
  color: var(--primary-color);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.document-header:hover {
  background-color: #f1f5f8;
}

.document-header {
  position: relative;
  padding-left: 1.5rem;
}

.toggle-icon {
  position: absolute;
  left: 0.5rem;
  transition: transform 0.2s ease;
}

.document-header.open .toggle-icon {
  transform: rotate(90deg);
}

.delete-document-btn {
  margin-left: auto;
  background-color: transparent;
  color: #e53e3e;
  font-size: 1rem;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.delete-document-btn:hover {
  background-color: #fed7d7;
}

/* This duplicate is removed as it conflicts with the earlier definition */

.chunk-item {
  padding: 1rem;
  margin-bottom: 0.75rem;
  background-color: #fff;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.chunk-title {
  font-size: 0.9rem;
  color: var(--primary-color);
  margin-bottom: 0.5rem;
}

.chunk-content {
  font-size: 0.9rem;
  color: #4a5568;
  line-height: 1.5;
}

/* Documents list and Chunks list */
#documents-list, #chunks-list {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: #f9fafc;
  min-height: 300px;
  max-height: 500px;
}

#all-chunks-container {
  margin-top: 30px;
  border-top: 1px solid var(--border-color);
  padding-top: 20px;
}

.mt-4 {
  margin-top: 1rem;
}

/* Pagination */
#pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 20px;
}

#pagination button {
  background-color: var(--primary-color);
  color: white;
  border: none;
  padding: 8px 15px;
  border-radius: 4px;
  cursor: pointer;
  margin: 0 10px;
}

#pagination button:disabled {
  background-color: #cbd5e0;
  cursor: not-allowed;
}

#page-info {
  font-size: 0.9rem;
}

/* Footer */
footer {
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid var(--border-color);
  color: #718096;
  font-size: 0.9rem;
  position: relative;
}

footer .prompt-suggestions-container {
  margin: 0 auto;
  text-align: center;
  max-width: 800px;
}

footer #prompt-suggestions {
  justify-content: center;
  margin-bottom: 30px; /* Add space for the admin button */
}

/* Admin toggle button */
.admin-toggle {
  position: absolute;
  right: 10px;
  bottom: 10px;
  background-color: transparent;
  color: #cbd5e0;
  border: none;
  font-size: 0.8rem;
  padding: 5px;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.2s;
}

.admin-toggle:hover {
  opacity: 1;
  color: var(--primary-color);
}

/* Prompt Suggestions */
.prompt-suggestions-container {
  margin: 15px 0;
}

.prompt-suggestions-container h4 {
  font-size: 0.9rem;
  color: #718096;
  margin-bottom: 10px;
}

#prompt-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 15px;
}

.prompt-suggestion {
  background-color: #f1f5f8;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 8px 15px;
  font-size: 0.9rem;
  color: var(--primary-color);
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.prompt-suggestion:hover {
  background-color: #e2e8f0;
  transform: translateY(-2px);
}

.prompt-suggestion:active {
  transform: translateY(0);
}

/* Responsive */
@media (max-width: 900px) {
  .two-column-layout {
    flex-direction: column;
    height: auto;
  }
  
  .chat-column, .source-column {
    flex: none;
    width: 100%;
  }
  
  .source-column {
    margin-top: 20px;
  }
  
  #chat-history {
    max-height: 400px;
  }
  
  #source-viewer {
    max-height: 300px;
  }
}

@media (max-width: 600px) {
  .app-container {
    padding: 15px;
  }
  
  .chat-input-container {
    flex-direction: column;
  }
  
  input[type="text"] {
    border-radius: 4px;
    margin-bottom: 10px;
  }
  
  #send-button {
    border-radius: 4px;
    width: 100%;
  }
  
  .tabs {
    overflow-x: auto;
  }
  
  #chat-history {
    min-height: 250px;
    max-height: 300px;
  }
  
  #source-viewer {
    max-height: 250px;
  }
}
