:root {
  --background-primary: #fafafa;
  --background-secondary: #f5f5f5;
  --background-tertiary: #e0e0e0;
  --text-primary: #212121;
  --text-secondary: #666;
  --text-tertiary: #999;
  --border-primary: #ddd;
  --border-secondary: #ccc;
  --highlight-primary: #007bff;
  --highlight-text: #fff;
  --button-dashed-border-blue: #2196f3;
  --button-dashed-text-blue: #1565c0;
  --button-dashed-border-orange: #ff9800;
  --button-dashed-text-orange: #e65100;
  --button-clear-background: #ffebee;
  --button-clear-text: #c62828;
  --tag-checked-background: #fff3e0;
  --paper-checked-background: #e3f2fd;
  --paper-added-background: #f0f0f0;

  --button-stop-border: #dc3545;
  --button-stop-background: #fff;
  --button-stop-text: #dc3545;
  --button-clear-border: #6c757d;
  --button-save-border: #28a745;
  --button-save-background: #fff;
  --button-save-text: #28a745;
  --image-preview-background: #f0f8ff;
  --image-preview-border: #03a9f4;
  --image-preview-text: #0288d1;
  --message-user-background: #e3f2fd;
  --message-user-text: #1976d2;
  --message-assistant-background: #f5f5f5;
  --message-assistant-text: #424242;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background-primary: #333;
    --background-secondary: #2a2a2a;
    --background-tertiary: #424242;
    --text-primary: #eee;
    --text-secondary: #bbb;
    --text-tertiary: #888;
    --border-primary: #555;
    --border-secondary: #666;
    --highlight-primary: #0088ff;
    --highlight-text: #fff;
    --button-dashed-border-blue: #4dabf5;
    --button-dashed-text-blue: #4dabf5;
    --button-dashed-border-orange: #ffc94d;
    --button-dashed-text-orange: #ffc94d;
    --button-clear-background: #5c1f1f;
    --button-clear-text: #f48a8a;
    --tag-checked-background: #6d4d00;
    --paper-checked-background: #0d47a1;
    --paper-added-background: #424242;

    --button-stop-border: #e57373;
    --button-stop-background: #333;
    --button-stop-text: #e57373;
    --button-clear-border: #90a4ae;
    --button-save-border: #81c784;
    --button-save-background: #333;
    --button-save-text: #81c784;
    --image-preview-background: #012a3f;
    --image-preview-border: #4fc3f7;
    --image-preview-text: #4fc3f7;
    --message-user-background: #0d47a1;
    --message-user-text: #bbdefb;
    --message-assistant-background: #424242;
    --message-assistant-text: #eee;
  }
}

body.dark,
:root[data-theme="dark"],
html.dark {
  --background-primary: #333;
  --background-secondary: #2a2a2a;
  --background-tertiary: #424242;
  --text-primary: #eee;
  --text-secondary: #bbb;
  --text-tertiary: #888;
  --border-primary: #555;
  --border-secondary: #666;
  --highlight-primary: #0088ff;
  --highlight-text: #fff;
  --button-dashed-border-blue: #4dabf5;
  --button-dashed-text-blue: #4dabf5;
  --button-dashed-border-orange: #ffc94d;
  --button-dashed-text-orange: #ffc94d;
  --button-clear-background: #5c1f1f;
  --button-clear-text: #f48a8a;
  --tag-checked-background: #6d4d00;
  --paper-checked-background: #0d47a1;
  --paper-added-background: #424242;

  --button-stop-border: #e57373;
  --button-stop-background: #333;
  --button-stop-text: #e57373;
  --button-clear-border: #90a4ae;
  --button-save-border: #81c784;
  --button-save-background: #333;
  --button-save-text: #81c784;
  --image-preview-background: #012a3f;
  --image-preview-border: #4fc3f7;
  --image-preview-text: #4fc3f7;
  --message-user-background: #0d47a1;
  --message-user-text: #bbdefb;
  --message-assistant-background: #424242;
  --message-assistant-text: #eee;
}

.makeItRed {
  background-color: tomato;
}

.chip {
  color: var(--text-primary);
}

.chip-items {
  background-color: #e3f2fd;
  border-color: #2196f3;
}

.chip-creators {
  background-color: #f3e5f5;
  border-color: #9c27b0;
}

.chip-tags {
  background-color: #fff3e0;
  border-color: #ff9800;
}

.chip-collections {
  background-color: #e8f5e9;
  border-color: #4caf50;
}

.chip-notes {
  background-color: #fffde7;
  border-color: #ffeb3b;
}

