/* ==========================================================================
   SaaS Platform — Design Tokens & Component Library
   Modern 2025-era foundation: light, airy, consistent
   ========================================================================== */

:root {
  /* --- Primary Palette (Indigo) --- */
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #eef2ff;
  --primary-dark: #4338ca;

  /* --- Neutral Gray Scale --- */
  --gray-50:  #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* --- Semantic Colors --- */
  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --danger:  #ef4444;
  --danger-light: #fef2f2;
  --info:    #3b82f6;
  --info-light: #eff6ff;

  /* --- Background --- */
  --bg-page:    #f9fafb;
  --bg-surface: #ffffff;
  --bg-muted:   #f3f4f6;

  /* --- Text --- */
  --text-primary:   #111827;
  --text-secondary: #6b7280;
  --text-muted:     #9ca3af;
  --text-white:     #ffffff;

  /* --- Borders --- */
  --border-color: #e5e7eb;
  --border-light: #f3f4f6;

  /* --- Sidebar (dark, like Linear/Vercel) --- */
  --sidebar-width: 260px;
  --sidebar-bg: #1e1e2e;
  --sidebar-text: rgba(255,255,255,0.7);
  --sidebar-text-active: #ffffff;
  --sidebar-hover: rgba(255,255,255,0.08);
  --sidebar-active: rgba(99,102,241,0.25);
  --sidebar-border: rgba(255,255,255,0.06);
  --sidebar-heading: rgba(255,255,255,0.35);

  /* --- Topbar --- */
  --topbar-height: 56px;
  --topbar-bg: #ffffff;
  --topbar-border: #e5e7eb;

  /* --- Typography --- */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --font-size-xs:   0.75rem;   /* 12px */
  --font-size-sm:   0.8125rem; /* 13px */
  --font-size-base: 0.875rem;  /* 14px */
  --font-size-lg:   1rem;      /* 16px */
  --font-size-xl:   1.125rem;  /* 18px */
  --font-size-2xl:  1.25rem;   /* 20px */
  --font-size-3xl:  1.5rem;    /* 24px */
  --font-size-4xl:  1.875rem;  /* 30px */

  /* --- Spacing (4px grid) --- */
  --spacing-1:  0.25rem;  /*  4px */
  --spacing-2:  0.5rem;   /*  8px */
  --spacing-3:  0.75rem;  /* 12px */
  --spacing-4:  1rem;     /* 16px */
  --spacing-5:  1.25rem;  /* 20px */
  --spacing-6:  1.5rem;   /* 24px */
  --spacing-8:  2rem;     /* 32px */
  --spacing-10: 2.5rem;   /* 40px */
  --spacing-12: 3rem;     /* 48px */

  /* --- Shadows (subtle, layered) --- */
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.06), 0 2px 4px -2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.06), 0 4px 6px -4px rgba(0,0,0,0.04);

  /* --- Radius --- */
  --radius-sm:   0.25rem;  /* 4px  */
  --radius-md:   0.375rem; /* 6px  */
  --radius-lg:   0.5rem;   /* 8px  */
  --radius-xl:   0.75rem;  /* 12px */
  --radius-2xl:  1rem;     /* 16px */
  --radius-full: 9999px;

  /* --- Transitions --- */
  --transition-fast:   0.1s ease;
  --transition-normal: 0.2s ease;
  --transition-slow:   0.3s ease;

  /* --- Legacy compat (keep for now) --- */
  --primary-color: var(--primary);
  --primary-hover-color: var(--primary-hover);
  --secondary-color: #764ba2;
  --gradient-primary: linear-gradient(135deg, var(--primary) 0%, #764ba2 100%);
}

/* ==========================================================================
   Global Reset & Defaults
   ========================================================================== */
body {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
}

code, pre {
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  color: var(--primary-hover);
}

/* ==========================================================================
   Card — modern subtle style
   ========================================================================== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

.card-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
  padding: var(--spacing-4) var(--spacing-5);
}

.card-modern {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-normal), transform var(--transition-normal);
}
.card-modern:hover {
  box-shadow: var(--shadow-md);
}

/* ==========================================================================
   Buttons — solid primary, no gradient
   ========================================================================== */
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--text-white);
  font-weight: 500;
  border-radius: var(--radius-md);
}
.btn-primary:hover,
.btn-primary:focus {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: var(--text-white);
}

/* ==========================================================================
   Metrics Row — compact horizontal stats
   ========================================================================== */
