@media (max-width: 650px) {
  .main:has(.bill-heading) {
    padding: 14px 12px 102px;
  }

  .main:has(.bill-heading) .topbar {
    display: flex;
    margin-bottom: 16px;
  }

  .main:has(.bill-heading) .topbar-heading > div,
  .main:has(.bill-heading) .top-actions {
    display: none;
  }

  .bill-heading {
    gap: 10px;
    margin-bottom: 12px;
  }

  .bill-heading h2 {
    font-size: 18px;
    line-height: 1.3;
  }

  .bill-heading p {
    line-height: 1.4;
  }

  .bill-calendar {
    padding: 8px 10px;
  }

  .bill-filter-panel {
    padding: 12px;
    margin-bottom: 12px;
  }

  .bill-filters {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .bill-filters select,
  .bill-filters .btn {
    min-width: 0;
    min-height: 40px;
    font-size: 13px;
  }

  .bill-stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    margin-bottom: 12px;
  }

  .bill-stat {
    min-width: 0;
    min-height: 64px;
    padding: 9px;
    overflow-wrap: anywhere;
  }

  .bill-stat span { font-size: 10px; }
  .bill-stat strong { margin-top: 5px; font-size: 12px; }

  .bill-layout,
  .bill-layout > main,
  .bill-table-panel,
  .bill-sidebar {
    min-width: 0;
  }

  .bill-layout { gap: 10px; }
  .bill-table-panel { padding: 12px 9px; }
  .bill-table-panel .panel-head { align-items: flex-start; gap: 8px; }
  .bill-table-panel .panel-head .muted { font-size: 10px; text-align: right; }
  .bill-table-panel .harvest-table-wrap,
  .harvest-workspace .harvest-table-wrap,
  .recent-harvests .harvest-table-wrap {
    max-width: 100%;
    overflow: visible;
  }

  .bill-table-panel .harvest-table,
  .harvest-workspace .harvest-table,
  .recent-harvests .harvest-table {
    display: block;
    width: 100% !important;
    min-width: 0 !important;
    border: 0;
  }

  .bill-table-panel .harvest-table thead,
  .harvest-workspace .harvest-table thead,
  .recent-harvests .harvest-table thead {
    display: none;
  }

  .bill-table-panel .harvest-table tbody,
  .harvest-workspace .harvest-table tbody,
  .recent-harvests .harvest-table tbody {
    display: grid;
    gap: 8px;
  }

  .bill-table-panel .harvest-table tbody tr,
  .harvest-workspace .harvest-table tbody tr,
  .recent-harvests .harvest-table tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 8px;
    min-width: 0;
    padding: 7px;
    border: 1px solid #e4eaf1;
    border-radius: 8px;
    background: #fff;
  }

  .bill-table-panel .harvest-table td,
  .harvest-workspace .harvest-table td,
  .recent-harvests .harvest-table td {
    display: flex;
    min-width: 0;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 2px;
    padding: 5px 4px;
    border: 0;
    font-size: 11px;
    line-height: 1.25;
    overflow-wrap: anywhere;
  }

  .bill-table-panel .harvest-table td::before,
  .harvest-workspace .harvest-table tbody td::before,
  .recent-harvests .harvest-table td::before {
    color: #718096;
    font-size: 9px;
    font-weight: 600;
  }

  .bill-table-panel .bill-table tbody td:nth-child(1)::before { content: "Date"; }
  .bill-table-panel .bill-table tbody td:nth-child(2)::before { content: "Crop"; }
  .bill-table-panel .bill-table tbody td:nth-child(3)::before { content: "Weight"; }
  .bill-table-panel .bill-table tbody td:nth-child(4)::before { content: "Rate"; }
  .bill-table-panel .bill-table tbody td:nth-child(5)::before { content: "Total"; }
  .bill-table-panel .bill-table tbody td:nth-child(6)::before { content: "Status"; }
  .bill-table-panel .bill-table tbody td:nth-child(7)::before { content: "Action"; }
  html[lang="ta"] .bill-table-panel .bill-table tbody td:nth-child(1)::before { content: "\ba4 \bc7 \ba4 \bbf "; }
  html[lang="ta"] .bill-table-panel .bill-table tbody td:nth-child(2)::before { content: "\baa \baf \bbf \bb0 \bcd "; }
  html[lang="ta"] .bill-table-panel .bill-table tbody td:nth-child(3)::before { content: "\b8e \b9f \bc8 "; }
  html[lang="ta"] .bill-table-panel .bill-table tbody td:nth-child(4)::before { content: "\bb5 \bbf \bb2 \bc8 "; }
  html[lang="ta"] .bill-table-panel .bill-table tbody td:nth-child(5)::before { content: "\bae \bca \ba4 \bcd \ba4 \bae \bcd "; }
  html[lang="ta"] .bill-table-panel .bill-table tbody td:nth-child(6)::before { content: "\ba8 \bbf \bb2 \bc8 "; }
  html[lang="ta"] .bill-table-panel .bill-table tbody td:nth-child(7)::before { content: "\b9a \bc6 \baf \bb2 \bcd "; }

  .bill-table-panel .bill-table tbody td:first-child {
    grid-column: 1 / -1;
    border-bottom: 1px solid #edf1f5;
    font-weight: 600;
  }

  .bill-table-panel .bill-table tbody td:nth-child(7) {
    align-items: flex-end;
  }

  .bill-table-panel .bill-table tbody td:nth-child(7) .tiny {
    min-width: 58px;
    min-height: 30px;
  }

  .bill-table-panel .monthly-bill-table tbody td:nth-child(1)::before { content: "Day"; }
  .bill-table-panel .monthly-bill-table tbody td:nth-child(2)::before { content: "Date"; }
  .bill-table-panel .monthly-bill-table tbody td:nth-child(3)::before { content: "Weight"; }
  .bill-table-panel .monthly-bill-table tbody td:nth-child(4)::before { content: "Rate"; }
  .bill-table-panel .monthly-bill-table tbody td:nth-child(5)::before { content: "Total"; }
  .bill-table-panel .inline-bill-table tbody td:nth-child(1)::before { content: "Date"; }
  .bill-table-panel .inline-bill-table tbody td:nth-child(2)::before { content: "Weight"; }
  .bill-table-panel .inline-bill-table tbody td:nth-child(3)::before { content: "Rate"; }
  .bill-table-panel .inline-bill-table tbody td:nth-child(4)::before { content: "Amount"; }
  .bill-table-panel .inline-bill-table tbody td:nth-child(5)::before { content: "Status"; }
  .bill-table-panel .inline-bill-table tbody td:nth-child(6)::before { content: "Actions"; }
  html[lang="ta"] .bill-table-panel .monthly-bill-table tbody td:nth-child(1)::before { content: "\ba8 \bbe \bb3 \bcd "; }
  html[lang="ta"] .bill-table-panel .monthly-bill-table tbody td:nth-child(2)::before { content: "\ba4 \bc7 \ba4 \bbf "; }
  html[lang="ta"] .bill-table-panel .monthly-bill-table tbody td:nth-child(3)::before { content: "\b8e \b9f \bc8 "; }
  html[lang="ta"] .bill-table-panel .monthly-bill-table tbody td:nth-child(4)::before { content: "\bb5 \bbf \bb2 \bc8 "; }
  html[lang="ta"] .bill-table-panel .monthly-bill-table tbody td:nth-child(5)::before { content: "\bae \bca \ba4 \bcd \ba4 \bae \bcd "; }
  html[lang="ta"] .bill-table-panel .inline-bill-table tbody td:nth-child(1)::before { content: "\ba4 \bc7 \ba4 \bbf "; }
  html[lang="ta"] .bill-table-panel .inline-bill-table tbody td:nth-child(2)::before { content: "\b8e \b9f \bc8 "; }
  html[lang="ta"] .bill-table-panel .inline-bill-table tbody td:nth-child(3)::before { content: "\bb5 \bbf \bb2 \bc8 "; }
  html[lang="ta"] .bill-table-panel .inline-bill-table tbody td:nth-child(4)::before { content: "\ba4 \bca \ba95 \bc8 "; }
  html[lang="ta"] .bill-table-panel .inline-bill-table tbody td:nth-child(5)::before { content: "\ba8 \bbf \bb2 \bc8 "; }
  html[lang="ta"] .bill-table-panel .inline-bill-table tbody td:nth-child(6)::before { content: "\b9a \bc6 \baf \bb2 \bcd \b95 \bb3 \bcd "; }
  .bill-table-panel .monthly-bill-table tbody td:first-child { grid-column: auto; }
  .bill-table-panel .monthly-bill-table tbody td:nth-child(2) { grid-column: 1 / -1; }
  .bill-table-panel .inline-bill-table tbody td:first-child { grid-column: 1 / -1; }

  .bill-table-panel .monthly-bill-table input {
    min-width: 0;
    min-height: 34px;
    padding: 5px 7px;
    font-size: 12px;
  }

  .bill-table-panel .monthly-bill-table tfoot {
    display: block;
    margin-top: 8px;
  }

  .bill-table-panel .monthly-bill-table tfoot tr {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 9px;
    border-radius: 7px;
    background: #eaf2ff;
  }

  .bill-table-panel .monthly-bill-table tfoot th {
    display: block;
    padding: 2px;
    border: 0;
    font-size: 11px;
  }

  .bill-sidebar { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .bill-sidebar .panel { padding: 13px; }

  .harvest-workspace { padding: 12px 10px; }
  .harvest-workspace .panel-head { align-items: stretch; flex-direction: column; gap: 8px; }
  .harvest-workspace .panel-head .btn { width: 100%; min-height: 38px; }
  .harvest-workspace .harvest-table tbody tr { gap: 1px 8px; }
  .harvest-workspace .harvest-table tbody td:nth-child(1) { display: none; }
  .harvest-workspace .harvest-table tbody td:nth-child(2)::before { content: "Date"; }
  .harvest-workspace .harvest-table tbody td:nth-child(3)::before { content: "Weight (kg)"; }
  .harvest-workspace .harvest-table tbody td:nth-child(4)::before { content: "Rate"; }
  .harvest-workspace .harvest-table tbody td:nth-child(5)::before { content: "Total"; }
  html[lang="ta"] .harvest-workspace .harvest-table tbody td:nth-child(2)::before { content: "\ba4 \bc7 \ba4 \bbf "; }
  html[lang="ta"] .harvest-workspace .harvest-table tbody td:nth-child(3)::before { content: "\b8e \b9f \bc8  (kg)"; }
  html[lang="ta"] .harvest-workspace .harvest-table tbody td:nth-child(4)::before { content: "\bb5 \bbf \bb2 \bc8 "; }
  html[lang="ta"] .harvest-workspace .harvest-table tbody td:nth-child(5)::before { content: "\bae \bca \ba4 \bcd \ba4 \bae \bcd "; }
  .harvest-workspace .harvest-table tbody td:nth-child(6) {
    grid-column: 1 / -1;
    align-items: flex-end;
    padding-top: 0;
  }

  .harvest-workspace .harvest-table input {
    min-width: 0;
    min-height: 34px;
    padding: 5px 7px;
    font-size: 12px;
  }

  .harvest-workspace .harvest-table tfoot {
    display: block;
    margin-top: 8px;
  }

  .harvest-workspace .harvest-table tfoot tr {
    display: flex;
    justify-content: space-between;
    gap: 5px;
    padding: 8px;
    border-radius: 7px;
    background: #f3f6fa;
  }

  .harvest-workspace .harvest-table tfoot td {
    display: block;
    padding: 2px;
    font-size: 10px;
    white-space: nowrap;
  }

  .harvest-workspace .form-actions { flex-wrap: wrap; gap: 8px; }
  .harvest-workspace .form-actions > * { flex: 1 1 100%; min-height: 40px; text-align: center; }
  .recent-harvests .history-table tbody td:nth-child(1)::before { content: "Date"; }
  .recent-harvests .history-table tbody td:nth-child(2)::before { content: "Weight"; }
  .recent-harvests .history-table tbody td:nth-child(3)::before { content: "Rate"; }
  .recent-harvests .history-table tbody td:nth-child(4)::before { content: "Total"; }
  html[lang="ta"] .recent-harvests .history-table tbody td:nth-child(1)::before { content: "\ba4 \bc7 \ba4 \bbf "; }
  html[lang="ta"] .recent-harvests .history-table tbody td:nth-child(2)::before { content: "\b8e \b9f \bc8 "; }
  html[lang="ta"] .recent-harvests .history-table tbody td:nth-child(3)::before { content: "\bb5 \bbf \bb2 \bc8 "; }
  html[lang="ta"] .recent-harvests .history-table tbody td:nth-child(4)::before { content: "\bae \bca \ba4 \bcd \ba4 \bae \bcd "; }

  .inline-bill-table tbody td:nth-child(1)::before { content: "Date"; }
  .inline-bill-table tbody td:nth-child(2)::before { content: "Weight"; }
  .inline-bill-table tbody td:nth-child(3)::before { content: "Rate"; }
  .inline-bill-table tbody td:nth-child(4)::before { content: "Total"; }
  .inline-bill-table tbody td:nth-child(5)::before { content: "Status"; }
  .inline-bill-table tbody td:nth-child(6)::before { content: "Actions"; }

  .inline-bill-table tbody td:nth-child(1) { grid-column: 1 / -1; }
  .inline-bill-table tbody td:nth-child(6) {
    grid-column: 1 / -1;
    align-items: flex-end;
  }

  .inline-bill-table input,
  .inline-bill-table select {
    min-width: 0;
    min-height: 34px;
    font-size: 12px;
  }

  .inline-bill-controls { grid-template-columns: minmax(0, 1fr); }
  .inline-bill-controls .btn,
  .bill-save-actions .btn { width: 100%; min-height: 40px; }
  .bill-save-actions { padding-right: 0; padding-left: 0; }
}

