:root {
  --primary-color: #ff7a00;
  --background-color: #f9f9f9;
  --sidebar-bg: #1a1a1a;
  --text-color: #333;
  --text-on-dark: #f0f0f0;
  --border-color: #e0e0e0;
  --user-msg-bg: #e9e9eb;
  --bot-msg-bg: #ffffff;
  --font-family: 'Tajawal', sans-serif;
  --shadow-color: rgba(0, 0, 0, 0.2);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--background-color);
  color: var(--text-color);
  direction: rtl;
  overflow: hidden;
}

#root {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 320px;
  flex-shrink: 0; /* Prevents the sidebar from shrinking */
  background-color: var(--sidebar-bg);
  color: var(--text-on-dark);
  padding: 24px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid #333; /* Darker border for better contrast */
}

.sidebar-header {
  text-align: center;
  margin-bottom: 24px;
  flex-shrink: 0;
}

.sidebar-header h1 {
  font-size: 1.5rem;
  color: var(--primary-color);
}

.sidebar-header p {
  font-size: 0.875rem;
  opacity: 0.7;
}

.sidebar-content-wrapper {
  flex-grow: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  margin-bottom: 16px;
  /* Custom scrollbar for webkit browsers */
  &::-webkit-scrollbar {
    width: 6px;
  }
  &::-webkit-scrollbar-track {
    background: #2c2c2c;
  }
  &::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 3px;
  }
  &::-webkit-scrollbar-thumb:hover {
    background: #777;
  }
}

.file-upload-area {
  border: 2px dashed var(--primary-color);
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  margin-bottom: 20px;
  transition: background-color 0.2s ease;
  flex-shrink: 0;
}

.file-upload-area:hover, .file-upload-area.drag-over {
  background-color: rgba(255, 122, 0, 0.1);
}

.file-upload-area svg {
  width: 40px;
  height: 40px;
  stroke: var(--primary-color);
  margin-bottom: 8px;
}

.uploaded-files {
  margin-top: 16px;
  flex-shrink: 0;
}

.uploaded-files h3 {
  margin-bottom: 12px;
  font-size: 1rem;
  color: var(--primary-color);
}

.file-item {
  display: flex;
  align-items: flex-start; /* Aligns items to the top for multi-line text */
  gap: 12px;
  background-color: #2c2c2c;
  padding: 12px;
  border-radius: 8px; /* Slightly larger radius */
  margin-bottom: 10px; /* More space */
  box-shadow: 0 2px 4px var(--shadow-color);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.file-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--shadow-color);
}

.file-item-icon {
  margin-top: 2px; /* Align icon better with first line of text */
}

.file-item-icon svg {
  width: 20px;
  height: 20px;
  stroke: #888;
  flex-shrink: 0;
}

.file-item-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-grow: 1; /* Allows this element to take up space */
  overflow: visible; /* Allows content to wrap and expand */
}

.file-name {
  font-size: 0.875rem;
  color: var(--text-on-dark);
  line-height: 1.5;
  word-break: break-word; /* Ensures long file names wrap */
  white-space: normal; /* Allows text to wrap */
}

.file-status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-text {
  font-size: 0.75rem;
  color: #999;
}

.status-text.done {
  color: #4caf50;
}

.status-text.error {
  color: #f44336;
}


.spinner {
  animation: spin 1.5s linear infinite;
  color: #999;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.delete-file-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #888;
  opacity: 0.5;
  transition: opacity 0.2s ease, color 0.2s ease, background-color 0.2s ease;
  border-radius: 4px;
  flex-shrink: 0; /* Prevents button from shrinking */
}

.file-item:hover .delete-file-btn {
    opacity: 1;
}

.delete-file-btn:hover {
    color: #f44336;
    background-color: rgba(244, 67, 54, 0.1);
}

.delete-file-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

.chat-history {
  margin-top: 24px;
}

.chat-history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.chat-history-header h3 {
  margin-bottom: 0;
  font-size: 1rem;
  color: var(--primary-color);
}

.clear-all-chats-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #888;
    opacity: 0.7;
    transition: opacity 0.2s ease, color 0.2s ease, background-color 0.2s ease;
    border-radius: 4px;
}

