/* ═══════════════════════════════════════════════════════════════
   BRG COMPONENT LIBRARY v1.0
   Depends on: tokens.css (must load first)
   Last Updated: 2026-04-16 (Sprint 0)

   12 core components — use these classes instead of writing
   inline styles. If a pattern appears twice, it lives here.
═══════════════════════════════════════════════════════════════ */


/* ── 1. APP SHELL ────────────────────────────────────────────── */

#app {
  display: none;   /* shown by JS after auth */
  min-height: 100vh;
}
#app.ready { display: block; }

/* TOPBAR */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: var(--z-topbar);
  background: rgba(2,4,8,0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-1);
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 18px;
  gap: 14px;
}
.topbar-logo {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 3px;
  flex-shrink: 0;
}
.topbar-context {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-1);
  padding: 3px 10px;
  background: var(--gold-dim);
  border: 1px solid var(--gold-border);
  border-radius: var(--radius-pill);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.topbar-sep { flex: 1; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.topbar-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
}
.topbar-badge.live {
  color: var(--live);
  background: var(--live-dim);
  border-color: var(--live-border);
}
.topbar-badge.pending {
  color: var(--warn);
  background: var(--warn-dim);
  border-color: var(--warn-border);
}
.topbar-badge.critical {
  color: var(--crit);
  background: var(--crit-dim);
  border-color: var(--crit-border);
}
.topbar-badge .pulse-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulseLive 2s infinite;
}
@keyframes pulseLive {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.topbar-ts {
  font-size: 10px;
  color: var(--text-4);
  font-family: var(--font-mono);
  flex-shrink: 0;
}
.btn-topbar {
  background: none;
  border: 1px solid var(--border-1);
  color: var(--text-3);
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  transition: all var(--transition-base);
}
.btn-topbar:hover {
  border-color: var(--border-2);
  color: var(--text-2);
}

/* SIDENAV */
.sidenav {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  z-index: var(--z-sidenav);
  width: var(--sidenav-w);
  background: rgba(2,4,8,0.97);
  border-right: 1px solid var(--border-1);
  display: flex;
  flex-direction: column;
  padding: 12px 0;
  transition: width var(--transition-slow);
  overflow: hidden;
}
.sidenav:hover,
.sidenav.expanded {
  width: var(--sidenav-expanded);
}
.sidenav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  transition: all var(--transition-base);
  cursor: pointer;
  white-space: nowrap;
  border-left: 2px solid transparent;
}
.sidenav-item:hover {
  color: var(--text-2);
  background: var(--bg-4);
}
.sidenav-item.active {
  color: var(--gold);
  border-left-color: var(--gold);
  background: var(--gold-dim);
}
.sidenav-icon {
  font-size: 16px;
  flex-shrink: 0;
  width: 22px;
  text-align: center;
}

/* MAIN CONTENT */
.main-content {
  margin-left: var(--sidenav-w);
  padding-top: var(--topbar-h);
  min-height: 100vh;
  transition: margin-left var(--transition-slow);
}
.page-content {
  padding: 24px 28px;
  max-width: 1400px;
}


/* ── 2. CARDS ────────────────────────────────────────────────── */

.card {
  background: var(--bg-3);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
}
.card-sm { padding: 14px 16px; }
.card-lg { padding: 28px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-2);
}
.card-title.gold { color: var(--gold); }

.card-gold {
  border-color: rgba(245,158,11,0.2);
  box-shadow: var(--shadow-gold);
}
.card-critical {
  border-color: var(--crit-border);
}


/* ── 3. STAT / KPI TILES ─────────────────────────────────────── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.stat-tile {
  background: var(--bg-4);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-tile:hover { border-color: var(--border-2); }

.stat-value {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  color: var(--text-1);
  line-height: 1;
}
.stat-value.gold { color: var(--gold); }
.stat-value.live { color: var(--live); }
.stat-value.crit { color: var(--crit); }
.stat-value.warn { color: var(--warn); }

.stat-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-3);
}
.stat-delta {
  font-size: 11px;
  font-weight: 600;
  color: var(--live);
}
.stat-delta.down { color: var(--crit); }


/* ── 4. BADGES / STATUS PILLS ────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.live    { color: var(--live);   background: var(--live-dim);   border-color: var(--live-border); }
.badge.warn    { color: var(--warn);   background: var(--warn-dim);   border-color: var(--warn-border); }
.badge.crit    { color: var(--crit);   background: var(--crit-dim);   border-color: var(--crit-border); }
.badge.blue    { color: var(--blue);   background: var(--blue-dim);   border-color: var(--blue-border); }
.badge.gold    { color: var(--gold);   background: var(--gold-dim);   border-color: var(--gold-border); }
.badge.muted   { color: var(--text-3); background: var(--bg-4);       border-color: var(--border-1); }
.badge.ai      { color: var(--purple); background: var(--purple-dim); border-color: rgba(139,92,246,0.2); }

.badge-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge-dot.pulse { animation: pulseLive 2s infinite; }


/* ── 5. BUTTONS ──────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 700;
  border: none;
  transition: all var(--transition-base);
  cursor: pointer;
  white-space: nowrap;
  letter-spacing: 0.2px;
}
.btn-primary {
  background: var(--gold);
  color: var(--gold-text);
}
.btn-primary:hover { background: var(--gold-hover); }

.btn-secondary {
  background: var(--bg-4);
  color: var(--text-2);
  border: 1px solid var(--border-2);
}
.btn-secondary:hover {
  background: var(--bg-5);
  color: var(--text-1);
  border-color: var(--border-3);
}
.btn-ghost {
  background: none;
  color: var(--text-3);
  border: 1px solid var(--border-1);
}
.btn-ghost:hover {
  color: var(--text-2);
  border-color: var(--border-2);
  background: var(--bg-4);
}
.btn-danger {
  background: var(--crit-dim);
  color: var(--crit);
  border: 1px solid var(--crit-border);
}
.btn-danger:hover {
  background: rgba(239,68,68,0.15);
}
.btn-sm { padding: 5px 12px; font-size: 11px; }
.btn-lg { padding: 13px 28px; font-size: 14px; }
.btn-full { width: 100%; }

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}


/* ── 6. FORM INPUTS ──────────────────────────────────────────── */

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.form-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.3px;
}
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  color: var(--text-1);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color var(--transition-base);
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--gold);
}
.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-4);
}
.form-hint {
  font-size: 11px;
  color: var(--text-3);
}
.form-error {
  font-size: 11px;
  color: var(--crit);
  min-height: 14px;
}
.form-textarea { resize: vertical; min-height: 80px; }


