/* ============================================================
   Embedding Core Console — Dark Sidebar Layout
   ============================================================ */

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

:root {
  --sidebar-w: 230px;
  --bg-900: #060b14;
  --bg-800: #0d1526;
  --bg-700: #111d35;
  --sidebar-bg: #080f1e;
  --accent-primary: #3b82f6;
  --accent-secondary: #06b6d4;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-amber: #f59e0b;
  --accent-purple: #8b5cf6;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #475569;
  --glass-bg: rgba(255,255,255,0.04);
  --glass-border: rgba(255,255,255,0.08);
  --gradient-primary: linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
  --shadow-card: 0 4px 24px rgba(0,0,0,0.4);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-900);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  display: flex;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 50;
  overflow-y: auto;
  transition: transform 0.3s;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 24px;
  border-bottom: 1px solid var(--glass-border);
  text-decoration: none;
  color: var(--text-primary);
}
.sidebar-brand .logo {
  width: 32px; height: 32px;
  background: var(--gradient-primary);
  border-radius: 8px;
  position: relative;
  flex-shrink: 0;
}
.sidebar-brand .logo::after {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 3px;
  border: 2px solid rgba(255,255,255,0.7);
}
.sidebar-brand span { font-weight: 700; font-size: 0.95rem; }

.sidebar-nav { padding: 16px 12px; flex: 1; }
.nav-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 16px 8px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  margin-bottom: 2px;
}
.nav-item .icon { font-size: 1rem; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }
.nav-item.active { background: rgba(59,130,246,0.12); color: var(--accent-primary); }
.nav-item.active .icon { filter: brightness(1.3); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--glass-border);
}
.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--glass-bg);
}
.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
  overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 0.82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-signout {
  padding: 4px 8px;
  border-radius: 5px;
  background: transparent;
  border: 1px solid var(--glass-border);
  color: var(--text-muted);
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  margin-top: 6px;
  width: 100%;
}
.btn-signout:hover { background: rgba(239,68,68,0.1); color: var(--accent-red); border-color: rgba(239,68,68,0.3); }

/* ---- Main content ---- */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  border-bottom: 1px solid var(--glass-border);
  background: rgba(6,11,20,0.8);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 40;
}
.topbar-left h1 { font-size: 1.15rem; font-weight: 700; }
.topbar-left p { font-size: 0.82rem; color: var(--text-muted); }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.workspace-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 100px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-family: 'JetBrains Mono', monospace;
}
.workspace-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent-green); }

/* ---- Views ---- */
.view { display: none; padding: 32px; }
.view.active { display: block; }

/* ---- Login gate ---- */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.login-card {
  background: var(--bg-700);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 56px 48px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0,0,0,0.5);
}
.login-logo {
  width: 72px; height: 72px;
  background: var(--gradient-primary);
  border-radius: 18px;
  margin: 0 auto 28px;
  position: relative;
}
.login-logo::after {
  content: '';
  position: absolute;
  inset: 14px;
  border-radius: 5px;
  border: 2.5px solid rgba(255,255,255,0.7);
}
.login-card h1 { font-size: 1.6rem; font-weight: 800; margin-bottom: 8px; }
.login-card p { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 32px; }

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 13px 24px;
  background: #fff;
  color: #1f2937;
  font-weight: 600;
  font-size: 0.95rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.15s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.btn-google:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.4); transform: translateY(-1px); }
.btn-google svg { width: 20px; height: 20px; }

/* ---- Metrics grid ---- */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}
.metric-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  transition: border-color 0.2s;
}
.metric-card:hover { border-color: rgba(59,130,246,0.3); }
.metric-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}
.metric-value { font-size: 2rem; font-weight: 800; line-height: 1; margin-bottom: 6px; }
.metric-trend { font-size: 0.78rem; }
.trend-up { color: var(--accent-green); }
.trend-neutral { color: var(--text-muted); }

