/*
  The account's pages (src/accountPages.ts), in the farm's website frame (site.css): each page's
  name as its heading, its parts on white cards on the farm's cream, as the mockups Jeff passed
  have them. The pages are reached from the menu under "Account" in the header (R297).
*/

/* A picture's <picture> only chooses its file (src/pictureMarkup.ts): its <img> is laid out as
   if it stood alone, so the rules below for an img hold as they are. Its AVIF <source> is not
   drawn, or it would take a place of its own in a row or a grid of pictures. */
picture {
  display: contents;
}

picture > source {
  display: none;
}

.site-main {
  background: var(--cream);
}

.account {
  /* The page's main text; the site's body text (--green-soft) is too light to read here. */
  color: var(--green);
  max-width: 880px;
  margin: 0 auto;
  padding: 12px 0 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.account-narrow {
  max-width: 720px;
}

.account p {
  margin: 0;
}

.account-quiet {
  color: var(--green-quiet);
  font-size: 15px;
}

.account-label {
  font-size: 14px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--green-quiet);
}

.account-title {
  margin: 0;
}

.account-part {
  background: var(--paper);
  border: 1px solid var(--green-faint);
  border-radius: var(--radius-card);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-margin-top: 16px;
}

.account-part > h1,
.account-part > h2 {
  margin: 0;
}

.account-part h2 {
  font-size: 28px;
}

.account-owed {
  border-color: var(--critical);
}

.account-owed h2 {
  font-size: 24px;
}

.account-problem {
  color: var(--critical);
  font-size: 15px;
}

.account-buttons {
  display: flex;
  gap: 10px 18px;
  flex-wrap: wrap;
  align-items: center;
}

.account .button {
  min-height: 46px;
  padding: 0 22px;
  font-size: 16px;
}

.account .button:disabled {
  opacity: 0.55;
  cursor: default;
}

/* Your CSA: the next box on its gray card, then the coming weeks. */
.account-lines,
.account-weeks ul,
.account-invoices,
.account-money {
  list-style: none;
  margin: 0;
  padding: 0;
}

.account-lines li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  font-size: 16px;
}

.account-lines .account-lines-total {
  border-top: 1px solid var(--green-faint);
  margin-top: 4px;
  padding-top: 8px;
}

.account-money li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 16px;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--green-faint);
}

/*
 * Your CSA's weeks (R292): every coming week in date order under its month, each on a tile with
 * its day; a skipped week stays in its place, dashed; the next box is opened up where it falls.
 */
.account-month {
  margin-top: 6px;
}

.account-week {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 14px 0;
  border-top: 1px solid var(--green-faint);
}

.account-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  line-height: 1.1;
  color: var(--green);
}

.account-day small {
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.account-day b {
  font-size: 24px;
  font-weight: 400;
}

.account-week-what {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.account-week-title {
  font-size: 17px;
  color: var(--green);
}

.account-week-note {
  font-size: 14px;
  color: var(--green-quiet);
}

.account-week-action {
  display: flex;
  align-items: center;
  gap: 18px;
  justify-content: flex-end;
}

.account-week-amount {
  font-size: 16px;
  color: var(--green);
}

.account-week-skipped .account-day {
  border-style: dashed;
  color: var(--green-quiet);
}

.account-week-skipped .account-day b {
  text-decoration: line-through;
}

.account-week-skipped .account-week-title {
  color: var(--green-quiet);
}

.account-week-next {
  grid-template-columns: 64px minmax(0, 1fr);
  align-items: start;
  margin: 6px 0;
  padding: 18px;
  border-top: 0;
  border-radius: 12px;
  background: var(--card);
}

.account-week-next + li {
  border-top: 0;
}

.account-week-next .account-day {
  background: var(--green);
  border-color: var(--green);
  color: var(--paper);
}

.account-week-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.account-tag {
  display: inline-block;
  margin-right: 8px;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--sage);
  color: var(--paper);
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  vertical-align: 2px;
}

/* What the member just did, with Undo (R292). */
.account-done {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--green-faint);
  color: var(--green);
  font-size: 15px;
}

.account-more {
  padding-top: 10px;
  border-top: 1px solid var(--green-faint);
}

.account-cancel {
  border-top: 1px solid var(--green-faint);
  padding-top: 14px;
  text-align: right;
  font-size: 15px;
}

.account-cancel a {
  color: var(--green-quiet);
}

