/* ==========================================================================
   Sales Hub — List Pages Stylesheet
   Shared styles for all entity list/index pages.
   Uses CSS custom properties from panel.css.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Page Header
   -------------------------------------------------------------------------- */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
  gap: var(--space-4);
}

.list-header h1 {
  margin: 0;
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--text-primary);
}

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

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-5);
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  height: 38px;
}

.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 2px 8px rgba(255, 122, 0, 0.25);
  color: var(--white);
  text-decoration: none;
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-primary svg,
.btn-primary .btn-icon {
  width: 16px;
  height: 16px;
}

/* Secondary/outline button */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--white);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  height: 38px;
  text-decoration: none;
  white-space: nowrap;
}

.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
  text-decoration: none;
}

/* --------------------------------------------------------------------------
   2. View Toggle (Table / Kanban)
   -------------------------------------------------------------------------- */
.view-toggle {
  display: inline-flex;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.view-toggle button {
  padding: var(--space-2) var(--space-4);
  background: var(--white);
  border: none;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.view-toggle button + button {
  border-left: 1px solid var(--border-color);
}

.view-toggle button.active {
  background: var(--primary);
  color: var(--white);
}

.view-toggle button:hover:not(.active) {
  background: var(--gray-100);
}

/* --------------------------------------------------------------------------
   3. Filter Bar
   -------------------------------------------------------------------------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  padding: var(--space-4) var(--space-5);
  background: var(--white);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.filter-group label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.filter-group input,
.filter-group select {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  background: var(--white);
  height: 36px;
  min-width: 140px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.filter-group input:focus,
.filter-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(255, 122, 0, 0.15);
}

.filter-group input[type="search"] {
  min-width: 220px;
}

.filter-group .input-range {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.filter-group .input-range input {
  width: 100px;
  min-width: 80px;
}

.filter-group .input-range span {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

/* --------------------------------------------------------------------------
   4. Data Table
   -------------------------------------------------------------------------- */
.table-wrapper {
  background: var(--white);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.data-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  background: #f8f9fa;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
  user-select: none;
}

.data-table th.sortable {
  cursor: pointer;
  transition: color var(--transition-fast);
}

.data-table th.sortable:hover {
  color: var(--primary);
}

.data-table th .sort-arrow {
  display: inline-block;
  margin-left: var(--space-1);
  font-size: 10px;
  color: var(--text-muted);
  transition: transform var(--transition-fast), color var(--transition-fast);
}

.data-table th.sort-asc .sort-arrow {
  color: var(--primary);
}

.data-table th.sort-desc .sort-arrow {
  color: var(--primary);
  transform: rotate(180deg);
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--text-primary);
  vertical-align: middle;
}

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

.data-table tbody tr:hover {
  background: rgba(59, 130, 246, 0.04);
}

.data-table tbody tr:nth-child(even) {
  background: rgba(249, 250, 251, 0.5);
}

.data-table tbody tr:nth-child(even):hover {
  background: rgba(59, 130, 246, 0.04);
}

.data-table tbody tr.row-overdue {
  background: rgba(239, 68, 68, 0.05);
}

.data-table tbody tr.row-overdue:hover {
  background: rgba(239, 68, 68, 0.08);
}

/* Right-aligned columns (monetary values) */
.data-table th.col-amount,
.data-table td.col-amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table th.col-center,
.data-table td.col-center {
  text-align: center;
}

/* Clickable row name */
.data-table td a.row-link {
  color: var(--text-primary);
  font-weight: 600;
  text-decoration: none;
  transition: color var(--transition-fast);
}

.data-table td a.row-link:hover {
  color: var(--primary);
  text-decoration: none;
}

/* --------------------------------------------------------------------------
   5. Contact Cell (Avatar + Name)
   -------------------------------------------------------------------------- */
.contact-cell {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.contact-cell .avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--primary-light);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-xs);
  font-weight: 700;
  flex-shrink: 0;
  text-transform: uppercase;
}

.contact-cell .cell-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.contact-cell .cell-text .name {
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color var(--transition-fast);
}

.contact-cell .cell-text .name:hover {
  color: var(--primary);
}

.contact-cell .cell-text .sub {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --------------------------------------------------------------------------
   6. Status Badges
   -------------------------------------------------------------------------- */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.6;
}

