/* In index.css */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f7f7f8;
  --bg-overlay: rgba(247, 247, 248, 0.9); /* 90% opacity white */
  --bg-tertiary: #ececf1;
  --text-primary: #0d0d0d;
  --text-secondary: #676767;
  --text-tertiary: #8e8ea0;
  --border-light: #e5e5e5;
  --accent: #10a37f;
  --danger: #ef4444;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  --radius: 8px;
}
[data-theme="dark"] {
  --bg-primary: #212121;
  --bg-secondary: #2f2f2f;
  --bg-overlay: rgba(47, 47, 47, 0.9); /* 90% opacity dark */
  --bg-tertiary: #404040;
  --text-primary: #ececec;
  --text-secondary: #c5c5c5;
  --border-light: #4a4a4a;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
}
/* --- Layout --- */
.main-content {
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: 61px;
  transition: margin-left 0.3s ease, margin-right 0.3s ease;
}

.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  background-color: var(--bg-primary);
}
.menu-button {
  position: relative;
  background: none;
  border: none;
  padding: 8px;
  margin-right: 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
}
.header-title {
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 12px; /* A bit more padding */
  border-radius: var(--radius);
  transition: color 0.2s, background-color 0.2s, border-color 0.2s;
  margin-left: 0; /* Remove the negative margin */
  /* --- STATIC BUTTON STYLES --- */
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-light);
  color: var(--text-secondary); /* Make it look like a button, not a title */
}
.header-title:hover {
  color: var(--accent);
  background-color: var(--bg-tertiary); /* Darken the bg on hover */
  border-color: var(--accent); /* Add accent border on hover */
}
.chat-area-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 768px;
  min-width: 0;
  margin: 0 auto;
  width: 100%;
  overflow-y: auto;
}
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}
/* Wrapper to hold chat and panel side-by-side */
.content-wrapper {
  flex: 1;
  display: flex;
  width: 100%;
  max-width: 1200px; /* Wider max-width to accommodate the panel */
  margin: 0 auto;
  overflow: hidden;
}
/* Document Panel Styles */
#page-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 950; /* Below sidebars (1000) but above content */
}
#page-overlay.visible {
  opacity: 1;
  pointer-events: all;
}
.document-panel-container {
  position: fixed;
  top: 61px; /* Height of the header */
  right: 0;
  bottom: 0;
  /* The width also uses our new variable */
  width: var(--document-panel-width, 320px);
  z-index: 500; /* Below modals but above content */
  border-left: 1px solid var(--border-light);
  background-color: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease, opacity 0.05s ease;
  transform: translateX(100%); /* Start off-screen */
}
/* --- STYLES FOR RESIZER AND REOPEN BUTTON --- */
/* The draggable handle */
#panel-resizer {
  position: fixed;
  top: 61px;
  bottom: 0;
  /* Positioned to the left of the panel */
  right: var(--document-panel-width, 320px);
  width: 8px; /* Makes it easier to grab */
  cursor: ew-resize; /* The classic resize cursor */
  z-index: 501; /* On top of the panel border */
  /* This makes the clickable area 8px wide without changing its visual position */
  transform: translateX(50%);
}
/* This creates the visible "pill" handle in the middle of the resizer */
#panel-resizer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 4px;
  height: 40px;
  background-color: var(--border-light);
  border-radius: 4px;
  transition: background-color 0.2s;
}

#panel-resizer:hover::after {
  background-color: var(--accent); /* Highlights on hover */
}

/* The button to reopen the panel when it's closed */
#reopen-panel-btn {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  z-index: 499;
  background-color: var(--accent);
  color: white;
  border: none;
  width: 32px;
  height: 60px;
  border-radius: 8px 0 0 8px; /* Rounded on the left side */
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: background-color 0.2s;
}

#reopen-panel-btn:hover {
  filter: brightness(1.1);
}

.document-panel-container.visible {
  transform: translateX(0); /* Slide into view */
}

.document-panel-container.hidden {
  display: flex;
  transform: translateX(100%);
}

.doc-panel-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.doc-panel-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.doc-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.doc-panel-empty {
  padding: 24px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.doc-file-item {
  background: var(--bg-primary);
  border-radius: var(--radius);
  margin-bottom: 8px;
  border: 1px solid var(--border-light);
  overflow: hidden;
}

.doc-file-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  cursor: pointer;
}

