/* LeadForge HQ — Design System */

:root {
  --bg:           #F7F6F2;
  --surface:      #FFFFFF;
  --surface-alt:  #FBFBF9;
  --surface-mute: #F2F1ED;

  --border:       #E5E3DC;
  --border-mute:  #EFEEE9;

  --text:         #1A1916;
  --text-muted:   #6B6962;
  --text-faint:   #A8A6A0;

  --primary:        #01696F;
  --primary-hover:  #035A60;
  --primary-soft:   #E5F0F0;

  --success:        #437A22;
  --success-soft:   #ECF3E5;
  --warning:        #B45309;
  --warning-soft:   #FEF3C7;
  --error:          #B42318;
  --error-soft:     #FEE4E2;

  --tier-a:         #20808D;
  --tier-b:         #BB8B3F;
  --tier-c:         #9CA3AF;

  --text-display:   1.5rem;
  --text-heading:   1.125rem;
  --text-body:      0.875rem;
  --text-small:     0.75rem;
  --text-micro:     0.6875rem;

  --space-1: 4px;   --space-2: 8px;   --space-3: 12px;  --space-4: 16px;
  --space-5: 20px;  --space-6: 24px;  --space-8: 32px;  --space-10: 40px;
  --space-12: 48px;

  --radius-sm: 6px;
  --radius:    8px;
  --radius-lg: 12px;

  --shadow-sm:  0 1px 2px rgba(20,18,13,0.04);
  --shadow-pop: 0 8px 24px rgba(20,18,13,0.08);
}

/* ── Base ─────────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  font-feature-settings: "cv11" 1, "ss01" 1;
  font-size: var(--text-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.mono {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
}

/* ── Tabular numerics ─────────────────────────────────────────────────────── */

.num, td.num, .kpi-value, .metric, .cost, .count {
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
}

/* ── Reduced motion ───────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Layout shell ─────────────────────────────────────────────────────────── */

.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 56px 1fr;
  height: 100dvh;
}

.sidebar {
  grid-row: 1 / -1;
  background: var(--surface-mute);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
}

.topbar {
  grid-column: 2;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  box-shadow: var(--shadow-sm);
}

.main {
  grid-column: 2;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-6) var(--space-8) var(--space-10);
}

/* ── Login ────────────────────────────────────────────────────────────────── */

.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-pop);
}

/* ── Card ─────────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5) var(--space-6);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.card-title {
  font-size: var(--text-heading);
  font-weight: 600;
  line-height: 1.2;
}

.card-subtitle {
  font-size: var(--text-small);
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Eyebrow / section label ─────────────────────────────────────────────── */

.eyebrow {
  font-size: var(--text-micro);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

/* ── KPI ──────────────────────────────────────────────────────────────────── */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
}

.kpi-card {
  padding: var(--space-4) var(--space-5);
}

