:root {
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #242424;
  --bg-hover: #2a2a2a;
  --text-primary: #e0e0e0;
  --text-secondary: #888;
  --text-muted: #555;
  --accent: #6c8aff;
  --accent-dim: #4a6adf;
  --accent-glow: rgba(108, 138, 255, 0.15);
  --border: #2a2a2a;
  --user-bubble: #1e2a3a;
  --assistant-bubble: #242424;
  --context-node: #1a2535;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: 260px 1fr 280px;
  height: 100vh;
}

/* Sidebar */
#sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.sidebar-header h1 {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
}

.sidebar-header button, .sidebar-footer button {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.sidebar-header button:hover, .sidebar-footer button:hover {
  background: var(--bg-hover);
}

#sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.session-item {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all 0.15s;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.session-item.active {
  background: var(--accent-glow);
  color: var(--accent);
  border-left: 2px solid var(--accent);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

/* Chat Area */
#chat-area {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

#chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
}

#session-title {
  font-size: 15px;
  font-weight: 500;
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--accent-glow);
  color: var(--accent);
  font-weight: 500;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  max-width: 720px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user {
  background: var(--user-bubble);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  margin-left: 48px;
}

.message.assistant {
  background: var(--assistant-bubble);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  margin-right: 48px;
}

.message .role {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#input-area {
  display: flex;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
}

#message-input {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 12px 16px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 150px;
  line-height: 1.5;
}

#message-input:focus {
  outline: none;
  border-color: var(--accent-dim);
}

#send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s;
  white-space: nowrap;
}

#send-btn:hover {
  background: var(--accent-dim);
}

#send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Context Panel */
#context-panel {
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.panel-header h2 {
  font-size: 14px;
  font-weight: 600;
}

.panel-header button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

#context-nodes {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.context-node {
  background: var(--context-node);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 12px;
}

.context-node .node-label {
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
}

.context-node .node-type {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.context-node .node-summary {
  color: var(--text-secondary);
  margin-top: 6px;
  line-height: 1.4;
}

.context-node .node-keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.context-node .keyword {
  font-size: 10px;
  padding: 1px 6px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  color: var(--text-muted);
}

.context-node .boost-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 10px;
  margin-top: 6px;
  transition: all 0.15s;
}

.context-node .boost-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90vw;
  height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.modal-header h2 { font-size: 16px; }

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
}

#graph-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #080808;
}

#graph-svg {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#graph-svg:active { cursor: grabbing; }

.graph-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

#graph-search {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 6px 12px;
  font-size: 13px;
  width: 200px;
}

#graph-search:focus {
  outline: none;
  border-color: var(--accent-dim);
}

.graph-tooltip {
  position: absolute;
  background: rgba(20, 20, 20, 0.95);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 12px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  max-width: 250px;
  z-index: 10;
}

.graph-tooltip.visible { opacity: 1; }
.graph-tooltip .tt-label { color: var(--accent); font-weight: 600; }
.graph-tooltip .tt-type { color: var(--text-muted); font-size: 10px; margin-left: 6px; }
.graph-tooltip .tt-kw { color: var(--text-secondary); margin-top: 4px; font-size: 11px; }

.graph-stats {
  position: absolute;
  bottom: 12px;
  left: 12px;
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(0,0,0,0.5);
  padding: 4px 10px;
  border-radius: 4px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Hamburger button - hidden on desktop */
#hamburger-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  gap: 4px;
  flex-direction: column;
  justify-content: center;
}

#hamburger-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 1px;
  transition: all 0.25s ease;
}

#mobile-context-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
}

.sidebar-header-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.mobile-close-sidebar {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
}

#mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 49;
}

