/* =============================================================
   Cuemath School CRM — Design System
   Based on Vignelli's design spec (2026-03-02)
   ============================================================= */

/* Google Fonts: Inter */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* =============================================================
   CSS Custom Properties
   ============================================================= */
:root {
  /* Background */
  --bg-primary: #FFFFFF;
  --bg-secondary: #F7F8FA;
  --bg-tertiary: #EBEDF0;

  /* Border */
  --border-default: #E1E4E8;
  --border-focus: #FFBA07;

  /* Text */
  --text-primary: #1B1F24;
  --text-secondary: #57606A;
  --text-tertiary: #8B949E;

  /* Accent */
  --accent-primary: #FFBA07;
  --accent-primary-hover: #E5A706;
  --accent-bg: #FFF8E1;

  /* Semantic */
  --color-success: #16A34A;
  --color-warning: #D97706;
  --color-danger: #DC2626;
  --color-info: #2563EB;

  /* Pipeline stages */
  --stage-identified-bg: #E8E8ED;
  --stage-identified-text: #57606A;
  --stage-contacted-bg: #DBE9FE;
  --stage-contacted-text: #1D4ED8;
  --stage-responded-bg: #D1FAE5;
  --stage-responded-text: #065F46;
  --stage-discussion-bg: #FEF3C7;
  --stage-discussion-text: #92400E;
  --stage-future-bg: #E0E7FF;
  --stage-future-text: #3730A3;
  --stage-denied-bg: #FEE2E2;
  --stage-denied-text: #991B1B;
  --stage-onboarded-bg: #191919;
  --stage-onboarded-text: #FFFFFF;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius-full: 9999px;

  /* Sidebar */
  --sidebar-width: 240px;
  --sidebar-collapsed-width: 56px;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', monospace;
}

/* =============================================================
   Base Typography
   ============================================================= */
body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-secondary);
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text-primary);
}

h2 {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
}

h5 {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}

.text-metric {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text-primary);
}

.text-metric-label {
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.text-caption {
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-tertiary);
}

.label-upper {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-tertiary);
}

/* =============================================================
   Sidebar Layout
   ============================================================= */
.crm-layout {
  display: flex;
  min-height: 100vh;
}

.crm-sidebar {
  width: var(--sidebar-width);
  background: var(--bg-primary);
  border-right: 1px solid var(--border-default);
  padding: var(--space-md) 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: width 200ms ease, transform 200ms ease;
  overflow-x: hidden;
  overflow-y: auto;
}

.crm-sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

.crm-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: var(--space-lg);
  transition: margin-left 200ms ease;
  min-height: 100vh;
}

.crm-sidebar.collapsed + .crm-main,
.crm-main.sidebar-collapsed {
  margin-left: var(--sidebar-collapsed-width);
}

/* Sidebar Logo */
.sidebar-logo {
  padding: 0 var(--space-md) var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  text-decoration: none;
  color: var(--text-primary);
}

.sidebar-logo-icon {
  font-size: 24px;
  color: var(--accent-primary);
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.sidebar-logo-text {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
}

.crm-sidebar.collapsed .sidebar-logo-text,
.crm-sidebar.collapsed .sidebar-section-label,
.crm-sidebar.collapsed .sidebar-nav-text,
.crm-sidebar.collapsed .sidebar-user-info,
.crm-sidebar.collapsed .sidebar-badge-text {
  display: none;
}

/* Sidebar Navigation */
.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-tertiary);
  padding: var(--space-md) var(--space-md) var(--space-xs);
  white-space: nowrap;
}

.sidebar-nav {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-nav-item {
  margin: 1px var(--space-sm);
}

.sidebar-nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  padding: 0 var(--space-sm);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 400;
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: all 150ms ease;
  white-space: nowrap;
  position: relative;
}

.sidebar-nav-link:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.sidebar-nav-link.active {
  background: var(--accent-bg);
  color: var(--text-primary);
  font-weight: 600;
  border-left: 3px solid var(--accent-primary);
  padding-left: calc(var(--space-sm) - 3px);
}

