/**
 * High 5 Connect CRM — V2 Financials + Insurance + Warranty Styles
 */

/* ─── Financials ──────────────────────────────────────────── */
.financials-section {
  padding: var(--s2) 0;
}

.financials-section h4 {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--s4);
}

.fin-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s3);
  margin-bottom: var(--s4);
}

.fin-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s3);
  text-align: center;
}

.fin-card-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: var(--tracking-wide);
  color: var(--text-label);
  display: block;
  margin-bottom: var(--s1);
}

.fin-card-value {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
}

.fin-card-revenue { border-left: 3px solid var(--accent); }
.fin-card-expenses { border-left: 3px solid var(--amber); }
.fin-card-profit { border-left: 3px solid var(--green); }
.fin-card-loss { border-left: 3px solid var(--red); }

.fin-breakdown {
  margin-bottom: var(--s3);
  padding: var(--s4);
}

.fin-breakdown-title {
  font-size: var(--text-sm);
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-label);
  margin-bottom: var(--s3);
}

.fin-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--s2) 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.fin-row:last-child {
  border-bottom: none;
}

.fin-row-total {
  font-weight: 700;
  color: var(--text-primary);
  border-top: 2px solid var(--border);
  margin-top: var(--s1);
  padding-top: var(--s3);
}

.fin-positive { color: var(--green); font-weight: 600; }
.fin-negative { color: var(--red); font-weight: 600; }

/* ─── Inline Editable Fields ─────────────────────────────── */
.fin-row-editable { background: var(--bg-page); border-radius: var(--r-sm); padding: var(--s2) var(--s3); margin: 2px 0; }
.fin-inline-edit { display: flex; align-items: center; gap: 4px; }
.fin-inline-input { width: 90px; text-align: right; font-weight: 600; padding: 2px 6px; }
.fin-pct-input { width: 60px; }
.fin-dollar-sign { color: var(--text-label); font-size: var(--text-sm); font-weight: 600; }
.fin-pct-sign { color: var(--text-label); font-size: var(--text-sm); font-weight: 600; }
.fin-calc-result { color: var(--text-secondary); font-size: var(--text-sm); margin-left: 6px; white-space: nowrap; }

.fin-breakdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s3);
}

.fin-breakdown-header .fin-breakdown-title {
  margin-bottom: 0;
}

.fin-row-custom {
  background: var(--bg-page);
  border-radius: var(--r-sm);
  padding: var(--s2) var(--s3);
  margin: var(--s1) 0;
}

.fin-remove-expense {
  border: none;
  background: transparent;
  color: var(--text-label);
  cursor: pointer;
  font-size: var(--text-lg);
  padding: 0 0 0 var(--s2);
  transition: color var(--t-fast);
}

.fin-remove-expense:hover {
  color: var(--red);
}

.fin-progress {
  height: 8px;
  background: var(--bg-input);
  border-radius: var(--r-full);
  overflow: hidden;
  margin-top: var(--s3);
}

.fin-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: var(--r-full);
  transition: width var(--t-normal);
}

.fin-progress-label {
  font-size: var(--text-xs);
  color: var(--text-label);
  margin-top: var(--s1);
  display: block;
}

/* ─── Insurance ──────────────────────────────────────────── */
.insurance-section {
  padding: var(--s2) 0;
}

.insurance-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s4);
}

.insurance-header h4 {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
}

.insurance-status {
  margin-bottom: var(--s3);
}

.insurance-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s3);
}

.insurance-card {
  padding: var(--s4);
}

.insurance-card h5 {
  font-size: var(--text-sm);
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-label);
  margin-bottom: var(--s3);
}

.insurance-row {
  display: flex;
  justify-content: space-between;
  padding: var(--s2) 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
}

.insurance-row:last-child {
  border-bottom: none;
}

.insurance-label {
  color: var(--text-label);
}

.insurance-value {
  color: var(--text-primary);
  font-weight: 600;
}

