/* Receipt blocks owned by package B: rating, social links, Google review,
   terms, ads (banner, rotating, app), printed receipt PDF. Built on
   receipt.css and design-system classes and tokens; no raw hex.
   Every rule is scoped under an rb- block class: the old inline <style>s
   set bare h1, label, textarea, input[type=submit] and .loader for the
   whole page. */

.rb-title { margin: 0; font-size: var(--text-base); font-weight: var(--font-bold); line-height: 1.4; }
.rb-card-title { margin: 0; font-size: var(--text-lg); font-weight: var(--font-bold); line-height: 1.4; }
.rb-line { margin: 0; font-size: var(--text-sm); line-height: 1.6; color: var(--color-text-secondary); }
.rb-hint { font-size: 13px; color: var(--color-text-secondary); }
@keyframes rb-spin { to { transform: rotate(360deg); } }
.rb-spin { animation: rb-spin 0.9s linear infinite; }

/* ── Rating ── */
.rb-rating form { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); width: 100%; margin: 0; }
.rb-stars { display: flex; gap: 6px; direction: ltr; border: 0; margin: 0; padding: 0; min-width: 0; }
.rb-star {
  width: var(--receipt-tap); height: var(--receipt-tap);
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-full); cursor: pointer; color: var(--neutral-600);
  transition: transform var(--duration-fast) var(--ease-default), color var(--duration-fast) var(--ease-default);
}
.rb-star .r-icon { width: 30px; height: 30px; stroke-width: 1.8; }
/* On: the checked star and every star before it. Forward DOM order keeps
   arrow keys and screen readers going 1 to 5. */
.rb-star:has(input:checked),
.rb-star:has(~ .rb-star input:checked) { color: var(--color-accent); }
.rb-star:has(input:checked) .r-icon,
.rb-star:has(~ .rb-star input:checked) .r-icon { fill: currentColor; }
.rb-star:active { transform: scale(0.92); }
.rb-star:has(input:focus-visible) { outline: 2px solid var(--color-border-focus); outline-offset: 2px; }
.rb-rating__more { display: flex; flex-direction: column; gap: var(--space-3); width: 100%; text-align: start; }
.rb-rating form[hidden],
.rb-rating__more[hidden],
.rb-rating .alert[hidden],
.rb-thanks[hidden] { display: none; }
.rb-rating .textarea.input { min-height: 96px; font-size: var(--text-base); border-radius: var(--radius-lg); background: var(--receipt-card-bg); }
.rb-rating .alert { display: flex; align-items: center; gap: var(--space-2); width: 100%; margin: 0; text-align: start; }
.rb-rating .alert .r-icon { flex: none; width: 18px; height: 18px; }
.rb-rating .alert[hidden] { display: none; }
/* Sending: the stars and the comment are locked until the server answers. */
.rb-stars:disabled .rb-star { cursor: default; pointer-events: none; opacity: 0.6; }
.rb-rating form.is-sending .textarea.input { background: var(--color-bg-tertiary); }
.rb-rating form.is-sending .btn { opacity: 1; cursor: progress; }
.rb-rating .btn .rb-spin { margin-inline-end: var(--space-2); }
.rb-rating .btn .r-icon { width: 18px; height: 18px; }
.rb-thanks { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); width: 100%; }
.rb-stars-static { display: flex; gap: 2px; direction: ltr; color: var(--neutral-600); }
.rb-stars-static .r-icon { width: 24px; height: 24px; stroke-width: 1.8; }
.rb-stars-static .is-on { color: var(--color-accent); fill: currentColor; }
.rb-thanks__comment {
  margin: 0; width: 100%; padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg); background: var(--color-bg-tertiary);
  font-size: var(--text-sm); line-height: 1.6; text-align: start; overflow-wrap: anywhere; white-space: pre-line;
}
.rb-thanks__comment:empty { display: none; }

/* ── Social links ── */
/* Centred like the Google card: on a 360 px phone six platforms wrap to two
   rows, and centred rows read as intended rather than as a leftover. */