.clear-all-chats-btn:hover {
    opacity: 1;
    color: #f44336;
    background-color: rgba(244, 67, 54, 0.1);
}

.clear-all-chats-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
}


.chat-history ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.chat-history-item {
  padding: 12px;
  border-radius: 8px; /* Match file-item */
  margin-bottom: 10px; /* Match file-item */
  cursor: pointer;
  font-size: 0.875rem;
  background-color: #333;
  display: flex;
  align-items: flex-start; /* Align top for multi-line */
  justify-content: space-between;
  gap: 8px;
  box-shadow: 0 2px 4px var(--shadow-color);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.chat-history-item:hover {
  background-color: #444;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px var(--shadow-color);
}

.chat-history-item.active {
  background-color: var(--primary-color);
  color: #1a1a1a;
  font-weight: 700;
}
.chat-history-item.active:hover {
  background-color: #e66a00; /* Darken on hover for active item */
}


.chat-history-title {
    flex-grow: 1;
    word-break: break-word; /* Allows long chat titles to wrap */
    white-space: normal; /* Allows text to wrap */
    line-height: 1.5;
}

.delete-chat-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #888;
    opacity: 0;
    transition: opacity 0.2s ease, color 0.2s ease;
    flex-shrink: 0;
    border-radius: 4px;
}

.chat-history-item:hover .delete-chat-btn {
    opacity: 0.7;
}

.delete-chat-btn:hover {
    opacity: 1;
    color: #f44336;
}

.chat-history-item.active .delete-chat-btn {
    color: #1a1a1a;
}

.chat-history-item.active .delete-chat-btn:hover {
    color: #fff;
    background-color: rgba(0, 0, 0, 0.2);
}


.delete-chat-btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
}


.config-section {
    flex-shrink: 0;
    padding-top: 20px;
    border-top: 1px solid #444;
}

.config-section label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.config-section select {
  width: 100%;
  padding: 8px;
  border-radius: 4px;
  border: 1px solid #555;
  background-color: #333;
  color: var(--text-on-dark);
  font-family: var(--font-family);
  margin-bottom: 12px;
}

.external-sources {
    display: flex;
    align-items: center;
    font-size: 0.9rem;
}

.external-sources input {
    margin-left: 8px;
    accent-color: var(--primary-color);
}

.new-chat-btn {
    width: 100%;
    padding: 10px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    font-family: var(--font-family);
    font-size: 1rem;
    cursor: pointer;
    margin-top: 16px;
    transition: background-color 0.2s ease;
}

.new-chat-btn:hover {
    background-color: #e66a00;
}

.chat-area {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--background-color);
  min-width: 0; /* Prevents flex items from overflowing and pushing the sidebar */
}

.chat-messages {
  flex-grow: 1;
  overflow-y: auto;
  padding: 24px;
}

.message {
  display: flex;
  margin-bottom: 16px;
  max-width: 80%;
}

.message-content {
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08); /* Add subtle shadow to messages */
}

.message.user {
  margin-left: auto;
}

.message.bot {
  margin-right: auto;
}

.message.user .message-content {
  background-color: var(--primary-color);
  color: white; /* Changed for better contrast */
  border-bottom-left-radius: 0;
}

.message.bot .message-content {
  background-color: var(--bot-msg-bg);
  border: 1px solid var(--border-color);
  border-bottom-right-radius: 0;
}

.file-download-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.file-download-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background-color: var(--primary-color);
  color: #fff;
  padding: 10px 15px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 500;
  transition: background-color 0.2s ease;
  align-self: flex-start; /* Prevent stretching */
}

.file-download-link:hover {
  background-color: #e66a00;
}

.file-download-link svg {
  width: 20px;
  height: 20px;
  stroke: #fff;
}

.message .sources {
    margin-top: 10px;
    font-size: 0.8rem;
    padding-top: 8px;
    border-top: 1px solid #eee;
}

.message .sources strong {
    display: block;
    margin-bottom: 4px;
    color: var(--text-color);
}

.message .source-item {
    display: block;
    color: #555;
    margin-bottom: 2px;
    white-space: pre-wrap;
    word-break: break-all;
}
.message .source-item a {
    color: var(--primary-color);
    text-decoration: none;
}
.message .source-item a:hover {
    text-decoration: underline;
}