.chip-notes-summary {
  background-color: #fffde7;
  border: 1px solid #ffeb3b;
}

.chip-attachments {
  background-color: #fce4ec;
  border-color: #e91e63;
}

.chip-images {
  background-color: #e1f5fe;
  border-color: #03a9f4;
}

.chip-tables {
  background-color: #f3e5f5;
  border-color: #7b1fa2;
}

/* Dark mode chip overrides (Class/Attribute) */
body.dark .chip-items,
:root[data-theme="dark"] .chip-items,
html.dark .chip-items {
  background-color: #0d47a1;
  border-color: #4dabf5;
  color: #fff;
}

body.dark .chip-creators,
:root[data-theme="dark"] .chip-creators,
html.dark .chip-creators {
  background-color: #4a148c;
  border-color: #ab47bc;
  color: #fff;
}

body.dark .chip-tags,
:root[data-theme="dark"] .chip-tags,
html.dark .chip-tags {
  background-color: #6d4d00;
  border-color: #ffc94d;
  color: #fff;
}

body.dark .chip-collections,
:root[data-theme="dark"] .chip-collections,
html.dark .chip-collections {
  background-color: #1b5e20;
  border-color: #66bb6a;
  color: #fff;
}

body.dark .chip-notes,
:root[data-theme="dark"] .chip-notes,
html.dark .chip-notes {
  background-color: #fff59d;
  border-color: #ffc107;
  color: #000;
}

body.dark .chip-notes-summary,
:root[data-theme="dark"] .chip-notes-summary,
html.dark .chip-notes-summary {
  background-color: #fff59d;
  border: 1px solid #ffc107;
  color: #000;
}

body.dark .chip-attachments,
:root[data-theme="dark"] .chip-attachments,
html.dark .chip-attachments {
  background-color: #880e4f;
  border-color: #f06292;
  color: #fff;
}

body.dark .chip-images,
:root[data-theme="dark"] .chip-images,
html.dark .chip-images {
  background-color: #01579b;
  border-color: #4fc3f7;
  color: #fff;
}

body.dark .chip-tables,
:root[data-theme="dark"] .chip-tables,
html.dark .chip-tables {
  background-color: #4a148c;
  border-color: #ab47bc;
  color: #fff;
}

/* Dark mode chip overrides - media query fallback for sidebar panels */
@media (prefers-color-scheme: dark) {
  .chip-items {
    background-color: #0d47a1;
    border-color: #4dabf5;
    color: #fff;
  }

  .chip-creators {
    background-color: #4a148c;
    border-color: #ab47bc;
    color: #fff;
  }

  .chip-tags {
    background-color: #6d4d00;
    border-color: #ffc94d;
    color: #fff;
  }

  .chip-collections {
    background-color: #1b5e20;
    border-color: #66bb6a;
    color: #fff;
  }

  .chip-notes {
    background-color: #fff59d;
    border-color: #ffc107;
    color: #000;
  }

  .chip-notes-summary {
    background-color: #fff59d;
    border: 1px solid #ffc107;
    color: #000;
  }

  .chip-attachments {
    background-color: #880e4f;
    border-color: #f06292;
    color: #fff;
  }

  .chip-images {
    background-color: #01579b;
    border-color: #4fc3f7;
    color: #fff;
  }

  .chip-tables {
    background-color: #4a148c;
    border-color: #ab47bc;
    color: #fff;
  }
}

.message-user {
  background-color: var(--message-user-background);
  color: var(--message-user-text);
  box-sizing: border-box;
}

.message-assistant {
  background-color: var(--message-assistant-background);
  color: var(--message-assistant-text);
  box-sizing: border-box;
}

/* Ensure message bubbles never shrink/truncate when new messages are added.
   The messages area is a flex-column scroll container; bubbles must keep their
   intrinsic height and let the container scroll instead. */
.message-bubble {
  box-sizing: border-box;
  min-width: 0;
  flex-shrink: 0;
  overflow-wrap: break-word;
  word-break: break-word;
}

.message-bubble.message-user {
  max-width: 90%;
}

.message-bubble.message-assistant {
  max-width: 100%;
}

.message-bubble [data-content] {
  overflow-x: auto;
  overflow-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
  min-width: 0;
}

/* Tab Bar Styles */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-primary);
  background-color: var(--background-secondary);
  border-radius: 6px 6px 0 0;
  overflow: hidden;
  min-width: 0;
}

