/**
 * Premium AI Sales Intelligence dashboard.
 * 12-column CSS Grid · white cards on #F8FAFC · 16px radius.
 */

.dash {
  --dash-gap: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--dash-gap);
}

.dash__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--space-5);
  flex-wrap: wrap;
  padding-bottom: var(--space-2);
}

.dash__eyebrow {
  margin: 0 0 var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.dash__title {
  margin: 0;
  font-size: clamp(1.75rem, 2.4vw, 2.25rem);
  font-weight: var(--weight-bold);
  letter-spacing: -0.03em;
  color: var(--color-text);
}

.dash__subtitle {
  margin: var(--space-2) 0 0;
  max-width: 36rem;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  line-height: 1.6;
}

.dash__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
}

/* 12-column grid */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--dash-gap);
}

.dash-span-3 { grid-column: span 3; }
.dash-span-4 { grid-column: span 4; }
.dash-span-5 { grid-column: span 5; }
.dash-span-6 { grid-column: span 6; }
.dash-span-7 { grid-column: span 7; }
.dash-span-8 { grid-column: span 8; }
.dash-span-12 { grid-column: span 12; }

/* Panel / card primitive (not Bootstrap) */
.dash-panel {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.dash-panel--flush {
  padding: 0;
  overflow: hidden;
}

.dash-panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.dash-panel__title {
  margin: 0;
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
  color: var(--color-text);
}

.dash-panel__meta {
  margin: var(--space-1) 0 0;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.dash-panel__link {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-primary);
  text-decoration: none;
  white-space: nowrap;
}

.dash-panel__link:hover {
  text-decoration: underline;
}

.dash-panel__body {
  flex: 1;
  min-height: 0;
}

/* KPI cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--space-4);
}

.kpi-card {
  grid-column: span 3;
  position: relative;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 132px;
  transition: box-shadow var(--transition), border-color var(--transition), transform var(--transition);
  cursor: help;
}

.kpi-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-border-strong);
  transform: translateY(-1px);
}

.kpi-card__top {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.kpi-card__icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--color-bg-muted);
  color: var(--color-primary);
}

.kpi-card__icon i,
.kpi-card__icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
}

.kpi-card--primary .kpi-card__icon { background: var(--color-primary-soft); color: var(--color-primary); }
.kpi-card--success .kpi-card__icon { background: #ecfdf5; color: var(--color-success); }
.kpi-card--info .kpi-card__icon { background: var(--color-primary-soft); color: var(--color-info); }
.kpi-card--warning .kpi-card__icon { background: #fffbeb; color: var(--color-warning); }
.kpi-card--muted .kpi-card__icon { background: var(--color-bg-muted); color: var(--color-text-secondary); }

.kpi-card__label {
  margin: 0;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
}

.kpi-card__value {
  margin: var(--space-2) 0 0;
  font-size: clamp(1.6rem, 2vw, 1.9rem);
  font-weight: var(--weight-bold);
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--color-text);
}

.kpi-card__trend {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
}

.kpi-card__trend-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-full);
  font-weight: var(--weight-semibold);
  font-size: 0.7rem;
}

.kpi-card__trend-badge.is-up {
  background: #e8f8ee;
  color: var(--color-success);
}

.kpi-card__trend-badge.is-down {
  background: #fdecec;
  color: var(--color-danger);
}

.kpi-card__trend-badge.is-flat {
  background: var(--color-bg-muted);
  color: var(--color-text-secondary);
}

/* Empty / banner */
.dash-empty-hero {
  text-align: center;
  padding: var(--space-12) var(--space-8);
  align-items: center;
}

.dash-empty-hero__icon {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  margin: 0 auto var(--space-5);
  background: #e8f2f9;
  color: var(--color-primary);
}

.dash-empty-hero__icon svg { width: 36px; height: 36px; }

.dash-empty-hero__title {
  margin: 0 0 var(--space-3);
  font-size: var(--text-xl);
}

.dash-empty-hero__body {
  margin: 0 auto var(--space-6);
  max-width: 32rem;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

.dash-banner {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: var(--space-5) var(--space-6);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-primary-muted);
  background: linear-gradient(135deg, var(--color-accent-soft) 0%, var(--color-bg-card) 100%);
  box-shadow: var(--shadow-xs);
}

.dash-banner__icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  background: var(--color-primary-soft);
  color: var(--color-primary);
  flex: 0 0 auto;
}