.doc-file-icon {
  font-size: 1.1rem;
  color: var(--text-secondary);
}

.doc-file-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
  white-space: normal;
  word-break: break-all;
  /*overflow: hidden; fix bug for right bar*/
}

.doc-file-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-weight: bold;
  transition: transform 0.2s;
}

.doc-file-item.open .doc-file-toggle {
  transform: rotate(180deg);
}

.doc-file-summary {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out, padding 0.3s ease-out;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-secondary);
  background: var(--bg-secondary);
}

.doc-file-item.open .doc-file-summary {
  max-height: 500px; /* An arbitrary large value */
  padding: 12px;
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
}

.summary-content-wrapper {
  padding-bottom: 8px;
  overflow-y: auto;
}
.summary-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
/* End hold chat and panel side-by-side*/
.carousel-section {
  margin-bottom: 24px;
}
.carousel-section h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  padding-left: 4px;
}
.carousel-section-wrapper {
  position: relative;
}

.task-carousel-container.active {
  cursor: grabbing;
  cursor: -webkit-grabbing;
  transform: scale(1.01); /* Slight lift effect when dragging */
}

.carousel-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  background-color: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border-light);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.carousel-nav-btn:hover {
  background-color: white;
  color: var(--text-primary);
  transform: translateY(-50%) scale(1.1);
}

.carousel-nav-btn.left {
  left: -18px;
}

.carousel-nav-btn.right {
  right: -18px;
}

[data-theme="dark"] .carousel-nav-btn {
  background-color: rgba(60, 60, 60, 0.9);
}
[data-theme="dark"] .carousel-nav-btn:hover {
  background-color: var(--bg-tertiary);
}

/* Status colors are no longer needed on the card itself */
.task-card-status {
  display: none;
}
.task-carousel-container {
  display: flex;
  overflow-x: auto;
  padding: 16px 0;
  gap: 12px;
  /* Hides the scrollbar but keeps it scrollable */
  scrollbar-width: none; /* For Firefox */
  -ms-overflow-style: none; /* For Internet Explorer and Edge */
}

.task-carousel-container::-webkit-scrollbar {
  display: none; /* For Chrome, Safari, and Opera */
}

.task-card {
  flex: 0 0 280px; /* Prevents cards from shrinking, sets a fixed width */
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: var(--shadow-sm);
  cursor: grab;
}

.task-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}

.task-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.task-card-status {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: var(--radius-full);
  color: #fff;
  background-color: #888; /* Default color */
}

/* Status-specific colors */
.task-card-status.trễ-hạn {
  background-color: #e53e3e;
}
.task-card-status.mới-hôm-nay {
  background-color: #3b82f6;
}
.task-card-status.ưu-tiên {
  background-color: #f59e0b;
}
.task-card-status.sắp-tới-hạn {
  background-color: #8b5cf6;
}
.task-card-status.khác {
  background-color: #6b7280;
}

.task-card-title {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.4;
  margin: 0 0 16px 0;
  flex-grow: 1; /* Allows title to take available space */
  color: var(--text-primary);
}

.task-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border-light);
  padding-top: 12px;
  margin-top: auto; /* Pushes footer to the bottom */
}