.typing-indicator {
  display: flex;
  align-items: center;
}

.typing-indicator span {
  height: 8px;
  width: 8px;
  margin: 0 2px;
  background-color: #9e9e9e;
  display: block;
  border-radius: 50%;
  opacity: 0.4;
  animation: typing 1s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  50% { opacity: 1; transform: translateY(-3px); }
}


.chat-input-area {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  background-color: #fff;
}

.chat-input-form {
  display: flex;
  align-items: center;
  background-color: #f0f0f0;
  border-radius: 8px;
  padding: 4px;
}

.chat-input-form input {
  flex-grow: 1;
  border: none;
  background-color: transparent;
  padding: 12px;
  font-family: var(--font-family);
  font-size: 1rem;
  color: #1a1a1a;
}

.chat-input-form input::placeholder {
  color: #333;
  opacity: 1;
}

.chat-input-form input:focus {
  outline: none;
}

.chat-input-form button {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-input-form button svg {
  width: 24px;
  height: 24px;
  stroke: #555;
  transition: stroke 0.2s ease;
}

.chat-input-form button:hover svg {
  stroke: var(--primary-color);
}

.chat-input-form button.mic-btn.recording svg {
    stroke: #f44336;
}

.send-btn {
    background-color: var(--primary-color) !important;
    border-radius: 6px;
    margin-left: 4px;
}
.send-btn svg {
    stroke: white !important;
}

/* --- Project Summary Card Styles --- */

.project-summary-container h3 {
  font-size: 1.2rem;
  color: var(--text-color);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary-color);
}

.project-card {
  background-color: #f9f9f9;
  border: 1px solid #e9e9e9;
  border-right: 4px solid var(--primary-color);
  border-radius: 8px;
  padding: 16px;
  margin-top: 12px;
  transition: box-shadow 0.2s ease;
}

.project-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.project-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.project-title svg {
  width: 20px;
  height: 20px;
  stroke: var(--primary-color);
  flex-shrink: 0;
}

.project-title h4 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-color);
}

.project-detail {
  margin-bottom: 10px;
}

.project-detail strong {
  font-weight: 700;
  color: #333;
  display: block;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.project-detail p, .project-detail span {
  font-size: 0.95rem;
  color: #555;
  line-height: 1.7;
  padding-right: 8px;
}

.project-source {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px dashed #ddd;
}
.project-source span {
  color: #777;
  font-size: 0.85rem;
}

/* --- Confirmation Dialog --- */
.confirm-dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  direction: rtl;
}

.confirm-dialog {
  background: var(--bot-msg-bg);
  color: var(--text-color);
  padding: 32px;
  border-radius: 12px;
  box-shadow: 0 5px 20px rgba(0,0,0,0.25);
  width: 90%;
  max-width: 400px;
  text-align: center;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.confirm-dialog h3 {
  font-size: 1.25rem;
  margin-bottom: 12px;
  color: var(--text-color);
}

.confirm-dialog p {
  font-size: 1rem;
  line-height: 1.6;
  color: #555;
  margin-bottom: 24px;
}

.confirm-dialog-buttons {
  display: flex;
  justify-content: center;
  gap: 16px;
}

.confirm-dialog-buttons button {
  font-family: var(--font-family);
  font-size: 1rem;
  font-weight: 500;
  padding: 10px 24px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.confirm-dialog-buttons .btn-cancel {
  background-color: #f0f0f0;
  color: #333;
  border: 1px solid #ddd;
}

.confirm-dialog-buttons .btn-cancel:hover {
  background-color: #e0e0e0;
}

.confirm-dialog-buttons .btn-confirm-delete {
  background-color: #d9534f;
  color: white;
}

.confirm-dialog-buttons .btn-confirm-delete:hover {
  background-color: #c9302c;
  box-shadow: 0 2px 8px rgba(217, 83, 79, 0.3);
}

/* For mobile */
@media (max-width: 768px) {
  #root {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: 40vh;
    overflow-y: auto;
    border-left: none;
    border-bottom: 1px solid var(--border-color);
  }
  .chat-area {
    height: 60vh;
  }
  .message {
    max-width: 95%;
  }
}
