:root {
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --bg-hover: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --border: #334155;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 8px;
  --sidebar-width: 220px;
}

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

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

/* Login page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box {
  background: var(--bg-secondary);
  padding: 3rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: 360px;
  text-align: center;
}
.login-box h1 { font-size: 2rem; margin-bottom: 0.25rem; color: var(--accent); }
.login-box .subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }
.login-box input {
  width: 100%;
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 1rem;
}
.login-box input:focus { outline: none; border-color: var(--accent); }
.login-box button {
  width: 100%;
  padding: 0.75rem;
  border-radius: var(--radius);
  background: var(--accent);
  color: white;
  border: none;
  font-size: 1rem;
  cursor: pointer;
}
.login-box button:hover { background: var(--accent-hover); }
.error { color: var(--danger); font-size: 0.85rem; margin-bottom: 0.5rem; }
.hidden { display: none; }

/* Layout */
#app { display: flex; height: 100vh; }

/* Sidebar */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem;
}
#sidebar-header { margin-bottom: 1rem; }
#sidebar-header h1 {
  font-size: 1.25rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
}
#model-select {
  width: 100%;
  padding: 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.8rem;
}
#nav-links { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.nav-btn {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  text-align: left;
  font-size: 0.9rem;
  cursor: pointer;
}
.nav-btn:hover { background: var(--bg-hover); color: var(--text); }
.nav-btn.active { background: var(--accent); color: white; }

#sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block;
}
.status-dot.connected { background: var(--success); }
.status-dot.disconnected { background: var(--danger); }
#logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
}
#logout-btn:hover { color: var(--text); border-color: var(--text-muted); }

/* Main area */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.panel { display: none; flex-direction: column; height: 100%; padding: 1.5rem; overflow-y: auto; }
.panel.active { display: flex; }
.panel h2 {
  font-size: 1.25rem;
  color: var(--text);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* Chat */
#chat-messages { flex: 1; overflow-y: auto; padding: 0 1rem; }
#chat-messages .message {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  max-width: 85%;
  line-height: 1.5;
  white-space: pre-wrap;
}
.message.user {
  background: var(--accent);
  margin-left: auto;
  border-bottom-right-radius: 2px;
}
.message.assistant {
  background: var(--bg-secondary);
  margin-right: auto;
  border-bottom-left-radius: 2px;
  border: 1px solid var(--border);
}
.message.tool {
  background: #1a1a2e;
  border: 1px solid var(--warning);
  margin-right: auto;
  max-width: 90%;
  font-size: 0.85rem;
  border-left: 3px solid var(--warning);
}
.tool-header {
  color: var(--warning);
  font-weight: 600;
  margin-bottom: 0.25rem;
  cursor: pointer;
}
.tool-output {
  color: var(--text-muted);
  font-family: monospace;
  font-size: 0.8rem;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg);
  padding: 0.5rem;
  border-radius: 4px;
}
.thinking {
  color: var(--text-muted);
  font-style: italic;
  padding: 0.75rem 1rem;
}
.thinking::after { content: '...'; animation: dots 1.5s steps(4, end) infinite; }
@keyframes dots {
  0% { content: '.'; }
  33% { content: '..'; }
  66% { content: '...'; }
}

#chat-input-bar {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  border-top: 1px solid var(--border);
}
#chat-input {
  flex: 1;
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 0.95rem;
  resize: none;
  font-family: inherit;
}
#chat-input:focus { outline: none; border-color: var(--accent); }
#send-btn {
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
}
#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Session list */
#session-list { display: flex; flex-direction: column; gap: 4px; }
.session-item {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.session-item:hover { background: var(--bg-hover); }
.session-title { font-weight: 500; }
.session-meta { color: var(--text-muted); font-size: 0.8rem; }
.session-actions { display: flex; gap: 0.5rem; }
.session-actions button {
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
}
.session-actions button:hover { color: var(--text); }

/* Skills */
#skill-list { display: flex; flex-direction: column; gap: 4px; }
.skill-item {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  cursor: pointer;
}
.skill-item:hover { background: var(--bg-hover); }
.skill-name { font-weight: 500; }
.skill-desc { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.25rem; }
#skill-detail {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  font-family: monospace;
  font-size: 0.85rem;
}

/* Config */
#config-display {
  background: var(--bg-secondary);
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-family: monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  line-height: 1.6;
}

/* Cron */
#cron-list { display: flex; flex-direction: column; gap: 4px; }
.cron-item {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
}
.cron-schedule { color: var(--accent); font-weight: 600; font-family: monospace; }
.cron-name { margin-top: 0.25rem; }
.cron-status { font-size: 0.8rem; margin-top: 0.25rem; }
.cron-status.active { color: var(--success); }
.cron-status.paused { color: var(--warning); }

/* Memory */
#memory-list { display: flex; flex-direction: column; gap: 4px; }
.memory-item {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
}
.memory-target {
  font-size: 0.7rem;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}
.memory-content { font-size: 0.9rem; }

/* Responsive */
@media (max-width: 768px) {
  #app { flex-direction: column; }
  #sidebar {
    width: 100%;
    min-width: 0;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  #sidebar-header { display: flex; align-items: center; gap: 0.5rem; margin: 0; }
  #sidebar-header h1 { font-size: 1rem; margin: 0; }
  #model-select { width: 120px; }
  #nav-links { flex-direction: row; flex-wrap: wrap; }
  .nav-btn { font-size: 0.75rem; padding: 0.35rem 0.5rem; }
  #sidebar-footer { display: none; }
  .message { max-width: 95%; }
}