.insurance-row-total {
  border-top: 2px solid var(--border);
  margin-top: var(--s1);
  padding-top: var(--s3);
  font-weight: 700;
}

.insurance-notes {
  padding: var(--s4);
  margin-top: var(--s3);
}

.insurance-notes h5 {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-label);
  margin-bottom: var(--s2);
}

/* ─── Warranty ───────────────────────────────────────────── */
.warranty-section {
  padding: var(--s2) 0;
}

.warranty-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s4);
}

.warranty-header h4 {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
}

.warranty-card {
  margin-bottom: var(--s3);
  padding: var(--s4);
}

.warranty-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s3);
}

.warranty-days {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-left: var(--s2);
}

.warranty-expired {
  color: var(--red);
  font-weight: 700;
}

.warranty-card-body {
  margin-bottom: var(--s2);
}

.warranty-row {
  display: flex;
  justify-content: space-between;
  padding: var(--s2) 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
}

.warranty-row:last-child {
  border-bottom: none;
}

.warranty-label {
  color: var(--text-label);
}

.warranty-value {
  color: var(--text-primary);
  font-weight: 600;
}

.warranty-terms {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  padding-top: var(--s2);
  border-top: 1px solid var(--border);
  white-space: pre-wrap;
}

/* ─── Responsive ──────────────────────────────────────────── */
@media (min-width: 641px) {
  .fin-summary {
    grid-template-columns: repeat(4, 1fr);
  }

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

  .insurance-grid > :last-child {
    grid-column: span 2;
  }
}

@media (min-width: 1025px) {
  .insurance-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .insurance-grid > :last-child {
    grid-column: auto;
  }
}

/* ═══════════════════════════════════════════════════════════════
   PROFIT TRACKER — Standalone page
   ═══════════════════════════════════════════════════════════════ */

.profit-tracker-page {
  padding: var(--s4);
  max-width: 960px;
  margin: 0 auto;
}

.profit-header {
  margin-bottom: var(--s4);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s3);
}

.profit-header h3 {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
}

.profit-date-filter {
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.profit-date-filter .input {
  max-width: 150px;
}

.profit-collections {
  margin-bottom: var(--s5);
  padding: var(--s4);
}

.profit-collections-grid {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
}

.profit-lost-section {
  margin-bottom: var(--s5);
  padding: var(--s4);
}

.profit-bar-profit {
  font-size: var(--text-xs);
  font-weight: 600;
  text-align: center;
  margin-bottom: 2px;
}

.profit-bar-count {
  text-align: center;
}

.profit-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s3);
  margin-bottom: var(--s5);
}

@media (min-width: 768px) {
  .profit-summary {
    grid-template-columns: repeat(4, 1fr);
  }
}

.profit-chart-section,
.profit-budget-section,
.profit-table-section {
  margin-bottom: var(--s5);
  padding: var(--s4);
}

/* ─── Monthly Bar Chart ──────────────────────────────────── */
.profit-bars {
  display: flex;
  align-items: flex-end;
  gap: var(--s3);
  height: 200px;
  padding: var(--s3) 0;
}

.profit-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
}

.profit-bar-value {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--s1);
  white-space: nowrap;
}

.profit-bar-wrapper {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
}

.profit-bar {
  width: 100%;
  background: linear-gradient(180deg, var(--accent), rgba(6, 139, 195, 0.5));
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  min-height: 4px;
  transition: height 300ms ease;
}

.profit-bar-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-label);
  margin-top: var(--s1);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* ─── Budget vs Actual ───────────────────────────────────── */
.budget-comparison {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

.budget-row {
  display: grid;
  grid-template-columns: 80px 1fr 120px;
  gap: var(--s3);
  align-items: center;
}

.budget-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
}

.budget-bar-track {
  height: 12px;
  background: var(--bg-input);
  border-radius: var(--r-full);
  overflow: hidden;
}