.sidebar-nav-link i {
  font-size: 18px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-nav-badge {
  background: var(--color-danger);
  color: #FFFFFF;
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 600;
  margin-left: auto;
  flex-shrink: 0;
}

.sidebar-divider {
  height: 1px;
  background: var(--border-default);
  margin: var(--space-sm) var(--space-md);
}

/* Sidebar User Area */
.sidebar-user {
  border-top: 1px solid var(--border-default);
  padding: var(--space-sm) var(--space-md);
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-primary);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-email {
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-logout {
  color: var(--text-tertiary);
  font-size: 18px;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: all 150ms ease;
  flex-shrink: 0;
}

.sidebar-logout:hover {
  color: var(--color-danger);
  background: #FEE2E2;
}

/* Sidebar Collapse Toggle */
.sidebar-toggle {
  position: absolute;
  top: var(--space-md);
  right: -12px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1;
  font-size: 12px;
  color: var(--text-tertiary);
  transition: all 150ms ease;
}

.sidebar-toggle:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.crm-sidebar.collapsed .sidebar-toggle {
  right: -12px;
}

/* Sidebar tooltip for collapsed state */
.crm-sidebar.collapsed .sidebar-nav-link {
  justify-content: center;
  padding: 0;
}

.crm-sidebar.collapsed .sidebar-nav-link[title] {
  position: relative;
}

/* Mobile sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1039;
}

.sidebar-overlay.show {
  display: block;
}

/* Mobile hamburger */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-default);
  z-index: 1038;
  padding: 0 var(--space-md);
  align-items: center;
}

.mobile-hamburger {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-primary);
  padding: 4px;
  cursor: pointer;
}

/* =============================================================
   Pipeline Stage Badges (soft-tinted)
   ============================================================= */
.stage-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
  white-space: nowrap;
}

.stage-badge-identified,
.stage-badge-secondary {
  background: var(--stage-identified-bg);
  color: var(--stage-identified-text);
}

.stage-badge-contacted,
.stage-badge-info {
  background: var(--stage-contacted-bg);
  color: var(--stage-contacted-text);
}

.stage-badge-responded,
.stage-badge-primary {
  background: var(--stage-responded-bg);
  color: var(--stage-responded-text);
}

.stage-badge-in_discussion,
.stage-badge-warning {
  background: var(--stage-discussion-bg);
  color: var(--stage-discussion-text);
}

.stage-badge-future_potential {
  background: var(--stage-future-bg);
  color: var(--stage-future-text);
}

.stage-badge-denied,
.stage-badge-danger {
  background: var(--stage-denied-bg);
  color: var(--stage-denied-text);
}

.stage-badge-onboarded,
.stage-badge-dark {
  background: var(--stage-onboarded-bg);
  color: var(--stage-onboarded-text);
}

/* Also override Bootstrap .bg-* badge colors for backward compat */
.badge.bg-secondary { background: var(--stage-identified-bg) !important; color: var(--stage-identified-text) !important; }
.badge.bg-info { background: var(--stage-contacted-bg) !important; color: var(--stage-contacted-text) !important; }
.badge.bg-primary { background: var(--stage-responded-bg) !important; color: var(--stage-responded-text) !important; }
.badge.bg-warning { background: var(--stage-discussion-bg) !important; color: var(--stage-discussion-text) !important; }
.badge.bg-danger { background: var(--stage-denied-bg) !important; color: var(--stage-denied-text) !important; }
.badge.bg-dark { background: var(--stage-onboarded-bg) !important; color: var(--stage-onboarded-text) !important; }
.badge.bg-success { background: #D1FAE5 !important; color: #065F46 !important; }

/* =============================================================
   Component Overrides: Cards
   ============================================================= */
.card {
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.card-header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-default);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
}

.card-body {
  padding: var(--space-md);
}

/* =============================================================
   Component Overrides: Buttons
   ============================================================= */
.btn-accent {
  background: var(--accent-primary);
  color: var(--text-primary);
  border: none;
  font-weight: 600;
  border-radius: var(--radius-md);
  transition: background 150ms ease;
}

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

