:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-card-h: #1c2333;
  --bg-sidebar: #0d1117;
  --bg-hover: #1c2333;
  --border: #30363d;
  --text: #e6edf3;
  --text-sec: #8b949e;
  --text-muted: #484f58;
  --accent: #58a6ff;
  --green: #3fb950;
  --orange: #d29922;
  --red: #f85149;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
  --mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --radius: 8px;
  --radius-sm: 6px;
}

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

html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

/* Layout */
.layout {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 8px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.logo { font-size: 24px; line-height: 1; }

.sidebar-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.3px;
}

.sidebar-subtitle {
  font-size: 11px;
  color: var(--text-sec);
}

.conn-bar {
  padding: 4px 0;
}

.conn-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  display: inline-block;
}

.conn-badge.connected { background: #1a7f37; color: #fff; }
.conn-badge.connecting { background: #9e6a03; color: #fff; }
.conn-badge.disconnected { background: #21262d; color: var(--text-sec); }
.conn-badge.error { background: #cf222e; color: #fff; }
.conn-badge.auth { background: #9e6a03; color: #fff; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--text-sec);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
  text-align: left;
}

.nav-btn:hover { background: var(--bg-hover); color: var(--text); }

.nav-btn.active {
  background: var(--bg-card);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-footer {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.text-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  text-align: left;
  padding: 0;
}

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

/* Main content */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Dashboard grid */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card-h {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-sec);
}

.card-b { padding: 10px 14px; }

/* Info rows */
.ir {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(48, 54, 61, 0.4);
  font-size: 13px;
}

.ir:last-child { border-bottom: none; }

.ir-l { color: var(--text-sec); }
.ir-v { color: var(--text); }
.ir-v.mono { font-family: var(--mono); font-size: 12px; }

.status-pending { color: var(--orange); }
.status-ok { color: var(--green); }

/* Memory items */
.mem-item { padding: 6px 0; border-bottom: 1px solid rgba(48,54,61,0.3); }
.mem-item:last-child { border-bottom: none; }
.mem-d { font-size: 11px; color: var(--text-muted); font-family: var(--mono); }
.mem-t { font-size: 13px; font-weight: 600; }
.mem-s { font-size: 12px; color: var(--text-sec); }

/* Chat */
.chat-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 40px);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-msg {
  padding: 10px 14px;
  border-radius: var(--radius);
  max-width: 80%;
}

.chat-msg.user {
  align-self: flex-end;
  background: #1f6feb;
  color: #fff;
}

.chat-msg.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.chat-msg.system {
  align-self: center;
  font-size: 12px;
  color: var(--text-sec);
  padding: 4px 8px;
  background: transparent;
}

.msg-label {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
  opacity: 0.8;
}

.msg-text {
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

/* Chat composer */
.chat-composer {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--text-muted); }

/* Buttons */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.15); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--bg-hover); }

.btn-send {
  background: var(--accent);
  color: #fff;
  padding: 10px 20px;
}

.btn-send:hover { filter: brightness(1.15); }

.text-secondary { color: var(--text-sec); }

/* Token Dialog */
.token-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.token-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 420px;
  max-width: 90vw;
}

.token-dialog-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
}

.token-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: var(--mono);
  outline: none;
  margin-bottom: 12px;
}

.token-input:focus { border-color: var(--accent); }

.token-actions {
  display: flex;
  justify-content: flex-end;
}

code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 12px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { width: 56px; min-width: 56px; overflow: hidden; }
  .sidebar-title, .sidebar-subtitle, .sidebar-footer, .nav-btn span:not(:first-child) { display: none; }
  .nav-btn { justify-content: center; padding: 10px; }
  .dash-grid { grid-template-columns: 1fr; }
  .main-content { padding: 12px; }
}