.task-card-due-date {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.task-card-button {
  /* Inherits from .chat-action-button, but we can add overrides */
  padding: 10px 18px;
  font-size: 1.1rem;
  min-width: 115px;
  min-height: 35px;
  background-color: var(--accent-primary);
  color: white;
  border: none;
}
.task-card-button:hover {
  background-color: var(--accent-primary-hover);
}
/* --- Sidebar --- */
.sidebar {
  position: fixed;
  left: 0;
  top: 61px;
  width: 260px;
  height: calc(100vh - 61px);
  background: var(--bg-secondary);
  padding: 12px;
  z-index: 1000;
  border-right: 1px solid var(--border-light);
  transform: translateX(-100%);
  transition: transform 0.3s;
  display: flex;
  flex-direction: column;
  overflow-y: auto; /* <-- Enables scrolling when needed */
  /* ---  Hides the scrollbar visually --- */
  scrollbar-width: none; /* For Firefox */
  -ms-overflow-style: none; /* For Internet Explorer and Edge */
}

/* --- Hides scrollbar for Chrome/Safari --- */
.sidebar::-webkit-scrollbar {
  display: none;
}
/* --- Makes the top button section grow --- */
/* This pushes the settings to the bottom, just like 'space-between' did */
.sidebar > div:first-of-type {
  flex-grow: 1;
}

.sidebar.open {
  transform: translateX(0);
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.sidebar-logo-img {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  object-fit: cover;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--text-primary);
}
.close-sidebar {
  border: 1px solid #374047;
  border-radius: 3px;
  background-color: var(--bg-secondary);
  color: #0f161b;
  padding: 3px 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.close-sidebar:hover {
  background-color: #0078d4;
  color: #fff;
  box-shadow: 0 0 6px rgba(0, 120, 212, 0.6);
}
.sidebar-button .icon {
  width: 18px;
  height: 18px;
  stroke-width: 2;
  flex-shrink: 0;
}
.sidebar-button {
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.sidebar-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.sidebar-button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.sidebar-button:active {
  transform: scale(0.98);
  filter: brightness(0.95);
}
.sidebar-settings {
  border-top: 1px solid var(--border-light);
  padding-top: 12px;
}

.volume-slider-container {
  position: relative; /* Crucial for positioning the tooltip */
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

#notification-volume {
  flex: 1;
}

.volume-tooltip {
  position: absolute;
  bottom: 100%; /* Position it above the slider */
  left: 50%;
  transform: translateX(-50%); /* Center it horizontally */
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: bold;
  opacity: 0; /* Hidden by default */
  pointer-events: none; /* Can't be clicked */
  transition: opacity 0.2s;
  margin-bottom: 8px;
}

.volume-tooltip.visible {
  opacity: 1; /* Show it when dragging */
}
#volume-value {
  font-weight: bold;
  min-width: 24px;
  text-align: center;
}

.automation-setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px;
  font-size: 13px;
}
#auto-scan-interval {
  width: 60px;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--border-light);
  background: var(--bg-primary);
  color: var(--text-primary);
  text-align: center;
}
#save-automation-settings {
  margin-top: 12px;
}
#automation-status {
  margin-top: 8px;
  font-size: 12px;
  text-align: center;
}
/* Styles for the toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-tertiary);
  transition: 0.4s;
}
.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.4s;
}
input:checked + .slider {
  background-color: var(--accent);
}
input:focus + .slider {
  box-shadow: 0 0 1px var(--accent);
}
input:checked + .slider:before {
  transform: translateX(20px);
}
.slider.round {
  border-radius: 24px;
}
.slider.round:before {
  border-radius: 50%;
}

/* Sidebar Panel*/
.sidebar-panel {
  /* This is no longer position: absolute */
  position: relative;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 8px; /* A small gap between the button and the panel */
  box-shadow: var(--shadow);
  animation: slideDOwnFadeIn 0.5s ease-out;
}

.panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}

.panel-empty-text {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 8px 0;
}

/* This is the new scrollable box container */
.panel-list-container {
  max-height: 220px;
  overflow-y: auto;
}

.panel-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.panel-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 4px;
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  transition: background-color 0.2s;
}

.panel-item:hover {
  background-color: var(--accent);
  color: white;
}

.panel-item-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.panel-delete-btn {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  opacity: 0.6;
}

.panel-item:hover .panel-delete-btn {
  color: white;
  opacity: 1;
}

.delete-all-btn {
  width: 100%;
  margin-top: 8px;
  padding: 8px;
  background-color: var(--danger);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.panel-item.file-item {
  gap: 8px; /* Add some space between the icon and the name */
}
.file-preview-image {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0; /* Prevent image from shrinking */
}

.file-preview-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  color: var(--text-tertiary);
}
/* --- Welcome Screen & Bubbles --- */
.welcome-subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-top: -16px;
  margin-bottom: 24px;
  max-width: 450px;
}

.core-functions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
  align-items: center;
}

.function-item {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 400px;
  border: 1px solid transparent;
}
.function-icon {
  font-size: 1.2rem;
}

.function-text {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
}
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
}
.welcome-title {
  font-size: 32px;
  font-weight: 600;
  margin-bottom: 24px;
  color: var(--text-primary);
}
.suggestions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 450px;
}
/* Styles for 2-column layout */
.suggestions.suggestions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.suggestion.suggestion-stretch {
  grid-column: span 2; /* Make the last odd item stretch across 2 columns */
}
.suggestion {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s;
}
.suggestion:hover {
  border-color: var(--accent);
}
.suggestion-title {
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text-primary);
}
.suggestion-desc {
  font-size: 14px;
  color: var(--text-secondary);
}