.metrics-row {
  display: flex;
  gap: var(--spacing-4);
  flex-wrap: wrap;
  margin-bottom: var(--spacing-6);
}

.metric-item {
  flex: 1;
  min-width: 140px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--spacing-4) var(--spacing-5);
  display: flex;
  align-items: center;
  gap: var(--spacing-3);
}

.metric-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.metric-icon.primary   { background: var(--primary-light); color: var(--primary); }
.metric-icon.success   { background: var(--success-light); color: var(--success); }
.metric-icon.warning   { background: var(--warning-light); color: var(--warning); }
.metric-icon.danger    { background: var(--danger-light);  color: var(--danger); }
.metric-icon.info      { background: var(--info-light);    color: var(--info); }

.metric-body {
  min-width: 0;
}
.metric-value {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
}
.metric-label {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 500;
}
.metric-sub {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

/* ==========================================================================
   Table — modern clean style
   ========================================================================== */
.table-modern {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.table-modern thead th {
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border-color);
  padding: var(--spacing-3) var(--spacing-4);
  background: transparent;
  white-space: nowrap;
}

.table-modern tbody td {
  padding: var(--spacing-3) var(--spacing-4);
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
  color: var(--text-primary);
}

.table-modern tbody tr:hover {
  background: var(--gray-50);
}

.table-modern tbody tr:last-child td {
  border-bottom: none;
}

/* ==========================================================================
   Empty State
   ========================================================================== */
.empty-state {
  text-align: center;
  padding: var(--spacing-12) var(--spacing-6);
}

.empty-state-icon {
  font-size: 2.5rem;
  color: var(--text-muted);
  margin-bottom: var(--spacing-4);
}

.empty-state-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--spacing-2);
}

.empty-state-text {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  max-width: 400px;
  margin: 0 auto var(--spacing-5);
}

/* ==========================================================================
   Section Header
   ========================================================================== */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-5);
}

.section-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

/* ==========================================================================
   Badge — subtle variant
   ========================================================================== */
.badge-subtle-primary {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 500;
  font-size: var(--font-size-xs);
  padding: 0.25em 0.6em;
  border-radius: var(--radius-sm);
}
.badge-subtle-success {
  background: var(--success-light);
  color: #059669;
  font-weight: 500;
  font-size: var(--font-size-xs);
  padding: 0.25em 0.6em;
  border-radius: var(--radius-sm);
}
.badge-subtle-warning {
  background: var(--warning-light);
  color: #d97706;
  font-weight: 500;
  font-size: var(--font-size-xs);
  padding: 0.25em 0.6em;
  border-radius: var(--radius-sm);
}
.badge-subtle-danger {
  background: var(--danger-light);
  color: #dc2626;
  font-weight: 500;
  font-size: var(--font-size-xs);
  padding: 0.25em 0.6em;
  border-radius: var(--radius-sm);
}
.badge-subtle-info {
  background: var(--info-light);
  color: #2563eb;
  font-weight: 500;
  font-size: var(--font-size-xs);
  padding: 0.25em 0.6em;
  border-radius: var(--radius-sm);
}
.badge-subtle-secondary {
  background: var(--gray-100);
  color: var(--gray-600);
  font-weight: 500;
  font-size: var(--font-size-xs);
  padding: 0.25em 0.6em;
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   Alerts — keep Bootstrap defaults but soften
   ========================================================================== */
.alert {
  border-radius: var(--radius-lg);
  font-size: var(--font-size-sm);
}

/* ==========================================================================
   Form Controls — smaller, tighter
   ========================================================================== */
.form-control, .form-select {
  font-size: var(--font-size-sm);
  border-radius: var(--radius-md);
  border-color: var(--border-color);
  padding: 0.5rem 0.75rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
.form-label {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 0.375rem;
}
.form-text {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

/* ==========================================================================
   Navbar — hidden by default when using app-shell
   Legacy support for views not yet migrated
   ========================================================================== */
.navbar {
  background: var(--gray-800) !important;
}
.navbar .navbar-brand,
.navbar .nav-link {
  color: var(--text-white) !important;
}
.navbar .nav-link:hover {
  background: rgba(255,255,255,0.08);
  border-radius: var(--radius-md);
}

/* ==========================================================================
   Legacy compat: old stat-card/icon classes
   ========================================================================== */
.stats-card {
  background: var(--bg-surface) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-color) !important;
}
.stats-icon {
  font-size: 1.5rem;
  margin-bottom: var(--spacing-2);
  opacity: 0.8;
}

/* ==========================================================================
   Utility — backward compat
   ========================================================================== */
.bg-gradient-primary {
  background: var(--gradient-primary);
}
.shadow-custom {
  box-shadow: var(--shadow-lg) !important;
}
.text-primary {
  color: var(--primary) !important;
}

/* Override Bootstrap's .text-secondary to use our tokens */
.text-secondary {
  color: var(--text-secondary) !important;
}

/* ==========================================================================
   App Shell — Sidebar + Topbar Unified Layout
   ========================================================================== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.app-sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 1040;
  overflow-y: auto;
  transition: transform var(--transition-slow);
}

.sidebar-header {
  padding: var(--spacing-5) var(--spacing-5) var(--spacing-4);
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--spacing-3);
  color: var(--sidebar-text-active);
  text-decoration: none;
  font-weight: 700;
  font-size: var(--font-size-lg);
}
.sidebar-brand i {
  font-size: 1.25rem;
  color: var(--primary);
}
.sidebar-brand .sidebar-brand-mark {
  width: 28px;
  height: 32px;
  object-fit: contain;
  display: block;
}

.sidebar-nav {
  flex: 1;
  padding: var(--spacing-3) 0;
  overflow-y: auto;
}

.sidebar-section {
  padding: 0 var(--spacing-3);
  margin-bottom: var(--spacing-2);
}

.sidebar-heading {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sidebar-heading);
  font-weight: 600;
  padding: var(--spacing-3) var(--spacing-4) var(--spacing-1);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--spacing-3);
  padding: var(--spacing-2) var(--spacing-4);
  margin: 1px var(--spacing-3);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: var(--font-size-sm);
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}
.sidebar-link:hover {
  color: var(--sidebar-text-active);
  background: var(--sidebar-hover);
}
.sidebar-link.active {
  color: var(--sidebar-text-active);
  background: var(--sidebar-active);
}
.sidebar-link i {
  width: 18px;
  text-align: center;
  font-size: 0.875rem;
  opacity: 0.7;
}
.sidebar-link.active i {
  opacity: 1;
}

.sidebar-divider {
  border-top: 1px solid var(--sidebar-border);
  margin: var(--spacing-3) var(--spacing-4);
}

/* Sidebar Footer / User */
.sidebar-footer {
  padding: var(--spacing-3) var(--spacing-4);
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-3);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--spacing-3);
  min-width: 0;
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: var(--font-size-sm);
  flex-shrink: 0;
}

