/* ============================================================================
   EdQuill CRM - Design System Foundation
   Enterprise-grade design tokens, utility classes, and base styles.
   Load order: Bootstrap -> style.css (NiceAdmin) -> design-system.css -> styles.css
   ============================================================================ */

/* ============================================================================
   1. DESIGN TOKENS (CSS Custom Properties)
   ============================================================================ */

:root {
  /* --- Brand Colors --- */
  --eq-primary:        #4361ee;
  --eq-primary-hover:  #3a56d4;
  --eq-primary-light:  #eef1fd;
  --eq-primary-dark:   #2d41a7;
  --eq-accent:         #48bdf0;
  --eq-accent-light:   #e8f6fd;

  /* --- Semantic Colors --- */
  --eq-success:        #10b981;
  --eq-success-light:  #ecfdf5;
  --eq-warning:        #f59e0b;
  --eq-warning-light:  #fffbeb;
  --eq-danger:         #ef4444;
  --eq-danger-light:   #fef2f2;
  --eq-info:           #06b6d4;
  --eq-info-light:     #ecfeff;

  /* --- Neutral Palette --- */
  --eq-gray-50:        #f8fafc;
  --eq-gray-100:       #f1f5f9;
  --eq-gray-200:       #e2e8f0;
  --eq-gray-300:       #cbd5e1;
  --eq-gray-400:       #94a3b8;
  --eq-gray-500:       #64748b;
  --eq-gray-600:       #475569;
  --eq-gray-700:       #334155;
  --eq-gray-800:       #1e293b;
  --eq-gray-900:       #0f172a;

  /* --- Surface Colors --- */
  --eq-bg-page:        #f1f5f9;
  --eq-bg-card:        #ffffff;
  --eq-bg-elevated:    #ffffff;
  --eq-border-color:   #e2e8f0;
  --eq-border-light:   #f1f5f9;

  /* --- Typography --- */
  --eq-font-sans:      'Inter', 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --eq-font-heading:   'Inter', 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --eq-font-mono:      'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  /* Type Scale (1.200 minor third) */
  --eq-text-xs:        0.694rem;   /* 11.1px */
  --eq-text-sm:        0.833rem;   /* 13.3px */
  --eq-text-base:      0.9375rem;  /* 15px - slightly larger base for readability */
  --eq-text-md:        1.0rem;     /* 16px */
  --eq-text-lg:        1.125rem;   /* 18px */
  --eq-text-xl:        1.35rem;    /* 21.6px */
  --eq-text-2xl:       1.62rem;    /* 25.9px */
  --eq-text-3xl:       1.944rem;   /* 31.1px */

  /* Line Heights */
  --eq-leading-tight:  1.25;
  --eq-leading-normal: 1.5;
  --eq-leading-relaxed:1.625;

  /* Font Weights */
  --eq-font-normal:    400;
  --eq-font-medium:    500;
  --eq-font-semibold:  600;
  --eq-font-bold:      700;

  /* --- Spacing Scale (4px base) --- */
  --eq-space-0:        0;
  --eq-space-1:        0.25rem;  /* 4px */
  --eq-space-2:        0.5rem;   /* 8px */
  --eq-space-3:        0.75rem;  /* 12px */
  --eq-space-4:        1rem;     /* 16px */
  --eq-space-5:        1.25rem;  /* 20px */
  --eq-space-6:        1.5rem;   /* 24px */
  --eq-space-8:        2rem;     /* 32px */
  --eq-space-10:       2.5rem;   /* 40px */
  --eq-space-12:       3rem;     /* 48px */
  --eq-space-16:       4rem;     /* 64px */

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

  /* --- Shadows --- */
  --eq-shadow-xs:      0 1px 2px rgba(0, 0, 0, 0.05);
  --eq-shadow-sm:      0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --eq-shadow-md:      0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --eq-shadow-lg:      0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --eq-shadow-xl:      0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);

  /* --- Transitions --- */
  --eq-transition-fast:   150ms cubic-bezier(0.4, 0, 0.2, 1);
  --eq-transition-base:   200ms cubic-bezier(0.4, 0, 0.2, 1);
  --eq-transition-slow:   300ms cubic-bezier(0.4, 0, 0.2, 1);

  /* --- Layout --- */
  --eq-header-height:    60px;
  --eq-sidebar-width:    260px;
  --eq-sidebar-collapsed:72px;
  --eq-touch-target-min: 44px;

  /* --- Z-index Scale --- */
  --eq-z-dropdown:     1000;
  --eq-z-sticky:       1020;
  --eq-z-fixed:        1030;
  --eq-z-backdrop:     1040;
  --eq-z-modal:        1050;
  --eq-z-popover:      1060;
  --eq-z-tooltip:      1070;
}