/* --- Chat Messages --- */
.message {
  margin-bottom: 24px;
  display: flex;
  gap: 16px;
}
.message.user {
  flex-direction: row-reverse;
}
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.avatar.user {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}
.avatar.assistant {
  background: var(--accent);
  color: white;
}
.message-content {
  padding: 12px 16px;
  border-radius: 18px;
  max-width: 80%;
}
.message.user .message-content {
  background: var(--bg-tertiary);
}
.message-text {
  line-height: 1.5;
  word-wrap: break-word;
  color: var(--text-primary);
}
.message-files {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
  border-top: 1px solid var(--border-light);
  padding-top: 8px;
}

/* --- Input Area --- */
.input-container {
  padding: 12px 20px 20px 20px;
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
}
.input-wrapper {
  position: relative;
  max-width: 768px;
  margin: 0 auto;
}
.input-box {
  display: flex;
  align-items: center;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 4px 8px;
}
.input-box:focus-within {
  border-color: var(--accent);
}
.input-textarea {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  resize: none;
  padding: 8px;
  font-size: 16px;
  color: var(--text-primary);
  max-height: 200px;
}
.action-button {
  background: none;
  border: none;
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.action-button svg {
  width: 20px;
  height: 20px;
  stroke-width: 2; /* Thinner stroke for a sleeker look */
}
.send-button {
  background: var(--accent);
  color: white;
}
.send-button:disabled {
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  cursor: not-allowed;
}
.file-preview {
  margin-bottom: 12px;
}
.file-preview-title {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 12px;
}
.file-remove {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
}
/* --- Search Source Selector --- */
#search-source-selector {
  display: flex; /* Helps align the button */
  position: relative; /* Anchors the pop-up menu */
}

.search-source-button {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.search-source-button:hover {
  border-color: var(--accent);
}

/* style for the green 'Search Source' button */
.search-source-button.search-source-button-primary {
  background-color: var(--accent);
  color: white;
  border-color: var(--accent);
}

.source-menu {
  position: absolute;
  bottom: 100%; /* Position it to pop UP from the button */
  left: 0; /* Align to the relative parent */
  margin-bottom: 4px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
  z-index: 102; /* Make sure it appears on top of other content */
}

.source-menu-item {
  display: flex;
  align-items: center;
  padding: 6px;
  font-size: 14px;
  white-space: nowrap;
}

.source-menu-item label {
  margin-left: 8px;
  cursor: pointer;
}
/* --- Drag Overlay: HIDDEN BY DEFAULT --- */
.drag-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.drag-overlay.show {
  display: flex;
}
.drag-content {
  background: var(--bg-primary);
  border: 2px dashed var(--accent);
  border-radius: 12px;
  padding: 40px;
  text-align: center;
}
/* ----- Bot typing indicator ----- */
.typing-indicator {
  display: inline-flex; /* Keeps the bubble tight around the dots */
  align-items: center;
  justify-content: center;
  padding: 12px 16px; /* Padding for the bubble */
  background: var(--bg-secondary); /* Matches other bot messages */
  border-radius: 18px; /* Rounded corners */
  border-bottom-left-radius: 2px; /* Makes it look like a message bubble */
  margin-top: 4px;
  width: fit-content; /* Ensures it doesn't stretch */
}

.typing-indicator div {
  width: 8px;
  height: 8px;
  background-color: var(--text-tertiary); /* Uses your theme color */
  border-radius: 50%;
  margin: 0 3px;
  animation: typing-bounce 1.4s infinite ease-in-out both;
}

.typing-indicator div:nth-child(1) {
  animation-delay: -0.32s;
}
.typing-indicator div:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes typing-bounce {
  0%,
  80%,
  100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}
/* --- In-Message Action Buttons --- */
.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  justify-content: flex-start;
}

.chat-action-button {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-light);
  color: var(--accent);
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chat-action-button:hover:not(:disabled) {
  background-color: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: translateY(-1px);
}

.chat-action-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  background-color: var(--bg-tertiary) !important;
  color: var(--text-tertiary) !important;
  border-color: var(--border-light) !important;
}

