/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0f;
  --bg2: #111118;
  --bg3: #1a1a24;
  --bg4: #22222f;
  --border: #2a2a3a;
  --border2: #3a3a50;
  --text: #e8e8f0;
  --text2: #9090a8;
  --text3: #6060780;
  --accent: #6366f1;
  --accent2: #8b5cf6;
  --accent3: #a78bfa;
  --green: #10b981;
  --red: #ef4444;
  --yellow: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 48px rgba(0,0,0,0.6);
  --glow: 0 0 20px rgba(99,102,241,0.3);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ===== HEADER ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10,10,15,0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 32px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  flex-shrink: 0;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, rgba(99,102,241,0.2), rgba(139,92,246,0.2));
  border: 1px solid rgba(99,102,241,0.4);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-title {
  display: block;
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, #6366f1, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}

.logo-sub {
  display: block;
  font-size: 10px;
  color: var(--text2);
  font-weight: 400;
  letter-spacing: 0.5px;
}

.nav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--text2);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  font-family: inherit;
}

.nav-btn:hover { color: var(--text); background: var(--bg3); }
.nav-btn.active { color: var(--accent3); background: rgba(99,102,241,0.15); }

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border2);
  transition: all 0.3s;
}

.status-dot.online { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status-dot.error { background: var(--red); }

.status-text {
  font-size: 13px;
  color: var(--text2);
}

/* ===== MAIN ===== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ===== TAB PANELS ===== */
.tab-panel { display: none; flex: 1; }
.tab-panel.active { display: flex; flex-direction: column; flex: 1; }

/* ===== CHAT LAYOUT ===== */
.chat-layout {
  display: flex;
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
  gap: 24px;
  height: calc(100vh - 64px);
}

/* ===== SIDEBAR ===== */
.chat-sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.sidebar-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.sidebar-card h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text2);
}

.stat-row:last-child { border-bottom: none; }

.stat-val {
  font-weight: 600;
  color: var(--accent3);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}

.cap-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }

.cap-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text2);
}

.cap-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border2);
  flex-shrink: 0;
}

.cap-item.active .cap-dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.cap-item.active { color: var(--text); }

.quick-cmds { display: flex; flex-direction: column; gap: 8px; }

.refresh-prompts {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
  opacity: 0.6;
  transition: all 0.2s;
  vertical-align: middle;
}

.refresh-prompts:hover { opacity: 1; color: var(--accent3); transform: rotate(180deg); }

.quick-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  text-align: left;
  transition: all 0.2s;
  font-family: inherit;
}

.quick-btn:hover {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(99,102,241,0.1);
}

/* ===== CHAT CONTAINER ===== */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-width: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ===== WELCOME ===== */
.welcome-msg {
  text-align: center;
  padding: 60px 40px;
  max-width: 500px;
  margin: auto;
}

.welcome-icon {
  font-size: 56px;
  margin-bottom: 20px;
  filter: drop-shadow(0 0 20px rgba(99,102,241,0.5));
}

.welcome-msg h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #e8e8f0, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-msg p {
  color: var(--text2);
  line-height: 1.7;
  margin-bottom: 12px;
  font-size: 15px;
}

.welcome-hint {
  background: rgba(99,102,241,0.1);
  border: 1px solid rgba(99,102,241,0.3);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--accent3);
}

.welcome-hint strong { color: var(--accent3); }

/* ===== MESSAGES ===== */
.message {
  display: flex;
  gap: 12px;
  animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  font-weight: 600;
}

.message.user .msg-avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  font-size: 13px;
}

.message.ai .msg-avatar {
  background: linear-gradient(135deg, rgba(99,102,241,0.2), rgba(139,92,246,0.2));
  border: 1px solid rgba(99,102,241,0.3);
}

.msg-content { max-width: 75%; display: flex; flex-direction: column; gap: 4px; }

.message.user .msg-content { align-items: flex-end; }

.msg-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
}

.message.user .msg-bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  border-bottom-right-radius: 4px;
}

.message.ai .msg-bubble {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.msg-bubble pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
}

.msg-bubble code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  background: rgba(99,102,241,0.15);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent3);
}

.msg-bubble pre code {
  background: none;
  padding: 0;
  color: var(--text);
}

.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; margin: 8px 0; }
.msg-bubble li { margin-bottom: 4px; }
.msg-bubble strong { color: var(--accent3); font-weight: 600; }
.msg-bubble em { color: var(--text2); }

.msg-meta {
  font-size: 11px;
  color: var(--text2);
  display: flex;
  align-items: center;
  gap: 8px;
}

.msg-memory-tag {
  background: rgba(16,185,129,0.15);
  border: 1px solid rgba(16,185,129,0.3);
  color: var(--green);
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 500;
}

/* ===== THINKING ===== */
.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--text2);
  font-size: 13px;
  border-top: 1px solid var(--border);
}