/* ============================================================================
   2. BASE / RESET IMPROVEMENTS
   ============================================================================ */

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--eq-font-sans);
  font-size: var(--eq-text-base);
  line-height: var(--eq-leading-normal);
  color: var(--eq-gray-700);
  background-color: var(--eq-bg-page);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--eq-font-heading);
  font-weight: var(--eq-font-semibold);
  color: var(--eq-gray-900);
  line-height: var(--eq-leading-tight);
}

/* Focus visible for keyboard accessibility */
:focus-visible {
  outline: 2px solid var(--eq-primary);
  outline-offset: 2px;
  border-radius: var(--eq-radius-sm);
}

/* Remove default focus for mouse users */
:focus:not(:focus-visible) {
  outline: none;
}

/* Smooth scrolling on elements */
.smooth-scroll {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}


/* ============================================================================
   3. ENTERPRISE CARD SYSTEM
   ============================================================================ */

.eq-card {
  background: var(--eq-bg-card);
  border: 1px solid var(--eq-border-color);
  border-radius: var(--eq-radius-lg);
  box-shadow: var(--eq-shadow-xs);
  transition: box-shadow var(--eq-transition-base);
}

.eq-card:hover {
  box-shadow: var(--eq-shadow-sm);
}

.eq-card-header {
  padding: var(--eq-space-4) var(--eq-space-5);
  border-bottom: 1px solid var(--eq-border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--eq-space-3);
}

.eq-card-header h5,
.eq-card-header h6 {
  margin: 0;
  font-size: var(--eq-text-md);
  font-weight: var(--eq-font-semibold);
}

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

.eq-card-footer {
  padding: var(--eq-space-3) var(--eq-space-5);
  border-top: 1px solid var(--eq-border-light);
  background: var(--eq-gray-50);
  border-radius: 0 0 var(--eq-radius-lg) var(--eq-radius-lg);
}


/* ============================================================================
   4. ENTERPRISE TABLE STYLES
   ============================================================================ */

.eq-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--eq-text-sm);
}

.eq-table thead th {
  background: var(--eq-gray-50);
  color: var(--eq-gray-600);
  font-weight: var(--eq-font-semibold);
  font-size: var(--eq-text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--eq-space-3) var(--eq-space-4);
  border-bottom: 2px solid var(--eq-border-color);
  position: sticky;
  top: 0;
  z-index: 10;
  white-space: nowrap;
  text-align: left;
}

.eq-table tbody td {
  padding: var(--eq-space-3) var(--eq-space-4);
  border-bottom: 1px solid var(--eq-border-light);
  color: var(--eq-gray-700);
  vertical-align: middle;
}

.eq-table tbody tr {
  transition: background-color var(--eq-transition-fast);
}

.eq-table tbody tr:hover {
  background-color: var(--eq-primary-light);
}

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

/* Table responsive wrapper */
.eq-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--eq-border-color);
  border-radius: var(--eq-radius-lg);
}

.eq-table-wrap .eq-table thead th:first-child {
  border-radius: var(--eq-radius-lg) 0 0 0;
}

.eq-table-wrap .eq-table thead th:last-child {
  border-radius: 0 var(--eq-radius-lg) 0 0;
}


/* ============================================================================
   5. BADGE & STATUS SYSTEM
   ============================================================================ */

.eq-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  font-size: var(--eq-text-xs);
  font-weight: var(--eq-font-semibold);
  border-radius: var(--eq-radius-full);
  line-height: 1.6;
  white-space: nowrap;
}

