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

:root {
  --bg: #0f1117; --bg2: #1a1c24; --bg3: #24262e;
  --text: #e4e6ef; --text2: #8b8fa3;
  --primary: #6c5ce7; --primary-hover: #7f70f0;
  --border: #2a2c35; --accent: #00d4aa;
  --radius: 8px; --radius-sm: 6px;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); }
#app { display: flex; height: 100vh; overflow: hidden; }

#sidebar {
  width: 280px; min-width: 280px; background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px; gap: 12px; overflow-y: auto;
}
.sidebar-header h1 { font-size: 18px; font-weight: 700; color: var(--primary); margin-bottom: 12px; }
.btn-primary {
  background: var(--primary); color: #fff; border: none; padding: 8px 16px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 14px; font-weight: 500; transition: background .15s;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
  background: var(--bg3); color: var(--text); border: 1px solid var(--border); padding: 8px 16px;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; text-decoration: none; display: inline-block;
}

#feature-nav { display: flex; flex-direction: column; gap: 4px; }
.feature-btn {
  display: flex; align-items: center; gap: 10px; background: none; border: none; color: var(--text2);
  padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; text-align: left; transition: all .15s;
}
.feature-btn:hover { background: var(--bg3); color: var(--text); }
.feature-btn.active { background: var(--bg3); color: var(--primary); font-weight: 600; }
.feature-btn .icon { font-size: 16px; }

.model-selector label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 4px; }
.model-selector select {
  width: 100%; padding: 8px 10px; background: var(--bg3); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 13px; cursor: pointer;
}

#conversation-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.conv-item {
  padding: 8px 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; color: var(--text2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background .15s;
}
.conv-item:hover { background: var(--bg3); }
.conv-item.active { background: var(--bg3); color: var(--text); }

.sidebar-footer { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text2); padding-top: 8px; border-top: 1px solid var(--border); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-dot.online { background: var(--accent); }
.status-dot.offline { background: #e74c3c; }

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.feature-pane { display: none; flex-direction: column; height: 100%; }
.feature-pane.active { display: flex; }
.feature-header { padding: 20px 24px 12px; border-bottom: 1px solid var(--border); }
.feature-header h2 { font-size: 20px; margin-bottom: 4px; }
.feature-header p { font-size: 13px; color: var(--text2); }

.messages { flex: 1; overflow-y: auto; padding: 16px 24px; display: flex; flex-direction: column; gap: 12px; }
.message {
  max-width: 80%; padding: 12px 16px; border-radius: var(--radius); line-height: 1.5; font-size: 14px;
  word-wrap: break-word; white-space: pre-wrap;
}
.message.user { align-self: flex-end; background: var(--primary); color: #fff; }
.message.assistant { align-self: flex-start; background: var(--bg3); color: var(--text); }
.message.system { align-self: center; background: transparent; color: var(--text2); font-style: italic; font-size: 12px; max-width: 100%; }
.message.tool { align-self: flex-start; background: var(--bg2); color: var(--text2); font-size: 13px; border-left: 3px solid var(--accent); }
.message-header { font-size: 11px; color: var(--text2); margin-bottom: 4px; font-weight: 600; text-transform: uppercase; }
.message-image { max-width: 300px; border-radius: var(--radius-sm); margin-top: 8px; }
.typing-indicator { align-self: flex-start; background: var(--bg3); padding: 12px 20px; border-radius: var(--radius); }
.typing-indicator span { display: inline-block; width: 6px; height: 6px; background: var(--text2); border-radius: 50%; margin: 0 3px; animation: typing 1.4s infinite; }
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes typing { 0%,60%,100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }

#input-area, .input-area {
  padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 12px; align-items: flex-end;
}
textarea {
  flex: 1; resize: none; padding: 12px; background: var(--bg3); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; font-family: inherit; outline: none;
}
textarea:focus { border-color: var(--primary); }

.builder-form {
  padding: 20px 24px; display: flex; flex-direction: column; gap: 12px;
}
.builder-form input, .builder-form select {
  padding: 10px 12px; background: var(--bg3); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px;
}
.builder-form textarea { width: 100%; }

#builder-output { padding: 0 24px 20px; display: flex; flex-direction: column; gap: 12px; }
.code-block {
  background: #1a1c24; padding: 16px; border-radius: var(--radius); font-family: 'Fira Code', 'Cascadia Code', monospace;
  font-size: 13px; line-height: 1.5; overflow-x: auto; max-height: 400px; overflow-y: auto; white-space: pre-wrap;
  border: 1px solid var(--border); color: #a8b0c0;
}
#builder-status { font-size: 13px; color: var(--text2); }
#builder-actions { display: flex; gap: 8px; }

.rag-upload {
  padding: 16px 24px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.rag-upload input[type="file"] { font-size: 13px; color: var(--text2); }
.rag-upload select { padding: 8px 10px; background: var(--bg3); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; flex: 1; min-width: 150px; }

@media (max-width: 768px) {
  #sidebar { width: 100%; min-width: unset; display: none; }
  #sidebar.open { display: flex; position: fixed; z-index: 100; height: 100vh; }
  .message { max-width: 90%; }
}
