/* ============================================================
   VS Code-inspired Bud Dashboard — style.css
   ============================================================ */

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

:root {
  --bg:           #1e1e1e;
  --sidebar-bg:   #252526;
  --panel-bg:     #1e1e1e;
  --active-bg:    #37373d;
  --text:         #cccccc;
  --text-muted:   #858585;
  --text-bright:  #e8e8e8;
  --accent:       #007acc;
  --accent-hover: #1a8fd1;
  --user-bubble:  #0e639c;
  --bot-bubble:   #2d2d2d;
  --border:       #3c3c3c;
  --input-bg:     #3c3c3c;
  --tab-inactive: #2d2d2d;
  --scrollbar:    #4a4a4a;
  --font-mono:    'Consolas', 'Courier New', monospace;
  --font-ui:      -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius:       4px;
  --titlebar-h:   32px;
  --tabbar-h:     35px;
  --input-h:      72px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
}

/* ============================================================
   Scrollbars
   ============================================================ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #666; }

/* ============================================================
   Title Bar
   ============================================================ */
#titlebar {
  height: var(--titlebar-h);
  background: #323233;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  flex-shrink: 0;
  user-select: none;
}

#titlebar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.titlebar-icon {
  color: var(--accent);
  font-size: 16px;
}

.titlebar-title {
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.5px;
}

#titlebar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.status-dot.connected    { background: #4ec9b0; box-shadow: 0 0 6px #4ec9b080; }
.status-dot.connecting   { background: #dcdcaa; animation: pulse 1s infinite; }
.status-dot.disconnected { background: #f44747; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

#status-label {
  font-size: 11px;
  color: var(--text-muted);
}

/* ============================================================
   Layout
   ============================================================ */
#layout {
  display: flex;
  height: calc(100vh - var(--titlebar-h));
  overflow: hidden;
}

/* ============================================================
   Sidebar
   ============================================================ */
#sidebar {
  width: 280px;
  min-width: 160px;
  max-width: 500px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

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

.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  padding: 2px 4px;
  border-radius: var(--radius);
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}
.icon-btn:hover { color: var(--text); background: var(--active-bg); }

.sidebar-section-label {
  padding: 4px 12px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  letter-spacing: 0.3px;
  border-bottom: 1px solid var(--border);
}

#file-tree {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.tree-placeholder {
  padding: 12px 16px;
  color: var(--text-muted);
  font-style: italic;
  font-size: 12px;
}

/* Tree Items */
.tree-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
  cursor: pointer;
  border-radius: 0;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
}

.tree-item:hover {
  background: var(--active-bg);
}

.tree-item.selected {
  background: #094771;
  color: var(--text-bright);
}

.tree-item-icon {
  flex-shrink: 0;
  font-size: 13px;
  width: 16px;
  text-align: center;
}

.tree-item-name {
  font-family: var(--font-mono);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-children {
  /* padding handled by indent on items */
}

/* ============================================================
   Resize Handle
   ============================================================ */
#resize-handle {
  width: 4px;
  background: transparent;
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.15s;
  position: relative;
  z-index: 10;
}
#resize-handle:hover,
#resize-handle.dragging {
  background: var(--accent);
}

/* ============================================================
   Main Panel
   ============================================================ */
#main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ============================================================
   Tab Bar
   ============================================================ */
#tab-bar {
  display: flex;
  background: var(--tab-inactive);
  border-bottom: 1px solid var(--border);
  height: var(--tabbar-h);
  flex-shrink: 0;
  overflow: hidden;
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 16px;
  height: 100%;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  border-right: 1px solid var(--border);
  border-top: 2px solid transparent;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
  position: relative;
}

.tab:hover { background: var(--active-bg); color: var(--text); }

.tab.active {
  background: var(--panel-bg);
  color: var(--text-bright);
  border-top-color: var(--accent);
}

.tab-icon { font-size: 13px; }

.tab-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  padding: 1px 3px;
  border-radius: 2px;
  line-height: 1;
  margin-left: 2px;
  transition: color 0.15s, background 0.15s;
}
.tab-close:hover { color: var(--text-bright); background: rgba(255,255,255,0.1); }

.hidden { display: none !important; }

/* ============================================================
   Panels
   ============================================================ */
.panel {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel.hidden { display: none !important; }
.panel.active { display: flex; }

/* ============================================================
   Chat Panel
   ============================================================ */
#chat-panel {
  position: relative;
}

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

