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

:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --border: #30363d;
  --text: #c9d1d9;
  --text2: #8b949e;
  --accent: #58a6ff;
  --accent2: #1f6feb;
  --boss: #f0883e;
  --user-msg: #1f6feb;
  --assistant-msg: #21262d;
  --radius: 8px;
}

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

#app {
  display: flex;
  height: 100vh;
}

/* Sidebar */
#sidebar {
  width: 280px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

#sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

#sidebar-header h1 {
  font-size: 22px;
  color: var(--accent);
  letter-spacing: 2px;
}

#sidebar-header p {
  font-size: 11px;
  color: var(--text2);
  margin-top: 2px;
}

#login-box {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

#email-input {
  flex: 1;
  min-width: 120px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
}

#login-btn {
  padding: 6px 12px;
  background: var(--accent2);
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  font-size: 12px;
}

#login-btn:hover { opacity: 0.85; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: bold;
}

.badge.boss { background: var(--boss); color: #000; }
.badge.famille { background: #2ea043; color: #fff; }
.badge.invite { background: var(--border); color: var(--text); }

/* Tabs */
#tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 10px 4px;
  background: transparent;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 12px;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

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

/* Conversation list */
#conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

#new-conv-btn {
  width: 100%;
  padding: 8px;
  background: var(--bg3);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 8px;
}

#new-conv-btn:hover { background: var(--border); }

.conv-item {
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 2px;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.conv-item:hover { background: var(--bg3); }
.conv-item.active { background: var(--accent2); color: white; }

.conv-item .delete-conv {
  opacity: 0;
  background: none;
  border: none;
  color: #f85149;
  cursor: pointer;
  font-size: 14px;
}

.conv-item:hover .delete-conv { opacity: 1; }

.conv-tags {
  font-size: 10px;
  color: var(--text2);
  margin-top: 2px;
}

/* Main */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.tab-content.active {
  display: flex;
}

/* Chat */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  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;
}

.message.user {
  align-self: flex-end;
  background: var(--user-msg);
  color: #fff;
  border-bottom-right-radius: 2px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant-msg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}

.message .role-label {
  font-size: 10px;
  color: var(--text2);
  margin-bottom: 4px;
  font-weight: bold;
}

/* Actions */
#chat-actions {
  display: flex;
  gap: 6px;
  padding: 0 20px 8px;
}

.action-btn {
  padding: 4px 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text2);
  cursor: pointer;
  font-size: 11px;
  transition: all 0.2s;
}

.action-btn:hover {
  background: var(--accent2);
  color: white;
  border-color: var(--accent2);
}

/* Chat form */
#chat-form {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

#chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg2);
  color: var(--text);
  resize: none;
  font-family: inherit;
  font-size: 14px;
}

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

#send-btn {
  width: 44px;
  height: 44px;
  background: var(--accent2);
  border: none;
  border-radius: var(--radius);
  color: white;
  cursor: pointer;
  font-size: 18px;
  flex-shrink: 0;
}

#send-btn:hover { opacity: 0.85; }

/* Docs tab */
#tab-docs {
  padding: 20px;
  overflow-y: auto;
  gap: 16px;
}

#tab-docs h2, #tab-docs h3 {
  color: var(--accent);
  margin-bottom: 8px;
}

#tab-docs hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

#upload-form {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

#file-input {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg2);
  color: var(--text);
  font-size: 13px;
}

#doc-status {
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 12px;
}

.doc-card {
  padding: 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.doc-card .delete-doc {
  background: none;
  border: none;
  color: #f85149;
  cursor: pointer;
  font-size: 16px;
}

#rag-form {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

#rag-input {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg2);
  color: var(--text);
  font-size: 14px;
}

#rag-result {
  padding: 12px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  white-space: pre-wrap;
  line-height: 1.6;
}

/* Memory tab */
#tab-memory {
  padding: 20px;
  overflow-y: auto;
  gap: 12px;
}

#tab-memory h2 {
  color: var(--accent);
  margin-bottom: 12px;
}

#memory-search {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg2);
  color: var(--text);
  font-size: 14px;
  margin-bottom: 12px;
}

#memory-results .memory-item {
  padding: 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 6px;
  font-size: 13px;
  line-height: 1.5;
}

/* General */
button {
  padding: 8px 16px;
  background: var(--accent2);
  border: none;
  border-radius: var(--radius);
  color: white;
  cursor: pointer;
  font-size: 13px;
  transition: opacity 0.2s;
}

button:hover { opacity: 0.85; }

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

.loading {
  opacity: 0.6;
  font-style: italic;
}

pre, code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

pre {
  padding: 12px;
  overflow-x: auto;
}

/* Responsive */
@media (max-width: 768px) {
  #sidebar {
    width: 100%;
    height: auto;
    max-height: 200px;
    overflow-y: auto;
  }
  #app {
    flex-direction: column;
  }
  .message {
    max-width: 95%;
  }
}