/*
  Orders (R305): each order a frame of its own, a soft band across its top of two lines. The
  first has the title, its quieter pencil (R301) and the amount at the right; a label as the
  title keeps the number after it in parentheses, which stay on one line with the pencil. The
  second has the day and place, small and light, and at the right whether it is paid, as a small
  rounded label, then Pay or the receipt, so paid and unpaid frames keep one shape. Under the
  band its items' photos, which fill the frame evenly, a full row as far from either side
  (R299), then "View items", which opens the order in their place.
*/
.account-invoices {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.account-invoice {
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  overflow: hidden;
}

.account-invoice-band {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 18px;
  background: var(--cream);
}

.account-invoice-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  min-width: 0;
  /* As tall as Pay, so a paid frame and an unpaid one keep one shape. */
  min-height: 32px;
}

/*
  The first line: the amount floats at its right, so a long label wraps under it across the
  whole band rather than in a narrow column beside it.
*/
.account-invoice-line:first-child {
  display: block;
  min-height: 0;
}

.account-invoice-title {
  min-width: 0;
  font-size: 18px;
  color: var(--green);
  overflow-wrap: anywhere;
}

.account-invoice-tail {
  white-space: nowrap;
}

.account-invoice-number {
  font-size: 0.85em;
  color: var(--green-quiet);
}

.account-invoice-pencil {
  display: inline-block;
  vertical-align: -1px;
  margin: -6px 0 -6px 2px;
  padding: 6px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--green-light);
  line-height: 0;
  cursor: pointer;
}

.account-invoice-pencil svg {
  width: 14px;
  height: 14px;
}

.account-invoice-pencil:hover,
.account-invoice-pencil[aria-expanded='true'] {
  color: var(--green);
  background: var(--green-faint);
}

.account-invoice-line .account-amount {
  float: right;
  margin-left: 14px;
  font-size: 18px;
}

.account-invoice-when {
  min-width: 0;
  font-size: 13.5px;
  font-style: italic;
  letter-spacing: 0.2px;
  color: var(--green-light);
}

/* The day in short is for a phone (below). */
.account-when-short {
  display: none;
}

/* Whether it is paid, and what to do about it (R305). */
.account-order-state {
  display: flex;
  flex: none;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

/*
  The state as a small rounded label: owed in a warm sand, paid in the soft green. Nothing owed
  is a warning: a bill still open is nothing to be alarmed by (principle 1).
*/
.account-state-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 13px;
  line-height: 24px;
  letter-spacing: 0.2px;
}

.account-state-tag[data-tone='owed'] {
  background: var(--sand);
  color: var(--sand-ink);
}

.account-state-tag[data-tone='paid'] {
  background: var(--sage-pale);
  color: var(--sage-pale-ink);
}

/* Pay: the site's button, sized to the line. */
.account .button.account-invoice-pay {
  min-height: 32px;
  padding: 0 16px;
  font-size: 14px;
  letter-spacing: 0.6px;
}

.account-invoice-receipt {
  font-size: 14px;
  color: var(--green);
  text-underline-offset: 4px;
}

.account-invoice-view {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  padding: 0;
  border: 0;
  background: none;
  color: var(--green);
  font: inherit;
  font-size: 15px;
  letter-spacing: inherit;
  cursor: pointer;
}

.account-invoice-view [data-view-words] {
  text-decoration: underline;
  text-underline-offset: 5px;
  text-decoration-thickness: 1px;
}

.account-invoice-view[aria-expanded='true'] svg {
  transform: rotate(180deg);
}

.account-invoice-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 18px 16px;
}

.account-invoice-label {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--paper);
}

.account-invoice-label[hidden] {
  display: none;
}

.account-invoice-label label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--green);
}

.account-invoice-label input {
  font: inherit;
  font-size: 16px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

.account-invoice-label input:focus {
  outline: none;
  border-color: var(--sage-deep);
  box-shadow: 0 0 0 1px var(--sage-deep);
}

.account-invoice-label .account-quiet {
  font-size: 13px;
}

.account-invoice-photos {
  /* A tap on them opens the order, as "View" does, which is the control for a keyboard. */
  cursor: pointer;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 12px;
}

.account-invoice-photos img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 6px;
}

.account-invoice[data-open] .account-invoice-photos {
  display: none;
}

.account-invoice-order[hidden] {
  display: none;
}

/* A label just saved: the band glows once. */
.account-invoice-band[data-saved] {
  animation: account-saved 1.4s ease-out;
}

@keyframes account-saved {
  0% {
    background: rgb(140 160 120 / 0.35);
  }
  100% {
    background: var(--cream);
  }
}

.account-amount {
  white-space: nowrap;
  color: var(--green);
}

.account-card-fields {
  min-height: 0;
}

.account-card-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.account-card-form .button {
  align-self: flex-start;
}

.account-card-words {
  font-size: 15px;
  color: var(--green-quiet);
}

.card-fields-failed {
  color: var(--critical);
}