/* --- Manual Adjustment Form Modal --- */
#form-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3000;
  pointer-events: none;
}
.form-modal-overlay.hidden {
  display: none;
}
.form-modal {
  position: absolute;
  background: var(--bg-primary);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-light);

  width: 800px; /* Initial width */
  height: 700px; /* Initial height */
  min-width: 450px; /* Prevent it from getting too small */
  min-height: 400px; /* Prevent it from getting too small */

  display: flex;
  flex-direction: column;
  overflow: hidden; /* VERY IMPORTANT for rounded corners and resize */
  pointer-events: all; /* The window itself is clickable */
}
/* --- Window Header (for dragging and controls) --- */
.form-window-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-light);
  cursor: move; /* The cursor indicates it's draggable */
  flex-shrink: 0;
}
.form-window-title {
  font-weight: 600;
  font-size: 14px;
}
.form-window-controls {
  display: flex;
  gap: 4px;
}
.window-control-btn {
  background: none;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.window-control-btn:hover {
  background: var(--bg-tertiary);
}
.window-control-btn.close:hover {
  background: #e81123;
  color: white;
}
/* Add padding back to header and actions */
.form-actions {
  padding: 12px 24px;
  flex-shrink: 0;
  border-top: 1px solid var(--border-light);
  background-color: var(--bg-secondary);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}
/* New container will hold all the form groups and will be the scrollable area */
.form-modal-body {
  flex-grow: 1; /* Take up all available vertical space */
  overflow-y: auto; /* Add scrollbar ONLY when content overflows */
  padding: 16px 24px;
}
#manual-adjust-form {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  /* prevents the form from overflowing the modal window */
  overflow: hidden;
}
.multi-select-container {
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 8px;
  height: 180px;
  max-height: 360px;
  min-height: 100px;
  overflow: auto;
  resize: vertical;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}
.resizer {
  position: absolute;
  background: transparent;
}
.resizer.right {
  width: 5px;
  top: 0;
  right: 0;
  bottom: 0;
  cursor: ew-resize;
}
.resizer.left {
  width: 5px;
  top: 0;
  left: 0;
  bottom: 0;
  cursor: ew-resize;
}
.resizer.top {
  height: 5px;
  top: 0;
  left: 0;
  right: 0;
  cursor: ns-resize;
}
.resizer.bottom {
  height: 5px;
  bottom: 0;
  left: 0;
  right: 0;
  cursor: ns-resize;
}
.resizer.top-left {
  width: 10px;
  height: 10px;
  top: 0;
  left: 0;
  cursor: nwse-resize;
}
.resizer.top-right {
  width: 10px;
  height: 10px;
  top: 0;
  right: 0;
  cursor: nesw-resize;
}
.resizer.bottom-left {
  width: 10px;
  height: 10px;
  bottom: 0;
  left: 0;
  cursor: nesw-resize;
}
.resizer.bottom-right {
  width: 10px;
  height: 10px;
  bottom: 0;
  right: 0;
  cursor: nwse-resize;
}
.form-modal.minimized {
  display: none; /* Hide the window when minimized */
}
.restore-widget {
  position: fixed;
  bottom: 20px;
  left: 20px;
  background: var(--accent);
  color: white;
  padding: 10px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 3001;
  font-size: 14px;
  animation: fadeIn 0.3s;
}

/* Allow textareas inside the form to be resized vertically by the user */
.form-modal .input-textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.form-select {
  width: 100%;
  padding: 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 14px;
}
.form-select:focus {
  outline: none;
  border-color: var(--accent);
}
.form-button {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
}
.form-button.primary {
  background-color: var(--accent);
  color: white;
}
.form-button.secondary {
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
}

/* --- Styles for Form Enhancements --- */
.searchable-select-container {
  position: relative;
}

.searchable-select-input {
  width: 100%;
  padding: 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 14px;
}

.searchable-select-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 150px;
  overflow-y: auto;
  z-index: 4000;
  display: none;
}

.searchable-select-dropdown.open {
  display: block;
}

.searchable-select-option {
  padding: 10px;
  cursor: pointer;
  font-size: 14px;
}

.searchable-select-option:hover,
.searchable-select-option.selected {
  background-color: var(--bg-tertiary);
}

