:root {
  color-scheme: light;
  --bg-color: #f4f4f0;
  --text-primary: #111111;
  --text-secondary: #555555;
  --panel-bg: #f4f4f0;
  --panel-border: #111111;
  --accent-color: #111111;
  --chat-user-bg: #e0e0d8;
  --chat-ai-bg: transparent;
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', Courier, monospace;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-main);
  background-color: var(--bg-color);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.5;
}

.sys-title, .mono-text {
  font-family: var(--font-mono);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.container {
  display: flex;
  width: 100%;
  height: 100%;
}

.panel {
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Reset all visual flair */
  border-radius: 0;
  box-shadow: none;
  backdrop-filter: none;
}

/* --- Sidebar --- */
.sidebar {
  width: 260px;
  background: var(--bg-color);
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  transition: width 0.3s;
  background: var(--panel-bg);
}
.sidebar.closed {
  width: 0;
  border-right: none;
  overflow: hidden;
}

/* Right Sidebar (Knowledge) */
.right-sidebar {
  border-right: none;
  border-left: 1px solid var(--panel-border);
}
.right-sidebar.closed {
  border-left: none;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sidebar-header h2 {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}
.btn-new-chat {
  font-family: var(--font-mono);
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--panel-border);
  padding: 8px;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.2s;
  border-radius: 0;
}
.btn-new-chat:hover, .btn-secondary:hover {
  background: var(--text-primary);
  color: var(--bg-color);
}
.session-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 0;
  margin: 0;
}
.session-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--panel-border);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.1s;
  border-radius: 0;
}
.tree-drop-zone {
  margin: 16px;
  padding: 24px;
  border: 1px dashed var(--panel-border);
  text-align: center;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  transition: all 0.2s;
  background: transparent;
  border-radius: 0;
}
.tree-drop-zone.drag-over {
  background: var(--text-primary);
  color: var(--bg-color);
}
.session-item:hover {
  background: rgba(17, 17, 17, 0.05);
}
.session-item.active {
  background: var(--text-primary);
  color: var(--bg-color);
}
.session-item.active .btn-delete-session {
  color: var(--bg-color);
}
.session-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-delete-session {
   background: none; border: none; cursor: pointer; color: var(--text-primary); font-family: var(--font-mono);
   font-size: 0.85rem; opacity: 0; padding: 2px 6px; border-radius: 0;
}
.session-item:hover .btn-delete-session { opacity: 1; }
.btn-delete-session:hover { text-decoration: underline; }


/* --- Chat Panel --- */
.chat-panel {
  flex: 1;
}

.chat-header, .tree-header {
  padding: 16px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.knowledge-controls {
  padding: 12px;
  border-bottom: 1px solid var(--panel-border);
}
#knowledge-search {
  width: 100%;
  padding: 6px;
  background: transparent;
  color: var(--text-primary);
  border: 1px dashed var(--panel-border);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  border-radius: 0;
}
#knowledge-search:focus {
  outline: none;
  border-color: var(--text-primary);
}
.knowledge-apply-zone {
  padding: 12px;
  border-bottom: 2px solid var(--text-primary);
  background: var(--panel-border);
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  padding: 6px;
  transition: all 0.2s;
  border-radius: 0;
  text-decoration: none;
  white-space: nowrap;
}
.btn-icon:hover {
  background: var(--text-primary);
  color: var(--bg-color);
}
.btn-undo:disabled {
  opacity: 0.2;
  pointer-events: none;
}

.context-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: transparent;
  color: var(--text-secondary);
  padding: 4px 8px;
  border: 1px solid var(--panel-border);
  text-transform: uppercase;
}
.context-badge.active {
  background: var(--text-primary);
  color: var(--bg-color);
}