.dash-banner__body strong {
  display: block;
  font-size: var(--text-base);
  color: var(--color-text);
  margin-bottom: var(--space-1);
}

.dash-banner p {
  margin: 0;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  line-height: 1.5;
}

.dash-banner .btn { margin-left: auto; }

.dash-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-3);
  min-height: 240px;
  padding: var(--space-8) var(--space-4);
}

.dash-empty-state__icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--color-bg-muted);
  color: var(--color-text-muted);
}

.dash-empty-state__icon svg { width: 28px; height: 28px; }

.dash-empty-state__title {
  margin: 0;
  font-weight: var(--weight-semibold);
  font-size: var(--text-base);
}

.dash-empty-state__body {
  margin: 0;
  max-width: 22rem;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

.job-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.job-summary__item {
  padding: var(--space-3) var(--space-4);
  border-radius: 12px;
  background: var(--color-bg-muted);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.job-summary__item span {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.job-summary__item strong {
  font-size: var(--text-lg);
  font-variant-numeric: tabular-nums;
}

.job-item__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}

.qa-grid--8 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* Funnel */
.funnel {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.funnel__row {
  display: grid;
  grid-template-columns: 8.5rem 1fr 3rem;
  gap: var(--space-3);
  align-items: center;
  font-size: var(--text-sm);
}

.funnel__label {
  color: var(--color-text-secondary);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.funnel__track {
  height: 12px;
  border-radius: var(--radius-full);
  background: var(--color-bg-muted);
  overflow: hidden;
}

.funnel__fill {
  height: 100%;
  width: var(--funnel-w, 0%);
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
  transition: width 400ms ease;
}

.funnel__count {
  text-align: right;
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
}

/* Charts */
.chart-box {
  width: 100%;
  min-height: 280px;
}

.chart-box--sm {
  min-height: 260px;
}

/* AI insights */
.insight-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.insight-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: 14px;
  background: var(--color-bg-muted);
  border: 1px solid transparent;
}

.insight-item__icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--color-bg-card);
  color: var(--color-primary);
}

.insight-item__icon svg {
  width: 18px;
  height: 18px;
}

.insight-item__title {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.insight-item__body {
  margin: var(--space-1) 0 0;
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  line-height: 1.55;
}

.insight-item--success .insight-item__icon { color: var(--color-success); }
.insight-item--warning .insight-item__icon { color: var(--color-warning); }
.insight-item--info .insight-item__icon { color: var(--color-info); }

/* Jobs */
.job-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.job-item {
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background: var(--color-bg-card);
}

.job-item__row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  align-items: flex-start;
}

.job-item__title {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.job-item__type {
  margin: var(--space-1) 0 0;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.job-item__status {
  font-size: 0.7rem;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  background: var(--color-bg-muted);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.job-item__status.is-running,
.job-item__status.is-queued,
.job-item__status.is-retrying,
.job-item__status.is-pending {
  background: #e8f0fe;
  color: var(--color-info);
}

.job-item__status.is-idle {
  background: var(--color-bg-muted);
  color: var(--color-text-muted);
}

.job-item__bar {
  margin-top: var(--space-3);
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-bg-muted);
  overflow: hidden;
}

.job-item__bar > span {
  display: block;
  height: 100%;
  width: var(--job-w, 0%);
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
  border-radius: inherit;
}

.job-item__msg {
  margin: var(--space-2) 0 0;
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}

/* Timeline */
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.timeline__item {
  position: relative;
  display: grid;
  grid-template-columns: 1.25rem 1fr;
  gap: var(--space-3);
  padding: 0 0 var(--space-5);
}

.timeline__item:last-child {
  padding-bottom: 0;
}

.timeline__rail {
  position: relative;
  display: flex;
  justify-content: center;
}

.timeline__dot {
  width: 10px;
  height: 10px;
  margin-top: 0.35rem;
  border-radius: 50%;
  background: var(--color-primary);
  box-shadow: 0 0 0 4px #e8f2f9;
  z-index: 1;
}

.timeline__rail::after {
  content: "";
  position: absolute;
  top: 1rem;
  bottom: -0.25rem;
  width: 2px;
  background: var(--color-border);
}

.timeline__item:last-child .timeline__rail::after {
  display: none;
}

.timeline__time {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}

.timeline__title {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.timeline__detail {
  margin: var(--space-1) 0 0;
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  line-height: 1.5;
}

/* Recent companies table */
.dash-table-wrap {
  overflow-x: auto;
  margin: 0 calc(var(--space-6) * -1);
  padding: 0 var(--space-6);
}

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

.dash-table th {
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  padding: 0 var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.dash-table td {
  padding: var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
  color: var(--color-text);
}

.dash-table tr:last-child td {
  border-bottom: 0;
}

.dash-table a {
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  text-decoration: none;
}

.dash-table a:hover {
  color: var(--color-primary);
}

.dash-company {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.dash-company__avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #e8f2f9, #daebe8);
  color: var(--color-primary);
  display: grid;
  place-items: center;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  flex: 0 0 auto;
}

.score-pill {
  display: inline-flex;
  min-width: 2.5rem;
  justify-content: center;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  background: #e8f2f9;
  color: var(--color-primary);
}

.dash-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: var(--weight-semibold);
  text-transform: capitalize;
  background: var(--color-bg-muted);
  color: var(--color-text-secondary);
}

.dash-badge--active {
  background: #e8f8ee;
  color: var(--color-success);
}

/* Quick actions */
.qa-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
}

.qa-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-5);
  border-radius: 16px;
  border: 1px solid var(--color-border);
  background: var(--color-bg-card);
  box-shadow: var(--shadow-xs);
  text-decoration: none;
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  min-height: 128px;
}

.qa-card:hover {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  text-decoration: none;
  color: var(--color-text);
}

.qa-card__icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: #e8f2f9;
  color: var(--color-primary);
}

