.reports-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.reports-heading h1,
.reports-heading p {
  margin: 0;
}

.reports-heading h1 {
  margin-top: 4px;
  font-size: 30px;
  letter-spacing: -.6px;
}

.reports-kicker {
  color: var(--brand);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 1.3px;
}

.reports-heading p {
  margin-top: 6px;
  color: var(--muted);
}

.report-filter {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 16px;
}

.report-filter p {
  margin: 0;
}

.report-filter input {
  min-width: 145px;
  padding: 9px 11px;
}

.report-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.report-tab {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  box-shadow: 0 5px 18px rgba(16, 69, 43, .05);
  cursor: pointer;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.report-tab:hover {
  transform: translateY(-1px);
  border-color: #afd3bf;
}

.report-tab.active {
  border-color: var(--brand);
  background: linear-gradient(135deg, #f4fbf7, #fff);
  box-shadow: 0 8px 22px rgba(16, 105, 62, .12), inset 0 0 0 1px var(--brand);
}

.report-tab-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: #e9f5ee;
  color: var(--brand);
  font-size: 18px;
  font-weight: 900;
}

.report-tab > span:not(.report-tab-icon) {
  display: block;
}

.report-tab b,
.report-tab small {
  display: block;
}

.report-tab b {
  font-size: 13px;
}

.report-tab small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
}

.report-tab strong {
  color: var(--brand);
  font-size: 16px;
  font-weight: 850;
}

.report-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.report-summary .card {
  margin: 0;
  padding: 17px;
}

.report-summary small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.report-summary b {
  display: block;
  margin-top: 7px;
  color: var(--brand-dark);
  font-size: 23px;
}

.page-reports .report-section {
  display: none;
  scroll-margin-top: 20px;
}

.page-reports .report-section.active {
  display: block;
}

.report-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 15px;
}

.report-section-head h2,
.report-section-head p {
  margin: 0;
}

.report-section-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.report-table-wrap {
  overflow-x: auto;
}

.report-customer {
  min-width: 165px;
}

.report-customer b,
.report-customer small {
  display: block;
}

.report-customer small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.balance-positive {
  color: #a53b32;
  font-weight: 800;
}

.balance-clear {
  color: var(--brand);
  font-weight: 800;
}

.report-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.report-actions .btn {
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 10px;
  box-shadow: none;
}

.whatsapp-btn {
  background: linear-gradient(135deg, #22a767, #138b51) !important;
}

.report-empty {
  padding: 30px !important;
  color: var(--muted);
  text-align: center;
}

.ledger-launch {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: end;
  gap: 12px;
}

.ledger-launch p {
  margin: 0;
}

.report-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 800;
}

.report-status.ready {
  background: #e5f6ed;
  color: #147346;
}

.report-status.missing {
  background: #fff0e7;
  color: #a14d1f;
}