/* Responsive */
@media (max-width: 900px) {
  #app {
    grid-template-columns: 1fr;
  }

  #hamburger-btn, #mobile-context-btn {
    display: flex;
  }

  #chat-header {
    gap: 8px;
  }

  #chat-header #session-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    display: flex;
  }

  #sidebar.open {
    transform: translateX(0);
  }

  .mobile-close-sidebar {
    display: flex;
  }

  #mobile-overlay.open {
    display: block;
  }

  #context-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 300px;
    max-width: 85vw;
    z-index: 50;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    display: flex;
  }

  #context-panel.open {
    transform: translateX(0);
  }

  .modal-content {
    width: 95vw;
    max-height: 90vh;
  }

  .modal-lg {
    width: 95vw;
  }

  .tab-bar {
    margin-left: 8px;
    overflow-x: auto;
  }

  .graph-controls {
    flex-wrap: wrap;
  }

  #graph-search {
    width: 120px;
  }
}

/* Loading animation */
.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

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

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* Settings */
.modal-sm {
  width: 480px;
  height: auto;
  max-width: 95vw;
}

.setting-group {
  padding: 16px 24px;
}

.setting-group + .setting-group {
  border-top: 1px solid var(--border);
}

.setting-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.setting-group input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
}

.setting-group input:focus {
  outline: none;
  border-color: var(--accent-dim);
}

.setting-group small {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

.setting-actions {
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--border);
}

.btn-primary {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 8px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: var(--accent-dim);
}

#settings-status {
  font-size: 12px;
  color: var(--accent);
}

/* Context Manager */
.modal-lg {
  width: 800px;
  max-width: 95vw;
  height: 75vh;
}

.tab-bar {
  display: flex;
  gap: 2px;
  margin-left: 24px;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 6px 16px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}

.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.tab-panel.active { display: flex; }

.tab-toolbar {
  display: flex;
  gap: 8px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.tab-toolbar input, .tab-toolbar select {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 6px 12px;
  font-size: 13px;
  font-family: inherit;
}

.tab-toolbar input:focus, .tab-toolbar select:focus {
  outline: none;
  border-color: var(--accent-dim);
}

.tab-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
}

.btn-sm { padding: 6px 14px; font-size: 12px; }

.btn-danger {
  background: #5c2020;
  border: none;
  color: #ff6c6c;
  padding: 8px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}

.btn-danger:hover { background: #7c2020; }

/* Node list items */
.node-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.node-list-item:hover { background: var(--bg-hover); }

.node-list-item .nli-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.node-list-item .nli-label {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node-list-item .nli-type {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  flex-shrink: 0;
}

.node-list-item .nli-weight {
  font-size: 11px;
  color: var(--accent);
  min-width: 32px;
  text-align: right;
  flex-shrink: 0;
}

/* Log entries */
.log-entry {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.5;
}

.log-entry .le-action {
  font-weight: 600;
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  text-transform: uppercase;
  margin-right: 6px;
}

.le-action.extracted { background: #1a2a1a; color: #6cffb8; }
.le-action.created { background: #1a1a2a; color: #6c8aff; }
.le-action.updated { background: #2a2a1a; color: #ffd66c; }
.le-action.deleted { background: #2a1a1a; color: #ff6c6c; }
.le-action.boosted { background: #2a1a2a; color: #d06cff; }
.le-action.retrieved { background: #1a2a2a; color: #6cd6ff; }
.le-action.link_created { background: #1a2a1a; color: #6cffb8; }
.le-action.link_extracted { background: #1a2a1a; color: #6cffb8; }

.log-entry .le-node { color: var(--accent); font-weight: 500; }
.log-entry .le-source { color: var(--text-muted); font-size: 10px; }
.log-entry .le-time { color: var(--text-muted); font-size: 10px; float: right; }
.log-entry .le-detail { color: var(--text-secondary); margin-top: 2px; font-size: 11px; }

.setting-group textarea {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}

.setting-group textarea:focus {
  outline: none;
  border-color: var(--accent-dim);
}

.setting-group select {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
}

.setting-group select:focus {
  outline: none;
  border-color: var(--accent-dim);
}
