/* FILE: /emduit-rag/rag.css */

/* ===== LAYOUT WRAPPER (optional if you already have one) ===== */

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background-color: #0b1120; /* dark background */
  color: #e5e7eb;
}

#ragApp {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  height: 100vh;
  background: radial-gradient(circle at top left, #1e293b 0, #020617 45%);
}

/* ===== LEFT: AGENT / KNOWLEDGE TREE ===== */

#ragTree {
  padding: 12px;
  border-right: 1px solid rgba(148, 163, 184, 0.3);
  overflow-y: auto;
  background: linear-gradient(to bottom, #020617, #020617 50%, #020617);
}

.rag-tree-empty {
  margin-top: 20px;
  padding: 12px;
  border-radius: 10px;
  border: 1px dashed rgba(148, 163, 184, 0.6);
  font-size: 13px;
  text-align: center;
  color: #cbd5f5;
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.9), rgba(15, 23, 42, 0.3));
}

.rag-tree-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.rag-tree-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 10px;
  border-radius: 10px;
  margin-bottom: 6px;
  background: radial-gradient(circle at top left, rgba(30, 64, 175, 0.35), rgba(15, 23, 42, 0.95));
  border: 1px solid rgba(37, 99, 235, 0.4);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease,
    border-color 0.15s ease;
}

.rag-tree-item:hover {
  background: radial-gradient(circle at top left, rgba(59, 130, 246, 0.5), rgba(15, 23, 42, 1));
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.6),
    0 12px 30px rgba(15, 23, 42, 0.7);
  transform: translateY(-1px);
}

.rag-tree-item-main {
  flex: 1;
  min-width: 0;
}

.rag-tree-title {
  font-size: 14px;
  font-weight: 600;
  color: #e5e7eb;
  margin-bottom: 2px;
}

.rag-tree-sub {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 11px;
  color: #9ca3af;
}

.rag-tree-desc {
  opacity: 0.9;
}

.rag-tree-model {
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid rgba(129, 140, 248, 0.5);
  background: rgba(15, 23, 42, 0.8);
  color: #a5b4fc;
}

/* action buttons in tree */

.rag-tree-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ===== GENERIC BUTTONS ===== */

.rag-btn {
  font-size: 11px;
  line-height: 1.2;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.8);
  background: radial-gradient(circle at top left, rgba(55, 65, 81, 0.9), rgba(15, 23, 42, 1));
  color: #e5e7eb;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease,
    transform 0.08s ease, box-shadow 0.15s ease;
}

.rag-btn:hover {
  background: radial-gradient(circle at top left, rgba(37, 99, 235, 0.95), rgba(15, 23, 42, 1));
  border-color: rgba(96, 165, 250, 0.95);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.7),
    0 10px 25px rgba(15, 23, 42, 0.6);
  transform: translateY(-0.5px);
}

.rag-btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.rag-btn-small {
  font-size: 12px;
  padding: 6px 12px;
  margin-top: 8px;
}

.rag-btn-xs {
  font-size: 10px;
  padding: 3px 7px;
}

.rag-btn-danger {
  border-color: rgba(248, 113, 113, 0.9);
  color: #fecaca;
  background: radial-gradient(circle at top left, rgba(127, 29, 29, 0.9), rgba(15, 23, 42, 1));
}

.rag-btn-danger:hover {
  border-color: rgba(252, 165, 165, 1);
  box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.8),
    0 10px 25px rgba(15, 23, 42, 0.7);
}

/* ===== RIGHT: CHAT PANEL ===== */

#chatPanel {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: radial-gradient(circle at top right, #1f2937 0, #020617 50%);
}

#chatHeader {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.5);
  display: flex;
  justify-content: space-between;
  align-items: center;
  backdrop-filter: blur(14px);
  background: linear-gradient(to right, rgba(15, 23, 42, 0.85), rgba(15, 23, 42, 0.95));
}

#chatAgentName {
  font-size: 14px;
  font-weight: 600;
  color: #e5e7eb;
}

#chatMessages {
  flex: 1;
  padding: 18px 18px 10px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #4b5563 transparent;
}

#chatMessages::-webkit-scrollbar {
  width: 6px;
}

#chatMessages::-webkit-scrollbar-thumb {
  background-color: #4b5563;
  border-radius: 999px;
}

/* Chat bubbles */

.chat-bubble {
  margin-bottom: 10px;
  display: flex;
}

