/* ==========================================================================
   Sales Hub — Win/Loss Analysis Stylesheet
   Uses CSS custom properties from panel.css.
   ========================================================================== */

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

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

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

.wl-period-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: 38px;
  min-width: 180px;
  cursor: pointer;
}

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

/* --------------------------------------------------------------------------
   2. KPI Cards Grid
   -------------------------------------------------------------------------- */
.wl-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.wl-kpi-card {
  background: var(--white);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  text-align: center;
  transition: box-shadow var(--transition-fast);
}

.wl-kpi-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.wl-kpi-card__label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-2);
}

.wl-kpi-card__value {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.wl-kpi-card__value--success {
  color: var(--success);
}

.wl-kpi-card__value--danger {
  color: var(--danger);
}

.wl-kpi-card__sub {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

/* --------------------------------------------------------------------------
   3. Chart Containers
   -------------------------------------------------------------------------- */
.wl-charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
  margin-bottom: var(--space-6);
}

.wl-chart-card {
  background: var(--white);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-5);
}

.wl-chart-card--full {
  grid-column: 1 / -1;
}

.wl-chart-card__title {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-4);
}

.wl-chart-canvas {
  width: 100%;
  height: 280px;
}

.wl-chart-canvas--tall {
  height: 350px;
}

/* --------------------------------------------------------------------------
   4. Data Tables
   -------------------------------------------------------------------------- */
.wl-table-wrapper {
  background: var(--white);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin-bottom: var(--space-6);
}

.wl-table-wrapper__title {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--text-primary);
  padding: var(--space-4) var(--space-4) 0;
  margin-bottom: 0;
}

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

.wl-table th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-weight: 600;
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  background: var(--gray-50);
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}

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

.wl-table td.col-right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.wl-table th.col-right {
  text-align: right;
}

.wl-table tbody tr:hover {
  background: var(--gray-50);
}

/* Progress bar in table cells */
.wl-pct-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.wl-pct-bar__track {
  flex: 1;
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
  overflow: hidden;
  min-width: 60px;
}

.wl-pct-bar__fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.wl-pct-bar__label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 40px;
  text-align: right;
}

/* --------------------------------------------------------------------------
   5. Loading State
   -------------------------------------------------------------------------- */
.wl-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);
}

.wl-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: wl-spin 0.6s linear infinite;
}

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

/* --------------------------------------------------------------------------
   6. Top Performers Section
   -------------------------------------------------------------------------- */
.wl-performers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-3);
}

.wl-performer-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--gray-50);
  border-radius: var(--radius-md);
}

.wl-performer-rank {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-xs);
  font-weight: 700;
  flex-shrink: 0;
}

.wl-performer-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.wl-performer-name {
  font-weight: 600;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wl-performer-stat {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   7. Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .wl-kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .wl-charts-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .wl-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .wl-kpi-grid {
    grid-template-columns: 1fr 1fr;
  }

  .wl-charts-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .wl-kpi-grid {
    grid-template-columns: 1fr;
  }
}