.whatsapp-template {
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid #dce9e1;
  border-radius: 12px;
  background: linear-gradient(135deg, #f8fcfa, #f1f8f4);
}

.whatsapp-template-editor {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(240px, .65fr);
  gap: 16px;
  margin-bottom: 12px;
}

.whatsapp-template-editor p {
  margin: 0;
}

.whatsapp-template textarea {
  min-height: 105px;
  background: #fff;
}

.whatsapp-template small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.whatsapp-preview {
  min-height: 105px;
  padding: 13px 14px;
  border: 1px solid #cfe4d8;
  border-radius: 11px 11px 11px 3px;
  background: #e7f7ed;
  color: #173d29;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  box-shadow: 0 5px 16px rgba(19, 111, 65, .07);
}

@media (max-width: 900px) {
  .reports-heading {
    display: block;
  }

  .report-filter {
    margin-top: 14px;
    flex-wrap: wrap;
  }

  .report-tabs,
  .report-summary {
    grid-template-columns: 1fr 1fr;
  }

  .ledger-launch {
    grid-template-columns: 1fr;
  }

  .whatsapp-template-editor {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .page-reports .wrap {
    padding-left: 10px;
    padding-right: 10px;
  }

  .reports-heading {
    margin-bottom: 14px;
  }

  .reports-heading h1 {
    font-size: 27px;
  }

  .reports-heading p {
    font-size: 11px;
    line-height: 1.45;
  }

  .report-filter {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
    padding: 11px;
  }

  .report-filter p {
    min-width: 0;
  }

  .report-filter input {
    min-width: 0;
    height: 38px;
    padding: 8px 9px;
    font-size: 12px;
  }

  .report-filter button {
    min-height: 38px;
    padding: 8px 10px;
    font-size: 11px;
  }

  .report-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    margin: 0 -2px 12px;
    padding: 2px 2px 5px;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .report-tabs::-webkit-scrollbar {
    display: none;
  }

  .report-tab {
    flex: 0 0 225px;
    grid-template-columns: 30px minmax(0, 1fr) auto;
    gap: 8px;
    min-height: 62px;
    padding: 10px 11px;
    border-radius: 12px;
    scroll-snap-align: start;
  }

  .report-tab-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    font-size: 14px;
  }

  .report-tab b {
    font-size: 11px;
  }

  .report-tab small {
    margin-top: 2px;
    font-size: 8px;
  }

  .report-tab strong {
    font-size: 12px;
  }

  .report-summary {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
  }

  .report-summary .card {
    padding: 12px;
    border-radius: 12px;
  }

  .report-summary .card:first-child {
    grid-column: 1 / -1;
  }

  .report-summary small {
    font-size: 8px;
  }

  .report-summary b {
    margin-top: 5px;
    font-size: 18px;
  }

  .page-reports .report-section {
    padding: 13px 11px;
  }

  .report-section-head {
    align-items: flex-start;
    margin-bottom: 10px;
  }

  .report-section-head h2 {
    font-size: 17px;
  }

  .report-section-head p {
    font-size: 9px;
    line-height: 1.4;
  }

  .report-section-head > .balance-positive {
    flex: 0 0 auto;
    margin-top: 2px;
    font-size: 12px;
    white-space: nowrap;
  }

  /* Mobile outstanding list: show the information needed for collection,
     while keeping the complete accounting table unchanged on desktop/print. */
  #outstanding .report-table-wrap {
    overflow: visible;
  }

  #outstanding table,
  #outstanding tbody {
    display: block;
    width: 100%;
    overflow: visible;
    white-space: normal;
  }

  #outstanding thead {
    display: none;
  }

  #outstanding tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 5px 10px;
    width: 100%;
    padding: 10px 3px;
    border-bottom: 1px solid #e6eee9;
    background: transparent;
  }

  #outstanding tbody tr:last-child {
    border-bottom: 0;
  }

  #outstanding tbody td {
    display: block;
    min-width: 0;
    padding: 0;
    border: 0;
    white-space: normal;
  }

  #outstanding tbody td:nth-child(2),
  #outstanding tbody td:nth-child(3),
  #outstanding tbody td:nth-child(4) {
    display: none;
  }

  #outstanding .report-customer {
    min-width: 0;
    grid-column: 1;
    grid-row: 1;
  }

  #outstanding .report-customer b {
    color: #243b30;
    font-size: 11px;
    line-height: 1.35;
    overflow-wrap: anywhere;
  }

  #outstanding .report-customer small {
    margin-top: 2px;
    font-size: 8px;
    line-height: 1.3;
    overflow-wrap: anywhere;
  }

  #outstanding tbody td:nth-child(5) {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
    color: #a53b32;
    font-size: 11px;
    font-weight: 850;
    text-align: right;
    white-space: nowrap;
  }

  #outstanding tbody td:nth-child(5)::before {
    content: "Balance";
    display: block;
    margin-bottom: 2px;
    color: #8a9790;
    font-size: 7px;
    font-weight: 700;
    letter-spacing: .35px;
    text-transform: uppercase;
  }

  #outstanding tbody td:nth-child(6) {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  #outstanding .report-actions {
    gap: 5px;
    margin-top: 3px;
    white-space: normal;
  }

  #outstanding .report-actions .btn {
    min-height: 29px;
    padding: 6px 9px;
    border-radius: 7px;
    font-size: 9px;
  }

  .ledger-launch {
    gap: 9px;
  }
}


.whatsapp-list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 4px 0 12px;
}

.whatsapp-list-toolbar > div {
  display: grid;
  gap: 3px;
}

.whatsapp-list-toolbar b {
  color: var(--brand-dark);
  font-size: 14px;
}

.whatsapp-list-toolbar small {
  color: var(--muted);
  font-size: 10px;
}

.whatsapp-list-toolbar input {
  width: min(330px, 100%);
  height: 40px;
  padding: 9px 11px;
  font-size: 12px;
}

.whatsapp-table .whatsapp-balance {
  white-space: nowrap;
}

.whatsapp-action-cell .btn {
  min-width: 112px;
  padding: 8px 11px;
  font-size: 10px;
  box-shadow: none;
}