.tab-item {
  padding: 4px 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background-color: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  transition: all 0.2s ease;
  flex: 1;
  text-align: center;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab-item:hover {
  background-color: var(--background-tertiary);
  color: var(--text-primary);
}

.tab-item.active {
  color: var(--highlight-primary);
  border-bottom-color: var(--highlight-primary);
  background-color: var(--background-primary);
}

/* Papers Table Styles */
.papers-table-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.table-toolbar {
  display: flex;
  gap: 8px;
  padding: 8px;
  background-color: var(--background-secondary);
  border-bottom: 1px solid var(--border-primary);
  align-items: center;
  flex-wrap: wrap;
  flex-shrink: 0;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.table-search-input {
  flex: 1;
  min-width: 60px;
  padding: 6px 10px;
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  font-size: 12px;
  background-color: var(--background-primary);
  color: var(--text-primary);
  box-sizing: border-box;
}

.table-search-input::placeholder {
  color: var(--text-tertiary);
}

.table-btn {
  padding: 6px 12px;
  font-size: 11px;
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  background-color: var(--background-primary);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.table-btn:hover {
  background-color: var(--background-tertiary);
}

.table-btn-primary {
  background-color: var(--highlight-primary);
  color: var(--highlight-text);
  border-color: var(--highlight-primary);
}

.table-btn-primary:hover {
  opacity: 0.9;
}

/* Table Wrapper */
.table-wrapper {
  flex: 1;
  overflow: auto;
  background-color: var(--background-primary);
  min-width: 0;
}

.papers-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: fixed;
  max-width: 100%;
}

.papers-table th {
  position: sticky;
  top: 0;
  background-color: var(--background-secondary);
  border-bottom: 1px solid var(--border-primary);
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.papers-table th:hover {
  background-color: var(--background-tertiary);
}

.papers-table th.sortable::after {
  content: "";
  display: inline-block;
  margin-left: 4px;
  width: 0;
  height: 0;
  vertical-align: middle;
}

.papers-table th.sort-asc::after {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 4px solid var(--text-primary);
}

.papers-table th.sort-desc::after {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid var(--text-primary);
}

.column-resize-handle {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  cursor: col-resize;
  background-color: transparent;
}

.column-resize-handle:hover {
  background-color: var(--highlight-primary);
}

.papers-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-primary);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.papers-table tr:hover td {
  background-color: var(--background-secondary);
}

.papers-table tr.selected td {
  background-color: var(--paper-checked-background);
}

/* Table Empty State */
.table-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-tertiary);
  text-align: center;
  gap: 8px;
}

.table-empty-state-icon {
  font-size: 32px;
  opacity: 0.5;
}

.table-empty-state-text {
  font-size: 13px;
}

/* Response Length Slider */
.response-length-container {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background-color: var(--background-tertiary);
  border-radius: 4px;
}

.response-length-label {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.response-length-slider {
  width: 80px;
  cursor: pointer;
}

.response-length-value {
  font-size: 11px;
  color: var(--text-primary);
  min-width: 30px;
}

/* Column Manager Modal */
.column-manager-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 300px;
  overflow-y: auto;
}

.column-manager-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 4px;
  background-color: var(--background-secondary);
}

.column-manager-item:hover {
  background-color: var(--background-tertiary);
}

.column-manager-item label {
  flex: 1;
  font-size: 13px;
  cursor: pointer;
}

.column-manager-item input[type="checkbox"] {
  cursor: pointer;
}

/* Chat Markdown Styling */
.chat-md-table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 0.95em;
  background-color: var(--background-primary);
  table-layout: auto;
}

.chat-md-th {
  border: 1px solid var(--border-primary);
  padding: 8px;
  background-color: var(--background-secondary);
  text-align: left;
  color: var(--text-primary);
  word-break: break-word;
}

.chat-md-td {
  border: 1px solid var(--border-primary);
  padding: 8px;
  color: var(--text-primary);
  word-break: break-word;
}

.chat-md-code {
  background-color: var(--background-tertiary);
  padding: 2px 4px;
  border-radius: 3px;
  font-family: monospace;
  font-size: 0.9em;
  color: var(--text-primary);
  word-break: break-all;
}

/* Markdown content container - ensure content fits within parent */
.markdown-content {
  overflow-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
}

.chat-md-pre {
  background-color: var(--background-tertiary);
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
  font-family: monospace;
  font-size: 0.9em;
  margin: 8px 0;
  color: var(--text-primary);
  max-width: 100%;
  box-sizing: border-box;
  white-space: pre-wrap;
  word-break: break-all;
}

.chat-md-link {
  color: var(--highlight-primary);
  text-decoration: underline;
}

.chat-md-quote {
  border-left: 3px solid var(--border-primary);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-secondary);
  font-style: italic;
}

