/* Financial lists: use the available width on small laptops and landscape tablets. */
@media (min-width: 701px) and (max-width: 1300px) {
  .process-table tr,
  .payment-table tr {
    grid-template-columns: minmax(0, 2fr) minmax(90px, 1fr) minmax(95px, 1fr);
  }

  .process-table td:nth-child(2),
  .payment-table td:nth-child(2) { grid-column: 1; }
  .process-table td:nth-child(3),
  .payment-table td:nth-child(3) { grid-column: 2; }
  .process-table td:nth-child(4),
  .payment-table td:nth-child(4) { grid-column: 3; }

  .process-table td:nth-child(5) { grid-column: 1; }
  .process-table td:nth-child(6) { grid-column: 2 / 4; }
  .payment-table td:nth-child(5) { grid-column: 1 / -1; }
}

/* Each work row uses the same tracks, including when the state label changes. */
.work-list { --work-actions-width: 208px; border-inline-start-width: 2px; }
.work-row .quick {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px 36px;
  align-items: center;
  width: var(--work-actions-width);
  max-width: 100%;
}
.work-row .quick .work-state-control { justify-self: start; max-width: 100%; overflow: hidden; }
.work-row .quick .button.small { width: 100%; min-height: 28px; }

@media (min-width: 1251px) {
  .work-row { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr) 124px var(--work-actions-width); }
  .work-row .due-button { justify-self: start; }
}