.eq-badge-primary   { background: var(--eq-primary-light); color: var(--eq-primary); }
.eq-badge-success   { background: var(--eq-success-light); color: #059669; }
.eq-badge-warning   { background: var(--eq-warning-light); color: #d97706; }
.eq-badge-danger    { background: var(--eq-danger-light);  color: #dc2626; }
.eq-badge-info      { background: var(--eq-info-light);    color: #0891b2; }
.eq-badge-neutral   { background: var(--eq-gray-100);      color: var(--eq-gray-600); }

/* Dot indicator before badge text */
.eq-badge-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}


/* ============================================================================
   6. EMPTY / ERROR / LOADING STATES
   ============================================================================ */

.eq-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--eq-space-12) var(--eq-space-6);
  text-align: center;
}

.eq-empty-state i {
  font-size: 3rem;
  color: var(--eq-gray-300);
  margin-bottom: var(--eq-space-4);
}

.eq-empty-state h4 {
  font-size: var(--eq-text-lg);
  font-weight: var(--eq-font-semibold);
  color: var(--eq-gray-700);
  margin-bottom: var(--eq-space-2);
}

.eq-empty-state p {
  font-size: var(--eq-text-sm);
  color: var(--eq-gray-500);
  max-width: 360px;
  margin: 0 auto;
}

/* Error state */
.eq-error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--eq-space-8) var(--eq-space-6);
  text-align: center;
}

.eq-error-state i {
  font-size: 2.5rem;
  color: var(--eq-danger);
  margin-bottom: var(--eq-space-3);
}

/* Skeleton loading */
.eq-skeleton {
  background: linear-gradient(90deg, var(--eq-gray-100) 25%, var(--eq-gray-200) 50%, var(--eq-gray-100) 75%);
  background-size: 200% 100%;
  animation: eq-skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--eq-radius-sm);
}

.eq-skeleton-text {
  height: 14px;
  margin-bottom: 8px;
  border-radius: var(--eq-radius-sm);
}

.eq-skeleton-text:last-child {
  width: 70%;
}

.eq-skeleton-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

@keyframes eq-skeleton-pulse {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Spinner overlay */
.eq-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.8);
  z-index: 20;
  border-radius: inherit;
}


/* ============================================================================
   7. FORM IMPROVEMENTS
   ============================================================================ */

.eq-form-label {
  font-size: var(--eq-text-sm);
  font-weight: var(--eq-font-medium);
  color: var(--eq-gray-700);
  margin-bottom: var(--eq-space-1);
}

.eq-form-control {
  display: block;
  width: 100%;
  padding: var(--eq-space-2) var(--eq-space-3);
  font-size: var(--eq-text-base);
  line-height: var(--eq-leading-normal);
  color: var(--eq-gray-800);
  background-color: var(--eq-bg-card);
  border: 1px solid var(--eq-gray-300);
  border-radius: var(--eq-radius-md);
  transition: border-color var(--eq-transition-fast), box-shadow var(--eq-transition-fast);
}

.eq-form-control:focus {
  border-color: var(--eq-primary);
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
  outline: none;
}

.eq-form-control::placeholder {
  color: var(--eq-gray-400);
}

.eq-form-hint {
  font-size: var(--eq-text-xs);
  color: var(--eq-gray-500);
  margin-top: var(--eq-space-1);
}

.eq-form-error {
  font-size: var(--eq-text-xs);
  color: var(--eq-danger);
  margin-top: var(--eq-space-1);
}

/* Validation states */
.eq-form-control.is-invalid,
.form-control.ng-touched.ng-invalid {
  border-color: var(--eq-danger);
}

.eq-form-control.is-invalid:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}


/* ============================================================================
   8. BUTTON SYSTEM
   ============================================================================ */

.eq-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--eq-space-2);
  padding: var(--eq-space-2) var(--eq-space-4);
  font-size: var(--eq-text-sm);
  font-weight: var(--eq-font-medium);
  line-height: 1.5;
  border-radius: var(--eq-radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--eq-transition-fast);
  white-space: nowrap;
  min-height: var(--eq-touch-target-min);
}