.rb-social { align-items: center; text-align: center; }
.rb-social .social-media-icons { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-2); }
.rb-social .social-link {
  /* 44 px (the tap minimum) with an 8 px gap fits six platforms on one row at 375 px. */
  width: var(--receipt-tap); height: var(--receipt-tap); margin: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-full); border: var(--border-width-thin) solid var(--color-border-primary);
  background: var(--receipt-card-bg); color: var(--color-text-primary); text-decoration: none;
  transition: border-color var(--duration-fast) var(--ease-default);
}
.rb-social .social-link:hover { border-color: var(--color-text-primary); }
.rb-social .social-link .r-icon { width: 20px; height: 20px; }
.rb-social .social-link img { width: 24px; height: 24px; object-fit: contain; }

/* ── Google review ── */
.rb-glyph {
  width: 48px; height: 48px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-full); background: var(--color-bg-tertiary); color: var(--color-text-primary);
}
.rb-google .btn,
.rb-google .btn:hover { text-decoration: none; }
.rb-google .btn .r-icon { width: 18px; height: 18px; }

/* ── Terms and conditions ── */
.rb-terms { padding-block: var(--space-2); gap: 0; }
.rb-terms:has([aria-expanded="true"]) { padding-block-end: var(--space-5); gap: 10px; }
.rb-terms .r-disclosure { font-size: var(--text-base); font-weight: var(--font-bold); }
.rb-terms .r-disclosure .r-icon { color: var(--color-text-secondary); }
.rb-terms__label { display: flex; align-items: center; gap: 10px; }
.rb-terms__body[hidden] { display: none; }
.rb-terms__text { font-size: var(--text-sm); line-height: 1.8; color: var(--color-text-secondary); overflow-wrap: anywhere; text-align: start; }
/* Both languages written: show the page's. Only one written: show it
   whatever the page language. main-script sets <html lang> on every toggle. */
html[lang="ar"] .rb-terms--both > .rb-terms__text[lang="en"],
html:not([lang="ar"]) .rb-terms--both > .rb-terms__text[lang="ar"] { display: none; }

/* ── Ads: banner, rotating, app ── */
.rb-ad { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.rb-ad__label { font-size: var(--text-xs); font-weight: var(--font-medium); color: var(--color-text-secondary); }
.rb-banner { display: block; overflow: hidden; border-radius: var(--radius-xl); background: var(--color-bg-tertiary); }
.rb-banner img,
img.rb-banner { display: block; width: 100%; height: auto; }

.rb-carousel { gap: var(--space-2); }
.rb-carousel__track {
  display: flex; gap: var(--space-3);
  overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory; scrollbar-width: none;
}
.rb-carousel__track::-webkit-scrollbar { display: none; }
.rb-carousel__slide { flex: 0 0 88%; min-width: 0; scroll-snap-align: start; }
.rb-carousel__slide:only-child { flex-basis: 100%; }
.rb-carousel__dots { display: flex; gap: var(--space-1); justify-content: center; }
.rb-carousel__dot {
  width: 24px; height: 24px; padding: 0; border: 0; background: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-full);
}
.rb-carousel__dot::before {
  content: ""; width: 8px; height: 8px; border-radius: var(--radius-full); background: var(--neutral-400);
  transition: width var(--duration-fast) var(--ease-default), background var(--duration-fast) var(--ease-default);
}
.rb-carousel__dot[aria-current="true"]::before { width: 20px; background: var(--color-accent); }

.rb-app__card { display: flex; flex-direction: column; overflow: hidden; border-radius: var(--receipt-card-radius); background: var(--receipt-card-bg); }
.rb-app__cover { display: block; background: var(--color-bg-tertiary); }
.rb-app__cover img,
img.rb-app__cover { display: block; width: 100%; height: auto; }
.rb-app__stores { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); padding: var(--space-4) var(--space-5) var(--space-5); }
.rb-app__stores--one { grid-template-columns: minmax(0, 1fr); }
.rb-store,
.rb-store:hover {
  display: flex; align-items: center; justify-content: center; height: 48px;
  border-radius: var(--radius-lg); background: var(--color-text-primary); color: var(--color-text-inverse);
  font-size: var(--text-sm); font-weight: var(--font-bold); text-decoration: none;
}

