:root {
  --bg: #0d1117;
  --bg-panel: #151a23;
  --bg-panel2: #1a212d;
  --bg-hover: #21293a;
  --bg-input: #10151d;
  --border: #262f3f;
  --border-soft: #1f2632;
  --text: #e6edf3;
  --text-dim: #8b98a9;
  --text-faint: #6b7686;
  --accent: #2f81f7;
  --accent-hover: #1f6feb;
  --accent-dim: rgba(47, 129, 247, .14);
  --purple: #a371f7;
  --green: #3fb950;
  --orange: #d29922;
  --red: #f85149;
  --gold: #ffd700;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 13px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; height: 100vh; }
.hidden { display: none !important; }

/* Auth */
#authOverlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: min(360px, 90vw);
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.auth-card h1 { font-size: 22px; margin: 0 0 6px; }
.auth-card h2 { font-size: 18px; margin: 0 0 8px; }
.auth-card p { margin: 0 0 18px; color: var(--text-dim); font-size: 14px; }
.auth-card input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 15px;
}
.auth-card input:focus { outline: none; border-color: var(--accent); }
.auth-card button {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 15px;
  cursor: pointer;
}
.auth-card button:hover { background: var(--accent-hover); }
.auth-error { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* Layout */
.sidebar {
  width: 260px;
  flex: 0 0 260px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 { font-size: 15px; font-weight: 600; }
.sidebar-header p { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.nav-list { flex: 1; overflow-y: auto; padding: 8px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }
.nav-item svg { width: 16px; height: 16px; flex: 0 0 16px; }
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 52px;
  flex: 0 0 52px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}
.topbar h1 { font-size: 16px; font-weight: 600; }
.topbar-actions { display: flex; gap: 8px; }

.content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-panel2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--red); border-color: rgba(248, 81, 73, 0.4); }

/* Dashboard */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.card h3 {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.card .value {
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
}
.card .value.small { font-size: 18px; }
.card .sub { color: var(--text-dim); font-size: 12px; margin-top: 6px; }
.card .value.positive { color: var(--green); }
.card .value.negative { color: var(--red); }

/* Projects list */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.project-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.project-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.project-card .header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}
.project-card .title { font-size: 15px; font-weight: 600; }
.project-card .badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-hover);
  color: var(--text-dim);
}
.project-card .badge.autonomous { background: rgba(63, 185, 80, 0.15); color: var(--green); }
.project-card .badge.supervised { background: rgba(210, 153, 34, 0.15); color: var(--orange); }
.project-card .desc {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 12px;
  min-height: 40px;
}
.project-card .footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-faint);
  font-size: 12px;
}

/* Workspace */
.workspace-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.workspace-header h2 { font-size: 18px; }
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.tab {
  padding: 10px 16px;
  cursor: pointer;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

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

.editor-field { margin-bottom: 16px; }
.editor-field label {
  display: block;
  color: var(--text-dim);
  font-size: 12px;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.editor-field textarea,
.editor-field input[type="text"],
.editor-field input[type="number"] {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  padding: 10px 12px;
  font-size: 13px;
  font-family: inherit;
}
.editor-field textarea { min-height: 100px; resize: vertical; }
.editor-field input[type="number"] { max-width: 160px; }

/* Chat */
.chat-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 220px);
}
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; }
.chat-msg { margin-bottom: 12px; max-width: 80%; }
.chat-msg.user { margin-left: auto; }
.chat-msg.assistant { margin-right: auto; }
.chat-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  background: var(--bg-panel2);
  border: 1px solid var(--border);
  white-space: pre-wrap;
}
.chat-msg.user .chat-bubble { background: var(--accent-dim); border-color: rgba(47, 129, 247, 0.3); }
.chat-msg .meta { font-size: 11px; color: var(--text-faint); margin-top: 4px; }
.chat-composer {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}
.chat-composer input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  padding: 10px 12px;
  font-size: 13px;
}
.chat-composer input:focus { outline: none; border-color: var(--accent); }

/* Tables */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
th { color: var(--text-dim); font-weight: 500; }
tr:hover td { background: rgba(255,255,255,0.02); }

.alert {
  background: rgba(248, 81, 73, 0.12);
  border: 1px solid rgba(248, 81, 73, 0.35);
  color: #ff7b72;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}

.placeholder {
  color: var(--text-dim);
  padding: 40px 20px;
  text-align: center;
  background: var(--bg-panel);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}

@media (max-width: 768px) {
  .sidebar { width: 200px; flex: 0 0 200px; }
  .projects-grid { grid-template-columns: 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
}