/* Lead statuses */
.status-hot        { background: #fde8e8; color: #991b1b; }
.status-warm       { background: #fff3cd; color: #92400e; }
.status-cold       { background: #dbeafe; color: #1e40af; }
.status-inactive   { background: var(--gray-100); color: var(--gray-500); }

/* Offer statuses */
.status-draft      { background: var(--gray-100); color: var(--gray-600); }
.status-sent       { background: #dbeafe; color: #1e40af; }
.status-viewed     { background: #fff3cd; color: #92400e; }
.status-signed     { background: #d1fae5; color: #065f46; }
.status-expired    { background: #fde8e8; color: #991b1b; }

/* Contract statuses */
.status-active     { background: #d1fae5; color: #065f46; }
.status-paused     { background: #fef3c7; color: #92400e; }
.status-terminated { background: #fde8e8; color: #991b1b; }
.status-expired-dark { background: var(--gray-200); color: var(--gray-700); }

/* Task priority */
.priority-urgent   { background: #fde8e8; color: #991b1b; }
.priority-high     { background: #ffedd5; color: #9a3412; }
.priority-medium   { background: #dbeafe; color: #1e40af; }
.priority-low      { background: var(--gray-100); color: var(--gray-500); }

/* Task statuses */
.status-open       { background: #dbeafe; color: #1e40af; }
.status-in_progress { background: #fef3c7; color: #92400e; }
.status-completed  { background: #d1fae5; color: #065f46; }

/* Deal stage badges */
.stage-qualifiedtobuy        { background: #dbeafe; color: #1e40af; }
.stage-presentationscheduled { background: #ffedd5; color: #9a3412; }
.stage-decisionmakerboughtin { background: #fef3c7; color: #92400e; }
.stage-contractsent          { background: #e0e7ff; color: #3730a3; }
.stage-closedwon             { background: #d1fae5; color: #065f46; }
.stage-closedlost            { background: #fde8e8; color: #991b1b; }

/* Contract type badges */
.type-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: 600;
  background: var(--gray-100);
  color: var(--gray-700);
  white-space: nowrap;
  line-height: 1.6;
}

/* Task type badges */
.task-type-call      { background: #e0e7ff; color: #3730a3; }
.task-type-email     { background: #dbeafe; color: #1e40af; }
.task-type-meeting   { background: #fef3c7; color: #92400e; }
.task-type-follow_up { background: #ffedd5; color: #9a3412; }
.task-type-general   { background: var(--gray-100); color: var(--gray-600); }
.task-type-document  { background: #e0e7ff; color: #3730a3; }
.task-type-review    { background: #ede9fe; color: #5b21b6; }

/* --------------------------------------------------------------------------
   7. Lead Score Mini Bar
   -------------------------------------------------------------------------- */
.score-bar {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.score-bar .bar-track {
  width: 60px;
  height: 4px;
  background: var(--gray-200);
  border-radius: 2px;
  overflow: hidden;
}

.score-bar .bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width var(--transition-base);
}

.score-bar .bar-fill.score-low    { background: #ef4444; }
.score-bar .bar-fill.score-mid    { background: #f59e0b; }
.score-bar .bar-fill.score-high   { background: #22c55e; }

/* --------------------------------------------------------------------------
   8. Pagination
   -------------------------------------------------------------------------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  margin-top: var(--space-5);
  padding: var(--space-4) 0;
}

.pagination .page-info {
  margin-right: var(--space-4);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

.pagination button,
.pagination a {
  min-width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--space-2);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text-primary);
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
}

.pagination button:hover:not(:disabled):not(.active),
.pagination a:hover:not(.active) {
  background: var(--gray-50);
  border-color: var(--primary);
  color: var(--primary);
}

.pagination button.active,
.pagination a.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--white);
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   9. Empty State
   -------------------------------------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-4);
  text-align: center;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: var(--space-4);
  opacity: 0.35;
}

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

.empty-state .empty-sub {
  font-size: var(--font-size-sm);
  margin-top: var(--space-2);
}

.empty-state .btn-primary {
  margin-top: var(--space-5);
}

/* --------------------------------------------------------------------------
   10. Loading State
   -------------------------------------------------------------------------- */
.table-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-4);
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

.table-loading::before {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin-right: var(--space-3);
  animation: spin 0.6s linear infinite;
}

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

/* --------------------------------------------------------------------------
   11. Kanban / Pipeline View (Deals)
   -------------------------------------------------------------------------- */
.pipeline-view {
  display: none;
}

.pipeline-view.active {
  display: block;
}

.table-view {
  display: none;
}

.table-view.active {
  display: block;
}

/* Pipeline Summary Bar */
.pipeline-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  padding: var(--space-5);
  background: var(--white);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.pipeline-summary__item {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  text-align: center;
  padding: var(--space-2);
}

.pipeline-summary__label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.pipeline-summary__value {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* Pipeline columns wrapper */
.pipeline-columns {
  display: flex;
  gap: var(--space-3);
  overflow-x: auto;
  padding-bottom: var(--space-4);
  scroll-snap-type: x mandatory;
}

/* Individual pipeline stage column */
.pipeline-stage {
  flex: 1;
  min-width: 240px;
  max-width: 320px;
  background: var(--gray-50);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 320px);
  scroll-snap-align: start;
}

.pipeline-stage__header {
  padding: var(--space-3) var(--space-4);
  font-weight: 600;
  font-size: var(--font-size-sm);
  border-bottom: 2px solid var(--primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  background: var(--white);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.pipeline-stage__count {
  background: var(--gray-200);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  padding: 0 var(--space-2);
  font-size: var(--font-size-xs);
  font-weight: 600;
}

.pipeline-stage__total {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
  font-variant-numeric: tabular-nums;
}

.pipeline-stage__body {
  padding: var(--space-3);
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* Drag-over visual feedback */
.pipeline-stage.drag-over {
  background: rgba(255, 122, 0, 0.06);
  outline: 2px dashed var(--primary);
  outline-offset: -2px;
}

/* Pipeline card */
.pipeline-card {
  background: var(--white);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  cursor: grab;
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}

.pipeline-card:active {
  cursor: grabbing;
}

.pipeline-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--gray-300);
}

.pipeline-card.dragging {
  opacity: 0.5;
  transform: rotate(2deg);
  box-shadow: var(--shadow-lg);
}

.pipeline-card__name {
  font-weight: 600;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  margin-bottom: 2px;
}

.pipeline-card__name a {
  color: inherit;
  text-decoration: none;
}

.pipeline-card__name a:hover {
  color: var(--primary);
}

.pipeline-card__company {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.pipeline-card__amount {
  font-weight: 700;
  color: var(--primary);
  font-size: var(--font-size-sm);
  font-variant-numeric: tabular-nums;
}

.pipeline-card__meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--space-2);
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

/* Stage duration on deal cards */
.pipeline-card__stage-duration {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  padding: 2px 0;
}

.pipeline-card__stage-duration--warning {
  color: var(--warning);
  font-weight: 600;
}

.pipeline-card__stage-duration--critical {
  color: var(--danger);
  font-weight: 600;
}

/* Stale deal card border warnings */
.pipeline-card--stale {
  border-left: 3px solid var(--warning) !important;
}

.pipeline-card--critical {
  border-left: 3px solid var(--danger) !important;
}

/* --------------------------------------------------------------------------
   12. Overdue Highlight (date cells)
   -------------------------------------------------------------------------- */
.text-overdue {
  color: var(--danger);
  font-weight: 600;
}

.text-muted {
  color: var(--text-muted);
}

.text-success {
  color: var(--success);
}

/* --------------------------------------------------------------------------
   13. CSV Export Button
   -------------------------------------------------------------------------- */
.btn-export {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--white);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  height: 38px;
  text-decoration: none;
}

.btn-export:hover {
  border-color: var(--primary);
  color: var(--primary);
  text-decoration: none;
}

/* --------------------------------------------------------------------------
   14. Inline Action Buttons (row actions)
   -------------------------------------------------------------------------- */
.row-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.data-table tbody tr:hover .row-actions {
  opacity: 1;
}

.row-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 14px;
}

.row-action-btn:hover {
  background: var(--gray-100);
  color: var(--primary);
}

.row-action-btn.danger:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

/* --------------------------------------------------------------------------
   15. Bulk Selection Bar
   -------------------------------------------------------------------------- */
.bulk-bar {
  display: none;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  margin-bottom: var(--space-4);
  background: rgba(255, 122, 0, 0.06);
  border: 1px solid rgba(255, 122, 0, 0.2);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
}

.bulk-bar.active {
  display: flex;
}

.bulk-bar .bulk-count {
  font-weight: 600;
  color: var(--primary);
}

.bulk-bar .bulk-actions {
  display: flex;
  gap: var(--space-2);
  margin-left: auto;
}

/* --------------------------------------------------------------------------
   16. Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .list-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .filter-bar {
    flex-direction: column;
    padding: var(--space-3);
  }

  .filter-group {
    width: 100%;
  }

  .filter-group input,
  .filter-group select {
    width: 100%;
    min-width: 0;
  }

  .filter-group input[type="search"] {
    min-width: 0;
  }

  .pagination {
    flex-wrap: wrap;
  }

  .data-table th,
  .data-table td {
    padding: var(--space-2) var(--space-3);
  }

  .pipeline-summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .pipeline-columns {
    gap: var(--space-2);
  }

  .pipeline-stage {
    min-width: 200px;
  }

  .row-actions {
    opacity: 1;
  }
}