.chat-history {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.chat-message {
  max-width: 85%;
  padding: 14px 18px;
  word-wrap: break-word;
  border-radius: 0;
}

.chat-message.user {
  align-self: flex-end;
  background-color: var(--chat-user-bg);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
}

.chat-message.ai {
  align-self: flex-start;
  background-color: var(--chat-ai-bg);
  color: var(--text-primary);
  border-left: 4px solid var(--panel-border);
  padding-left: 16px;
}
.chat-message.ai p { margin: 0 0 10px; }
.chat-message.ai p:last-child { margin: 0; }
.chat-message.ai pre {
  background: var(--text-primary);
  color: var(--bg-color);
  padding: 12px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  margin: 10px 0;
  border-radius: 0;
}

/* File Attachment Preview */
.attachment-preview {
  padding: 10px 16px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  border-top: 1px solid var(--panel-border);
}
.attachment-preview.hidden { display: none; }
.file-badge {
  background: transparent;
  border: 1px solid var(--panel-border);
  padding: 4px 8px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-primary);
  border-radius: 0;
}
.file-badge .file-remove {
  cursor: pointer;
  font-weight: bold;
}
.file-badge .file-remove:hover {
  text-decoration: underline;
}

.chat-input-area {
  padding: 16px;
  border-top: 1px solid var(--panel-border);
  display: flex;
  gap: 12px;
  align-items: flex-end;
  background: var(--bg-color);
}

.btn-attach {
  font-size: 0.9rem;
  margin-bottom: 6px;
  padding: 8px;
  border: 1px solid var(--panel-border);
}

#chat-input {
  flex: 1;
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--panel-border);
  padding: 12px;
  font-family: var(--font-main);
  font-size: 1rem;
  resize: none;
  min-height: 24px;
  max-height: 200px;
  overflow-y: auto;
  border-radius: 0;
  box-sizing: border-box;
}
#chat-input:focus {
  outline: none;
  background: rgba(17, 17, 17, 0.03);
}

.chat-actions {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  margin-bottom: 6px;
}

.btn-send {
  background: var(--text-primary);
  color: var(--bg-color);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
  border: 1px solid var(--panel-border);
  padding: 12px 16px;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 0;
}
.btn-send:hover {
  background: var(--bg-color);
  color: var(--text-primary);
}
.btn-send.hidden { display: none; }

#tree-loading {
  font-size: 0.8rem;
  font-weight: bold;
}

/* Resizer */
.resizer {
  width: 4px;
  background: var(--panel-border);
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.2s;
}
.resizer:hover, .resizer.dragging {
  background: var(--text-primary);
}

/* Responsive Tabs */
.mobile-tabs {
  border-bottom: 1px solid var(--panel-border);
  padding: 12px 16px;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 0;
}

/* --- Tree Panel --- */
.tree-panel {
  width: 45%;
  min-width: 350px;
  border-right: none;
}

.tree-header-main {
  display: flex;
  align-items: center;
  gap: 12px;
}
.tree-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.folder-indicator {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 6px;
  border: 1px solid transparent;
  transition: border 0.2s;
  white-space: nowrap;
  display: inline-block;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}
.folder-indicator:hover {
  border-color: var(--text-primary);
}

.tree-loading {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  white-space: nowrap;
}
.tree-loading.hidden { display: none; }

.tree-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.node {
  background: transparent;
  border: 1px solid var(--panel-border);
  margin-bottom: 16px;
  transition: all 0.2s;
  border-radius: 0;
}
.node:hover {
  border-style: solid;
}

.node-header {
  padding: 12px 16px;
  background: rgba(17, 17, 17, 0.03);
  border-bottom: 1px dashed var(--panel-border);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}
.node-header.drag-over {
  background: var(--text-primary);
  color: var(--bg-color);
}
.node-header.active {
  background: var(--text-primary);
  color: var(--bg-color);
  border-bottom: 1px solid var(--panel-border);
}

.node-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: inherit;
  overflow: hidden;
}
.node-title span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-chevron {
  font-size: 0.8rem;
  display: inline-block;
  color: inherit;
  white-space: nowrap;
  flex-shrink: 0;
}

.node-actions {
  opacity: 0;
  transition: opacity 0.2s;
  display: flex;
  gap: 8px;
}
.node-header:hover .node-actions, .node-header.active .node-actions {
  opacity: 1;
}

.btn-small {
  background: transparent;
  border: 1px solid currentcolor;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  cursor: pointer;
  border-radius: 0;
  color: inherit;
  white-space: nowrap;
}
.btn-small:hover {
  background: var(--text-primary);
  color: var(--bg-color);
}
.node-header.active .btn-small:hover {
  background: var(--bg-color);
  color: var(--text-primary);
}

