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

:root {
  --bg: #0b0d12;
  --surface: #12141a;
  --surface2: #1a1d27;
  --surface3: #232738;
  --border: #262a36;
  --text: #e8eaed;
  --text2: #8b8fa3;
  --accent: #6c5ce7;
  --accent2: #a78bfa;
  --green: #34d399;
  --radius: 10px;
  --radius-sm: 6px;
}

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

/* SIDEBAR */
#sidebar {
  width: 240px; min-width: 240px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 12px; gap: 8px;
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.logo { display: flex; align-items: center; gap: 8px; }
.logo-icon { color: var(--accent); font-size: 20px; }
.logo-text { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }
.btn-new {
  width: 32px; height: 32px; border-radius: 8px; border: none; background: var(--surface2);
  color: var(--text2); font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.btn-new:hover { background: var(--accent); color: #fff; }

#feature-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  border: none; background: none; color: var(--text2); font-size: 14px; cursor: pointer;
  transition: all .15s; text-align: left;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--surface2); color: var(--accent2); font-weight: 600; }
.nav-icon { font-size: 15px; width: 20px; text-align: center; }

.model-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.model-label { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.model-row select {
  flex: 1; padding: 6px 8px; background: var(--surface2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; font-size: 12px; cursor: pointer; outline: none;
}
.model-row select:focus { border-color: var(--accent); }

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

.sidebar-footer { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text2); padding-top: 8px; border-top: 1px solid var(--border); margin-top: auto; }
.dot { width: 6px; height: 6px; border-radius: 50%; }
.dot.online { background: var(--green); box-shadow: 0 0 6px rgba(52,211,153,.4); }

/* MAIN */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

.tab-content { display: none; flex-direction: column; height: 100%; }
.tab-content.active { display: flex; }
.tab-header { padding: 20px 24px 8px; }
.tab-header h2 { font-size: 18px; font-weight: 600; margin-bottom: 2px; }
.tab-header p { font-size: 13px; color: var(--text2); }

.msg-list { flex: 1; overflow-y: auto; padding: 12px 20px; display: flex; flex-direction: column; gap: 8px; }
.msg {
  max-width: 78%; padding: 10px 14px; border-radius: 12px; line-height: 1.5; font-size: 14px;
  word-wrap: break-word; white-space: pre-wrap; animation: fadeIn .2s ease;
}
.msg.user {
  align-self: flex-end; background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start; background: var(--surface2); color: var(--text);
  border-bottom-left-radius: 4px; border: 1px solid var(--border);
}
.msg.system { align-self: center; background: transparent; color: var(--text2); font-size: 12px; max-width: 100%; font-style: italic; }
.msg.tool { align-self: flex-start; background: var(--surface); color: var(--text2); font-size: 13px; border-left: 3px solid var(--accent); padding: 8px 12px; }

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

.typing {
  align-self: flex-start; background: var(--surface2); padding: 14px 18px; border-radius: 12px;
  border: 1px solid var(--border); display: flex; gap: 4px;
}
.typing span { width: 6px; height: 6px; background: var(--text2); border-radius: 50%; animation: bounce 1.4s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 0%,60%,100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }

.input-row {
  padding: 10px 16px 14px; display: flex; gap: 8px; align-items: flex-end;
  background: var(--bg); border-top: 1px solid var(--border);
}
.input-row textarea {
  flex: 1; resize: none; padding: 10px 14px; background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; font-size: 14px; font-family: inherit;
  outline: none; max-height: 120px; line-height: 1.4;
}
.input-row textarea:focus { border-color: var(--accent); }
.input-row textarea::placeholder { color: var(--text2); }

.btn-send {
  width: 38px; height: 38px; border-radius: 10px; border: none; background: var(--accent);
  color: #fff; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all .15s; flex-shrink: 0;
}
.btn-send:hover { background: var(--accent2); transform: scale(1.05); }

/* APP BUILDER */
.builder-box { padding: 16px 24px; display: flex; flex-direction: column; gap: 10px; flex: 1; overflow-y: auto; }
.builder-row { display: flex; gap: 10px; }
.builder-row select, .builder-row input {
  padding: 9px 12px; background: var(--surface2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; outline: none;
}
.builder-row select { flex: 0 0 140px; }
.builder-row input { flex: 1; }
.builder-box textarea { width: 100%; padding: 10px 12px; background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; font-size: 13px; outline: none; font-family: inherit; }
.builder-box textarea:focus { border-color: var(--accent); }
.btn-primary {
  background: var(--accent); color: #fff; border: none; padding: 9px 18px; border-radius: 8px;
  cursor: pointer; font-size: 13px; font-weight: 500; transition: all .15s; align-self: flex-start;
}
.btn-primary:hover { background: var(--accent2); }
.btn-sm {
  background: var(--surface2); color: var(--text); border: 1px solid var(--border); padding: 7px 14px;
  border-radius: 6px; cursor: pointer; font-size: 12px; transition: all .15s;
}
.btn-sm:hover { background: var(--surface3); }
#builder-status { font-size: 12px; color: var(--text2); min-height: 18px; }
.code-box {
  background: #0d0f16; padding: 14px; border-radius: 8px; font-family: 'Fira Code', 'Cascadia Code', monospace;
  font-size: 12px; line-height: 1.5; overflow: auto; max-height: 300px; white-space: pre-wrap;
  border: 1px solid var(--border); color: #a8b0c0; min-height: 40px;
}
#builder-actions { display: flex; gap: 8px; }

/* RAG */
.rag-bar {
  padding: 12px 24px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.rag-bar input[type="file"] { font-size: 12px; color: var(--text2); }
.rag-bar select { padding: 6px 10px; background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; font-size: 12px; flex: 1; min-width: 120px; }

/* SCROLLBAR */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }

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