:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #0b1220;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --user-bg: #1e3a5f;
  --assistant-bg: #1e293b;
  --error: #f87171;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: min(360px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.login-card input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.5rem 0.75rem;
  font: inherit;
}

.error-text { color: var(--error); font-size: 0.85rem; }
.muted { color: var(--muted); font-size: 0.9rem; }

.app {
  display: grid;
  grid-template-columns: 240px 1fr 420px;
  height: 100vh;
}

.sidebar {
  background: var(--surface2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  gap: 0.75rem;
  min-width: 0;
}

.brand { font-weight: 600; font-size: 0.9rem; }
.logo { color: var(--accent); }

.sidebar-section { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.files-section { flex: 0 0 35%; }
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.thread-list, .file-tree {
  list-style: none;
  overflow-y: auto;
  font-size: 0.85rem;
}

.thread-item, .file-tree li {
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-item:hover, .file-tree li:hover { background: var(--surface); }
.thread-item.active { background: var(--surface); color: var(--accent); }
.file-tree li.dir::before { content: '📁 '; }
.file-tree li.file::before { content: '📄 '; }

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
}

.sidebar-footer select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem;
  font-size: 0.8rem;
}

.mode-toggle { display: flex; gap: 0.25rem; }
.mode-btn {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 0.3rem;
  cursor: pointer;
  font-size: 0.75rem;
}
.mode-btn.active { border-color: var(--accent); color: var(--accent); }

.btn-link, .health-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  text-align: left;
  font-size: 0.75rem;
  text-decoration: none;
}

.editor-pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 0;
}

.editor-tabs {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.editor {
  flex: 1;
  resize: none;
  background: var(--bg);
  color: var(--text);
  border: none;
  padding: 1rem;
  font: 0.9rem/1.5 ui-monospace, monospace;
}

.chat-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.llm-banner {
  background: #7f1d1d;
  color: #fecaca;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.welcome { color: var(--muted); text-align: center; margin: auto; }
.welcome h2 { color: var(--text); margin-bottom: 0.35rem; }

.msg {
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.9rem;
}

.msg.user { background: var(--user-bg); }
.msg.assistant { background: var(--assistant-bg); border: 1px solid var(--border); }
.msg.error { border-color: var(--error); color: #fca5a5; }
.msg .role { font-size: 0.65rem; text-transform: uppercase; color: var(--muted); margin-bottom: 0.25rem; }
.typing::after { content: '▋'; animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

.agent-steps {
  max-height: 200px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
}

.agent-steps .step { margin-bottom: 0.5rem; }
.agent-steps pre {
  background: var(--surface);
  padding: 0.35rem;
  border-radius: 4px;
  overflow-x: auto;
  white-space: pre-wrap;
  font-size: 0.75rem;
}

.composer {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
}

.composer textarea {
  flex: 1;
  resize: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font: inherit;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  font: inherit;
}

.btn-primary {
  background: var(--accent);
  color: #0f172a;
  font-weight: 600;
  padding: 0 1rem;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.25rem 0.5rem;
}

.btn-sm { font-size: 0.75rem; }
.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 4px;
  line-height: 1;
}

@media (max-width: 1000px) {
  .app { grid-template-columns: 1fr; }
  .editor-pane { display: none; }
}
