.profit-page, .profit-results, .profit-cost-form {
  display: grid;
  gap: 16px;
  min-width: 0;
}
.profit-tabs, .profit-materials-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.profit-filters, .profit-amounts {
  display: grid;
  grid-template-columns: minmax(160px,1fr) repeat(2, minmax(140px,180px));
  gap: 12px;
  align-items: end;
  min-width: 0;
}
.profit-filters input, .profit-amounts input { min-width: 0; width: 100%; }
.profit-metrics {
  display: grid;
  grid-template-columns: repeat(4,minmax(0,1fr));
  gap: 12px;
}
.profit-metric {
  min-width: 0;
  padding: 14px;
  display: grid;
  gap: 8px;
}
.profit-metric > span, .profit-assignment-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: .875rem;
}
.profit-metric > span svg { color: var(--accent-strong); }
.profit-metric > strong {
  font-size: clamp(1rem, 2vw, 1.45rem);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.profit-structure { display:flex; justify-content:space-between; align-items:center; gap:12px; flex-wrap:wrap; padding:14px; }
.profit-structure > div { display:grid; gap:4px; font-size:.875rem; }
.profit-breakdown { padding:12px; border:1px solid var(--line); border-radius:var(--radius); background:var(--panel-soft); }
.profit-table td, .profit-table th, .profit-detail td, .profit-detail th { white-space: nowrap; }
.profit-table th:first-child, .profit-detail td:nth-child(2) { white-space: normal; min-width: 150px; }
.profit-table td:nth-child(n+2), .profit-table th:nth-child(n+2), .profit-detail td:nth-child(n+3), .profit-detail th:nth-child(n+3) { text-align: right; }
.profit-table td:not(.profit-empty), .profit-detail td { font-variant-numeric: tabular-nums; }
.profit-table .text-button { color: var(--text); text-align: left; }
.profit-table .profit-empty { text-align: center; color: var(--muted); padding: 22px; }
.profit-table-note { display: block; margin-top: 3px; color: var(--muted); font-size: .75rem; }
.profit-loss { color: var(--red); }
.profit-assignment-badge { color: var(--amber); margin: 0; }
.profit-materials-head h3 { margin-right: auto; }
.profit-material-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) minmax(96px,130px) 42px;
  gap: 8px;
  align-items: end;
  margin-bottom: 8px;
}
.profit-material-row :is(input,select) { min-width: 0; width: 100%; }
.profit-material-row .icon-button { min-height: 42px; }
.specialty-options {
  min-width: 0;
  grid-column: 1/-1;
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 7px 12px;
  padding: 10px 12px 12px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
}
.specialty-options legend { padding: 0 4px; font-size: .875rem; font-weight: 600; }
.specialty-options .specialty-general { grid-column: 1/-1; }
.specialty-options label { line-height: 1.25; }
.specialty-options input { flex: none; }

@media (max-width: 920px) {
  .profit-metrics { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 590px) {
  .profit-filters { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
  .profit-search { grid-column: 1/-1; }
  .profit-metrics { gap: 8px; }
  .profit-metric { padding: 11px; gap: 5px; }
  .profit-metric > span { font-size: .8125rem; }
  .profit-metric > span svg { width: 15px; flex: none; }
  .profit-metric > strong { font-size: 1rem; }
  .profit-amounts { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .profit-material-row { grid-template-columns: minmax(0,1fr) minmax(90px,105px) 39px; }
}
@media (max-width: 365px) {
  .profit-tabs .secondary { font-size: .75rem; padding-inline: 7px; gap: 3px; }
  .specialty-options { grid-template-columns: minmax(0,1fr); }
}

@media (max-width: 590px) {
  .profit-table { overflow: clip; }
  .profit-table .data-table, .profit-table tbody { display: block; }
  .profit-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .profit-table tbody tr {
    display: grid;
    position: relative;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 7px 10px;
    padding: 9px 12px 13px;
    border-bottom: 1px solid var(--line);
  }
  .profit-table tbody tr:last-child { border-bottom: 0; }
  .profit-table tbody th, .profit-table tbody td {
    min-width: 0;
    padding: 2px 0;
    border: 0;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .profit-table tbody th { grid-column: 1/-1; padding-right: 44px; }
  .profit-table tbody td[data-column]::before {
    content: attr(data-column);
    display: block;
    color: var(--muted);
    font-size: .75rem;
    margin-bottom: 2px;
  }
  .profit-table tbody td:last-child:not(.profit-empty) { position: absolute; top: 9px; right: 12px; }
  .profit-table .profit-empty { grid-column: 1/-1; }
}