.multi-select-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
}
.multi-select-option:hover {
  background-color: var(--bg-tertiary);
}
.multi-select-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin-right: 8px;
}
/* --- SSO Login Modal --- */
#login-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5); /* Add a semi-transparent background */
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
}
#login-modal-overlay.hidden {
  display: none !important;
}
.login-modal-content {
  position: relative;
  background-color: var(--bg-primary);
  padding: 32px;
  border-radius: var(--radius);
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
  animation: fadeIn 0.3s ease-out;
}
.login-modal-header {
  text-align: center;
  margin-bottom: 24px;
}
.modal-close-btn {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  font-size: 28px;
  color: var(--text-tertiary);
  cursor: pointer;
  line-height: 1;
  padding: 0;
}
.modal-close-btn:hover {
  color: var(--text-primary);
}
.login-logo {
  height: 40px;
  margin-bottom: 12px;
  display: inline-block;
}
.login-title {
  color: #af3c43; /* Specific color from the image */
  font-size: 16px;
  font-weight: bold;
}
.login-welcome-message {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 20px;
  line-height: 1.5;
}
.login-form-group {
  margin-bottom: 16px;
}
.login-form-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  font-size: 14px;
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}
.login-form-actions {
  margin-top: 24px;
}
.login-button {
  background-color: #3b5998; /* Specific blue from the image */
  color: white;
  border: none;
  width: 100%;
  padding: 12px;
  border-radius: 4px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
}
.login-button:hover {
  background-color: #324b81;
}
.login-status-hidden {
  display: none;
}
.login-status-visible {
  display: block;
  margin-top: 16px;
  padding: 10px;
  border-radius: 4px;
  font-size: 14px;
}
.login-status-success {
  background-color: #d4edda;
  color: #155724;
}
.login-status-error {
  background-color: #f8d7da;
  color: #721c24;
}
/* --- User Status in Header --- */
.user-status-container {
  flex-grow: 1;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.greeting-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}
.login-header-btn {
  background-color: var(--accent);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
}
.login-header-btn:hover {
  background-color: #0d8a6a;
}
.logout-btn {
  margin-left: 12px;
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
}
.logout-btn:hover {
  background: var(--danger);
  color: white;
}
/* --- Notification Bubble & Unread Indicators --- */
#new-chat-notifier {
  position: absolute;
  top: -5px; /* Position it slightly above the button */
  right: -5px; /* Position it slightly to the right of the button */
  background-color: var(--danger);
  color: white;
  min-width: 20px; /* Use min-width so it can expand for "9+" */
  height: 20px;
  border-radius: 10px; /* Keep it perfectly round */
  padding: 0 4px; /* Add some horizontal padding */
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  animation: fadeIn 0.3s ease-out;
}

/* Style for unread items in the sidebar chat list */
.panel-item.unread {
  background-color: var(--accent);
  color: white;
}

.panel-item.unread .panel-item-title {
  font-weight: bold;
}
.panel-item.unread:hover {
  background-color: #0d8a6a; /* A slightly darker accent color on hover */
}

.action-bar-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 768px;
  margin: 0 auto;
  padding: 0 20px 12px 20px;
  flex-shrink: 0;
}
/* --- Animations --- */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.message.new-message {
  animation: fadeIn 0.4s ease-out;
}
@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}
.fade-out {
  animation: fadeOut 0.3s ease-out forwards;
}
.hidden {
  display: none !important;
}
@keyframes slideDownFadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes pulse-animation {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 82, 82, 0.7);
  }
  70% {
    transform: scale(1.1);
    box-shadow: 0 0 0 10px rgba(255, 82, 82, 0);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 82, 82, 0);
  }
}
.pulse {
  animation: pulse-animation 1s;
}

.summary-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}

.view-original-file-btn {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 12px;
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s ease;
}

.view-original-file-btn:hover {
  background-color: var(--accent);
  color: white;
}
/* --- RESPONSIVE LAYOUT LOGIC --- */
/* DESKTOP MODE (Wide Screens): Sidebars "push" the main content. */
@media (min-width: 1024px) {
  .main-content.sidebar-open {
    margin-left: 260px;
  }
  .main-content.panel-open {
    margin-right: var(--document-panel-width, 320px);
  }
  /* The resizer is visible on desktop */
  #panel-resizer {
    display: block;
  }
}