.budget-bar-fill {
  height: 100%;
  border-radius: var(--r-full);
  transition: width 400ms ease;
}

.budget-actual { background: var(--accent); }
.budget-expense { background: var(--amber); }
.budget-profit { background: var(--green); }
.budget-loss { background: var(--red); }

.budget-values {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  text-align: right;
}

/* ─── Data Table ─────────────────────────────────────────── */
.data-table-wrap {
  overflow-x: auto;
}

.sortable {
  cursor: pointer;
  user-select: none;
}

.sortable:hover {
  color: var(--accent);
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (min-width: 641px) {
  .profit-summary {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 640px) {
  .profit-tracker-page {
    padding: var(--s3);
  }

  .profit-bars {
    height: 140px;
  }

  .budget-row {
    grid-template-columns: 60px 1fr 80px;
  }
}

/* ─── Profit Tracker Expanded Section ────────────────────── */
.stat-card-active {
  outline: 2px solid var(--teal, #14b8a6);
  outline-offset: -2px;
}

.profit-expanded-section {
  background: var(--bg-secondary, #f8fafc);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 8px);
  padding: var(--s3);
  margin-bottom: var(--s4);
}

.profit-expanded-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--s3);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

/* ─── Expandable Cost Breakdown Rows ─────────────────────── */
.expense-cat-wrapper {
  margin-bottom: 2px;
}

.expense-cat-clickable {
  transition: background 0.15s, border-color 0.15s;
  border-radius: var(--r-sm);
  padding: var(--s2) var(--s1);
  margin: 0 calc(-1 * var(--s1));
}

.expense-cat-clickable:hover {
  background: var(--bg-hover, rgba(0,0,0,0.03));
}

.expense-cat-active {
  background: var(--bg-hover, rgba(0,0,0,0.03));
}

.expense-cat-chevron {
  display: inline-block;
  font-size: 10px;
  margin-right: var(--s1);
  transition: transform 0.2s ease;
  color: var(--text-label);
}

.expense-cat-chevron.chevron-open {
  transform: rotate(90deg);
}

.expense-cat-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-input, #e2e8f0);
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: var(--r-full, 9999px);
  padding: 0 5px;
  margin-left: var(--s1);
}

/* ─── Expandable Card Container (animate expand/collapse) ── */
.profit-expandable-cards {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.35s ease, opacity 0.25s ease;
}

.profit-expandable-cards.expanded {
  max-height: 2000px;
  opacity: 1;
}

/* Cost breakdown expanded cards need instant expand since they
   are rendered already in expanded state */
.profit-cost-cards {
  padding: var(--s2) 0 var(--s1) var(--s4);
  border-left: 2px solid var(--border);
  margin-left: var(--s2);
}

/* ─── Job Card (updated layout with stage badge) ─────────── */
.profit-job-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  border-radius: var(--radius, 6px);
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--border);
}

.profit-job-card:last-child {
  border-bottom: none;
}

.profit-job-card:hover {
  background: var(--bg-hover, rgba(0,0,0,0.04));
}

.profit-job-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--s3);
}

.profit-job-name {
  font-weight: 600;
  color: var(--text-primary);
  min-width: 100px;
  white-space: nowrap;
}

.profit-job-title {
  flex: 1;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profit-job-meta {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-shrink: 0;
}

.profit-job-amount {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text-primary);
  white-space: nowrap;
}

/* ─── Stage Badge ────────────────────────────────────────── */
.profit-stage-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #fff;
  padding: 2px 8px;
  border-radius: var(--r-full, 9999px);
  white-space: nowrap;
  line-height: 1.4;
}

/* ─── Responsive: stack job card on mobile ────────────────── */
@media (max-width: 640px) {
  .profit-job-card {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--s1);
  }

  .profit-job-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .profit-job-meta {
    width: 100%;
    justify-content: space-between;
  }

  .profit-cost-cards {
    margin-left: var(--s1);
    padding-left: var(--s2);
  }
}