.qa-card__icon svg {
  width: 20px;
  height: 20px;
}

.qa-card__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.qa-card__hint {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  line-height: 1.45;
}

.dash-empty {
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

/* Widen dashboard canvas */
.main:has(.dash) {
  max-width: 1440px;
}

@media (max-width: 1280px) {
  .kpi-card {
    grid-column: span 4;
  }

  .job-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .qa-grid--8 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dash-span-3,
  .dash-span-4,
  .dash-span-5,
  .dash-span-6,
  .dash-span-7,
  .dash-span-8 {
    grid-column: span 6;
  }
}

@media (max-width: 960px) {
  .kpi-card,
  .dash-span-3,
  .dash-span-4,
  .dash-span-5,
  .dash-span-6,
  .dash-span-7,
  .dash-span-8,
  .dash-span-12 {
    grid-column: span 12;
  }

  .qa-grid,
  .qa-grid--8 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .dash-banner .btn {
    margin-left: 0;
  }

  .funnel__row {
    grid-template-columns: 6.5rem 1fr 2.5rem;
  }

  .dash-panel {
    padding: var(--space-5);
  }
}

@media (max-width: 640px) {
  .qa-grid {
    grid-template-columns: 1fr;
  }

  .dash__header {
    align-items: flex-start;
  }

  .job-summary {
    grid-template-columns: 1fr 1fr;
  }
}

/* Legacy class aliases kept for other pages */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--space-4);
}

.dashboard-grid > .card,
.dashboard-grid > .stat-card {
  grid-column: span 3;
}

.dashboard-span-4 { grid-column: span 4; }
.dashboard-span-6 { grid-column: span 6; }
.dashboard-span-8 { grid-column: span 8; }
.dashboard-span-12 { grid-column: span 12; }