.account-order-where {
  display: block;
}

.account-money li {
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.account-pair {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
}

.account-shop {
  text-align: center;
}

/* An order and a receipt. */
.account-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.account-table th,
.account-table td {
  /* A name or a quantity that wraps reads as one block, as the site's headings do; the rows'
     padding keeps them apart. */
  line-height: 1.3;
  padding: 8px 6px;
  border-bottom: 1px solid var(--green-faint);
  text-align: left;
  vertical-align: middle;
}

.account-table td:last-child,
.account-table th:last-child {
  text-align: right;
  white-space: nowrap;
}

.account-table td:first-child {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* A very long word in a name breaks rather than push the table wider than its card. */
.account-table td:first-child > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.account-table img,
.account-table .leaf-thumb {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 6px;
  flex: none;
}

.account-table tfoot th {
  font-weight: 400;
  text-align: right;
}

.account-amount-due {
  font-size: 20px;
  color: var(--green);
  text-align: right;
}

.account-label-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.account-label-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 15px;
}

.account-label-form input,
.account-label-form textarea {
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--green);
}

.account-label-form .button {
  align-self: flex-start;
}

@media print {
  .site-header,
  .site-brand,
  .site-footer,
  .account > p:first-child,
  [data-print] {
    display: none !important;
  }
  .site-main {
    background: none;
  }
  .account-part {
    border: 0;
    padding: 0;
  }
}

/* Change box: tiles of photos on a wide screen, rows on a phone (R244 to R248). */
.box-scope {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  border: 1px solid var(--green);
  border-radius: var(--radius-button);
  overflow: hidden;
}

.box-scope a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 8px 10px;
  text-decoration: none;
  font-size: 15px;
  background: var(--paper);
}

.box-scope a[aria-current] {
  background: var(--green);
  color: var(--paper);
}

.box-scope a[aria-disabled='true'] {
  background: var(--cream);
  color: var(--green-pill);
  cursor: not-allowed;
}

.box-locked {
  font-style: italic;
}

.box-lines {
  min-height: 280px;
}

.box-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}

.box-line {
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}

.box-line-removed {
  border-style: dashed;
  background: var(--card);
}

.box-picture {
  position: relative;
}

.box-photo {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--card);
}

.box-line-removed .box-photo {
  opacity: 0.3;
  filter: grayscale(1);
}

.box-badge {
  position: absolute;
  left: 8px;
  top: 8px;
  /* Clear of the remove button at the right: a long choice's name wraps instead. */
  max-width: calc(100% - 66px);
  font-size: 14px;
  line-height: 1.35;
  padding: 3px 12px;
  border-radius: 16px;
  background: var(--green);
  color: var(--paper);
}

.box-badge-removed {
  background: var(--green-quiet);
}

.box-cross {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border-radius: 17px;
  border: 0;
  background: rgb(255 255 255 / 0.92);
  color: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.box-icon {
  width: 16px;
  height: 16px;
}

.box-words {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  /* A long name or choice wraps inside the line rather than pushing past it. */
  min-width: 0;
}

.box-name {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--green);
  font-size: 16px;
}

.box-name .box-line-total {
  display: none;
}

.box-was {
  color: var(--green-quiet);
  font-size: 15px;
  text-decoration: line-through;
}

.box-undo {
  align-self: flex-start;
  margin-top: auto;
}

/* A product's choices, under its own options' names, as the shop shows them (R213, R181). */
.box-choice-label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
  color: var(--green-quiet);
  font-size: 15px;
}

.box-choice {
  font: inherit;
  min-width: 0;
  max-width: 100%;
  font-size: 15px;
  padding: 6px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--paper);
  color: var(--green);
}

.box-unit {
  color: var(--green-quiet);
  font-size: 15px;
}

.box-qty {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
}

/* A raise held back: what they have is fine, but no more right now (R258, R259). */
.box-held {
  margin: 0;
  color: var(--green);
  font-size: 14px;
}

.box-stepper {
  display: flex;
  align-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 40px;
}

