/* ==========================================================================
   FilterXD Admin Dashboard & Analytics Design System (Dual-Theme)
   ========================================================================== */

:root {
  /* Light Theme Palette */
  --db-bg-page: #f8fafc;
  --db-bg-card: #ffffff;
  --db-bg-subtle: #f1f5f9;
  --db-bg-hover: #f8fafc;
  --db-border: #e2e8f0;
  --db-border-light: #f1f5f9;
  --db-border-hover: #cbd5e1;
  
  --db-text-primary: #0f172a;
  --db-text-secondary: #475569;
  --db-text-muted: #94a3b8;
  
  --db-emerald: #10b981;
  --db-emerald-light: #ecfdf5;
  --db-emerald-text: #047857;
  
  --db-blue: #3b82f6;
  --db-blue-light: #eff6ff;
  --db-blue-text: #1d4ed8;
  
  --db-purple: #8b5cf6;
  --db-purple-light: #f5f3ff;
  --db-purple-text: #6d28d9;
  
  --db-amber: #f59e0b;
  --db-amber-light: #fffbeb;
  --db-amber-text: #b45309;

  --db-rose: #f43f5e;
  --db-rose-light: #fff1f2;
  --db-rose-text: #be123c;

  --db-red: #ef4444;
  --db-red-light: #fef2f2;
  --db-red-text: #b91c1c;

  --db-shadow-card: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.05);
  --db-shadow-hover: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
}

/* Dark Theme Overrides */
html.dark,
.dark {
  --db-bg-page: #0a0a0a;
  --db-bg-card: #121519;
  --db-bg-subtle: #1a1e24;
  --db-bg-hover: #222730;
  --db-border: #262c36;
  --db-border-light: #1f242d;
  --db-border-hover: #3b4352;
  
  --db-text-primary: #f8fafc;
  --db-text-secondary: #cbd5e1;
  --db-text-muted: #64748b;
  
  --db-emerald: #10b981;
  --db-emerald-light: rgba(16, 185, 129, 0.15);
  --db-emerald-text: #34d399;
  
  --db-blue: #3b82f6;
  --db-blue-light: rgba(59, 130, 246, 0.15);
  --db-blue-text: #60a5fa;
  
  --db-purple: #8b5cf6;
  --db-purple-light: rgba(139, 92, 246, 0.15);
  --db-purple-text: #a78bfa;
  
  --db-amber: #f59e0b;
  --db-amber-light: rgba(245, 158, 11, 0.15);
  --db-amber-text: #fbbf24;

  --db-rose: #f43f5e;
  --db-rose-light: rgba(244, 63, 94, 0.15);
  --db-rose-text: #fb7185;

  --db-red: #ef4444;
  --db-red-light: rgba(239, 68, 68, 0.15);
  --db-red-text: #f87171;

  --db-shadow-card: 0 4px 12px rgba(0, 0, 0, 0.35);
  --db-shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.45);
}

/* Base Dashboard Wrapper */
.db-container {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 1rem 1.25rem 2.5rem 1.25rem;
  box-sizing: border-box;
}

/* Custom Scrollbar for Dashboard */
.db-container::-webkit-scrollbar,
.db-scrollable::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.db-container::-webkit-scrollbar-track,
.db-scrollable::-webkit-scrollbar-track {
  background: transparent;
}
.db-container::-webkit-scrollbar-thumb,
.db-scrollable::-webkit-scrollbar-thumb {
  background: var(--db-border);
  border-radius: 9999px;
}
.db-container::-webkit-scrollbar-thumb:hover,
.db-scrollable::-webkit-scrollbar-thumb:hover {
  background: var(--db-text-muted);
}

/* ==========================================================================
   Header Section
   ========================================================================== */
.db-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1.25rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--db-border);
}

.db-title-group h1 {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--db-text-primary);
  letter-spacing: -0.025em;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.db-title-group p {
  font-size: 0.775rem;
  color: var(--db-text-muted);
  margin: 0.25rem 0 0 0;
}