/* ── Printed receipt PDF: one card, state in data-state (loading | pages | error) ── */
.rb-pdf { gap: 14px; }
.rb-pdf__head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); }
.rb-pdf__count { font-size: 13px; color: var(--color-text-secondary); white-space: nowrap; }
.rb-pdf .loading,
.rb-pdf .error,
.rb-pdf .pdf_pages,
.rb-pdf__count,
.rb-pdf__nav { display: none; }
.rb-pdf[data-state="loading"] .loading,
.rb-pdf[data-state="error"] .error { display: flex; }
.rb-pdf[data-state="pages"] .pdf_pages { display: block; }
.rb-pdf[data-state="pages"][data-multi] .rb-pdf__count { display: inline; }
.rb-pdf[data-state="pages"] .rb-pdf__nav,
.rb-pdf[data-state="error"] .rb-pdf__nav { display: grid; }
.rb-pdf .loading {
  height: 180px; border-radius: var(--radius-lg); background: var(--color-bg-tertiary);
  align-items: center; justify-content: center; gap: var(--space-2);
  font-size: var(--text-sm); color: var(--color-text-secondary);
}
.rb-pdf .loading .r-icon { color: var(--color-accent); stroke-width: 2.5; }
.rb-pdf .error { flex-direction: column; gap: var(--space-3); }
.rb-pdf .error .alert { margin: 0; border: 0; border-radius: var(--radius-lg); padding: var(--space-3) 14px; gap: 10px; line-height: 1.6; color: var(--color-error); }
.rb-pdf .error .alert .r-icon { width: 18px; height: 18px; margin-top: 3px; }
/* The retry button keeps its bare class="retry_btn" (pinned by
   main/test_printed_receipt_pdf_viewer.py), so it takes the design
   system's outline-button look here. */
.rb-pdf .retry_btn {
  height: 48px; width: 100%; border-radius: var(--radius-lg);
  border: var(--border-width-thin) solid var(--color-accent); background: var(--receipt-card-bg); color: var(--color-accent);
  font: inherit; font-size: var(--text-base); font-weight: var(--font-bold); cursor: pointer;
  transition: background var(--duration-fast) var(--ease-default), color var(--duration-fast) var(--ease-default);
}
.rb-pdf .retry_btn:hover { background: var(--color-accent); color: var(--color-accent-text); }
.rb-pdf .pdf_page {
  display: block; width: 100%; height: auto;
  border-radius: var(--radius-lg); border: var(--border-width-thin) solid var(--color-border-primary);
  box-shadow: var(--shadow-sm); background: var(--receipt-card-bg);
}
.rb-pdf .pdf_page[hidden] { display: none; }
/* The page-1 PNG (issue 27) stands in for the first canvas until pdf.js has drawn it. */
.rb-pdf .rb-pdf__preview { display: none; }
.rb-pdf[data-state="loading"][data-preview] .loading { display: none; }
.rb-pdf[data-state="loading"][data-preview] .rb-pdf__preview {
  display: block; width: 100%; height: auto;
  border-radius: var(--radius-lg); border: var(--border-width-thin) solid var(--color-border-primary);
  box-shadow: var(--shadow-sm); background: var(--receipt-card-bg);
}
.rb-pdf__nav { grid-template-columns: var(--receipt-tap) minmax(0, 1fr) var(--receipt-tap); align-items: center; gap: var(--space-2); }
.rb-pdf__nav .r-iconbtn:disabled { opacity: 0.4; cursor: default; }
.rb-pdf__nav .r-iconbtn[hidden] { display: none; }
.rb-pdf__prev { grid-column: 1; }
.rb-pdf__next { grid-column: 3; }
.rb-pdf .pdf_open_link {
  grid-column: 2; justify-self: center;
  display: inline-flex; align-items: center; min-height: var(--receipt-tap); padding-inline: var(--space-2);
  font-size: 15px; font-weight: var(--font-bold); color: var(--color-text-link);
}

/* ── Live item lines (STREAM_ITEMS): the QR header, a thin bar toward the total, lines appended one by one.
   The rows reuse the extracted receipt's .rx-item look so the reload into it does not jump. ── */