.kpi-label {
  font-size: var(--text-small);
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

.kpi-value {
  font-size: 28px;
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: tabular-nums lining-nums;
}

.kpi-delta {
  font-size: var(--text-small);
  margin-top: var(--space-1);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.kpi-delta.up   { color: var(--success); }
.kpi-delta.down { color: var(--error); }
.kpi-delta.flat { color: var(--text-muted); }

/* ── Status dot ───────────────────────────────────────────────────────────── */

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.ok       { background: var(--success); }
.dot.degraded { background: var(--warning); }
.dot.idle     { background: var(--text-faint); }
.dot.down     { background: var(--error); animation: pulse 2s ease-in-out infinite; }

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

/* ── Chip ─────────────────────────────────────────────────────────────────── */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--text-micro);
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-mute);
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.chip.tier-a { background: rgba(32,128,141,0.08); color: #0F5860; border-color: rgba(32,128,141,0.2); }
.chip.tier-b { background: rgba(187,139,63,0.08); color: #7A5A22; border-color: rgba(187,139,63,0.2); }

.chip.ok    { background: var(--success-soft); color: var(--success); border-color: rgba(67,122,34,0.2); }
.chip.warn  { background: var(--warning-soft); color: var(--warning); border-color: rgba(180,83,9,0.2); }
.chip.error { background: var(--error-soft);   color: var(--error);   border-color: rgba(180,35,24,0.2); }

/* ── Table ────────────────────────────────────────────────────────────────── */

.dt {
  width: 100%;
  border-collapse: collapse;
}

.dt thead th {
  font-size: var(--text-micro);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.dt th.num { text-align: right; }

.dt tbody td {
  padding: 10px var(--space-3);
  border-bottom: 1px solid var(--border-mute);
  font-size: var(--text-body);
}

.dt tbody tr:hover { background: var(--surface-alt); cursor: pointer; }
.dt tbody tr:last-child td { border-bottom: none; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */

.sidebar-brand {
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--border);
}

.sidebar-brand-title {
  font-size: var(--text-body);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.sidebar-user {
  font-size: var(--text-small);
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer {
  margin-top: auto;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
}

.nav-section {
  padding: var(--space-3) var(--space-2) var(--space-1);
}

.nav-section-label {
  font-size: var(--text-micro);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 0 var(--space-2);
  margin-bottom: var(--space-1);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 7px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-body);
  color: var(--text-muted);
  text-decoration: none;
  transition: background 80ms;
  cursor: pointer;
  border: none;
  border-left: 2px solid transparent;
  background: none;
  width: 100%;
  text-align: left;
  margin-left: -2px;
  padding-left: calc(var(--space-2) + 2px);
}

.nav-link:hover { background: var(--surface-alt); color: var(--text); }

.nav-link.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 500;
}

.nav-link .icon svg { width: 16px; height: 16px; opacity: 0.7; }
.nav-link.active .icon svg { opacity: 1; }

/* ── Topbar ───────────────────────────────────────────────────────────────── */

.topbar-title {
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--text);
}

.topbar-meta {
  font-size: var(--text-small);
  color: var(--text-faint);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.refresh-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-small);
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  transition: background 80ms;
}

.refresh-btn:hover { background: var(--surface-mute); color: var(--text); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-size: var(--text-body);
  font-weight: 500;
  padding: 7px var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 80ms;
  text-decoration: none;
  font-family: inherit;
  line-height: 1;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

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

.btn-ghost {
  background: none;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-ghost:hover { background: var(--surface-mute); color: var(--text); }

.btn-sm {
  font-size: var(--text-small);
  padding: 4px var(--space-3);
}

/* ── Health strip ─────────────────────────────────────────────────────────── */

.health-strip {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-5);
}

.health-service {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-small);
  color: var(--text-muted);
}

/* ── Spend layout ─────────────────────────────────────────────────────────── */

.spend-grid {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: var(--space-4);
}

/* ── Progress bar ─────────────────────────────────────────────────────────── */

.progress-track {
  width: 100%;
  height: 6px;
  background: var(--surface-mute);
  border-radius: 999px;
  overflow: hidden;
  margin: var(--space-2) 0;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
  transition: width 600ms cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-fill.warn  { background: var(--warning); }
.progress-fill.error { background: var(--error); }

/* ── Page structure ───────────────────────────────────────────────────────── */

.page-section { margin-bottom: var(--space-8); }

.page-header { margin-bottom: var(--space-6); }

.page-title {
  font-size: var(--text-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  margin: 0;
}

/* ── Skeleton loading ─────────────────────────────────────────────────────── */

.skel {
  display: block;
  background: linear-gradient(
    90deg,
    var(--border) 0%,
    var(--surface-alt) 50%,
    var(--border) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: 4px;
  margin-bottom: 6px;
}

@keyframes shimmer {
  0%   { background-position: 200% center; }
  100% { background-position: -200% center; }
}

/* ── Forms ────────────────────────────────────────────────────────────────── */

.input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px var(--space-3);
  font-size: var(--text-body);
  color: var(--text);
  outline: none;
  transition: border-color 80ms;
  font-family: inherit;
}

.input:focus  { border-color: var(--primary); }
.input::placeholder { color: var(--text-faint); }

/* ── Icons ────────────────────────────────────────────────────────────────── */

.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  vertical-align: middle;
}

.icon svg { width: 16px; height: 16px; }
.icon-sm svg { width: 14px; height: 14px; }
.icon-lg svg { width: 20px; height: 20px; }

/* ── Empty states ─────────────────────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--text-muted);
  gap: var(--space-2);
}

.empty-state-icon { color: var(--text-faint); margin-bottom: var(--space-2); }

.empty-state-title {
  font-size: var(--text-body);
  font-weight: 500;
  color: var(--text);
}

.empty-state-body {
  font-size: var(--text-small);
  max-width: 340px;
  line-height: 1.6;
}

/* ── Error states ─────────────────────────────────────────────────────────── */

.error-banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--error-soft);
  border: 1px solid rgba(180,35,24,0.2);
  border-radius: var(--radius);
  font-size: var(--text-small);
  color: var(--error);
}