.box-step {
  width: 40px;
  height: 40px;
  border: 0;
  background: none;
  color: var(--green);
  font: inherit;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.box-step:disabled {
  opacity: 0.4;
  cursor: default;
}

.box-count {
  min-width: 22px;
  text-align: center;
}

.box-line-add {
  border: 0;
  background: none;
}

.box-add {
  min-height: 220px;
  height: 100%;
  width: 100%;
  border: 1.5px dashed var(--line-strong);
  border-radius: 12px;
  background: var(--card);
  color: var(--green);
  font: inherit;
  font-size: 17px;
  cursor: pointer;
}

.box-picker ul {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

.box-pick {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--green-faint);
}

.box-pick-photo {
  width: 64px;
  height: 48px;
  aspect-ratio: auto;
  border-radius: 6px;
}

.box-picker h2 {
  margin: 10px 0 0;
  font-size: 22px;
}

.box-warning {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  font-size: 15px;
}

.box-foot {
  border-top: 1px solid var(--green-faint);
  padding-top: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.box-total {
  font-size: 22px;
  color: var(--green);
}

/* A phone: a box's items are rows. */
@media (max-width: 749px) {
  /*
    An order's lines in two columns, so the amount always fits: the item, its photo and name
    with the quantity under the name, quieter and a size smaller; and the amount at the right,
    never wrapping. The quantity keeps its own cell, and its heading is there for a screen
    reader. The sums under them line up with the amounts.
  */
  .account-table,
  .account-table thead,
  .account-table tbody,
  .account-table tfoot {
    display: block;
  }

  .account-table tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 12px;
    align-items: center;
    border-bottom: 1px solid var(--green-faint);
  }

  .account-table th,
  .account-table td {
    border-bottom: 0;
  }

  .account-table thead th:nth-child(2) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .account-table tbody td:first-child {
    grid-column: 1;
    grid-row: 1;
    padding-bottom: 2px;
  }

  /* The quantity, under the name: in from the photo (52 px) and the gap (10 px). */
  .account-table tbody td:nth-child(2) {
    grid-column: 1;
    grid-row: 2;
    padding-top: 0;
    padding-left: 68px;
    font-size: 14px;
    color: var(--green-quiet);
  }

  .account-table tbody td:last-child {
    grid-column: 2;
    grid-row: 1 / span 2;
  }

  /* "Due" ends where the amounts above it do, inside their cells' padding. */
  .account-amount-due {
    padding-right: 6px;
  }

  /* A coming week's tile smaller, its price left to the next box, so Skip stays in reach. */
  .account-week {
    grid-template-columns: 52px minmax(0, 1fr) auto;
    gap: 12px;
  }

  .account-week-next {
    grid-template-columns: 52px minmax(0, 1fr);
    padding: 14px;
  }

  .account-day {
    width: 52px;
    height: 56px;
  }

  .account-day b {
    font-size: 20px;
  }

  .account-week-amount {
    display: none;
  }

  .site-main {
    padding-left: 0;
    padding-right: 0;
  }

  .account {
    padding: 4px 16px 32px;
    gap: 16px;
  }

  .account-part {
    padding: 18px;
  }

  .account-part h2 {
    font-size: 24px;
  }

  .account-week-next .button {
    width: 100%;
  }

  .account-buttons {
    flex-direction: column;
    align-items: stretch;
  }

  .account-invoice-band {
    padding: 12px 14px;
  }

  .account-invoice-body {
    padding: 12px 14px 14px;
  }

  /* The day in short beside the state, so the band stays two lines. */
  .account-when-long {
    display: none;
  }

  .account-when-short {
    display: inline;
  }

  .account-invoice-line {
    gap: 8px;
  }

  .account-order-state {
    gap: 6px;
  }

  .account-state-tag {
    padding: 0 8px;
  }

  .account .button.account-invoice-pay {
    padding: 0 12px;
  }

  .account-invoice-photos {
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    gap: 8px;
  }

  .account-pair {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }

  .box-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .box-line {
    flex-direction: row;
    gap: 12px;
    border: 0;
    border-bottom: 1px solid var(--green-faint);
    border-radius: 0;
    padding: 14px 0;
    background: none;
  }

  .box-line-removed {
    background: none;
  }

  .box-picture {
    flex: none;
  }

  .box-photo {
    width: 76px;
    height: 76px;
    aspect-ratio: auto;
    border-radius: 8px;
  }

  .box-cross,
  .box-line-total-tile {
    display: none;
  }

  .box-name .box-line-total {
    display: inline;
    white-space: nowrap;
  }

  .box-badge {
    position: static;
    display: inline-block;
    max-width: none;
    margin-top: 6px;
    font-size: 13px;
    padding: 1px 10px;
  }

  .box-words {
    padding: 0;
    gap: 4px;
  }

  .box-line-add {
    border: 0;
    padding: 12px 0 0;
  }

  .box-add {
    min-height: 48px;
    font-size: 16px;
  }

  .box-step {
    width: 44px;
    height: 38px;
  }
}

/* Narrower than a phone usually is: Pay and its label go under the day rather than squeeze it. */
@media (max-width: 359px) {
  .account-invoice-line:last-child {
    flex-wrap: wrap;
    row-gap: 6px;
  }

  .account-invoice-line:last-child .account-order-state {
    margin-left: auto;
  }
}