.node-body {
  padding: 12px 16px;
  display: none;
  font-size: 0.9rem;
}
.node-body.open {
  display: block;
}

.note-item {
  position: relative;
  padding: 8px 0;
  border-bottom: 1px dotted var(--panel-border);
  line-height: 1.6;
}
.note-item:last-child {
  border-bottom: none;
}
.note-item.latest {
  font-weight: 500;
  background: rgba(17, 17, 17, 0.05);
  padding: 8px;
  border-bottom: 1px solid var(--panel-border);
}

/* Modal */
.modal {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(244, 244, 240, 0.8);
  backdrop-filter: blur(2px);
  display: flex; justify-content: center; align-items: center;
  z-index: 1000;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--bg-color);
  padding: 30px; width: 450px;
  border: 2px solid var(--panel-border);
  border-radius: 0;
  box-shadow: 10px 10px 0px rgba(17, 17, 17, 1); /* Harsh industrial shadow */
}
.modal-content h3 { margin-top: 0; color: var(--text-primary); margin-bottom: 10px; }
.modal-content p { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 20px; line-height: 1.4; font-family: var(--font-mono); }
.modal-content label { display: block; margin-top: 15px; font-size: 0.85rem; color: var(--text-primary); font-family: var(--font-mono); font-weight: bold;}
.modal-content input {
  width: 100%; padding: 10px; margin-top: 5px; box-sizing: border-box;
  background: transparent; border: 1px solid var(--panel-border);
  color: var(--text-primary); font-family: var(--font-mono);
  border-radius: 0;
}
.modal-content input:focus {
  outline: 1px solid var(--text-primary);
  background: rgba(17, 17, 17, 0.05);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 25px; }
.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--panel-border);
  cursor: pointer;
  padding: 10px 16px;
  font-family: var(--font-mono);
  font-weight: 700;
  border-radius: 0;
}

/* Typing Indicator (ASCII style) */
.typing-indicator {
  display: flex;
  gap: 6px;
  padding: 16px;
  align-self: flex-start;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  border-left: 4px solid var(--panel-border);
}

.typing-dot {
  animation: blink 1.4s infinite reverse both;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0% { opacity: 0.2; }
  20% { opacity: 1; }
  100% { opacity: 0.2; }
}

@keyframes pulse-attention {
  0% { background-color: transparent; color: var(--text-primary); }
  50% { background-color: var(--text-primary); color: var(--bg-color); }
  100% { background-color: transparent; color: var(--text-primary); }
}

.blink-attention {
  animation: pulse-attention 1.5s infinite;
  border: 1px dotted var(--text-primary);
}

/* Custom Scrollbar Industrial */
::-webkit-scrollbar {
  width: 10px;
}
::-webkit-scrollbar-track {
  background: var(--bg-color);
  border-left: 1px solid var(--panel-border);
}
::-webkit-scrollbar-thumb {
  background: var(--text-primary);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* Mobile Tabs Setup */
.mobile-tabs {
  display: none; /* Hide on desktop */
  background: var(--panel-bg);
  border-bottom: 1px solid var(--panel-border);
  position: absolute;
  top: 0; width: 100%;
  z-index: 100;
}

@media (max-width: 800px) {
  body {
    flex-direction: column;
    padding-top: 40px; /* Space for tabs */
  }
  .mobile-tabs {
    display: flex;
  }
  .mobile-tabs button {
    flex: 1;
    background: transparent;
    color: var(--text-primary);
    border: none;
    border-right: 1px solid var(--panel-border);
    padding: 10px;
    font-family: var(--font-mono);
    font-weight: 700;
    cursor: pointer;
  }
  .mobile-tabs button.active {
    background: var(--text-primary);
    color: var(--bg-color);
  }
  .container {
    flex-direction: column;
    position: relative;
    height: calc(100vh - 40px);
  }
  /* On mobile panel width is 100% */
  .chat-panel, .tree-panel {
    width: 100%;
    min-width: 100%;
    height: 100%;
    display: none;
    margin: 0;
  }
  .chat-panel.active-tab, .tree-panel.active-tab {
    display: flex;
  }
  
  /* Make header stack to avoid pushing buttons */
  .tree-header { 
    flex-direction: column; 
    align-items: flex-start;
    gap: 8px;
  }
}