.btn {
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
}

.btn-sm {
  font-size: 13px;
}

/* =============================================================
   Component Overrides: Tables
   ============================================================= */
.table {
  --bs-table-bg: var(--bg-primary);
}

.table > thead {
  background: var(--bg-secondary);
}

.table > thead th {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-secondary);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-default);
}

.table > tbody > tr {
  transition: background 100ms ease;
}

.table > tbody > tr:hover {
  background: var(--bg-secondary) !important;
}

.table > tbody > tr > td {
  padding: 10px 12px;
  vertical-align: middle;
  border-color: var(--border-default);
  font-size: 14px;
}

tr.cursor-pointer {
  cursor: pointer;
}

/* =============================================================
   Component Overrides: Forms
   ============================================================= */
.form-control, .form-select {
  border-radius: var(--radius-md);
  border-color: var(--border-default);
  font-size: 14px;
}

.form-control:focus, .form-select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(255, 186, 7, 0.2);
}

.form-label {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

/* =============================================================
   Filter Chips
   ============================================================= */
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  padding: var(--space-sm) 0;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: var(--space-xs) 10px;
  background: var(--accent-bg);
  border: 1px solid var(--accent-primary);
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
}

.filter-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 10px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 100ms ease;
  text-decoration: none;
  line-height: 1;
}

.filter-chip-remove:hover {
  background: #FEE2E2;
  color: var(--color-danger);
}

/* =============================================================
   Metric Cards (Dashboard)
   ============================================================= */
.metric-card {
  text-align: center;
  padding: var(--space-md);
}

.metric-card .metric-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text-primary);
}

.metric-card .metric-label {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-top: var(--space-xs);
}

/* =============================================================
   Today's Actions Card (Dashboard)
   ============================================================= */
.action-card {
  text-align: center;
  padding: var(--space-md);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-default);
  background: var(--bg-primary);
  transition: box-shadow 150ms ease;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
}

.action-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  color: inherit;
}

.action-card .action-count {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
}

.action-card .action-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 2px;
}

.action-card.action-danger .action-count { color: var(--color-danger); }
.action-card.action-warning .action-count { color: var(--color-warning); }
.action-card.action-info .action-count { color: var(--color-info); }
.action-card.action-success .action-count { color: var(--color-success); }

/* =============================================================
   Modal Overrides
   ============================================================= */
.modal-content {
  border-radius: var(--radius-xl);
  border: none;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}

.modal-header {
  border-bottom-color: var(--border-default);
  padding: var(--space-md) var(--space-lg);
}

.modal-body {
  padding: var(--space-lg);
}

.modal-footer {
  border-top-color: var(--border-default);
  padding: var(--space-md) var(--space-lg);
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
}

/* =============================================================
   Focus / Accessibility
   ============================================================= */
*:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* =============================================================
   Pagination Overrides
   ============================================================= */
.page-link {
  color: var(--text-secondary);
  border-color: var(--border-default);
  font-size: 13px;
}

.page-item.active .page-link {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: var(--text-primary);
}

.page-link:hover {
  background: var(--accent-bg);
  border-color: var(--accent-primary);
  color: var(--text-primary);
}

/* =============================================================
   Alert Overrides (flash messages)
   ============================================================= */
.alert {
  border-radius: var(--radius-lg);
  font-size: 14px;
}

/* =============================================================
   AI Search Indicator
   ============================================================= */
.ai-search-indicator {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent-primary);
  font-size: 14px;
  opacity: 0.7;
}

.search-wrapper {
  position: relative;
}

.search-wrapper .form-control {
  padding-right: 30px;
}

/* =============================================================
   Responsive: Tablet
   ============================================================= */
@media (max-width: 1199px) {
  .crm-sidebar {
    width: var(--sidebar-collapsed-width);
  }

  .crm-sidebar .sidebar-logo-text,
  .crm-sidebar .sidebar-section-label,
  .crm-sidebar .sidebar-nav-text,
  .crm-sidebar .sidebar-user-info,
  .crm-sidebar .sidebar-badge-text {
    display: none;
  }

  .crm-sidebar .sidebar-nav-link {
    justify-content: center;
    padding: 0;
  }

  .crm-main {
    margin-left: var(--sidebar-collapsed-width);
  }
}