.db-actions {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.db-btn-sync {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  font-size: 0.775rem;
  font-weight: 600;
  border-radius: 0.5rem;
  background-color: var(--db-bg-subtle);
  color: var(--db-text-secondary);
  border: 1px solid var(--db-border);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
}
.db-btn-sync:hover {
  background-color: var(--db-bg-hover);
  color: var(--db-text-primary);
  border-color: var(--db-border-hover);
}

.db-btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 1rem;
  font-size: 0.775rem;
  font-weight: 600;
  border-radius: 0.5rem;
  background-color: var(--db-emerald);
  color: #ffffff !important;
  border: none;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 2px 6px rgba(16, 185, 129, 0.3);
  transition: all 0.2s ease;
}
.db-btn-primary:hover {
  background-color: #059669;
  box-shadow: 0 4px 10px rgba(16, 185, 129, 0.4);
  transform: translateY(-1px);
}

/* ==========================================================================
   Visitor & People Interactions Section (Top Row Highlights)
   ========================================================================== */
.db-visitor-banner {
  background-color: var(--db-bg-card);
  border: 1px solid var(--db-border);
  border-radius: 0.75rem;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--db-shadow-card);
}

.db-visitor-banner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--db-border-light);
}

.db-visitor-banner-title {
  font-size: 0.825rem;
  font-weight: 800;
  color: var(--db-text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.db-visitor-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.85rem;
}

.db-visitor-pill {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  background-color: var(--db-bg-subtle);
  border: 1px solid var(--db-border-light);
  border-radius: 0.625rem;
  transition: all 0.2s ease;
}
.db-visitor-pill:hover {
  border-color: var(--db-border-hover);
  transform: translateY(-1px);
}

.db-pill-icon {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.db-pill-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.db-pill-num {
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--db-text-primary);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.db-pill-label {
  font-size: 0.675rem;
  font-weight: 700;
  color: var(--db-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.15rem;
}

/* ==========================================================================
   KPI Cards Grid
   ========================================================================== */
.db-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.db-kpi-card {
  background-color: var(--db-bg-card);
  border: 1px solid var(--db-border);
  border-radius: 0.75rem;
  padding: 1.15rem;
  box-shadow: var(--db-shadow-card);
  transition: all 0.25s ease;
  position: relative;
  overflow: hidden;
}
.db-kpi-card:hover {
  border-color: var(--db-border-hover);
  box-shadow: var(--db-shadow-hover);
  transform: translateY(-2px);
}

.db-kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.db-kpi-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--db-text-muted);
}

.db-kpi-icon-wrap {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.db-kpi-icon-emerald { background-color: var(--db-emerald-light); color: var(--db-emerald); }
.db-kpi-icon-blue    { background-color: var(--db-blue-light); color: var(--db-blue); }
.db-kpi-icon-purple  { background-color: var(--db-purple-light); color: var(--db-purple); }
.db-kpi-icon-amber   { background-color: var(--db-amber-light); color: var(--db-amber); }
.db-kpi-icon-rose    { background-color: var(--db-rose-light); color: var(--db-rose); }

.db-kpi-val-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.db-kpi-number {
  font-size: 1.75rem;
  font-weight: 900;
  color: var(--db-text-primary);
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.db-kpi-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 700;
}
.db-kpi-badge-emerald { background-color: var(--db-emerald-light); color: var(--db-emerald-text); }
.db-kpi-badge-blue    { background-color: var(--db-blue-light); color: var(--db-blue-text); }
.db-kpi-badge-purple  { background-color: var(--db-purple-light); color: var(--db-purple-text); }
.db-kpi-badge-rose    { background-color: var(--db-rose-light); color: var(--db-rose-text); }

.db-kpi-subtext {
  font-size: 0.725rem;
  color: var(--db-text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* ==========================================================================
   Charts Grid & Cards
   ========================================================================== */
.db-charts-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 1024px) {
  .db-charts-grid {
    grid-template-columns: 1fr;
  }
}

.db-card {
  background-color: var(--db-bg-card);
  border: 1px solid var(--db-border);
  border-radius: 0.75rem;
  padding: 1.25rem;
  box-shadow: var(--db-shadow-card);
  display: flex;
  flex-direction: column;
}

.db-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--db-border-light);
}

.db-card-title-group {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.db-card-icon {
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
}

.db-card-title {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--db-text-primary);
  margin: 0;
}

.db-card-subtitle {
  font-size: 0.725rem;
  color: var(--db-text-muted);
  margin: 0.15rem 0 0 0;
}

.db-chart-canvas-wrap {
  position: relative;
  width: 100%;
  min-height: 240px;
  max-height: 260px;
  flex: 1;
}

/* Doughnut Chart Row Layout */
.db-doughnut-layout {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  align-items: center;
  gap: 1rem;
  width: 100%;
  flex: 1;
}

@media (max-width: 640px) {
  .db-doughnut-layout {
    grid-template-columns: 1fr;
  }
}

.db-doughnut-canvas-wrap {
  position: relative;
  width: 100%;
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.db-legend-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.db-legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  padding: 0.25rem 0.4rem;
  border-radius: 0.375rem;
  transition: background 0.15s ease;
}
.db-legend-item:hover {
  background-color: var(--db-bg-subtle);
}

.db-legend-dot {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 9999px;
  flex-shrink: 0;
}

.db-legend-name {
  color: var(--db-text-secondary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}

.db-legend-pct {
  color: var(--db-text-primary);
  font-weight: 700;
  margin-left: 0.5rem;
}

/* ==========================================================================
   Top 10 Performance Tabs & Leaderboards
   ========================================================================== */
.db-top10-card {
  background-color: var(--db-bg-card);
  border: 1px solid var(--db-border);
  border-radius: 0.75rem;
  padding: 1.25rem;
  box-shadow: var(--db-shadow-card);
  margin-bottom: 1.5rem;
}

.db-tab-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.db-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 0.5rem;
  background-color: var(--db-bg-subtle);
  color: var(--db-text-secondary);
  border: 1px solid var(--db-border);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}
.db-tab-btn:hover {
  background-color: var(--db-bg-hover);
  color: var(--db-text-primary);
}
.db-tab-btn.active {
  background-color: var(--db-emerald);
  color: #ffffff;
  border-color: var(--db-emerald);
  box-shadow: 0 2px 6px rgba(16, 185, 129, 0.3);
}

.db-tab-pane {
  display: none;
}
.db-tab-pane.active {
  display: block;
}

.db-top10-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.db-top10-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem;
  background-color: var(--db-bg-subtle);
  border: 1px solid var(--db-border-light);
  border-radius: 0.625rem;
  transition: all 0.2s ease;
}
.db-top10-item:hover {
  border-color: var(--db-border-hover);
  background-color: var(--db-bg-hover);
  transform: translateY(-1px);
}