.sidebar-user-info {
  min-width: 0;
}
.sidebar-user-name {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--sidebar-text-active);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-email {
  font-size: var(--font-size-xs);
  color: var(--sidebar-heading);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-logout {
  color: var(--sidebar-text);
  padding: var(--spacing-2);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}
.sidebar-logout:hover {
  color: var(--danger);
  background: rgba(239,68,68,0.1);
}

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

/* --- Topbar --- */
.app-topbar {
  height: var(--topbar-height);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--spacing-6);
  position: sticky;
  top: 0;
  z-index: 1020;
}

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

.sidebar-toggle {
  display: none; /* Hidden on desktop */
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.25rem;
  padding: var(--spacing-2);
  cursor: pointer;
  border-radius: var(--radius-md);
}
.sidebar-toggle:hover {
  background: var(--gray-100);
  color: var(--text-primary);
}

.topbar-breadcrumb {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}
.topbar-breadcrumb .breadcrumb {
  margin: 0;
  padding: 0;
  background: none;
  font-size: var(--font-size-sm);
}
.topbar-breadcrumb .breadcrumb-item + .breadcrumb-item::before {
  color: var(--text-muted);
}

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

/* --- Page Content --- */
.app-content {
  flex: 1;
  padding: var(--spacing-6);
  max-width: 100%;
}

/* --- Sidebar Overlay (mobile) --- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1035;
}
.sidebar-overlay.active {
  display: block;
}

/* ==========================================================================
   Mobile Responsive — Sidebar collapse
   ========================================================================== */
@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.open {
    transform: translateX(0);
  }
  .app-main {
    margin-left: 0;
  }
  .sidebar-toggle {
    display: block;
  }
  .app-content {
    padding: var(--spacing-4);
  }
}

@media (max-width: 575.98px) {
  .metrics-row {
    flex-direction: column;
  }
  .metric-item {
    min-width: 100%;
  }
  .app-content {
    padding: var(--spacing-3);
  }
  .app-topbar {
    padding: 0 var(--spacing-4);
  }
}

/* ==========================================================================
   Legacy compat: old stat-card styling for unmigrated views
   ========================================================================== */