/* ── 7. TABLES ───────────────────────────────────────────────── */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.data-table th {
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-1);
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(26,42,66,0.5);
  color: var(--text-2);
  vertical-align: middle;
}
.data-table tr:hover td {
  background: var(--bg-4);
  color: var(--text-1);
}
.data-table .mono {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
}


/* ── 8. AI INTELLIGENCE CARD ─────────────────────────────────── */
/* Visually distinct from regular cards — purple accent          */

.intel-card {
  background: var(--bg-3);
  border: 1px solid rgba(139,92,246,0.15);
  border-radius: var(--radius-lg);
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.intel-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(139,92,246,0.4), transparent);
}
.intel-card-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--purple);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.intel-card-body {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.6;
}
.intel-card-body strong { color: var(--text-1); }
.intel-card-meta {
  margin-top: 12px;
  font-size: 10px;
  color: var(--text-4);
  font-family: var(--font-mono);
}


/* ── 9. AGENT HEALTH ROW ─────────────────────────────────────── */

.agent-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}
.agent-row:hover { background: var(--bg-4); }

.agent-status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.agent-status-dot.live  { background: var(--live);  box-shadow: 0 0 6px rgba(16,185,129,0.5); }
.agent-status-dot.warn  { background: var(--warn);  box-shadow: 0 0 6px rgba(245,158,11,0.5); }
.agent-status-dot.crit  { background: var(--crit);  box-shadow: 0 0 6px rgba(239,68,68,0.5); }
.agent-status-dot.idle  { background: var(--text-4); }

.agent-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-1);
  font-family: var(--font-mono);
  flex: 1;
  min-width: 0;
}
.agent-last-run {
  font-size: 10px;
  color: var(--text-4);
  font-family: var(--font-mono);
  flex-shrink: 0;
}


/* ── 10. SECTION HEADER ──────────────────────────────────────── */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}
.section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title::before {
  content: '';
  display: block;
  width: 3px;
  height: 14px;
  background: var(--gold);
  border-radius: 2px;
  flex-shrink: 0;
}
.section-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}


/* ── 11. TIMELINE / ACTIVITY FEED ────────────────────────────── */

.timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
  position: relative;
}
.timeline::before {
  content: '';
  position: absolute;
  left: 15px;
  top: 8px;
  bottom: 8px;
  width: 1px;
  background: var(--border-1);
}
.timeline-item {
  display: flex;
  gap: 16px;
  padding: 8px 0;
  position: relative;
}
.timeline-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border-2);
  flex-shrink: 0;
  margin-top: 4px;
  position: relative;
  z-index: 1;
  margin-left: 11px;
}
.timeline-dot.live  { background: var(--live); }
.timeline-dot.gold  { background: var(--gold); }
.timeline-dot.crit  { background: var(--crit); }

.timeline-content { flex: 1; min-width: 0; }
.timeline-text {
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.4;
}
.timeline-text strong { color: var(--text-1); }
.timeline-ts {
  font-size: 10px;
  color: var(--text-4);
  font-family: var(--font-mono);
  margin-top: 2px;
}


/* ── 12. EMPTY / LOADING STATES ──────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 10px;
  text-align: center;
}
.empty-icon {
  font-size: 32px;
  opacity: 0.4;
}
.empty-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-3);
}
.empty-body {
  font-size: 11px;
  color: var(--text-4);
  max-width: 240px;
  line-height: 1.5;
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-4) 25%, var(--bg-5) 50%, var(--bg-4) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-text  { height: 12px; width: 100%; margin-bottom: 8px; }
.skeleton-title { height: 18px; width: 60%; margin-bottom: 12px; }
.skeleton-stat  { height: 40px; width: 80px; }


/* ── UTILITY CLASSES ─────────────────────────────────────────── */

.mono  { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

.text-1 { color: var(--text-1); }
.text-2 { color: var(--text-2); }
.text-3 { color: var(--text-3); }
.text-gold { color: var(--gold); }
.text-live { color: var(--live); }
.text-crit { color: var(--crit); }
.text-warn { color: var(--warn); }

.flex  { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