.thinking-dots {
  display: flex;
  gap: 4px;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ===== INPUT AREA ===== */
.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 16px;
  background: var(--bg2);
}

.input-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 200px;
  transition: border-color 0.2s;
  line-height: 1.5;
}

.chat-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

.chat-input::placeholder { color: var(--text2); }

.send-btn {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  border-radius: var(--radius);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.send-btn:hover { transform: scale(1.05); box-shadow: var(--glow); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text2);
}

.clear-btn {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  transition: color 0.2s;
}

.clear-btn:hover { color: var(--red); }

/* ===== PAGE INNER ===== */
.page-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 24px;
  width: 100%;
}

.page-header {
  margin-bottom: 32px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.page-header h2 {
  font-size: 28px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--text), var(--accent3));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.page-header p {
  color: var(--text2);
  margin-top: 4px;
  font-size: 15px;
}

/* ===== MEMORY GRID ===== */
.memory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.memory-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: all 0.2s;
  animation: fadeInUp 0.3s ease;
}

.memory-card:hover {
  border-color: var(--accent);
  box-shadow: var(--glow);
}

.memory-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.memory-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.memory-tag.fact { background: rgba(99,102,241,0.2); color: var(--accent3); border: 1px solid rgba(99,102,241,0.3); }
.memory-tag.context { background: rgba(16,185,129,0.2); color: var(--green); border: 1px solid rgba(16,185,129,0.3); }
.memory-tag.preference { background: rgba(245,158,11,0.2); color: var(--yellow); border: 1px solid rgba(245,158,11,0.3); }
.memory-tag.knowledge { background: rgba(139,92,246,0.2); color: var(--accent2); border: 1px solid rgba(139,92,246,0.3); }

.memory-score {
  font-size: 11px;
  color: var(--text2);
  font-family: 'JetBrains Mono', monospace;
}

.memory-text {
  font-size: 13px;
  color: var(--text2);
  line-height: 1.6;
  margin-bottom: 10px;
}

.memory-footer {
  font-size: 11px;
  color: var(--text2);
  display: flex;
  justify-content: space-between;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 40px;
  color: var(--text2);
}

.empty-state span { font-size: 48px; display: block; margin-bottom: 16px; }
.empty-state p { font-size: 15px; }

/* ===== SETTINGS ===== */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 24px;
}

.settings-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.settings-card h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text);
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 8px;
}

.form-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

.form-input::placeholder { color: var(--text2); }

select.form-input { cursor: pointer; }
select.form-input option { background: var(--bg3); }

.form-group small {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text2);
  line-height: 1.5;
}

.input-with-toggle {
  position: relative;
}

.input-with-toggle .form-input { padding-right: 44px; }

.toggle-vis {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.toggle-vis:hover { opacity: 1; }

.range-input {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
  margin: 8px 0;
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  color: white;
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.2s;
  width: 100%;
}

.primary-btn:hover { opacity: 0.9; box-shadow: var(--glow); }

.danger-btn {
  background: rgba(239,68,68,0.15);
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--red);
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.2s;
}

.danger-btn:hover { background: rgba(239,68,68,0.25); }

.connection-test {
  margin-top: 12px;
  font-size: 13px;
  min-height: 20px;
}

.connection-test.success { color: var(--green); }
.connection-test.error { color: var(--red); }

/* ===== ABOUT ===== */
.about-hero {
  text-align: center;
  padding: 48px 0 40px;
}

.about-icon {
  font-size: 72px;
  margin-bottom: 20px;
  filter: drop-shadow(0 0 30px rgba(99,102,241,0.6));
}

.about-hero h1 {
  font-size: 40px;
  font-weight: 800;
  background: linear-gradient(135deg, #e8e8f0, #6366f1, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.about-version {
  color: var(--text2);
  font-size: 15px;
}

.about-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

.about-card--wide {
  grid-column: 1 / -1;
}

.about-card pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  overflow-x: auto;
  margin: 10px 0 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text2);
}

.about-card code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  background: rgba(99,102,241,0.15);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent3);
}

.about-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  transition: all 0.2s;
}

.about-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.about-card h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

.about-card p {
  font-size: 14px;
  color: var(--text2);
  line-height: 1.7;
}

.about-card ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.about-card li {
  font-size: 14px;
  color: var(--text2);
  padding-left: 16px;
  position: relative;
}

.about-card li::before {
  content: '→';
  position: absolute;
  left: 0;
  color: var(--accent);
}

.about-card em { color: var(--accent3); font-style: normal; font-weight: 500; }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  font-size: 14px;
  color: var(--text);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  animation: slideIn 0.3s ease;
  max-width: 320px;
}

.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .chat-sidebar { display: none; }
  .chat-layout { padding: 16px; }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .header-inner { padding: 0 16px; gap: 16px; }
  .nav-btn { padding: 6px 10px; font-size: 13px; }
  .page-inner { padding: 24px 16px; }
}