.chat-md-hr {
  border: none;
  border-top: 1px solid var(--border-primary);
  margin: 16px 0;
}

.chat-md-em-title {
  color: var(--highlight-primary);
}

/* Firecrawl Settings Popover */
.firecrawl-popover {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  background-color: var(--background-primary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  min-width: 200px;
  color: var(--text-primary);
}

.firecrawl-input {
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  background-color: var(--background-secondary);
  color: var(--text-primary);
}

.chat-md-h1 {
  font-size: 1.5em;
  font-weight: 700;
  margin: 12px 0 8px 0;
}

.chat-md-h2 {
  font-size: 1.3em;
  font-weight: 700;
  margin: 12px 0 8px 0;
}

.chat-md-h3 {
  font-size: 1.15em;
  font-weight: 600;
  margin: 12px 0 8px 0;
}

.chat-md-h4 {
  font-size: 1.05em;
  font-weight: 600;
  margin: 12px 0 8px 0;
}

.chat-md-h5 {
  font-size: 1em;
  font-weight: 600;
  margin: 12px 0 8px 0;
}

.chat-md-h6 {
  font-size: 0.95em;
  font-weight: 600;
  margin: 12px 0 8px 0;
}

.chat-md-ul {
  margin: 8px 0;
  padding-left: 20px;
}

.chat-md-ol {
  margin: 8px 0;
  padding-left: 20px;
}

.chat-md-li {
  margin: 4px 0;
}

.chat-md-paragraph {
  margin: 4px 0;
}

.chat-md-paragraph-break {
  height: 8px;
}

.context-action-btn {
  border-radius: 12px;
  padding: 3px 10px;
  font-size: 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  transition: background-color 0.2s ease;
  gap: 4px;
}

/* ==================== Prompt Library Styles ==================== */

.prompt-picker-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 10000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 100px;
}

.prompt-picker-container {
  background: var(--background-primary);
  border: 1px solid var(--border-primary);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  max-width: 400px;
  max-height: 500px;
  overflow: hidden;
}

.prompt-card {
  padding: 10px 12px;
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--background-primary);
}

.prompt-card:hover {
  border-color: var(--border-secondary);
  background: var(--background-secondary);
}

.prompt-card.selected {
  border-color: var(--highlight-primary);
  background: var(--paper-checked-background);
}

/* ==================== Placeholder Dropdown Styles ==================== */

#placeholder-dropdown {
  background: var(--background-primary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

/* ==================== History Popover Styles ==================== */

.history-popover {
  animation: slide-up 0.2s ease-out;
}

.history-list::-webkit-scrollbar {
  width: 6px;
}

.history-list::-webkit-scrollbar-thumb {
  background-color: var(--border-secondary);
  border-radius: 3px;
}

.history-item {
  transition: background 0.2s ease;
}

.history-item:hover {
  background-color: var(--background-secondary) !important;
}

.history-item.active {
  background-color: var(--paper-checked-background) !important;
  border-left: 3px solid var(--highlight-primary) !important;
}

.history-item .delete-btn:hover {
  color: #ff4444;
  transform: scale(1.1);
}

@keyframes slide-up {
  from {
    transform: translateY(10px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.history-item.active {
  background-color: var(--background-primary) !important;
  border-left: 3px solid var(--highlight-primary);
}

.history-item:hover .delete-btn {
  display: block !important;
}

.delete-btn {
  opacity: 0.6;
  transition:
    opacity 0.2s,
    color 0.2s;
}

.delete-btn:hover {
  opacity: 1;
  color: #dc3545 !important;
}

.new-chat-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.new-chat-btn:active {
  transform: translateY(0);
}

/* Scrollbar styling for history list */
.history-list::-webkit-scrollbar {
  width: 6px;
}

.history-list::-webkit-scrollbar-track {
  background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
  background: var(--border-primary);
  border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

.placeholder-item:hover {
  background: var(--paper-checked-background);
}

.placeholder-item.selected {
  background: var(--paper-checked-background);
}

/* Dark mode overrides for prompt library */
@media (prefers-color-scheme: dark) {
  .prompt-picker-overlay {
    background: rgba(0, 0, 0, 0.5);
  }

  .prompt-card:hover {
    background: var(--background-tertiary);
  }
}

body.dark .prompt-picker-overlay,
:root[data-theme="dark"] .prompt-picker-overlay,
html.dark .prompt-picker-overlay {
  background: rgba(0, 0, 0, 0.5);
}

body.dark .prompt-card:hover,
:root[data-theme="dark"] .prompt-card:hover,
html.dark .prompt-card:hover {
  background: var(--background-tertiary);
}
