/* ==========================================================================
   AG Grid Theme Overrides — NM-ERP Design System
   Maps AG Grid Alpine variables to existing design tokens.
   Loaded AFTER ag-theme-alpine.min.css, BEFORE page CSS.
   spec: ag-grid-visual-spec.md Section 13
   ========================================================================== */

/* --------------------------------------------------------------------------
   13.1  AG Grid CSS variable overrides
   -------------------------------------------------------------------------- */

.erp-grid.ag-theme-alpine {
  /* Colours */
  --ag-alpine-active-color:                var(--primary, #3b82f6);
  --ag-background-color:                   var(--surface, #ffffff);
  --ag-odd-row-background-color:           var(--surface, #ffffff);
  --ag-header-background-color:            transparent;
  --ag-header-foreground-color:            var(--text-muted, #94a3b8);
  --ag-header-cell-hover-background-color: #f8fafc;
  --ag-foreground-color:                   var(--text-secondary, #475569);
  --ag-secondary-foreground-color:         var(--text-muted, #94a3b8);
  --ag-row-hover-color:                    #f8fafc;
  --ag-selected-row-background-color:      var(--primary-light, #eff6ff);
  --ag-border-color:                       var(--border, #e2e8f0);
  --ag-row-border-color:                   var(--border, #e2e8f0);

  /* Typography */
  --ag-font-family:                        var(--font-sans, 'Inter', system-ui, -apple-system, sans-serif);
  --ag-font-size:                          13px;

  /* Dimensions — match production table visual density */
  --ag-row-height:                         56px;
  --ag-header-height:                      48px;
  --ag-cell-horizontal-padding:            16px;

  /* Checkbox */
  --ag-checkbox-checked-color:             var(--primary, #3b82f6);
  --ag-checkbox-unchecked-color:           var(--border-strong, #cbd5e1);

  /* Focus & selection */
  --ag-range-selection-border-color:       transparent;
  --ag-input-focus-border-color:           var(--primary, #3b82f6);
  --ag-input-focus-box-shadow:             0 0 0 3px rgba(59, 130, 246, 0.15);

  /* Borders */
  --ag-borders:                            solid 1px;
  --ag-border-radius:                      0;

  /* Icons */
  --ag-icon-size:                          16px;
}


/* --------------------------------------------------------------------------
   13.2  Header cell typography
   -------------------------------------------------------------------------- */

.erp-grid .ag-header-cell-text {
  font-size: 12px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
}


/* --------------------------------------------------------------------------
   13.3  Row states
   -------------------------------------------------------------------------- */

/* Pointer cursor on all data rows */
.erp-grid .ag-row {
  cursor: pointer;
  transition: background-color 0.1s ease;
}

/* Inactive/deactivated row (clients) */
.erp-grid .ag-row.row-inactive {
  opacity: 0.55;
}

/* Keyboard focus indicator */
.erp-grid .ag-row-focus {
  box-shadow: inset 0 0 0 2px var(--primary, #3b82f6);
}


/* --------------------------------------------------------------------------
   13.4  Cell-level overrides
   -------------------------------------------------------------------------- */

/* Action cells — prevent clipping of buttons, suppress row click cursor */
.erp-grid .ag-cell[col-id="actions"] {
  overflow: visible;
}

/* Monospace cells (dispatch number, project number) */
.erp-grid .cell-mono {
  font-family: var(--font-mono, 'SF Mono', 'Cascadia Code', 'Fira Mono', Consolas, monospace);
  font-size: 12px;
  color: var(--text-primary, #0f172a);
}

/* Name cell with avatar (clients) */
.erp-grid .cell-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  color: var(--text-primary, #0f172a);
}

.erp-grid .company-initial {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  user-select: none;
}

/* Muted text cells (city, contact name, phone) */
.erp-grid .cell-muted {
  color: var(--text-muted, #94a3b8);
}

/* Truncated text cells */
.erp-grid .cell-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Phone number monospace */
.erp-grid .cell-phone {
  font-family: var(--font-mono, 'SF Mono', 'Cascadia Code', 'Fira Mono', Consolas, monospace);
  font-size: 12px;
  color: var(--text-muted, #94a3b8);
}


/* --------------------------------------------------------------------------
   13.5  Badge and pill inheritance
   --------------------------------------------------------------------------

   All badge and pill classes are defined in design-system.css and projects.css.
   AG Grid cells inherit these styles without overrides. The selectors below
   exist only as documentation and as a safety net for specificity.              */

.erp-grid .badge,
.erp-grid .badge-stage,
.erp-grid .pill,
.erp-grid .company-badge {
  /* Inherited from global styles — no overrides */
}


/* --------------------------------------------------------------------------
   13.6  Action buttons inside cells
   -------------------------------------------------------------------------- */

/* Icon-only action button (clients edit/deactivate) */
.erp-grid .btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm, 4px);
  color: var(--text-muted, #94a3b8);
  cursor: pointer;
  transition: all 120ms ease;
}

.erp-grid .btn-icon:hover {
  background: var(--content-bg, #f8fafc);
  border-color: var(--border, #e2e8f0);
  color: var(--text-secondary, #475569);
}

.erp-grid .btn-icon svg {
  width: 16px;
  height: 16px;
}

/* Extra-small button for dense columns (projects actions) */
.erp-grid .btn-xs {
  height: 28px;
  padding: 0 10px;
  font-size: 11px;
}


/* --------------------------------------------------------------------------
   13.7  Pagination bar
   -------------------------------------------------------------------------- */

.erp-grid-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid var(--border, #e2e8f0);
  background: var(--surface, #ffffff);
  flex-wrap: wrap;
  gap: 12px;
}

.erp-grid-pagination-info {
  font-size: 13px;
  color: var(--text-muted, #94a3b8);
}

.erp-grid-pagination-info strong {
  color: var(--text-secondary, #475569);
  font-weight: 500;
}

.erp-grid-pagination-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.erp-grid-pagination-page {
  font-size: 13px;
  color: var(--text-secondary, #475569);
  white-space: nowrap;
}

.erp-grid-pagination-select {
  height: 32px;
  font-size: 12px;
  padding: 0 8px;
  border: 1px solid var(--border-strong, #cbd5e1);
  border-radius: var(--radius-sm, 4px);
  background: var(--surface, #ffffff);
  color: var(--text-primary, #0f172a);
  font-family: var(--font-sans, 'Inter', system-ui, sans-serif);
  cursor: pointer;
}

.erp-grid-pagination-select:focus {
  outline: none;
  border-color: var(--primary, #3b82f6);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}


/* --------------------------------------------------------------------------
   13.7b  Grid toolbar (always visible, above grid)
   -------------------------------------------------------------------------- */

.erp-grid-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 0 0 8px;
}

.erp-grid-col-toggle {
  position: relative;
}

.erp-grid-col-toggle .ms-panel {
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 220px;
  max-height: 320px;
  overflow-y: auto;
  margin-top: 4px;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: var(--radius-md, 6px);
  box-shadow: var(--shadow-md, 0 4px 6px -1px rgba(0,0,0,.1));
  z-index: 100;
  padding: 4px 0;
}

.erp-grid-col-toggle .ms-option {
  padding: 6px 12px;
  font-size: 13px;
}

/* --------------------------------------------------------------------------
   13.8  Empty state overlay
   -------------------------------------------------------------------------- */

.erp-grid .ag-overlay-no-rows-wrapper {
  padding: 40px 20px;
}

.erp-grid-empty-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary, #475569);
  margin-bottom: 4px;
}

.erp-grid-empty-subtitle {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted, #94a3b8);
}


/* --------------------------------------------------------------------------
   13.9  Loading state overlay
   -------------------------------------------------------------------------- */

.erp-grid .ag-overlay-loading-wrapper {
  padding: 40px 20px;
}

.erp-grid-loading-spinner {
  width: 24px;
  height: 24px;
  margin: 0 auto 12px;
  border: 2px solid var(--border, #e2e8f0);
  border-top-color: var(--primary, #3b82f6);
  border-radius: 50%;
  animation: erp-grid-spin 0.6s linear infinite;
}

@keyframes erp-grid-spin {
  to { transform: rotate(360deg); }
}

.erp-grid-loading-text {
  font-size: 13px;
  color: var(--text-muted, #94a3b8);
  text-align: center;
}


/* --------------------------------------------------------------------------
   13.10  Suppress unwanted AG Grid Chrome
   -------------------------------------------------------------------------- */

/* Remove the bottom border from the grid wrapper (table-card provides it) */
.erp-grid.ag-theme-alpine .ag-root-wrapper {
  border: none;
  border-radius: 0;
}

/* Remove header bottom border doubling (table-card + ag-header) */
.erp-grid.ag-theme-alpine .ag-header {
  border-bottom: 1px solid var(--border, #e2e8f0);
}

/* Remove the "no rows" overlay wrapper background */
.erp-grid .ag-overlay-no-rows-wrapper,
.erp-grid .ag-overlay-loading-wrapper {
  background: transparent;
}

/* Suppress cell focus outline (keyboard focus is on row level) */
.erp-grid .ag-cell-focus:not(.ag-cell-range-selected) {
  border: none !important;
}

/* Suppress horizontal resize handle visual noise */
.erp-grid .ag-header-cell-resize {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.erp-grid .ag-header-cell:hover .ag-header-cell-resize {
  opacity: 0.5;
}
