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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3a;
  --text: #e2e8f0;
  --muted: #8b92a5;
  --accent: #6366f1;
  --accent-hover: #4f52d8;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --user-bubble: #1e3a5f;
  --claude-bubble: #1a2535;
  --radius: 8px;
  --radius-lg: 12px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.container { max-width: 960px; margin: 0 auto; padding: 0 1.5rem; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0;
}
header .inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
header h1 { font-size: 1.1rem; font-weight: 600; color: var(--text); }
header .nav { display: flex; align-items: center; gap: 0.75rem; }
.username-badge {
  color: var(--muted);
  font-size: 0.875rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); text-decoration: none; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #353848; text-decoration: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
input[type="text"], input[type="password"] {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus, input[type="password"]:focus {
  border-color: var(--accent);
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}
th { color: var(--muted); font-weight: 500; }
tr:last-child td { border-bottom: none; }

/* Page sections */
.page { padding: 2rem 0; }
.page-title {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
}
.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
  margin-bottom: 0.75rem;
}

/* Alert */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}
.alert-error { background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.3); color: #fca5a5; }
.alert-success { background: rgba(34,197,94,0.12); border: 1px solid rgba(34,197,94,0.3); color: #86efac; }

/* Login */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}
.login-card h1 {
  font-size: 1.3rem;
  margin-bottom: 0.25rem;
}
.login-card .subtitle {
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
}

/* Codebase grid */
.codebase-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.codebase-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.codebase-card:hover { border-color: var(--accent); background: #1e2133; }
.codebase-card h3 { font-size: 1rem; margin-bottom: 0.25rem; }
.codebase-card .path { color: var(--muted); font-size: 0.8rem; font-family: monospace; }
.codebase-card .sync-time { color: var(--muted); font-size: 0.75rem; margin-top: 0.5rem; }

/* Sessions list */
.sessions-list { display: flex; flex-direction: column; gap: 0.5rem; }
.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}
.session-item .meta { font-size: 0.8rem; color: var(--muted); }

/* Chat UI */
.chat-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 57px);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.message { display: flex; gap: 0.75rem; }
.message.user { flex-direction: row-reverse; }
.message-bubble {
  max-width: 75%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-lg);
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.message.user .message-bubble { background: var(--user-bubble); border-bottom-right-radius: 4px; }
.message.assistant .message-bubble { background: var(--claude-bubble); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
  background: var(--border);
  color: var(--muted);
}
.message.user .message-avatar { background: var(--accent); color: #fff; }

.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem;
  background: var(--surface);
}
.chat-input-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}
textarea {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  font-family: inherit;
  resize: none;
  outline: none;
  min-height: 44px;
  max-height: 180px;
  line-height: 1.5;
  transition: border-color 0.15s;
}
textarea:focus { border-color: var(--accent); }
textarea::placeholder { color: var(--muted); }

.loading-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0 1.5rem 0.5rem;
}
.dot-pulse {
  display: flex;
  gap: 3px;
}
.dot-pulse span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: pulse 1.2s infinite;
}
.dot-pulse span:nth-child(2) { animation-delay: 0.2s; }
.dot-pulse span:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

.hidden { display: none !important; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 400px;
}
.modal h3 { margin-bottom: 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.25rem; }