@media (max-width: 520px) {
  .page-whatsapp_reminders .reports-heading {
    margin-bottom: 12px;
  }

  .page-whatsapp_reminders .reports-heading h1 {
    max-width: 290px;
    font-size: 25px;
    line-height: 1.08;
  }

  .page-whatsapp_reminders .reports-heading p {
    max-width: 330px;
    font-size: 10px;
    line-height: 1.45;
  }

  .page-whatsapp_reminders .report-summary {
    margin-bottom: 10px;
  }

  #whatsapp-report {
    padding: 12px 10px;
  }

  #whatsapp-report .report-section-head {
    gap: 8px;
  }

  #whatsapp-report .report-section-head h2 {
    font-size: 16px;
  }

  #whatsapp-report .report-section-head > div:last-child {
    display: flex;
    flex: 0 0 auto;
    gap: 4px;
  }

  #whatsapp-report .report-status {
    padding: 3px 6px;
    font-size: 8px;
  }

  .whatsapp-template {
    margin-bottom: 12px;
    padding: 11px;
  }

  .whatsapp-template-editor {
    gap: 10px;
    margin-bottom: 9px;
  }

  .whatsapp-template textarea {
    min-height: 88px;
    padding: 9px 10px;
    font-size: 11px;
    line-height: 1.45;
  }

  .whatsapp-template small {
    margin-top: 5px;
    font-size: 8px;
    line-height: 1.4;
  }

  .whatsapp-preview {
    min-height: 76px;
    padding: 10px 11px;
    font-size: 10px;
    line-height: 1.45;
  }

  .whatsapp-template .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
  }

  .whatsapp-template .actions button {
    min-width: 0;
    min-height: 36px;
    padding: 7px 8px;
    font-size: 9px;
  }

  .whatsapp-list-toolbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin: 4px 0 9px;
  }

  .whatsapp-list-toolbar b {
    font-size: 12px;
  }

  .whatsapp-list-toolbar small {
    font-size: 8px;
  }

  .whatsapp-list-toolbar input {
    width: 100%;
    height: 38px;
    padding: 8px 10px;
    font-size: 11px;
  }

  .whatsapp-table-wrap {
    overflow: visible;
  }

  .whatsapp-table,
  .whatsapp-table tbody {
    display: block;
    width: 100%;
    overflow: visible;
    white-space: normal;
  }

  .whatsapp-table thead {
    display: none;
  }

  .whatsapp-table tbody tr[data-whatsapp-row] {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "customer balance"
      "phone action";
    align-items: center;
    gap: 4px 10px;
    width: 100%;
    padding: 9px 2px;
    border-bottom: 1px solid #e4ede7;
    background: transparent;
  }

  .whatsapp-table tbody tr[data-whatsapp-row]:last-of-type {
    border-bottom: 0;
  }

  .whatsapp-table tbody tr[data-whatsapp-row] > td {
    display: block;
    min-width: 0;
    padding: 0;
    border: 0;
    white-space: normal;
  }

  .whatsapp-table .report-customer {
    grid-area: customer;
    min-width: 0;
  }

  .whatsapp-table .report-customer b {
    color: #243b30;
    font-size: 10.5px;
    line-height: 1.3;
    overflow-wrap: anywhere;
  }

  .whatsapp-table .report-customer small {
    margin-top: 2px;
    max-width: 210px;
    overflow: hidden;
    color: #829087;
    font-size: 7.5px;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .whatsapp-table .whatsapp-balance {
    grid-area: balance;
    color: #a53b32;
    font-size: 10.5px;
    font-weight: 850;
    text-align: right;
    white-space: nowrap;
  }

  .whatsapp-table .whatsapp-phone {
    grid-area: phone;
    color: #697970;
    font-size: 8.5px;
    white-space: nowrap;
  }

  .whatsapp-table .whatsapp-status-cell {
    display: none !important;
  }

  .whatsapp-table .whatsapp-action-cell {
    grid-area: action;
    justify-self: end;
  }

  .whatsapp-table .whatsapp-action-cell .btn {
    min-width: 96px;
    min-height: 29px;
    padding: 6px 8px;
    border-radius: 7px;
    font-size: 8.5px;
  }

  #whatsapp-filter-empty,
  .whatsapp-table .report-empty {
    display: table-cell;
    padding: 18px 8px !important;
    font-size: 10px;
  }
}