/* MOBILE MODE (Narrow Screens): Sidebars act as overlays. */
@media (max-width: 1023px) {
  .sidebar.open,
  .document-panel-container.visible {
    background-color: var(--bg-overlay);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
  }
  /* On mobile, the main content never gets a margin */
  .main-content.sidebar-open {
    margin-left: 0;
  }
  .main-content.panel-open {
    margin-right: 0;
  }

  /* The right panel takes up most of the screen */
  .document-panel-container {
    width: var(--document-panel-width, 320px);
  }

  /* The resizer is not needed on mobile touch screens */
  #panel-resizer {
    display: block;
    width: 30px; /* Increase the draggable area for touch */
  }
  /* Create a big, visible button for mobile */
  #panel-resizer::after {
    content: "↔"; /* A clear resize icon */
    font-size: 14px;
    color: var(--text-primary);
    width: 30px; /* Button width */
    height: 30px; /* Button height */
    background-color: var(--bg-primary);
    border-radius: 50%; /* Make it a circle */
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    /* Add flex to center the icon */
    display: flex;
    align-items: center;
    justify-content: center;
  }
  #panel-resizer:hover::after {
    background-color: var(--accent); /* Keep the hover effect */
    color: white;
  }
}
/* --- Master Loading Overlay --- */
.master-loader-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4000; /* Higher than login modal (3000) */
  color: white;
  font-size: 1.2rem;
  font-weight: 500;
  text-align: center;
  padding: 20px;
  animation: fadeIn 0.3s ease-out;
}
/* --- RAG Image Style --- */
.rag-image {
  max-width: 100%;
  border-radius: 8px;
  margin: 8px 0;
  border: 1px solid var(--border-light);
}
/* --- RAG Table Style --- */
.rag-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 0.9em;
  border: 1px solid var(--border-light);
}
.rag-table th,
.rag-table td {
  border: 1px solid var(--border-light);
  padding: 8px 12px;
  text-align: left;
}
.rag-table th {
  background-color: var(--bg-secondary);
  font-weight: 600;
  color: var(--text-primary);
}
.rag-table tbody tr:nth-child(even) {
  background-color: var(--bg-secondary);
}
/* --- Flatpickr Dark Mode Override (Corrected) --- */

/* 1. Main Background & Shadow */
[data-theme="dark"] .flatpickr-calendar {
  background: var(--bg-secondary) !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5) !important;
  border: 1px solid var(--border-light) !important;
}

/* 2. Header Text (Month & Year) */
[data-theme="dark"] .flatpickr-month {
  color: var(--text-primary) !important;
  fill: var(--text-primary) !important; /* For SVG arrows */
}
[data-theme="dark"] .flatpickr-current-month input.cur-year {
  color: var(--text-primary) !important;
}

/* 3. FIX: Month Dropdown Menu */
/* We must force the background of the select box to be dark */
[data-theme="dark"] .flatpickr-current-month .flatpickr-monthDropdown-months {
  background-color: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
}
/* Handle hover state in the dropdown */
[data-theme="dark"]
  .flatpickr-current-month
  .flatpickr-monthDropdown-months:hover {
  background-color: var(--bg-tertiary) !important;
}

/* 4. Navigation Arrows */
[data-theme="dark"] .flatpickr-prev-month,
[data-theme="dark"] .flatpickr-next-month {
  color: var(--text-primary) !important;
  fill: var(--text-primary) !important;
}
[data-theme="dark"] .flatpickr-prev-month:hover svg,
[data-theme="dark"] .flatpickr-next-month:hover svg {
  fill: var(--accent) !important;
}

/* 5. Weekday Labels (Mon, Tue, etc.) */
[data-theme="dark"] span.flatpickr-weekday {
  color: var(--text-secondary) !important;
  background: var(--bg-secondary) !important;
}

/* 6. Regular Active Days */
[data-theme="dark"] .flatpickr-day {
  color: var(--text-primary) !important;
}

/* 7. FIX: Faded Days (Previous/Next Month) */
/* We target these specifically to make them dim */
[data-theme="dark"] .flatpickr-day.prevMonthDay,
[data-theme="dark"] .flatpickr-day.nextMonthDay,
[data-theme="dark"] .flatpickr-day.disabled {
  color: var(--text-tertiary) !important;
  background: transparent !important;
  border-color: transparent !important;
}

/* 8. Selected Day (Overrides everything else) */
[data-theme="dark"] .flatpickr-day.selected,
[data-theme="dark"] .flatpickr-day.startRange,
[data-theme="dark"] .flatpickr-day.endRange {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: white !important;
}

/* 9. Hover State (Only for valid days) */
[data-theme="dark"]
  .flatpickr-day:not(.selected):not(.prevMonthDay):not(.nextMonthDay):not(
    .disabled
  ):hover {
  background: var(--bg-tertiary) !important;
  border-color: var(--border-light) !important;
}