.chat-bot {
  justify-content: flex-start;
}

.chat-user {
  justify-content: flex-end;
}

.chat-bubble-inner {
  max-width: 70%;
  padding: 8px 11px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.chat-bot .chat-bubble-inner {
  background: radial-gradient(circle at top left, rgba(17, 24, 39, 1), rgba(31, 41, 55, 0.95));
  border: 1px solid rgba(148, 163, 184, 0.9);
  color: #e5e7eb;
}

.chat-user .chat-bubble-inner {
  background: radial-gradient(circle at top right, rgba(37, 99, 235, 0.95), rgba(30, 64, 175, 0.95));
  border: 1px solid rgba(191, 219, 254, 0.9);
  color: #eff6ff;
}

/* Input row */

#chatInputRow {
  border-top: 1px solid rgba(148, 163, 184, 0.5);
  padding: 10px 14px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: linear-gradient(to top, rgba(15, 23, 42, 1), rgba(15, 23, 42, 0.95));
}

#chatInput {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.8);
  background: radial-gradient(circle at top left, rgba(15, 23, 42, 1), rgba(15, 23, 42, 0.9));
  color: #e5e7eb;
  font-size: 13px;
  padding: 8px 10px;
  outline: none;
}

#chatInput:focus {
  border-color: rgba(96, 165, 250, 1);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.9);
}

#chatSend {
  font-size: 13px;
  border-radius: 999px;
  border: 1px solid rgba(37, 99, 235, 0.95);
  padding: 8px 16px;
  background: radial-gradient(circle at top, rgba(37, 99, 235, 1), rgba(30, 64, 175, 1));
  color: #eff6ff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.08s ease,
    opacity 0.1s ease;
}

#chatSend:hover:not(:disabled) {
  box-shadow: 0 0 0 1px rgba(191, 219, 254, 0.9),
    0 14px 30px rgba(15, 23, 42, 0.85);
  transform: translateY(-0.5px);
}

#chatSend:disabled {
  opacity: 0.6;
  cursor: default;
  box-shadow: none;
}

/* ===== NEW AGENT BUTTON (if placed above tree) ===== */

#btnNewAgent {
  margin: 10px 12px 4px;
}

/* ===== MODAL: NEW AGENT / KNOWLEDGE ===== */

#ragModalOverlay.hidden {
  display: none;
}

#ragModalOverlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(12px);
}

#ragModal {
  position: relative;
  width: 420px;
  max-width: 92vw;
  max-height: 80vh;
  overflow-y: auto;
  background: radial-gradient(circle at top left, #020617, #020617 40%, #020617);
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.9);
  box-shadow: 0 25px 60px rgba(15, 23, 42, 0.95);
  padding: 16px 16px 14px;
}

#ragModalClose {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  background: transparent;
  color: #9ca3af;
  font-size: 18px;
  cursor: pointer;
}

#ragModalClose:hover {
  color: #e5e7eb;
}

#newAgentForm {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#newAgentForm input[type="text"],
#newAgentForm textarea,
#newAgentForm select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.9);
  background: radial-gradient(circle at top left, rgba(15, 23, 42, 1), rgba(15, 23, 42, 0.95));
  color: #e5e7eb;
  font-size: 13px;
  padding: 7px 9px;
  outline: none;
}

#newAgentForm input[type="text"]:focus,
#newAgentForm textarea:focus,
#newAgentForm select:focus {
  border-color: rgba(96, 165, 250, 1);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.9);
}

#newAgentForm label {
  font-size: 12px;
  color: #9ca3af;
}

#newAgentForm textarea {
  min-height: 60px;
  resize: vertical;
}

#newAgentForm input[type="file"] {
  font-size: 11px;
  color: #9ca3af;
}

#newAgentForm button[type="submit"] {
  margin-top: 4px;
  align-self: flex-end;
}

/* Small helper text style for hints if you add them */
.rag-hint {
  font-size: 11px;
  color: #9ca3af;
  opacity: 0.9;
}

/* Mobile / narrow layout */

@media (max-width: 800px) {
  #ragApp {
    grid-template-columns: 1fr;
  }

  #ragTree {
    height: 180px;
    border-right: none;
    border-bottom: 1px solid rgba(148, 163, 184, 0.4);
  }

  #chatPanel {
    height: calc(100vh - 180px);
  }

  .chat-bubble-inner {
    max-width: 85%;
  }
}