@media print {
  .reports-heading .report-filter,
  .report-tabs,
  .report-actions,
  .no-report-print {
    display: none !important;
  }

  .report-section {
    break-inside: avoid;
  }
}


/* Mobile readability pass for Reports and WhatsApp reminders. */
@media (max-width:520px) {
  .reports-heading h1 { font-size: 29px; }
  .reports-heading p { font-size: 12px; line-height: 1.5; }

  .report-filter input { height: 40px; font-size: 14px; }
  .report-filter button { min-height: 40px; font-size: 12px; }

  .report-tab b { font-size: 12.5px; }
  .report-tab small { font-size: 9px; }
  .report-tab strong { font-size: 13.5px; }

  .report-summary small { font-size: 9px; }
  .report-summary b { font-size: 20px; }

  .report-section-head h2 { font-size: 18px; }
  .report-section-head p { font-size: 10.5px; line-height: 1.45; }
  .report-section-head > .balance-positive { font-size: 13.5px; }

  #outstanding .report-customer b { font-size: 13px; line-height: 1.35; }
  #outstanding .report-customer small { font-size: 9px; line-height: 1.35; }
  #outstanding tbody td:nth-child(5) { font-size: 13px; }
  #outstanding tbody td:nth-child(5)::before { font-size: 8px; }
  #outstanding .report-actions .btn { min-height: 31px; font-size: 10px; }

  .page-whatsapp_reminders .reports-heading h1 {
    font-size: 27px;
    line-height: 1.1;
  }
  .page-whatsapp_reminders .reports-heading p {
    font-size: 11.5px;
    line-height: 1.5;
  }
  #whatsapp-report .report-section-head h2 { font-size: 17px; }
  #whatsapp-report .report-status { font-size: 9px; }

  .whatsapp-template textarea { font-size: 12.5px; line-height: 1.5; }
  .whatsapp-template small { font-size: 9px; line-height: 1.45; }
  .whatsapp-preview { font-size: 11.5px; line-height: 1.5; }
  .whatsapp-template .actions button {
    min-height: 38px;
    font-size: 10px;
  }

  .whatsapp-list-toolbar b { font-size: 13.5px; }
  .whatsapp-list-toolbar small { font-size: 9px; }
  .whatsapp-list-toolbar input {
    height: 40px;
    font-size: 13px;
  }

  .whatsapp-table .report-customer b {
    font-size: 12.5px;
    line-height: 1.35;
  }
  .whatsapp-table .report-customer small { font-size: 9px; }
  .whatsapp-table .whatsapp-balance { font-size: 12.5px; }
  .whatsapp-table .whatsapp-phone { font-size: 10px; }
  .whatsapp-table .whatsapp-action-cell .btn {
    min-width: 104px;
    min-height: 31px;
    font-size: 10px;
  }
}


/* Prevent mobile report-tab title/value overlap. */
@media (max-width:520px) {
  .report-tab {
    flex: 0 0 245px;
    grid-template-columns: 30px minmax(0,1fr);
    grid-template-areas:
      "icon copy"
      "icon value";
    align-items: start;
    gap: 4px 9px;
    min-height: 78px;
    padding: 11px 12px;
  }

  .report-tab-icon {
    grid-area: icon;
    align-self: center;
  }

  .report-tab > span:not(.report-tab-icon) {
    grid-area: copy;
    min-width: 0;
  }

  .report-tab b {
    display: block;
    font-size: 12.5px;
    line-height: 1.2;
    overflow-wrap: anywhere;
  }

  .report-tab small {
    display: block;
    margin-top: 2px;
    font-size: 9px;
    line-height: 1.25;
  }

  .report-tab strong {
    grid-area: value;
    justify-self: start;
    max-width: 100%;
    margin-top: 1px;
    font-size: 13px;
    line-height: 1.2;
    white-space: nowrap;
  }
}

/* Keep customer advances distinct from amounts still due. */
.report-balance-summary {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.report-summary b.balance-advance,
#outstanding tbody td.balance-advance {
  color: #1d4ed8;
  font-weight: 800;
}

.report-balance-type {
  display: block;
  margin-bottom: 3px;
  font-size: 10px;
  font-weight: 750;
}

@media (max-width: 900px) {
  .report-balance-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .report-balance-summary .card:first-child {
    grid-column: auto;
  }

  #outstanding tbody td.report-balance::before {
    content: none;
  }

  #outstanding .report-balance-type {
    font-size: 9px;
  }

  #outstanding tbody tr.report-balance-empty {
    display: block;
  }
}