/* Message bubbles */
.message {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  gap: 3px;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user {
  align-self: flex-end;
  align-items: flex-end;
}

.message.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

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

.message.user .message-role { text-align: right; }

.message-bubble {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
}

.message.user .message-bubble {
  background: var(--user-bubble);
  color: #ffffff;
  border-bottom-right-radius: 2px;
}

.message.assistant .message-bubble {
  background: var(--bot-bubble);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}

/* Markdown inside assistant bubbles */
.message-bubble h1, .message-bubble h2, .message-bubble h3 {
  margin: 0.6em 0 0.3em;
  color: var(--text-bright);
}
.message-bubble p { margin: 0.3em 0; }
.message-bubble p:first-child { margin-top: 0; }
.message-bubble p:last-child  { margin-bottom: 0; }
.message-bubble code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: rgba(255,255,255,0.08);
  padding: 1px 5px;
  border-radius: 3px;
}
.message-bubble pre {
  background: #1a1a1a;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  margin: 8px 0;
  overflow-x: auto;
}
.message-bubble pre code {
  background: none;
  padding: 0;
  font-size: 12px;
  color: #d4d4d4;
}
.message-bubble ul, .message-bubble ol {
  padding-left: 1.4em;
  margin: 0.3em 0;
}
.message-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
  margin: 6px 0;
  color: var(--text-muted);
}
.message-bubble a { color: var(--accent); }
.message-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}
.message-bubble table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12px;
  margin: 6px 0;
}
.message-bubble th, .message-bubble td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
}
.message-bubble th { background: rgba(255,255,255,0.05); }

.message-timestamp {
  font-size: 10px;
  color: var(--text-muted);
}

/* Streaming cursor */
.streaming-cursor::after {
  content: '▊';
  animation: blink 0.8s step-start infinite;
  color: var(--accent);
  margin-left: 1px;
}
@keyframes blink {
  50% { opacity: 0; }
}

/* Thinking indicator */
#thinking-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
  flex-shrink: 0;
}

.thinking-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: thinking 1.2s ease-in-out infinite;
}
.thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.thinking-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinking {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1; }
}

/* ============================================================
   File Panel
   ============================================================ */
#file-panel {
  overflow: hidden;
}

#file-header {
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar-bg);
  flex-shrink: 0;
}

#file-path-display {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

#file-content {
  flex: 1;
  overflow: auto;
  padding: 16px 20px;
}

/* Markdown file rendering */
#file-content.markdown {
  color: var(--text);
  line-height: 1.65;
}
#file-content.markdown h1 { font-size: 1.6em; color: var(--text-bright); margin: 0.5em 0 0.3em; border-bottom: 1px solid var(--border); padding-bottom: 0.2em; }
#file-content.markdown h2 { font-size: 1.3em; color: var(--text-bright); margin: 1em 0 0.3em; }
#file-content.markdown h3 { font-size: 1.1em; color: var(--text-bright); margin: 0.8em 0 0.2em; }
#file-content.markdown p  { margin: 0.5em 0; }
#file-content.markdown code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: rgba(255,255,255,0.08);
  padding: 1px 5px;
  border-radius: 3px;
}
#file-content.markdown pre {
  background: #141414;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 14px;
  margin: 10px 0;
  overflow-x: auto;
}
#file-content.markdown pre code { background: none; padding: 0; color: #d4d4d4; }
#file-content.markdown ul, #file-content.markdown ol { padding-left: 1.6em; margin: 0.4em 0; }
#file-content.markdown li { margin: 0.2em 0; }
#file-content.markdown blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 6px 0;
  color: var(--text-muted);
}
#file-content.markdown a { color: var(--accent); }
#file-content.markdown hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
#file-content.markdown table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
#file-content.markdown th, #file-content.markdown td { border: 1px solid var(--border); padding: 5px 10px; }
#file-content.markdown th { background: rgba(255,255,255,0.05); }

/* Raw text file rendering */
#file-content.raw {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--text);
}

.file-loading {
  color: var(--text-muted);
  font-style: italic;
  font-size: 12px;
}

/* ============================================================
   Input Area
   ============================================================ */
#input-area {
  border-top: 1px solid var(--border);
  background: var(--sidebar-bg);
  padding: 10px 16px;
  flex-shrink: 0;
}

#input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  transition: border-color 0.15s;
}

#input-wrapper:focus-within {
  border-color: var(--accent);
}

#message-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
}

#message-input::placeholder { color: var(--text-muted); }

#send-btn {
  background: var(--accent);
  border: none;
  color: white;
  cursor: pointer;
  border-radius: 4px;
  padding: 5px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
#send-btn:hover:not(:disabled) { background: var(--accent-hover); }
#send-btn:disabled { background: var(--border); cursor: default; opacity: 0.5; }

/* ============================================================
   Utility
   ============================================================ */
.error-msg {
  color: #f44747;
  font-style: italic;
  font-size: 12px;
}
