@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&family=Source+Sans+3:wght@400;500;600&display=swap');

:root {
  --bg-deep: #0a0e17;
  --bg-surface: #111827;
  --bg-raised: #1a2233;
  --bg-hover: #1f2b3d;
  --bg-row-alt: #0f1520;

  --text-primary: #c9d1d9;
  --text-secondary: #7d8590;
  --text-muted: #484f58;
  --text-bright: #e6edf3;

  --accent: #f0b429;
  --accent-dim: #a17a1a;
  --accent-glow: rgba(240, 180, 41, 0.12);

  --danger: #da3633;
  --danger-dim: #8b2220;

  --type-agent: #2dd4bf;
  --type-file: #818cf8;

  --border: #21262d;
  --border-subtle: #161b22;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;

  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --font-ui: 'Source Sans 3', 'Source Sans Pro', system-ui, sans-serif;
}

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

html {
  font-size: 15px;
}

body {
  font-family: var(--font-ui);
  background: var(--bg-deep);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Navigation ── */

.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 48px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text-bright);
}

.brand-icon {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--accent);
}

.brand-text {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
}

.nav-links a {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}

.nav-links a:hover {
  color: var(--accent);
  background: var(--accent-glow);
}

.activity-indicator {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.3s;
}

.activity-indicator.active {
  opacity: 1;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* ── Container ── */

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ── Page Header ── */

.page-header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-bright);
}

.page-count {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Project Cards ── */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.project-card {
  display: block;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.project-card:hover {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 1px var(--accent-dim), 0 4px 24px rgba(0, 0, 0, 0.3);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.card-title {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-bright);
}

.card-count {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--accent);
}

.card-stats {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 0.75rem;
}

.stat {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.25rem;
}

/* ── Tag Pills ── */

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 9999px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.tag-count {
  color: var(--text-muted);
  font-size: 0.65rem;
}

/* ── Type Badges ── */

.type-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.type-agent-memory {
  background: rgba(45, 212, 191, 0.1);
  color: var(--type-agent);
  border: 1px solid rgba(45, 212, 191, 0.2);
}

.type-file-indexed {
  background: rgba(129, 140, 248, 0.1);
  color: var(--type-file);
  border: 1px solid rgba(129, 140, 248, 0.2);
}

.indexing-badge {
  font-size: 0.75rem;
  color: var(--accent);
  background: var(--surface);
  padding: 2px 8px;
  border-radius: 4px;
  animation: pulse 1.5s ease-in-out infinite;
}

/* ── Empty State ── */

.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-secondary);
}

.empty-icon {
  font-family: var(--font-mono);
  font-size: 3rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.empty-hint {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.empty-hint code {
  font-family: var(--font-mono);
  color: var(--accent);
  background: var(--accent-glow);
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-sm);
}

.empty-table {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

/* ── Filter Bar ── */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.filter-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  flex: 1;
}

.search-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.filter-bar select,
.filter-bar input[type="text"] {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.4rem 0.6rem;
  background: var(--bg-deep);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s;
}

.filter-bar select:focus,
.filter-bar input[type="text"]:focus {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 1px var(--accent-glow);
}

.filter-bar input[type="text"]::placeholder {
  color: var(--text-muted);
}

.filter-bar input[name="q"] {
  min-width: 200px;
}

/* ── Table Actions ── */

.table-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

/* ── Buttons ── */

.btn {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.btn:hover {
  color: var(--text-bright);
  border-color: var(--text-muted);
  background: var(--bg-raised);
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-ghost {
  border-color: transparent;
}

.btn-ghost:hover {
  border-color: transparent;
  color: var(--accent);
  background: var(--accent-glow);
}

.btn-danger:hover {
  color: var(--danger);
  border-color: var(--danger-dim);
  background: rgba(218, 54, 51, 0.08);
}

.btn-icon {
  padding: 0.2rem 0.45rem;
  font-size: 1rem;
  line-height: 1;
  border: none;
  color: var(--text-muted);
}

.btn-icon:hover {
  border: none;
  background: transparent;
}

.btn-delete:hover {
  color: var(--danger);
}

/* ── Memory Table ── */

.memory-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.memory-table thead {
  position: sticky;
  top: 48px;
  z-index: 10;
}

.memory-table th {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 0.6rem 0.75rem;
  text-align: left;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.memory-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}

.memory-row:nth-child(even) {
  background: var(--bg-row-alt);
}

.memory-row:hover {
  background: var(--bg-hover);
}

.col-check {
  width: 32px;
  text-align: center;
}

.col-content {
  min-width: 300px;
}

.col-source {
  max-width: 180px;
}

.col-tags {
  max-width: 200px;
}

.col-type {
  width: 110px;
}

.col-date {
  width: 90px;
}

.col-actions {
  width: 40px;
  text-align: center;
}

.col-content {
  cursor: pointer;
}

.content-snippet {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--text-primary);
  word-break: break-word;
}

.content-full {
  display: none;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--text-primary);
  word-break: break-word;
  white-space: pre-wrap;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border-subtle);
  margin-top: 0.4rem;
}

.col-content.expanded .content-snippet {
  display: none;
}

.col-content.expanded .content-full {
  display: block;
}

.source-text {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-secondary);
  word-break: break-all;
}

.date-text {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* checkboxes */
input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Pagination ── */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.5rem;
  padding: 0.75rem 0;
}

.page-info {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Scrollbar ── */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-deep);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ── HTMX loading indicator ── */

.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator {
  display: inline-block;
}

.htmx-request.htmx-indicator {
  display: inline-block;
}

/* Fade rows in after HTMX swap */
.memory-row {
  animation: fadeIn 0.15s ease-in;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