/* ---- Tier badge ---- */
.tier-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.tier-free { background: rgba(71,85,105,0.2); color: #94a3b8; border: 1px solid rgba(71,85,105,0.3); }
.tier-standard { background: rgba(59,130,246,0.15); color: #60a5fa; border: 1px solid rgba(59,130,246,0.3); }
.tier-enterprise { background: rgba(139,92,246,0.15); color: #c4b5fd; border: 1px solid rgba(139,92,246,0.3); }
.tier-pro { background: rgba(16,185,129,0.15); color: #34d399; border: 1px solid rgba(16,185,129,0.3); }

/* ---- Panel cards ---- */
.panel {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 28px;
  margin-bottom: 24px;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.panel-title { font-size: 1rem; font-weight: 700; }
.panel-subtitle { font-size: 0.82rem; color: var(--text-secondary); margin-top: 2px; }

/* ---- Forms ---- */
.form-group { margin-bottom: 20px; }
.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 7px;
}
.form-input {
  width: 100%;
  padding: 10px 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.2s;
  outline: none;
}
.form-input::placeholder { color: var(--text-muted); }
.form-input:focus { border-color: var(--accent-primary); }
.form-input.mono { font-family: 'JetBrains Mono', monospace; font-size: 0.82rem; }
select.form-input { cursor: pointer; }

.btn-primary {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 22px;
  background: var(--gradient-primary);
  color: #fff; font-weight: 600; font-size: 0.9rem;
  border: none; border-radius: var(--radius-sm);
  cursor: pointer; text-decoration: none;
  transition: opacity 0.2s, transform 0.15s;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }

.btn-secondary {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 22px;
  background: transparent; color: var(--text-primary);
  font-weight: 600; font-size: 0.9rem;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  cursor: pointer; text-decoration: none;
  transition: background 0.2s, border-color 0.2s;
}
.btn-secondary:hover { background: var(--glass-bg); border-color: rgba(59,130,246,0.3); }

.btn-danger {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 22px;
  background: rgba(239,68,68,0.1);
  color: var(--accent-red); font-weight: 600; font-size: 0.9rem;
  border: 1px solid rgba(239,68,68,0.25);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
}
.btn-danger:hover { background: rgba(239,68,68,0.18); }

/* ---- API Key display ---- */
.api-key-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-800);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
}
.api-key-value {
  flex: 1;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  color: var(--text-secondary);
  word-break: break-all;
}
.btn-icon {
  padding: 6px 10px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}
.btn-icon:hover { background: rgba(59,130,246,0.1); color: var(--accent-primary); }

/* ---- Data table ---- */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.855rem; }
.data-table th {
  padding: 10px 14px;
  text-align: left;
  background: var(--bg-800);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--glass-border);
}
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--glass-border);
  color: var(--text-secondary);
  vertical-align: middle;
}
.data-table tr:hover td { background: rgba(255,255,255,0.02); }
.data-table td.mono { font-family: 'JetBrains Mono', monospace; font-size: 0.78rem; }
.data-table td.primary { color: var(--text-primary); font-weight: 500; }

/* ---- Mini chart bars ---- */
.chart-container { position: relative; height: 160px; margin-bottom: 8px; }
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 100%; }
.bar-group { display: flex; flex-direction: column; align-items: center; flex: 1; gap: 4px; height: 100%; justify-content: flex-end; }
.bar {
  width: 100%;
  border-radius: 4px 4px 0 0;
  min-height: 4px;
  transition: opacity 0.2s;
  position: relative;
}
.bar:hover { opacity: 0.8; }
.bar.ingest { background: var(--accent-primary); }
.bar.search { background: var(--accent-secondary); }
.bar-label { font-size: 0.68rem; color: var(--text-muted); text-align: center; margin-top: 4px; }
.chart-legend { display: flex; gap: 16px; margin-top: 8px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--text-secondary); }
.legend-dot { width: 8px; height: 8px; border-radius: 2px; }

/* ---- Toast ---- */
#toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 9999; display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 18px; border-radius: 8px;
  font-size: 0.875rem; font-weight: 500; color: #fff;
  animation: toast-in 0.3s ease;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  max-width: 340px;
}
.toast.success { background: linear-gradient(135deg,#059669,#10b981); }
.toast.error { background: linear-gradient(135deg,#dc2626,#ef4444); }
.toast.info { background: linear-gradient(135deg,#2563eb,#3b82f6); }
@keyframes toast-in { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:none; } }

/* ---- Admin stat row ---- */
.stat-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.stat-pill {
  flex: 1;
  min-width: 140px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 20px;
}
.stat-pill .number { font-size: 1.8rem; font-weight: 800; }
.stat-pill .label { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

/* ---- Loading spinner ---- */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--glass-border);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: 16px; }
.empty-state p { font-size: 0.9rem; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
}
