/* ─── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-hover: #22263a;
  --border: #2a2d3e;
  --text: #e2e8f0;
  --text-muted: #8892a4;
  --text-dim: #4a5568;
  --accent: #6c63ff;
  --accent-light: #8b85ff;
  --green: #48bb78;
  --yellow: #ecc94b;
  --red: #fc8181;
  --blue: #63b3ed;
  --orange: #f6ad55;
  --sidebar-width: 220px;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f8fc;
    --bg-card: #ffffff;
    --bg-hover: #f0f2f8;
    --border: #e2e6ef;
    --text: #1a202c;
    --text-muted: #4a5568;
    --text-dim: #a0aec0;
    --accent: #6c63ff;
  }
}

/* ─── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
}

/* ─── Project Switcher ──────────────────────────────────────────────────────── */
.project-switcher {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  flex-shrink: 0;
  z-index: 100;
}
.switcher-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 48px;
}
.switcher-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.switcher-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  white-space: nowrap;
}
.switcher-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  padding: 5px 10px;
  cursor: pointer;
  max-width: 200px;
}
.switcher-select:focus { outline: none; border-color: var(--accent); }
.switcher-arrow { color: var(--text-dim); flex-shrink: 0; }
.switcher-manage {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: var(--radius);
  transition: background 0.15s, color 0.15s;
}
.switcher-manage:hover { background: var(--bg-hover); color: var(--text); }

/* ─── App layout ────────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  height: 100%;
  overflow-y: auto;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 20px 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 24px;
  font-weight: 700;
  font-size: 16px;
  color: var(--accent-light);
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.nav-links {
  list-style: none;
  padding: 0 10px;
}

.nav-links li { margin: 2px 0; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  font-size: 13.5px;
}

.nav-link:hover { background: var(--bg-hover); color: var(--text); }
.nav-link.active { background: rgba(108, 99, 255, 0.15); color: var(--accent-light); }

/* ─── Sidebar footer (aktueller User / Abmelden) ────────────────────────────── */
.sidebar-footer {
  margin-top: auto;
  padding: 12px 20px 0;
  border-top: 1px solid var(--border);
}
.sidebar-user-email {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 4px;
}
.sidebar-logout {
  font-size: 12.5px;
  color: var(--text-dim);
  text-decoration: none;
}
.sidebar-logout:hover { color: var(--red); }

/* ─── Main content ──────────────────────────────────────────────────────────── */
.main-content { flex: 1; overflow-y: auto; padding: 28px 32px; }

.view { display: none; }
.view.active { display: block; }

/* ─── Nav separator ─────────────────────────────────────────────────────────── */
.nav-separator {
  height: 1px;
  background: var(--border);
  margin: 8px 10px;
}

/* ─── Page header ───────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h1 { font-size: 22px; font-weight: 700; }
.page-subtitle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ─── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ─── Stats grid ────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}

.stat-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ─── Tables ────────────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); cursor: pointer; }
tr.no-hover:hover td { background: transparent; cursor: default; }

/* ─── Badges ────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green  { background: rgba(72, 187, 120, 0.15); color: var(--green); }
.badge-yellow { background: rgba(236, 201, 75, 0.15);  color: var(--yellow); }
.badge-red    { background: rgba(252, 129, 129, 0.15); color: var(--red); }
.badge-blue   { background: rgba(99, 179, 237, 0.15);  color: var(--blue); }
.badge-gray   { background: rgba(74, 85, 104, 0.2);    color: var(--text-muted); }
.badge-purple { background: rgba(108, 99, 255, 0.15);  color: var(--accent-light); }

/* ─── Source indicators ─────────────────────────────────────────────────────── */
.source-dots { display: flex; gap: 6px; flex-wrap: wrap; }
.source-dot {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
}
.source-dot::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}
.source-dot.has-mention { color: var(--text); }
.source-dot.source-openai::before      { background: #10a37f; }
.source-dot.source-claude::before      { background: #d97706; }
.source-dot.source-perplexity::before  { background: #3b82f6; }
.source-dot.source-google::before      { background: #ef4444; }

/* ─── Trend arrows ──────────────────────────────────────────────────────────── */
.trend-up   { color: var(--green); }
.trend-down { color: var(--red); }
.trend-flat { color: var(--text-muted); }

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: opacity 0.15s;
  text-decoration: none;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--accent); color: white; }
.btn-ghost   { background: var(--bg-hover); color: var(--text); border: 1px solid var(--border); }

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

/* ─── Chart containers ──────────────────────────────────────────────────────── */
.chart-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}
.chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.chart-canvas-wrap { position: relative; height: 260px; }

/* ─── Status run bar ────────────────────────────────────────────────────────── */
.run-status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  font-size: 13px;
}
.run-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}
.run-dot.running  { background: var(--yellow); animation: pulse 1s infinite; }
.run-dot.completed { background: var(--green); }
.run-dot.failed    { background: var(--red); }

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

/* ─── Snippet ───────────────────────────────────────────────────────────────── */
.snippet {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg);
  border-radius: 4px;
  padding: 8px 10px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.snippet mark {
  background: rgba(108, 99, 255, 0.3);
  color: var(--accent-light);
  border-radius: 2px;
}

/* ─── Accordion ─────────────────────────────────────────────────────────────── */
.accordion-item { border-bottom: 1px solid var(--border); }
.accordion-header {
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text);
  font-size: 13px;
}
.accordion-header:hover { background: var(--bg-hover); }
.accordion-body { padding: 0 16px 16px; display: none; }
.accordion-body.open { display: block; }

/* ─── Empty state ───────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state svg { margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 13px; }

/* ─── Loading ───────────────────────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--text-muted);
}
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Grid ──────────────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ─── Back link ─────────────────────────────────────────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  margin-bottom: 16px;
}
.back-link:hover { color: var(--text); }

/* ─── Target filter bar ─────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.filter-pill {
  padding: 4px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.filter-pill:hover { border-color: var(--accent); color: var(--text); }
.filter-pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ─── Forms ─────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.form-input, .form-textarea, .form-select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  padding: 8px 12px;
  transition: border-color 0.15s;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  outline: none;
  border-color: var(--accent);
}
.form-textarea {
  resize: vertical;
  min-height: 90px;
  line-height: 1.5;
}
.form-help {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

/* ─── Modal overlay ──────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 480px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 20px;
}

/* ─── Btn danger ─────────────────────────────────────────────────────────────── */
.btn-danger { background: rgba(252,129,129,0.15); color: var(--red); border: 1px solid rgba(252,129,129,0.3); }
.btn-danger:hover { background: rgba(252,129,129,0.25); opacity: 1; }

/* ─── Tag input ──────────────────────────────────────────────────────────────── */
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(108,99,255,0.15);
  color: var(--accent-light);
  border-radius: 20px;
  padding: 2px 10px 2px 10px;
  font-size: 12px;
}
.tag-remove {
  background: none;
  border: none;
  color: var(--accent-light);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 0 0 2px;
  opacity: 0.7;
}
.tag-remove:hover { opacity: 1; }

/* ─── No project selected notice ────────────────────────────────────────────── */
.no-project-notice {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  color: var(--text-muted);
  text-align: center;
  gap: 12px;
}
.no-project-notice svg { opacity: 0.3; }
.no-project-notice h2 { font-size: 18px; font-weight: 600; color: var(--text); }
.no-project-notice p { font-size: 13px; max-width: 340px; }
