/* Balmung MCP Dashboard — Dark Theme */

:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-card-hover: #222633;
  --bg-input: #252830;
  --border: #2d3140;
  --text: #e4e6ed;
  --text-muted: #8b8fa3;
  --accent: #5b8af5;
  --accent-hover: #4a7ae8;
  --green: #3dd68c;
  --red: #f5555b;
  --orange: #f5a623;
  --font-mono: "SF Mono", "Cascadia Code", "Fira Code", "JetBrains Mono", Consolas, monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius: 8px;
}

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

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

.hidden { display: none !important; }

/* ---- Login ---- */

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3rem;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-box h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.login-subtitle {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.login-box input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font-mono);
  margin-bottom: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

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

.login-box button {
  width: 100%;
  padding: 0.75rem;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.login-box button:hover { background: var(--accent-hover); }

.error-msg {
  color: var(--red);
  font-size: 0.85rem;
  margin-top: 0.75rem;
}

/* ---- Header ---- */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.header-badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  background: var(--green);
  color: #000;
  font-weight: 600;
}

.btn-logout {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  padding: 0.4rem 1rem;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.btn-logout:hover {
  color: var(--red);
  border-color: var(--red);
}

/* ---- Tabs ---- */

.tabs {
  display: flex;
  gap: 0;
  padding: 0 2rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  padding: 0.75rem 1.25rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
  transition: all 0.2s;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---- Tab Content ---- */

.tab-content {
  display: none;
  padding: 1.5rem 2rem;
  max-width: 1400px;
}

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

/* ---- Cards ---- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

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

.card-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.card-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
}

/* ---- Tables ---- */

.table-wrap {
  overflow-x: auto;
  margin-bottom: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  font-family: var(--font-mono);
}

th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

tr:hover td { background: var(--bg-card-hover); }

tr.clickable { cursor: pointer; }

.status-ok { color: var(--green); }
.status-err { color: var(--red); }
.status-active { color: var(--green); }
.status-ended { color: var(--text-muted); }

.muted { color: var(--text-muted); font-style: italic; font-size: 0.85rem; }

/* ---- Filters ---- */

.filters {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: center;
}

.filters select {
  padding: 0.5rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font-mono);
  outline: none;
  min-width: 160px;
}

.filters select:focus { border-color: var(--accent); }

.btn-small {
  padding: 0.5rem 1rem;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s;
}

.btn-small:hover { background: var(--accent-hover); }

/* ---- Pagination ---- */

.pagination {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  padding: 1rem 0;
  font-size: 0.85rem;
}

.pagination button {
  padding: 0.4rem 0.8rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}

.pagination button:hover { border-color: var(--accent); color: var(--accent); }
.pagination button:disabled { opacity: 0.4; cursor: default; }
.pagination span { color: var(--text-muted); }

/* ---- Modal ---- */

.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 800px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}

.modal-content h3 { margin-bottom: 1rem; }

.modal-content pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-y: auto;
  max-height: 60vh;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover { color: var(--text); }

/* ---- Embeddings ---- */

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

.btn-primary {
  padding: 0.5rem 1.25rem;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.sync-status {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.sync-status.running { background: rgba(91, 138, 245, 0.15); border: 1px solid var(--accent); }
.sync-status.done { background: rgba(61, 214, 140, 0.15); border: 1px solid var(--green); }
.sync-status.error { background: rgba(245, 85, 91, 0.15); border: 1px solid var(--red); }

.emb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.emb-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.emb-card-name {
  font-weight: 600;
  text-transform: capitalize;
  font-size: 0.95rem;
}

.emb-card-count {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
}

.emb-card-sync {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.emb-card button {
  margin-top: auto;
  padding: 0.35rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  align-self: flex-start;
}

.emb-card button:hover { border-color: var(--accent); color: var(--accent); }
.emb-card button:disabled { opacity: 0.4; cursor: default; }

/* ---- Bar Chart (CSS-only) ---- */

.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 2rem;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.bar-label {
  min-width: 120px;
  text-align: right;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-track {
  flex: 1;
  height: 24px;
  background: var(--bg-card);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.4s ease;
  min-width: 2px;
}

.bar-fill.error { background: var(--red); }

.bar-value {
  min-width: 60px;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* ---- Responsive ---- */

@media (max-width: 768px) {
  header { padding: 0.75rem 1rem; }
  .tabs { padding: 0 1rem; }
  .tab-content { padding: 1rem; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .emb-grid { grid-template-columns: repeat(2, 1fr); }
  .filters { flex-direction: column; }
  .filters select { width: 100%; }
  .bar-label { min-width: 80px; font-size: 0.7rem; }
  td { font-size: 0.75rem; }
}

/* ---- Loading spinner ---- */

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 0.5rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Event type badges ---- */

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-start { background: rgba(61, 214, 140, 0.2); color: var(--green); }
.badge-end { background: rgba(139, 143, 163, 0.2); color: var(--text-muted); }
.badge-error { background: rgba(245, 85, 91, 0.2); color: var(--red); }
