/*
 * Receipts: a strip of receipt chips under the list's progress, the
 * upload drop zone, reading/failed states and the review.
 */
@layer components {
  .button--danger { color: var(--danger); text-decoration-color: currentColor; }
  .button--danger:hover { color: var(--danger); }

  /* Receipts scanned for a list, then the way to scan another. */
  .receipt-strip {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: var(--space-3) 0 var(--space-4);
  }
  .receipt-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 40px;
    padding: 0 var(--space-4) 0 var(--space-3);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-pill);
    background: var(--surface);
    color: var(--ink);
    font-size: var(--text-sm);
    font-weight: 800;
    text-decoration: none;
  }
  .receipt-chip svg { width: 18px; height: 18px; flex: none; }
  .receipt-chip__status { color: var(--muted); font-weight: 700; }
  .receipt-chip--ready { border-color: var(--sunny); background: var(--sunny-soft); }
  .receipt-chip--ready .receipt-chip__status { color: var(--ink); }
  .receipt-chip--failed { border-color: var(--danger); }
  .receipt-chip--failed .receipt-chip__status { color: var(--danger); }
  .receipt-chip--scan { border-style: dashed; border-color: var(--leaf); color: var(--leaf); }
  .receipt-chip:hover { border-color: var(--leaf); }

  /* The whole box is the file input's label: a big, thumb-sized target. */
  .photo-drop {
    position: relative;
    display: grid;
    justify-items: center;
    gap: var(--space-2);
    padding: var(--space-6) var(--space-5);
    border: 2px dashed var(--leaf);
    border-radius: var(--radius-lg, 24px);
    background: var(--mint-soft);
    text-align: center;
    cursor: pointer;
  }
  .photo-drop:focus-within { outline: 3px solid var(--leaf); outline-offset: 3px; }
  .photo-drop--invalid { border-color: var(--danger); background: var(--danger-soft); }
  .photo-drop__icon { width: 44px; height: 44px; color: var(--leaf); }
  .photo-drop__title { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 800; }
  .photo-drop__hint { max-width: 34ch; color: var(--muted); font-size: var(--text-sm); }
  .photo-drop__input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

  .receipt-status { display: grid; justify-items: center; gap: var(--space-2); text-align: center; }
  .receipt-status p { max-width: 40ch; color: var(--muted); }
  .receipt-status__icon { width: 36px; height: 36px; color: var(--danger); }
  .receipt-status__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-3); margin-top: var(--space-2); }
  .receipt-status__spinner {
    width: 36px;
    height: 36px;
    border: 4px solid var(--mint);
    border-top-color: var(--leaf);
    border-radius: 50%;
    animation: receipt-spin 900ms linear infinite;
  }
  @keyframes receipt-spin { to { transform: rotate(1turn); } }
  @media (prefers-reduced-motion: reduce) {
    .receipt-status__spinner { animation-duration: 3s; }
  }

  .receipt-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-4);
    margin-top: var(--space-6);
    color: var(--muted);
    font-size: var(--text-sm);
  }
  .receipt-footer p { margin-right: auto; }

  /* Review: the receipt's facts, then lines grouped by what they need. */
  .receipt-summary { display: grid; gap: var(--space-3); }
  .receipt-summary__facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-3); margin: 0; }
  .receipt-summary__facts dt { color: var(--muted); font-size: var(--text-xs); font-weight: 700; }
  .receipt-summary__facts dd { margin: 0; font-family: var(--font-display); font-size: var(--text-lg); font-weight: 800; }
  .receipt-summary__check { display: flex; align-items: flex-start; gap: var(--space-2); color: var(--leaf); font-size: var(--text-sm); font-weight: 700; }
  .receipt-summary__check svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
  .receipt-summary__check--off { padding: var(--space-2) var(--space-3); border-radius: var(--radius-md, 14px); background: var(--sunny-soft); color: var(--ink); }
  .receipt-summary__facts .receipt-summary__list { grid-column: 1 / -1; }
  .receipt-summary__facts .receipt-summary__list dd { font-size: var(--text-md); }
  .receipt-list-note { flex-direction: column; }
  .receipt-list-note p { display: flex; gap: var(--space-2); margin: 0; }
  .receipt-list-note__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
  .receipt-summary__adjustment { color: var(--muted); font-size: var(--text-sm); }
  .receipt-summary__edit summary, .receipt-line__change summary, .receipt-line__figures summary {
    color: var(--muted);
    font-size: var(--text-sm);
    font-weight: 700;
    text-decoration: underline;
    text-decoration-color: var(--line-strong);
    cursor: pointer;
  }
  .receipt-summary__edit[open] summary { margin-bottom: var(--space-3); }

  .receipt-group { margin-top: var(--space-6); }
  .receipt-group h2 { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-xl); }
  .receipt-group h2 svg { width: 24px; height: 24px; }
  .receipt-group--help h2 svg { color: var(--ink); }
  .receipt-group--known h2 svg { color: var(--leaf); }
  .receipt-group__lead { margin: var(--space-1) 0 var(--space-3); color: var(--muted); font-size: var(--text-sm); }
  .receipt-group--skipped summary { font-weight: 800; cursor: pointer; }
  /* Recognised and other purchases fold away: the heading is the toggle. */
  .receipt-group--known > summary, .receipt-group--other > summary {
    display: grid;
    gap: var(--space-1);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--line);
    border-radius: var(--radius-md, 14px);
    background: var(--surface);
    list-style: none;
    cursor: pointer;
  }
  .receipt-group--known > summary::-webkit-details-marker, .receipt-group--other > summary::-webkit-details-marker { display: none; }
  .receipt-group--known > summary h2, .receipt-group--other > summary h2 { font-size: var(--text-lg); }
  .receipt-group--known > summary h2::after, .receipt-group--other > summary h2::after {
    content: "Show";
    margin-left: auto;
    color: var(--muted);
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    font-weight: 700;
    text-decoration: underline;
  }
  .receipt-group--known[open] > summary h2::after, .receipt-group--other[open] > summary h2::after { content: "Hide"; }
  .receipt-group--known > summary .receipt-group__lead, .receipt-group--other > summary .receipt-group__lead { margin: 0; }
  .receipt-group--known[open] > summary, .receipt-group--other[open] > summary { margin-bottom: var(--space-3); }
  .receipt-group--other h2 svg { color: var(--muted); }
  .count {
    display: inline-grid;
    place-items: center;
    min-width: 26px;
    height: 26px;
    padding: 0 var(--space-2);
    border-radius: var(--radius-pill);
    background: var(--mint-soft);
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    font-weight: 800;
  }
  .receipt-group--help .count { background: var(--sunny); }

  .receipt-lines { display: grid; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
  .receipt-line {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--line);
    border-radius: var(--radius-md, 14px);
    background: var(--surface);
  }
  .receipt-line--help, .receipt-line--needs-review { border-color: var(--sunny); border-width: 2px; }
  .receipt-line--other { gap: var(--space-1); padding-block: var(--space-2); }
  .receipt-line--skipped, .receipt-line--voided { opacity: 0.75; }
  .receipt-line__row { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
  .receipt-line__main { display: grid; min-width: 0; }
  .receipt-line__name { font-weight: 800; }
  .receipt-line__printed { overflow-wrap: anywhere; color: var(--muted); font-size: var(--text-xs); letter-spacing: 0.02em; }
  .receipt-line__price { display: grid; justify-items: end; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .receipt-line__price small { color: var(--leaf); font-size: var(--text-xs); font-weight: 700; }
  .receipt-line__price--unclear { padding: 0 var(--space-2); border-radius: var(--radius-pill); background: var(--sunny-soft); }
  .receipt-line__why { font-size: var(--text-sm); }
  .receipt-line__why svg { display: inline; width: 16px; height: 16px; vertical-align: -3px; color: var(--danger); }
  .receipt-line__item { display: flex; align-items: center; gap: var(--space-1); color: var(--leaf); font-size: var(--text-sm); font-weight: 700; }
  .receipt-line__item svg { width: 16px; height: 16px; }
  .receipt-line--skipped .receipt-line__item { color: var(--muted); }
  .receipt-line__decide { display: grid; gap: var(--space-1); }
  .receipt-line__decide .inline-form__row .input { flex: 1; min-width: 0; }
  .receipt-line__skip { justify-self: start; }
  .receipt-line__change[open] { display: grid; gap: var(--space-2); }
  .receipt-line__figures[open] summary { margin-bottom: var(--space-2); }
  .receipt-line__figures .field-row { grid-template-columns: 1fr; }
  @media (min-width: 560px) { .receipt-line__figures .field-row { grid-template-columns: 2fr 1fr 1fr; } }

  .receipt-confirm { display: grid; gap: var(--space-2); margin-top: var(--space-6); text-align: center; }

  /* After confirming: what the receipts mean for the list. */
  .list-check { margin-top: var(--space-6); padding: var(--space-5); border-radius: var(--radius-lg, 24px); background: var(--mint-soft); }
  .list-check h2 { font-size: var(--text-xl); }
  .list-check h3 { display: flex; align-items: center; gap: var(--space-2); margin: var(--space-5) 0 var(--space-2); font-size: var(--text-md); }
  .list-check h3 svg { width: 20px; height: 20px; color: var(--leaf); }
  .list-check__form { display: grid; gap: var(--space-3); }
  .list-check__rows, .list-check__plain { display: grid; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
  .list-check__row label {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 0 var(--space-3);
    min-height: var(--touch);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-md, 14px);
    background: var(--surface);
    cursor: pointer;
  }
  .list-check__box { grid-row: span 2; width: 24px; height: 24px; accent-color: var(--leaf); }
  .list-check__name { font-weight: 800; }
  .list-check__detail { color: var(--muted); font-size: var(--text-sm); }
  .list-check__row--partial .list-check__detail, .list-check__row--unclear .list-check__detail { color: var(--ink); }
  .list-check__row--unclear label { box-shadow: inset 3px 0 0 var(--sunny); }
  .list-check__plain li { font-size: var(--text-sm); }
  .receipt-line__price .receipt-line__pending { color: var(--ink); background: var(--sunny-soft); padding: 0 var(--space-1); border-radius: 6px; }
  .receipt-line--adjustment .inline-form__row .input { flex: 1; min-width: 0; }

  /* A batch of old receipts: progress, then what Repeat learnt, then the
     few that need a look. Quiet, not a ledger. */
  .import-progress p:last-child, .import-summary p { color: var(--muted); }
  .import-summary h2, .import-attention h2 { margin-bottom: var(--space-1); }
  .import-attention .purchase-list { margin-top: var(--space-3); }
  .purchase-row--static:hover { border-color: var(--line); }
  .import-note { color: var(--muted); font-size: var(--text-sm); margin: 0 0 var(--space-4); }
  .import-added summary { cursor: pointer; font-weight: 800; }
  .import-added .purchase-list { margin-top: var(--space-3); }
  .import-naming summary { cursor: pointer; font-weight: 800; }
  .import-naming summary small { color: var(--muted); font-weight: 700; }
  .import-naming__list { display: grid; gap: var(--space-4); margin: var(--space-4) 0 0; padding: 0; list-style: none; }
  .import-naming__label { display: grid; }
  .import-naming__label small { color: var(--muted); }
  .import-summary__headline { font-size: var(--text-xl); line-height: 1.25; }
  .import-frequent .purchase-list { margin-top: var(--space-3); }

  /* Suggested regulars: the evidence first, then a form to adjust it. */
  .suggestion-coverage { color: var(--muted); font-size: var(--text-sm); margin: 0 0 var(--space-4); }
  .suggestion-list { display: grid; gap: var(--space-4); margin: 0; padding: 0; list-style: none; }
  .suggestion { display: grid; gap: var(--space-3); }
  .suggestion__name { font-size: var(--text-lg); }
  .suggestion__evidence { color: var(--muted); }
  .suggestion__proposal { font-weight: 800; }
  .suggestion__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
  .suggestion__adjust summary { cursor: pointer; color: var(--leaf); font-weight: 800; font-size: var(--text-sm); }
  .suggestion__adjust[open] summary { margin-bottom: var(--space-3); }
  .suggestion-banner { display: grid; gap: var(--space-1); margin-bottom: var(--space-4); color: var(--ink); text-decoration: none; background: var(--mint-soft, var(--surface)); }
  .suggestion-banner span { color: var(--muted); font-size: var(--text-sm); }

  .receipt-line__skip { display: flex; flex-wrap: wrap; gap: var(--space-1); }
}

/* History → Receipts: each row says how far linking got, quietly. */
@layer components {
  .receipt-filter { display: flex; width: fit-content; margin-bottom: var(--space-3); }
  .segmented--small .segmented__option { min-height: 32px; padding-inline: var(--space-3); font-size: var(--text-xs); }
  .receipt-filter .count { min-width: 20px; height: 20px; margin-left: var(--space-1); font-size: var(--text-xs); color: var(--ink); }
  .receipt-row__title { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); min-width: 0; }
  .receipt-row .purchase-row__price { align-self: center; }

  .chip svg { width: 14px; height: 14px; flex: none; }
  .chip--quiet { background: var(--cream); box-shadow: inset 0 0 0 1px var(--line); color: var(--muted); }
  .chip--done { background: var(--leaf-soft); color: var(--leaf-strong); }
  .chip--attention { background: var(--peach-soft); color: var(--danger); }

  .receipt-linked-note { display: flex; align-items: center; gap: var(--space-2); }
  .receipt-linked-note svg { width: 20px; height: 20px; flex: none; color: var(--leaf); }
  .receipt-linked-note p { margin: 0; }
}