.work-due-label{white-space:normal}
.work-due-label.late{color:#a53239;font-weight:650}

@media (min-width: 851px) and (max-width: 1250px) {
  .work-row { grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px; padding: 9px 12px; }
  .work-main { grid-column: 1 / -1; grid-row: 1; }
  .work-client { grid-column: 1; grid-row: 2; }
  .work-row .work-meta { display: flex; grid-column: 1; grid-row: 3; align-items: center; gap: 8px; min-width: 0; }
  .work-row .owner-button { display: block; min-width: 0; overflow-wrap: anywhere; white-space: normal; text-align: left; }
  .work-row .due-button { flex: none; }
  .work-row .quick { grid-column: 2; grid-row: 2 / 4; align-self: center; margin: 0; }
}
@media (max-width: 850px) {
  .work-row .quick .work-state-control,
  .work-row .quick .button.small { min-height: 36px; }
}

/* Keep parcel actions readable at the narrowest supported phone width. */
@media (max-width: 700px) {
  .payment-part-wrap { max-width: 100%; min-width: 0; }
  .payment-part-wrap .payment-part { min-width: 0; }
  .payment-part-edit { flex: 0 0 auto; white-space: nowrap; }
}

/* The row opens a detail page where the complete title remains visible. */
@media (max-width: 850px) {
  .work-expand {
    min-height: 36px;
    margin-top: 0;
    padding: 6px 8px 6px 0;
  }

  .work-title strong {
    display: block;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    overflow-wrap: normal;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Give the four work-detail actions usable tap targets without clipping labels at 320px. */
@media (max-width: 430px) {
  #page:has(.work-detail-layout) .page-heading .actions .button { min-height: 44px; }
  #page:has(.work-detail-layout) .page-heading .actions .button:not(.action-icon) {
    white-space: normal;
    line-height: 1.1;
  }
  #page:has(.work-detail-layout) .page-heading .actions .action-icon {
    flex: 0 0 44px;
    min-width: 44px;
    min-height: 44px;
  }
}

/* Status control and amount matching */
.work-state-control{min-height:28px;padding:4px 10px;border:0;cursor:pointer;white-space:nowrap;font-weight:750}
.work-state-control:hover{text-decoration:underline;text-underline-offset:3px}
.work-state-control:focus-visible,.cash-toggle button:focus-visible,.amount-controls input:focus-visible{outline:2px solid #1e6598;outline-offset:3px}
.fact .badge.work-state-control{box-shadow:none}
.work-state-dialog{display:grid;gap:12px}
.work-state-dialog p{margin:0}
.work-state-dialog [data-current-work-status]{min-height:25px}
.work-state-dialog .field-help{color:#53616d}
.work-fire{display:inline-block;margin-inline-start:.35em;font-size:.9em;line-height:1;vertical-align:baseline}
.badge.plum,.fact .badge.plum{background:#f4e8f3;color:#734573}
.group.state-plum .work-list{border-inline-start-color:#ba90bb}
.group.state-plum .group-title .badge{white-space:normal}
.fact.state-plum{--fact-accent:#ba90bb}
.work-state-review{display:grid;gap:1px;text-align:start;line-height:1.22}
.work-state-review small,.fact .work-state-review small{color:inherit;font-size:9px;font-weight:650;line-height:inherit}
.finance-record:focus{outline:2px solid #4d89b1;outline-offset:4px;background:#f1f8fc}
.finance-record b small,.payment-installment-meta small{display:block;font-size:.82em;color:#51616d;font-weight:500}
.payment-installment-meta b>.amount-label{display:block}
.amount-controls{display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:12px;padding:12px;margin-bottom:8px}
.amount-controls .search{flex:1;min-width:min(100%,290px)}
.amount-controls .chips{margin:0;flex-wrap:wrap;gap:5px;overflow:visible}
.amount-controls .chip{min-height:35px}
.amount-results{width:100%;table-layout:auto;min-width:0}
.amount-results td{vertical-align:top}
.amount-results td:nth-child(3),.amount-results td:nth-child(4){font-variant-numeric:tabular-nums;white-space:nowrap}
.amount-results td:last-child a{display:block}
.amount-match{background:#ffecaa;color:#463500;border-radius:5px;padding:.16em .32em;font-weight:800}
.reference-match{background:#dbede9;color:#1a5148;border-radius:4px;padding:.12em .25em;font-weight:750}
.financial-source-notice{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:11px 14px;margin:0 0 12px;border:1px solid #d3e2ed;border-radius:9px;background:#f1f8fc;color:#334e61;font-size:12px}
.cash-summary{display:grid;gap:9px;margin:0 0 16px}
.cash-summary>.cash-toggle{width:max-content;max-width:100%}
.cash-summary .cash-hero{min-width:0;display:grid;grid-template-columns:minmax(0,1.15fr) minmax(0,1fr);gap:16px 28px;align-items:center;margin:0;padding:20px 24px}
.cash-summary .cash-realized{background:linear-gradient(125deg,#0b3938,#145a54 76%,#26685a);border-color:#174f49;color:#fff}
.cash-summary .cash-forecast{background:linear-gradient(125deg,#edf4ff,#f3f2fb 63%,#fcf6ee);border-color:#d8e1f0;color:#243957}
.cash-summary .cash-realized small{color:#c2e5dc}
.cash-summary .cash-forecast small{color:#495d79}
.cash-summary .cash-hero strong{font-size:clamp(1.85rem,3.6vw,2.8rem);overflow-wrap:anywhere}
.cash-summary .cash-hero-split{margin:0;padding:0;border:0;background:none;justify-content:space-between;flex-wrap:wrap;gap:12px}
.cash-summary .cash-hero-split b{font-variant-numeric:tabular-nums}
.cash-toggle{display:flex;gap:3px;background:#e9eff3;border-radius:10px;padding:3px}
.cash-toggle button{color:#385267;background:transparent;border:1px solid transparent;border-radius:8px;min-height:34px;padding:6px 13px;font-weight:700;cursor:pointer}
.cash-toggle button[aria-pressed=true]{background:#fff;color:#124e52;border-color:#cfdee4}
.cash-chart-panel .cash-legend{color:#455c66;flex-wrap:wrap}
.cash-chart-panel .cash-month-label small{color:#47616b}
.cash-chart-panel .cash-in{background:linear-gradient(to top,#168575,#48ac98)}
.cash-chart-panel .cash-out{background:linear-gradient(to top,#c67543,#efae83)}
.cash-chart-panel .cash-key.in{background:#168575}.cash-chart-panel .cash-key.out{background:#c67543}
.cash-chart-panel .cash-bar{transform-origin:bottom}
.cash-month-summary{display:flex;flex-wrap:wrap;gap:6px 18px;margin:12px 0 0;padding:9px 11px;color:#3e5760;background:#f0f6f6;border-radius:8px;font-size:12px;font-variant-numeric:tabular-nums}
.cash-month-summary strong{text-transform:capitalize;color:#234951}
.cash-plot.has-negative .cash-plot-refunds{top:160px;height:80px}
.cash-plot-refunds .cash-bar-column{align-items:flex-start}
.cash-plot-refunds .cash-bar{border-radius:0 0 5px 5px;transform-origin:top}
.finance-method{margin:12px 0;color:#536572;font-size:12px;line-height:1.5}
.finance-disclosure{margin-top:12px;color:#536572;font-size:12px}
.finance-disclosure summary{width:fit-content;cursor:pointer;color:#385665;font-weight:700}
.finance-checks{margin-top:14px}
.cash-quality{margin:10px 0}
.cash-quality p{margin:0 0 5px}
.cash-quality ul{padding-left:20px}
.margin-panel{border-color:#d7e6df}
.margin-period{padding:15px;border:1px solid #d6e6df;background:linear-gradient(145deg,#edf7f3,#fff 70%);border-radius:12px;min-width:0}
.margin-overview{display:flex;align-items:baseline;flex-wrap:wrap;gap:4px 12px}
.margin-overview>span{color:#21594e;font-weight:750;text-transform:capitalize}
.margin-overview>strong{font-size:19px;font-variant-numeric:tabular-nums}
.margin-overview small,.margin-period li small{color:#52686b;font-size:11px}
.margin-period ol{list-style:none;margin:10px 0 0;padding:0}
.margin-period li{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:8px;align-items:start;border-top:1px solid #dfe9e4;padding:8px 0;font-size:12px;overflow-wrap:anywhere}
.margin-period li small{display:block;margin-top:3px}
.margin-period li a{color:#205e68;font-weight:700}
.margin-period li strong{font-variant-numeric:tabular-nums}
@media(prefers-reduced-motion:no-preference){
  @keyframes pipeline-cash-rise{from{transform:scaleY(.72);opacity:.65}to{transform:scaleY(1);opacity:1}}
  .cash-chart-panel .cash-bar{animation:pipeline-cash-rise 280ms ease-out both}
}
@media(max-width:900px){
  .cash-summary .cash-hero{padding:18px}
}
@media(max-width:700px){
  .amount-results td:last-child{grid-column:1/-1}
  .amount-controls .chips{width:100%}
  .amount-controls .chip{min-height:36px}
  .cash-summary{gap:9px}
}
@media(max-width:500px){
  .topbar .top-brand{display:none}
  .cash-summary .cash-hero{grid-template-columns:1fr;gap:12px}
  .work-row .quick{grid-column:1/-1;grid-row:4;flex-wrap:wrap;justify-self:start}
  .work-row .work-meta{grid-column:1/-1}
  .financial-source-notice{align-items:start;flex-wrap:wrap}
}