/* Keep the bill-entry grid as a four-column table on phones. */
@media(max-width:650px){.bill-table-panel .harvest-table-wrap:has(.bill-entry-row){overflow-x:hidden}.bill-table-panel .inline-bill-table:has(.bill-entry-row){display:table!important;table-layout:fixed;width:100%!important;min-width:0!important;border-collapse:separate;border-spacing:0}.bill-table-panel .inline-bill-table:has(.bill-entry-row) thead{display:table-header-group!important}.bill-table-panel .inline-bill-table:has(.bill-entry-row) tbody{display:table-row-group!important}.bill-table-panel .inline-bill-table:has(.bill-entry-row) thead tr,.bill-table-panel .inline-bill-table:has(.bill-entry-row) tbody tr.bill-entry-row{display:table-row!important;padding:0;border:0;border-radius:0;background:#fff}.bill-table-panel .inline-bill-table:has(.bill-entry-row) th,.bill-table-panel .inline-bill-table:has(.bill-entry-row) td{display:table-cell!important;width:25%;min-width:0;padding:7px 3px!important;text-align:center;vertical-align:middle;font-size:10px;line-height:1.2;overflow-wrap:anywhere}.bill-table-panel .inline-bill-table:has(.bill-entry-row) th{background:#f3f6fa;color:#50637b;font-size:9px}.bill-table-panel .inline-bill-table:has(.bill-entry-row) td::before{content:none!important;display:none!important}.bill-table-panel .inline-bill-table:has(.bill-entry-row) td:first-child{font-size:9px;font-weight:600;border-bottom:1px solid #edf1f5}.bill-table-panel .inline-bill-table:has(.bill-entry-row) input{display:block;width:100%;min-width:0;min-height:34px;padding:4px 2px;font-size:11px;text-align:center}.bill-table-panel .inline-bill-table:has(.bill-entry-row) tfoot{display:table-footer-group!important}.bill-table-panel .inline-bill-table:has(.bill-entry-row) tfoot tr{display:table-row!important;padding:0;border-radius:0;background:#eaf2ff}.bill-table-panel .inline-bill-table:has(.bill-entry-row) tfoot th{display:table-cell!important;padding:9px 4px!important;font-size:11px}.bill-table-panel .inline-bill-table:has(.bill-entry-row) tfoot th[colspan="3"]{text-align:right}}