.rb-live { gap: var(--space-3); }
.rb-live[hidden], .rb-pdf[hidden] { display: none; }
.rb-live__seller { margin: 0; overflow-wrap: anywhere; }
.rb-live__facts { display: flex; flex-direction: column; gap: var(--space-1); font-size: var(--text-sm); color: var(--color-text-secondary); }
.rb-live__bar { height: 3px; border-radius: 999px; background: var(--color-bg-tertiary); overflow: hidden; }
.rb-live__fill { display: block; height: 100%; width: 0; background: var(--color-accent); border-radius: inherit;
  transition: width var(--duration-normal, 250ms) var(--ease-default, ease-out); }
.receipt-page .rb-live__more[hidden], .rb-live__item[hidden] { display: none; }
.rb-live__more-count[hidden] { display: none; }
.rb-live__list:empty { min-height: var(--space-6); }
.rb-live__item--in { animation: rb-live-in 220ms var(--ease-default, ease-out) both; }
.rb-live__item--in .rb-live__qty, .rb-live__item--in .rx-item__total { opacity: 0; transition: opacity 180ms var(--ease-default, ease-out); }
.rb-live__item--in.rb-live__item--done .rb-live__qty, .rb-live__item--in.rb-live__item--done .rx-item__total { opacity: 1; }
@keyframes rb-live-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .rb-spin { animation-duration: 2.4s; }
  .rb-star, .rb-carousel__dot::before, .rb-social .social-link, .rb-pdf .retry_btn, .rb-live__fill { transition: none; }
  .rb-live__item--in { animation: none; }
  .rb-live__item--in .rb-live__qty, .rb-live__item--in .rx-item__total { transition: none; }
}

/* ── Print (Ctrl/Cmd+P, iOS "Print"): the receipt, not the page ──
   Controls, marketing and the sign-up card stay off the paper; everything the
   screen folds (items after the third, payment, store details, combo contents,
   terms) is written out, because a printed receipt cannot be tapped open. The
   hidden items carry an inline display:none, hence !important. Merchant block
   ORDER is untouched. */
@media print {
  @page { margin: 12mm; }
  .receipt-page { background: var(--receipt-card-bg); }
  .receipt-page #container { max-width: none; padding: 0; }
  .receipt-page .rx-topbar,
  .receipt-page .rx-totop,
  .receipt-page .rx-morebtn,
  .receipt-page .rx-nest-toggle,
  .receipt-page .r-disclosure .r-icon,
  .receipt-page .invoice-loader-overlay,
  .r-toasts,
  .r-sheet-backdrop,
  .receipt-page .invoice-block[data-token="rating"],
  .receipt-page .invoice-block[data-token="social_share"],
  .receipt-page .invoice-block[data-token="google_review"],
  .receipt-page .invoice-block[data-token="app_ad"],
  .receipt-page .invoice-block[data-token^="banner_ad"],
  .receipt-page .invoice-block[data-token^="rotating_ad"],
  .receipt-page .invoice-block[data-token="save_receipt_or_create_account"],
  .receipt-page .invoice-block[data-token="loyalty_stamps"],
  .receipt-page .rx-footer .r-link { display: none !important; }
  .receipt-page .invoice-item { display: flex !important; }
  .receipt-page .rx-nest[hidden],
  .receipt-page .rx-pay__body[hidden],
  .receipt-page .rx-store__more[hidden] { display: flex !important; }
  .receipt-page .rb-terms__body[hidden] { display: block !important; }
  .receipt-page .rx-items__more[hidden] { display: block !important; }
  .receipt-page .r-card,
  .receipt-page .branch-info.card { box-shadow: none; border: var(--border-width-thin) solid var(--color-border-primary); break-inside: avoid; }
  .receipt-page .r-total,
  .receipt-page .r-total--refund { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* «رقمي» (R1): the phone-capture form, in its own block and inside the white-label loyalty card. */
.rq-card { display: flex; flex-direction: column; gap: var(--space-3); }
.rq-fields { display: flex; flex-direction: column; gap: var(--space-3); }
.rq-done { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) 0; }
.rq-done[hidden], .rq-fields[hidden], .rq-error[hidden] { display: none; }
.rq-done__text { margin: 0; font-weight: var(--font-medium); }