.eq-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.eq-btn-outline {
  background: transparent;
  color: var(--eq-gray-700);
  border-color: var(--eq-gray-300);
}
.eq-btn-outline:hover:not(:disabled) {
  background: var(--eq-gray-50);
  border-color: var(--eq-gray-400);
}

.eq-btn-ghost {
  background: transparent;
  color: var(--eq-gray-600);
  border-color: transparent;
}
.eq-btn-ghost:hover:not(:disabled) {
  background: var(--eq-gray-100);
}

.eq-btn-danger {
  background: var(--eq-danger);
  color: #fff;
  border-color: var(--eq-danger);
}
.eq-btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

.eq-btn-sm {
  padding: var(--eq-space-1) var(--eq-space-3);
  font-size: var(--eq-text-xs);
  min-height: 32px;
}

.eq-btn-lg {
  padding: var(--eq-space-3) var(--eq-space-6);
  font-size: var(--eq-text-md);
  min-height: 48px;
}

.eq-btn-icon {
  width: var(--eq-touch-target-min);
  height: var(--eq-touch-target-min);
  padding: 0;
  border-radius: var(--eq-radius-md);
}


/* ============================================================================
   9. IMPROVED GLOBAL OVERRIDES (upgrade existing Bootstrap/NiceAdmin)
   ============================================================================ */

/* Upgrade existing cards to use design system shadows */
.card {
  border: 1px solid var(--eq-border-color);
  border-radius: var(--eq-radius-lg);
  box-shadow: var(--eq-shadow-xs);
  overflow: hidden;
}

.card-header {
  background: var(--eq-gray-50);
  border-bottom: 1px solid var(--eq-border-light);
  font-weight: var(--eq-font-semibold);
}

