/* ============================================================================
   PROFITABILITY DASHBOARD — CSS
   Uses main design system variables from style.css
   ============================================================================ */

.profit-section {
  --p-bg: var(--bg-primary, #1A1F2E);
  --p-surface: var(--bg-card-solid, #2D3550);
  --p-surface2: var(--bg-tertiary, #282F42);
  --p-border: var(--border-solid, #3A4560);
  --p-text: var(--text, #F1F5F9);
  --p-text-dim: var(--text-secondary, #B0BEC5);
  --p-accent: var(--accent, #38BDF8);
  --p-accent-dim: rgba(56, 189, 248, 0.18);
  --p-green: var(--green, #34D399);
  --p-green-dim: var(--green-bg, rgba(52,211,153,.16));
  --p-red: var(--red, #F87171);
  --p-red-dim: var(--red-bg, rgba(248,113,113,.16));
  --p-yellow: var(--orange, #FBBF24);
  --p-yellow-dim: var(--orange-bg, rgba(251,191,36,.16));
  --p-orange: #fb923c;

  background: var(--p-bg);
  color: var(--p-text);
  padding: 24px;
  border-radius: var(--radius-lg, 16px);
  font-family: inherit;
  min-height: 400px;
}

/* ============================================================================
   SUB-TAB NAVIGATION
   ============================================================================ */
.profit-sub-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  background: var(--p-surface);
  border-radius: 10px;
  padding: 4px;
  width: fit-content;
  overflow-x: auto;
}

.profit-sub-tab {
  padding: 9px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--p-text-dim);
  transition: all .15s;
  border: none;
  background: none;
  font-family: inherit;
  white-space: nowrap;
}
.profit-sub-tab:hover:not(.active) {
  color: var(--p-text);
  background: var(--p-surface2);
}
.profit-sub-tab.active {
  background: var(--accent-gradient, linear-gradient(135deg, #0EA5E9, #38BDF8));
  color: #fff;
  font-weight: 600;
  box-shadow: 0 0 15px var(--accent-glow, rgba(56,189,248,.15));
}

/* ============================================================================
   FILTER ROW
   ============================================================================ */
.profit-filter-row {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.profit-filter-btn {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  color: var(--p-text-dim);
  background: transparent;
  border: 1px solid var(--p-border);
  transition: all .15s;
  font-family: inherit;
}
.profit-filter-btn:hover {
  border-color: var(--border-hover, rgba(56,189,248,.2));
  color: var(--p-text);
}
.profit-filter-btn.active {
  background: var(--accent-gradient, linear-gradient(135deg, #0EA5E9, #38BDF8));
  border-color: var(--p-accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 0 15px var(--accent-glow, rgba(56,189,248,.15));
}

/* ============================================================================
   KPI CARDS
   ============================================================================ */
.profit-kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.profit-kpi {
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: var(--radius, 12px);
  padding: 18px 20px;
  transition: all .2s;
  position: relative;
  overflow: hidden;
}
.profit-kpi::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(56,189,248,.03), transparent);
  pointer-events: none;
}
.profit-kpi:hover {
  border-color: var(--border-hover, rgba(56,189,248,.2));
  box-shadow: 0 0 20px var(--accent-glow, rgba(56,189,248,.15));
}
.profit-kpi-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 2px;
  color: var(--p-accent);
  text-shadow: 0 0 12px rgba(56,189,248,.2);
}
.profit-kpi-label {
  font-size: 12px;
  color: var(--p-text-dim);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
}
.profit-kpi-sub {
  font-size: 11px;
  color: var(--p-text-dim);
  margin-top: 4px;
}

/* ============================================================================
   TABLE
   ============================================================================ */
.profit-table-wrap {
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: var(--radius, 12px);
  overflow: hidden;
  margin-bottom: 20px;
}
.profit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.profit-table th {
  text-align: left;
  padding: 12px 16px;
  background: var(--p-surface2);
  color: var(--p-text-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .4px;
  border-bottom: 1px solid var(--p-border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.profit-table th[data-sort]::after {
  content: '⇅';
  margin-left: 6px;
  font-size: 10px;
  opacity: 0.4;
}
.profit-table th[data-sort].sort-asc::after { content: '↑'; opacity: 0.9; color: var(--p-accent); }
.profit-table th[data-sort].sort-desc::after { content: '↓'; opacity: 0.9; color: var(--p-accent); }
.profit-table th[data-sort]:hover { color: var(--p-accent); }

.profit-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--p-border);
  vertical-align: middle;
}
.profit-table tr:last-child td { border-bottom: none; }
.profit-table tbody tr:hover td { background: rgba(56,189,248,.04); }

.profit-job-row { cursor: pointer; }
.profit-job-row:hover td { background: rgba(56,189,248,.08) !important; }

.expand-icon {
  display: inline-flex;
  width: 22px;
  height: 22px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--p-surface2);
  color: var(--p-text-dim);
  font-weight: 700;
  font-size: 14px;
  transition: all .15s;
}
.profit-job-row:hover .expand-icon {
  background: var(--accent-glow, rgba(56,189,248,.15));
  color: var(--p-accent);
}

/* ============================================================================
   MARGIN BAR
   ============================================================================ */
.profit-margin-bar {
  width: 80px;
  height: 8px;
  background: var(--p-surface2);
  border-radius: 4px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
}
.profit-margin-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .3s ease;
}

/* ============================================================================
   TYPE BADGES
   ============================================================================ */
.profit-badge-resi {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent-glow, rgba(56,189,248,.15));
  color: var(--p-accent);
}
.profit-badge-comm {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: var(--orange-bg, rgba(251,191,36,.12));
  color: var(--p-yellow);
}
.profit-badge-service {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(251,146,60,.15);
  color: var(--p-orange);
}

/* ============================================================================
   DETAIL PANEL
   ============================================================================ */
.profit-detail-panel td {
  padding: 0 !important;
  border-bottom: 1px solid var(--p-border) !important;
}
.profit-detail-panel h4 { color: var(--p-text); font-size: 13px; }
.profit-detail-panel table { color: var(--p-text); }
.profit-detail-panel strong { color: var(--p-text); }

/* ============================================================================
   CHART GRID
   ============================================================================ */
.profit-chart-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
.profit-chart-card {
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: var(--radius, 12px);
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.profit-chart-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(56,189,248,.02), transparent);
  pointer-events: none;
}
.profit-chart-card h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--p-text-dim);
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: .3px;
  position: relative;
}
.profit-chart-card canvas { max-height: 250px; position: relative; }

/* ============================================================================
   OVER BUDGET & HEADINGS
   ============================================================================ */
.profit-over-budget td { background: var(--p-red-dim) !important; }
.profit-section h3 { color: var(--p-text); font-size: 15px; font-weight: 600; }
.profit-section .badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */
@media (max-width: 900px) {
  .profit-chart-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .profit-section { padding: 16px; }
  .profit-kpi-row { grid-template-columns: 1fr 1fr; gap: 10px; }
  .profit-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .profit-sub-tabs { width: 100%; }
}
@media (max-width: 480px) {
  .profit-kpi-row { grid-template-columns: 1fr; }
  .profit-kpi-value { font-size: 22px; }
}
