/* =============================================================================
   css/screens/customers.css
   Where things go on the Customers screen (js/screens/customers.js): the
   list with its search and chips, the customer page, the "Who owes us"
   report, and the Receive payment sheet (CUST-01 to CUST-07).

   Tablet and laptop (768px and up): list on the left, the customer or the
   report on the right, both scrolling on their own. Phone: one at a time;
   #/customers is the list, #/customers/:id the customer with a back arrow
   (docs/05-ux-spec.md section 3, PWA-03). The same shape as Bills.

   Positioning only. The rows, badges, timeline, buckets and the amount
   boxes are components in components.css; every value here is a token
   (docs/05-ux-spec.md section 8, CLAUDE.md rule 9).
   ============================================================================= */


/* -----------------------------------------------------------------------------
   THE TWO PANES
   ----------------------------------------------------------------------------- */

.customers {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: var(--space-4);
  height: 100%;
  min-height: 0;
  padding: var(--space-3) var(--space-4);
}

.customers__list,
.customers__detail {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Phone: one pane fills the screen; which one is data-mode on the root. */
@media (max-width: 767px) {
  .customers {
    display: block;
    height: auto;
    padding: var(--space-3);
  }

  .customers[data-mode='list'] .customers__detail,
  .customers[data-mode='detail'] .customers__list {
    display: none;
  }

  .customers__list,
  .customers__detail {
    overflow: visible;
  }
}

/* The back arrow is only for a phone; on a tablet the list is beside. */
.customers__back {
  align-self: flex-start;
}

@media (min-width: 768px) {
  .customers__back {
    display: none;
  }
}


/* -----------------------------------------------------------------------------
   THE LIST: title row, the "Who owes us" card, search, chips, results
   ----------------------------------------------------------------------------- */

.customers__title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: none;
}

.customers__title h1 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: var(--text-heading);
}

/* The card: title, the total, a note, and a chevron on the right. */
.customers__owing {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto auto;
  gap: 0 var(--space-3);
  align-items: center;
  flex: none;
  text-decoration: none;
  color: inherit;
}

.customers__owing > .card__title,
.customers__owing > .card__value,
.customers__owing > .card__note {
  grid-column: 1;
}

.customers__owing > .card__title {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.customers__owing > .icon {
  grid-column: 2;
  grid-row: 1 / span 3;
  color: var(--color-text-faint);
}

.customers__owing[aria-pressed='true'] {
  background: var(--color-primary-faint);
}

.customers__filters {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  flex: none;
}

/* Never shrunk: the column scrolls as a whole, so the count line always
   sits under the last row rather than over it. */
.customers__results {
  flex: none;
}

.customers__count {
  flex: none;
  font-size: var(--text-small);
}


/* -----------------------------------------------------------------------------
   ONE CUSTOMER, and the report: a card
   ----------------------------------------------------------------------------- */

.customers__card {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}

.customers__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
}

.customers__name {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: var(--text-heading);
  font-weight: var(--font-bold);
}

/* "Owes Rs 5,000.00", orange while something is owed. */
.customers__balance {
  font-size: var(--text-heading);
  font-weight: var(--font-bold);
  white-space: nowrap;
}

.customers__balance[data-owing='true'] {
  color: var(--color-warning);
}

.customers__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  color: var(--color-text-muted);
}

.customers__meta span {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

/* Receive payment first and largest; the rest wrap after it. */
.customers__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.customers__actions > .btn--primary {
  flex: 1 1 100%;
}

@media (min-width: 768px) {
  .customers__actions > .btn--primary {
    flex: 0 1 auto;
    min-width: 240px;
  }
}

.customers__section-title {
  margin: 0 0 var(--space-2);
  font-size: var(--text-body);
  font-weight: var(--font-medium);
  color: var(--color-text-muted);
}


/* -----------------------------------------------------------------------------
   THE RECEIVE PAYMENT SHEET (CUST-04), js/ui/receive-payment-sheet.js
   Fields on the left, the number pad on the right, as the payment sheet
   on Sell. On a phone the pad drops under the fields.
   ----------------------------------------------------------------------------- */

.receive-sheet__columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-5);
  align-items: start;
  padding-top: var(--space-3);
}

@media (max-width: 767px) {
  .receive-sheet__columns {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }

  .receive-sheet__pad {
    justify-self: center;
  }
}

.receive-sheet__fields {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}

.receive-sheet__quick {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* "Common amounts to take:", "This money goes to the oldest bill first:" */
.receive-sheet__quick-label {
  margin: 0;
  font-size: var(--text-small);
}

.receive-sheet__status {
  margin: var(--space-3) 0 0;
  color: var(--color-text-muted);
}

.receive-sheet__status.is-danger {
  padding: var(--space-2) var(--space-3);
  color: var(--color-danger);
  font-weight: var(--font-medium);
  background: var(--color-danger-faint);
  border-radius: var(--radius-sm);
}

/* After saving: what was received and what is owed now, then Done. */
.receive-sheet__done {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding-top: var(--space-3);
}

.receive-sheet__queued {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  color: var(--color-warning);
  font-weight: var(--font-medium);
}


/* -----------------------------------------------------------------------------
   THE ADD / EDIT / MERGE DIALOGS, js/ui/customer-form.js
   ----------------------------------------------------------------------------- */

.customer-dialog {
  width: min(560px, calc(100vw - var(--space-6)));
}