/* ── Utility ──────────────────────────────────────────────────────────────── */

.hidden   { display: none !important; }
.flex     { display: flex; }
.items-center { align-items: center; }
.gap-2    { gap: var(--space-2); }
.gap-3    { gap: var(--space-3); }
.text-muted  { color: var(--text-muted); }
.text-faint  { color: var(--text-faint); }
.text-small  { font-size: var(--text-small); }
.text-micro  { font-size: var(--text-micro); }
.font-500    { font-weight: 500; }
.font-600    { font-weight: 600; }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 900px) {
  .spend-grid { grid-template-columns: 1fr; }
  .kpi-grid   { grid-template-columns: repeat(2, 1fr); }
}

/* ── Filter bar ───────────────────────────────────────────────────────────── */

.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.filter-chips {
  display: flex;
  gap: var(--space-1);
}

.filter-chip {
  font-size: var(--text-small);
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 80ms;
  font-family: inherit;
}

.filter-chip:hover { background: var(--surface-mute); color: var(--text); }

.filter-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.filter-chip.tier-a.active { background: var(--tier-a); border-color: var(--tier-a); }
.filter-chip.tier-b.active { background: var(--tier-b); border-color: var(--tier-b); }

/* ── Score badge ──────────────────────────────────────────────────────────── */

.score-badge {
  display: inline-block;
  min-width: 36px;
  text-align: center;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: var(--text-small);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.score-badge.tier-a { background: rgba(32,128,141,0.1); color: #0F5860; }
.score-badge.tier-b { background: rgba(187,139,63,0.1);  color: #7A5A22; }
.score-badge.tier-c { background: var(--surface-mute);   color: var(--text-muted); }

/* ── Pagination ───────────────────────────────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-mute);
  font-size: var(--text-small);
  color: var(--text-muted);
}

.pagination-btns {
  display: flex;
  gap: var(--space-2);
}

/* ── Lead drawer ──────────────────────────────────────────────────────────── */

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20,18,13,0.3);
  z-index: 200;
  display: flex;
  justify-content: flex-end;
  animation: fadeOverlay 150ms ease-out;
}

@keyframes fadeOverlay {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.drawer {
  width: 440px;
  max-width: 100vw;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(20,18,13,0.08);
  animation: slideDrawer 200ms ease-out;
  overflow: hidden;
}

@keyframes slideDrawer {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.drawer-body {
  padding: var(--space-5) var(--space-6);
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.drawer-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.drawer-close:hover { background: var(--surface-mute); color: var(--text); }

.drawer-field {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-mute);
}

.drawer-field:last-child { border-bottom: none; }

.drawer-field-label {
  font-size: var(--text-micro);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: var(--space-1);
}

.drawer-field-value {
  font-size: var(--text-body);
  color: var(--text);
}