.db-top10-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  flex: 1;
}

.db-top10-rank {
  font-size: 0.8rem;
  font-weight: 900;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 0.375rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--db-bg-card);
  color: var(--db-text-muted);
  border: 1px solid var(--db-border);
  flex-shrink: 0;
}
.db-top10-rank-1 { background-color: #fef3c7; color: #b45309; border-color: #fde68a; }
.db-top10-rank-2 { background-color: #f1f5f9; color: #475569; border-color: #cbd5e1; }
.db-top10-rank-3 { background-color: #ffedd5; color: #c2410c; border-color: #fed7aa; }

.db-top10-title {
  font-size: 0.775rem;
  font-weight: 700;
  color: var(--db-text-primary);
  line-height: 1.35;
  margin: 0 0 0.15rem 0;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.db-top10-meta {
  font-size: 0.675rem;
  color: var(--db-text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.db-top10-metric {
  text-align: right;
  flex-shrink: 0;
}

.db-top10-metric-val {
  font-size: 0.875rem;
  font-weight: 900;
  color: var(--db-text-primary);
  display: block;
}

.db-top10-metric-lbl {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--db-text-muted);
  text-transform: uppercase;
}

/* Search Query Badges */
.db-search-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.65rem;
  margin-top: 1rem;
}

.db-search-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  background-color: var(--db-bg-subtle);
  border: 1px solid var(--db-border-light);
  border-radius: 0.5rem;
  transition: all 0.2s ease;
}
.db-search-pill:hover {
  border-color: var(--db-border-hover);
  background-color: var(--db-bg-hover);
}

.db-search-query {
  font-size: 0.775rem;
  font-weight: 700;
  color: var(--db-text-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.db-search-count {
  font-size: 0.725rem;
  font-weight: 800;
  color: var(--db-emerald);
}

/* ==========================================================================
   Bottom Grid (Leaderboard & Stream)
   ========================================================================== */
.db-bottom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

@media (max-width: 1024px) {
  .db-bottom-grid {
    grid-template-columns: 1fr;
  }
}

/* Leaderboard Rows */
.db-agent-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--db-border-light);
  transition: background 0.15s ease;
}
.db-agent-row:last-child {
  border-bottom: none;
}

.db-agent-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.db-rank-num {
  font-size: 0.75rem;
  font-weight: 900;
  width: 1.25rem;
  text-align: center;
  color: var(--db-text-muted);
}
.db-rank-top {
  color: var(--db-emerald) !important;
}

.db-agent-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  background-color: var(--db-bg-subtle);
  border: 1px solid var(--db-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--db-text-secondary);
  overflow: hidden;
  flex-shrink: 0;
}
.db-agent-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.db-agent-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--db-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.db-priority-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.35rem;
  border-radius: 0.25rem;
  font-size: 0.65rem;
  font-weight: 800;
  background-color: var(--db-emerald-light);
  color: var(--db-emerald-text);
  border: 1px solid rgba(16, 185, 129, 0.3);
  margin-left: 0.35rem;
}

.db-agent-username {
  font-size: 0.7rem;
  color: var(--db-text-muted);
  display: block;
}

.db-agent-right {
  text-align: right;
  flex-shrink: 0;
}

.db-agent-count {
  font-size: 0.8rem;
  font-weight: 900;
  color: var(--db-text-primary);
}

.db-bar-track {
  width: 5rem;
  height: 0.35rem;
  background-color: var(--db-bg-subtle);
  border-radius: 9999px;
  overflow: hidden;
  margin-top: 0.25rem;
}

.db-bar-fill {
  height: 100%;
  background-color: var(--db-emerald);
  border-radius: 9999px;
}

/* Live Stream Items */
.db-stream-list {
  display: flex;
  flex-direction: column;
  max-height: 310px;
  overflow-y: auto;
}

.db-stream-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.625rem 0.35rem;
  border-bottom: 1px solid var(--db-border-light);
  border-radius: 0.375rem;
  transition: background 0.15s ease;
}
.db-stream-item:last-child {
  border-bottom: none;
}
.db-stream-item:hover {
  background-color: var(--db-bg-subtle);
}

.db-stream-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.2rem;
}

.db-stream-author {
  font-size: 0.725rem;
  font-weight: 700;
  color: var(--db-text-secondary);
}

.db-stream-cat {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 0.25rem;
  background-color: var(--db-bg-subtle);
  color: var(--db-text-secondary);
}

.db-stream-title {
  font-size: 0.775rem;
  font-weight: 600;
  color: var(--db-text-primary);
  line-height: 1.35;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.db-stream-time {
  font-size: 0.675rem;
  color: var(--db-text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.db-pulse-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 9999px;
  background-color: var(--db-emerald);
  animation: dbPulse 2s infinite;
}

@keyframes dbPulse {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}