/* Upgrade existing table headers (replace the cyan hardcoded headers) */
th {
  background-color: var(--eq-gray-50);
  color: var(--eq-gray-600);
  font-weight: var(--eq-font-semibold);
  font-size: var(--eq-text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: none;
  border-bottom: 2px solid var(--eq-border-color);
  padding: var(--eq-space-3) var(--eq-space-3);
}

td {
  border: none;
  border-bottom: 1px solid var(--eq-border-light);
  padding: var(--eq-space-2) var(--eq-space-3);
  position: static;
}

/* Table responsive - remove the broken 100px max-height */
.table-responsive {
  max-height: none;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.scrollable {
  max-height: 500px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.scroll {
  max-height: 500px;
  overflow-y: auto;
}

/* Upgrade page title */
.pagetitle h1 {
  font-size: var(--eq-text-2xl);
  font-weight: var(--eq-font-bold);
  color: var(--eq-gray-900);
}

/* Better link styles */
a {
  color: var(--eq-primary);
  text-decoration: none;
  transition: color var(--eq-transition-fast);
}

a:hover {
  color: var(--eq-primary-hover);
}

/* Upgrade page background */
body {
  background: var(--eq-bg-page);
}

/* Main content area */
#main {
  padding: var(--eq-space-5);
  margin-top: var(--eq-header-height);
}

/* Upgrade header */
.header {
  height: var(--eq-header-height);
  box-shadow: var(--eq-shadow-sm);
  background: var(--eq-bg-card);
  border-bottom: 1px solid var(--eq-border-color);
  transition: all var(--eq-transition-slow);
}

/* Upgrade sidebar */
.sidebar {
  width: var(--eq-sidebar-width);
  background: var(--eq-bg-card);
  box-shadow: var(--eq-shadow-md);
  border-right: 1px solid var(--eq-border-light);
}

.sidebar-nav .nav-link {
  border-radius: var(--eq-radius-md);
  font-weight: var(--eq-font-medium);
  font-size: var(--eq-text-sm);
  padding: var(--eq-space-2) var(--eq-space-3);
  transition: all var(--eq-transition-fast);
}

.sidebar-nav .nav-link:hover {
  background: var(--eq-primary-light);
  color: var(--eq-primary);
}

.sidebar-nav .nav-link:hover i {
  color: var(--eq-primary);
}

.sidebar-nav .nav-link:not(.collapsed) {
  background: var(--eq-primary-light);
  color: var(--eq-primary);
}

.sidebar-nav .nav-link:not(.collapsed) i {
  color: var(--eq-primary);
}

/* Sidebar margin for main content */
@media (min-width: 1200px) {
  #main, #footer {
    margin-left: var(--eq-sidebar-width);
  }
}

/* Upgrade dropdown menus */
.dropdown-menu {
  border: 1px solid var(--eq-border-color);
  border-radius: var(--eq-radius-md);
  box-shadow: var(--eq-shadow-lg);
  padding: var(--eq-space-1) 0;
}

.dropdown-item {
  padding: var(--eq-space-2) var(--eq-space-4);
  font-size: var(--eq-text-sm);
  color: var(--eq-gray-700);
  transition: background-color var(--eq-transition-fast);
}

.dropdown-item:hover,
.dropdown-item:focus {
  background-color: var(--eq-gray-50);
  color: var(--eq-gray-900);
}

.dropdown-item:active {
  background-color: var(--eq-primary-light);
  color: var(--eq-primary);
}


/* ============================================================================
   10. MOBILE-FIRST RESPONSIVE BASE
   ============================================================================ */

/* Touch-friendly defaults on touch devices */
@media (pointer: coarse) {
  .btn, .eq-btn, .dropdown-item, .nav-link, .list-group-item {
    min-height: var(--eq-touch-target-min);
  }

  /* Larger tap targets for form elements */
  .form-control, .form-select, .eq-form-control {
    min-height: var(--eq-touch-target-min);
    font-size: 16px; /* Prevents iOS zoom on focus */
  }
}

/* Mobile layout adjustments */
@media (max-width: 767.98px) {
  #main {
    padding: var(--eq-space-3);
  }

  .pagetitle h1 {
    font-size: var(--eq-text-xl);
  }

  .pagetitle {
    margin-bottom: var(--eq-space-3);
  }

  /* Stack card actions on mobile */
  .card-header {
    flex-wrap: wrap;
    gap: var(--eq-space-2);
  }

  /* Full-width buttons on mobile */
  .eq-btn-mobile-full {
    width: 100%;
  }

  /* Hide non-essential columns on mobile */
  .eq-hide-mobile {
    display: none;
  }

  /* Compact table padding on mobile */
  th, td {
    padding: var(--eq-space-2);
    font-size: var(--eq-text-xs);
  }
}

/* Tablet adjustments */
@media (max-width: 991.98px) {
  .eq-hide-tablet {
    display: none;
  }
}

/* Sidebar mobile overlay */
@media (max-width: 1199.98px) {
  .sidebar {
    z-index: var(--eq-z-fixed);
  }

  /* Backdrop when sidebar is open on mobile */
  .toggle-sidebar .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: calc(var(--eq-z-fixed) - 1);
    backdrop-filter: blur(2px);
    animation: eq-fade-in var(--eq-transition-base);
  }
}

@keyframes eq-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}


/* ============================================================================
   11. UTILITY CLASSES
   ============================================================================ */

/* Truncate text */
.eq-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Line clamp (multi-line truncate) */
.eq-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Screen reader only */
.eq-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Divider */
.eq-divider {
  height: 1px;
  background: var(--eq-border-color);
  margin: var(--eq-space-4) 0;
}

/* Status dot (inline) */
.eq-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.eq-dot-success { background: var(--eq-success); }
.eq-dot-warning { background: var(--eq-warning); }
.eq-dot-danger  { background: var(--eq-danger); }
.eq-dot-info    { background: var(--eq-info); }
.eq-dot-neutral { background: var(--eq-gray-400); }

/* Smooth transitions for interactive elements */
.eq-interactive {
  transition: all var(--eq-transition-fast);
  cursor: pointer;
}

.eq-interactive:hover {
  transform: translateY(-1px);
  box-shadow: var(--eq-shadow-md);
}

/* Pulse animation for notifications */
@keyframes eq-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.1); }
}

.eq-pulse {
  animation: eq-pulse 2s ease-in-out infinite;
}