/* =============================================================
   Responsive: Mobile
   ============================================================= */
@media (max-width: 767.98px) {
  .crm-sidebar {
    transform: translateX(-100%);
    width: 280px;
    z-index: 1050;
  }

  .crm-sidebar.mobile-open {
    transform: translateX(0);
  }

  /* On mobile, always show full text */
  .crm-sidebar.mobile-open .sidebar-logo-text,
  .crm-sidebar.mobile-open .sidebar-section-label,
  .crm-sidebar.mobile-open .sidebar-nav-text,
  .crm-sidebar.mobile-open .sidebar-user-info,
  .crm-sidebar.mobile-open .sidebar-badge-text {
    display: block;
  }

  .crm-sidebar.mobile-open .sidebar-nav-link {
    justify-content: flex-start;
    padding: 0 var(--space-sm);
  }

  .crm-main {
    margin-left: 0;
    padding: var(--space-md);
    padding-top: 68px; /* space for mobile header */
  }

  .mobile-header {
    display: flex;
  }

  .sidebar-toggle {
    display: none;
  }

  /* Stack metric cards */
  .metric-grid {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* =============================================================
   Utility: Metric grid
   ============================================================= */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-md);
}

/* =============================================================
   Help Center Styles
   ============================================================= */
.guide-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 150ms ease, border-color 150ms ease;
  display: block;
  height: 100%;
}

.guide-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  border-color: var(--accent-primary);
  color: inherit;
}

.guide-card-icon {
  font-size: 28px;
  margin-bottom: var(--space-sm);
  color: var(--accent-primary);
}

.guide-card-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: var(--space-xs);
}

.guide-card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.guide-card-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent-primary);
  margin-top: var(--space-sm);
  display: inline-block;
}

/* FAQ Accordion */
.faq-item {
  border-bottom: 1px solid var(--border-default);
}

.faq-question {
  padding: var(--space-md) 0;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.faq-answer {
  padding: 0 0 var(--space-md);
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  display: none;
}

.faq-item.open .faq-answer {
  display: block;
}

/* =============================================================
   Tutorial / Onboarding Styles
   ============================================================= */
.tutorial-header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-default);
  padding: var(--space-md) var(--space-lg);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tutorial-progress {
  display: flex;
  gap: 6px;
  align-items: center;
}

.tutorial-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-default);
}

.tutorial-dot.active {
  background: var(--accent-primary);
}

.tutorial-dot.visited {
  background: var(--accent-primary);
  opacity: 0.5;
}

.tutorial-content {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-2xl) var(--space-lg);
}

.tutorial-step-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-2xl);
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

.tutorial-step-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: var(--space-md);
}

.tutorial-step-desc {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: var(--space-lg);
}

.tutorial-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: var(--space-lg);
  border-top: 1px solid var(--border-default);
  margin-top: var(--space-lg);
}

/* Welcome modal */
.welcome-modal-body {
  text-align: center;
  padding: var(--space-2xl);
}

.welcome-modal-icon {
  font-size: 48px;
  color: var(--accent-primary);
  margin-bottom: var(--space-md);
}

.welcome-modal-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: var(--space-sm);
}

.welcome-modal-desc {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: var(--space-lg);
}

/* =============================================================
   Request status badges
   ============================================================= */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
}

.status-badge-open { background: var(--stage-contacted-bg); color: var(--stage-contacted-text); }
.status-badge-in_progress { background: var(--stage-discussion-bg); color: var(--stage-discussion-text); }
.status-badge-done { background: var(--stage-responded-bg); color: var(--stage-responded-text); }
.status-badge-wont_fix { background: var(--stage-identified-bg); color: var(--stage-identified-text); }

.type-badge-feature { background: #E0E7FF; color: #3730A3; }
.type-badge-change { background: #FEF3C7; color: #92400E; }
.type-badge-bug { background: #FEE2E2; color: #991B1B; }
